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

Oleg/feature/optimise tx confirmation #147

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 7 additions & 1 deletion packages/common/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 7 additions & 8 deletions packages/distributor/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
IClawbackData,
ICreateDistributorData,
ICreateDistributorResult,
IGetClaimsData,
IGetClaimData,
IGetDistributors,
ICreateSolanaExt,
IInteractSolanaExt,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -217,16 +217,15 @@ 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 };
}

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);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/distributor/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export interface IClawbackData {
id: string;
}

export interface IGetClaimsData {
export interface IGetClaimData {
id: string;

recipients: string[];
recipient: string;
}

export interface IGetDistributors {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
42 changes: 8 additions & 34 deletions packages/stream/solana/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -508,12 +507,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
extParams: IInteractStreamSolanaExt,
): Promise<ITransactionResult> {
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 };
Expand Down Expand Up @@ -570,12 +564,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
*/
public async cancel({ id }: ICancelData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult> {
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 };
Expand Down Expand Up @@ -639,12 +628,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
extParams: IInteractStreamSolanaExt,
): Promise<ITransactionResult> {
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 };
Expand Down Expand Up @@ -698,12 +682,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
*/
public async topup({ id, amount }: ITopUpData, extParams: ITopUpStreamSolanaExt): Promise<ITransactionResult> {
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 };
Expand Down Expand Up @@ -820,12 +799,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
*/
public async update(data: IUpdateData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult> {
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 {
Expand Down
Loading