From c927387cd4c2c08cb22072bc6bc2ba5bce77d093 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Tue, 11 Jul 2023 09:29:31 +0200 Subject: [PATCH 01/10] early draft of pause functionality --- package.json | 3 ++- src/bridgePausing.ts | 44 +++++++++++++++++++++++++++------- src/constants.ts | 10 ++++++++ src/utils.ts | 51 ++++++++++++++++++++++++++++++++++++++++ tsconfig.cjs.json | 2 +- types/constants.d.ts | 4 ++++ types/constants.d.ts.map | 2 +- types/utils.d.ts | 5 ++++ types/utils.d.ts.map | 1 + 9 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 src/utils.ts create mode 100644 types/utils.d.ts create mode 100644 types/utils.d.ts.map diff --git a/package.json b/package.json index dfe5a68..a4ec1b5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "build:all": "yarn build:cjs && yarn build:types", "lint": "eslint 'src/**/*.ts'", "lint:fix": "yarn run lint --fix", - "clean": "rm -rf ./dist ./dist-cjs ./dist-esm ./types" + "clean": "rm -rf ./dist ./dist-cjs ./dist-esm ./types", + "build-and-test": "yarn run build:all && node ./dist-cjs/bridgePausing.js pause 95be8d0ee6436056dbabfdb2da70585a7baf23ceca320304a600c94e67f507f5 testnet" }, "keywords": [], "author": "Sygma Protocol Product Team", diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 8e515f9..5a14322 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -1,24 +1,50 @@ import axios from 'axios'; import {Command, Option} from 'commander'; import {ConfigUrl} from "./constants"; -import {RawConfig} from "@buildwithsygma/sygma-sdk-core"; +import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; const program = new Command(); -console.log("pero"); program .name("pause-bridge") .description("Pauses all bridge instances across all networks") - .argument("", "mnemonic or private key of the wallet") + .version("0.0.1") + +program + .command("pause") .addOption( - new Option('--environment, -e', 'Environment on which to pause bridge instances') + new Option('-e, --environment ', 'Environment on which to pause bridge instances') .choices(['devnet', 'testnet', 'mainnet']) ) - .action(async (mnemonic: string, environment: keyof typeof ConfigUrl) => { + .addOption( + new Option('-pk, --private-key ', 'Private key to use for signing transactions') + ) + .addOption( + new Option('-m, --mnemonic ', 'Mnemonic to use for signing transactions').conflicts('private-key') + ) + .action(async (configs: any) => { try { - console.log("pero"); - const response = await axios.get(ConfigUrl[environment]) as unknown as RawConfig; - console.log(response) + const network: keyof typeof ConfigUrl = configs.environment; + const { + privateKey, + mnemonic + } = configs; + + const response = await axios.get(ConfigUrl[network]) as any; + const networks = response.data.domains.filter((network: any) => network.type === "evm"); // just evms for now + + let wallets: any = []; + + if (mnemonic) { + wallets = await deriveWalletsFromMnemonic(mnemonic, networks); + } else if (privateKey) { + wallets = await getWalletsForDifferentProviders(privateKey, networks); + } else { + throw new Error('Either mnemonic or private key must be provided'); + } + + await sendPauseTransactions(networks, wallets); + } catch (err) { if (err instanceof Error) { throw new Error(`Failed to fetch shared config because of: ${err.message}`); @@ -27,3 +53,5 @@ program } } }) + +program.parse(process.argv); diff --git a/src/constants.ts b/src/constants.ts index d226f17..c9db7ad 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,3 +3,13 @@ export const ConfigUrl = { testnet: "https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json", mainnet: "https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json" } + +// chain id -> provider url +export const chainIdToRpc = { + 5: "https://goerli.infura.io/v3/" +} + +export const bridgeAbi = [ + +] + diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..f19dab8 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,51 @@ +import {ethers} from 'ethers'; +import {chainIdToRpc, bridgeAbi} from "./constants"; + +export async function getWalletsForDifferentProviders(privateKey: string, networks: any) { + const wallets = []; + for (let i = 0; i < networks.length; i++) { + const network = networks[i]; + const chainId: keyof typeof chainIdToRpc = network.chainId; + const rpc = chainIdToRpc[chainId]; + if (rpc) { + const provider = new ethers.JsonRpcProvider(rpc); + const wallet = new ethers.Wallet(privateKey, provider); // add error handling for invalid private key + wallets.push(wallet); + } + } + return wallets; +} + +export async function deriveWalletsFromMnemonic(mnemonic: string, networks: any) { + const wallets = []; + for (let i = 0; i < networks.length; i++) { + const network = networks[i]; + const chainId: keyof typeof chainIdToRpc = network.chainId; + const rpc = chainIdToRpc[chainId]; + if (rpc) { + const provider = new ethers.JsonRpcProvider(rpc); + const wallet = ethers.Wallet.fromPhrase(mnemonic, provider); + wallets.push(wallet); + } + } + return wallets; +} + +export async function sendPauseTransactions(networks: any, wallets: any) { + const receipts = []; + for (let i = 0; i < networks.length; i++) { + const network = networks[i]; + const wallet = wallets[i]; + const bridge = await getBridgeContractInstance(network, wallet) + const tx = await bridge.pause(); + const receipt = await tx.wait(); + console.log(`Transaction no. ${i+1} completed, bridge on ${network.name} paused`); + receipts.push(receipt); + } + return receipts; +} + +async function getBridgeContractInstance(network: any, wallet: ethers.Wallet) { + const bridge = new ethers.Contract(network.bridge, bridgeAbi, wallet); + return bridge; +} \ No newline at end of file diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 791a21f..000327d 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -8,6 +8,6 @@ "declaration": true, "esModuleInterop": true, "module": "commonjs", - "outDir": "./dis-cjs" + "outDir": "./dist-cjs" } } diff --git a/types/constants.d.ts b/types/constants.d.ts index 8b288de..df66f52 100644 --- a/types/constants.d.ts +++ b/types/constants.d.ts @@ -3,4 +3,8 @@ export declare const ConfigUrl: { testnet: string; mainnet: string; }; +export declare const chainIdToRpc: { + 5: string; +}; +export declare const bridgeAbi: never[]; //# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/types/constants.d.ts.map b/types/constants.d.ts.map index 66f6ca6..613b04d 100644 --- a/types/constants.d.ts.map +++ b/types/constants.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA"} \ No newline at end of file +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA;AAED,eAAO,MAAM,SAAS,SAErB,CAAA"} \ No newline at end of file diff --git a/types/utils.d.ts b/types/utils.d.ts new file mode 100644 index 0000000..dc7d459 --- /dev/null +++ b/types/utils.d.ts @@ -0,0 +1,5 @@ +import { ethers } from 'ethers'; +export declare function getWalletsForDifferentProviders(privateKey: string, networks: any): Promise; +export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: any): Promise; +export declare function sendPauseTransactions(networks: any, wallets: any): Promise; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/types/utils.d.ts.map b/types/utils.d.ts.map new file mode 100644 index 0000000..b435a51 --- /dev/null +++ b/types/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAG9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,4BAatF;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,kCAa9E;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,kBAYtE"} \ No newline at end of file From 7ec9441658b282742f3f251015decf1bfa9a833c Mon Sep 17 00:00:00 2001 From: Matej DB Date: Tue, 11 Jul 2023 13:21:18 +0200 Subject: [PATCH 02/10] key fix --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index a4ec1b5..dfe5a68 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,7 @@ "build:all": "yarn build:cjs && yarn build:types", "lint": "eslint 'src/**/*.ts'", "lint:fix": "yarn run lint --fix", - "clean": "rm -rf ./dist ./dist-cjs ./dist-esm ./types", - "build-and-test": "yarn run build:all && node ./dist-cjs/bridgePausing.js pause 95be8d0ee6436056dbabfdb2da70585a7baf23ceca320304a600c94e67f507f5 testnet" + "clean": "rm -rf ./dist ./dist-cjs ./dist-esm ./types" }, "keywords": [], "author": "Sygma Protocol Product Team", From d415d4c21e3f46004928d1483561fa3730fe4a0d Mon Sep 17 00:00:00 2001 From: Matej DB Date: Tue, 11 Jul 2023 16:16:47 +0200 Subject: [PATCH 03/10] adding some typescript types --- src/bridgePausing.ts | 3 ++- src/utils.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 5a14322..6a59182 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -2,6 +2,7 @@ import axios from 'axios'; import {Command, Option} from 'commander'; import {ConfigUrl} from "./constants"; import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; +import {HDNodeVoidWallet, ethers} from 'ethers'; const program = new Command(); @@ -33,7 +34,7 @@ program const response = await axios.get(ConfigUrl[network]) as any; const networks = response.data.domains.filter((network: any) => network.type === "evm"); // just evms for now - let wallets: any = []; + let wallets: Array = []; if (mnemonic) { wallets = await deriveWalletsFromMnemonic(mnemonic, networks); diff --git a/src/utils.ts b/src/utils.ts index f19dab8..e79f8d4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import {ethers} from 'ethers'; import {chainIdToRpc, bridgeAbi} from "./constants"; -export async function getWalletsForDifferentProviders(privateKey: string, networks: any) { +export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { const wallets = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; @@ -16,7 +16,7 @@ export async function getWalletsForDifferentProviders(privateKey: string, networ return wallets; } -export async function deriveWalletsFromMnemonic(mnemonic: string, networks: any) { +export async function deriveWalletsFromMnemonic(mnemonic: string, networks: Array) { const wallets = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; @@ -31,7 +31,7 @@ export async function deriveWalletsFromMnemonic(mnemonic: string, networks: any) return wallets; } -export async function sendPauseTransactions(networks: any, wallets: any) { +export async function sendPauseTransactions(networks: Array, wallets: Array) { const receipts = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; From 8df9c465f17f3f338efcdb0c121c5a42827aad09 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Tue, 11 Jul 2023 16:17:43 +0200 Subject: [PATCH 04/10] fixing some bugs --- src/bridgePausing.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 6a59182..b9619a0 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -2,7 +2,7 @@ import axios from 'axios'; import {Command, Option} from 'commander'; import {ConfigUrl} from "./constants"; import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; -import {HDNodeVoidWallet, ethers} from 'ethers'; +import {ethers} from 'ethers'; const program = new Command(); @@ -34,7 +34,7 @@ program const response = await axios.get(ConfigUrl[network]) as any; const networks = response.data.domains.filter((network: any) => network.type === "evm"); // just evms for now - let wallets: Array = []; + let wallets: Array = []; if (mnemonic) { wallets = await deriveWalletsFromMnemonic(mnemonic, networks); From 0a8b2a095fc59c5387ab0ab4c650239fb03bf5f8 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Tue, 11 Jul 2023 16:57:50 +0200 Subject: [PATCH 05/10] added bridge abi --- abis/bridgeAbi.ts | 789 +++++++++++++++++++++++++++++++++++++++++++ src/bridgePausing.ts | 1 - src/constants.ts | 4 - src/utils.ts | 5 +- 4 files changed, 792 insertions(+), 7 deletions(-) create mode 100644 abis/bridgeAbi.ts diff --git a/abis/bridgeAbi.ts b/abis/bridgeAbi.ts new file mode 100644 index 0000000..057394f --- /dev/null +++ b/abis/bridgeAbi.ts @@ -0,0 +1,789 @@ +export const bridgeAbi = [ + { + "inputs": [ + { + "internalType": "uint8", + "name": "domainID", + "type": "uint8" + }, + { + "internalType": "address", + "name": "accessControl", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "bytes4", + "name": "funcSig", + "type": "bytes4" + } + ], + "name": "AccessNotAllowed", + "type": "error" + }, + { + "inputs": [], + "name": "DepositToCurrentDomain", + "type": "error" + }, + { + "inputs": [], + "name": "EmptyProposalsArray", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidProposalSigner", + "type": "error" + }, + { + "inputs": [], + "name": "MPCAddressAlreadySet", + "type": "error" + }, + { + "inputs": [], + "name": "MPCAddressIsNotUpdatable", + "type": "error" + }, + { + "inputs": [], + "name": "MPCAddressNotSet", + "type": "error" + }, + { + "inputs": [], + "name": "MPCAddressZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "NonceDecrementsNotAllowed", + "type": "error" + }, + { + "inputs": [], + "name": "ResourceIDNotMappedToHandler", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "newAccessControl", + "type": "address" + } + ], + "name": "AccessControlChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "destinationDomainID", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "handlerResponse", + "type": "bytes" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "EndKeygen", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes", + "name": "lowLevelData", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "originDomainID", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + } + ], + "name": "FailedHandlerExecution", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "newFeeHandler", + "type": "address" + } + ], + "name": "FeeHandlerChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "hash", + "type": "string" + } + ], + "name": "KeyRefresh", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "originDomainID", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "dataHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "handlerResponse", + "type": "bytes" + } + ], + "name": "ProposalExecution", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "txHash", + "type": "string" + } + ], + "name": "Retry", + "type": "event" + }, + { + "anonymous": false, + "inputs": [], + "name": "StartKeygen", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "_MPCAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "_accessControl", + "outputs": [ + { + "internalType": "contract IAccessControlSegregator", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "_depositCounts", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "_domainID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "_feeHandler", + "outputs": [ + { + "internalType": "contract IFeeHandler", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "_resourceIDToHandlerAddress", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "isValidForwarder", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "usedNonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "adminPauseTransfers", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "adminUnpauseTransfers", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "handlerAddress", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "contractAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "args", + "type": "bytes" + } + ], + "name": "adminSetResource", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "handlerAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + } + ], + "name": "adminSetBurnable", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "domainID", + "type": "uint8" + }, + { + "internalType": "uint64", + "name": "nonce", + "type": "uint64" + } + ], + "name": "adminSetDepositNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "forwarder", + "type": "address" + }, + { + "internalType": "bool", + "name": "valid", + "type": "bool" + } + ], + "name": "adminSetForwarder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newAccessControl", + "type": "address" + } + ], + "name": "adminChangeAccessControl", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newFeeHandler", + "type": "address" + } + ], + "name": "adminChangeFeeHandler", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "handlerAddress", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "adminWithdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "destinationDomainID", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "depositData", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "feeData", + "type": "bytes" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "internalType": "bytes", + "name": "handlerResponse", + "type": "bytes" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "originDomainID", + "type": "uint8" + }, + { + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "internalType": "struct Bridge.Proposal", + "name": "proposal", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "executeProposal", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "originDomainID", + "type": "uint8" + }, + { + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "internalType": "struct Bridge.Proposal[]", + "name": "proposals", + "type": "tuple[]" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "executeProposals", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "startKeygen", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "MPCAddress", + "type": "address" + } + ], + "name": "endKeygen", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "hash", + "type": "string" + } + ], + "name": "refreshKey", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "txHash", + "type": "string" + } + ], + "name": "retry", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "domainID", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "depositNonce", + "type": "uint256" + } + ], + "name": "isProposalExecuted", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "originDomainID", + "type": "uint8" + }, + { + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "internalType": "struct Bridge.Proposal[]", + "name": "proposals", + "type": "tuple[]" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "verify", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } + ] \ No newline at end of file diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index b9619a0..7e758c4 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -2,7 +2,6 @@ import axios from 'axios'; import {Command, Option} from 'commander'; import {ConfigUrl} from "./constants"; import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; -import {ethers} from 'ethers'; const program = new Command(); diff --git a/src/constants.ts b/src/constants.ts index c9db7ad..985599f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -9,7 +9,3 @@ export const chainIdToRpc = { 5: "https://goerli.infura.io/v3/" } -export const bridgeAbi = [ - -] - diff --git a/src/utils.ts b/src/utils.ts index e79f8d4..85ee2db 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ import {ethers} from 'ethers'; -import {chainIdToRpc, bridgeAbi} from "./constants"; +import {chainIdToRpc} from "./constants"; +import {bridgeAbi} from "../abis/bridgeAbi"; export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { const wallets = []; @@ -37,7 +38,7 @@ export async function sendPauseTransactions(networks: Array, wallets: Array const network = networks[i]; const wallet = wallets[i]; const bridge = await getBridgeContractInstance(network, wallet) - const tx = await bridge.pause(); + const tx = await bridge.adminPauseTransfers(); const receipt = await tx.wait(); console.log(`Transaction no. ${i+1} completed, bridge on ${network.name} paused`); receipts.push(receipt); From 795fc7941c3227f09636a8ae25559a6bc35fd1e5 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Wed, 12 Jul 2023 12:50:54 +0200 Subject: [PATCH 06/10] comments regarding typescript types --- abis/bridgeAbi.ts | 789 ------------------------------- src/bridgePausing.ts | 12 +- src/utils.ts | 14 +- types/abis/bridgeAbi.d.ts | 61 +++ types/abis/bridgeAbi.d.ts.map | 1 + types/constants.d.ts | 1 - types/constants.d.ts.map | 2 +- types/src/bridgePausing.d.ts | 2 + types/src/bridgePausing.d.ts.map | 1 + types/src/constants.d.ts | 9 + types/src/constants.d.ts.map | 1 + types/src/index.d.ts | 2 + types/src/index.d.ts.map | 1 + types/src/utils.d.ts | 5 + types/src/utils.d.ts.map | 1 + types/utils.d.ts | 6 +- types/utils.d.ts.map | 2 +- 17 files changed, 102 insertions(+), 808 deletions(-) delete mode 100644 abis/bridgeAbi.ts create mode 100644 types/abis/bridgeAbi.d.ts create mode 100644 types/abis/bridgeAbi.d.ts.map create mode 100644 types/src/bridgePausing.d.ts create mode 100644 types/src/bridgePausing.d.ts.map create mode 100644 types/src/constants.d.ts create mode 100644 types/src/constants.d.ts.map create mode 100644 types/src/index.d.ts create mode 100644 types/src/index.d.ts.map create mode 100644 types/src/utils.d.ts create mode 100644 types/src/utils.d.ts.map diff --git a/abis/bridgeAbi.ts b/abis/bridgeAbi.ts deleted file mode 100644 index 057394f..0000000 --- a/abis/bridgeAbi.ts +++ /dev/null @@ -1,789 +0,0 @@ -export const bridgeAbi = [ - { - "inputs": [ - { - "internalType": "uint8", - "name": "domainID", - "type": "uint8" - }, - { - "internalType": "address", - "name": "accessControl", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "bytes4", - "name": "funcSig", - "type": "bytes4" - } - ], - "name": "AccessNotAllowed", - "type": "error" - }, - { - "inputs": [], - "name": "DepositToCurrentDomain", - "type": "error" - }, - { - "inputs": [], - "name": "EmptyProposalsArray", - "type": "error" - }, - { - "inputs": [], - "name": "InvalidProposalSigner", - "type": "error" - }, - { - "inputs": [], - "name": "MPCAddressAlreadySet", - "type": "error" - }, - { - "inputs": [], - "name": "MPCAddressIsNotUpdatable", - "type": "error" - }, - { - "inputs": [], - "name": "MPCAddressNotSet", - "type": "error" - }, - { - "inputs": [], - "name": "MPCAddressZeroAddress", - "type": "error" - }, - { - "inputs": [], - "name": "NonceDecrementsNotAllowed", - "type": "error" - }, - { - "inputs": [], - "name": "ResourceIDNotMappedToHandler", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "newAccessControl", - "type": "address" - } - ], - "name": "AccessControlChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "destinationDomainID", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "indexed": true, - "internalType": "address", - "name": "user", - "type": "address" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "data", - "type": "bytes" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "handlerResponse", - "type": "bytes" - } - ], - "name": "Deposit", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "EndKeygen", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "bytes", - "name": "lowLevelData", - "type": "bytes" - }, - { - "indexed": false, - "internalType": "uint8", - "name": "originDomainID", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - } - ], - "name": "FailedHandlerExecution", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "newFeeHandler", - "type": "address" - } - ], - "name": "FeeHandlerChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "hash", - "type": "string" - } - ], - "name": "KeyRefresh", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "originDomainID", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "indexed": false, - "internalType": "bytes32", - "name": "dataHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "handlerResponse", - "type": "bytes" - } - ], - "name": "ProposalExecution", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "txHash", - "type": "string" - } - ], - "name": "Retry", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "StartKeygen", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "inputs": [], - "name": "_MPCAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_accessControl", - "outputs": [ - { - "internalType": "contract IAccessControlSegregator", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "_depositCounts", - "outputs": [ - { - "internalType": "uint64", - "name": "", - "type": "uint64" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_domainID", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_feeHandler", - "outputs": [ - { - "internalType": "contract IFeeHandler", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "_resourceIDToHandlerAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "isValidForwarder", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "usedNonces", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "adminPauseTransfers", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "adminUnpauseTransfers", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "handlerAddress", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "contractAddress", - "type": "address" - }, - { - "internalType": "bytes", - "name": "args", - "type": "bytes" - } - ], - "name": "adminSetResource", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "handlerAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - } - ], - "name": "adminSetBurnable", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "domainID", - "type": "uint8" - }, - { - "internalType": "uint64", - "name": "nonce", - "type": "uint64" - } - ], - "name": "adminSetDepositNonce", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "forwarder", - "type": "address" - }, - { - "internalType": "bool", - "name": "valid", - "type": "bool" - } - ], - "name": "adminSetForwarder", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newAccessControl", - "type": "address" - } - ], - "name": "adminChangeAccessControl", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newFeeHandler", - "type": "address" - } - ], - "name": "adminChangeFeeHandler", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "handlerAddress", - "type": "address" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "adminWithdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "destinationDomainID", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "depositData", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "feeData", - "type": "bytes" - } - ], - "name": "deposit", - "outputs": [ - { - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "internalType": "bytes", - "name": "handlerResponse", - "type": "bytes" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "originDomainID", - "type": "uint8" - }, - { - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "internalType": "struct Bridge.Proposal", - "name": "proposal", - "type": "tuple" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "executeProposal", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "originDomainID", - "type": "uint8" - }, - { - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "internalType": "struct Bridge.Proposal[]", - "name": "proposals", - "type": "tuple[]" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "executeProposals", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "startKeygen", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "MPCAddress", - "type": "address" - } - ], - "name": "endKeygen", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "hash", - "type": "string" - } - ], - "name": "refreshKey", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "txHash", - "type": "string" - } - ], - "name": "retry", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "domainID", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "depositNonce", - "type": "uint256" - } - ], - "name": "isProposalExecuted", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "originDomainID", - "type": "uint8" - }, - { - "internalType": "uint64", - "name": "depositNonce", - "type": "uint64" - }, - { - "internalType": "bytes32", - "name": "resourceID", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "internalType": "struct Bridge.Proposal[]", - "name": "proposals", - "type": "tuple[]" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "verify", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - } - ] \ No newline at end of file diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 7e758c4..2b0eb91 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -1,7 +1,9 @@ import axios from 'axios'; +import {ethers} from 'ethers'; import {Command, Option} from 'commander'; import {ConfigUrl} from "./constants"; import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; +import {RawConfig, Domain} from '@buildwithsygma/sygma-sdk-core'; const program = new Command(); @@ -30,10 +32,14 @@ program mnemonic } = configs; - const response = await axios.get(ConfigUrl[network]) as any; - const networks = response.data.domains.filter((network: any) => network.type === "evm"); // just evms for now + const { + data + } = await axios.get(ConfigUrl[network]) as unknown as {data: RawConfig}; + + + const networks = data.domains.filter((network: Domain) => network.name === "ethereum"); // just evms for now - let wallets: Array = []; + let wallets: Array = []; if (mnemonic) { wallets = await deriveWalletsFromMnemonic(mnemonic, networks); diff --git a/src/utils.ts b/src/utils.ts index 85ee2db..052b325 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,6 @@ import {ethers} from 'ethers'; import {chainIdToRpc} from "./constants"; -import {bridgeAbi} from "../abis/bridgeAbi"; +import {Bridge__factory} from "@buildwithsygma/sygma-contracts"; export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { const wallets = []; @@ -32,21 +32,15 @@ export async function deriveWalletsFromMnemonic(mnemonic: string, networks: Arra return wallets; } -export async function sendPauseTransactions(networks: Array, wallets: Array) { +export async function sendPauseTransactions(networks: Array, wallets: Array) { const receipts = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; const wallet = wallets[i]; - const bridge = await getBridgeContractInstance(network, wallet) + const bridge = Bridge__factory.connect(network.bridge, wallet); const tx = await bridge.adminPauseTransfers(); - const receipt = await tx.wait(); console.log(`Transaction no. ${i+1} completed, bridge on ${network.name} paused`); - receipts.push(receipt); + receipts.push(tx); } return receipts; } - -async function getBridgeContractInstance(network: any, wallet: ethers.Wallet) { - const bridge = new ethers.Contract(network.bridge, bridgeAbi, wallet); - return bridge; -} \ No newline at end of file diff --git a/types/abis/bridgeAbi.d.ts b/types/abis/bridgeAbi.d.ts new file mode 100644 index 0000000..fd3b5b3 --- /dev/null +++ b/types/abis/bridgeAbi.d.ts @@ -0,0 +1,61 @@ +export declare const bridgeAbi: ({ + inputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + name?: undefined; + anonymous?: undefined; + outputs?: undefined; +} | { + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name: string; + type: string; + stateMutability?: undefined; + anonymous?: undefined; + outputs?: undefined; +} | { + anonymous: boolean; + inputs: { + indexed: boolean; + internalType: string; + name: string; + type: string; + }[]; + name: string; + type: string; + stateMutability?: undefined; + outputs?: undefined; +} | { + inputs: ({ + components: { + internalType: string; + name: string; + type: string; + }[]; + internalType: string; + name: string; + type: string; + } | { + internalType: string; + name: string; + type: string; + components?: undefined; + })[]; + name: string; + outputs: { + internalType: string; + name: string; + type: string; + }[]; + stateMutability: string; + type: string; + anonymous?: undefined; +})[]; +//# sourceMappingURL=bridgeAbi.d.ts.map \ No newline at end of file diff --git a/types/abis/bridgeAbi.d.ts.map b/types/abis/bridgeAbi.d.ts.map new file mode 100644 index 0000000..e74ea0f --- /dev/null +++ b/types/abis/bridgeAbi.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bridgeAbi.d.ts","sourceRoot":"","sources":["../../abis/bridgeAbi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoxBnB,CAAA"} \ No newline at end of file diff --git a/types/constants.d.ts b/types/constants.d.ts index df66f52..bd14f86 100644 --- a/types/constants.d.ts +++ b/types/constants.d.ts @@ -6,5 +6,4 @@ export declare const ConfigUrl: { export declare const chainIdToRpc: { 5: string; }; -export declare const bridgeAbi: never[]; //# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/types/constants.d.ts.map b/types/constants.d.ts.map index 613b04d..6d14c37 100644 --- a/types/constants.d.ts.map +++ b/types/constants.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA;AAED,eAAO,MAAM,SAAS,SAErB,CAAA"} \ No newline at end of file +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA"} \ No newline at end of file diff --git a/types/src/bridgePausing.d.ts b/types/src/bridgePausing.d.ts new file mode 100644 index 0000000..c67a35a --- /dev/null +++ b/types/src/bridgePausing.d.ts @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=bridgePausing.d.ts.map \ No newline at end of file diff --git a/types/src/bridgePausing.d.ts.map b/types/src/bridgePausing.d.ts.map new file mode 100644 index 0000000..6d6d77c --- /dev/null +++ b/types/src/bridgePausing.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bridgePausing.d.ts","sourceRoot":"","sources":["../../src/bridgePausing.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/types/src/constants.d.ts b/types/src/constants.d.ts new file mode 100644 index 0000000..bd14f86 --- /dev/null +++ b/types/src/constants.d.ts @@ -0,0 +1,9 @@ +export declare const ConfigUrl: { + devnet: string; + testnet: string; + mainnet: string; +}; +export declare const chainIdToRpc: { + 5: string; +}; +//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/types/src/constants.d.ts.map b/types/src/constants.d.ts.map new file mode 100644 index 0000000..63693dd --- /dev/null +++ b/types/src/constants.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA"} \ No newline at end of file diff --git a/types/src/index.d.ts b/types/src/index.d.ts new file mode 100644 index 0000000..646da0f --- /dev/null +++ b/types/src/index.d.ts @@ -0,0 +1,2 @@ +export * from "bridgePausing"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/types/src/index.d.ts.map b/types/src/index.d.ts.map new file mode 100644 index 0000000..3a2fe1c --- /dev/null +++ b/types/src/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"} \ No newline at end of file diff --git a/types/src/utils.d.ts b/types/src/utils.d.ts new file mode 100644 index 0000000..1936b61 --- /dev/null +++ b/types/src/utils.d.ts @@ -0,0 +1,5 @@ +import { ethers } from 'ethers'; +export declare function getWalletsForDifferentProviders(privateKey: string, networks: Array): Promise; +export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: Array): Promise; +export declare function sendPauseTransactions(networks: Array, wallets: Array): Promise; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/types/src/utils.d.ts.map b/types/src/utils.d.ts.map new file mode 100644 index 0000000..e11f0ff --- /dev/null +++ b/types/src/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAI9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,4BAa7F;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,kCAarF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,kBAY9F"} \ No newline at end of file diff --git a/types/utils.d.ts b/types/utils.d.ts index dc7d459..218dc5f 100644 --- a/types/utils.d.ts +++ b/types/utils.d.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -export declare function getWalletsForDifferentProviders(privateKey: string, networks: any): Promise; -export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: any): Promise; -export declare function sendPauseTransactions(networks: any, wallets: any): Promise; +export declare function getWalletsForDifferentProviders(privateKey: string, networks: Array): Promise; +export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: Array): Promise; +export declare function sendPauseTransactions(networks: Array, wallets: Array): Promise; //# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/types/utils.d.ts.map b/types/utils.d.ts.map index b435a51..f765207 100644 --- a/types/utils.d.ts.map +++ b/types/utils.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAG9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,4BAatF;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,kCAa9E;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,kBAYtE"} \ No newline at end of file +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAI9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,4BAa7F;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,kCAarF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,yCAW9F"} \ No newline at end of file From e7e03ad14203d4e3beb1c35c719664a62c44e843 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Wed, 12 Jul 2023 13:02:32 +0200 Subject: [PATCH 07/10] adding more types --- src/bridgePausing.ts | 2 +- src/utils.ts | 13 +++++++------ types/utils.d.ts | 7 ++++--- types/utils.d.ts.map | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 2b0eb91..9d26f67 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -37,7 +37,7 @@ program } = await axios.get(ConfigUrl[network]) as unknown as {data: RawConfig}; - const networks = data.domains.filter((network: Domain) => network.name === "ethereum"); // just evms for now + const networks: Array = data.domains.filter((network: Domain) => network.name === "ethereum"); // just evms for now let wallets: Array = []; diff --git a/src/utils.ts b/src/utils.ts index 052b325..5bcff0c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,13 +1,14 @@ import {ethers} from 'ethers'; import {chainIdToRpc} from "./constants"; import {Bridge__factory} from "@buildwithsygma/sygma-contracts"; +import {Domain} from "@buildwithsygma/sygma-sdk-core"; -export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { +export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { const wallets = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; - const chainId: keyof typeof chainIdToRpc = network.chainId; - const rpc = chainIdToRpc[chainId]; + const chainId = network.chainId; + const rpc = chainIdToRpc[chainId as keyof typeof chainIdToRpc]; if (rpc) { const provider = new ethers.JsonRpcProvider(rpc); const wallet = new ethers.Wallet(privateKey, provider); // add error handling for invalid private key @@ -17,12 +18,12 @@ export async function getWalletsForDifferentProviders(privateKey: string, networ return wallets; } -export async function deriveWalletsFromMnemonic(mnemonic: string, networks: Array) { +export async function deriveWalletsFromMnemonic(mnemonic: string, networks: Array) { const wallets = []; for (let i = 0; i < networks.length; i++) { const network = networks[i]; - const chainId: keyof typeof chainIdToRpc = network.chainId; - const rpc = chainIdToRpc[chainId]; + const chainId = network.chainId; + const rpc = chainIdToRpc[chainId as keyof typeof chainIdToRpc]; if (rpc) { const provider = new ethers.JsonRpcProvider(rpc); const wallet = ethers.Wallet.fromPhrase(mnemonic, provider); diff --git a/types/utils.d.ts b/types/utils.d.ts index 218dc5f..b86cc75 100644 --- a/types/utils.d.ts +++ b/types/utils.d.ts @@ -1,5 +1,6 @@ import { ethers } from 'ethers'; -export declare function getWalletsForDifferentProviders(privateKey: string, networks: Array): Promise; -export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: Array): Promise; -export declare function sendPauseTransactions(networks: Array, wallets: Array): Promise; +import { Domain } from "@buildwithsygma/sygma-sdk-core"; +export declare function getWalletsForDifferentProviders(privateKey: string, networks: Array): Promise; +export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: Array): Promise; +export declare function sendPauseTransactions(networks: Array, wallets: Array): Promise; //# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/types/utils.d.ts.map b/types/utils.d.ts.map index f765207..09a97e7 100644 --- a/types/utils.d.ts.map +++ b/types/utils.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAI9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,4BAa7F;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,kCAarF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,yCAW9F"} \ No newline at end of file +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAC,MAAM,EAAC,MAAM,gCAAgC,CAAC;AAEtD,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,4BAahG;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,kCAaxF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,yCAWpH"} \ No newline at end of file From 9b28408e0097a7577a9e45ec5a81cc15b24c05c8 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Wed, 12 Jul 2023 13:06:03 +0200 Subject: [PATCH 08/10] changing types to reflect update --- types/abis/bridgeAbi.d.ts | 61 -------------------------------- types/abis/bridgeAbi.d.ts.map | 1 - types/src/bridgePausing.d.ts | 2 -- types/src/bridgePausing.d.ts.map | 1 - types/src/constants.d.ts | 9 ----- types/src/constants.d.ts.map | 1 - types/src/index.d.ts | 2 -- types/src/index.d.ts.map | 1 - types/src/utils.d.ts | 5 --- types/src/utils.d.ts.map | 1 - 10 files changed, 84 deletions(-) delete mode 100644 types/abis/bridgeAbi.d.ts delete mode 100644 types/abis/bridgeAbi.d.ts.map delete mode 100644 types/src/bridgePausing.d.ts delete mode 100644 types/src/bridgePausing.d.ts.map delete mode 100644 types/src/constants.d.ts delete mode 100644 types/src/constants.d.ts.map delete mode 100644 types/src/index.d.ts delete mode 100644 types/src/index.d.ts.map delete mode 100644 types/src/utils.d.ts delete mode 100644 types/src/utils.d.ts.map diff --git a/types/abis/bridgeAbi.d.ts b/types/abis/bridgeAbi.d.ts deleted file mode 100644 index fd3b5b3..0000000 --- a/types/abis/bridgeAbi.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -export declare const bridgeAbi: ({ - inputs: { - internalType: string; - name: string; - type: string; - }[]; - stateMutability: string; - type: string; - name?: undefined; - anonymous?: undefined; - outputs?: undefined; -} | { - inputs: { - internalType: string; - name: string; - type: string; - }[]; - name: string; - type: string; - stateMutability?: undefined; - anonymous?: undefined; - outputs?: undefined; -} | { - anonymous: boolean; - inputs: { - indexed: boolean; - internalType: string; - name: string; - type: string; - }[]; - name: string; - type: string; - stateMutability?: undefined; - outputs?: undefined; -} | { - inputs: ({ - components: { - internalType: string; - name: string; - type: string; - }[]; - internalType: string; - name: string; - type: string; - } | { - internalType: string; - name: string; - type: string; - components?: undefined; - })[]; - name: string; - outputs: { - internalType: string; - name: string; - type: string; - }[]; - stateMutability: string; - type: string; - anonymous?: undefined; -})[]; -//# sourceMappingURL=bridgeAbi.d.ts.map \ No newline at end of file diff --git a/types/abis/bridgeAbi.d.ts.map b/types/abis/bridgeAbi.d.ts.map deleted file mode 100644 index e74ea0f..0000000 --- a/types/abis/bridgeAbi.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"bridgeAbi.d.ts","sourceRoot":"","sources":["../../abis/bridgeAbi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoxBnB,CAAA"} \ No newline at end of file diff --git a/types/src/bridgePausing.d.ts b/types/src/bridgePausing.d.ts deleted file mode 100644 index c67a35a..0000000 --- a/types/src/bridgePausing.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=bridgePausing.d.ts.map \ No newline at end of file diff --git a/types/src/bridgePausing.d.ts.map b/types/src/bridgePausing.d.ts.map deleted file mode 100644 index 6d6d77c..0000000 --- a/types/src/bridgePausing.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"bridgePausing.d.ts","sourceRoot":"","sources":["../../src/bridgePausing.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/types/src/constants.d.ts b/types/src/constants.d.ts deleted file mode 100644 index bd14f86..0000000 --- a/types/src/constants.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export declare const ConfigUrl: { - devnet: string; - testnet: string; - mainnet: string; -}; -export declare const chainIdToRpc: { - 5: string; -}; -//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/types/src/constants.d.ts.map b/types/src/constants.d.ts.map deleted file mode 100644 index 63693dd..0000000 --- a/types/src/constants.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA"} \ No newline at end of file diff --git a/types/src/index.d.ts b/types/src/index.d.ts deleted file mode 100644 index 646da0f..0000000 --- a/types/src/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "bridgePausing"; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/types/src/index.d.ts.map b/types/src/index.d.ts.map deleted file mode 100644 index 3a2fe1c..0000000 --- a/types/src/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"} \ No newline at end of file diff --git a/types/src/utils.d.ts b/types/src/utils.d.ts deleted file mode 100644 index 1936b61..0000000 --- a/types/src/utils.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ethers } from 'ethers'; -export declare function getWalletsForDifferentProviders(privateKey: string, networks: Array): Promise; -export declare function deriveWalletsFromMnemonic(mnemonic: string, networks: Array): Promise; -export declare function sendPauseTransactions(networks: Array, wallets: Array): Promise; -//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/types/src/utils.d.ts.map b/types/src/utils.d.ts.map deleted file mode 100644 index e11f0ff..0000000 --- a/types/src/utils.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAI9B,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,4BAa7F;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,kCAarF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,kBAY9F"} \ No newline at end of file From 615f4fb6988236421c6ac1759d970cd68621aea3 Mon Sep 17 00:00:00 2001 From: Matej DB Date: Wed, 12 Jul 2023 16:48:44 +0200 Subject: [PATCH 09/10] moving constants to a separate folder --- .env.example | 1 + src/bridgePausing.ts | 20 +++++++------- src/constants.ts | 11 -------- src/constants/index.ts | 2 ++ src/constants/rpc.ts | 5 ++++ src/constants/sharedConfig.ts | 5 ++++ src/utils.ts | 40 +++++++++++++-------------- types/bridgePausing.d.ts | 2 +- types/bridgePausing.d.ts.map | 2 +- types/constants.d.ts | 9 ------ types/constants.d.ts.map | 1 - types/constants/index.d.ts | 3 ++ types/constants/index.d.ts.map | 1 + types/constants/rpc.d.ts | 4 +++ types/constants/rpc.d.ts.map | 1 + types/constants/sharedConfig.d.ts | 6 ++++ types/constants/sharedConfig.d.ts.map | 1 + types/utils.d.ts.map | 2 +- yarn.lock | 8 ++++++ 19 files changed, 70 insertions(+), 54 deletions(-) create mode 100644 .env.example delete mode 100644 src/constants.ts create mode 100644 src/constants/index.ts create mode 100644 src/constants/rpc.ts create mode 100644 src/constants/sharedConfig.ts delete mode 100644 types/constants.d.ts delete mode 100644 types/constants.d.ts.map create mode 100644 types/constants/index.d.ts create mode 100644 types/constants/index.d.ts.map create mode 100644 types/constants/rpc.d.ts create mode 100644 types/constants/rpc.d.ts.map create mode 100644 types/constants/sharedConfig.d.ts create mode 100644 types/constants/sharedConfig.d.ts.map diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..fccb414 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +GOERLI_RPC_URL= diff --git a/src/bridgePausing.ts b/src/bridgePausing.ts index 9d26f67..d6a44fe 100644 --- a/src/bridgePausing.ts +++ b/src/bridgePausing.ts @@ -1,9 +1,10 @@ +import 'dotenv/config'; import axios from 'axios'; -import {ethers} from 'ethers'; -import {Command, Option} from 'commander'; -import {ConfigUrl} from "./constants"; -import {getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions} from "./utils"; -import {RawConfig, Domain} from '@buildwithsygma/sygma-sdk-core'; +import { ethers } from 'ethers'; +import { Command, Option } from 'commander'; +import { SharedConfig } from "./constants"; +import { getWalletsForDifferentProviders, deriveWalletsFromMnemonic, sendPauseTransactions } from "./utils"; +import { RawConfig, Domain } from '@buildwithsygma/sygma-sdk-core'; const program = new Command(); @@ -26,7 +27,7 @@ program ) .action(async (configs: any) => { try { - const network: keyof typeof ConfigUrl = configs.environment; + const network: keyof typeof SharedConfig = configs.environment; const { privateKey, mnemonic @@ -34,9 +35,8 @@ program const { data - } = await axios.get(ConfigUrl[network]) as unknown as {data: RawConfig}; - - + } = await axios.get(SharedConfig[network]) as unknown as { data: RawConfig }; + const networks: Array = data.domains.filter((network: Domain) => network.name === "ethereum"); // just evms for now let wallets: Array = []; @@ -50,7 +50,7 @@ program } await sendPauseTransactions(networks, wallets); - + } catch (err) { if (err instanceof Error) { throw new Error(`Failed to fetch shared config because of: ${err.message}`); diff --git a/src/constants.ts b/src/constants.ts deleted file mode 100644 index 985599f..0000000 --- a/src/constants.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const ConfigUrl = { - devnet: "https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-dev.json", - testnet: "https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json", - mainnet: "https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json" -} - -// chain id -> provider url -export const chainIdToRpc = { - 5: "https://goerli.infura.io/v3/" -} - diff --git a/src/constants/index.ts b/src/constants/index.ts new file mode 100644 index 0000000..3275969 --- /dev/null +++ b/src/constants/index.ts @@ -0,0 +1,2 @@ +export { chainIdToRpc } from "./rpc"; +export { SharedConfig } from "./sharedConfig"; diff --git a/src/constants/rpc.ts b/src/constants/rpc.ts new file mode 100644 index 0000000..557d2dc --- /dev/null +++ b/src/constants/rpc.ts @@ -0,0 +1,5 @@ +// chain id -> provider url +export const chainIdToRpc = { + 5: process.env.GOERLI_RPC_URL, +} + diff --git a/src/constants/sharedConfig.ts b/src/constants/sharedConfig.ts new file mode 100644 index 0000000..fbdc482 --- /dev/null +++ b/src/constants/sharedConfig.ts @@ -0,0 +1,5 @@ +export const SharedConfig = { + devnet: "https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-dev.json", + testnet: "https://chainbridge-assets-stage.s3.us-east-2.amazonaws.com/shared-config-test.json", + mainnet: "https://sygma-assets-mainnet.s3.us-east-2.amazonaws.com/shared-config-mainnet.json" +}; diff --git a/src/utils.ts b/src/utils.ts index 5bcff0c..9a69c85 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ -import {ethers} from 'ethers'; -import {chainIdToRpc} from "./constants"; -import {Bridge__factory} from "@buildwithsygma/sygma-contracts"; -import {Domain} from "@buildwithsygma/sygma-sdk-core"; +import { ethers } from 'ethers'; +import { chainIdToRpc } from "./constants"; +import { Bridge__factory } from "@buildwithsygma/sygma-contracts"; +import { Domain } from "@buildwithsygma/sygma-sdk-core"; export async function getWalletsForDifferentProviders(privateKey: string, networks: Array) { const wallets = []; @@ -10,9 +10,9 @@ export async function getWalletsForDifferentProviders(privateKey: string, networ const chainId = network.chainId; const rpc = chainIdToRpc[chainId as keyof typeof chainIdToRpc]; if (rpc) { - const provider = new ethers.JsonRpcProvider(rpc); - const wallet = new ethers.Wallet(privateKey, provider); // add error handling for invalid private key - wallets.push(wallet); + const provider = new ethers.JsonRpcProvider(rpc); + const wallet = new ethers.Wallet(privateKey, provider); // add error handling for invalid private key + wallets.push(wallet); } } return wallets; @@ -25,23 +25,23 @@ export async function deriveWalletsFromMnemonic(mnemonic: string, networks: Arra const chainId = network.chainId; const rpc = chainIdToRpc[chainId as keyof typeof chainIdToRpc]; if (rpc) { - const provider = new ethers.JsonRpcProvider(rpc); - const wallet = ethers.Wallet.fromPhrase(mnemonic, provider); - wallets.push(wallet); + const provider = new ethers.JsonRpcProvider(rpc); + const wallet = ethers.Wallet.fromPhrase(mnemonic, provider); + wallets.push(wallet); } } return wallets; } export async function sendPauseTransactions(networks: Array, wallets: Array) { - const receipts = []; - for (let i = 0; i < networks.length; i++) { - const network = networks[i]; - const wallet = wallets[i]; - const bridge = Bridge__factory.connect(network.bridge, wallet); - const tx = await bridge.adminPauseTransfers(); - console.log(`Transaction no. ${i+1} completed, bridge on ${network.name} paused`); - receipts.push(tx); - } - return receipts; + const receipts = []; + for (let i = 0; i < networks.length; i++) { + const network = networks[i]; + const wallet = wallets[i]; + const bridge = Bridge__factory.connect(network.bridge, wallet); + const tx = await bridge.adminPauseTransfers(); + console.log(`Transaction no. ${i + 1} completed, bridge on ${network.name} paused`); + receipts.push(tx); + } + return receipts; } diff --git a/types/bridgePausing.d.ts b/types/bridgePausing.d.ts index c67a35a..c3201ee 100644 --- a/types/bridgePausing.d.ts +++ b/types/bridgePausing.d.ts @@ -1,2 +1,2 @@ -export {}; +import 'dotenv/config'; //# sourceMappingURL=bridgePausing.d.ts.map \ No newline at end of file diff --git a/types/bridgePausing.d.ts.map b/types/bridgePausing.d.ts.map index 1b01a5e..57df4f7 100644 --- a/types/bridgePausing.d.ts.map +++ b/types/bridgePausing.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"bridgePausing.d.ts","sourceRoot":"","sources":["../src/bridgePausing.ts"],"names":[],"mappings":""} \ No newline at end of file +{"version":3,"file":"bridgePausing.d.ts","sourceRoot":"","sources":["../src/bridgePausing.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC"} \ No newline at end of file diff --git a/types/constants.d.ts b/types/constants.d.ts deleted file mode 100644 index bd14f86..0000000 --- a/types/constants.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export declare const ConfigUrl: { - devnet: string; - testnet: string; - mainnet: string; -}; -export declare const chainIdToRpc: { - 5: string; -}; -//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/types/constants.d.ts.map b/types/constants.d.ts.map deleted file mode 100644 index 6d14c37..0000000 --- a/types/constants.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;CAIrB,CAAA;AAGD,eAAO,MAAM,YAAY;;CAExB,CAAA"} \ No newline at end of file diff --git a/types/constants/index.d.ts b/types/constants/index.d.ts new file mode 100644 index 0000000..73fd687 --- /dev/null +++ b/types/constants/index.d.ts @@ -0,0 +1,3 @@ +export { chainIdToRpc } from "./rpc"; +export { SharedConfig } from "./sharedConfig"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/types/constants/index.d.ts.map b/types/constants/index.d.ts.map new file mode 100644 index 0000000..9cd4389 --- /dev/null +++ b/types/constants/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"} \ No newline at end of file diff --git a/types/constants/rpc.d.ts b/types/constants/rpc.d.ts new file mode 100644 index 0000000..c127d6a --- /dev/null +++ b/types/constants/rpc.d.ts @@ -0,0 +1,4 @@ +export declare const chainIdToRpc: { + 5: string | undefined; +}; +//# sourceMappingURL=rpc.d.ts.map \ No newline at end of file diff --git a/types/constants/rpc.d.ts.map b/types/constants/rpc.d.ts.map new file mode 100644 index 0000000..b472ab6 --- /dev/null +++ b/types/constants/rpc.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../src/constants/rpc.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY;;CAExB,CAAA"} \ No newline at end of file diff --git a/types/constants/sharedConfig.d.ts b/types/constants/sharedConfig.d.ts new file mode 100644 index 0000000..6b9e0dd --- /dev/null +++ b/types/constants/sharedConfig.d.ts @@ -0,0 +1,6 @@ +export declare const SharedConfig: { + devnet: string; + testnet: string; + mainnet: string; +}; +//# sourceMappingURL=sharedConfig.d.ts.map \ No newline at end of file diff --git a/types/constants/sharedConfig.d.ts.map b/types/constants/sharedConfig.d.ts.map new file mode 100644 index 0000000..affbd14 --- /dev/null +++ b/types/constants/sharedConfig.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sharedConfig.d.ts","sourceRoot":"","sources":["../../src/constants/sharedConfig.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIxB,CAAC"} \ No newline at end of file diff --git a/types/utils.d.ts.map b/types/utils.d.ts.map index 09a97e7..38e71f4 100644 --- a/types/utils.d.ts.map +++ b/types/utils.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAC,MAAM,EAAC,MAAM,gCAAgC,CAAC;AAEtD,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,4BAahG;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,kCAaxF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,yCAWpH"} \ No newline at end of file +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,4BAahG;AAED,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,kCAaxF;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,yCAWpH"} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index dba5742..00f66b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -165,6 +165,7 @@ __metadata: "@buildwithsygma/sygma-sdk-core": ^2.1.0 axios: ^1.4.0 commander: ^11.0.0 + dotenv: ^16.3.1 ethers: ^6.6.2 typescript: ^5.1.6 languageName: unknown @@ -3005,6 +3006,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.3.1": + version: 16.3.1 + resolution: "dotenv@npm:16.3.1" + checksum: b95ff1bbe624ead85a3cd70dbd827e8e06d5f05f716f2d0cbc476532d54c7c9469c3bc4dd93ea519f6ad711cb522c00ac9a62b6eb340d5affae8008facc3fbd7 + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" From 0c57136ace1a72311650a9f0b28118b963f1620b Mon Sep 17 00:00:00 2001 From: Matej DB Date: Thu, 13 Jul 2023 09:59:15 +0200 Subject: [PATCH 10/10] added desc to readme file --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d8495e..785cb08 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -# maintenance-utils \ No newline at end of file +# maintenance-utils +NodeCLI for various purposes + +## Commands + +```pause``` - Pause all transfers across all bridges on selected enviroment (devnet, testnet or mainnet) + +Run with: + +``` +node pause -pk "private-key" -m "mnemonic words" -e "environment" +``` \ No newline at end of file