Created
January 7, 2023 19:03
-
-
Save gchatz22/44ab349d4fd57207601a23df099bd26e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { executeTransaction } from "@cardinal/common"; | |
import type { Wallet } from "@coral-xyz/anchor"; | |
import { BN } from "@coral-xyz/anchor"; | |
import type { Connection } from "@solana/web3.js"; | |
import { PublicKey, Transaction } from "@solana/web3.js"; | |
import { findPaymentInfoId, rewardsCenterProgram } from "../../sdk"; | |
export const commandName = "createPaymentInfo"; | |
export const description = "Create a payment info object"; | |
export const getArgs = (_connection: Connection, wallet: Wallet) => ({ | |
identifier: "cardinal-default", | |
authority: wallet.publicKey, | |
paymentAmount: 5 * 10 ** 7, | |
paymentMint: PublicKey.default, | |
paymentShares: [ | |
{ | |
address: new PublicKey("cteamyte8zjZTeexp3qTzvpb24TKRSL3HFad9SzNaNJ"), | |
basisPoints: 10000, | |
}, | |
], | |
}); | |
export type InitPaymentInfoIx = { | |
authority: PublicKey; | |
identifier: string; | |
paymentAmount: number; | |
paymentMint: PublicKey; | |
paymentShares: { address: PublicKey; basisPoints: number }[]; | |
}; | |
export const handler = async ( | |
connection: Connection, | |
wallet: Wallet, | |
args: InitPaymentInfoIx | |
) => { | |
const transaction = new Transaction(); | |
const paymentInfoId = findPaymentInfoId(args.identifier); | |
const program = rewardsCenterProgram(connection, wallet); | |
transaction.add( | |
await program.methods | |
.initPaymentInfo({ | |
authority: args.authority, | |
identifier: args.identifier, | |
paymentAmount: new BN(args.paymentAmount), | |
paymentMint: args.paymentMint, | |
paymentShares: args.paymentShares, | |
}) | |
.accounts({ paymentInfo: paymentInfoId, payer: wallet.publicKey }) | |
.instruction() | |
); | |
await new Promise((r) => setTimeout(r, 200)); | |
await executeTransaction(connection, transaction, wallet); | |
console.log( | |
`Created payment manager ${args.identifier} [${paymentInfoId.toString()}]`, | |
args | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment