diff --git a/programs/cardinal-rewards-center/src/payment/state.rs b/programs/cardinal-rewards-center/src/payment/state.rs index 15ee262b..69da4ba8 100644 --- a/programs/cardinal-rewards-center/src/payment/state.rs +++ b/programs/cardinal-rewards-center/src/payment/state.rs @@ -42,27 +42,12 @@ pub enum Action { pub fn assert_payment_info(stake_pool: Pubkey, action: Action, payment_info: Pubkey) -> Result<()> { let default_allowed_payment_infos = match action { - Action::ClaimRewards => [ - "CUeHFsFqfbLfBGSbuNbaAi4wK6V835PoRg1CqCLo8tpM".to_string(), // claim-rewards-0 - "AmJdpbtEzFBVWhznaEQM3V4fNZBa8FWj36Lu2BtnaDYt".to_string(), // cardinal-test-wsol - ] - .to_vec(), _ => [ - "3dxFgrZt9DLn1J5ZB1bDwjeDvbESzNxA11KggRcywKbm".to_string(), // cardinal-test (native) - "AmJdpbtEzFBVWhznaEQM3V4fNZBa8FWj36Lu2BtnaDYt".to_string(), // cardinal-test-wsol - "HB8ApbkwKNXUTpYxgAXKG5GsRV9uPD7Drsj9rCw4M6a7".to_string(), // 1-dust + "7cKQgnFTzLtdNWgMuQVQG4LjWShsGsgXx284VBr5eRsM".to_string(), // cardinal-default 0.005 ] .to_vec(), }; let allowed_payment_infos = match (stake_pool.key().to_string().as_str(), action) { - // y00ts - ("6GWB85u6uPmhWLsP2kww7pPrn3tdu6itjTgqvLGhD5oM", Action::ClaimRewards) => ["8qPuPHyxaRPf6qazsb6iqBBe4Dm4AM88MoQnf5cRU9A3".to_string()].to_vec(), // claim-rewards-y00ts - ("6GWB85u6uPmhWLsP2kww7pPrn3tdu6itjTgqvLGhD5oM", Action::Stake) => ["2w2XUCTzhpdGz5DmAV4C6UWKX8dUcofLRKB3LLHFs6ep".to_string()].to_vec(), // stake-y00ts - ("6GWB85u6uPmhWLsP2kww7pPrn3tdu6itjTgqvLGhD5oM", Action::Unstake) => ["67z45vkcgMQnyfKULurbvazyxJT5oLDtQ3PbZSu9Bt3X".to_string()].to_vec(), // unstake-y00ts - // degods - ("D7UVbgKZHetCzqMErp6nA9TmGMkDAMrLj7a2Hcx8p5Lx", Action::ClaimRewards) => ["5QvTr4GhT9zpWDfdtX3p4jFLfp9WKFxZEmj1JKww1KCD".to_string()].to_vec(), // claim-rewards-degods - ("D7UVbgKZHetCzqMErp6nA9TmGMkDAMrLj7a2Hcx8p5Lx", Action::Stake) => ["6xfYPm79w4sBurpMS6qvX5avqww4q5gXVdRvrivDLrt1".to_string()].to_vec(), // stake-degods - ("D7UVbgKZHetCzqMErp6nA9TmGMkDAMrLj7a2Hcx8p5Lx", Action::Unstake) => ["DSzrtPLkJYKHyuE8HeZiaKNvnEGk7UrcoDUauwqAnwek".to_string()].to_vec(), // unstake-degods _ => default_allowed_payment_infos, }; if !allowed_payment_infos.contains(&payment_info.to_string()) { diff --git a/tools/cli.ts b/tools/cli.ts index 63708c94..55564b7f 100644 --- a/tools/cli.ts +++ b/tools/cli.ts @@ -1,12 +1,7 @@ -#!/usr/bin/env node -/* eslint-disable import/first */ -import * as dotenv from "dotenv"; - -dotenv.config(); - import { connectionFor } from "@cardinal/common"; import { Wallet } from "@project-serum/anchor"; import type { Cluster, Connection } from "@solana/web3.js"; +import * as dotenv from "dotenv"; import * as readline from "readline"; import type { ArgumentsCamelCase, CommandModule } from "yargs"; import yargs from "yargs"; @@ -17,6 +12,8 @@ import * as updatePaymentInfo from "./payment/updatePaymentInfo"; import * as getStakePool from "./stake-pool/getStakePool"; import { keypairFrom } from "./utils"; +dotenv.config(); + export type ProviderParams = { cluster: string; wallet: string; diff --git a/tools/payment/createPaymentInfo.ts b/tools/payment/createPaymentInfo.ts index f1e5e7a1..b2daaed0 100644 --- a/tools/payment/createPaymentInfo.ts +++ b/tools/payment/createPaymentInfo.ts @@ -1,4 +1,5 @@ -import type { BN, Wallet } from "@project-serum/anchor"; +import type { Wallet } from "@project-serum/anchor"; +import { BN } from "@project-serum/anchor"; import type { Connection } from "@solana/web3.js"; import { PublicKey, Transaction } from "@solana/web3.js"; @@ -8,18 +9,14 @@ import { executeTransaction } from "../utils"; export const commandName = "createPaymentInfo"; export const description = "Create a payment info object"; export const getArgs = (_connection: Connection, wallet: Wallet) => ({ - identifier: "unstake-y00ts", + identifier: "cardinal-default", authority: wallet.publicKey, - paymentAmount: 3 * 10 ** 9, - paymentMint: new PublicKey("DUSTawucrTsGU8hcqRdHDCbuYhCPADMLM2VcCb8VnFnQ"), + paymentAmount: 5 * 10 ** 7, + paymentMint: PublicKey.default, paymentShares: [ { address: new PublicKey("cteamyte8zjZTeexp3qTzvpb24TKRSL3HFad9SzNaNJ"), - basisPoints: 5000, - }, - { - address: new PublicKey("yootn8Kf22CQczC732psp7qEqxwPGSDQCFZHkzoXp25"), - basisPoints: 5000, + basisPoints: 10000, }, ], }); @@ -27,9 +24,9 @@ export const getArgs = (_connection: Connection, wallet: Wallet) => ({ export type InitPaymentInfoIx = { authority: PublicKey; identifier: string; - paymentAmount: BN; + paymentAmount: number; paymentMint: PublicKey; - paymentShares: PublicKey[]; + paymentShares: { address: PublicKey; basisPoints: number }[]; }; export const handler = async ( @@ -43,7 +40,13 @@ export const handler = async ( transaction.add( await program.methods - .initPaymentInfo(args) + .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() ); diff --git a/tools/payment/updatePaymentInfo.ts b/tools/payment/updatePaymentInfo.ts index b3b0b89d..46bcf756 100644 --- a/tools/payment/updatePaymentInfo.ts +++ b/tools/payment/updatePaymentInfo.ts @@ -1,12 +1,9 @@ import type { Wallet } from "@project-serum/anchor"; +import { BN } from "@project-serum/anchor"; import type { Connection } from "@solana/web3.js"; import { PublicKey, Transaction } from "@solana/web3.js"; -import type { UpdatePaymentInfoIx } from "../../sdk"; -import { - createUpdatePaymentInfoInstruction, - findPaymentInfoId, -} from "../../sdk"; +import { findPaymentInfoId, rewardsCenterProgram } from "../../sdk"; import { executeTransaction } from "../utils"; export const commandName = "updatePaymentInfo"; @@ -17,6 +14,13 @@ export type Args = { ix: UpdatePaymentInfoIx; }; +export type UpdatePaymentInfoIx = { + authority: PublicKey; + paymentAmount: number; + paymentMint: PublicKey; + paymentShares: { address: PublicKey; basisPoints: number }[]; +}; + export const getArgs = (_connection: Connection, wallet: Wallet) => ({ identifier: "unstake-y00ts", ix: { @@ -43,15 +47,22 @@ export const handler = async ( ) => { const transaction = new Transaction(); const paymentInfoId = findPaymentInfoId(args.identifier); + const program = rewardsCenterProgram(connection, wallet); + transaction.add( - createUpdatePaymentInfoInstruction( - { + await program.methods + .updatePaymentInfo({ + authority: args.ix.authority, + paymentAmount: new BN(args.ix.paymentAmount), + paymentMint: args.ix.paymentMint, + paymentShares: args.ix.paymentShares, + }) + .accounts({ paymentInfo: paymentInfoId, authority: wallet.publicKey, payer: wallet.publicKey, - }, - { ix: args.ix } - ) + }) + .instruction() ); await executeTransaction(connection, transaction, wallet); console.log(