Skip to content

Commit

Permalink
Fix compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAurelius committed Dec 19, 2024
1 parent a193022 commit 2db7810
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 21 deletions.
104 changes: 104 additions & 0 deletions src/infinity/facets/Bridges/CMARK/RetireCMARKFacet.sol
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);
}
}
7 changes: 3 additions & 4 deletions src/infinity/interfaces/ICMARKCredit.sol
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);
}
8 changes: 5 additions & 3 deletions src/infinity/libraries/Bridges/LibCMARKCarbon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ library LibCMARKCarbon {
* @param retirementMessage String message for this specific retirement
*/
function retireCMARK(
address poolToken,
address projectToken,
uint amount,
address retiringAddress,
string memory retiringEntityString,
address beneficiaryAddress,
string memory beneficiaryString,
string memory retirementMessage
string memory retirementMessage,
string memory consumptionCountryCode
) internal {
ICMARKProjectToken(projectToken).offsetFor(amount, beneficiaryAddress, beneficiaryString, retirementMessage);
ICMARKCreditToken(projectToken).retire(amount, beneficiaryAddress, beneficiaryString, retirementMessage);

LibRetire.saveRetirementDetails(
poolToken,
Expand All @@ -68,6 +70,6 @@ library LibCMARKCarbon {
}

function isValid(address token) internal returns (bool) {
return ICMARKProjectFactory(C.cMARKProjectFactory()).creditAddressToId(token) != '';
return ICMARKCreditTokenFactory(C.cMARKCreditFactory()).creditAddressToId(token) != '';
}
}
9 changes: 1 addition & 8 deletions src/infinity/libraries/LibRetire.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {LibMeta} from "./LibMeta.sol";
import "./Bridges/LibToucanCarbon.sol";
import "./Bridges/LibMossCarbon.sol";
import "./Bridges/LibC3Carbon.sol";
import "./Bridges/LibCMARKCarbon.sol";
import "./Bridges/LibICRCarbon.sol";
import "./Bridges/LibCoorestCarbon.sol";
import "./Token/LibTransfer.sol";
Expand Down Expand Up @@ -304,14 +305,6 @@ library LibRetire {
details
);
} else if (LibCMARKCarbon.isValid(creditToken)) {
RetireDetails memory details;

details.retiringAddress = retiringAddress;
details.retiringEntityString = retiringEntityString;
details.beneficiaryAddress = beneficiaryAddress;
details.beneficiaryString = beneficiaryString;
details.retirementMessage = retirementMessage;

// Retire the carbon
LibCMARKCarbon.retireCMARK(
address(0), // Direct retirement, no pool token
Expand Down
11 changes: 5 additions & 6 deletions test/infinity/Bridge/CMARK.RetireCMARK.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {console2} from "../../../lib/forge-std/src/console2.sol";
import "../TestHelper.sol";
import "../../helpers/AssertionHelper.sol";

contract RetireICRICCFacetTest is TestHelper, AssertionHelper {
contract RetireCMARKFacetTest is TestHelper, AssertionHelper {
event CarbonRetired(
LibRetire.CarbonBridge carbonBridge,
address indexed retiringAddress,
Expand Down Expand Up @@ -43,17 +43,16 @@ contract RetireICRICCFacetTest is TestHelper, AssertionHelper {
function setUp() public {
addConstantsGetter(diamond);
constantsFacet = ConstantsGetter(diamond);
retireICRFacet = RetireICRFacet(diamond);
retireCMARKFacet = RetireCMARKFacet(diamond);
quoterFacet = RetirementQuoter(diamond);

upgradeCurrentDiamond(diamond);
}

function test_infinity_cmarkRetireExactCMARK() public {
function test_infinity_cmarkRetireExactCarbon() public {
uint256 tokenId = 1; // TODO: decide how to set this
uint256 retireAmount = 100e18;
mintERC20Tokens(CMARK, retireAmount, address(this));

swipeERC20Tokens(CMARK, defaultCarbonRetireAmount, CMARK, address(this));
IERC20(CMARK).setApprovalForAll(diamond, true);

uint256 currentRetirements = LibRetire.getTotalRetirements(beneficiaryAddress);
Expand All @@ -79,7 +78,7 @@ contract RetireICRICCFacetTest is TestHelper, AssertionHelper {
defaultCarbonRetireAmount
);

uint256 retirementIndex = retireICRFacet.icrRetireExactCarbon(
uint256 retirementIndex = retireCMARKFacet.cmarkRetireExactCarbon(
CMARK,
tokenId,
defaultCarbonRetireAmount,
Expand Down

0 comments on commit 2db7810

Please sign in to comment.