-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drafting deployment script and instructions
The plan is to use deploy.sh script to deploy programs on Solana and use a migration script to execute required instructions on the deployed programs.
- Loading branch information
Showing
5 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
node_modules | ||
test-ledger | ||
.yarn | ||
solana.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
help() { | ||
echo -e "\nUsage: $0 --cluster <cluster>" | ||
|
||
echo -e "\nCommand line arguments:\n" | ||
echo -e "\t--cluster: <cluster>\n" \ | ||
"\t\tAvailable deployment clusters: 'mainnet-beta', 'devnet', and 'localnet'." \ | ||
"Overrides a cluster set in Anchor.toml" | ||
exit 1 # Exit script after printing help | ||
} | ||
|
||
# Setting env variables in the current bash shell | ||
source solana.env | ||
|
||
# Transform long options to short ones | ||
for arg in "$@"; do | ||
shift | ||
case "$arg" in | ||
"--cluster") set -- "$@" "-n" ;; | ||
"--help") set -- "$@" "-h" ;; | ||
*) set -- "$@" "$arg" ;; | ||
esac | ||
done | ||
|
||
# Parse short options | ||
OPTIND=1 | ||
while getopts "n:w:h" opt; do | ||
case "$opt" in | ||
n) CLUSTER="$OPTARG" ;; | ||
h) help ;; | ||
?) help ;; # Print help in case parameter is non-existent | ||
esac | ||
done | ||
shift $(expr $OPTIND - 1) # remove options from positional parameters | ||
|
||
[ -z "$CLUSTER" ] && { | ||
echo "'--cluster' option not provided" >&2 | ||
help | ||
exit 1 | ||
} | ||
|
||
[ -z "$WALLET" ] && { | ||
echo "'WALLET' env var is not set" >&2 | ||
help | ||
exit 1 | ||
} | ||
|
||
echo "Building workspace for cluster: $CLUSTER" | ||
anchor build --provider.cluster $CLUSTER | ||
|
||
echo "Syncing the program's id ..." | ||
anchor keys sync | ||
|
||
echo "Building workspace again to include new program ID in the binary ..." | ||
anchor build --provider.cluster $CLUSTER | ||
|
||
echo "Deploying program(s) for cluster: $CLUSTER" | ||
anchor deploy --provider.cluster $CLUSTER --provider.wallet $WALLET | ||
|
||
echo "Migrating..." | ||
anchor migrate --provider.cluster $CLUSTER --provider.wallet $WALLET | ||
# TODO: anchor migrate // executes migrations/deploy.ts script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,55 @@ | ||
// Migrations are an early feature. Currently, they're nothing more than this | ||
// single deploy script that's invoked from the CLI, injecting a provider | ||
// configured from the workspace's Anchor.toml. | ||
|
||
const anchor = require("@coral-xyz/anchor"); | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import * as web3 from "@solana/web3.js"; | ||
import fs from "fs"; | ||
import { Keypair } from "@solana/web3.js"; | ||
import dotenv from "dotenv"; | ||
|
||
module.exports = async function (provider) { | ||
// Configure client to use the provider. | ||
dotenv.config({ path: "../solana.env" }) | ||
|
||
anchor.setProvider(provider); | ||
|
||
// Add your deploy script here. | ||
const program = anchor.workspace.Tbtc; | ||
// This wallet deployed the program and is also an authority | ||
const authority = loadKey(process.env.WALLET); | ||
const tbtcKeys = loadKey(process.env.TBTC_KEYS); | ||
|
||
const [tbtcMintPDA, _] = web3.PublicKey.findProgramAddressSync( | ||
[ | ||
anchor.utils.bytes.utf8.encode("tbtc-mint"), | ||
tbtcKeys.publicKey.toBuffer(), | ||
], | ||
program.programId, | ||
); | ||
|
||
// Initalize tbtc program | ||
await program.methods | ||
.initialize() | ||
.accounts({ | ||
tbtcMint: tbtcMintPDA, | ||
tbtc: tbtcKeys.publicKey, | ||
authority: authority.publicKey, | ||
}) | ||
.signers([tbtcKeys]) | ||
.rpc(); | ||
|
||
// add a minter (wormhole gateway (minter keys)) | ||
|
||
// add a guardian? | ||
|
||
// update mappings (self, arbitrum, optimism, polygon) | ||
|
||
// transfer ownership to council | ||
// solana program set-upgrade-authority -k <current_keypair_path> <programID> --new-upgrade-authority <pubkey> | ||
}; | ||
|
||
function loadKey(filename: string): Keypair { | ||
try { | ||
const contents = fs.readFileSync(filename).toString(); | ||
const bs = Uint8Array.from(JSON.parse(contents)); | ||
|
||
return Keypair.fromSecretKey(bs); | ||
} catch { | ||
console.log("Unable to read keypair...", filename); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
WALLET=<path> | ||
TBTC_KEYS=<path> | ||
UPGRADE_AUTHORITY=<threshold_council_multisig> |