From d9ef795b1f3e07d10ec1a1c1240a70867ccf2bbb Mon Sep 17 00:00:00 2001 From: Yolley Date: Wed, 20 Mar 2024 17:39:57 +0900 Subject: [PATCH 1/3] support different distributors in getClaims --- packages/distributor/solana/client.ts | 9 ++++----- packages/distributor/solana/types.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/distributor/solana/client.ts b/packages/distributor/solana/client.ts index fde6b6ac..6d9b120b 100644 --- a/packages/distributor/solana/client.ts +++ b/packages/distributor/solana/client.ts @@ -29,7 +29,7 @@ import { IClawbackData, ICreateDistributorData, ICreateDistributorResult, - IGetClaimsData, + IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt, @@ -223,10 +223,9 @@ export default class SolanaDistributorClient { return { ixs, txId: signature }; } - public async getClaims(data: IGetClaimsData): Promise<(ClaimStatus | null)[]> { - const distributorPublicKey = new PublicKey(data.id); - const claimStatusPublicKeys = data.recipients.map((recipient) => { - return getClaimantStatusPda(this.programId, distributorPublicKey, new PublicKey(recipient)); + public async getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]> { + const claimStatusPublicKeys = data.map(({ id, recipient }) => { + return getClaimantStatusPda(this.programId, new PublicKey(id), new PublicKey(recipient)); }); return ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId); } diff --git a/packages/distributor/solana/types.ts b/packages/distributor/solana/types.ts index fbc20770..0a7d08f6 100644 --- a/packages/distributor/solana/types.ts +++ b/packages/distributor/solana/types.ts @@ -38,10 +38,10 @@ export interface IClawbackData { id: string; } -export interface IGetClaimsData { +export interface IGetClaimData { id: string; - recipients: string[]; + recipient: string; } export interface IGetDistributors { From 9ab57c431f34c13412cb5b5bc9aa4ab65ca5515c Mon Sep 17 00:00:00 2001 From: Yolley Date: Wed, 20 Mar 2024 17:41:33 +0900 Subject: [PATCH 2/3] bump --- lerna.json | 2 +- packages/common/package.json | 2 +- packages/distributor/package.json | 2 +- packages/eslint-config/package.json | 2 +- packages/stream/package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lerna.json b/lerna.json index ff85458b..c9177ade 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,6 @@ "packages": [ "packages/*" ], - "version": "6.0.0-alpha.5", + "version": "6.0.0-alpha.6", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/common/package.json b/packages/common/package.json index 42834948..af78c117 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/common", - "version": "6.0.0-alpha.5", + "version": "6.0.0-alpha.6", "description": "Common utilities and types used by streamflow packages.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/index.js", diff --git a/packages/distributor/package.json b/packages/distributor/package.json index f8172aa9..4badb36d 100644 --- a/packages/distributor/package.json +++ b/packages/distributor/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/distributor", - "version": "6.0.0-alpha.5", + "version": "6.0.0-alpha.6", "description": "JavaScript SDK to interact with Streamflow Airdrop protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/index.js", diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 4007d66d..b01fa424 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/eslint-config", - "version": "6.0.0-alpha.5", + "version": "6.0.0-alpha.6", "license": "ISC", "main": "index.js", "files": [ diff --git a/packages/stream/package.json b/packages/stream/package.json index a4b9c7d3..1ad1ee22 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/stream", - "version": "6.0.0-alpha.5", + "version": "6.0.0-alpha.6", "description": "JavaScript SDK to interact with Streamflow protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/index.js", From dcd3dca17e1544fc7c424f02fc770756fd364871 Mon Sep 17 00:00:00 2001 From: Yolley Date: Tue, 26 Mar 2024 12:18:53 +0900 Subject: [PATCH 3/3] STREAM-1403: optimize tx confirmation --- packages/common/solana/utils.ts | 8 ++++- packages/distributor/solana/client.ts | 6 ++-- packages/stream/solana/StreamClient.ts | 42 +++++--------------------- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/packages/common/solana/utils.ts b/packages/common/solana/utils.ts index d64684b4..f60fdf3c 100644 --- a/packages/common/solana/utils.ts +++ b/packages/common/solana/utils.ts @@ -65,7 +65,13 @@ export function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): } /** - * Creates a Transaction with given instructions and optionally signs it + * Creates a Transaction with given instructions and optionally signs it. + * Be careful when passing `commitment` as for `confirmed` blockhash it always returns blockheight + 300 in `lastValidBlockHeight` + * And if you use this blockheight to confirm the transaction it could happen so that transaction is successfully executed + * But because `confirmTransaction` waits for only a minute it considers tx as expired as it could be that 300 blocks won't pass in a minute + * https://solana.stackexchange.com/questions/6238/why-is-lastvalidblockheight-300-blocks-ahead-than-current-blockheight-if-hashes + * https://solana.com/docs/core/transactions/retry + * It might be better to rely on `commitment` level that you pass to `Connection` instance of Solana client as it will be used when fetching blockheight on transaction confirmation * @param connection - Solana client connection * @param ixs - Instructions to add to the Transaction * @param payer - PublicKey of payer diff --git a/packages/distributor/solana/client.ts b/packages/distributor/solana/client.ts index 6d9b120b..60e6cf68 100644 --- a/packages/distributor/solana/client.ts +++ b/packages/distributor/solana/client.ts @@ -129,7 +129,7 @@ export default class SolanaDistributorClient { ), ); - const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment()); + const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey); const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash); return { @@ -182,7 +182,7 @@ export default class SolanaDistributorClient { ixs.push(claimLocked(accounts, this.programId)); - const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment()); + const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey); const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash); return { ixs, txId: signature }; @@ -217,7 +217,7 @@ export default class SolanaDistributorClient { ixs.push(clawback(accounts, this.programId)); - const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment()); + const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey); const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash); return { ixs, txId: signature }; diff --git a/packages/stream/solana/StreamClient.ts b/packages/stream/solana/StreamClient.ts index bb5b2a62..f3fe804e 100644 --- a/packages/stream/solana/StreamClient.ts +++ b/packages/stream/solana/StreamClient.ts @@ -139,7 +139,7 @@ export default class SolanaStreamClient extends BaseStreamClient { this.connection, ixs, extParams.sender.publicKey, - this.getCommitment(), + undefined, metadata, ); const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, hash); @@ -271,7 +271,7 @@ export default class SolanaStreamClient extends BaseStreamClient { this.connection, ixs, extParams.sender.publicKey, - this.getCommitment(), + undefined, metadata, ); const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, hash); @@ -428,8 +428,7 @@ export default class SolanaStreamClient extends BaseStreamClient { }); } - const commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment; - const hash = await this.connection.getLatestBlockhash(commitment); + const hash = await this.connection.getLatestBlockhash(); for (const { ixs, metadata, recipient } of instructionsBatch) { const tx = new Transaction({ @@ -508,12 +507,7 @@ export default class SolanaStreamClient extends BaseStreamClient { extParams: IInteractStreamSolanaExt, ): Promise { const ixs: TransactionInstruction[] = await this.prepareWithdrawInstructions({ id, amount }, extParams); - const { tx, hash } = await prepareTransaction( - this.connection, - ixs, - extParams.invoker.publicKey, - this.getCommitment(), - ); + const { tx, hash } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey); const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash); return { ixs, txId: signature }; @@ -570,12 +564,7 @@ export default class SolanaStreamClient extends BaseStreamClient { */ public async cancel({ id }: ICancelData, extParams: IInteractStreamSolanaExt): Promise { const ixs = await this.prepareCancelInstructions({ id }, extParams); - const { tx, hash } = await prepareTransaction( - this.connection, - ixs, - extParams.invoker.publicKey, - this.getCommitment(), - ); + const { tx, hash } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey); const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash); return { ixs, txId: signature }; @@ -639,12 +628,7 @@ export default class SolanaStreamClient extends BaseStreamClient { extParams: IInteractStreamSolanaExt, ): Promise { const ixs: TransactionInstruction[] = await this.prepareTransferInstructions({ id, newRecipient }, extParams); - const { tx, hash } = await prepareTransaction( - this.connection, - ixs, - extParams.invoker.publicKey, - this.getCommitment(), - ); + const { tx, hash } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey); const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash); return { ixs, txId: signature }; @@ -698,12 +682,7 @@ export default class SolanaStreamClient extends BaseStreamClient { */ public async topup({ id, amount }: ITopUpData, extParams: ITopUpStreamSolanaExt): Promise { const ixs: TransactionInstruction[] = await this.prepareTopupInstructions({ id, amount }, extParams); - const { tx, hash } = await prepareTransaction( - this.connection, - ixs, - extParams.invoker.publicKey, - this.getCommitment(), - ); + const { tx, hash } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey); const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash); return { ixs, txId: signature }; @@ -820,12 +799,7 @@ export default class SolanaStreamClient extends BaseStreamClient { */ public async update(data: IUpdateData, extParams: IInteractStreamSolanaExt): Promise { const ixs = await this.prepareUpdateInstructions(data, extParams); - const { tx, hash } = await prepareTransaction( - this.connection, - ixs, - extParams.invoker.publicKey, - this.getCommitment(), - ); + const { tx, hash } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey); const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash); return {