Skip to content

Commit cd85e75

Browse files
authored
Merge pull request #29 from danceratopz/docs/improve-doc-and-autogenerate-from-natspec
Docs: Improve readme and autogenerate natspec doc
2 parents 54cad5b + c9cfad3 commit cd85e75

File tree

8 files changed

+658
-88
lines changed

8 files changed

+658
-88
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
env:
6262
POLYGON_URL: ${{ secrets.POLYGON_URL }}
6363

64+
- name: Test solidity-docgen builds
65+
run: yarn doc
66+
6467
- name: Deploy contract
6568
run: yarn hardhat --network hardhat deployOffsetHelper --verify false
6669
env:

README.md

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Example Implementations
22

3-
A collection of examples that implement, integrate with or otherwise use Toucan's contracts and infrastructure. Some of these may be used in production.
3+
A collection of Solidity contract examples that integrate with or demonstrate the use of Toucan's contracts and infrastructure. Some of these may be used in production.
44

55
## Contracts
66

@@ -10,46 +10,39 @@ A collection of examples that implement, integrate with or otherwise use Toucan'
1010

1111
## OffsetHelper
1212

13-
The `OffsetHelper` abstracts the carbon offsetting process offered by Toucan to make it easier. Instead of you manually swapping your USDC for NCT, redeeming the NCT for TCO2, then retiring the TCO2... you can just use the `OffsetHelper` to swiftly do this process in 1-2 transactions.
13+
The `OffsetHelper` contract implements helper functions that simplify the carbon offsetting (retirement) process.
1414

15-
This contract has 2 main methods that users would interact with: `autoOffset` and `autoOffsetUsingPoolToken`.
15+
See [./docs/OffsetHelper.md](./docs/OffsetHelper.md) for detailed documentation.
1616

17-
### `autoOffset(address _depositedToken, address _poolToken_, uint256 _amountToOffset)`
17+
### Development
1818

19-
This method takes your tokens, swaps them for pool tokens (BCT or NCT), redeems that for the lowest quality TCO2 and then retires it.
19+
## Preqrequisites
2020

21-
Let's discuss the params: the first is the token you will deposit to do the offset (could be USDC, WETH or WMATIC), the second is the pool token you want the contract to use (could be NCT or BCT) and the last is the amount of TCO2 to retire.
21+
1. Install the required packages:
22+
```
23+
yarn
24+
```
25+
2. Copy `.env.example` to `.env` and modify values of the required environment variables:
26+
1. `POLYGON_URL`/`MUMBAI_URL` to specify custom RPC endpoints for Polygon Mainnet, respectively, the Mumbai Testnet.
27+
2. `PRIVATE_KEY` and `POLYGONSCAN_KEY` in order to deploy contract and publish source code on [polygonscan](https://polygonscan.com).
2228

23-
You will have to approve the `OffsetHelper` from the token you wish to deposit before calling `autoOffset()` in this case.
29+
## Commands
2430

25-
### `autoOffset(address _poolToken_, uint256 _amountToOffset)`
31+
Use the following commands to compile, test and deploy the contracts:
32+
```
33+
yarn compile
34+
yarn test # test using a polygon fork
35+
yarn coverage # test using a polygon fork with coverage report
36+
yarn deploy
37+
```
2638

27-
If you call the `autoOffset()` method specifying only 2 params, it will be payable and you will need to specify a `msg.value`. It works the same as the above method, only this one will swap MATIC for pool tokens instead.
39+
Documentation can be auto-generated from the contract's [natspec](https://docs.soliditylang.org/en/latest/natspec-format.html) in [./docs/](./docs/) using
40+
```
41+
yarn doc
42+
```
2843

29-
The first param is the pool token you want the contract to use (could be NCT or BCT) and the second is the amount of TCO2 to retire.
44+
Deploy the contract locally with:
45+
```
46+
yarn hardhat --network hardhat deployOffsetHelper --verify false
47+
```
3048

31-
In case you send too much MATIC in the `msg.value`, the contract is programed to send leftover MATIC back to the user. But, I suggest you use the `calculateNeededETHAmount()` method of the contract before calling `autoOffset()` in this case.
32-
33-
We'll discuss the `calculateNeededETHAmount()` method below.
34-
35-
### `autoOffsetUsingPoolToken(address _poolToken, uint256 _amountToOffset)`
36-
37-
This method is made for users that already have a pool token in their wallet (BCT or NCT), but still would like to use the `OffsetHelper` to abstract away a few steps.
38-
39-
It takes your pool token, redeems it for the lowest quality TCO2 and retires it.
40-
41-
The first parameter is the pool token you will deposit to do the offset (could be NCT or BCT), the second is the amount of TCO2 to retire.
42-
43-
You will want to approve the `OffsetHelper` from the token you wish to deposit before calling `autoOffsetUsingPoolToken()` in this case.
44-
45-
### `calculateNeededETHAmount(address _toToken, uint256 _amount)`
46-
47-
This is a view method that allows you to see how much MATIC it would cost you to get a certain amount of BCT / NCT.
48-
49-
Since (when automatically redeeming pool tokens for the lowest quality TCO2s) the redeeming has no fees and you get 1 TCO2 for each pool token you redeem, effectively this method will tell you how much MATIC you have to deposit to be able to retired a specific amount of TCO2.
50-
51-
Normally, you'd use it before calling `autoOffset(address _poolToken_, uint256 _amountToOffset)` and the result it returns will be assigned as msg.value when you call `autoOffset(address _poolToken_, uint256 _amountToOffset)`.
52-
53-
### Others
54-
55-
There are other methods you can interact with, but you probably won't because it would result in a fairly manual, multi-step offsetting process which is what we're trying to abstract.

0 commit comments

Comments
 (0)