KlimaRetirementAggregator

Git Source

Inherits: Initializable, ContextUpgradeable, OwnableUpgradeable

Author: KlimaDAO

This is the master aggregator contract for the Klima retirement utility. This allows a user to provide a source token and an approved carbon pool token to retire. If the source is different than the pool, it will attempt to swap to that pool then retire.

State Variables

KLIMA

=== State Variables and Mappings ===

address public KLIMA;

sKLIMA

address public sKLIMA;

wsKLIMA

address public wsKLIMA;

USDC

address public USDC;

staking

address public staking;

stakingHelper

address public stakingHelper;

treasury

address public treasury;

klimaRetirementStorage

address public klimaRetirementStorage;

isPoolToken

mapping(address => bool) public isPoolToken;

poolBridge

mapping(address => uint256) public poolBridge;

bridgeHelper

mapping(uint256 => address) public bridgeHelper;

INFINITY

address public constant INFINITY = 0x8cE54d9625371fb2a068986d32C85De8E6e995f8;

Functions

initialize

function initialize() public initializer;

retireCarbon

=== Non Specific Auto Retirements

This function will retire a carbon pool token that is held in the caller's wallet. Depending on the pool provided the appropriate retirement helper will be used as defined in the bridgeHelper mapping. If a token other than the pool is provided then the helper will attempt to swap to the appropriate pool and then retire.

function retireCarbon(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage
) 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.

retireCarbon

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

retireCarbonFrom

This function will retire a carbon pool token that has been transferred to this contract. Useful when an intermediary contract has approval to transfer the source tokens from the initiator. Depending on the pool provided the appropriate retirement helper will be used as defined in the bridgeHelper mapping. If a token other than the pool is provided then the helper will attempt to swap to the appropriate pool and then retire.

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

Parameters

NameTypeDescription
_initiatoraddressThe original sender of the transaction.
_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.

_retireCarbon

Internal function that checks to make sure the needed source tokens have been transferred to this contract, then calls the retirement function on the bridge's specific helper contract.

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

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.
_retireeaddressAddress of the initiator where source tokens originated.

_retireCarbon

function _retireCarbon(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    string memory _retireEntityString,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    address _retiree
) internal;

retireCarbonSpecific

=== Specific offset selection retirements ===

This function will retire a carbon pool token that is held in the caller's wallet. Depending on the pool provided the appropriate retirement helper will be used as defined in the bridgeHelper mapping. If a token other than the pool is provided then the helper will attempt to swap to the appropriate pool and then retire.

function retireCarbonSpecific(
    address _sourceToken,
    address _poolToken,
    uint256 _amount,
    bool _amountInCarbon,
    address _beneficiaryAddress,
    string memory _beneficiaryString,
    string memory _retirementMessage,
    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.
_carbonListaddress[]

retireCarbonSpecific

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

retireCarbonSpecificFrom

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

_retireCarbonSpecific

Internal function that checks to make sure the needed source tokens have been transferred to this contract, then calls the retirement function on the bridge's specific helper contract.

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

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.
_retireeaddressAddress of the initiator where source tokens originated.
_carbonListaddress[]

_retireCarbonSpecific

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

_prepareRetireSpecific

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

getSourceAmount

=== External views and helpful functions ===

This function calls the appropriate helper for a pool token and returns the total amount in source tokens needed to perform the transaction. Any swap slippage buffers and fees are included in the return value.

function getSourceAmount(address _sourceToken, address _poolToken, uint256 _amount, bool _amountInCarbon)
    public
    view
    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.

Returns

NameTypeDescription
<none>uint256Returns both the source amount and carbon amount as a result of swaps.
<none>uint256

getSourceAmountSpecific

Same as getSourceAmount, but factors in the redemption fee for specific retirements.

function getSourceAmountSpecific(address _sourceToken, address _poolToken, uint256 _amount, bool _amountInCarbon)
    public
    view
    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.

Returns

NameTypeDescription
<none>uint256Returns both the source amount and carbon amount as a result of swaps.
<none>uint256

setAddress

Allow the contract owner to update Klima protocol addresses resulting from possible migrations.

function setAddress(uint256 _selection, address _newAddress) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_selectionuint256Int to indicate which address is being updated.
_newAddressaddressNew address for contract needing to be updated.

Returns

NameTypeDescription
<none>boolbool

addPool

Add a new carbon pool to retire with helper contract.

function addPool(address _poolToken, uint256 _poolBridge) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_poolTokenaddressPool being added.
_poolBridgeuint256Int ID of the bridge used for this token.

Returns

NameTypeDescription
<none>boolbool

removePool

Remove a carbon pool to retire.

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

Parameters

NameTypeDescription
_poolTokenaddressPool being removed.

Returns

NameTypeDescription
<none>boolbool

setBridgeHelper

Set the helper contract to be used with a carbon bridge.

function setBridgeHelper(uint256 _bridgeID, address _helper) external onlyOwner returns (bool);

Parameters

NameTypeDescription
_bridgeIDuint256Int ID of the bridge.
_helperaddressHelper contract to use with this bridge.

Returns

NameTypeDescription
<none>boolbool

feeWithdraw

Allow withdrawal of any tokens sent in error

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

Parameters

NameTypeDescription
_tokenaddressAddress of token to transfer
_recipientaddress

Events

AddressUpdated

=== Event Setup ===

event AddressUpdated(uint256 addressIndex, address indexed oldAddress, address indexed newAddress);

PoolAdded

event PoolAdded(address poolToken, uint256 bridge);

PoolRemoved

event PoolRemoved(address poolToken);

BridgeHelperUpdated

event BridgeHelperUpdated(uint256 bridgeID, address helper);