RetireC3Carbon

Git Source

Inherits: Initializable, ContextUpgradeable, OwnableUpgradeable

State Variables

feeAmount

=== State Variables and Mappings ===

feeAmount represents the fee to be bonded for KLIMA. 0.1% increments. 10 = 1%

uint256 public feeAmount;

masterAggregator

address public masterAggregator;

tridentRouter

address public tridentRouter;

bento

address public bento;

isPoolToken

mapping(address => bool) public isPoolToken;

poolRouter

mapping(address => address) public poolRouter;

tridentPool

mapping(address => address) public tridentPool;

Functions

initialize

function initialize() public initializer;

retireC3

=== Free Redeem and Offset Functions ===

This function transfers source tokens if needed, swaps to the C3 pool token, utilizes freeRedeem, then retires the redeemed C3T. Needed source token amount is expected to be held by the caller to use.

function retireC3(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    address _retiree
) public;

Parameters

NameTypeDescription
_sourceTokenaddressThe contract address of the token being supplied.
_poolTokenaddressThe contract address of the pool token being retired.
_amountuint256The amount being supplied. Expressed in either the total carbon to offset or the total source to spend. See _amountInCarbon.
_amountInCarbonboolBool indicating if _amount is in carbon or source.
_beneficiaryAddressaddressAddress of the beneficiary of the retirement.
_beneficiaryStringstringString representing the beneficiary. A name perhaps.
_retirementMessagestringSpecific message relating to this retirement event.
_retireeaddressThe original sender of the transaction.

_retireCarbon

Redeems the pool and retires the C3T tokens on Polygon. Emits a retirement event and updates the KlimaCarbonRetirements contract with retirement details and amounts.

function _retireCarbon(
    uint256 _totalAmount,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    address _poolToken
) internal;

Parameters

NameTypeDescription
_totalAmountuint256Total pool tokens being retired. Expected uint with 18 decimals.
_beneficiaryAddressaddressAddress of the beneficiary if different than sender. Value is set to _msgSender() if null is sent.
_beneficiaryStringstringString that can be used to describe the beneficiary
_retirementMessagestringString for specific retirement message if needed.
_poolTokenaddressAddress of pool token being used to retire.

retireC3Specific

=== Taxed Redeem and Offset Functions ===

This function transfers source tokens if needed, swaps to the C3 pool token, utilizes taxedRedeem, then retires the redeemed C3T. Needed source token amount is expected to be held by the caller to use.

function retireC3Specific(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    address _retiree,
    address[] memory _carbonList
) public;

Parameters

NameTypeDescription
_sourceTokenaddressThe contract address of the token being supplied.
_poolTokenaddressThe contract address of the pool token being retired.
_amountuint256The amount being supplied. Expressed in either the total carbon to offset or the total source to spend. See _amountInCarbon.
_amountInCarbonboolBool indicating if _amount is in carbon or source.
_beneficiaryAddressaddressAddress of the beneficiary of the retirement.
_beneficiaryStringstringString representing the beneficiary. A name perhaps.
_retirementMessagestringSpecific message relating to this retirement event.
_retireeaddressThe original sender of the transaction.
_carbonListaddress[]List of C3Ts to redeem

_prepareRetireSpecific

This function is mainly used to avoid stack too deep. It performs the initial transfer and swap to the pool token for a specific retirement.

function _prepareRetireSpecific(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    address _retiree
) internal returns (uint256, uint256);

Parameters

NameTypeDescription
_sourceTokenaddressThe contract address of the token being supplied.
_poolTokenaddressThe contract address of the pool token being retired.
_amountuint256The amount being supplied. Expressed in either the total carbon to offset or the total source to spend. See _amountInCarbon.
_amountInCarbonboolBool indicating if _amount is in carbon or source.
_retireeaddressThe original sender of the transaction. To return trade dust.

Returns

NameTypeDescription
<none>uint256(uint256, uint256) tuple for the amount to pass to redeem and retire, and the aggregator fee.
<none>uint256

_retireCarbonSpecific

Redeems the pool and retires the C3T tokens on Polygon. Emits a retirement event and updates the KlimaCarbonRetirements contract with retirement details and amounts.

function _retireCarbonSpecific(
    uint256 _totalAmount,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    address _poolToken,
    address[] memory _carbonList
) internal;

Parameters

NameTypeDescription
_totalAmountuint256Total pool tokens being retired. Expected uint with 18 decimals.
_beneficiaryAddressaddressAddress of the beneficiary if different than sender. Value is set to _msgSender() if null is sent.
_beneficiaryStringstringString that can be used to describe the beneficiary
_retirementMessagestringString for specific retirement message if needed.
_poolTokenaddressAddress of pool token being used to retire.
_carbonListaddress[]List of C3T tokens to redeem

_transferSourceTokens

=== Internal helper functions ===

Transfers the needed source tokens from the caller to perform any needed swaps and then retire the tokens.

function _transferSourceTokens(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    bool _specificRetire
) internal returns (uint256, uint256, uint256);

Parameters

NameTypeDescription
_sourceTokenaddressThe contract address of the token being supplied.
_poolTokenaddressThe contract address of the pool token being retired.
_amountuint256The amount being supplied. Expressed in either the total carbon to offset or the total source to spend. See _amountInCarbon.
_amountInCarbonboolBool indicating if _amount is in carbon or source.
_specificRetirebool

_stakedToUnstaked

Unwraps/unstakes any KLIMA needed to regular KLIMA.

function _stakedToUnstaked(address _klimaType, uint256 _amountIn) internal returns (uint256);

Parameters

NameTypeDescription
_klimaTypeaddressAddress of the KLIMA type being used.
_amountInuint256Amount of total KLIMA needed.

Returns

NameTypeDescription
<none>uint256Returns the total number of KLIMA after unwrapping/unstaking.

_swapForExactCarbon

Swaps the source token for an exact number of carbon tokens, and returns any dust to the initiator.

This is only called if the _amountInCarbon bool is set to true.

function _swapForExactCarbon(
    address _sourceToken,
    address _poolToken,
    uint256 _carbonAmount,
    uint256 _amountIn,
    address _retiree
) internal;

Parameters

NameTypeDescription
_sourceTokenaddressAddress of token being used to purchase the pool token.
_poolTokenaddressAddress of pool token being used.
_carbonAmountuint256Total carbon needed.
_amountInuint256Maximum amount of source tokens.
_retireeaddressInitiator of the retirement to return any dust.

_swapExactForCarbon

Swaps an exact number of source tokens for carbon tokens.

This is only called if the _amountInCarbon bool is set to false.

function _swapExactForCarbon(address _sourceToken, address _poolToken, uint256 _amountIn)
    internal
    returns (uint256, uint256);

Parameters

NameTypeDescription
_sourceTokenaddressAddress of token being used to purchase the pool token.
_poolTokenaddressAddress of pool token being used.
_amountInuint256Total source tokens to swap.

Returns

NameTypeDescription
<none>uint256Returns the resulting carbon amount to retire and the fee from the results of the swap.
<none>uint256

_returnTradeDust

Returns any trade dust to the designated address. If sKLIMA or wsKLIMA was provided as a source token, it is re-staked and/or wrapped before transferring back.

function _returnTradeDust(uint256[] memory _amounts, address _sourceToken, uint256 _amountIn, address _retiree)
    internal;

Parameters

NameTypeDescription
_amountsuint256[]The amounts resulting from the Uniswap tradeTokensForExactTokens.
_sourceTokenaddressAddress of token being used to purchase the pool token.
_amountInuint256Total source tokens initially provided.
_retireeaddressAddress where to send the dust.

_getSpecificCarbonFee

Gets the fee amount for a carbon pool and returns the value.

function _getSpecificCarbonFee(address _poolToken, uint256 _poolAmount, bool _amountInCarbon)
    internal
    view
    returns (uint256);

Parameters

NameTypeDescription
_poolTokenaddressAddress of pool token being used.
_poolAmountuint256Amount of tokens being retired.
_amountInCarbonboolBool indicating if _amount is in carbon or source.

Returns

NameTypeDescription
<none>uint256poolFeeAmount Fee amount for specificly redeeming a ton.

getNeededBuyAmount

=== External views and helpful functions ===

Call the UniswapV2 routers for needed amounts on token being retired. Also calculates and returns any fee needed in the pool token total.

function getNeededBuyAmount(address _sourceToken, address _poolToken, uint256 _poolAmount, bool _specificRetire)
    public
    view
    returns (uint256, uint256);

Parameters

NameTypeDescription
_sourceTokenaddressAddress of token being used to purchase the pool token.
_poolTokenaddressAddress of pool token being used.
_poolAmountuint256Amount of tokens being retired.
_specificRetirebool

Returns

NameTypeDescription
<none>uint256Tuple of the total pool amount needed, followed by the fee.
<none>uint256

getSwapPath

This creates the path for UniswapV2 to get to KLIMA. A secondary swap will be performed in Trident to get the pool token.

This function will produce an invalid path if the source token does not have a direct USDC LP route on the pool's AMM. The resulting transaction would revert.

function getSwapPath(address _sourceToken, address _poolToken) public view returns (address[] memory);

Parameters

NameTypeDescription
_sourceTokenaddressAddress of token being used to purchase the pool token.
_poolTokenaddressAddress of pool token being used.

Returns

NameTypeDescription
<none>address[]Array of addresses to be used as the path for the swap.

setFeeAmount

=== Admin Functions ===

Set the fee for the helper

function setFeeAmount(uint256 _amount) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_amountuint256New fee amount, in .1% increments. 10 = 1%

Returns

NameTypeDescription
<none>boolbool

setPoolRouter

Update the router for an existing pool

function setPoolRouter(address _poolToken, address _router) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_poolTokenaddressPool being updated
_routeraddressNew router address

Returns

NameTypeDescription
<none>boolbool

addPool

Add a new carbon pool to retire with helper contract

function addPool(address _poolToken, address _router, address _tridentPool) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_poolTokenaddressPool being added
_routeraddressUniswapV2 router to route trades through for non-pool retirements
_tridentPooladdress

Returns

NameTypeDescription
<none>boolbool

removePool

Remove a carbon pool to retire with helper contract

function removePool(address _poolToken) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_poolTokenaddressPool being removed

Returns

NameTypeDescription
<none>boolbool

feeWithdraw

Allow withdrawal of any tokens sent in error

function feeWithdraw(address _token, address _recipient) public onlyOwner returns (bool);

Parameters

NameTypeDescription
_tokenaddressAddress of token to transfer
_recipientaddressAddress where to send tokens.

setMasterAggregator

Allow the contract owner to update the master aggregator proxy address used.

function setMasterAggregator(address _newAddress) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_newAddressaddressNew address for contract needing to be updated.

Returns

NameTypeDescription
<none>boolbool

setTrident

Allow the contract owner to update the SushiSwap Trident AMM addresses.

function setTrident(address _tridentRouter, address _bento) external onlyOwner;

Parameters

NameTypeDescription
_tridentRouteraddressNew address for Trident router.
_bentoaddressNew address for Bento Box.

Events

C3Retired

=== Event Setup ===

event C3Retired(
    address indexed retiringAddress,
    address indexed beneficiaryAddress,
    string beneficiaryString,
    string retirementMessage,
    address indexed carbonPool,
    address carbonToken,
    uint256 retiredAmount
);

PoolAdded

event PoolAdded(address indexed carbonPool, address indexed poolRouter, address indexed tridentPool);

PoolRemoved

event PoolRemoved(address indexed carbonPool);

PoolRouterChanged

event PoolRouterChanged(address indexed carbonPool, address indexed oldRouter, address indexed newRouter);

TridentChanged

event TridentChanged(
    address indexed oldBento, address indexed newBento, address indexed oldTrident, address newTrident
);

FeeUpdated

event FeeUpdated(uint256 oldFee, uint256 newFee);

MasterAggregatorUpdated

event MasterAggregatorUpdated(address indexed oldAddress, address indexed newAddress);