Skip to content

Latest commit

 

History

History
411 lines (245 loc) · 11.1 KB

disCarbonSwapAndRetire.md

File metadata and controls

411 lines (245 loc) · 11.1 KB

disCarbonSwapAndRetire

haurog, danceratopz

disCarbon generalized swap and retire contract

This contract exchanges the coins/tokens of the user for carbon tokens (NCT) and redeems them for an underlying project token and retires them. It also keeps track on the cumulative retirements of each address.

Methods

addDonation

function addDonation(uint256 carbonAmountToRetire, uint256 donationPercentage) external pure returns (uint256)

Calculates the amount of carbon tokens that need to be swapped including donations.

Parameters

Name Type Description
carbonAmountToRetire uint256 Carbon amount that needs to be retired.
donationPercentage uint256 The given donation percentage which needs to be added.

Returns

Name Type Description
_0 uint256 carbonAmountWithDonation How many carbon tokens need to be received from swap to have enough for the donation.

beneficiaryRetirements

function beneficiaryRetirements(address) external view returns (uint256)

The total amount of carbon retired by each beneficiary

Parameters

Name Type Description
_0 address undefined

Returns

Name Type Description
_0 uint256 undefined

calculateNeededAmount

function calculateNeededAmount(address fromToken, uint256 carbonAmountToRetire, uint256 donationPercentage, bool fees) external view returns (uint256)

Calculates the needed amount of coins/tokens. the swapped tokens.

Parameters

Name Type Description
fromToken address Address of the token that is used to swap from. To estimate Matic tokens, use WMATIC address.
carbonAmountToRetire uint256 Carbon Amount that needs to be purchased.
donationPercentage uint256 The given donation percentage 1 = 1%.
fees bool a boolean to include fees for specific project redemption in cost estimation

Returns

Name Type Description
_0 uint256 tokenAmountNeeded How many tokens/coins needed for buying the needed carbon tokens.

callerRetirements

function callerRetirements(address) external view returns (uint256)

The total amount of carbon retired by each address that has called this contract

Parameters

Name Type Description
_0 address undefined

Returns

Name Type Description
_0 uint256 undefined

donationAddress

function donationAddress() external view returns (address)

Address to where the donations are sent to

Returns

Name Type Description
_0 address undefined

getRetirementCallerAddresses

function getRetirementCallerAddresses() external view returns (address[])

A getter function for the array holding all addresses that have retired via this contract.

Returns

Name Type Description
_0 address[] retireeAddresses An array (can be empty) of all addresses that have retired.

getRetirementCallerCount

function getRetirementCallerCount() external view returns (uint256)

A function to get the number of addresses that have retired via this contract.

Returns

Name Type Description
_0 uint256 uint256 The length of the retireeAddresses array.

onERC721Received

function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external nonpayable returns (bytes4)

Required for use with safeTransferFrom() (from OpenZeppelin's ERC721 contract) used by Toucan's RetirementCertificates in order to transfer the ERC721 retirement certificates to this contract).

Parameters

Name Type Description
_operator address undefined
_from address undefined
_tokenId uint256 undefined
_data bytes undefined

Returns

Name Type Description
_0 bytes4 undefined

redemptionFee

function redemptionFee(uint256 carbonAmountToRetire) external view returns (uint256)

Calculates the redemptionFees that needs to be added to exactly redeem carbonAmountToRetire.

Parameters

Name Type Description
carbonAmountToRetire uint256 Carbon amount that needs to be retired.

Returns

Name Type Description
_0 uint256 undefined

retireAndMintCertificateWithMatic

function retireAndMintCertificateWithMatic(uint256 carbonAmountToRetire, uint256 donationPercentage, address beneficiaryAddress, string beneficiaryString, string retirementMessage) external payable returns (address[] tco2Addresses, uint256[] tco2Amounts, uint256[] tco2CertificateTokenIds)

Receives Matic, swaps to carbon token, retires the swapped tokens via autoRedeem2 and mints the retirement certificate. Forwards donations in carbon tokens. Returns any excess Matic.

Parameters

Name Type Description
carbonAmountToRetire uint256 The number of carbon tokens to be retired.
donationPercentage uint256 Donation as a percentage 1 = 1% added for donation.
beneficiaryAddress address The retirement beneficiary to specify in the retirement certificate.
beneficiaryString string The retirement beneficiary name to specify in the retirement certificate.
retirementMessage string The retirement message to specify in the retirement certificate.

Returns

