Skip to content

Commit

Permalink
Lint Distributor after rebase (#142)
Browse files Browse the repository at this point in the history
- run lint after rebase
- use prepareTransaction to create transactions
  • Loading branch information
Yolley authored Mar 13, 2024
1 parent 0be6147 commit 4f5eed3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 47 deletions.
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.2",
"version": "6.0.0-alpha.3",
"$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.2",
"version": "6.0.0-alpha.3",
"description": "Common utilities and types used by streamflow packages.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
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.2",
"version": "6.0.0-alpha.3",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
39 changes: 14 additions & 25 deletions packages/distributor/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import {
PublicKey,
SystemProgram,
TransactionInstruction,
Transaction,
Commitment,
ConnectionConfig,
} from "@solana/web3.js";
import { ICluster, ITransactionResult } from "@streamflow/common";
import { ata, checkOrCreateAtaBatch, prepareWrappedAccount, prepareBaseInstructions } from "@streamflow/common/solana";
import {
ata,
checkOrCreateAtaBatch,
prepareWrappedAccount,
prepareBaseInstructions,
prepareTransaction,
} from "@streamflow/common/solana";

import { DISTRIBUTOR_PROGRAM_ID } from "./constants";
import {
Expand Down Expand Up @@ -67,6 +72,10 @@ export default class SolanaDistributorClient {
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(DISTRIBUTOR_PROGRAM_ID[cluster]);
}

public getCommitment(): Commitment | undefined {
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
}

public async create(
data: ICreateDistributorData,
{ invoker, isNative = false, computePrice, computeLimit }: ICreateSolanaExt,
Expand Down Expand Up @@ -120,15 +129,7 @@ export default class SolanaDistributorClient {
),
);

const commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;

const hash = await this.connection.getLatestBlockhash(commitment);
const tx = new Transaction({
feePayer: invoker.publicKey,
blockhash: hash.blockhash,
lastValidBlockHeight: hash.lastValidBlockHeight,
}).add(...ixs);

const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment());
const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash);

return {
Expand Down Expand Up @@ -181,13 +182,7 @@ export default class SolanaDistributorClient {
ixs.push(newClaim(args, accounts, this.programId));
}

const commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
const hash = await this.connection.getLatestBlockhash(commitment);
const tx = new Transaction({
feePayer: invoker.publicKey,
blockhash: hash.blockhash,
lastValidBlockHeight: hash.lastValidBlockHeight,
}).add(...ixs);
const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment());
const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash);

return { ixs, txId: signature };
Expand Down Expand Up @@ -222,13 +217,7 @@ export default class SolanaDistributorClient {

ixs.push(clawback(accounts, this.programId));

const commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
const hash = await this.connection.getLatestBlockhash(commitment);
const tx = new Transaction({
feePayer: invoker.publicKey,
blockhash: hash.blockhash,
lastValidBlockHeight: hash.lastValidBlockHeight,
}).add(...ixs);
const { tx, hash } = await prepareTransaction(this.connection, ixs, invoker.publicKey, this.getCommitment());
const signature = await wrappedSignAndExecuteTransaction(this.connection, invoker, tx, hash);

return { ixs, txId: signature };
Expand Down
3 changes: 1 addition & 2 deletions packages/distributor/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export async function wrappedSignAndExecuteTransaction(
hash: BlockhashWithExpiryBlockHeight,
): Promise<string> {
try {
const signature = await signAndExecuteTransaction(connection, invoker, tx, hash);
return signature;
return await signAndExecuteTransaction(connection, invoker, tx, hash);
} catch (err: any) {
if (err instanceof Error) {
const parsed = fromTxError(err);
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.2",
"version": "6.0.0-alpha.3",
"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.2",
"version": "6.0.0-alpha.3",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
27 changes: 12 additions & 15 deletions packages/stream/solana/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
*/
public async createMultiple(
data: ICreateMultipleStreamData,
{
sender,
metadataPubKeys,
isNative = false,
computePrice,
computeLimit,
}: ICreateStreamSolanaExt,
{ sender, metadataPubKeys, isNative = false, computePrice, computeLimit }: ICreateStreamSolanaExt,
): Promise<IMultiTransactionResult> {
const { recipients } = data;

Expand All @@ -420,8 +414,9 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { ixs, metadata, metadataPubKey } = await this.prepareStreamInstructions(recipientData, data, {
sender,
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
computePrice,
computeLimit,});
computePrice,
computeLimit,
});

metadataToRecipient[metadataPubKey.toBase58()] = recipientData;

Expand Down Expand Up @@ -452,14 +447,14 @@ export default class SolanaStreamClient extends BaseStreamClient {
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);

const prepareTransaction = new Transaction({
const tx = new Transaction({
feePayer: sender.publicKey,
blockhash: hash.blockhash,
lastValidBlockHeight: hash.lastValidBlockHeight,
}).add(...nativeInstructions);

batch.push({
tx: prepareTransaction,
tx,
recipient: sender.publicKey.toBase58(),
});
}
Expand Down Expand Up @@ -512,11 +507,13 @@ export default class SolanaStreamClient extends BaseStreamClient {
{ id, amount = WITHDRAW_AVAILABLE_AMOUNT }: IWithdrawData,
extParams: IInteractStreamSolanaExt,
): Promise<ITransactionResult> {
const ixs: TransactionInstruction[] = await this.prepareWithdrawInstructions(
{ id, amount },
extParams
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, this.getCommitment());
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

return { ixs, txId: signature };
Expand Down

0 comments on commit 4f5eed3

Please sign in to comment.