Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
she110ff opened this issue Aug 8, 2023 · 1 comment
Open

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

she110ff opened this issue Aug 8, 2023 · 1 comment
Assignees

Comments

@she110ff
Copy link
Contributor

she110ff commented Aug 8, 2023

No description provided.

@she110ff she110ff self-assigned this Aug 8, 2023
@she110ff she110ff changed the title deposit ERC20 L1 to L2 deposit(L1 to L2) and withdraw(L2 to L1) ERC20 Aug 8, 2023
@she110ff
Copy link
Contributor Author

she110ff commented Aug 8, 2023

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 );
  • L2 토큰이 소각됩니다.
  • 출금에 대한 정보가 포함된 L2 -> L1 메시지가 전송됩니다.
  • 그 후, L1 브리지의 모든 사람이 출금 작업을 완료할 수 있습니다.(L1 브리지 컨트랙트에서 finalizeWithdrawal 메서드를 호출할 때 수행되는 L2 -> L1 메시지의 포함을 증명) - 증명에 대한 시간을 충분히 주기 위해 타임락 제공과 연관이 있음.
  • 메서드가 호출된 후 자금은 L1 브리지에서 잠금 해제되어 출금 수신자에게 전송됩니다.

@she110ff she110ff changed the title deposit(L1 to L2) and withdraw(L2 to L1) ERC20 ETH and ERC20 deposit(L1 to L2) and withdraw(L2 to L1) Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant