-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da969bb
commit 7d29012
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |