-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a193022
commit 2db7810
Showing
5 changed files
with
118 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
|
||
import "../../../libraries/Bridges/LibCMARKCarbon.sol"; | ||
import "../../../libraries/LibRetire.sol"; | ||
import "../../../libraries/TokenSwap/LibSwap.sol"; | ||
import "../../../ReentrancyGuard.sol"; | ||
|
||
contract RetireCMARKFacet is ReentrancyGuard { | ||
event CarbonRetired( | ||
LibRetire.CarbonBridge carbonBridge, | ||
address indexed retiringAddress, | ||
string retiringEntityString, | ||
address indexed beneficiaryAddress, | ||
string beneficiaryString, | ||
string retirementMessage, | ||
address indexed carbonPool, | ||
address carbonToken, | ||
uint retiredAmount | ||
); | ||
|
||
/** | ||
* @notice This contract assumes that the token being provided is a raw CMARK credit token. | ||
* @notice The transactions will revert otherwise. | ||
*/ | ||
|
||
/** | ||
* @notice Retires CMARK credits directly | ||
* @param carbonToken Pool token to redeem | ||
* @param amount Amounts of underlying tokens to redeem | ||
* @param beneficiaryAddress 0x address for the beneficiary | ||
* @param beneficiaryString String description of the beneficiary | ||
* @param retirementMessage String message for this specific retirement | ||
* @param fromMode From Mode for transfering tokens | ||
* @return retirementIndex The latest retirement index for the beneficiary address | ||
*/ | ||
function cmarkRetireExactCarbon( | ||
address carbonToken, | ||
uint amount, | ||
address beneficiaryAddress, | ||
string memory beneficiaryString, | ||
string memory retirementMessage, | ||
LibTransfer.From fromMode | ||
) external nonReentrant returns (uint retirementIndex) { | ||
// Currently this is a simple wrapper for direct calls on specific CMARK tokens | ||
// No fee is charged | ||
|
||
LibTransfer.receiveToken(IERC20(carbonToken), amount, msg.sender, fromMode); | ||
|
||
// Retire the carbon | ||
LibCMARKCarbon.retireCMARK( | ||
address(0), // Direct retirement, no pool token | ||
carbonToken, | ||
amount, | ||
msg.sender, | ||
"KlimaDAO Retirement Aggregator", | ||
beneficiaryAddress, | ||
beneficiaryString, | ||
retirementMessage | ||
); | ||
|
||
return LibRetire.getTotalRetirements(beneficiaryAddress); | ||
} | ||
|
||
/** | ||
* @notice Retires CMARK credits directly | ||
* @param carbonToken Pool token to redeem | ||
* @param amount Amounts of underlying tokens to redeem | ||
* @param retiringEntityString String description of the retiring entity | ||
* @param beneficiaryAddress 0x address for the beneficiary | ||
* @param beneficiaryString String description of the beneficiary | ||
* @param retirementMessage String message for this specific retirement | ||
* @param fromMode From Mode for transfering tokens | ||
* @return retirementIndex The latest retirement index for the beneficiary address | ||
*/ | ||
function cmarkRetireExactCarbonWithEntity( | ||
address carbonToken, | ||
uint amount, | ||
string memory retiringEntityString, | ||
address beneficiaryAddress, | ||
string memory beneficiaryString, | ||
string memory retirementMessage, | ||
LibTransfer.From fromMode | ||
) external nonReentrant returns (uint retirementIndex) { | ||
// Currently this is a simple wrapper for direct calls on specific CMARK tokens | ||
// No fee is charged | ||
|
||
LibTransfer.receiveToken(IERC20(carbonToken), amount, msg.sender, fromMode); | ||
|
||
// Retire the carbon | ||
LibCMARKCarbon.retireCMARK( | ||
address(0), // Direct retirement, no pool token | ||
carbonToken, | ||
amount, | ||
msg.sender, | ||
retiringEntityString, | ||
beneficiaryAddress, | ||
beneficiaryString, | ||
retirementMessage | ||
); | ||
|
||
return LibRetire.getTotalRetirements(beneficiaryAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
interface ICMARKCreditToken { | ||
function retire(uint256 amount, address beneficiary, string beneficiaryName, string message, string consumptionCountryCode) external nonpayable; | ||
function retireFrom(uint256 amount, address beneficiary, string beneficiaryName, string message, string consumptionCountryCode, address account) external nonpayable; | ||
function retire(uint256 amount, address beneficiary, string calldata beneficiaryName, string calldata message, string calldata consumptionCountryCode) external; | ||
function retireFrom(uint256 amount, address beneficiary, string calldata beneficiaryName, string calldata message, string calldata consumptionCountryCode, address account) external; | ||
} | ||
|
||
interface ICMARKCreditTokenFactory { | ||
|
||
function creditAddressToId(address) returns (string) external view; | ||
function creditAddressToId(address) external view returns (string memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters