vUSD

On this page, you can find the contracts and their interactions involved when bridging to and from Ethereum (L1 - $DAI/$USDC/$USDT) and Cronos zkEVM (L2 - $vUSD ), it includes:

[L2 -> L1] Withdrawing $DAI from $vUSD

[L2 -> L1] Withdrawing $DAI from $vUSD

From Cronos zkEVM mainnet (L2) -> Ethereum mainnet (L1)

For withdrawing $vUSD (Cronos zkEVM Mainnet) and get $DAI (Ethereum Mainnet) , we would need to:

  1. [On Cronos zkEVM] Use $vUSD to redeem $ybUSD;

  2. [On Cronos zkEVM] Bridge $ybUSD to Ethereum;

  3. [On Ethereum] Redeem $ybUSD for $DAI

To redeem $vUSD from Cronos zkEVM mainnet -> Ethereum mainnet, and withdraw $DAI we would need to interact with the following contracts:

Step 1) Approving $vUSD to be spend by vUSD contract

On Cronos zkEVM, call approve on the $vUSD contract to approve $vUSD spend with appropriate amount.

Step 2) Redeeming $vUSD for $ybUSD

On Cronos zkEVM, call redeem on the vUSD contract, to burn $vUSD and redeem $ybUSD

Parameters
Comments

_receiver

Address to receive $ybUSD on Cronos zkEVM

_vUsdAmount

Amount of vUSD that will be burned to redeem $ybUSD

Once done, corresponding $ybUSD will be transfer to the _reciever address

Step 3) Approving $ybUSD to be spend by the L2Bridge

On Cronos zkEVM, call approve on the ybUSD contract, to approve L2Bridge contract to spend $ybUSD.

Step 4) Withdrawing $ybUSD and store withdrawal hash

On Cronos zkEVM, call withdraw on the L2Bridge contract

Parameters
Comments

_l1Receiver

Address on Ethereum to receive the token

_l2Token

The token to be withdrawn, the Cronos zkEVM contract address $ybUSD in this case.

_amount

amount of tokens to be withdrawn, note $ybUSD has 18 decimals

Keep the transaction hash for later use in Step 5. This withdraws $ybUSD from Cronos zkEVM to Ethereum. It takes 24 hours before the withdrawal can be finalized on Ethereum. Store the transaction hash from the withdrawal transaction; it will be needed to finalize the withdrawal.

Step 5) Gathering information for $ybUSD withdrawal on L1

Extra information for the L2 -> L1 transaction is required for the next step in claiming the $ybUSD. This information can be gathered by finalizeWithdrawalParams, using zksync-ethers package

This takes the L2 withdrawal hash as parameters and returns the parameters required for finalizing a withdrawal in the next step.

Example outputs

Step 6) Claiming the $ybUSD on L1

Once the transaction in Step 4 has been finalized, we can claim the withdrawn $ybUSD from the L2Bridge contract by calling its finalizeWithdrawal function. The inputs can be found in Step 5,

Parameters
Comments

_chainId

Chain id for Cronos zkEVM, which is 388

_l2BatchNumber

The L2 batch number where the withdrawal was processed, obtained in Step 5.

_l2MessageIndex

The position in the L2 logs Merkle tree of the l2Log that was sent with the message, obtained in Step 5.

_l2TxNumberInBatch

The L2 transaction number in the batch, in which the log was sent, obtained in Step 5.

_message

The L2 withdraw data, stored in an L2 -> L1 message, obtained in Step 5.

_merkleProof

The Merkle Proof, obtained in Step 5.

Once finalizeWithdrawal is completed, the withdrawn amount of $ybUSD will go into the receiver's wallet on Ethereum.

We can use zksync-ethers package isWithdrawalFinalized call to whether the withdrawal transaction is finalized on the L1 network.

Parameters
Comments

withdrawalHash

The transaction hash of the L2 transaction includes the withdrawal transaction from Step 4

Step 7) Approving $ybUSD to be spend by ybUSD contract

On Ethereum, call approve on the $ybUSD contract, to approve the contract to spend $ybUSD

Step 8) Redeem $ybUSD for $DAI

On Ethereum, call redeem on the the $ybUSD contract

Parameters
Comments

_amount

The amount of $ybUSD tokens to redeem for $DAI

Once redeem is completed, the withdrawn amount of $DAI will go into the receiver's wallet on Ethereum.

Last updated