forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-contracts.sh
More file actions
executable file
·142 lines (117 loc) · 3.49 KB
/
Copy pathdeploy-contracts.sh
File metadata and controls
executable file
·142 lines (117 loc) · 3.49 KB
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
141
142
#!/usr/bin/env bash
set -euo pipefail
NETWORK="${NETWORK:-testnet}"
DRY_RUN=false
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
CONTRACTS_DIR="$(cd "$(dirname "$0")/../contracts" && pwd)"
ENV_FILE="$(cd "$(dirname "$0")/.." && pwd)/.env.${NETWORK}"
if [[ "$NETWORK" == "mainnet" ]]; then
NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
RPC_URL="${MAINNET_RPC_URL:-https://soroban-rpc.stellar.org}"
else
NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
RPC_URL="${TESTNET_RPC_URL:-https://soroban-testnet.stellar.org}"
fi
: "${DEPLOYER_SECRET:?DEPLOYER_SECRET is required}"
: "${ADMIN_ADDRESS:?ADMIN_ADDRESS is required}"
: "${ADMIN_SIGNERS:=${ADMIN_ADDRESS}}"
: "${ADMIN_THRESHOLD:=1}"
log() { echo "[deploy] $*"; }
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
exit 1
fi
}
run() {
log "$ $*"
$DRY_RUN && return 0
eval "$@"
}
write_env() {
local key="$1" val="$2"
if grep -q "^${key}=" "$ENV_FILE" 2>/dev/null; then
sed -i "s|^${key}=.*|${key}=${val}|" "$ENV_FILE"
else
echo "${key}=${val}" >> "$ENV_FILE"
fi
}
build_contract() {
local pkg="$1"
log "Building ${pkg}..."
run cargo build --manifest-path "${CONTRACTS_DIR}/Cargo.toml" \
--target wasm32v1-none --release \
-p "${pkg}"
}
optimize_wasm() {
local pkg="$1"
local wasm="${CONTRACTS_DIR}/target/wasm32v1-none/release/${pkg}.wasm"
log "Optimising ${pkg}.wasm..."
run stellar contract optimize --wasm "$wasm"
}
upload_contract() {
local pkg="$1"
local wasm="${CONTRACTS_DIR}/target/wasm32v1-none/release/${pkg}.optimized.wasm"
log "Uploading ${pkg}..."
if $DRY_RUN; then echo "DRY_RUN_HASH_${pkg}"; return; fi
stellar contract upload \
--wasm "$wasm" \
--network-passphrase "${NETWORK_PASSPHRASE}" \
--rpc-url "${RPC_URL}" \
--source "${DEPLOYER_SECRET}"
}
deploy_contract() {
local pkg="$1" wasm_hash="$2"
log "Deploying ${pkg} (hash: ${wasm_hash})..."
if $DRY_RUN; then echo "DRY_RUN_CONTRACT_ID_${pkg}"; return; fi
stellar contract deploy \
--wasm-hash "$wasm_hash" \
--network-passphrase "${NETWORK_PASSPHRASE}" \
--rpc-url "${RPC_URL}" \
--source "${DEPLOYER_SECRET}"
}
invoke_init() {
local contract_id="$1"; shift
log "Initialising ${contract_id}..."
if $DRY_RUN; then return; fi
stellar contract invoke \
--id "$contract_id" \
--network-passphrase "${NETWORK_PASSPHRASE}" \
--rpc-url "${RPC_URL}" \
--source "${DEPLOYER_SECRET}" \
-- initialize "$@"
}
deploy() {
local pkg="$1" env_key="$2"; shift 2
build_contract "$pkg"
optimize_wasm "$pkg"
local hash; hash=$(upload_contract "$pkg")
local id; id=$(deploy_contract "$pkg" "$hash")
write_env "$env_key" "$id"
log "${env_key}=${id}"
invoke_init "$id" "$@"
}
require_cmd cargo
require_cmd stellar
deploy nova_token NOVA_TOKEN_CONTRACT_ID \
--admin "${ADMIN_ADDRESS}"
deploy reward_pool REWARD_POOL_CONTRACT_ID \
--admin "${ADMIN_ADDRESS}"
deploy vesting CLAIM_DISTRIBUTION_CONTRACT_ID \
--admin "${ADMIN_ADDRESS}"
deploy referral STAKING_CONTRACT_ID \
--admin "${ADMIN_ADDRESS}"
SIGNERS_JSON="["
first=true
for addr in $ADMIN_SIGNERS; do
$first || SIGNERS_JSON+=","
SIGNERS_JSON+="\"${addr}\""
first=false
done
SIGNERS_JSON+="]"
deploy admin_roles ADMIN_ROLES_CONTRACT_ID \
--admin "${ADMIN_ADDRESS}" \
--signers "${SIGNERS_JSON}" \
--threshold "${ADMIN_THRESHOLD}"
log "All contracts deployed. IDs written to ${ENV_FILE}"
$DRY_RUN && log "(dry-run: no transactions were broadcast)"