Skip to content

Commit

Permalink
add build and upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
achamely committed Sep 13, 2022
1 parent ff80e45 commit 700cc08
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

NAME="build_tether_near"

if docker ps -a --format '{{.Names}}' | grep -Eq "^${NAME}\$"; then
echo "Container exists"
else
docker create \
--mount type=bind,source=$DIR/..,target=/host \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
--name=$NAME \
-w /host/tether-near \
-e RUSTFLAGS='-C link-arg=-s' \
-it \
nearprotocol/contract-builder \
/bin/bash
fi

docker start $NAME
docker exec -it $NAME /bin/bash -c "rustup toolchain install stable; rustup default stable; rustup target add wasm32-unknown-unknown; cargo build --target wasm32-unknown-unknown --profile release; cargo test"

mkdir -p $DIR/../res
cp $DIR/../target/wasm32-unknown-unknown/release/tether_token.wasm $DIR/../res/tether_token.wasm
72 changes: 72 additions & 0 deletions scripts/multisafeUpgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict';
const nearAPI = require('near-api-js');
const { Contract } = nearAPI;
const BN = require('bn.js');
const fs = require('fs').promises;
const assert = require('assert').strict;

//const config = {
// networkId: 'testnet',
// nodeUrl: 'https://rpc.testnet.near.org',
// keyPath: '/home/user/.near-credentials/testnet/user.testnet.json',
// contractPath: './res/tether_token.wasm',
// accountId: 'user.testnet',
// contractId: 'usdt.token',
// msafeId: 'vault.multisafe',
//};

const config = {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.near.org',
keyPath: '/home/user/.near-credentials/mainnet/user.json',
contractPath: './res/tether_token.wasm',
accountId: 'user',
contractId: 'usdt.tether-token.near',
msafeId: 'tether.multisafe.near',
};

(async function () {
const keyFile = require(config.keyPath);
const privKey = nearAPI.utils.KeyPair.fromString(keyFile.private_key);

const keyStore = new nearAPI.keyStores.InMemoryKeyStore();
keyStore.setKey(config.networkId, config.accountId, privKey);

const near = await nearAPI.connect({
deps: {
keyStore,
},
networkId: config.networkId,
nodeUrl: config.nodeUrl,
});

const wasm = await fs.readFile(config.contractPath);
const account = new nearAPI.Account(near.connection, config.accountId);
const contract = new Contract(
account,
config.msafeId,
{
changeMethods: ['add_request_and_confirm'],
sender: account,
}
);

// Send Upgrade contract to multisafe.
await contract.add_request_and_confirm({
request: {
receiver_id: config.contractId,
actions: [
{
type: 'FunctionCall',
method_name: 'upgrade',
args: wasm.toString('base64'),
deposit:'0',
gas: '250000000000000',
},
],
}
},
300000000000000
);

})();

0 comments on commit 700cc08

Please sign in to comment.