Skip to content

Commit

Permalink
Drafting deployment scripts for Solana
Browse files Browse the repository at this point in the history
These changes include bash scripts and typescripts that are used to
build and deploy programs on Solana. We also need to initalize these
programs. More init work to come..
  • Loading branch information
dimpar committed Aug 8, 2023
1 parent b01aca1 commit 849d0ea
Show file tree
Hide file tree
Showing 10 changed files with 3,253 additions and 341 deletions.
3 changes: 2 additions & 1 deletion cross-chain/solana/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ target
node_modules
test-ledger
artifacts-mainnet
artifacts-testnet
artifacts-testnet
solana.env
3 changes: 3 additions & 0 deletions cross-chain/solana/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@thesis-co/prettier-config"),
}
1 change: 1 addition & 0 deletions cross-chain/solana/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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
84 changes: 75 additions & 9 deletions cross-chain/solana/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
// 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 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";

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(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 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))

// Add your deploy script here.
};
return Keypair.fromSecretKey(bs)
} catch {
console.log("Unable to read keypair...", filename)
}
}
Loading

0 comments on commit 849d0ea

Please sign in to comment.