Investa-Farm / investafarm-canisters

Backend canisters for investa farm
https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=4c3lo-haaaa-aaaam-adi5q-cai
0 stars 0 forks source link

ckUSDC Payments Section #39

Open Stephen-Kimoi opened 4 months ago

Stephen-Kimoi commented 4 months ago

Implementation of ckUSDC Payments:

Here's the link to the official documentation: Link

Here's the dashboard for ckUSDC canister: Link

Documentation on how to use ckUSDC token in dApps: Link

Testing purposes: We'll be implementing the sepolia version of ckUSDC for now. Link

Faucet for obtaining sepolia USDC - Link

Use the ckSepoliaETH minter canister (jzenf-aiaaa-aaaar-qaa7q-cai) to mint ckSepoliaETH. You need ckSepoliaETH before you can deposit Sepolia USDC and mint ckUSDC.

Finally, we'll use the ckSepoliaETH minter canister again to convert ckSepoliaETH into ckUSDC. You can use the get_minter_info method on the minter canister dashboard to retrieve all supported ckERC20 tokens.

Full instructions in the ckETH GitHub.

Dfinity Forum discussion

Implementation walkthrough: Obtain sepolia USDC from the faucet - Link

Sepolia USDC contract address - Link

ckSepoliaUSDC helper contract - Link

Official documentation of cKERC-20 on GitHub - Link

(New) ckERC-20 Helper Smart Contract - Link

Please note that you can also invoke the get_minter_info 18 on the Sepolia minter dashboard to get all ids and ckERC20 tokens supported.

ckERC-20 GitHub Documentation - Link

ckUSDC Links: ckUSDC Helper Contract (Ethereum) - Link

USDC Ethereum Mainnet Contract - Link

Important things to note from the documentation:

The ERC-20 → ckERC-20 flow involves the following steps:

  1. The user submits an Ethereum transaction calling the approve function of the ERC-20 smart contract to allow the helper smart contract address to use some of the user’s funds. The approve function can be invoked directly on the contract’s Etherscan page after connecting any of Web3-capable wallets.

  2. The user calls the minter helper contract deposit method of the helper smart contract (just as approve this method can be called from contract’s Etherscan page) specifying

    • The ERC-20 smart contract address. This identifies the ERC-20 token being deposited.
    • The amount of ERC-20 tokens being deposited.
    • The IC principal to which the amount of ckERC-20 should be minted.
  3. The helper smart contract does the following steps within the same Ethereum transaction

    • Call transferFrom on the ERC-20 smart contract to transfer the given amount of ERC-20 tokens from the user’s address to the minter’s address. (This requires that the smart contract’s address was previously approved as in step 2).
    • Emits the ReceiveErc20(address,address,uint,bytes32) event I) The first address argument is the ERC-20 smart contract Ethereum address. II) The second address argument is the source Ethereum address. III) The uint argument is the deposit value. IV) The bytes32 argument encodes the receiver of ckERC20 on the IC.
  4. The scrapping of the logs will be done as in ckETH, meaning that ckETH minter executes the following steps on a timer:

For each new event, if the transactionHash was not seen before (minter keeps track of minted transactions), check that the sender of the transaction is not on the blocklist and mint ckERC20 and include the transaction hash and the log entry index in the ckERC-20 mint transaction memo (ICRC-1 ledger feature). Add the transactionHash to the list of seen transactions kept by the minter. If the sender of the transaction was a blocked address, then the minter does not mint ckERC20, but still marks the transaction hash as seen.

Example 1. Deposit of Sepolia USDC → ckSepoliaUSDC: