Skip to content

Commit

Permalink
Add default payment info
Browse files Browse the repository at this point in the history
  • Loading branch information
Giannis Chatziveroglou committed Dec 7, 2022
1 parent 505aa9e commit 80425db
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
17 changes: 1 addition & 16 deletions programs/cardinal-rewards-center/src/payment/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 3 additions & 6 deletions tools/cli.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand Down
27 changes: 15 additions & 12 deletions tools/payment/createPaymentInfo.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -8,28 +9,24 @@ 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,
},
],
});

export type InitPaymentInfoIx = {
authority: PublicKey;
identifier: string;
paymentAmount: BN;
paymentAmount: number;
paymentMint: PublicKey;
paymentShares: PublicKey[];
paymentShares: { address: PublicKey; basisPoints: number }[];
};

export const handler = async (
Expand All @@ -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()
);
Expand Down
31 changes: 21 additions & 10 deletions tools/payment/updatePaymentInfo.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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: {
Expand All @@ -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(
Expand Down

0 comments on commit 80425db

Please sign in to comment.