From 528f4b359b8ae47b28bce3b349af6e027797fc49 Mon Sep 17 00:00:00 2001 From: aalavandhan1984 Date: Wed, 27 Oct 2021 10:19:38 -0400 Subject: [PATCH] intermediate --- contracts/_test/UFragmentsTestnet.sol | 20 ++++++ .../bridge-gateways/AMPLArbitrumGateway.sol | 2 +- helpers/contracts.js | 1 + helpers/deploy/ampl.js | 6 +- .../dev3RinkebyArbitrumSatChain.json | 36 +++++----- sdk/deployments/dev3RinkebyBaseChain.json | 57 ++++++++------- tasks/deploy/ampleforth.js | 5 +- tasks/deploy/arbitrum.js | 71 +++++++++++++++++++ test/integration/chain_bridge.js | 4 +- .../bridge-gateways/ampl_arbitrum_gateway.js | 2 +- 10 files changed, 150 insertions(+), 54 deletions(-) create mode 100644 contracts/_test/UFragmentsTestnet.sol diff --git a/contracts/_test/UFragmentsTestnet.sol b/contracts/_test/UFragmentsTestnet.sol new file mode 100644 index 0000000..623e49d --- /dev/null +++ b/contracts/_test/UFragmentsTestnet.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Importing uFragments contract dependencies to be compiled for integration tests +pragma solidity 0.7.6; + +import {UFragments} from "uFragments/contracts/UFragments.sol"; + +contract UFragmentsTestnet is UFragments { + event Result(bool result, bytes reason); + + function isArbitrumEnabled() external view returns (uint8) { + return uint8(0xa4b1); + } + + // NOTE: this allows the token contarct to register itself with the bridge on testnet + // The AMPL contract on mainnet is immutable and this can't be used! + function externalCall(address destination, bytes calldata data, uint256 value) external payable { + (bool result, bytes memory reason) = destination.call{value: value}(data); + emit Result(result, reason); + } +} diff --git a/contracts/base-chain/bridge-gateways/AMPLArbitrumGateway.sol b/contracts/base-chain/bridge-gateways/AMPLArbitrumGateway.sol index 03fee71..c634508 100644 --- a/contracts/base-chain/bridge-gateways/AMPLArbitrumGateway.sol +++ b/contracts/base-chain/bridge-gateways/AMPLArbitrumGateway.sol @@ -224,7 +224,7 @@ contract AMPLArbitrumGateway is IERC20(_l1Token).safeTransferFrom(from, address(this), _amount); IERC20(_l1Token).approve(vault, _amount); - ITokenVault(vault).lock(_l1Token, from, _amount); + ITokenVault(vault).lock(_l1Token, address(this), _amount); emit XCTransferOut(from, address(0), _amount, recordedGlobalAMPLSupply); } diff --git a/helpers/contracts.js b/helpers/contracts.js index 826d6e1..5f9227b 100644 --- a/helpers/contracts.js +++ b/helpers/contracts.js @@ -15,6 +15,7 @@ const ContractABIPaths = { UFragmentsPolicy: 'uFragments/contracts', Orchestrator: 'uFragments/contracts', MedianOracle: 'market-oracle/contracts', + UFragmentsTestnet: 'contracts/_test', // Chainbridge Bridge: 'chainbridge-solidity/contracts', diff --git a/helpers/deploy/ampl.js b/helpers/deploy/ampl.js index a53d331..7538604 100644 --- a/helpers/deploy/ampl.js +++ b/helpers/deploy/ampl.js @@ -6,7 +6,7 @@ const { deployProxyContract, } = require('../contracts'); -async function deployAMPLContracts( +async function deployAMPLTestnetContracts( ethers, deployer, txParams = {}, @@ -18,7 +18,7 @@ async function deployAMPLContracts( const ampl = await deployProxyContract( ethers, - 'UFragments', + 'UFragmentsTestnet', proxyAdmin, deployer, [deployerAddress], @@ -164,6 +164,6 @@ async function deployXCAmpleContracts( } module.exports = { - deployAMPLContracts, + deployAMPLTestnetContracts, deployXCAmpleContracts, }; diff --git a/sdk/deployments/dev3RinkebyArbitrumSatChain.json b/sdk/deployments/dev3RinkebyArbitrumSatChain.json index a03cbd4..c99eeed 100644 --- a/sdk/deployments/dev3RinkebyArbitrumSatChain.json +++ b/sdk/deployments/dev3RinkebyArbitrumSatChain.json @@ -1,6 +1,6 @@ { "proxyAdmin": { - "address": "0x7A3ce10573718e00F63187598b5BBe1D82931b28", + "address": "0xbAdBD05c2eC381B2DdF610E125A73baBda54fc7f", "abi": [ "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)", "function changeProxyAdmin(address proxy, address newAdmin)", @@ -13,11 +13,11 @@ "function upgrade(address proxy, address implementation)", "function upgradeAndCall(address proxy, address implementation, bytes data) payable" ], - "hash": "0xabb51fb3c568f280ccdfb834c77be3837585f566a58007832cae22e37ea43467", - "blockNumber": 5974712 + "hash": "0x800809255038a5d6659ff394b65b1334ac215c017d7ea8c43e16fa91c55ec753", + "blockNumber": 6019296 }, "xcAmple": { - "address": "0x9B76a1139bcE77399f88a0E397F044094c289a89", + "address": "0x4162aEE7665a2b8EafE5C257e600DEa7c4296f73", "abi": [ "event Approval(address indexed owner, address indexed spender, uint256 value)", "event ControllerUpdated(address controller)", @@ -56,11 +56,11 @@ "function transferFrom(address from, address to, uint256 value) returns (bool)", "function transferOwnership(address newOwner)" ], - "hash": "0x0eda762c735a4407c211a484aa6923359c0feb46e8f917ca4ce256b99eb44940", - "blockNumber": 5974717 + "hash": "0xd14fd701a190ab766181adfeb5e94b94011cf6628672521b2e789f3066f5623d", + "blockNumber": 6019298 }, "xcAmpleController": { - "address": "0x6F1cE4B4B7C30c903A42FDc0D77c8671393101C0", + "address": "0xDFbE71D6D42284e9a28aA84304c4696dE0e89f99", "abi": [ "event GatewayBurn(address indexed bridgeGateway, address indexed depositor, uint256 xcAmpleAmount)", "event GatewayMint(address indexed bridgeGateway, address indexed recipient, uint256 xcAmpleAmount)", @@ -88,11 +88,11 @@ "function whitelistedBridgeGateways(address) view returns (bool)", "function xcAmple() view returns (address)" ], - "hash": "0xde8074129b911b6281faf4d8ea6e9c6649453a85837ee2ffa9afa5f318da5093", - "blockNumber": 5974726 + "hash": "0x3081fdb2f1146254f743c8c4940b7fd6e6356927f94918227a07fc1ed4da4f9c", + "blockNumber": 6019305 }, "rebaseRelayer": { - "address": "0x91F2B10275A9C3F461ea19BB51ff960c3b933303", + "address": "0xBf1D78dEC7f1D82CCF0c45ab7Ee362e72BeE6f39", "abi": [ "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)", "event TransactionFailed(address indexed destination, uint256 index, bytes data, bytes reason)", @@ -108,12 +108,12 @@ "function transactionsSize() view returns (uint256)", "function transferOwnership(address newOwner)" ], - "hash": "0x22d7267332c9dd172ddb8a02a9ad339418c2e6294eb756984ab690c49d1934a5", - "blockNumber": 5974731 + "hash": "0x48788898957d483844e03f54f7eb6c330f32d59503872c7864b8fc5469390c21", + "blockNumber": 6019311 }, "isBaseChain": false, "arbitrum/transferGateway": { - "address": "0x2eAb9dE5f87a4A3261f1e33Dc4DB3EC0a68Ae61c", + "address": "0x75c00CF8B6C932AaD2E20fa238a57D389aE3842d", "abi": [ "constructor(address xcAmple_, address xcController_)", "event DepositFinalized(address indexed l1Token, address indexed _from, address indexed _to, uint256 _amount)", @@ -136,11 +136,11 @@ "function xcAmple() view returns (address)", "function xcController() view returns (address)" ], - "hash": "0x30b6c6898fc57f20a835c7182051f3a92d68345bf97aa64c2afd3b683d1ec59c", - "blockNumber": 5975087 + "hash": "0xb43520d64bc6ba1d1af688745608b7414e43457b484103f7f3f4a55c9bab2fe7", + "blockNumber": 6019546 }, "arbitrum/rebaseGateway": { - "address": "0x2eAb9dE5f87a4A3261f1e33Dc4DB3EC0a68Ae61c", + "address": "0x75c00CF8B6C932AaD2E20fa238a57D389aE3842d", "abi": [ "constructor(address xcAmple_, address xcController_)", "event DepositFinalized(address indexed l1Token, address indexed _from, address indexed _to, uint256 _amount)", @@ -163,7 +163,7 @@ "function xcAmple() view returns (address)", "function xcController() view returns (address)" ], - "hash": "0x30b6c6898fc57f20a835c7182051f3a92d68345bf97aa64c2afd3b683d1ec59c", - "blockNumber": 5975087 + "hash": "0xb43520d64bc6ba1d1af688745608b7414e43457b484103f7f3f4a55c9bab2fe7", + "blockNumber": 6019546 } } \ No newline at end of file diff --git a/sdk/deployments/dev3RinkebyBaseChain.json b/sdk/deployments/dev3RinkebyBaseChain.json index e936047..dc7bf31 100644 --- a/sdk/deployments/dev3RinkebyBaseChain.json +++ b/sdk/deployments/dev3RinkebyBaseChain.json @@ -1,6 +1,6 @@ { "proxyAdmin": { - "address": "0x2E5D096ef6f134A89270e791F502bCbA099d6f68", + "address": "0x38fab7E342311cF384f76d1Ea31c4AFcc565c55c", "abi": [ "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)", "function changeProxyAdmin(address proxy, address newAdmin)", @@ -13,17 +13,18 @@ "function upgrade(address proxy, address implementation)", "function upgradeAndCall(address proxy, address implementation, bytes data) payable" ], - "hash": "0x664201f2c6b027c92fc8de997fef95f3d8aca0a8936d5e7bf80ff36f569f0f5d", - "blockNumber": 9528020 + "hash": "0x0c4d620b0220a581f617919b347f7a078f312bcc51c047a042b2a63fecb10835", + "blockNumber": 9535696 }, "ampl": { - "address": "0xBb6ae64dAeE2264708cFc6c62100027c0bAB5a67", + "address": "0x244E12361f488adFa757E706466023673a96Fa3d", "abi": [ "event Approval(address indexed owner, address indexed spender, uint256 value)", "event LogMonetaryPolicyUpdated(address monetaryPolicy)", "event LogRebase(uint256 indexed epoch, uint256 totalSupply)", "event OwnershipRenounced(address indexed previousOwner)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)", + "event Result(bool result, bytes reason)", "event Transfer(address indexed from, address indexed to, uint256 value)", "function DOMAIN_SEPARATOR() view returns (bytes32)", "function EIP712_DOMAIN() view returns (bytes32)", @@ -34,9 +35,11 @@ "function balanceOf(address who) view returns (uint256)", "function decimals() view returns (uint8)", "function decreaseAllowance(address spender, uint256 subtractedValue) returns (bool)", + "function externalCall(address destination, bytes data, uint256 value) payable", "function increaseAllowance(address spender, uint256 addedValue) returns (bool)", "function initialize(string name, string symbol, uint8 decimals)", "function initialize(address owner_)", + "function isArbitrumEnabled() view returns (uint8)", "function isOwner() view returns (bool)", "function monetaryPolicy() view returns (address)", "function name() view returns (string)", @@ -56,11 +59,11 @@ "function transferFrom(address from, address to, uint256 value) returns (bool)", "function transferOwnership(address newOwner)" ], - "hash": "0xbc9e7e26e329f0d0f2fa203a849f20ab4f8f39762fd40816a3cef15926480720", - "blockNumber": 9528020 + "hash": "0x4dc164878c11e4bd6ba0986435d68a013dfb1dcf762ac2624db4632802b58aa0", + "blockNumber": 9535696 }, "policy": { - "address": "0xa5520E5bED964560d2B5d75A025B0FB78C97b1D4", + "address": "0x4964610919942c8680A0717b342c2A6176FE16b2", "abi": [ "event LogRebase(uint256 indexed epoch, uint256 exchangeRate, uint256 cpi, int256 requestedSupplyAdjustment, uint256 timestampSec)", "event OwnershipRenounced(address indexed previousOwner)", @@ -92,11 +95,11 @@ "function transferOwnership(address newOwner)", "function uFrags() view returns (address)" ], - "hash": "0x2f5bd869e28d941e588d56fde87a6e8c97b613f4b64099a6c9dcc245a6d1e2cb", - "blockNumber": 9528041 + "hash": "0xfbf40d4e2e276af206825e29bab48824a267fd9baec2822c60ab79321fdd4bc8", + "blockNumber": 9535712 }, "orchestrator": { - "address": "0x058c1c118373d2291adF21CB4C395698Ae2552E6", + "address": "0x90dE686Ba9289A2978B23Bf199299A33eA3ef036", "abi": [ "constructor(address policy_)", "event OwnershipRenounced(address indexed previousOwner)", @@ -114,11 +117,11 @@ "function transactionsSize() view returns (uint256)", "function transferOwnership(address newOwner)" ], - "hash": "0xcde9d28067494e5512e1430388ca2da66869f2c43204ee9c1de8beda9ac94216", - "blockNumber": 9528057 + "hash": "0xe7bd741ac56bbbcaee274b1261f237864b537f2dfba5ac86ed696132fc72409d", + "blockNumber": 9535726 }, "rateOracle": { - "address": "0x89Fb2e35cEf8480342d441702a82ED041135202d", + "address": "0x7156F72425C0D6A729b0016F7DC1E00050f6DA6E", "abi": [ "function reportDelaySec() view returns (uint256)", "function pushReport(uint256 payload)", @@ -145,11 +148,11 @@ "event ProviderReportPushed(address indexed provider, uint256 payload, uint256 timestamp)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)" ], - "hash": "0x656950a4690a21fbc0fde59312a7c94c7f0cd1d95dc22690dbcb2f70dd7e0ee0", - "blockNumber": 9528029 + "hash": "0x9f2e3ef3361cbce993f5dafc6bff2223164b6b75d61a842e721db1224577b3fc", + "blockNumber": 9535700 }, "cpiOracle": { - "address": "0x21e9d1FfE15991dD27256ff42963C86374d97B0E", + "address": "0x6e31D7Ea7176238392c07d58Fb9e3c6D78ae8910", "abi": [ "function reportDelaySec() view returns (uint256)", "function pushReport(uint256 payload)", @@ -176,12 +179,12 @@ "event ProviderReportPushed(address indexed provider, uint256 payload, uint256 timestamp)", "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)" ], - "hash": "0xbfa768aa20932344396b3d93fda79bf5269f7c3d0415194e8aac9def55e44124", - "blockNumber": 9528035 + "hash": "0x62577b74d7b88b0a748651998d134af4de3cc692b95145430b24ff7fd7c9e721", + "blockNumber": 9535706 }, "isBaseChain": true, "arbitrum/tokenVault": { - "address": "0xf704fCA2fd138E31760aa242240B78b7Ba89d2d2", + "address": "0x02C04C9DF6F994BFd54C66e770e5945f444A9526", "abi": [ "event GatewayLocked(address indexed bridgeGateway, address indexed token, address indexed depositor, uint256 amount)", "event GatewayUnlocked(address indexed bridgeGateway, address indexed token, address indexed recipient, uint256 amount)", @@ -197,11 +200,11 @@ "function unlock(address token, address recipient, uint256 amount)", "function whitelistedBridgeGateways(address) view returns (bool)" ], - "hash": "0x0c4060895cab3e4693fc5d6ba0924ff864cb188639fef0d3501415d2cda5ccd1", - "blockNumber": 9349617 + "hash": "0x773e193e00f36636c7bb633e31e6acecc2b428b54f0543ee8c698be60110d7c1", + "blockNumber": 9535747 }, "arbitrum/transferGateway": { - "address": "0x60CcDea1Ba997e2D781C13b5E6B4f7Fec94eE691", + "address": "0xbAb60bb39D6f086CA2e7e578fbF945E61a12cE3a", "abi": [ "constructor(address ampl_, address policy_, address vault_)", "event DepositInitiated(address l1Token, address indexed _from, address indexed _to, uint256 indexed _sequenceNumber, uint256 _amount)", @@ -225,11 +228,11 @@ "function vault() view returns (address)", "function xcAmple() view returns (address)" ], - "hash": "0x6bdcd4aadb75b28a76e6c166e5d25ac982788e8500855ab809b9d8dd5c02115c", - "blockNumber": 9528225 + "hash": "0xbb5bda37bdd726212b9c9cc5c08045d8b4eeec3631d24ba4a3293b8f34362b54", + "blockNumber": 9535779 }, "arbitrum/rebaseGateway": { - "address": "0x60CcDea1Ba997e2D781C13b5E6B4f7Fec94eE691", + "address": "0xbAb60bb39D6f086CA2e7e578fbF945E61a12cE3a", "abi": [ "constructor(address ampl_, address policy_, address vault_)", "event DepositInitiated(address l1Token, address indexed _from, address indexed _to, uint256 indexed _sequenceNumber, uint256 _amount)", @@ -253,7 +256,7 @@ "function vault() view returns (address)", "function xcAmple() view returns (address)" ], - "hash": "0x6bdcd4aadb75b28a76e6c166e5d25ac982788e8500855ab809b9d8dd5c02115c", - "blockNumber": 9528225 + "hash": "0xbb5bda37bdd726212b9c9cc5c08045d8b4eeec3631d24ba4a3293b8f34362b54", + "blockNumber": 9535779 } } \ No newline at end of file diff --git a/tasks/deploy/ampleforth.js b/tasks/deploy/ampleforth.js index 1b1f4bb..2ad5fc7 100644 --- a/tasks/deploy/ampleforth.js +++ b/tasks/deploy/ampleforth.js @@ -16,7 +16,7 @@ const { } = require('../../helpers/contracts'); const { - deployAMPLContracts, + deployAMPLTestnetContracts, deployXCAmpleContracts, deployTokenVault, } = require('../../helpers/deploy'); @@ -103,7 +103,7 @@ txTask('testnet:deploy:ampleforth', 'Deploy ampleforth contract suite') console.log('Deployer:', deployerAddress); const { proxyAdmin, ampl, policy, orchestrator, rateOracle, cpiOracle } = - await deployAMPLContracts(hre.ethers, deployer, txParams, 2); + await deployAMPLTestnetContracts(hre.ethers, deployer, txParams, 2); for (const w in args.fundingWallets) { await ampl.transfer(args.fundingWallets[w], toAmplFixedPt(args.amount)); } @@ -149,6 +149,7 @@ txTask('deploy:ampleforth_xc', 'Deploy cross chain ampleforth contract suite') if (txParams.gasPrice == 0) { txParams.gasPrice = await hre.ethers.provider.getGasPrice(); } + // const txParams = {} const deployer = await loadSignerSync(args, hre.ethers.provider); const deployerAddress = await deployer.getAddress(); diff --git a/tasks/deploy/arbitrum.js b/tasks/deploy/arbitrum.js index 6bc17f4..6c762b8 100644 --- a/tasks/deploy/arbitrum.js +++ b/tasks/deploy/arbitrum.js @@ -1,3 +1,5 @@ +const { Bridge } = require('arb-ts'); +const { hexDataLength } = require('@ethersproject/bytes'); const { txTask, loadSignerSync, @@ -215,3 +217,72 @@ txTask('deploy:arbitrum_connection', 'Connects the two gateway contracts') .initialize(args.satRouter, ampl.address, baseGateway.address, {}) ).wait(2); }); + + +txTask('deploy:arbitrum_register_testnet', 'Registers the token to the router') + .addParam('baseChainNetwork', 'The network name of the base chain network') + .addParam( + 'satChainNetwork', + 'The network name of the satellite chain network', + ) + .addParam( + 'baseRouter', + 'The address of the arbitrum router contract on the base chain', + ) + .setAction(async (args, hre) => { + const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit }; + if (txParams.gasPrice == 0) { + txParams.gasPrice = await hre.ethers.provider.getGasPrice(); + } + + const baseChainProvider = getEthersProvider(args.baseChainNetwork); + const satChainProvider = getEthersProvider(args.satChainNetwork); + + const baseChainSigner = loadSignerSync(args, baseChainProvider); + const satChainSigner = loadSignerSync(args, satChainProvider); + + const routerABI = [{"inputs":[{"internalType":"address","name":"_gateway","type":"address"},{"internalType":"uint256","name":"_maxGas","type":"uint256"},{"internalType":"uint256","name":"_gasPriceBid","type":"uint256"},{"internalType":"uint256","name":"_maxSubmissionCost","type":"uint256"}],"name":"setGateway","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"}] + const router = new ethers.Contract(args.baseRouter, routerABI, hre.ethers.provider); + + const ampl = await getDeployedContractInstance( + args.baseChainNetwork, + 'ampl', + baseChainProvider, + ); + + const baseGateway = await getDeployedContractInstance( + args.baseChainNetwork, + 'arbitrum/transferGateway', + baseChainProvider, + ); + + const arb = await Bridge.init(baseChainSigner, satChainSigner); + const fnDataBytes = ethers.utils.defaultAbiCoder.encode( + ['address', 'uint256', 'uint256', 'uint256'], + [baseGateway.address, '0','0','0'], + ); + const fnBytesLength = hexDataLength(fnDataBytes) + 4; + const [_submissionPriceWei, nextUpdateTimestamp] = + await arb.l2Bridge.getTxnSubmissionPrice(fnBytesLength); + const submissionPriceWei = _submissionPriceWei.mul(5); // buffer can be reduced + const maxGas = 500000; + const gasPriceBid = await satChainProvider.getGasPrice(); + const callValue = submissionPriceWei.add(gasPriceBid.mul(maxGas)); + + const ptx = await router.populateTransaction.setGateway( + baseGateway.address, + maxGas, + gasPriceBid, + submissionPriceWei) + + const tx = await ampl.connect(baseChainSigner).externalCall( + ptx.to, + ptx.data, + callValue, + { ...txParams, value: callValue} + ) + + console.log(tx.hash) + + await tx.wait(2) + }); \ No newline at end of file diff --git a/test/integration/chain_bridge.js b/test/integration/chain_bridge.js index 494620c..b1dcbd3 100644 --- a/test/integration/chain_bridge.js +++ b/test/integration/chain_bridge.js @@ -15,7 +15,7 @@ const { const { execRebase, toAmplFixedPt } = require('../../sdk/ampleforth'); const { - deployAMPLContracts, + deployAMPLTestnetContracts, deployXCAmpleContracts, deployTokenVault, deployChainBridgeContracts, @@ -55,7 +55,7 @@ async function setupContracts() { userASatChain2Wallet = accounts[6]; userBSatChain2Wallet = accounts[7]; - baseChainAmplContracts = await deployAMPLContracts(ethers, deployer); + baseChainAmplContracts = await deployAMPLTestnetContracts(ethers, deployer); baseChainAmplContracts.tokenVault = await deployTokenVault(ethers, deployer); baseChainBridgeContracts = await deployChainBridgeContracts( diff --git a/test/unit/base-chain/bridge-gateways/ampl_arbitrum_gateway.js b/test/unit/base-chain/bridge-gateways/ampl_arbitrum_gateway.js index a7ca156..c219995 100644 --- a/test/unit/base-chain/bridge-gateways/ampl_arbitrum_gateway.js +++ b/test/unit/base-chain/bridge-gateways/ampl_arbitrum_gateway.js @@ -257,7 +257,7 @@ describe('AMPLArbitrumGateway:outboundTransfer', () => { it('should lock into vault', async function () { await expect(r) .to.emit(vault, 'Lock') - .withArgs(ampl.address, depositorAddress, 1001); + .withArgs(ampl.address, gateway.address, 1001); }); });