bosagora / zkagora-simple-contract

MIT License
0 stars 0 forks source link

ETH and ERC20 deposit(L1 to L2) and withdraw(L2 to L1) #8

Open she110ff opened 1 year ago

she110ff commented 1 year ago

L1ERC20Bridge, L2ERC20Bridge 의 연동에 파악한다.

Deposit ERC20

L1ERC20Bridge

  1. deposit > _depositFunds > _token.safeTransaction
  2. zkSync.requestL2Transaction
  3. DepositInitiated event

L2ERC20Bridge

  1. finalizeDeposit > l2TokenAddress
  2. IL2StandardToken(expectedL2Token).bridgeMint
  3. FinalizeDeposit event

-l1 token address 를 salt 로 사용하는 create2 를 사용하여 standardToken 을 배포한다. -생성된 주소는 provider.l2TokenAddress 를 통해 얻을 수 있다.

web3 사용 예

https://era.zksync.io/docs/api/js/accounts-l1-l2.html#inputs-and-outputs

const usdcDepositHandle = await wallet.deposit({
  token: USDC_ADDRESS,
  amount: "10000000",
  approveERC20: true,
});
await usdcDepositHandle.wait();

Deposit ETH

approve 과정 또는 플래그가 필요하지 않으며, utils.ETH_ADDRESS 를 사용하는 것을 제외하면 토큰 deposit과 동일하다.

Withdraw ERC20, ETH

  const withdrawL2 = await wallet.withdraw({
    to: wallet.address,
    token: l2FunToken,
    amount: ethers.utils.parseEther("1"),
  });

  // Wait until the deposit is processed on zkSync
  const receipt = await withdrawL2.waitFinalize();
  console.log('receipt.transactionHash :', receipt.transactionHash);
  await wallet.finalizeWithdrawal( receipt.transactionHash );