Voucher

Function definitions, parameter descriptions, and use cases of the APIs of IcToken smart contract.

mint

Function Definition

function mint(uint64 term, uint256 amount, uint64[] calldata maturities, uint32[] calldata percentages, string memory originalInvestor) external returns (uint256, uint256);

Input Parameters

Parameter
Type
Note
term
uint64
Release term: One-time release type: fixed at 0; Linear and Staged release type: duration in seconds from start to end of release
amount
uint256
Amount of assets (ERC20) to be locked up
maturities
uint64[]
Timestamp of each release time node
percentages
uint32[]
Release percentage of each release time node
originalInvestor
string
Note indicating the original invester

Note:

  • Lengths of maturities and percentages must be equal;
  • The precision of the release percentage is 0.01% (i.e., a value of 10000 means 100%). Thus, the sum of all elements of percentages must be equal to 10000;
  • For Staged release type, the value of term must be equal to the time difference between the first and the last release time node;
  • The corresponding ERC20 token should be approved to the IcToken contract before mint.

Output Parameters

Parameter
Type
Note
slot
uint256
Slot of the minted Voucher
tokenId
uint256
Id of the minted Voucher

Use Cases

Use Cases in Solidity

  • Linear Release Type
    uint64 term = 86400 * 30;
    uint256 amount = 1000000000000000000;
    uint64[] memory maturities;
    maturities[0] = uint64(block.timestamp + 86400 * 60);
    uint32[] memory percentages;
    percentages[0] = 10000;
    string memory originalInvestor = "investor";
    icToken.mint(term, amount, maturities, percentages, originalInvestor);
  • One-time Release Type
    uint64 term = 0;
    uint256 amount = 1000000000000000000;
    uint64[] memory maturities;
    maturities[0] = uint64(block.timestamp + 86400 * 30);
    uint32[] memory percentages;
    percentages[0] = 10000;
    string memory originalInvestor = "investor";
    icToken.mint(term, amount, maturities, percentages, originalInvestor);
  • Staged Release Type
    uint64 term = 86400 * 60;
    uint256 amount = 1000000000000000000;
    uint64[] memory maturities;
    maturities[0] = uint64(block.timestamp + 86400 * 30);
    maturities[1] = uint64(block.timestamp + 86400 * 60);
    maturities[2] = uint64(block.timestamp + 86400 * 90);
    uint32[] memory percentages;
    percentages[0] = 3000;
    percentages[1] = 3000;
    percentages[2] = 4000;
    string memory originalInvestor = "investor";
    icToken.mint(term, amount, maturities, percentages, originalInvestor);

Use Cases with ethers.js

  • Linear Release Type
    let now = (await wallet.provider.getBlock()).timestamp;
    let term = 86400 * 30;
    let amount = 1000000000000000000n;
    let maturities = [now + 86400 * 60];
    let percentages = [10000];
    let originalInvestor = "investor";
    await icToken.mint(term, amount, maturities, percentages, originalInvestor);
  • One-time Release Type
    let now = (await wallet.provider.getBlock()).timestamp;
    let term = 0;
    let amount = 1000000000000000000n;
    let maturities = [now + 86400 * 30];
    let percentages = [10000];
    let originalInvestor = "investor";
    await icToken.mint(term, amount, maturities, percentages, originalInvestor);
  • Staged Release Type
    let now = (await wallet.provider.getBlock()).timestamp;
    let term = 86400 * 60;
    let amount = 1000000000000000000n;
    let maturities = [now + 86400 * 30, now + 86400 * 60, now + 86400 * 90];
    let percentages = [3000, 3000, 4000];
    let originalInvestor = "investor";
    await icToken.mint(term, amount, maturities, percentages, originalInvestor);

claim

Function Definition

Claim specified amount of assets of target Voucher.
function claim(uint256 tokenId, uint256 amount) external;

Input Parameters

Parameter
Type
Note
tokenId
uint256
Id of the Voucher to claim
amount
uint256
Amount of assets (ERC20) to claim

Use Cases

Use Cases in Solidity

uint256 tokenId = 101;
uint256 claimAmount = 500000000000000000;
icToken.claim(tokenId, claimAmount);

Use Cases with ethers.js

let tokenId = 101;
let amount = 500000000000000000n;
await icToken.claim(tokenId, amount);

claimAll

Claim All underlying assets of target Voucher.

Function Definition

function claimAll(uint256 tokenId) external;

Input Parameters

Parameter
Type
Note
tokenId
uint256
Id of the Voucher to claim

Use Cases

Use Cases in Solidity

uint256 tokenId = 101;
icToken.claimAll(tokenId);

Use Cases with ethers.js

let tokenId = 101;
await icToken.claimAll(tokenId);

claimableAmount

Function Definition

Query the released amount of the underlying assets.
function claimableAmount(uint256 tokenId) external view returns(uint256);

Input Parameters

Parameter
Type
Note
tokenId
uint256
Id of the Voucher to query

Output Parameters

Parameter
Type
Note
claimableAmount
uint256
Released amount of the underlying assets

Use Cases

Use Cases in Solidity

uint256 tokenId = 101;
uint256 amount = icToken.claimableAmount(tokenId);

Use Cases with ethers.js

let tokenId = 101;
let amount = await icToken.claimableAmount(tokenId);

transferFrom (transfer all)

Function Definition

function transferFrom(address from, address to, uint256 tokenId) public;

Input Parameters

Parameter
Type
Note
from
address
Address of the Voucher sender
to
address
Address of the Voucher recipient
tokenId
uint256
Id of the Voucher to transfer

Use Cases

Use Cases in Solidity

address from = 0x9a837E6d6fA9aA9Ee1DbBb7e260c38c7943A015F;
address to = 0xabcdE6D60F48cBE31202C766BbB0EE16AD0b47FF;
uint256 tokenId = 101;
icToken.transferFrom(from, to, tokenId);

Use Cases with ethers.js

let from = "0xabcdE6D60F48cBE31202C766BbB0EE16AD0b47FF";
let to = "0x9a837E6d6fA9aA9Ee1DbBb7e260c38c7943A015F";
let tokenId = 101;
await icToken.transferFrom(from, to, tokenId);

transferFrom (partial transfer)

Function Definition

function transferFrom(address from, address to, uint256 tokenId, uint256 transferUnits) public returns (uint256 newTokenId);

Input Parameters

Parameter
Type
Note
from
address
Address of the Voucher sender
to
address
Address of the Voucher recipient
tokenId
uint256
Id of the Voucher to transfer
transferUnits
uint256
Amount of units to transfer

Output Parameters

Parameter
Type
Note
newTokenId
uint256
Id of the Voucher created after transfer

Use Cases

Use Cases in Solidity

address from = 0x9a837E6d6fA9aA9Ee1DbBb7e260c38c7943A015F;
address to = 0xabcdE6D60F48cBE31202C766BbB0EE16AD0b47FF;
uint256 tokenId = 101;
uint256 units = 100000000000000000;
icToken.transferFrom(from, to, tokenId, units);

Use Cases with ethers.js

let from = "0xabcdE6D60F48cBE31202C766BbB0EE16AD0b47FF";
let to = "0x9a837E6d6fA9aA9Ee1DbBb7e260c38c7943A015F";
let tokenId = 101;
let units = 100000000000000000n;
await icToken.transferFrom(from, to, tokenId, units);

setApprovalForAll

Function Definition

function setApprovalForAll(address operator, bool approved) public;

Input Parameters

Parameter
Type
Note
operator
address
Address to be authorized
approved
bool
Whether to approve all Vouchers to operator

Use Cases

Use Cases in Solidity

address operator = 0xabcdE6D60F48cBE31202C766BbB0EE16AD0b47FF;
icToken.setApprovalForAll(operator, true);

Use Cases with ethers.js

let operator = "0x9a837E6d6fA9aA9Ee1DbBb7e260c38c7943A015F";
let approved = true;
await icToken.setApprovalForAll(operator, approved);