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

Conversation

tatomir-streamflow
Copy link
Contributor

Exposes the claimsLimit argument for distributor creation as well as the closeClaim method.

Protocol PR

public async closeClaim(data: ICloseClaimData, extParams: IInteractSolanaExt): Promise<ITransactionResult> {
const ixs = await this.prepareCloseClaimInstructions(data, extParams);
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
const signature = await wrappedSignAndExecuteTransaction(
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: I think it makes sense to get rid of these long wrappedSignAndExecuteTransactions calls and provide a private method to make it cleaner like so https://github.com/streamflow-finance/js-sdk/blob/master/packages/launchpad/solana/client.ts#L427

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't see how this would make it cleaner - I would just be adding more code by adding this already existing util function as a private method in this class, is it a better approach - idk

const distributorPublicKey = new PublicKey(data.id);
const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);

const claimantPublicKey = new PublicKey(data.claimant);
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: We now have a neat pk method that can receive either publickey or string and alsways returns PublicKey https://github.com/streamflow-finance/js-sdk/blob/master/packages/common/solana/public-key.ts#L3

program: this.programId,
};

const closeClaimArgs: CloseClaimArgs = {
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 parameters are optional so may be it would also make sense to make them optional here (admin should be able to close claim without them, also a potential user might close their claim after calling newClaim - while it's out of the scope for the task we're doing it for, I think would be neat to have it supported from the start).

claimsClosable: data.claimsClosable,
claimsClosableByAdmin: data.claimsClosableByAdmin,
claimsClosableByClaimant: data.claimsClosableByClaimant,
claimsLimit: new BN(data.claimsLimit || 0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

claimsLimit is u16, so no need to convert it to BN actually, we use BN for u64 as its value is larger what ecma number supports.

@@ -42,6 +46,10 @@ export interface ClaimStatusJSON {
closed: boolean;
/** 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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It will be returned as number I believe as it's u16.

@@ -181,6 +203,8 @@ export class ClaimStatus {
lastAmountPerUnlock: new BN(obj.lastAmountPerUnlock),
closed: obj.closed,
distributor: new PublicKey(obj.distributor),
claimsCount: new BN(obj.claimsCount),
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to convert to BN imo.

/** Whether claims are closable by the claimant or not */
claimsClosableByClaimant: boolean;
/** Limit number of claims */
claimsLimit: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the same thing with number

canUpdateDuration: obj.canUpdateDuration,
totalAmountUnlocked: new BN(obj.totalAmountUnlocked),
totalAmountLocked: new BN(obj.totalAmountLocked),
lastDurationUpdateTs: new BN(obj.lastDurationUpdateTs),
totalClaimablePreUpdate: new BN(obj.totalClaimablePreUpdate),
clawedBackTs: new BN(obj.clawedBackTs),
claimsClosableByClaimant: obj.claimsClosableByClaimant,
claimsLimit: new BN(obj.claimsLimit),
Copy link
Collaborator

Choose a reason for hiding this comment

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

extra bn conversion not needed imo

@@ -19,18 +24,33 @@ export interface CloseClaimAccounts {
program: PublicKey;
}

export function closeClaim(accounts: CloseClaimAccounts, programId: PublicKey = PROGRAM_ID) {
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.

claimsClosable: boolean;
claimsClosableByAdmin: boolean;
claimsClosableByClaimant: boolean;
claimsLimit: BN;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It can be represented as number.

@@ -1,6 +1,6 @@
{
"name": "@streamflow/common",
"version": "7.3.3",
"version": "8.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

why major? these changes are backward compatible if I understand correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well we did change some exposed interfaces (claimsClosable renamed to claimsClosableByAdmin in MerkleDistributor and ICreateDistributorData for example) so it is breaking... however maybe this does not warrant such a change, I can keep the exposed interface the same for SDK to keep it backwards compatible and have this be a minor change now that I reconsider it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Yolley tagging you since you also asked me about this
Blog by Tom, the creator of SemVer - TL;DR ANY breaking change (and this is one) should merit a major version bump - we are not going to run out of numbers any time soon

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tatomir-streamflow I agree with Roman as these methods are also not used at all by any client, so I think that having another major version bump for them is too much.

@@ -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. 🌚

@tatomir-streamflow tatomir-streamflow merged commit 4bc3748 into master Jan 28, 2025
2 checks passed
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants