diff --git a/cross-chain/solana/.env.template b/cross-chain/solana/.env.template new file mode 100644 index 000000000..564120216 --- /dev/null +++ b/cross-chain/solana/.env.template @@ -0,0 +1,6 @@ +export AUTHORITY= +export THRESHOLD_COUNCIL_MULTISIG= +export NETWORK= +export CLUSTER= +export ANCHOR_PROVIDER_URL= +export ANCHOR_WALLET= \ No newline at end of file diff --git a/cross-chain/solana/.gitignore b/cross-chain/solana/.gitignore index 29be122a2..05e8d8768 100644 --- a/cross-chain/solana/.gitignore +++ b/cross-chain/solana/.gitignore @@ -8,4 +8,4 @@ node_modules test-ledger artifacts-mainnet artifacts-testnet -solana.env \ No newline at end of file +.env \ No newline at end of file diff --git a/cross-chain/solana/Anchor.toml b/cross-chain/solana/Anchor.toml index 46ce2c333..052529539 100644 --- a/cross-chain/solana/Anchor.toml +++ b/cross-chain/solana/Anchor.toml @@ -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 diff --git a/cross-chain/solana/Makefile b/cross-chain/solana/Makefile index 60201a688..8440d187c 100644 --- a/cross-chain/solana/Makefile +++ b/cross-chain/solana/Makefile @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/cross-chain/solana/deploy/deploy.ts b/cross-chain/solana/deploy/deploy.ts new file mode 100644 index 000000000..6335d4d9f --- /dev/null +++ b/cross-chain/solana/deploy/deploy.ts @@ -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 { + dotenv.config({ path: "../solana.env" }) + + anchor.setProvider(anchor.AnchorProvider.env()); + + const tbtcProgram = anchor.workspace.Tbtc as Program; + + // 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) + } +} \ No newline at end of file diff --git a/cross-chain/solana/typescript/transfer_authority.ts b/cross-chain/solana/deploy/transfer_authority.ts similarity index 100% rename from cross-chain/solana/typescript/transfer_authority.ts rename to cross-chain/solana/deploy/transfer_authority.ts diff --git a/cross-chain/solana/migrations/deploy.ts b/cross-chain/solana/migrations/deploy.ts index 8c5ae8ac9..448a1b3f2 100644 --- a/cross-chain/solana/migrations/deploy.ts +++ b/cross-chain/solana/migrations/deploy.ts @@ -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) - } -} \ No newline at end of file +module.exports = async function (provider) { + // Configure client to use the provider. + anchor.setProvider(provider); + // Add your deploy script here. +}; \ No newline at end of file diff --git a/cross-chain/solana/scripts/deploy.sh b/cross-chain/solana/scripts/deploy.sh index a0619f171..19d2dcd55 100755 --- a/cross-chain/solana/scripts/deploy.sh +++ b/cross-chain/solana/scripts/deploy.sh @@ -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 } @@ -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 \ No newline at end of file +echo "Deploying WORMHOLE_GATEWAY program for cluster: $CLUSTER ..." +solana program deploy --url $CLUSTER --keypair $AUTHORITY ./$ARTIFACTS_PATH/wormhole_gateway.so diff --git a/cross-chain/solana/solana.env.template b/cross-chain/solana/solana.env.template deleted file mode 100644 index 17955b8fe..000000000 --- a/cross-chain/solana/solana.env.template +++ /dev/null @@ -1,3 +0,0 @@ -AUTHORITY= -THRESHOLD_COUNCIL_MULTISIG= -CLUSTER= \ No newline at end of file