Name Type Description
tco2Addresses address[] An array of the TCO2 addresses that were retired.
tco2Amounts uint256[] An array of the amounts of each TCO2 that was retired.
tco2CertificateTokenIds uint256[] An array of the corresponding retirement certificate ids.

retireAndMintCertificateWithToken

function retireAndMintCertificateWithToken(address fromToken, uint256 carbonAmountToRetire, uint256 donationPercentage, address beneficiaryAddress, string beneficiaryString, string retirementMessage) external nonpayable returns (address[] tco2Addresses, uint256[] tco2Amounts, uint256[] tco2CertificateTokenIds)

Takes a user approved token, swaps to carbon token, retires the swapped tokens via autoRedeem2 and mints the certificate. Forwards donations in carbon tokens. Only takes as many tokens as needed.

Parameters

Name Type Description
fromToken address Address of the erc20 token sent to buy carbon tokens with.
carbonAmountToRetire uint256 The number of carbon tokens to be retired.
donationPercentage uint256 Donation as a percentage 1 = 1% added for donation.
beneficiaryAddress address The retirement beneficiary to specify in the retirement certificate.
beneficiaryString string The retirement beneficiary name to specify in the retirement certificate.
retirementMessage string The retirement message to specify in the retirement certificate.

Returns

Name Type Description
tco2Addresses address[] An array of the TCO2 addresses that were retired.
tco2Amounts uint256[] An array of the amounts of each TCO2 that was retired.
tco2CertificateTokenIds uint256[] An array of the corresponding retirement certificate ids.

retireWithMatic

function retireWithMatic(uint256 carbonAmountToRetire, uint256 donationPercentage, address tco2Address) external payable returns (address[] tco2Addresses, uint256[] tco2Amounts)

Receives Matic, swaps to carbon token, retires the swapped tokens via autoRedeem2. Forwards donations in carbon tokens. Returns any excess Matic.

Parameters

Name Type Description
carbonAmountToRetire uint256 The number of carbon tokens to be retired.
donationPercentage uint256 Donation as a percentage 1 = 1% added for donation.
tco2Address address The TCO2 address to redeem and retire credits from. If address(0) is supplied it will redeem the default TCO2 in the pool.

Returns

Name Type Description
tco2Addresses address[] An array of the TCO2 addresses that were retired.
tco2Amounts uint256[] An array of the amounts of each TCO2 that was retired.

retireWithToken

function retireWithToken(address fromToken, uint256 carbonAmountToRetire, uint256 donationPercentage, address tco2Address) external nonpayable returns (address[] tco2Addresses, uint256[] tco2Amounts)

Takes a user approved token, swaps to carbon token, retires the swapped tokens via autoRedeem2. Forwards donations in carbon tokens. Only takes as many tokens as needed.

Parameters

Name Type Description
fromToken address Address of the erc20 token sent to buy carbon tokens with.
carbonAmountToRetire uint256 The number of carbon tokens to be retired.
donationPercentage uint256 Donation as a percentage 1 = 1% added for donation.
tco2Address address The TCO2 address to redeem and retire credits from. If address(0) is supplied it will redeem the default TCO2 in the pool.

Returns

Name Type Description
tco2Addresses address[] An array of the TCO2 addresses that were retired.
tco2Amounts uint256[] An array of the amounts of each TCO2 that was retired.

retirementBeneficiaryAddresses

function retirementBeneficiaryAddresses(uint256) external view returns (address)

An array of addresses that have been specified as retirement beneficiaries

Parameters

Name Type Description
_0 uint256 undefined

Returns

Name Type Description
_0 address undefined

retirementCallerAddresses

function retirementCallerAddresses(uint256) external view returns (address)

An array of addresses which have retired carbon by calling this contract

Parameters

Name Type Description
_0 uint256 undefined

Returns

Name Type Description
_0 address undefined

totalCarbonRetired

function totalCarbonRetired() external view returns (uint256)

The total amount of carbon retired via this contract

Returns

Name Type Description
_0 uint256 undefined

Events

CarbonRetired

event CarbonRetired(string tokenOrCoin, uint256 carbonAmountRetired)

Emitted after carbon tokens have been retired.

Parameters

Name Type Description
tokenOrCoin string undefined
carbonAmountRetired uint256 undefined

ERC721Received

event ERC721Received(address indexed sender, uint256 tokenId)

Emitted when an ERC721 is transferred to this retirement contract.

Parameters

Name Type Description
sender indexed address The address that sent the ERC721.
tokenId uint256 The ERC721 token ID sent.