From 276a9de441339ec9be43d7b1220dd8a37db9fd50 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 8 Jan 2024 11:29:12 +0100 Subject: [PATCH 01/10] Add supoprt for custom number of decimals used for fee token --- scripts/ethcommands.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 3d78233..c648230 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -197,6 +197,11 @@ export const createERC20Command = { describe: "account (see general help)", default: "user_l2user", }, + decimals: { + string: true, + describe: "number of decimals for token", + default: "18", + }, }, handler: async (argv: any) => { console.log("create-erc20"); @@ -207,12 +212,23 @@ export const createERC20Command = { argv.provider ); - const contractFactory = new ContractFactory( - ERC20PresetFixedSupplyArtifact.abi, - ERC20PresetFixedSupplyArtifact.bytecode, - deployerWallet - ); - const contract = await contractFactory.deploy("AppTestToken", "APP", ethers.utils.parseEther("1000000000"), namedAccount(argv.mintTo).address); + //// Bytecode below is generated from this simple ERC20 token contract which uses custom number of decimals + // contract TestToken is ERC20 { + // uint8 private immutable _decimals; + // + // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { + // _decimals = decimals_; + // _mint(mintTo, 1_000_000 * 10 ** uint256(decimals_)); + // } + // + // function decimals() public view virtual override returns (uint8) { + // return _decimals; + // } + // } + const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000198565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b81525081600390816200008191906200028b565b5060046200009082826200028b565b50505060ff82166080819052620000c5908290620000b090600a6200046c565b620000bf90620f424062000481565b620000cd565b5050620004b9565b6001600160a01b038216620001285760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200013c9190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001ac57600080fd5b825160ff81168114620001be57600080fd5b60208401519092506001600160a01b0381168114620001dc57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200021257607f821691505b6020821081036200023357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019357600081815260208120601f850160051c81016020861015620002625750805b601f850160051c820191505b8181101562000283578281556001016200026e565b505050505050565b81516001600160401b03811115620002a757620002a7620001e7565b620002bf81620002b88454620001fd565b8462000239565b602080601f831160018114620002f75760008415620002de5750858301515b600019600386901b1c1916600185901b17855562000283565b600085815260208120601f198616915b82811015620003285788860151825594840194600190910190840162000307565b5085821015620003475787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ae57816000190482111562000392576200039262000357565b80851615620003a057918102915b93841c939080029062000372565b509250929050565b600082620003c75750600162000466565b81620003d65750600062000466565b8160018114620003ef5760028114620003fa576200041a565b600191505062000466565b60ff8411156200040e576200040e62000357565b50506001821b62000466565b5060208310610133831016604e8410600b84101617156200043f575081810a62000466565b6200044b83836200036d565b806000190482111562000462576200046262000357565b0290505b92915050565b60006200047a8383620003b6565b9392505050565b60008160001904831182151516156200049e576200049e62000357565b500290565b8082018082111562000466576200046662000357565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220c17385bf7b455298f3c99090105f4b3d07556cb9d4d4e4b5d0698f6fc8faf19264736f6c63430008100033"; + const abi = ["constructor(uint8 decimals_, address mintTo)"]; + const contractFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); + const contract = await contractFactory.deploy(parseInt(argv.decimals), namedAccount(argv.mintTo).address); await contract.deployTransaction.wait(); console.log("Contract deployed at address:", contract.address); From 4f60f8c8ebb9543980683eacd263de0b34b66c7e Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 8 Jan 2024 11:44:12 +0100 Subject: [PATCH 02/10] Add decimals param to test-node.bash --- test-node.bash | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test-node.bash b/test-node.bash index 7d360e4..d920d60 100755 --- a/test-node.bash +++ b/test-node.bash @@ -35,6 +35,7 @@ dev_build_nitro=false dev_build_blockscout=false l3_custom_fee_token=false l3_token_bridge=false +l3_custom_fee_token_decimals=18 batchposters=1 devprivkey=b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 l1chainid=1337 @@ -128,6 +129,19 @@ while [[ $# -gt 0 ]]; do l3_custom_fee_token=true shift ;; + --l3-fee-token-decimals) + if ! $l3_custom_fee_token; then + echo "Error: --l3-fee-token-decimals requires --l3-fee-token to be provided." + exit 1 + fi + l3_custom_fee_token_decimals=$2 + if [[ $l3_custom_fee_token_decimals -lt 0 || $l3_custom_fee_token_decimals -gt 36 ]]; then + echo "l3-fee-token-decimals must be in range [0,36], value: $l3_custom_fee_token_decimals." + exit 1 + fi + shift + shift + ;; --l3-token-bridge) if ! $l3node; then echo "Error: --l3-token-bridge requires --l3node to be provided." @@ -165,6 +179,7 @@ while [[ $# -gt 0 ]]; do echo --pos l1 is a proof-of-stake chain \(using prysm for consensus\) echo --validate heavy computation, validating all blocks in WASM echo --l3-fee-token L3 chain is set up to use custom fee token. Only valid if also '--l3node' is provided + echo --l3-fee-token-decimals Number of decimals to use for custom fee token. Only valid if also '--l3-fee-token' is provided echo --l3-token-bridge Deploy L2-L3 token bridge. Only valid if also '--l3node' is provided echo --batchposters batch posters [0-3] echo --redundantsequencers redundant sequencers [0-3] @@ -383,7 +398,7 @@ if $force_init; then if $l3_custom_fee_token; then echo == Deploying custom fee token - nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer | tail -n 1 | awk '{ print $NF }'` + nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer --decimals $l3_custom_fee_token_decimals | tail -n 1 | awk '{ print $NF }'` EXTRA_L3_DEPLOY_FLAG="--nativeTokenAddress $nativeTokenAddress" fi From ddc75cee36cb90cee88cce13dcf3e6aad9dfd55e Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Mon, 8 Jan 2024 15:26:34 +0100 Subject: [PATCH 03/10] Adjust values --- scripts/ethcommands.ts | 8 +++++--- test-node.bash | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index c648230..8057ee7 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -1,5 +1,5 @@ import { runStress } from "./stress"; -import { ContractFactory, ethers, Wallet } from "ethers"; +import { BigNumber, ContractFactory, ethers, Wallet } from "ethers"; import * as consts from "./consts"; import { namedAccount, namedAddress } from "./accounts"; import * as ERC20PresetFixedSupplyArtifact from "@openzeppelin/contracts/build/contracts/ERC20PresetFixedSupply.json"; @@ -65,7 +65,9 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st /// deposit fee token const iface = new ethers.utils.Interface(["function depositERC20(uint256 amount)"]) - argv.data = iface.encodeFunctionData("depositERC20", [ethers.utils.parseEther(argv.amount)]); + const decimals = await nativeTokenContract.decimals() + const depositAmount = BigNumber.from(argv.amount).mul(BigNumber.from('10').pow(decimals)) + argv.data = iface.encodeFunctionData("depositERC20", [depositAmount]); await runStress(argv, sendTransaction); @@ -76,7 +78,7 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); while (true) { const balance = await bridger.getBalance() - if (balance.gte(ethers.utils.parseEther(argv.amount))) { + if (balance.gte(depositAmount)) { return } await sleep(100) diff --git a/test-node.bash b/test-node.bash index d920d60..a23ab48 100755 --- a/test-node.bash +++ b/test-node.bash @@ -423,8 +423,8 @@ if $force_init; then echo == Fund L3 accounts if $l3_custom_fee_token; then docker compose run scripts bridge-native-token-to-l3 --amount 50000 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 500 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 500 --from user_token_bridge_deployer --to "key_0x$devprivkey" --wait + docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --wait + docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --to "key_0x$devprivkey" --wait else docker compose run scripts bridge-to-l3 --ethamount 50000 --wait docker compose run scripts bridge-to-l3 --ethamount 500 --wait --from "key_0x$devprivkey" From 2148cc58254c1cd053c2d38916549fc8840b9b23 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Wed, 10 Jan 2024 10:28:18 +0100 Subject: [PATCH 04/10] Approve correct amount --- scripts/ethcommands.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 8057ee7..e57e0f5 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -58,15 +58,19 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st argv.to = "address_" + inboxAddr; - /// approve inbox to use fee token + // get token contract const bridgerParentChain = namedAccount(argv.from, argv.threadId).connect(argv.provider) const nativeTokenContract = new ethers.Contract(token, ERC20.abi, bridgerParentChain) - await nativeTokenContract.approve(inboxAddr, ethers.utils.parseEther(argv.amount)) - /// deposit fee token - const iface = new ethers.utils.Interface(["function depositERC20(uint256 amount)"]) + // scale deposit amount const decimals = await nativeTokenContract.decimals() const depositAmount = BigNumber.from(argv.amount).mul(BigNumber.from('10').pow(decimals)) + + /// approve inbox to use fee token + await nativeTokenContract.approve(inboxAddr, depositAmount) + + /// deposit fee token + const iface = new ethers.utils.Interface(["function depositERC20(uint256 amount)"]) argv.data = iface.encodeFunctionData("depositERC20", [depositAmount]); await runStress(argv, sendTransaction); From 9e3dc84ba8885a29386273fedc85b86351e010ba Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Thu, 8 Feb 2024 13:25:11 +0100 Subject: [PATCH 05/10] Move token deployment to separate function --- scripts/ethcommands.ts | 60 ++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index c2632ec..ef4d3cd 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -91,6 +91,34 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st } } +async function deployERC20Contract(deployerWallet: Wallet, mintTo: string, decimals: number): Promise { + //// Bytecode below is generated from this simple ERC20 token contract which uses custom number of decimals + // contract TestToken is ERC20 { + // uint8 private immutable _decimals; + // + // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { + // _decimals = decimals_; + // _mint(mintTo, 1_000_000 * 10 ** uint256(decimals_)); + // } + // + // function decimals() public view virtual override returns (uint8) { + // return _decimals; + // } + // } + const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000198565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b81525081600390816200008191906200028b565b5060046200009082826200028b565b50505060ff82166080819052620000c5908290620000b090600a6200046c565b620000bf90620f424062000481565b620000cd565b5050620004b9565b6001600160a01b038216620001285760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200013c9190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001ac57600080fd5b825160ff81168114620001be57600080fd5b60208401519092506001600160a01b0381168114620001dc57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200021257607f821691505b6020821081036200023357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019357600081815260208120601f850160051c81016020861015620002625750805b601f850160051c820191505b8181101562000283578281556001016200026e565b505050505050565b81516001600160401b03811115620002a757620002a7620001e7565b620002bf81620002b88454620001fd565b8462000239565b602080601f831160018114620002f75760008415620002de5750858301515b600019600386901b1c1916600185901b17855562000283565b600085815260208120601f198616915b82811015620003285788860151825594840194600190910190840162000307565b5085821015620003475787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ae57816000190482111562000392576200039262000357565b80851615620003a057918102915b93841c939080029062000372565b509250929050565b600082620003c75750600162000466565b81620003d65750600062000466565b8160018114620003ef5760028114620003fa576200041a565b600191505062000466565b60ff8411156200040e576200040e62000357565b50506001821b62000466565b5060208310610133831016604e8410600b84101617156200043f575081810a62000466565b6200044b83836200036d565b806000190482111562000462576200046262000357565b0290505b92915050565b60006200047a8383620003b6565b9392505050565b60008160001904831182151516156200049e576200049e62000357565b500290565b8082018082111562000466576200046662000357565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220c17385bf7b455298f3c99090105f4b3d07556cb9d4d4e4b5d0698f6fc8faf19264736f6c63430008100033"; + const abi = [ + "constructor(uint8 decimals_, address mintTo)", + "function transfer(address to, uint256 amount) returns (bool)"] + ; + const tokenFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); + const token = await tokenFactory.deploy(decimals, deployerWallet.address); + await token.deployTransaction.wait(); + // transfer half the supply to mintTo + const transferAmount = BigNumber.from("500000").mul(BigNumber.from('10').pow(decimals)) + await (await token.functions.transfer(namedAccount(mintTo).address, transferAmount)).wait(); + + return token; +} export const bridgeFundsCommand = { command: "bridge-funds", @@ -231,15 +259,8 @@ export const createERC20Command = { l1provider ); - const tokenFactory = new ContractFactory( - ERC20PresetFixedSupplyArtifact.abi, - ERC20PresetFixedSupplyArtifact.bytecode, - deployerWallet - ); - const token = await tokenFactory.deploy("AppTestToken", "APP", ethers.utils.parseEther("1000000000"), deployerWallet.address); - await token.deployTransaction.wait(); + const token = await deployERC20Contract(deployerWallet, argv.mintTo, argv.decimals); console.log("Contract deployed at L1 address:", token.address); - await (await token.functions.transfer(namedAccount(argv.mintTo).address, ethers.utils.parseEther("100000000"))).wait(); const l1GatewayRouter = new ethers.Contract(l1l2tokenbridge.l2Network.tokenBridge.l1GatewayRouter, L1GatewayRouter.abi, deployerWallet); await (await token.functions.approve(l1l2tokenbridge.l2Network.tokenBridge.l1ERC20Gateway, ethers.constants.MaxUint256)).wait(); @@ -275,27 +296,8 @@ export const createERC20Command = { ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), argv.provider ); - - //// Bytecode below is generated from this simple ERC20 token contract which uses custom number of decimals - // contract TestToken is ERC20 { - // uint8 private immutable _decimals; - // - // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { - // _decimals = decimals_; - // _mint(mintTo, 1_000_000 * 10 ** uint256(decimals_)); - // } - // - // function decimals() public view virtual override returns (uint8) { - // return _decimals; - // } - // } - const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000198565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b81525081600390816200008191906200028b565b5060046200009082826200028b565b50505060ff82166080819052620000c5908290620000b090600a6200046c565b620000bf90620f424062000481565b620000cd565b5050620004b9565b6001600160a01b038216620001285760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200013c9190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001ac57600080fd5b825160ff81168114620001be57600080fd5b60208401519092506001600160a01b0381168114620001dc57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200021257607f821691505b6020821081036200023357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019357600081815260208120601f850160051c81016020861015620002625750805b601f850160051c820191505b8181101562000283578281556001016200026e565b505050505050565b81516001600160401b03811115620002a757620002a7620001e7565b620002bf81620002b88454620001fd565b8462000239565b602080601f831160018114620002f75760008415620002de5750858301515b600019600386901b1c1916600185901b17855562000283565b600085815260208120601f198616915b82811015620003285788860151825594840194600190910190840162000307565b5085821015620003475787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ae57816000190482111562000392576200039262000357565b80851615620003a057918102915b93841c939080029062000372565b509250929050565b600082620003c75750600162000466565b81620003d65750600062000466565b8160018114620003ef5760028114620003fa576200041a565b600191505062000466565b60ff8411156200040e576200040e62000357565b50506001821b62000466565b5060208310610133831016604e8410600b84101617156200043f575081810a62000466565b6200044b83836200036d565b806000190482111562000462576200046262000357565b0290505b92915050565b60006200047a8383620003b6565b9392505050565b60008160001904831182151516156200049e576200049e62000357565b500290565b8082018082111562000466576200046662000357565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220c17385bf7b455298f3c99090105f4b3d07556cb9d4d4e4b5d0698f6fc8faf19264736f6c63430008100033"; - const abi = ["constructor(uint8 decimals_, address mintTo)"]; - const contractFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); - const contract = await contractFactory.deploy(parseInt(argv.decimals), namedAccount(argv.mintTo).address); - await contract.deployTransaction.wait(); - - console.log("Contract deployed at address:", contract.address); + const token = await deployERC20Contract(deployerWallet, argv.mintTo, argv.decimals); + console.log("Contract deployed at address:", token.address); argv.provider.destroy(); }, From 83476e2ad6f4465e50da7ece08fce0f8afba8f6f Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Fri, 19 Apr 2024 14:03:57 +0200 Subject: [PATCH 06/10] Adjust token amounts --- scripts/ethcommands.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 4192ece..cf5e43f 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -106,11 +106,7 @@ async function deployERC20Contract(deployerWallet: Wallet, mintTo: string, decim // } // } const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000198565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b81525081600390816200008191906200028b565b5060046200009082826200028b565b50505060ff82166080819052620000c5908290620000b090600a6200046c565b620000bf90620f424062000481565b620000cd565b5050620004b9565b6001600160a01b038216620001285760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200013c9190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001ac57600080fd5b825160ff81168114620001be57600080fd5b60208401519092506001600160a01b0381168114620001dc57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200021257607f821691505b6020821081036200023357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019357600081815260208120601f850160051c81016020861015620002625750805b601f850160051c820191505b8181101562000283578281556001016200026e565b505050505050565b81516001600160401b03811115620002a757620002a7620001e7565b620002bf81620002b88454620001fd565b8462000239565b602080601f831160018114620002f75760008415620002de5750858301515b600019600386901b1c1916600185901b17855562000283565b600085815260208120601f198616915b82811015620003285788860151825594840194600190910190840162000307565b5085821015620003475787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ae57816000190482111562000392576200039262000357565b80851615620003a057918102915b93841c939080029062000372565b509250929050565b600082620003c75750600162000466565b81620003d65750600062000466565b8160018114620003ef5760028114620003fa576200041a565b600191505062000466565b60ff8411156200040e576200040e62000357565b50506001821b62000466565b5060208310610133831016604e8410600b84101617156200043f575081810a62000466565b6200044b83836200036d565b806000190482111562000462576200046262000357565b0290505b92915050565b60006200047a8383620003b6565b9392505050565b60008160001904831182151516156200049e576200049e62000357565b500290565b8082018082111562000466576200046662000357565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220c17385bf7b455298f3c99090105f4b3d07556cb9d4d4e4b5d0698f6fc8faf19264736f6c63430008100033"; - const abi = [ - "constructor(uint8 decimals_, address mintTo)", - "function transfer(address to, uint256 amount) returns (bool)"] - ; - const tokenFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); + const tokenFactory = new ContractFactory(ERC20.abi, erc20TokenBytecode, deployerWallet); const token = await tokenFactory.deploy(decimals, deployerWallet.address); await token.deployTransaction.wait(); // transfer half the supply to mintTo @@ -264,8 +260,9 @@ export const createERC20Command = { const l1GatewayRouter = new ethers.Contract(l1l2tokenbridge.l2Network.tokenBridge.l1GatewayRouter, L1GatewayRouter.abi, deployerWallet); await (await token.functions.approve(l1l2tokenbridge.l2Network.tokenBridge.l1ERC20Gateway, ethers.constants.MaxUint256)).wait(); + const supply = await token.totalSupply(); await (await l1GatewayRouter.functions.outboundTransfer( - token.address, namedAccount(argv.mintTo).address, ethers.utils.parseEther("100000000"), 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { + token.address, namedAccount(argv.mintTo).address, supply.div(2), 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { value: ethers.utils.parseEther("1"), } )).wait(); From cc2ead1fdc8ff4f5df9dc64def0d93298bc8fc39 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Fri, 19 Apr 2024 15:52:50 +0200 Subject: [PATCH 07/10] Mint all to deployer --- scripts/ethcommands.ts | 37 ++++++++++++++++++------------------- test-node.bash | 5 +++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index cf5e43f..4045b0b 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -3,7 +3,6 @@ import { BigNumber, ContractFactory, ethers, Wallet } from "ethers"; import * as consts from "./consts"; import { namedAccount, namedAddress } from "./accounts"; import * as L1GatewayRouter from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol/L1GatewayRouter.json"; -import * as ERC20PresetFixedSupplyArtifact from "@openzeppelin/contracts/build/contracts/ERC20PresetFixedSupply.json"; import * as ERC20 from "@openzeppelin/contracts/build/contracts/ERC20.json"; import * as fs from "fs"; const path = require("path"); @@ -91,29 +90,33 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st } } -async function deployERC20Contract(deployerWallet: Wallet, mintTo: string, decimals: number): Promise { +async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Promise { //// Bytecode below is generated from this simple ERC20 token contract which uses custom number of decimals + + // pragma solidity 0.8.16; + // + // import {ERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; + // // contract TestToken is ERC20 { // uint8 private immutable _decimals; // // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { // _decimals = decimals_; - // _mint(mintTo, 1_000_000 * 10 ** uint256(decimals_)); + // _mint(mintTo, 1_000_000_000); // } // // function decimals() public view virtual override returns (uint8) { // return _decimals; // } // } - const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000198565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b81525081600390816200008191906200028b565b5060046200009082826200028b565b50505060ff82166080819052620000c5908290620000b090600a6200046c565b620000bf90620f424062000481565b620000cd565b5050620004b9565b6001600160a01b038216620001285760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200013c9190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001ac57600080fd5b825160ff81168114620001be57600080fd5b60208401519092506001600160a01b0381168114620001dc57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200021257607f821691505b6020821081036200023357634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019357600081815260208120601f850160051c81016020861015620002625750805b601f850160051c820191505b8181101562000283578281556001016200026e565b505050505050565b81516001600160401b03811115620002a757620002a7620001e7565b620002bf81620002b88454620001fd565b8462000239565b602080601f831160018114620002f75760008415620002de5750858301515b600019600386901b1c1916600185901b17855562000283565b600085815260208120601f198616915b82811015620003285788860151825594840194600190910190840162000307565b5085821015620003475787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ae57816000190482111562000392576200039262000357565b80851615620003a057918102915b93841c939080029062000372565b509250929050565b600082620003c75750600162000466565b81620003d65750600062000466565b8160018114620003ef5760028114620003fa576200041a565b600191505062000466565b60ff8411156200040e576200040e62000357565b50506001821b62000466565b5060208310610133831016604e8410600b84101617156200043f575081810a62000466565b6200044b83836200036d565b806000190482111562000462576200046262000357565b0290505b92915050565b60006200047a8383620003b6565b9392505050565b60008160001904831182151516156200049e576200049e62000357565b500290565b8082018082111562000466576200046662000357565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220c17385bf7b455298f3c99090105f4b3d07556cb9d4d4e4b5d0698f6fc8faf19264736f6c63430008100033"; - const tokenFactory = new ContractFactory(ERC20.abi, erc20TokenBytecode, deployerWallet); + + const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000bf438038062000bf483398101604081905262000034916200017d565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b815250816003908162000081919062000270565b50600462000090828262000270565b50505060ff8216608052620000aa81633b9aca00620000b2565b505062000364565b6001600160a01b0382166200010d5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200012191906200033c565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b600080604083850312156200019157600080fd5b825160ff81168114620001a357600080fd5b60208401519092506001600160a01b0381168114620001c157600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620001f757607f821691505b6020821081036200021857634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200017857600081815260208120601f850160051c81016020861015620002475750805b601f850160051c820191505b81811015620002685782815560010162000253565b505050505050565b81516001600160401b038111156200028c576200028c620001cc565b620002a4816200029d8454620001e2565b846200021e565b602080601f831160018114620002dc5760008415620002c35750858301515b600019600386901b1c1916600185901b17855562000268565b600085815260208120601f198616915b828110156200030d57888601518255948401946001909101908401620002ec565b50858210156200032c5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b808201808211156200035e57634e487b7160e01b600052601160045260246000fd5b92915050565b60805161087462000380600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220ae10cf6b65bb4070682573aeaa582fd9c484b3a2837f1c899bcbbd7ded6fcddb64736f6c63430008100033"; + const abi = ["constructor(uint8 decimals_, address mintTo)"]; + const tokenFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); const token = await tokenFactory.deploy(decimals, deployerWallet.address); await token.deployTransaction.wait(); - // transfer half the supply to mintTo - const transferAmount = BigNumber.from("500000").mul(BigNumber.from('10').pow(decimals)) - await (await token.functions.transfer(namedAccount(mintTo).address, transferAmount)).wait(); - return token; + return token.address; } export const bridgeFundsCommand = { @@ -222,10 +225,6 @@ export const createERC20Command = { string: true, describe: "account (see general help)" }, - mintTo: { - string: true, - describe: "account (see general help)", - }, bridgeable: { boolean: true, describe: "if true, deploy on L1 and bridge to L2", @@ -255,14 +254,15 @@ export const createERC20Command = { l1provider ); - const token = await deployERC20Contract(deployerWallet, argv.mintTo, argv.decimals); + const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); + const token = new ethers.Contract(tokenAddress, ERC20.abi, deployerWallet); console.log("Contract deployed at L1 address:", token.address); const l1GatewayRouter = new ethers.Contract(l1l2tokenbridge.l2Network.tokenBridge.l1GatewayRouter, L1GatewayRouter.abi, deployerWallet); await (await token.functions.approve(l1l2tokenbridge.l2Network.tokenBridge.l1ERC20Gateway, ethers.constants.MaxUint256)).wait(); const supply = await token.totalSupply(); await (await l1GatewayRouter.functions.outboundTransfer( - token.address, namedAccount(argv.mintTo).address, supply.div(2), 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { + token.address, deployerWallet.address, supply, 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { value: ethers.utils.parseEther("1"), } )).wait(); @@ -293,8 +293,8 @@ export const createERC20Command = { ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), argv.provider ); - const token = await deployERC20Contract(deployerWallet, argv.mintTo, argv.decimals); - console.log("Contract deployed at address:", token.address); + const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); + console.log("Contract deployed at address:", tokenAddress); argv.provider.destroy(); }, @@ -327,8 +327,7 @@ export const transferERC20Command = { argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); const account = namedAccount(argv.from).connect(argv.provider); const tokenContract = new ethers.Contract(argv.token, ERC20.abi, account); - const decimals = await tokenContract.decimals(); - await(await tokenContract.transfer(namedAccount(argv.to).address, ethers.utils.parseUnits(argv.amount, decimals))).wait(); + await(await tokenContract.transfer(namedAccount(argv.to).address, argv.amount)).wait(); argv.provider.destroy(); }, }; diff --git a/test-node.bash b/test-node.bash index 13f1bff..2b3d78a 100755 --- a/test-node.bash +++ b/test-node.bash @@ -411,8 +411,9 @@ if $force_init; then if $l3_custom_fee_token; then echo == Deploying custom fee token - nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer --bridgeable $tokenbridge --decimals $l3_custom_fee_token_decimals | tail -n 1 | awk '{ print $NF }'` - docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_token_bridge_deployer --to l3owner + nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --bridgeable $tokenbridge --decimals $l3_custom_fee_token_decimals | tail -n 1 | awk '{ print $NF }'` + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_fee_token_deployer --to l3owner + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_fee_token_deployer --to user_token_bridge_deployer EXTRA_L3_DEPLOY_FLAG="-e FEE_TOKEN_ADDRESS=$nativeTokenAddress" fi From 5789086c9e2b4cc0f6a06bbc3531352ce5ed1f26 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Fri, 19 Apr 2024 17:25:02 +0200 Subject: [PATCH 08/10] Fix amounts --- scripts/ethcommands.ts | 8 +++++--- test-node.bash | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 4045b0b..1f341ed 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -102,7 +102,7 @@ async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Pr // // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { // _decimals = decimals_; - // _mint(mintTo, 1_000_000_000); + // _mint(mintTo, 1_000_000_000 * 10 ** decimals_); // } // // function decimals() public view virtual override returns (uint8) { @@ -110,7 +110,7 @@ async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Pr // } // } - const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000bf438038062000bf483398101604081905262000034916200017d565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b815250816003908162000081919062000270565b50600462000090828262000270565b50505060ff8216608052620000aa81633b9aca00620000b2565b505062000364565b6001600160a01b0382166200010d5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200012191906200033c565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b600080604083850312156200019157600080fd5b825160ff81168114620001a357600080fd5b60208401519092506001600160a01b0381168114620001c157600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620001f757607f821691505b6020821081036200021857634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200017857600081815260208120601f850160051c81016020861015620002475750805b601f850160051c820191505b81811015620002685782815560010162000253565b505050505050565b81516001600160401b038111156200028c576200028c620001cc565b620002a4816200029d8454620001e2565b846200021e565b602080601f831160018114620002dc5760008415620002c35750858301515b600019600386901b1c1916600185901b17855562000268565b600085815260208120601f198616915b828110156200030d57888601518255948401946001909101908401620002ec565b50858210156200032c5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b808201808211156200035e57634e487b7160e01b600052601160045260246000fd5b92915050565b60805161087462000380600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220ae10cf6b65bb4070682573aeaa582fd9c484b3a2837f1c899bcbbd7ded6fcddb64736f6c63430008100033"; + const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000195565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b815250816003908162000081919062000288565b50600462000090828262000288565b50505060ff8216608052620000c281620000ac84600a62000469565b620000bc90633b9aca0062000481565b620000ca565b5050620004b9565b6001600160a01b038216620001255760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b8060026000828254620001399190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001a957600080fd5b825160ff81168114620001bb57600080fd5b60208401519092506001600160a01b0381168114620001d957600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200020f57607f821691505b6020821081036200023057634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019057600081815260208120601f850160051c810160208610156200025f5750805b601f850160051c820191505b8181101562000280578281556001016200026b565b505050505050565b81516001600160401b03811115620002a457620002a4620001e4565b620002bc81620002b58454620001fa565b8462000236565b602080601f831160018114620002f45760008415620002db5750858301515b600019600386901b1c1916600185901b17855562000280565b600085815260208120601f198616915b82811015620003255788860151825594840194600190910190840162000304565b5085821015620003445787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ab5781600019048211156200038f576200038f62000354565b808516156200039d57918102915b93841c93908002906200036f565b509250929050565b600082620003c45750600162000463565b81620003d35750600062000463565b8160018114620003ec5760028114620003f75762000417565b600191505062000463565b60ff8411156200040b576200040b62000354565b50506001821b62000463565b5060208310610133831016604e8410600b84101617156200043c575081810a62000463565b6200044883836200036a565b80600019048211156200045f576200045f62000354565b0290505b92915050565b60006200047a60ff841683620003b3565b9392505050565b60008160001904831182151516156200049e576200049e62000354565b500290565b8082018082111562000463576200046362000354565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220257f3d763bae7b8c0189ed676531d85a1046e0bea68722f67c2616d46f01c02964736f6c63430008100033"; const abi = ["constructor(uint8 decimals_, address mintTo)"]; const tokenFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); const token = await tokenFactory.deploy(decimals, deployerWallet.address); @@ -327,7 +327,9 @@ export const transferERC20Command = { argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); const account = namedAccount(argv.from).connect(argv.provider); const tokenContract = new ethers.Contract(argv.token, ERC20.abi, account); - await(await tokenContract.transfer(namedAccount(argv.to).address, argv.amount)).wait(); + const tokenDecimals = await tokenContract.decimals(); + const amountToTransfer = BigNumber.from(argv.amount).mul(BigNumber.from('10').pow(tokenDecimals)); + await(await tokenContract.transfer(namedAccount(argv.to).address, amountToTransfer)).wait(); argv.provider.destroy(); }, }; diff --git a/test-node.bash b/test-node.bash index 2b3d78a..676f65f 100755 --- a/test-node.bash +++ b/test-node.bash @@ -412,8 +412,8 @@ if $force_init; then if $l3_custom_fee_token; then echo == Deploying custom fee token nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --bridgeable $tokenbridge --decimals $l3_custom_fee_token_decimals | tail -n 1 | awk '{ print $NF }'` - docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_fee_token_deployer --to l3owner - docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_fee_token_deployer --to user_token_bridge_deployer + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 10000 --from user_fee_token_deployer --to l3owner + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 10000 --from user_fee_token_deployer --to user_token_bridge_deployer EXTRA_L3_DEPLOY_FLAG="-e FEE_TOKEN_ADDRESS=$nativeTokenAddress" fi @@ -445,7 +445,7 @@ if $force_init; then echo == Fund L3 accounts if $l3_custom_fee_token; then - docker compose run scripts bridge-native-token-to-l3 --amount 50000 --from user_token_bridge_deployer --wait + docker compose run scripts bridge-native-token-to-l3 --amount 5000 --from user_token_bridge_deployer --wait docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --wait docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --to "key_0x$devprivkey" --wait else From e8e187b4dced1083e34b8109753b40f18589d0f4 Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Wed, 19 Jun 2024 19:04:41 +0200 Subject: [PATCH 09/10] Fix funding the L3 accounts in case of fee token --- scripts/ethcommands.ts | 2 +- test-node.bash | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 1f341ed..d1bc514 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -82,7 +82,7 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); while (true) { const balance = await bridger.getBalance() - if (balance.gte(depositAmount)) { + if (balance.gte(0)) { return } await sleep(100) diff --git a/test-node.bash b/test-node.bash index cec7463..04778ec 100755 --- a/test-node.bash +++ b/test-node.bash @@ -463,9 +463,9 @@ if $force_init; then echo == Fund L3 accounts if $l3_custom_fee_token; then - docker compose run scripts bridge-native-token-to-l3 --amount 5000 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 5 --from user_token_bridge_deployer --to "key_0x$devprivkey" --wait + docker compose run scripts bridge-native-token-to-l3 --amount 5000 --from user_fee_token_deployer --wait + docker compose run scripts send-l3 --ethamount 5 --from user_fee_token_deployer --wait + docker compose run scripts send-l3 --ethamount 5 --from user_fee_token_deployer --to "key_0x$devprivkey" --wait else docker compose run scripts bridge-to-l3 --ethamount 50000 --wait docker compose run scripts bridge-to-l3 --ethamount 500 --wait --from "key_0x$devprivkey" From 3af86a023224688499c199184993e10221934d6e Mon Sep 17 00:00:00 2001 From: Goran Vladika Date: Tue, 9 Jul 2024 14:04:36 +0200 Subject: [PATCH 10/10] Properly check that native bridging was successful --- scripts/ethcommands.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index d1bc514..39254d2 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -58,6 +58,11 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st argv.to = "address_" + inboxAddr; + // snapshot balance before deposit + const childProvider = new ethers.providers.WebSocketProvider(chainUrl); + const bridger = namedAccount(argv.from, argv.threadId).connect(childProvider) + const bridgerBalanceBefore = await bridger.getBalance() + // get token contract const bridgerParentChain = namedAccount(argv.from, argv.threadId).connect(argv.provider) const nativeTokenContract = new ethers.Contract(token, ERC20.abi, bridgerParentChain) @@ -77,12 +82,25 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st argv.provider.destroy(); if (argv.wait) { - const childProvider = new ethers.providers.WebSocketProvider(chainUrl); - const bridger = namedAccount(argv.from, argv.threadId).connect(childProvider) const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); + + // calculate amount being minted on child chain + let expectedMintedAmount = depositAmount + if(decimals < 18) { + // inflate up to 18 decimals + expectedMintedAmount = depositAmount.mul(BigNumber.from('10').pow(18 - decimals)) + } else if(decimals > 18) { + // deflate down to 18 decimals, rounding up + const quotient = BigNumber.from('10').pow(decimals - 18) + expectedMintedAmount = depositAmount.div(quotient) + if(expectedMintedAmount.mul(quotient).lt(depositAmount)) { + expectedMintedAmount = expectedMintedAmount.add(1) + } + } + while (true) { - const balance = await bridger.getBalance() - if (balance.gte(0)) { + const bridgerBalanceAfter = await bridger.getBalance() + if (bridgerBalanceAfter.sub(bridgerBalanceBefore).eq(expectedMintedAmount)) { return } await sleep(100)