Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for claim limit for distributor #253

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/common/solana/public-key.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { PublicKey } from "@solana/web3.js";

/**
* Converts a string or PublicKey to a PublicKey object.
* @param key - The input key as a string or PublicKey.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the param name is address. 🌚

* @returns The PublicKey object.
*/
export const pk = (address: string | PublicKey): PublicKey => {
return typeof address === "string" ? new PublicKey(address) : address;
};
5 changes: 3 additions & 2 deletions packages/distributor/solana/clients/BaseDistributorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
buildSendThrottler,
prepareWrappedAccount,
IProgramAccount,
pk,
} from "@streamflow/common/solana";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
Expand Down Expand Up @@ -325,7 +326,7 @@ export default abstract class BaseDistributorClient {
const distributorPublicKey = new PublicKey(data.id);
const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);

const claimantPublicKey = new PublicKey(data.claimant);
const claimantPublicKey = pk(data.claimant);

if (!distributor) {
throw new Error("Couldn't get distributor account info");
Expand Down Expand Up @@ -469,7 +470,7 @@ export default abstract class BaseDistributorClient {
clawbackStartTs: new BN(data.clawbackStartTs),
claimsClosableByAdmin: data.claimsClosableByAdmin,
claimsClosableByClaimant: data.claimsClosableByClaimant,
claimsLimit: new BN(data.claimsLimit || 0),
claimsLimit: data.claimsLimit,
};

const nowTs = new BN(Math.floor(Date.now() / 1000));
Expand Down
10 changes: 5 additions & 5 deletions packages/distributor/solana/generated/accounts/ClaimStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ClaimStatusFields {
/** Distributor account for which ClaimStatus was created, useful to filter by in get_program_accounts */
distributor: PublicKey;
/** Number of time amount has been claimed */
claimsCount: BN;
claimsCount: number;
/** Time when claim was closed */
closedTs: BN;
/** Buffer for additional fields */
Expand All @@ -47,7 +47,7 @@ export interface ClaimStatusJSON {
/** Distributor account for which ClaimStatus was created, useful to filter by in get_program_accounts */
distributor: string;
/** Number of time amount has been claimed */
claimsCount: string;
claimsCount: number;
/** Time when claim was closed */
closedTs: string;
/** Buffer for additional fields */
Expand Down Expand Up @@ -81,7 +81,7 @@ export class ClaimStatus {
readonly distributor: PublicKey;

/** Number of time amount has been claimed */
readonly claimsCount: BN;
readonly claimsCount: number;

/** Time when claim was closed */
readonly closedTs: BN;
Expand Down Expand Up @@ -187,7 +187,7 @@ export class ClaimStatus {
lastAmountPerUnlock: this.lastAmountPerUnlock.toString(),
closed: this.closed,
distributor: this.distributor.toString(),
claimsCount: this.claimsCount.toString(),
claimsCount: this.claimsCount,
closedTs: this.closedTs.toString(),
buffer2: this.buffer2,
};
Expand All @@ -203,7 +203,7 @@ export class ClaimStatus {
lastAmountPerUnlock: new BN(obj.lastAmountPerUnlock),
closed: obj.closed,
distributor: new PublicKey(obj.distributor),
claimsCount: new BN(obj.claimsCount),
claimsCount: obj.claimsCount,
closedTs: new BN(obj.closedTs),
buffer2: obj.buffer2,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface MerkleDistributorFields {
/** Whether claims are closable by the claimant or not */
claimsClosableByClaimant: boolean;
/** Limit number of claims */
claimsLimit: BN;
claimsLimit: number;
/** Buffer for additional fields */
buffer2: Array<number>;
/** Buffer for additional fields */
Expand Down Expand Up @@ -111,7 +111,7 @@ export interface MerkleDistributorJSON {
/** Whether claims are closable by the claimant or not */
claimsClosableByClaimant: boolean;
/** Limit number of claims */
claimsLimit: string;
claimsLimit: number;
/** Buffer for additional fields */
buffer2: Array<number>;
/** Buffer for additional fields */
Expand Down Expand Up @@ -193,7 +193,7 @@ export class MerkleDistributor {
readonly claimsClosableByClaimant: boolean;

/** Limit number of claims */
readonly claimsLimit: BN;
readonly claimsLimit: number;

/** Buffer for additional fields */
readonly buffer2: Array<number>;
Expand Down Expand Up @@ -363,7 +363,7 @@ export class MerkleDistributor {
totalClaimablePreUpdate: this.totalClaimablePreUpdate.toString(),
clawedBackTs: this.clawedBackTs.toString(),
claimsClosableByClaimant: this.claimsClosableByClaimant,
claimsLimit: this.claimsLimit.toString(),
claimsLimit: this.claimsLimit,
buffer2: this.buffer2,
buffer3: this.buffer3,
};
Expand Down Expand Up @@ -395,7 +395,7 @@ export class MerkleDistributor {
totalClaimablePreUpdate: new BN(obj.totalClaimablePreUpdate),
clawedBackTs: new BN(obj.clawedBackTs),
claimsClosableByClaimant: obj.claimsClosableByClaimant,
claimsLimit: new BN(obj.claimsLimit),
claimsLimit: obj.claimsLimit,
buffer2: obj.buffer2,
buffer3: obj.buffer3,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/distributor/solana/generated/instructions/closeClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Buffer } from "buffer";
import { PROGRAM_ID } from "../programId";

export interface CloseClaimArgs {
amountUnlocked: BN;
amountLocked: BN;
proof: Array<Array<number>>;
amountUnlocked?: BN;
amountLocked?: BN;
proof?: Array<Array<number>>;
}
export interface CloseClaimAccounts {
/** The [MerkleDistributor]. */
Expand All @@ -25,9 +25,9 @@ export interface CloseClaimAccounts {
}

export const layout = borsh.struct([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these values are optional - it's really important to mark it in the borsh struct as optional field has an additional byte at the start of the value which signals whether the value is presented or not.

borsh.u64("amountUnlocked"),
borsh.u64("amountLocked"),
borsh.vec(borsh.array(borsh.u8(), 32), "proof"),
borsh.option(borsh.u64(), "amountUnlocked"),
borsh.option(borsh.u64(), "amountLocked"),
borsh.option(borsh.vec(borsh.array(borsh.u8(), 32)), "proof"),
]);

export function closeClaim(args: CloseClaimArgs, accounts: CloseClaimAccounts, programId: PublicKey = PROGRAM_ID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface NewDistributorArgs {
endVestingTs: BN;
clawbackStartTs: BN;
claimsClosableByAdmin: boolean;
claimsClosableByClaimant: boolean;
claimsLimit: BN;
claimsClosableByClaimant?: boolean;
claimsLimit?: number;
}

export interface NewDistributorAccounts {
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ICreateDistributorData {
endVestingTs: number;
clawbackStartTs: number;
claimsClosableByAdmin: boolean;
claimsClosableByClaimant: boolean;
claimsClosableByClaimant?: boolean;
claimsLimit?: number;
}

Expand Down