Skip to content

Commit

Permalink
Add eurc support
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Nov 4, 2024
1 parent fd2d31b commit fd987f7
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 8 deletions.
13 changes: 13 additions & 0 deletions scripts/usdc-bridge-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ CHILD_DEPLOYER_KEY=
L1_ROUTER=
L2_ROUTER=
INBOX=
## USDC (or EURC) address on the parent chain
L1_USDC=
## Naming params for the bridged token which is deployed to child chain. Values should be adjusted based on the parent chain and currency used
## Circle's naming guideline: https://brand.circle.com/d/M9z54TaEwsWL/stablecoins#/-/usdc-brand-guide/usdc-naming-guidelines
L2_TOKEN_NAME='USDC'
L2_TOKEN_SYMBOL='USDC.e'
L2_TOKEN_CURRENCY='USD'
## OPTIONAL arg. If set, script will register the gateway, otherwise it will store TX payload in a file
ROLLUP_OWNER_KEY=
```
Expand Down Expand Up @@ -80,3 +89,7 @@ Once transition to native USDC is agreed on, following steps are required:
- Circle calls `burnLockedUSDC()` on the L1 gateway using `burner` account to burn the `burnAmount` of USDC
- remaining USDC will be cleared off when remaining in-flight USDC withdrawals are executed, if any
- L1 gateway owner is trusted to not frontrun this TX to modify the burning amount

## EURC deployment

Circle also offers EURC stablecoin. This same standard implementation is applicable for EURC. There is no need to change anything, except to adjust the .env vars to provide EURC parent chain address instead of the USDC address and adjust the token naming vars (name, symbol, currency).
27 changes: 19 additions & 8 deletions scripts/usdc-bridge-deployment/deployUsdcBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ main().then(() => console.log('Done.'))
* - if `ROLLUP_OWNER_KEY` is provided, register the gateway in the router through the UpgradeExecutor
* - if `ROLLUP_OWNER_KEY` is not provided, prepare calldata and store it in `registerUsdcGatewayTx.json` file
* - set minter role to L2 USDC gateway with max allowance
*
* Note: Same implementation is used for bridged EURC (Circle's euro stablecoin). The only difference is in the
* name/symbol/currency of the L2 token deployment.
*/
async function main() {
console.log('Starting USDC bridge deployment')
Expand Down Expand Up @@ -184,30 +187,35 @@ async function _deployBridgedUsdc(
deployerL2Wallet
)

const tokenName = process.env['L2_TOKEN_NAME'] as string
const tokenSymbol = process.env['L2_TOKEN_SYMBOL'] as string
const tokenCurrency = process.env['L2_TOKEN_CURRENCY'] as string

const pauserL2 = deployerL2Wallet
const blacklisterL2 = deployerL2Wallet
const lostAndFound = deployerL2Wallet
await (
await l2UsdcFiatToken.initialize(
'USDC',
'USDC.e',
'USD',
tokenName,
tokenSymbol,
tokenCurrency,
6,
masterMinter.address,
pauserL2.address,
blacklisterL2.address,
deployerL2Wallet.address
)
).wait()
await (await l2UsdcFiatToken.initializeV2('USDC')).wait()

await (await l2UsdcFiatToken.initializeV2(tokenName)).wait()
await (await l2UsdcFiatToken.initializeV2_1(lostAndFound.address)).wait()
await (await l2UsdcFiatToken.initializeV2_2([], 'USDC.e')).wait()
await (await l2UsdcFiatToken.initializeV2_2([], tokenSymbol)).wait()

/// verify initialization
if (
(await l2UsdcFiatToken.name()) != 'USDC' ||
(await l2UsdcFiatToken.symbol()) != 'USDC.e' ||
(await l2UsdcFiatToken.currency()) != 'USD' ||
(await l2UsdcFiatToken.name()) != tokenName ||
(await l2UsdcFiatToken.symbol()) != tokenSymbol ||
(await l2UsdcFiatToken.currency()) != tokenCurrency ||
(await l2UsdcFiatToken.decimals()) != 6 ||
(await l2UsdcFiatToken.masterMinter()) != masterMinter.address ||
(await l2UsdcFiatToken.pauser()) != pauserL2.address ||
Expand Down Expand Up @@ -755,6 +763,9 @@ function _checkEnvVars() {
'L2_ROUTER',
'INBOX',
'L1_USDC',
'L2_TOKEN_NAME',
'L2_TOKEN_SYMBOL',
'L2_TOKEN_CURRENCY',
]

for (const envVar of requiredEnvVars) {
Expand Down
9 changes: 9 additions & 0 deletions scripts/usdc-bridge-deployment/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ CHILD_DEPLOYER_KEY=
L1_ROUTER=
L2_ROUTER=
INBOX=

## USDC (or EURC) address on the parent chain
L1_USDC=

## Naming params for the bridged token which is deployed to child chain. Values should be adjusted based on the parent chain and currency used
## Circle's naming guideline: https://brand.circle.com/d/M9z54TaEwsWL/stablecoins#/-/usdc-brand-guide/usdc-naming-guidelines
L2_TOKEN_NAME='USDC'
L2_TOKEN_SYMBOL='USDC.e'
L2_TOKEN_CURRENCY='USD'

## OPTIONAL arg. If set, script will register the gateway, otherwise it will store TX payload in a file
ROLLUP_OWNER_KEY=
74 changes: 74 additions & 0 deletions test-foundry/gas-reporter/ProductionGasReport.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import "forge-std/Test.sol";
import {L1GatewayRouter} from "../../contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol";
import {L1ERC20Gateway} from "../../contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol";
import {L1CustomGateway} from "../../contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract ProductionGasReportTest is Test {
/* solhint-disable func-name-mixedcase */

// based on TX: 0xa23e528910c7cb0f4e86d1b3745e334ad84bcd600591857b44854a5b7ad1f804
function test_depositTokenStdGateway() public virtual {
L1GatewayRouter router = L1GatewayRouter(0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef);
address origin = address(0x0936F059c3f3F6d354A268c927e83388A1db2BAe);
uint256 amount = 0.00020920159720128 ether;
address token = address(0xec53bF9167f50cDEB3Ae105f56099aaaB9061F83);
uint256 tokenAmount = 20_000_000_000_000_000_000_000;
vm.deal(origin, amount);
vm.startPrank(origin);
IERC20(token).approve(address(0xa3A7B6F88361F48403514059F1F16C8E78d60EeC), tokenAmount);
bytes memory data =
hex"0000000000000000000000000000000000000000000000000000b4732c3f8dc000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000";
uint256 gasBefore = gasleft();
router.outboundTransfer{value: amount}({
_token: token,
_to: address(0x0936F059c3f3F6d354A268c927e83388A1db2BAe),
_amount: tokenAmount,
_maxGas: 124_975,
_gasPriceBid: 86_376_000,
_data: data
});
uint256 gasAfter = gasleft();
console.log("GAs used:", gasBefore - gasAfter);
}

function test_Tstore() public {
L1ERC20Gateway gateway = new L1ERC20Gateway();
vm.etch(address(0xb4299A1F5f26fF6a98B7BA35572290C359fde900), address(gateway).code);
test_depositTokenStdGateway();
}

// based on TX: 0xf7925d851185bed53740694b1bcaaf7e78038847c259039d037a1ee7ccfcb38f
function test_depositTokenCustomGateway() public virtual {
L1GatewayRouter router = L1GatewayRouter(0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef);
address origin = address(0x41d3D33156aE7c62c094AAe2995003aE63f587B3);
uint256 amount = 0.000092506225179456 ether;
address token = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
uint256 tokenAmount = 50_000_000_000;
vm.deal(origin, amount);
vm.startPrank(origin);
IERC20(token).approve(address(0xcEe284F754E854890e311e3280b767F80797180d), tokenAmount);
bytes memory data =
hex"00000000000000000000000000000000000000000000000000004520940d734000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000";
uint256 gasBefore = gasleft();
router.outboundTransfer{value: amount}({
_token: token,
_to: address(0x0301A3C9887E2B8C26f9e8B48d56b81E7f4B3bCD),
_amount: tokenAmount,
_maxGas: 275_000,
_gasPriceBid: 60_000_000,
_data: data
});
uint256 gasAfter = gasleft();
console.log("GAs used:", gasBefore - gasAfter);
}

function test_TstoreCustom() public {
L1CustomGateway gateway = new L1CustomGateway();
vm.etch(address(0xC8D26aB9e132C79140b3376a0Ac7932E4680Aa45), address(gateway).code);
test_depositTokenCustomGateway();
}
}

0 comments on commit fd987f7

Please sign in to comment.