From 67961ed8673cf686581352568ba41073f8a842c8 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Mon, 25 Dec 2023 09:13:28 +0800 Subject: [PATCH] redeloy xtoken on testnet --- helix-contract/address/xtoken-dev.json | 12 +- .../deploy/deploy_msgline_messager.js | 4 +- helix-contract/deploy/deploy_xtoken_config.js | 24 +-- helix-contract/deploy/deploy_xtoken_proxy.js | 8 +- helix-contract/deploy/deploy_xtoken_test.js | 158 ++++++++++++++++++ 5 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 helix-contract/deploy/deploy_xtoken_test.js diff --git a/helix-contract/address/xtoken-dev.json b/helix-contract/address/xtoken-dev.json index e9675dd..4883da3 100644 --- a/helix-contract/address/xtoken-dev.json +++ b/helix-contract/address/xtoken-dev.json @@ -1,22 +1,22 @@ { "messagers": { "crab": { - "msglineMessager": "0xCAb1f69C671f1548fd3dE5d63852E9B9181a0D0E" + "msglineMessager": "0xf85638B61E0425D6BB91981190B73246e3AF3CA9" }, "sepolia": { - "msglineMessager": "0x527B67a61C6E1344C359Af2e241aAFeb0c3a9DE9" + "msglineMessager": "0xc876D0873e4060472334E297b2db200Ca10cc806" } }, "backingProxy": { - "crab": "0xb137BDf1Ad5392027832f54a4409685Ef52Aa9dA" + "crab": "0x27F58339CbB8c5A6f58d5D05Bfc1B3fd121F489C" }, "backingLogic": { - "crab": "0x0cDc94088C40B461C3c9cF44DD38B328BDca95e9" + "crab": "0xF2274a80e93075ccD5E2Af8F07beF370Bb6dfac7" }, "issuingProxy": { - "sepolia": "0x44A001aF6AcD2d5f5cB82FCB14Af3d497D56faB4" + "sepolia": "0xFF3bc7372A8011CFaD43D240464ef2fe74C59b86" }, "issuingLogic": { - "sepolia": "0x97cd4227eFC7AEd96CD027994dE2e3E9ACc1b394" + "sepolia": "0x1c955644c527BAA5a28255bCf9F7D3635B7ad99b" } } diff --git a/helix-contract/deploy/deploy_msgline_messager.js b/helix-contract/deploy/deploy_msgline_messager.js index b0e0783..140ac62 100644 --- a/helix-contract/deploy/deploy_msgline_messager.js +++ b/helix-contract/deploy/deploy_msgline_messager.js @@ -12,7 +12,7 @@ const crabNetwork = { url: "https://crab-rpc.darwinia.network", dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", deployer: "0xbe6b2860d3c17a719be0A4911EA0EE689e8357f3", - msgline: "0x000000000EFcBAdA3793cC59c62D79b9f56Ae48F", + msgline: "0x0000000000D2de3e2444926c4577b0A59F1DD8BC", }; const sepoliaNetwork = { @@ -20,7 +20,7 @@ const sepoliaNetwork = { url: "https://rpc-sepolia.rockx.com", dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", deployer: "0xbe6b2860d3c17a719be0A4911EA0EE689e8357f3", - msgline: "0x000000000EFcBAdA3793cC59c62D79b9f56Ae48F", + msgline: "0x0000000000D2de3e2444926c4577b0A59F1DD8BC", }; function wallet(url) { diff --git a/helix-contract/deploy/deploy_xtoken_config.js b/helix-contract/deploy/deploy_xtoken_config.js index 5ad953d..e0b0726 100644 --- a/helix-contract/deploy/deploy_xtoken_config.js +++ b/helix-contract/deploy/deploy_xtoken_config.js @@ -11,8 +11,8 @@ const crabNetwork = { name: "crab", url: "https://crab-rpc.darwinia.network", dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", - messager: "0xCAb1f69C671f1548fd3dE5d63852E9B9181a0D0E", - backing: "0xb137BDf1Ad5392027832f54a4409685Ef52Aa9dA", + messager: "0xf85638B61E0425D6BB91981190B73246e3AF3CA9", + backing: "0x27F58339CbB8c5A6f58d5D05Bfc1B3fd121F489C", chainid: 44 }; @@ -20,8 +20,8 @@ const sepoliaNetwork = { name: "sepolia", url: "https://rpc-sepolia.rockx.com", dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", - messager: "0x527B67a61C6E1344C359Af2e241aAFeb0c3a9DE9", - issuing: "0x44A001aF6AcD2d5f5cB82FCB14Af3d497D56faB4", + messager: "0xc876D0873e4060472334E297b2db200Ca10cc806", + issuing: "0xFF3bc7372A8011CFaD43D240464ef2fe74C59b86", chainid: 11155111 }; @@ -40,20 +40,20 @@ async function deploy() { // connect messager const backingMessager = await ethers.getContractAt("MsglineMessager", backingNetwork.messager, walletBacking); const issuingMessager = await ethers.getContractAt("MsglineMessager", issuingNetwork.messager, walletIssuing); - await backingMessager.setRemoteMessager(issuingNetwork.chainid, issuingNetwork.chainid, issuingMessager.address); - await issuingMessager.setRemoteMessager(backingNetwork.chainid, backingNetwork.chainid, backingMessager.address); + await backingMessager.setRemoteMessager(issuingNetwork.chainid, issuingNetwork.chainid, issuingMessager.address, {gasLimit: 2000000}); + await issuingMessager.setRemoteMessager(backingNetwork.chainid, backingNetwork.chainid, backingMessager.address, {gasLimit: 2000000}); console.log("connect messager successed"); // xTokenBridge <> messager authorize const backing = await ethers.getContractAt("xTokenBacking", backingNetwork.backing, walletBacking); const issuing = await ethers.getContractAt("xTokenIssuing", issuingNetwork.issuing, walletIssuing); - await backingMessager.setWhiteList(backing.address, true); - await issuingMessager.setWhiteList(issuing.address, true); + await backingMessager.setWhiteList(backing.address, true, {gasLimit: 2000000}); + await issuingMessager.setWhiteList(issuing.address, true, {gasLimit: 2000000}); console.log("messager authorize xtoken bridge successed"); - await backing.setSendService(issuingNetwork.chainid, issuing.address, backingMessager.address); - await backing.setReceiveService(issuingNetwork.chainid, issuing.address, backingMessager.address); - await issuing.setSendService(backingNetwork.chainid, backing.address, issuingMessager.address); - await issuing.setReceiveService(backingNetwork.chainid, backing.address, issuingMessager.address); + await backing.setSendService(issuingNetwork.chainid, issuing.address, backingMessager.address, {gasLimit: 2000000}); + await backing.setReceiveService(issuingNetwork.chainid, issuing.address, backingMessager.address, {gasLimit: 2000000}); + await issuing.setSendService(backingNetwork.chainid, backing.address, issuingMessager.address, {gasLimit: 2000000}); + await issuing.setReceiveService(backingNetwork.chainid, backing.address, issuingMessager.address, {gasLimit: 2000000}); console.log("xtoken bridge connect remote successed"); } diff --git a/helix-contract/deploy/deploy_xtoken_proxy.js b/helix-contract/deploy/deploy_xtoken_proxy.js index d031ec2..ea34151 100644 --- a/helix-contract/deploy/deploy_xtoken_proxy.js +++ b/helix-contract/deploy/deploy_xtoken_proxy.js @@ -45,12 +45,12 @@ async function deployxTokenProxy(wallet, salt, dao, proxyAdminAddress, logicAddr async function deploy() { const walletCrab = wallet(crabNetwork.url); - const backingLogic = "0x0cDc94088C40B461C3c9cF44DD38B328BDca95e9"; - await deployxTokenProxy(walletCrab, "xtoken-backing-1.0.0", crabNetwork.dao, crabNetwork.proxyAdmin, backingLogic, crabNetwork.deployer); + const backingLogic = "0xF2274a80e93075ccD5E2Af8F07beF370Bb6dfac7"; + await deployxTokenProxy(walletCrab, "xtoken-backing-1.0.1", crabNetwork.dao, crabNetwork.proxyAdmin, backingLogic, crabNetwork.deployer); const walletSepolia = wallet(sepoliaNetwork.url); - const issuingLogic = "0x97cd4227eFC7AEd96CD027994dE2e3E9ACc1b394"; - await deployxTokenProxy(walletSepolia, "xtoken-issuing-1.0.0", sepoliaNetwork.dao, sepoliaNetwork.proxyAdmin, issuingLogic, sepoliaNetwork.deployer); + const issuingLogic = "0x1c955644c527BAA5a28255bCf9F7D3635B7ad99b"; + await deployxTokenProxy(walletSepolia, "xtoken-issuing-1.0.1", sepoliaNetwork.dao, sepoliaNetwork.proxyAdmin, issuingLogic, sepoliaNetwork.deployer); } async function main() { diff --git a/helix-contract/deploy/deploy_xtoken_test.js b/helix-contract/deploy/deploy_xtoken_test.js new file mode 100644 index 0000000..1ddcb6f --- /dev/null +++ b/helix-contract/deploy/deploy_xtoken_test.js @@ -0,0 +1,158 @@ +const ethUtil = require('ethereumjs-util'); +const abi = require('ethereumjs-abi'); +const secp256k1 = require('secp256k1'); +const fs = require("fs"); + +var ProxyDeployer = require("./proxy.js"); + +const privateKey = process.env.PRIKEY + +const crabNetwork = { + name: "crab", + url: "https://crab-rpc.darwinia.network", + dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", + backing: "0x27F58339CbB8c5A6f58d5D05Bfc1B3fd121F489C", + chainid: 44 +}; + +const sepoliaNetwork = { + name: "sepolia", + url: "https://rpc-sepolia.rockx.com", + dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4", + issuing: "0xFF3bc7372A8011CFaD43D240464ef2fe74C59b86", + chainid: 11155111 +}; + +function wallet(url) { + const provider = new ethers.providers.JsonRpcProvider(url); + const wallet = new ethers.Wallet(privateKey, provider); + return wallet; +} + +async function registerIssuing() { + const issuingNetwork = sepoliaNetwork; + const walletIssuing = wallet(sepoliaNetwork.url); + + const issuing = await ethers.getContractAt("xTokenIssuing", issuingNetwork.issuing, walletIssuing); + + await issuing.registerxToken( + 44, + "0x0000000000000000000000000000000000000000", + "crab", + "crab native token", + "CRAB", + 18, + "0x56bc75e2d63100000", + { gasLimit: 1000000 } + ); +} + +async function registerBacking() { + const backingNetwork = crabNetwork; + const walletBacking = wallet(crabNetwork.url); + + const backing = await ethers.getContractAt("xTokenBacking", backingNetwork.backing, walletBacking); + const xToken = "0x4828B88240166B8bB79A833Fd0dD38EaeADAAB1a"; + + await backing.registerOriginalToken( + 11155111, + "0x0000000000000000000000000000000000000000", + xToken, + "0x56bc75e2d63100000" + ); +} + +async function lockAndRemoteIssuing() { + const backingNetwork = crabNetwork; + const walletBacking = wallet(crabNetwork.url); + + const backing = await ethers.getContractAt("xTokenBacking", backingNetwork.backing, walletBacking); + + //const tx = await backing.callStatic.lockAndRemoteIssuing( + await backing.lockAndRemoteIssuing( + 11155111, + "0x0000000000000000000000000000000000000000", + walletBacking.address, + ethers.utils.parseEther("100"), + 1703247763001, + "0x000000000000000000000000000000000000000000000000000000000005f02200000000000000000000000088a39b052d477cfde47600a7c9950a441ce61cb400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", + { value: ethers.utils.parseEther("105.4") } + ); +} + +async function burnAndRemoteUnlock() { + const issuingNetwork = sepoliaNetwork; + const walletIssuing = wallet(sepoliaNetwork.url); + + const issuing = await ethers.getContractAt("xTokenIssuing", issuingNetwork.issuing, walletIssuing); + + const xTokenAddress = "0x4828B88240166B8bB79A833Fd0dD38EaeADAAB1a"; + const xToken = await ethers.getContractAt("xTokenErc20", xTokenAddress, walletIssuing); + await xToken.approve(issuing.address, ethers.utils.parseEther("10000000"), {gasLimit: 500000}); + await issuing.burnAndRemoteUnlock( + xTokenAddress, + walletIssuing.address, + ethers.utils.parseEther("5"), + 1703248419043, + "0x000000000000000000000000000000000000000000000000000000000006493c00000000000000000000000088a39b052d477cfde47600a7c9950a441ce61cb400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", + { + value: ethers.utils.parseEther("0.0000007"), + gasLimit: 1000000, + } + ); +} + +async function requestRemoteUnlockForIssuingFailure() { + const issuingNetwork = sepoliaNetwork; + const walletIssuing = wallet(sepoliaNetwork.url); + + const issuing = await ethers.getContractAt("xTokenIssuing", issuingNetwork.issuing, walletIssuing); + + await issuing.requestRemoteUnlockForIssuingFailure( + 44, + "0x0000000000000000000000000000000000000000", + walletIssuing.address, + walletIssuing.address, + ethers.utils.parseEther("100"), + 1703247763000, + "0x000000000000000000000000000000000000000000000000000000000006493c00000000000000000000000088a39b052d477cfde47600a7c9950a441ce61cb400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", + { + value: ethers.utils.parseEther("0.0000007"), + gasLimit: 1000000, + } + ); +} + +async function requestRemoteIssuingForUnlockFailure() { + const backingNetwork = crabNetwork; + const walletBacking = wallet(crabNetwork.url); + + const backing = await ethers.getContractAt("xTokenBacking", backingNetwork.backing, walletBacking); + + await backing.requestRemoteIssuingForUnlockFailure( + "0xab4f619082b61cac56f60611a661e2b16d8052ab2531be791d95821f8fb232ce", + 11155111, + "0x0000000000000000000000000000000000000000", + walletBacking.address, + ethers.utils.parseEther("100"), + "0x000000000000000000000000000000000000000000000000000000000005f02200000000000000000000000088a39b052d477cfde47600a7c9950a441ce61cb400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000", + { value: ethers.utils.parseEther("5.4") } + ); +} + +async function main() { + //await registerIssuing(); + //await registerBacking(); + //await lockAndRemoteIssuing(); + //await burnAndRemoteUnlock(); + await requestRemoteUnlockForIssuingFailure(); + //await requestRemoteIssuingForUnlockFailure(); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); +