-
Notifications
You must be signed in to change notification settings - Fork 134
/
deploy_old_lockup.sh
executable file
·121 lines (101 loc) · 3.29 KB
/
deploy_old_lockup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
if [ -z "${NEAR_ENV}" ]; then
echo "NEAR_ENV is required, e.g. \`export NEAR_ENV=testnet\`"
exit 1
fi
if [ -z "${MASTER_ACCOUNT_ID}" ]; then
echo "MASTER_ACCOUNT_ID is required, e.g. \`export MASTER_ACCOUNT_ID=near\`"
exit 1
fi
echo "Using NEAR_ENV=${NEAR_ENV}"
echo "Using MASTER_ACCOUNT_ID=${MASTER_ACCOUNT_ID}"
# Verifying master account exist
RES=$(near state $MASTER_ACCOUNT_ID | grep "amount" && echo "OK" || echo "BAD")
if [ "$RES" = "BAD" ]; then
echo "Can't get state for ${MASTER_ACCOUNT_ID}. Maybe the account doesn't exist."
exit 1
fi
read -p "Enter account ID (prefix) to create: " ACCOUNT_PREFIX
PREFIX_RE=$(grep -qE '^([a-z0-9]+[-_])*[a-z0-9]+$' <<< "$ACCOUNT_PREFIX" && echo "OK" || echo "BAD")
if [ "$PREFIX_RE" = "OK" ]; then
ACCOUNT_ID="$ACCOUNT_PREFIX.${MASTER_ACCOUNT_ID}"
else
echo "Invalid new account prefix."
exit 1
fi
LOCKUP_ACCOUNT_ID="lockup.$ACCOUNT_ID"
echo "Multi-sig account ID is $ACCOUNT_ID"
echo "Lockup account ID is $LOCKUP_ACCOUNT_ID"
if [ ${#LOCKUP_ACCOUNT_ID} -gt "64" ]; then
echo "The legnth of the lockup account is longer than 64 characters"
exit 1
fi
# Verifying the new account doesn't exist
RES=$(near state $ACCOUNT_ID | grep "amount" && echo "BAD" || echo "OK")
if [ "$RES" = "BAD" ]; then
echo "The account ${ACCOUNT_ID} already exist."
exit 1
fi
PUBLIC_KEYS=()
for i in {1..3}; do
while true; do
read -p "New account multisig public key in base58 format ($i/3): " KEY
REPL=$(echo "nearAPI.utils.key_pair.PublicKey.fromString('$KEY').data.length == 32")
RES=$(echo "$REPL" | near repl | grep -q "true" && echo "OK" || echo "BAD")
if [ "$RES" = "OK" ]; then
break;
else
echo "Invalid public key. Try again."
fi
done
PUBLIC_KEYS+=( $KEY )
done
MINIMUM_BALANCE="35"
while true; do
read -p "Enter the amount in NEAR tokens to deposit on lockup contract (min $MINIMUM_BALANCE): " LOCKUP_BALANCE
if [ "$LOCKUP_BALANCE" -ge "$MINIMUM_BALANCE" ]; then
break;
else
echo "The minimum balance has to be $MINIMUM_BALANCE. Try again."
fi
done
#
#if
#
#echo "Deploying staking pool factory contract to $ACCOUNT_ID with 50 NEAR"
#
#
#REPL=$(cat <<-END
#const fs = require('fs');
#const account = await near.account("$MASTER_ACCOUNT_ID");
#const contractName = "$ACCOUNT_ID";
#const newArgs = {staking_pool_whitelist_account_id: "$WHITELIST_ACCOUNT_ID"};
#await account.signAndSendTransaction(
# contractName,
# [
# nearAPI.transactions.createAccount(),
# nearAPI.transactions.transfer("50000000000000000000000000"),
# nearAPI.transactions.deployContract(fs.readFileSync("../../staking-pool-factory/res/staking_pool_factory.wasm")),
# nearAPI.transactions.functionCall("new", Buffer.from(JSON.stringify(newArgs)), 10000000000000, "0"),
# ]);
#END
#)
#
#echo $REPL | near repl
#
#echo "Whetelisting staking pool factory $ACCOUNT_ID on whitelist contract $WHITELIST_ACCOUNT_ID"
#
#REPL=$(cat <<-END
#const account = await near.account("$MASTER_ACCOUNT_ID");
#const contractName = "$WHITELIST_ACCOUNT_ID";
#const args = {factory_account_id: "$ACCOUNT_ID"};
#await account.signAndSendTransaction(
# contractName,
# [
# nearAPI.transactions.functionCall("add_factory", Buffer.from(JSON.stringify(args)), 10000000000000, "0"),
# ]);
#END
#)
#
#echo $REPL | near repl