-
Notifications
You must be signed in to change notification settings - Fork 134
/
deploy_lockup.sh
executable file
·140 lines (120 loc) · 4.36 KB
/
deploy_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/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
if [ -z "${LOCKUP_MASTER_ACCOUNT_ID}" ]; then
echo "LOCKUP_MASTER_ACCOUNT_ID is required, e.g. \`export LOCKUP_MASTER_ACCOUNT_ID=lockup\`"
exit 1
fi
echo "Using NEAR_ENV=${NEAR_ENV}"
echo "Using MASTER_ACCOUNT_ID=${MASTER_ACCOUNT_ID}"
echo "Using LOCKUP_MASTER_ACCOUNT_ID=${LOCKUP_MASTER_ACCOUNT_ID}"
# Verifying master account exist
RES=$(near state $LOCKUP_MASTER_ACCOUNT_ID | grep "amount" && echo "OK" || echo "BAD")
if [ "$RES" = "BAD" ]; then
echo "Can't get state for ${LOCKUP_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.${LOCKUP_MASTER_ACCOUNT_ID}"
else
echo "Invalid new account prefix."
exit 1
fi
LOCKUP_ACCOUNT_ID=$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
while true; do
read -p "Enter OWNER_ACCOUNT_ID: " OWNER_ACCOUNT_ID
# Verifying master account exist
RES=$(near state $OWNER_ACCOUNT_ID | grep "amount" && echo "OK" || echo "BAD")
if [ "$RES" = "BAD" ]; then
echo "Can't get state for ${OWNER_ACCOUNT_ID}. Maybe the account doesn't exist."
else
echo "Using owner's account ID $OWNER_ACCOUNT_ID"
break;
fi
done
MINIMUM_BALANCE="35"
while true; do
read -p "Enter the amount in NEAR tokens (not yocto) to deposit on lockup contract (min $MINIMUM_BALANCE): " LOCKUP_BALANCE
if [ "$LOCKUP_BALANCE" -ge "$MINIMUM_BALANCE" ]; then
echo "Going to deposit $LOCKUP_BALANCE tokens or ${LOCKUP_BALANCE}000000000000000000000000 yocto NEAR"
break;
else
echo "The lockup balance has to be at least $MINIMUM_BALANCE NEAR tokens. Try again."
fi
done
VOTE_ACCOUNT_ID="vote.${MASTER_ACCOUNT_ID}"
WHITELIST_ACCOUNT_ID="whitelist.${MASTER_ACCOUNT_ID}"
REPL=$(cat <<-END
await new Promise(resolve => setTimeout(resolve, 100));
const fs = require('fs');
const account = await near.account("$LOCKUP_MASTER_ACCOUNT_ID");
const contractName = "$ACCOUNT_ID";
const newArgs = {
"owner_account_id": "$OWNER_ACCOUNT_ID",
"lockup_duration": "259200000000000",
"transfers_information": {
"TransfersDisabled": {
"transfer_poll_account_id": "$VOTE_ACCOUNT_ID"
}
},
"release_duration": "2592000000000000",
"staking_pool_whitelist_account_id": "$WHITELIST_ACCOUNT_ID",
};
await account.signAndSendTransaction(
contractName,
[
nearAPI.transactions.createAccount(),
nearAPI.transactions.transfer("${LOCKUP_BALANCE}000000000000000000000000"),
nearAPI.transactions.deployContract(fs.readFileSync("../lockup/res/lockup_contract.wasm")),
nearAPI.transactions.functionCall("new", Buffer.from(JSON.stringify(newArgs)), 10000000000000, "0"),
]);
END
)
#
#REPL=$(cat <<-END
#await new Promise(resolve => setTimeout(resolve, 100));
#const fs = require('fs');
#const account = await near.account("$LOCKUP_MASTER_ACCOUNT_ID");
#const contractName = "$ACCOUNT_ID";
#const newArgs = {
# "owner_account_id": "$OWNER_ACCOUNT_ID",
# "lockup_duration": "259200000000000",
# "transfers_information": {
# "TransfersEnabled": {
# "transfers_timestamp": "1597600995135000000"
# }
# },
# "release_duration": "2592000000000000",
# "staking_pool_whitelist_account_id": "$WHITELIST_ACCOUNT_ID",
#};
#await account.signAndSendTransaction(
# contractName,
# [
# nearAPI.transactions.createAccount(),
# nearAPI.transactions.transfer("${LOCKUP_BALANCE}000000000000000000000000"),
# nearAPI.transactions.deployContract(fs.readFileSync("../lockup/res/lockup_contract.wasm")),
# nearAPI.transactions.functionCall("new", Buffer.from(JSON.stringify(newArgs)), 10000000000000, "0"),
# ]);
#END
#)
echo $REPL | near repl