diff --git a/Anchor.toml b/Anchor.toml index 199f004..d336947 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -3,6 +3,9 @@ seeds = false [programs.localnet] casier = "FLoc9nBwGb2ayzVzb5GC9NttuPY3CxMhd4KDnApr79Ab" +[programs.mainnet] +casier = "CAsieqooSrgVxhgWRwh21gyjq7Rmuhmo4qTW9XzXtAvW" + [registry] url = "https://anchor.projectserum.com" diff --git a/migrations/deploy.ts b/migrations/deploy.ts index 5e3df0d..cb9fcd0 100644 --- a/migrations/deploy.ts +++ b/migrations/deploy.ts @@ -2,11 +2,61 @@ // single deploy script that's invoked from the CLI, injecting a provider // configured from the workspace's Anchor.toml. -const anchor = require("@project-serum/anchor"); +import * as anchor from "@project-serum/anchor"; +import { Program, AnchorProvider, Wallet } from "@project-serum/anchor"; +import { Casier } from "../target/types/casier"; +import { + PublicKey, + Connection, + Keypair, + SystemProgram, + SYSVAR_RENT_PUBKEY, +} from "@solana/web3.js"; +import * as fs from "fs"; -module.exports = async function (provider) { +function loadKeypair(keypairPath: string): any { + return JSON.parse(fs.readFileSync(keypairPath).toString()); +} + +function loadWallet(keypair: string): Keypair { + return Keypair.fromSecretKey(new Uint8Array(loadKeypair(keypair))); +} + +const fee_payer = loadWallet(process.env.FEE_PAYER_KEY_PATH); + +module.exports = async function () { // Configure client to use the provider. - anchor.setProvider(provider); + const idl = JSON.parse( + require("fs") + .readFileSync(`${process.cwd()}/../target/idl/casier.json`, "utf8") + .toString() + ); + const connection = new Connection(process.env.RPC_ENDPOINT, "recent"); + const wallet = new Wallet(fee_payer); + const provider = new AnchorProvider(connection, wallet, { + commitment: "recent", + }); + const program = new Program( + idl, + new PublicKey("CAsieqooSrgVxhgWRwh21gyjq7Rmuhmo4qTW9XzXtAvW"), + provider + ); + const tx1 = await program.methods.initialize().rpc(); + console.log(tx1); + const [configPDA] = await PublicKey.findProgramAddress( + [anchor.utils.bytes.utf8.encode("config")], + program.programId + ); + const tx2 = await program.methods + .initConfig() + .accounts({ + config: configPDA, + feePayer: fee_payer.publicKey, + systemProgram: SystemProgram.programId, + rent: SYSVAR_RENT_PUBKEY, + }) + .rpc(); + console.log(tx2); // Add your deploy script here. };