#!/usr/bin/env bash # One-shot mainnet setup. Run only after the dev account holds the funds and only # with a wasm built by CI. Stops at the first failure. Keys are read from files. # mainnet-setup.sh set -euo pipefail WASM=$1; K=$2 cd "$(dirname "$0")/.." USDC=17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1 need() { [ -r "$K/$1" ] || { echo "missing key file $1"; exit 1; }; } for f in mainnet-dev.json dulypay.near.json relayer.dulypay.near.json agent.dulypay.near.json agent.dulypay.near.fc.json; do need "$f"; done PK=$(python3 -I -c "import json;print(json.load(open('$K/dulypay.near.json'))['public_key'])") FC=$(python3 -I -c "import json;print(json.load(open('$K/agent.dulypay.near.fc.json'))['public_key'])") exists() { node scripts/chain.mjs exists mainnet "$1" | grep -q yes; } echo "1. create dulypay.near (2.20 NEAR for code and state)" exists dulypay.near || node scripts/chain.mjs call mainnet "$K/mainnet-dev.json" near create_account "{\"new_account_id\":\"dulypay.near\",\"new_public_key\":\"$PK\"}" 100 2200000000000000000000000 echo "2. fund it first: a deploy needs headroom for the gas it prepays, on top of storage" node scripts/chain.mjs transfer mainnet "$K/mainnet-dev.json" dulypay.near 0.26 echo "3. deploy and initialise" node scripts/chain.mjs deploy mainnet "$K/dulypay.near.json" "$WASM" new "{\"usdc\":\"$USDC\",\"intents\":\"intents.near\"}" echo "4. register the contract on USDC, then create the relayer and agent accounts" node scripts/chain.mjs call mainnet "$K/mainnet-dev.json" "$USDC" storage_deposit '{"account_id":"dulypay.near","registration_only":true}' 30 1250000000000000000000 node scripts/chain.mjs subaccount mainnet "$K/dulypay.near.json" "$K/relayer.dulypay.near.json" 0.22 node scripts/chain.mjs subaccount mainnet "$K/dulypay.near.json" "$K/agent.dulypay.near.json" 0.03 echo "5. agent gets a key that can only call offer_discount and agent_sweep" node scripts/chain.mjs addfnkey mainnet "$K/agent.dulypay.near.json" "$FC" dulypay.near offer_discount,agent_sweep 25000000000000000000000 echo "6. check" node scripts/chain.mjs view mainnet dulypay.near get_config '{}' | tr -d '\n '; echo