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:

[L1 -> L2] Minting $vUSD with $DAI/$USDC/$USDT

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

circle-info

The following instructions cover bridging and minting $vUSD with $DAI, $USDC, or $USDT deposits on L1.

Note that the contracts are based on $DAI. $USDC or $USDT deposits will be swapped to $DAI during the deposit process. Check Step 2) Minting And Bridging $ybUSD for details and parameters.


[L1 -> L2] Minting $vUSD with $DAI/$USDC/$USDT

From Ethereum mainnet (L1) to Cronos zkEVM mainnet (L2)

circle-info

For bridging $DAI/$USDC/$USDT (Ethereum Mainnet) to $vUSD (Cronos zkEVM Mainnet), we would need to:

  1. Mint and bridge $ybUSD from Ethereum to Cronos zkEVM Mainnet with $DAI/$USDC/$USDT;

  2. Mint $vUSD with $ybUSD on Cronos zkEVM Mainnet.

To bridge $DAI/$USDC/$USDT from Ethereum mainnet -> Cronos zkEVM mainnet, and obtain $vUSD we would need to interact with:

Step 1) Calculating the amount of $ybUSD to Bridge

On Ethereum, use ybUSD token contract to call the convertToShares function:

Parameters
Comments

daiAmount

The amount of $DAI (with 18 decimals) to be used to mint $ybUSD.

Keep this amount for later steps.

Step 2) Minting And Bridging $ybUSD

On Ethereum, call the mintAndBridge function on the ybUSDBridgecontract:

Parameters
Comments

_l2Receiver

The address on Cronos zkEVM that will receive $ybUSD

_amount

The amount of DAI/(USDC/USDT will be swapped to DAI) to deposit into the $ybUSD contract, in their corresponding decimals ( 18 for $DAI, 6 for $USDC and USDT )

_stableCoinType

Set 0 for $DAI, 1 for $USDC, 2 for $USDT

_minAmountAccepted

Minimum amount accepted when swapping USDC/USDT to DAI

_l2Gaslimit

Maximum amount of L2 gas that transaction can consume during execution on L2. Reference value: 500,000

_l2GasPerPubdataByteLimit

The maximum amount of L2 gas that the operator may charge the user for a single byte of pubdata. Reference value: 800

_refundRecipient

Address to collect refund, if bridging is unsuccessful.

This will mint $ybUSD on Ethereum and bridge it to the _l2Receiver address on L2.

Step 3) Approving $ybUSD to be spend by $vUSD contract

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

Step 4) Minting of $vUSD

On Cronos zkEVM, call mint on $vUSD contract , to mint $vUSD

Parameters
Comments

_receiver

Address to receive the minted $vUSD tokens

_ybUsdAmount

Amount of $ybUSD to be used to mint $vUSD

This will mint $vUSD into the _receiver address.


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

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

circle-info

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 finalizeWithdrawalParamsarrow-up-right, 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 isWithdrawalFinalizedarrow-up-right 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