terra: add columbus-5 deploy script

Change-Id: I33eead9ed1fd818dc8d6ff6e71230bda4b3d3c64
This commit is contained in:
Reisen 2021-10-04 11:52:11 +00:00 committed by David Paryente
parent 2163f420c9
commit 4933f35213
5 changed files with 1235 additions and 4 deletions

View File

@ -7,7 +7,7 @@ ADD contracts /code/contracts
RUN optimize_workspace.sh
# Contract deployment stage
FROM python:slim-buster@sha256:ec7a755e6313da2f7db02d8e82f6b0813b176f06c5622174c8ab45feefc8096d
FROM node:16-buster-slim@sha256:93c9fc3550f5f7d159f282027228e90e3a7f8bf38544758024f005e82607f546
RUN apt update && apt install netcat curl jq -y
@ -19,6 +19,4 @@ ADD ./tools /app/tools
RUN chmod +x /app/tools/deploy.sh
RUN pip install -r /app/tools/requirements.txt
ENTRYPOINT /app/tools/deploy.sh

175
terra/tools/deploy.js Normal file
View File

@ -0,0 +1,175 @@
import { Wallet, LCDClient, MnemonicKey } from "@terra-money/terra.js";
import { StdFee, MsgInstantiateContract, MsgExecuteContract, MsgStoreCode } from "@terra-money/terra.js";
import { readFileSync, readdirSync } from "fs";
// TODO: Workaround /tx/estimate_fee errors.
const gas_prices = {
uluna: "0.15",
usdr: "0.1018",
uusd: "0.15",
ukrw: "178.05",
umnt: "431.6259",
ueur: "0.125",
ucny: "0.97",
ujpy: "16",
ugbp: "0.11",
uinr: "11",
ucad: "0.19",
uchf: "0.13",
uaud: "0.19",
usgd: "0.2",
};
async function main() {
const terra = new LCDClient({
URL: "http://localhost:1317",
chainID: "localterra",
});
const wallet = terra.wallet(
new MnemonicKey({
mnemonic:
"notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius",
})
);
await wallet.sequence();
// Deploy WASM blobs.
const artifacts = readdirSync('../artifacts/');
artifacts.sort();
for (const artifact in artifacts) {
console.log(artifact);
console.log(artifacts.hasOwnProperty(artifact));
if(artifacts.hasOwnProperty(artifact) && artifacts[artifact].includes('.wasm')) {
const file = artifacts[artifact];
const contract_bytes = readFileSync(`../artifacts/${file}`);
console.log(`Storing Bytes, ${contract_bytes.length}, for ${file}`);
const store_code = new MsgStoreCode(
wallet.key.accAddress,
contract_bytes.toString('base64'),
);
try {
const tx = await wallet.createAndSignTx({
msgs: [store_code],
memo: '',
fee: new StdFee(
3000000,
{ uluna: "100000" }
)
});
const rs = await terra.tx.broadcast(tx);
console.log(JSON.stringify(rs, null, 2));
await wallet.sequence();
} catch (e) {
console.log('Failed to Execute');
}
}
}
const govChain = 1;
const govAddress = "0000000000000000000000000000000000000000000000000000000000000004";
//Instantiate Contracts
wallet.createAndSignTx({
msgs: [
new MsgInstantiateContract(
wallet.key.accAddress,
undefined,
2,
{
gov_chain: govChain,
gov_address: Buffer.from(govAddress, 'hex').toString('base64'),
guardian_set_expirity: 86400,
initial_guardian_set: {
addresses: [
{
bytes: Buffer.from('beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe', 'hex').toString('base64'),
}
],
expiration_time: 0
},
},
)
],
memo:'',
})
.then(tx => terra.tx.broadcast(tx))
.then(rs => console.log(rs));
wallet.createAndSignTx({
msgs: [
new MsgInstantiateContract(
wallet.key.accAddress,
undefined,
4,
{
owner: deployer.key.accAddress,
gov_chain: govChain,
gov_address: Buffer.from(govAddress, 'hex').toString('base64'),
wormhole_contract: "",
wrapped_asset_code_id: 2,
},
)
],
memo:'',
})
.then(tx => terra.tx.broadcast(tx))
.then(rs => console.log(rs));
wallet.createAndSignTx({
msgs: [
new MsgInstantiateContract(
wallet.key.accAddress,
undefined,
3,
{
name: "MOCK",
symbol: "MCK",
decimals: 6,
initial_balances: [
{
"address": deployer.key.acc_address,
"amount": "100000000"
}
],
mint: null,
},
)
],
memo:'',
})
.then(tx => terra.tx.broadcast(tx))
.then(rs => console.log(rs));
const registrations = [
'01000000000100c9f4230109e378f7efc0605fb40f0e1869f2d82fda5b1dfad8a5a2dafee85e033d155c18641165a77a2db6a7afbf2745b458616cb59347e89ae0c7aa3e7cc2d400000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e4272696467650100000001c69a1b1a65dd336bf1df6a77afb501fc25db7fc0938cb08595a9ef473265cb4f',
'01000000000100e2e1975d14734206e7a23d90db48a6b5b6696df72675443293c6057dcb936bf224b5df67d32967adeb220d4fe3cb28be515be5608c74aab6adb31099a478db5c01000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e42726964676501000000020000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16'
];
registrations.forEach(registration => {
wallet.createAndSignTx({
msgs: [
new MsgExecuteContract(
wallet.key.accAddress,
"",
{
submit_vaa: {
data: Buffer.from(registration, 'hex'),
},
},
{ uluna: 1000 }
),
],
memo: '',
})
.then(tx => terra.tx.broadcast(tx))
.then(rs => console.log(rs));
});
}
main()

View File

@ -2,6 +2,7 @@
while ! /bin/netcat -z localhost 26657; do
sleep 1
done
# Wait for first block
while [ $(curl localhost:26657/status -ks | jq ".result.sync_info.latest_block_height|tonumber") -lt 1 ]; do
sleep 1
@ -9,6 +10,6 @@ done
sleep 2
python deploy.py "http://terra-terrad:1317" "localterra" "notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius" 1 "0000000000000000000000000000000000000000000000000000000000000004" beFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe 86400
npm ci && node deploy.js
echo "Going to sleep, interrupt if running manually"
sleep infinity

1042
terra/tools/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
terra/tools/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "tools",
"version": "1.0.0",
"description": "",
"main": "deploy.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@terra-money/terra.js": "^2.0.11"
}
}