From e0a3eef31ca12d0492eac7a45a8f4b70f3c697df Mon Sep 17 00:00:00 2001 From: WaDadidou Date: Wed, 30 Oct 2024 19:40:22 -0400 Subject: [PATCH] chore: rust contract: use scripts instead of Makefile --- packages/networks/teritori-testnet/index.ts | 3 + packages/networks/types.ts | 2 + .../integration-testing/cwAddresslistTest.ts | 33 +++++ .../network-setup/deployCwAddressList.ts | 115 ++++++++++++++++++ rust/cw-contracts/cw-address-list/Makefile | 54 -------- .../cw-address-list/config-mainnet.json | 7 -- rust/cw-contracts/cw-address-list/config.json | 7 -- 7 files changed, 153 insertions(+), 68 deletions(-) create mode 100644 packages/scripts/integration-testing/cwAddresslistTest.ts create mode 100644 packages/scripts/network-setup/deployCwAddressList.ts delete mode 100644 rust/cw-contracts/cw-address-list/Makefile delete mode 100644 rust/cw-contracts/cw-address-list/config-mainnet.json delete mode 100644 rust/cw-contracts/cw-address-list/config.json diff --git a/packages/networks/teritori-testnet/index.ts b/packages/networks/teritori-testnet/index.ts index 8ea49b815..a92624a86 100644 --- a/packages/networks/teritori-testnet/index.ts +++ b/packages/networks/teritori-testnet/index.ts @@ -92,6 +92,9 @@ export const teritoriTestnetNetwork: CosmosNetworkInfo = { excludeFromLaunchpadList: [riotContractAddressGen1], socialFeedContractAddress: "tori1mf6ptkssddfmxvhdx0ech0k03ktp6kf9yk59renau2gvht3nq2gqg87tkw", + cwAddressListContractAddress: + "tori1x72plnprsjnmszylmdm3cnvu5h6u55fyf0pe02lye9p6q2ws05ps33qmft", + cwAddressListCodeId: 63, daoCoreCodeId: 30, daoPreProposeSingleCodeId: 32, daoProposalSingleCodeId: 33, diff --git a/packages/networks/types.ts b/packages/networks/types.ts index a59178757..495fc6a77 100644 --- a/packages/networks/types.ts +++ b/packages/networks/types.ts @@ -72,6 +72,8 @@ export type CosmosNetworkInfo = NetworkInfoBase & { daoVotingCw4CodeId?: number; cwAdminFactoryContractAddress?: string; coreDAOAddress?: string; + cwAddressListContractAddress?: string; + cwAddressListCodeId?: number; }; export type EthereumNetworkInfo = NetworkInfoBase & { diff --git a/packages/scripts/integration-testing/cwAddresslistTest.ts b/packages/scripts/integration-testing/cwAddresslistTest.ts new file mode 100644 index 000000000..b739aade8 --- /dev/null +++ b/packages/scripts/integration-testing/cwAddresslistTest.ts @@ -0,0 +1,33 @@ +import { program } from "commander"; +import fs from "fs/promises"; + +import { deployCwAddressList } from "./../network-setup/deployCwAddressList"; +import { buildCosmos, startCosmosLocalnet } from "./cosmos"; +import { teritoriLocalnetNetwork } from "../../networks/teritori-localnet"; + +const main = async () => { + program.argument( + "", + "Path to the repo to build latest binary from", + ); + program.parse(); + const [repoPath] = program.args; + + const binary = await buildCosmos(repoPath, "teritorid"); + + const { home, kill, admSigner } = await startCosmosLocalnet(binary); + if (!admSigner) { + throw new Error("adm signer is undefined"); + } + + await deployCwAddressList({ + opts: { binaryPath: binary, home }, + networkId: teritoriLocalnetNetwork.id, + wallet: "testnet-adm", + }); + + await kill(); + await fs.rm(home, { recursive: true, force: true }); +}; + +main(); diff --git a/packages/scripts/network-setup/deployCwAddressList.ts b/packages/scripts/network-setup/deployCwAddressList.ts new file mode 100644 index 000000000..3e9533892 --- /dev/null +++ b/packages/scripts/network-setup/deployCwAddressList.ts @@ -0,0 +1,115 @@ +import { OfflineSigner } from "@cosmjs/proto-signing"; +import { bech32 } from "bech32"; +import { program } from "commander"; +import { cloneDeep } from "lodash"; +import os from "os"; +import path from "path"; + +import { InstantiateMsg as CwAddressListInstantiateMsg } from "@/contracts-clients/cw-address-list"; +import { + allNetworks, + CosmosNetworkInfo, + getCosmosNetwork, + getNetworkFeature, + NetworkFeature, +} from "@/networks"; +import { execPromise } from "@/scripts/lib"; +import { + instantiateContract, + storeWASM, +} from "@/scripts/network-setup/deployLib"; + +// CONTRACT_ADDRESS_TESTNET = tori1x72plnprsjnmszylmdm3cnvu5h6u55fyf0pe02lye9p6q2ws05ps33qmft +// CODE_ID_TESTNET = 63 + +export const deployCwAddressList = async ({ + opts, + networkId, + wallet, +}: { + networkId: string; + wallet: string; + opts: { home: string; binaryPath: string; keyringBackend?: string }; +}) => { + const network = cloneDeep(getCosmosNetwork(networkId)); + if (!network) { + console.error(`Cosmos network ${networkId} not found`); + process.exit(1); + } + console.log(`Deploying to ${network.displayName}`); + + let walletAddr = ( + await execPromise( + `${opts.binaryPath} keys show --keyring-backend ${opts.keyringBackend || "test"} -a ${wallet} --home ${opts.home}`, + { encoding: "utf-8" }, + ) + ).stdout.trim(); + if (walletAddr.startsWith("Successfully migrated")) { + walletAddr = walletAddr.substring(walletAddr.indexOf("\n")).trim(); + } + bech32.decode(walletAddr); + console.log("Wallet address:", walletAddr); + + if (!network.cwAddressListContractAddress) { + console.log("Storing cw address list"); + const cwAddressListWasmFilePath = path.join( + __dirname, + "cw_address_list.wasm", + ); + network.cwAdminFactoryCodeId = await storeWASM( + opts, + wallet, + network, + cwAddressListWasmFilePath, + ); + + console.log("Instantiating cw address list", network.cwAdminFactoryCodeId); + network.cwAddressListContractAddress = await instantiateCwAddressList( + opts, + wallet, + walletAddr, + network, + ); + } +}; + +const instantiateCwAddressList = async ( + opts: { home: string; binaryPath: string; keyringBackend?: string }, + wallet: string, + adminAddr: string, + network: CosmosNetworkInfo, +) => { + const codeId = network.cwAdminFactoryCodeId; + if (!codeId) { + throw new Error("CW Address List code ID not found"); + } + return await instantiateContract( + opts, + wallet, + network, + codeId, + adminAddr, + "Teritori CW Address List", + {}, + ); +}; + +const main = async () => { + program.argument("", "Network id to deploy to"); + program.argument("", "Wallet to deploy from"); + program.option("--keyring-backend [keyring-backend]", "Keyring backend"); + program.parse(); + const [networkId, wallet] = program.args; + const { keyringBackend } = program.opts(); + + await deployCwAddressList({ + opts: { + home: path.join(os.homedir(), ".teritorid"), + binaryPath: "teritorid", + keyringBackend, + }, + networkId, + wallet, + }); +}; +main(); diff --git a/rust/cw-contracts/cw-address-list/Makefile b/rust/cw-contracts/cw-address-list/Makefile deleted file mode 100644 index fbc08b2e2..000000000 --- a/rust/cw-contracts/cw-address-list/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -ADMIN_TESTNET=testnet-adm -ADMIN_ADDR_TESTNET=$(shell teritorid keys show $(ADMIN_TESTNET) --keyring-backend test --output json | jq -r .address) -NODE_FLAG_TESTNET=--node https://rpc.testnet.teritori.com:443 -TX_FLAGS_TESTNET=--from $(ADMIN_TESTNET) --chain-id teritori-test-7 $(NODE_FLAG_TESTNET) --gas auto --gas-adjustment 1.3 -y -b sync --output json --keyring-backend test -o json -QUERY_FLAGS_TESTNET=$(NODE_FLAG_TESTNET) -o json -CODE_ID_TESTNET=63 -CONFIG_TESTNET=$(shell cat config.json | jq -r '.admin="$(ADMIN_ADDR_TESTNET)" | tojson | @sh') - -ADMIN_MAINNET=mainnet-adm -ADMIN_ADDR_MAINNET=$(shell teritorid keys show $(ADMIN_MAINNET) --output json | jq -r .address) -NODE_FLAG_MAINNET=--node https://rpc.mainnet.teritori.com:443 -# --keyring-backend os by default -TX_FLAGS_MAINNET=--from $(ADMIN_MAINNET) --chain-id teritori-1 $(NODE_FLAG_MAINNET) --gas auto --gas-adjustment 1.3 -y -b sync --output json -o json -QUERY_FLAGS_MAINNET=$(NODE_FLAG_MAINNET) -o json -CODE_ID_MAINNET= -CONFIG_MAINNET=$(shell cat config-mainnet.json | jq -r '.admin="$(ADMIN_ADDR_MAINNET)" | tojson | @sh') - -WORKSPACE_PATH := $(shell realpath $(shell dirname $(shell pwd))/../..) - -# only informative -# CONTRACT_ADDRESS_TESTNET= -# CONTRACT_ADDRESS_MAINNET= - -.PHONY: artifacts/cw_address_list.wasm -artifacts/cw_address_list.wasm: - docker run --rm -v "$(WORKSPACE_PATH):/code" \ - --platform linux/amd64 \ - --mount type=volume,source=cw_address_list_cache,target=/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.14.0 - -.PHONY: deploy.testnet -deploy.testnet: artifacts/cw_address_list.wasm - set -o pipefail; \ - TXHASH=$$(teritorid tx wasm store $(WORKSPACE_PATH)/artifacts/cw_address_list.wasm $(TX_FLAGS_TESTNET) | jq -r .txhash); \ - while ! teritorid query tx $$TXHASH $(QUERY_FLAGS_TESTNET) 2>/dev/null | jq -r '.logs[0].events[] | select(.type=="store_code").attributes[] | select(.key=="code_id").value'; do sleep 1; done - -.PHONY: instantiate.testnet -instantiate.testnet: config.json - set -o pipefail; \ - TXHASH=$$(teritorid tx wasm instantiate $(CODE_ID_TESTNET) $(CONFIG_TESTNET) --label CwAddressList --admin $(ADMIN_ADDR_TESTNET) $(TX_FLAGS_TESTNET) | jq -r .txhash); \ - while ! teritorid query tx $$TXHASH $(QUERY_FLAGS_TESTNET) 2>/dev/null | jq -r '.logs[0].events[] | select(.type=="instantiate").attributes[] | select(.key=="_contract_address").value'; do sleep 1; done - -.PHONY: deploy.mainnet -deploy.mainnet: artifacts/cw_address_list.wasm - set -o pipefail; \ - TXHASH=$$(teritorid tx wasm store $(WORKSPACE_PATH)/artifacts/cw_address_list.wasm $(TX_FLAGS_MAINNET) | jq -r .txhash); \ - while ! teritorid query tx $$TXHASH $(QUERY_FLAGS_MAINNET) 2>/dev/null | jq -r '.logs[0].events[] | select(.type=="store_code").attributes[] | select(.key=="code_id").value'; do sleep 1; done - -.PHONY: instantiate.mainnet -instantiate.mainnet: config-mainnet.json - set -o pipefail; \ - TXHASH=$$(teritorid tx wasm instantiate $(CODE_ID_MAINNET) $(CONFIG_MAINNET) --label CwAddressList --admin $(ADMIN_ADDR_MAINNET) $(TX_FLAGS_MAINNET) | jq -r .txhash); \ - while ! teritorid query tx $$TXHASH $(QUERY_FLAGS_MAINNET) 2>/dev/null | jq -r '.logs[0].events[] | select(.type=="instantiate").attributes[] | select(.key=="_contract_address").value'; do sleep 1; done \ No newline at end of file diff --git a/rust/cw-contracts/cw-address-list/config-mainnet.json b/rust/cw-contracts/cw-address-list/config-mainnet.json deleted file mode 100644 index 634621c57..000000000 --- a/rust/cw-contracts/cw-address-list/config-mainnet.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "config": { - "name": "CW Address List", - "supported_networks": ["teritori"], - "admin": "" - } - } \ No newline at end of file diff --git a/rust/cw-contracts/cw-address-list/config.json b/rust/cw-contracts/cw-address-list/config.json deleted file mode 100644 index 79e3f002c..000000000 --- a/rust/cw-contracts/cw-address-list/config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "config": { - "name": "CW Address List", - "supported_networks": ["teritori-testnet"], - "admin": "" - } - } \ No newline at end of file