Merge pull request #575 from cosmos/491-cosmwasm-stargate-contract-deployments

Deploy more contracts in Wasmd
This commit is contained in:
Will Clark 2020-12-15 16:27:27 +01:00 committed by GitHub
commit ca78c174f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 392 additions and 65 deletions

View File

@ -125,45 +125,38 @@ export const deployedHackatom = {
],
};
// /** Deployed as part of scripts/wasmd/init.sh */
// export const deployedErc20 = {
// codeId: 2,
// source: "https://crates.io/api/v1/crates/cw-erc20/0.7.0/download",
// builder: "cosmwasm/rust-optimizer:0.10.4",
// checksum: "d04368320ad55089384adb171aaea39e43d710d7608829adba0300ed30aa2988",
// instances: [
// // TODO: Update this address
// "cosmos1vjecguu37pmd577339wrdp208ddzymkudc46zj", // HASH
// // TODO: Update this address
// "cosmos1ym5m5dw7pttft5w430nxx6uat8f84ck4algmhg", // ISA
// // TODO: Update this address
// "cosmos1gv07846a3867ezn3uqkk082c5ftke7hpllcu8q", // JADE
// ],
// };
/** Deployed as part of scripts/wasmd/init.sh */
export const deployedErc20 = {
codeId: 2,
source: "https://crates.io/api/v1/crates/cw-erc20/0.7.0/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
checksum: "d04368320ad55089384adb171aaea39e43d710d7608829adba0300ed30aa2988",
instances: [
"wasm1vjecguu37pmd577339wrdp208ddzymku8yy0te", // HASH
"wasm1ym5m5dw7pttft5w430nxx6uat8f84ck4hrew7r", // ISA
"wasm1gv07846a3867ezn3uqkk082c5ftke7hp4rffwt", // JADE
],
};
// /** Deployed as part of scripts/wasmd/init.sh */
// export const deployedCw3 = {
// codeId: 3,
// source: "https://crates.io/api/v1/crates/cw3-fixed-multisig/0.3.1/download",
// builder: "cosmwasm/rust-optimizer:0.10.4",
// instances: [
// // TODO: Update this address
// "cosmos1xqeym28j9xgv0p93pwwt6qcxf9tdvf9zddufdw", // Multisig (1/3)
// // TODO: Update this address
// "cosmos1jka38ckju8cpjap00jf9xdvdyttz9caujtd6t5", // Multisig (2/3)
// // TODO: Update this address
// "cosmos12dnl585uxzddjw9hw4ca694f054shgpgr4zg80", // Multisig (uneven weights)
// ],
// };
/** Deployed as part of scripts/wasmd/init.sh */
export const deployedCw3 = {
codeId: 3,
source: "https://crates.io/api/v1/crates/cw3-fixed-multisig/0.3.1/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
instances: [
"wasm1xqeym28j9xgv0p93pwwt6qcxf9tdvf9z83duy9", // Multisig (1/3)
"wasm1jka38ckju8cpjap00jf9xdvdyttz9cauchu0zl", // Multisig (2/3)
"wasm12dnl585uxzddjw9hw4ca694f054shgpgffnawy", // Multisig (uneven weights)
],
};
// /** Deployed as part of scripts/wasmd/init.sh */
// export const deployedCw1 = {
// codeId: 4,
// source: "https://crates.io/api/v1/crates/cw1-subkeys/0.3.1/download",
// builder: "cosmwasm/rust-optimizer:0.10.4",
// // TODO: Update this address
// instances: ["cosmos1vs2vuks65rq7xj78mwtvn7vvnm2gn7ad5me0d2"],
// };
/** Deployed as part of scripts/wasmd/init.sh */
export const deployedCw1 = {
codeId: 4,
source: "https://crates.io/api/v1/crates/cw1-subkeys/0.3.1/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
instances: ["wasm1vs2vuks65rq7xj78mwtvn7vvnm2gn7ad78g6yp"],
};
export function wasmdEnabled(): boolean {
return !!process.env.WASMD_ENABLED;
@ -175,35 +168,35 @@ export function pendingWithoutWasmd(): void {
}
}
// export function erc20Enabled(): boolean {
// return !!process.env.ERC20_ENABLED;
// }
export function erc20Enabled(): boolean {
return !!process.env.ERC20_ENABLED;
}
// export function pendingWithoutErc20(): void {
// if (!erc20Enabled()) {
// return pending("Set ERC20_ENABLED to enable ERC20-based tests");
// }
// }
export function pendingWithoutErc20(): void {
if (!erc20Enabled()) {
return pending("Set ERC20_ENABLED to enable ERC20-based tests");
}
}
// export function cw3Enabled(): boolean {
// return !!process.env.CW3_ENABLED;
// }
export function cw3Enabled(): boolean {
return !!process.env.CW3_ENABLED;
}
// export function pendingWithoutCw3(): void {
// if (!cw3Enabled()) {
// return pending("Set CW3_ENABLED to enable CW3-based tests");
// }
// }
export function pendingWithoutCw3(): void {
if (!cw3Enabled()) {
return pending("Set CW3_ENABLED to enable CW3-based tests");
}
}
// export function cw1Enabled(): boolean {
// return !!process.env.CW1_ENABLED;
// }
export function cw1Enabled(): boolean {
return !!process.env.CW1_ENABLED;
}
// export function pendingWithoutCw1(): void {
// if (!cw1Enabled()) {
// return pending("Set CW1_ENABLED to enable CW1-based tests");
// }
// }
export function pendingWithoutCw1(): void {
if (!cw1Enabled()) {
return pending("Set CW1_ENABLED to enable CW1-based tests");
}
}
/** Returns first element. Throws if array has a different length than 1. */
export function fromOneElementArray<T>(elements: ArrayLike<T>): T {

58
scripts/wasmd/deploy_cw1.js Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/naming-convention */
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const fs = require("fs");
const endpoint = "http://localhost:26659";
const alice = {
mnemonic: "enlist hip relief stomach skate base shallow young switch frequent cry park",
address0: "wasm14qemq0vw6y3gc3u3e0aty2e764u4gs5lndxgyk",
// address1: "wasm1hhg2rlu9jscacku2wwckws7932qqqu8xm5ca8y",
// address2: "wasm1xv9tklw7d82sezh9haa573wufgy59vmwnxhnsl",
// address3: "wasm17yg9mssjenmc3jkqth6ulcwj9cxujrxxg9nmzk",
// address4: "wasm1f7j7ryulwjfe9ljplvhtcaxa6wqgula3nh873j",
};
const codeMeta = {
source: "https://crates.io/api/v1/crates/cw1-subkeys/0.3.1/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
};
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw1_subkeys.wasm");
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload CW1 subkeys contract");
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
const initMsg = {
admins: [alice.address0],
mutable: true,
};
const label = "Subkey test";
const { contractAddress } = await client.instantiate(alice.address0, uploadReceipt.codeId, initMsg, label, {
memo: `Create a CW1 instance for ${alice.address0}`,
admin: alice.address0,
});
await client.sendTokens(alice.address0, contractAddress, [
{
amount: "1000",
denom: "ucosm",
},
]);
console.info(`Contract instantiated for ${alice.address0} subkey at ${contractAddress}`);
}
main().then(
() => {
console.info("All done, let the coins flow.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);

108
scripts/wasmd/deploy_cw3.js Executable file
View File

@ -0,0 +1,108 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/naming-convention */
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const fs = require("fs");
const endpoint = "http://localhost:26659";
const alice = {
mnemonic: "enlist hip relief stomach skate base shallow young switch frequent cry park",
address0: "wasm14qemq0vw6y3gc3u3e0aty2e764u4gs5lndxgyk",
address1: "wasm1hhg2rlu9jscacku2wwckws7932qqqu8xm5ca8y",
address2: "wasm1xv9tklw7d82sezh9haa573wufgy59vmwnxhnsl",
address3: "wasm17yg9mssjenmc3jkqth6ulcwj9cxujrxxg9nmzk",
address4: "wasm1f7j7ryulwjfe9ljplvhtcaxa6wqgula3nh873j",
};
const codeMeta = {
source: "https://crates.io/api/v1/crates/cw3-fixed-multisig/0.3.1/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
};
const initData = [
{
admin: alice.address0,
label: "Multisig (1/3)",
initMsg: {
voters: [
{ addr: alice.address0, weight: 1 },
{ addr: alice.address1, weight: 1 },
{ addr: alice.address2, weight: 1 },
],
required_weight: 1,
max_voting_period: { height: 12345 },
},
},
{
admin: alice.address0,
label: "Multisig (2/3)",
initMsg: {
voters: [
{ addr: alice.address0, weight: 1 },
{ addr: alice.address1, weight: 1 },
{ addr: alice.address2, weight: 1 },
],
required_weight: 2,
max_voting_period: { height: 12345 },
},
},
{
admin: alice.address0,
label: "Multisig (uneven weights)",
initMsg: {
voters: [
{ addr: alice.address0, weight: 1 },
{ addr: alice.address1, weight: 2 },
{ addr: alice.address2, weight: 3 },
],
required_weight: 3,
max_voting_period: { height: 12345 },
},
},
];
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw3_fixed_multisig.wasm");
const uploadReceipt = await client.upload(
alice.address0,
wasm,
codeMeta,
"Upload CW3 fixed multisig contract",
);
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
for (const { admin, initMsg, label } of initData) {
const { contractAddress } = await client.instantiate(
alice.address0,
uploadReceipt.codeId,
initMsg,
label,
{
memo: `Create a CW3 instance for ${initMsg.symbol}`,
admin: admin,
},
);
await client.sendTokens(alice.address0, contractAddress, [
{
amount: "1000",
denom: "ucosm",
},
]);
console.info(`Contract instantiated for ${label} at ${contractAddress}`);
}
}
main().then(
() => {
console.info("All done, let the coins flow.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);

168
scripts/wasmd/deploy_erc20.js Executable file
View File

@ -0,0 +1,168 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/naming-convention */
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const fs = require("fs");
const endpoint = "http://localhost:26659";
const alice = {
mnemonic: "enlist hip relief stomach skate base shallow young switch frequent cry park",
address0: "wasm14qemq0vw6y3gc3u3e0aty2e764u4gs5lndxgyk",
address1: "wasm1hhg2rlu9jscacku2wwckws7932qqqu8xm5ca8y",
address2: "wasm1xv9tklw7d82sezh9haa573wufgy59vmwnxhnsl",
address3: "wasm17yg9mssjenmc3jkqth6ulcwj9cxujrxxg9nmzk",
address4: "wasm1f7j7ryulwjfe9ljplvhtcaxa6wqgula3nh873j",
};
const unused = {
address: "wasm1cjsxept9rkggzxztslae9ndgpdyt240842kpxh",
};
const guest = {
address: "wasm17d0jcz59jf68g52vq38tuuncmwwjk42us8fnse",
};
const codeMeta = {
source: "https://crates.io/api/v1/crates/cw-erc20/0.7.0/download",
builder: "cosmwasm/rust-optimizer:0.10.4",
};
const initDataHash = {
admin: undefined,
initMsg: {
decimals: 5,
name: "Hash token",
symbol: "HASH",
initial_balances: [
{
address: alice.address0,
amount: "11",
},
{
address: alice.address1,
amount: "11",
},
{
address: alice.address2,
amount: "11",
},
{
address: alice.address3,
amount: "11",
},
{
address: alice.address4,
amount: "11",
},
{
address: unused.address,
amount: "12812345",
},
{
address: guest.address,
amount: "22004000000",
},
],
},
};
const initDataIsa = {
admin: undefined,
initMsg: {
decimals: 0,
name: "Isa Token",
symbol: "ISA",
initial_balances: [
{
address: alice.address0,
amount: "999999999",
},
{
address: alice.address1,
amount: "999999999",
},
{
address: alice.address2,
amount: "999999999",
},
{
address: alice.address3,
amount: "999999999",
},
{
address: alice.address4,
amount: "999999999",
},
{
address: unused.address,
amount: "42",
},
],
},
};
const initDataJade = {
admin: alice.address1,
initMsg: {
decimals: 18,
name: "Jade Token",
symbol: "JADE",
initial_balances: [
{
address: alice.address0,
amount: "189189189000000000000000000", // 189189189 JADE
},
{
address: alice.address1,
amount: "189189189000000000000000000", // 189189189 JADE
},
{
address: alice.address2,
amount: "189189189000000000000000000", // 189189189 JADE
},
{
address: alice.address3,
amount: "189189189000000000000000000", // 189189189 JADE
},
{
address: alice.address4,
amount: "189189189000000000000000000", // 189189189 JADE
},
{
address: guest.address,
amount: "189500000000000000000", // 189.5 JADE
},
],
},
};
async function main() {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, "wasm");
const client = await SigningCosmWasmClient.connectWithWallet(endpoint, wallet);
const wasm = fs.readFileSync(__dirname + "/contracts/cw_erc20.wasm");
const uploadReceipt = await client.upload(alice.address0, wasm, codeMeta, "Upload ERC20 contract");
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
for (const { initMsg, admin } of [initDataHash, initDataIsa, initDataJade]) {
const { contractAddress } = await client.instantiate(
alice.address0,
uploadReceipt.codeId,
initMsg,
initMsg.symbol,
{
memo: `Create an ERC20 instance for ${initMsg.symbol}`,
admin: admin,
},
);
console.info(`Contract instantiated for ${initMsg.symbol} at ${contractAddress}`);
}
}
main().then(
() => {
console.info("All done, let the coins flow.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);

View File

@ -26,7 +26,7 @@ SCRIPT_DIR="$(realpath "$(dirname "$0")")"
sha256sum --check checksums.sha256
)
"$SCRIPT_DIR/deploy_hackatom.js"
# "$SCRIPT_DIR/deploy_erc20.js"
# "$SCRIPT_DIR/deploy_cw3.js"
# "$SCRIPT_DIR/deploy_cw1.js"
# # "$SCRIPT_DIR/deploy_nameservice.js"
"$SCRIPT_DIR/deploy_erc20.js"
"$SCRIPT_DIR/deploy_cw3.js"
"$SCRIPT_DIR/deploy_cw1.js"
# "$SCRIPT_DIR/deploy_nameservice.js"