@@ -10,18 +10,34 @@ import {
1010 randomAddress ,
1111 seedContract ,
1212 avmL1ToL2Alias ,
13+ keccak256 ,
14+ defaultAbiCoder ,
1315} from "../../../../utils/utils" ;
1416import { hre } from "../../../../utils/utils.hre" ;
1517
1618import { hubPoolFixture } from "../fixtures/HubPool.Fixture" ;
1719import { constructSingleRelayerRefundTree } from "../MerkleLib.utils" ;
1820import { smock } from "@defi-wonderland/smock" ;
1921
22+ const L2_ASSET_ROUTER = "0x0000000000000000000000000000000000010003" ;
2023// TODO: Grab the following from relayer/CONTRACT_ADDRESSES dictionary?
21- const ERC20_BRIDGE = "0x11f943b2c77b743ab90f4a0ae7d5a4e7fca3e102" ;
2224const USDC_BRIDGE = "0x350ACF3d84A6E668E53d4AA682989DCA15Ea27E2" ;
2325
2426const abiData = {
27+ l2AssetRouter : {
28+ abi : [
29+ {
30+ inputs : [
31+ { internalType : "bytes32" , name : "_assetId" , type : "bytes32" } ,
32+ { internalType : "bytes" , name : "_assetData" , type : "bytes" } ,
33+ ] ,
34+ name : "withdraw" ,
35+ outputs : [ { internalType : "bytes32" , name : "" , type : "bytes32" } ] ,
36+ stateMutability : "nonpayable" ,
37+ type : "function" ,
38+ } ,
39+ ] ,
40+ } ,
2541 erc20DefaultBridge : {
2642 abi : [
2743 {
@@ -60,7 +76,7 @@ describe("ZkSync Spoke Pool", function () {
6076 let hubPool : Contract , zkSyncSpokePool : Contract , dai : Contract , usdc : Contract , weth : Contract ;
6177 let l2Dai : string , crossDomainAliasAddress , crossDomainAlias : SignerWithAddress ;
6278 let owner : SignerWithAddress , relayer : SignerWithAddress , rando : SignerWithAddress ;
63- let zkErc20Bridge : FakeContract , zkUSDCBridge : FakeContract , l2Eth : FakeContract ;
79+ let l2AssetRouter : FakeContract , zkUSDCBridge : FakeContract , l2Eth : FakeContract ;
6480 let constructorArgs : unknown [ ] ;
6581
6682 beforeEach ( async function ( ) {
@@ -73,14 +89,14 @@ describe("ZkSync Spoke Pool", function () {
7389 crossDomainAlias = await ethers . getSigner ( crossDomainAliasAddress ) ;
7490 await owner . sendTransaction ( { to : crossDomainAliasAddress , value : toWei ( "1" ) } ) ;
7591
76- zkErc20Bridge = await smock . fake ( abiData . erc20DefaultBridge . abi , { address : ERC20_BRIDGE } ) ;
92+ l2AssetRouter = await smock . fake ( abiData . l2AssetRouter . abi , { address : L2_ASSET_ROUTER } ) ;
7793 zkUSDCBridge = await smock . fake ( abiData . erc20DefaultBridge . abi , { address : USDC_BRIDGE } ) ;
7894 l2Eth = await smock . fake ( abiData . eth . abi , { address : abiData . eth . address } ) ;
79- constructorArgs = [ weth . address , usdc . address , zkUSDCBridge . address , cctpTokenMessenger , 60 * 60 , 9 * 60 * 60 ] ;
95+ constructorArgs = [ weth . address , usdc . address , zkUSDCBridge . address , 1 , cctpTokenMessenger , 60 * 60 , 9 * 60 * 60 ] ;
8096
8197 zkSyncSpokePool = await hre . upgrades . deployProxy (
8298 await getContractFactory ( "ZkSync_SpokePool" , owner ) ,
83- [ 0 , zkErc20Bridge . address , owner . address , hubPool . address ] ,
99+ [ 0 , owner . address , hubPool . address ] ,
84100 { kind : "uups" , unsafeAllow : [ "delegatecall" ] , constructorArgs }
85101 ) ;
86102
@@ -98,11 +114,6 @@ describe("ZkSync Spoke Pool", function () {
98114 await expect ( zkSyncSpokePool . upgradeTo ( implementation ) ) . to . be . revertedWith ( "ONLY_COUNTERPART_GATEWAY" ) ;
99115 await zkSyncSpokePool . connect ( crossDomainAlias ) . upgradeTo ( implementation ) ;
100116 } ) ;
101- it ( "Only cross domain owner can set ZKBridge" , async function ( ) {
102- await expect ( zkSyncSpokePool . setZkBridge ( rando . address ) ) . to . be . reverted ;
103- await zkSyncSpokePool . connect ( crossDomainAlias ) . setZkBridge ( rando . address ) ;
104- expect ( await zkSyncSpokePool . zkErc20Bridge ( ) ) . to . equal ( rando . address ) ;
105- } ) ;
106117 it ( "Invalid USDC bridge configuration is rejected" , async function ( ) {
107118 let _constructorArgs = [ ...constructorArgs ] ;
108119 expect ( _constructorArgs [ 1 ] ) . to . equal ( usdc . address ) ;
@@ -166,14 +177,21 @@ describe("ZkSync Spoke Pool", function () {
166177 "ONLY_COUNTERPART_GATEWAY"
167178 ) ;
168179 } ) ;
169- it ( "Bridge tokens to hub pool correctly calls the Standard L2 Bridge for standard ERC20s" , async function ( ) {
180+ it ( "Bridge tokens to hub pool correctly calls the L2 Asset Router for standard ERC20s" , async function ( ) {
170181 const { leaves, tree } = await constructSingleRelayerRefundTree ( l2Dai , await zkSyncSpokePool . callStatic . chainId ( ) ) ;
171182 await zkSyncSpokePool . connect ( crossDomainAlias ) . relayRootBundle ( tree . getHexRoot ( ) , mockTreeRoot ) ;
172183 await zkSyncSpokePool . connect ( relayer ) . executeRelayerRefundLeaf ( 0 , leaves [ 0 ] , tree . getHexProof ( leaves [ 0 ] ) ) ;
173184
174- // This should have sent tokens back to L1. Check the correct methods on the gateway are correctly called.
175- expect ( zkErc20Bridge . withdraw ) . to . have . been . calledOnce ;
176- expect ( zkErc20Bridge . withdraw ) . to . have . been . calledWith ( hubPool . address , l2Dai , amountToReturn ) ;
185+ // This should have sent tokens back to L1.
186+ expect ( l2AssetRouter . withdraw ) . to . have . been . calledOnce ;
187+ const expectedAssetId = keccak256 (
188+ defaultAbiCoder . encode ( [ "uint256" , "address" , "address" ] , [ 1 , L2_ASSET_ROUTER , l2Dai ] )
189+ ) ;
190+ const expectedData = defaultAbiCoder . encode (
191+ [ "uint256" , "address" , "address" ] ,
192+ [ amountToReturn , hubPool . address , l2Dai ]
193+ ) ;
194+ expect ( l2AssetRouter . withdraw ) . to . have . been . calledWith ( expectedAssetId , expectedData ) ;
177195 } ) ;
178196 it ( "Bridge tokens to hub pool correctly calls the Standard L2 Bridge for zkSync Bridged USDC.e" , async function ( ) {
179197 // Redeploy the SpokePool with usdc address -> 0x0
@@ -193,8 +211,7 @@ describe("ZkSync Spoke Pool", function () {
193211 await zkSyncSpokePool . connect ( relayer ) . executeRelayerRefundLeaf ( 0 , leaves [ 0 ] , tree . getHexProof ( leaves [ 0 ] ) ) ;
194212
195213 // This should have sent tokens back to L1. Check the correct methods on the gateway are correctly called.
196- expect ( zkErc20Bridge . withdraw ) . to . have . been . calledOnce ;
197- expect ( zkErc20Bridge . withdraw ) . to . have . been . calledWith ( hubPool . address , usdc . address , amountToReturn ) ;
214+ expect ( l2AssetRouter . withdraw ) . to . have . been . calledOnce ;
198215 } ) ;
199216 it ( "Bridge tokens to hub pool correctly calls the custom USDC L2 Bridge for Circle Bridged USDC" , async function ( ) {
200217 const { leaves, tree } = await constructSingleRelayerRefundTree (
0 commit comments