diff --git a/rust/cw-contracts/nft-tr721/.cargo/config b/rust/cw-contracts/nft-tr721/.cargo/config.toml similarity index 100% rename from rust/cw-contracts/nft-tr721/.cargo/config rename to rust/cw-contracts/nft-tr721/.cargo/config.toml diff --git a/rust/cw-contracts/nft-tr721/Makefile b/rust/cw-contracts/nft-tr721/Makefile new file mode 100644 index 0000000000..8e312c7723 --- /dev/null +++ b/rust/cw-contracts/nft-tr721/Makefile @@ -0,0 +1,22 @@ +ADMIN=testnet-adm +NODE_FLAG=--node https://rpc.testnet.teritori.com:443 +TX_FLAGS=--from $(ADMIN) --chain-id teritori-test-7 $(NODE_FLAG) --gas auto --gas-adjustment 1.3 -y -b sync --output json --keyring-backend test -o json +QUERY_FLAGS=$(NODE_FLAG) -o json +WORKSPACE_PATH := $(shell realpath $(shell dirname $(shell pwd))/../..) + +# only informative +# CODE_ID=0 + +.PHONY: artifacts/nft_tr721.wasm +artifacts/nft_tr721.wasm: + docker run --rm -v "$(WORKSPACE_PATH):/code" \ + --platform linux/amd64 \ + --mount type=volume,source=nft_tr721_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/nft_tr721.wasm + set -o pipefail; \ + TXHASH=$$(teritorid tx wasm store $(WORKSPACE_PATH)/artifacts/nft_tr721.wasm $(TX_FLAGS) | jq -r .txhash); \ + while ! teritorid query tx $$TXHASH $(QUERY_FLAGS) 2>/dev/null | jq -r '.logs[0].events[] | select(.type=="store_code").attributes[] | select(.key=="code_id").value'; do sleep 1; done \ No newline at end of file diff --git a/rust/scripts/deploy-nft-tr721.ts b/rust/cw-contracts/nft-tr721/deploy.ts similarity index 76% rename from rust/scripts/deploy-nft-tr721.ts rename to rust/cw-contracts/nft-tr721/deploy.ts index 07b6724511..71fe342523 100644 --- a/rust/scripts/deploy-nft-tr721.ts +++ b/rust/cw-contracts/nft-tr721/deploy.ts @@ -1,5 +1,4 @@ -import { deploy } from "./utils"; - +import { deploy } from "../../utils/scripts"; const WASM_FILE = "nft_tr721.wasm"; const main = async () => { diff --git a/rust/scripts/utils.ts b/rust/scripts/utils.ts deleted file mode 100644 index df00313adf..0000000000 --- a/rust/scripts/utils.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"; -import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; -import { GasPrice } from "@cosmjs/stargate"; -import { readFileSync } from "fs"; -import path from "path"; - -import { MNEMONIC } from "./mnemonic"; - -const GAS_PRICE = GasPrice.fromString("0.025utori"); - -const NODE_RPC = "https://rpc.testnet.teritori.com:443"; -// const CHAIN_ID = "teritori-test-7"; - -export const getClientInfos = async () => { - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { - prefix: "tori", - }); - - const client = await SigningCosmWasmClient.connectWithSigner( - NODE_RPC, - wallet, - { gasPrice: GAS_PRICE }, - ); - - const sender = await wallet.getAccounts().then((res) => res[0]?.address); - - console.log("Sender:", sender); - - return { wallet, client, sender }; -}; - -const getWasmFile = (wasmFile: string) => { - const filePath = path.join(__dirname, "../..", "artifacts", wasmFile); - console.log("filePath:", filePath); - return readFileSync(filePath); -}; - -export const deploy = async (wasmFile: string) => { - const { client, sender } = await getClientInfos(); - const buffer = getWasmFile(wasmFile); - const u8Array = new Uint8Array(buffer); - - const uploadRes = await client.upload(sender, u8Array, "auto"); - - return uploadRes.codeId; -}; - -export const instantiate = async (codeId: number, label: string, msg: any) => { - const { client, sender } = await getClientInfos(); - - const instantiateRes = await client.instantiate( - sender, - codeId, - msg, - `${label} - ${codeId}`, - "auto", - ); - return instantiateRes.contractAddress; -}; diff --git a/rust/utils/scripts.ts b/rust/utils/scripts.ts index be5a2ad645..c6d63172f1 100644 --- a/rust/utils/scripts.ts +++ b/rust/utils/scripts.ts @@ -11,7 +11,7 @@ const GAS_PRICE = GasPrice.fromString("0.025utori"); const NODE_RPC = "https://rpc.testnet.teritori.com:443"; // const CHAIN_ID = "teritori-test-7"; -export const getClientInfos = async () => { +const getClientInfos = async () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, { prefix: "tori", });