Skip to content

Commit

Permalink
Adjusting deployment scripts to utilize Makefile
Browse files Browse the repository at this point in the history
- Moved init TS scripts to /deploy dir
- Building programs with make build
- Deploying programs with solana cli instead of anchor
  • Loading branch information
dimpar committed Aug 8, 2023
1 parent 849d0ea commit 3882cc4
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 97 deletions.
6 changes: 6 additions & 0 deletions cross-chain/solana/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export AUTHORITY=<path_to_keypair_deployer>
export THRESHOLD_COUNCIL_MULTISIG=<multisig_address>
export NETWORK=<solana-devnet, mainnet>
export CLUSTER=<devnet, mainnet-beta>
export ANCHOR_PROVIDER_URL=<http://localhost:8899, https://api.devnet.solana.com, https://api.mainnet-beta.solana.com>
export ANCHOR_WALLET=<path_to_keypair_deployer>
2 changes: 1 addition & 1 deletion cross-chain/solana/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ node_modules
test-ledger
artifacts-mainnet
artifacts-testnet
solana.env
.env
1 change: 0 additions & 1 deletion cross-chain/solana/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ wallet = "~/.config/solana/id.json"

[scripts]
test = "npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
authority = "ts-node --files ./typescript/transfer_authority.ts"

[test]
startup_wait = 10000
Expand Down
8 changes: 7 additions & 1 deletion cross-chain/solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ lint:
cargo fmt --check
cargo check --features "mainnet" --no-default-features
cargo check --features "solana-devnet" --no-default-features
cargo clippy --no-deps --all-targets -- -D warnings
cargo clippy --no-deps --all-targets -- -D warnings

init_programs:
ts-node --files ./deploy/deploy.ts

transfer_authority:
ts-node --files deploy/transfer_authority.ts
89 changes: 89 additions & 0 deletions cross-chain/solana/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as anchor from "@coral-xyz/anchor"
import fs from "fs"
import { PublicKey, Keypair } from "@solana/web3.js"
import dotenv from "dotenv"
import { Program } from "@coral-xyz/anchor";
import { Tbtc } from "../target/types/tbtc";
import { PROGRAM_ID as METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";

async function run(): Promise<void> {
dotenv.config({ path: "../solana.env" })

anchor.setProvider(anchor.AnchorProvider.env());

const tbtcProgram = anchor.workspace.Tbtc as Program<Tbtc>;

// This wallet deployed the program and is also an authority
const authority = (loadKey(process.env.AUTHORITY)).publicKey

const mint = PublicKey.findProgramAddressSync(
[Buffer.from("tbtc-mint")],
tbtcProgram.programId
)[0];

const config = PublicKey.findProgramAddressSync(
[Buffer.from("config")],
tbtcProgram.programId
)[0];

const guardians = PublicKey.findProgramAddressSync(
[Buffer.from("guardians")],
tbtcProgram.programId
)[0];

const minters = PublicKey.findProgramAddressSync(
[Buffer.from("minters")],
tbtcProgram.programId
)[0];

const tbtcMetadata = PublicKey.findProgramAddressSync(
[
Buffer.from("metadata"),
METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
METADATA_PROGRAM_ID
)[0];

const mplTokenMetadataProgram = METADATA_PROGRAM_ID;

// Initalize tbtc program
await tbtcProgram.methods
.initialize()
.accounts({
mint,
config,
guardians,
minters,
authority,
tbtcMetadata,
mplTokenMetadataProgram
})
.instruction()


// add minter

// add guardian?

// update mappings (self, base, arbitrum, optimism, polygon)
}

;(async () => {
try {
await run()
} catch (e) {
console.log("Exception called:", e)
}
})()

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)
}
}
85 changes: 9 additions & 76 deletions cross-chain/solana/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,11 @@
import * as anchor from "@coral-xyz/anchor"
import fs from "fs"
import { PublicKey, Keypair } from "@solana/web3.js"
import dotenv from "dotenv"
import { PROGRAM_ID as METADATA_PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata";
// 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.

module.exports = async function (provider) {
dotenv.config({ path: "../solana.env" })

anchor.setProvider(provider)

const tbtcProgram = anchor.workspace.Tbtc
// This wallet deployed the program and is also an authority
const authority = loadKey(process.env.AUTHORITY)
const newAuthority = process.env.THRESHOLD_COUNCIL_MULTISIG

const mint = PublicKey.findProgramAddressSync(
[Buffer.from("tbtc-mint")],
tbtcProgram.programId
)[0];

const config = PublicKey.findProgramAddressSync(
[Buffer.from("config")],
tbtcProgram.programId
)[0];

const guardians = PublicKey.findProgramAddressSync(
[Buffer.from("guardians")],
tbtcProgram.programId
)[0];

const minters = PublicKey.findProgramAddressSync(
[Buffer.from("minters")],
tbtcProgram.programId
)[0];

const tbtcMetadata = PublicKey.findProgramAddressSync(
[
Buffer.from("metadata"),
METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
METADATA_PROGRAM_ID
)[0];
const anchor = require("@coral-xyz/anchor");

const mplTokenMetadataProgram = METADATA_PROGRAM_ID;

// Initalize tbtc program
await tbtcProgram.methods
.initialize()
.accounts({
mint,
config,
guardians,
minters,
authority,
tbtcMetadata,
mplTokenMetadataProgram
})
.instruction()

// add minter

// add guardian?

// update mappings (self, base, arbitrum, optimism, polygon)
}

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)
}
}
module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);
// Add your deploy script here.
};
31 changes: 16 additions & 15 deletions cross-chain/solana/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
set -eo pipefail

# Setting env variables in the current bash shell
source solana.env
source .env

[ -z "$CLUSTER" ] && {
echo "'--cluster' option not provided" >&2
help
# Deploy to devnet by default
ARTIFACTS_PATH=artifacts-testnet

[ -z "$NETWORK" ] && {
echo "'NETWORK' env var is not set" >&2
exit 1
}

Expand All @@ -15,17 +17,16 @@ source solana.env
exit 1
}

echo "Building workspace for cluster: $CLUSTER ..."
anchor build --provider.cluster $CLUSTER

echo "Syncing the program's id ..."
anchor keys sync
if [[ $CLUSTER = mainnet-beta ]]
then
ARTIFACTS_PATH=artifacts-mainnet
fi

echo "Building workspace again to include new program ID in the binary ..."
anchor build --provider.cluster $CLUSTER
echo "Building workspace for cluster: $NETWORK ..."
make build

echo "Deploying program(s) for cluster: $CLUSTER ..."
anchor deploy --provider.cluster $CLUSTER --provider.wallet $AUTHORITY
echo "Deploying TBTC program for cluster: $CLUSTER ..."
solana program deploy --url $CLUSTER --keypair $AUTHORITY ./$ARTIFACTS_PATH/tbtc.so

echo "Migrating..."
anchor migrate --provider.cluster $CLUSTER --provider.wallet $AUTHORITY
echo "Deploying WORMHOLE_GATEWAY program for cluster: $CLUSTER ..."
solana program deploy --url $CLUSTER --keypair $AUTHORITY ./$ARTIFACTS_PATH/wormhole_gateway.so
3 changes: 0 additions & 3 deletions cross-chain/solana/solana.env.template

This file was deleted.

0 comments on commit 3882cc4

Please sign in to comment.