Skip to content

Commit

Permalink
chore: rust contract: use scripts instead of Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Oct 30, 2024
1 parent 0320c95 commit e0a3eef
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 68 deletions.
3 changes: 3 additions & 0 deletions packages/networks/teritori-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const teritoriTestnetNetwork: CosmosNetworkInfo = {
excludeFromLaunchpadList: [riotContractAddressGen1],
socialFeedContractAddress:
"tori1mf6ptkssddfmxvhdx0ech0k03ktp6kf9yk59renau2gvht3nq2gqg87tkw",
cwAddressListContractAddress:
"tori1x72plnprsjnmszylmdm3cnvu5h6u55fyf0pe02lye9p6q2ws05ps33qmft",
cwAddressListCodeId: 63,
daoCoreCodeId: 30,
daoPreProposeSingleCodeId: 32,
daoProposalSingleCodeId: 33,
Expand Down
2 changes: 2 additions & 0 deletions packages/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export type CosmosNetworkInfo = NetworkInfoBase & {
daoVotingCw4CodeId?: number;
cwAdminFactoryContractAddress?: string;
coreDAOAddress?: string;
cwAddressListContractAddress?: string;
cwAddressListCodeId?: number;
};

export type EthereumNetworkInfo = NetworkInfoBase & {
Expand Down
33 changes: 33 additions & 0 deletions packages/scripts/integration-testing/cwAddresslistTest.ts
Original file line number Diff line number Diff line change
@@ -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(
"<repo-path>",
"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();
115 changes: 115 additions & 0 deletions packages/scripts/network-setup/deployCwAddressList.ts
Original file line number Diff line number Diff line change
@@ -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>", "Network id to deploy to");
program.argument("<wallet>", "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();
54 changes: 0 additions & 54 deletions rust/cw-contracts/cw-address-list/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions rust/cw-contracts/cw-address-list/config-mainnet.json

This file was deleted.

7 changes: 0 additions & 7 deletions rust/cw-contracts/cw-address-list/config.json

This file was deleted.

0 comments on commit e0a3eef

Please sign in to comment.