diff --git a/scripts/docker_build.sh b/scripts/docker_build.sh new file mode 100644 index 0000000..7fd105d --- /dev/null +++ b/scripts/docker_build.sh @@ -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 diff --git a/scripts/multisafeUpgrade.js b/scripts/multisafeUpgrade.js new file mode 100644 index 0000000..4a393c0 --- /dev/null +++ b/scripts/multisafeUpgrade.js @@ -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 + ); + +})();