Skip to content

Commit

Permalink
init group tx
Browse files Browse the repository at this point in the history
  • Loading branch information
jgur-psyops committed Dec 13, 2024
1 parent da969bb commit 7d29012
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/scripts-ts/accounts_ref.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
TODO list of common banks and groups...

## PROGRAMS
* Mainnet - MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA
* Staging - stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct

## GROUPS
* Main group - 4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8
* Staging - FCPfpHA69EbS8f9KKSreTRkXbzFpunsKuYf5qNmnJjpo
Expand Down
66 changes: 66 additions & 0 deletions packages/scripts-ts/init_group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Connection, Keypair, PublicKey, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { Marginfi } from "../marginfi-client-v2/src/idl/marginfi-types";
import marginfiIdl from "../marginfi-client-v2/src/idl/marginfi.json";
import { loadKeypairFromFile } from "./utils";
import { assertI80F48Approx, assertKeysEqual } from "./softTests";

const verbose = true;

type Config = {
PROGRAM_ID: string;
ADMIN_KEY: PublicKey;
};

const config: Config = {
PROGRAM_ID: "stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct",
ADMIN_KEY: new PublicKey("mfC1LoEk4mpM5yx1LjwR9QLZQ49AitxxWkK5Aciw7ZC"),
};

const deriveGlobalFeeState = (programId: PublicKey) => {
return PublicKey.findProgramAddressSync([Buffer.from("feestate", "utf-8")], programId);
};

async function main() {
marginfiIdl.address = config.PROGRAM_ID;
const marginfiGroup = Keypair.generate();
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
const wallet = loadKeypairFromFile(process.env.HOME + "/keys/staging-deploy.json");
console.log("wallet: " + wallet.publicKey);

// @ts-ignore
const provider = new AnchorProvider(connection, wallet, {
preflightCommitment: "confirmed",
});

const program = new Program<Marginfi>(
// @ts-ignore
marginfiIdl as Marginfi,
provider
);
const transaction = new Transaction();
transaction.add(
await program.methods
.marginfiGroupInitialize()
.accounts({
marginfiGroup: marginfiGroup.publicKey,
// feeState: deriveGlobalFeeState(id),
admin: config.ADMIN_KEY,
// systemProgram: SystemProgram.programId,
})
.instruction()
);

try {
const signature = await sendAndConfirmTransaction(connection, transaction, [wallet, marginfiGroup]);
console.log("Transaction signature:", signature);
} catch (error) {
console.error("Transaction failed:", error);
}

console.log("Group init: " + marginfiGroup.publicKey);
}

main().catch((err) => {
console.error(err);
});

0 comments on commit 7d29012

Please sign in to comment.