@@ -15,36 +15,49 @@ import "hardhat/console.sol";
15
15
* @notice Helper functions that simplify the carbon offsetting (retirement)
16
16
* process.
17
17
*
18
- * Retiring carbon tokens normally requires multiple steps and interactions
19
- * with Toucan Protocol's main contracts:
18
+ * Retiring carbon tokens requires multiple steps and interactions with
19
+ * Toucan Protocol's main contracts:
20
20
* 1. Obtain a Toucan pool token such as BCT or NCT (by performing a token
21
21
* swap).
22
22
* 2. Redeem the pool token for a TCO2 token.
23
23
* 3. Retire the TCO2 token.
24
24
*
25
25
* These steps are combined in each of the following "auto offset" methods
26
26
* implemented in `OffsetHelper` to allow a retirement within one transaction:
27
- * - `autoOffsetUsingPoolToken()` if the user has already owns a Toucan pool
27
+ * - `autoOffsetUsingPoolToken()` if the user already owns a Toucan pool
28
28
* token such as BCT or NCT,
29
29
* - `autoOffsetUsingETH()` if the user would like to perform a retirement
30
30
* using MATIC,
31
31
* - `autoOffsetUsingToken()` if the user would like to perform a retirement
32
32
* using an ERC20 token: USDC, WETH or WMATIC.
33
33
*
34
34
* In these methods, "auto" refers to the fact that these methods use
35
- * `autoRedeem` in order to automatically choose a TCO2 token corresponding
35
+ * `autoRedeem() ` in order to automatically choose a TCO2 token corresponding
36
36
* to the oldest tokenized carbon project in the specfified token pool.
37
- * There are no fees incurred by the user when using `autoRedeem`.
37
+ * There are no fees incurred by the user when using `autoRedeem()`, i.e., the
38
+ * user receives 1 TCO2 token for each pool token (BCT/NCT) redeemed.
38
39
*
39
- * There are two read helper functions `calculateNeededETHAmount()` and
40
- * `calculateNeededTokenAmount()` that can be used before calling
41
- * `autoOffsetUsingETH()` and `autoOffsetUsingToken()`, to determine how MATIC,
42
- * respectively how much of the ERC20 token must be sent to the `OffsetHelper`
43
- * contract in order to retire the specified amount of carbon.
40
+ * There are two `view` helper functions `calculateNeededETHAmount()` and
41
+ * `calculateNeededTokenAmount()` that should be called before using
42
+ * `autoOffsetUsingETH()` and `autoOffsetUsingToken()`, to determine how much
43
+ * MATIC, respectively how much of the ERC20 token must be sent to the
44
+ * `OffsetHelper` contract in order to retire the specified amount of carbon.
44
45
*/
45
46
contract OffsetHelper is OffsetHelperStorage {
46
47
using SafeERC20 for IERC20 ;
47
48
49
+ /**
50
+ * @notice Contract constructor. Should specify arrays of ERC20 symbols and
51
+ * addresses that can used by the contract.
52
+ *
53
+ * @dev See `isEligible()` for a list of tokens that can be used in the
54
+ * contract. These can be modified after deployment by the contract owner
55
+ * using `setEligibleTokenAddress()` and `deleteEligibleTokenAddress()`.
56
+ *
57
+ * @param _eligibleTokenSymbols A list of token symbols.
58
+ * @param _eligibleTokenAddresses A list of token addresses corresponding
59
+ * to the provided token symbols.
60
+ */
48
61
constructor (
49
62
string [] memory _eligibleTokenSymbols ,
50
63
address [] memory _eligibleTokenAddresses
@@ -265,9 +278,9 @@ contract OffsetHelper is OffsetHelperStorage {
265
278
/**
266
279
* @notice Swap eligible ERC20 tokens for Toucan pool tokens (BCT/NCT) on SushiSwap
267
280
* @dev Needs to be approved on the client side
268
- * @param _fromToken token to deposit and swap
269
- * @param _toToken token to swap for (will be held within contract)
270
- * @param _amount amount of NCT / BCT wanted
281
+ * @param _fromToken The ERC20 oken to deposit and swap
282
+ * @param _toToken The token to swap for (will be held within contract)
283
+ * @param _amount The required amount of the Toucan pool token (NCT/BCT)
271
284
*/
272
285
function swap (
273
286
address _fromToken ,
@@ -358,8 +371,8 @@ contract OffsetHelper is OffsetHelperStorage {
358
371
359
372
/**
360
373
* @notice Swap MATIC for Toucan pool tokens (BCT/NCT) on SushiSwap
361
- * @param _toToken token to swap for (will be held within contract)
362
- * @param _amount amount of NCT / BCT wanted
374
+ * @param _toToken Token to swap for (will be held within contract)
375
+ * @param _amount Amount of NCT / BCT wanted
363
376
*/
364
377
function swap (address _toToken , uint256 _amount ) public payable {
365
378
// check tokens
@@ -403,7 +416,7 @@ contract OffsetHelper is OffsetHelperStorage {
403
416
}
404
417
405
418
/**
406
- * @notice allow users to withdraw tokens they have deposited
419
+ * @notice Allow users to withdraw tokens they have deposited.
407
420
*/
408
421
function withdraw (address _erc20Addr , uint256 _amount ) public {
409
422
require (
@@ -416,8 +429,8 @@ contract OffsetHelper is OffsetHelperStorage {
416
429
}
417
430
418
431
/**
419
- * @notice allow people to deposit BCT / NCT
420
- * @dev needs to be approved
432
+ * @notice Allow users to deposit BCT / NCT.
433
+ * @dev Needs to be approved
421
434
*/
422
435
function deposit (address _erc20Addr , uint256 _amount ) public {
423
436
require (isRedeemable (_erc20Addr), "Token not eligible " );
@@ -427,12 +440,12 @@ contract OffsetHelper is OffsetHelperStorage {
427
440
}
428
441
429
442
/**
430
- * @notice Redeems the specified amount of NCT / BCT for TCO2
431
- * @dev needs to be approved on the client side
432
- * @param _fromToken could be the address of NCT or BCT
433
- * @param _amount amount to redeem
434
- * @return tco2s an array of the TCO2 addresses that were redeemed
435
- * @return amounts an array of the amounts of each TCO2 that were redeemed
443
+ * @notice Redeems the specified amount of NCT / BCT for TCO2.
444
+ * @dev Needs to be approved on the client side
445
+ * @param _fromToken Could be the address of NCT or BCT
446
+ * @param _amount Amount to redeem
447
+ * @return tco2s An array of the TCO2 addresses that were redeemed
448
+ * @return amounts An array of the amounts of each TCO2 that were redeemed
436
449
*/
437
450
function autoRedeem (address _fromToken , uint256 _amount )
438
451
public
@@ -463,8 +476,9 @@ contract OffsetHelper is OffsetHelperStorage {
463
476
464
477
/**
465
478
* @notice Retire the specified TCO2 tokens.
466
- * @param _tco2s the addresses of the TCO2s to retire
467
- * @param _amounts the amounts to retire from the matching TCO2
479
+ * @param _tco2s The addresses of the TCO2s to retire
480
+ * @param _amounts The amounts to retire from each of the corresponding
481
+ * TCO2 addresses
468
482
*/
469
483
function autoRetire (address [] memory _tco2s , uint256 [] memory _amounts )
470
484
public
@@ -496,9 +510,9 @@ contract OffsetHelper is OffsetHelperStorage {
496
510
// ----------------------------------------
497
511
498
512
/**
499
- * @notice you can use this to change or add eligible tokens and their addresses if needed
500
- * @param _tokenSymbol symbol of the token to add
501
- * @param _address the address of the token to add
513
+ * @notice Change or add eligible tokens and their addresses.
514
+ * @param _tokenSymbol The symbol of the token to add
515
+ * @param _address The address of the token to add
502
516
*/
503
517
function setEligibleTokenAddress (
504
518
string memory _tokenSymbol ,
@@ -508,8 +522,8 @@ contract OffsetHelper is OffsetHelperStorage {
508
522
}
509
523
510
524
/**
511
- * @notice you can use this to delete eligible tokens if needed
512
- * @param _tokenSymbol symbol of the token to add
525
+ * @notice Delete eligible tokens stored in the contract.
526
+ * @param _tokenSymbol The symbol of the token to remove
513
527
*/
514
528
function deleteEligibleTokenAddress (string memory _tokenSymbol )
515
529
public
@@ -520,8 +534,8 @@ contract OffsetHelper is OffsetHelperStorage {
520
534
}
521
535
522
536
/**
523
- * @notice you can use this to change the TCO2 contracts registry if needed
524
- * @param _address the contract registry to use
537
+ * @notice Change the TCO2 contracts registry.
538
+ * @param _address The address of the Toucan contract registry to use
525
539
*/
526
540
function setToucanContractRegistry (address _address )
527
541
public
0 commit comments