Skip to content

Commit

Permalink
STREAM-1568: expose prepare methods in distributor (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolley committed May 14, 2024
1 parent df331dd commit 9b68da5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 26 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.3.5",
"version": "6.3.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.3.5",
"version": "6.3.6",
"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.3.5",
"version": "6.3.6",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
66 changes: 45 additions & 21 deletions packages/distributor/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ export default class SolanaDistributorClient {
}

public async create(data: ICreateDistributorData, extParams: ICreateSolanaExt): Promise<ICreateDistributorResult> {
const { ixs, distributorPublicKey } = await this.prepareCreateInstructions(data, extParams);
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
const signature = await wrappedSignAndExecuteTransaction(
this.connection,
extParams.invoker,
tx,
{
hash,
context,
commitment: this.getCommitment(),
},
{ sendThrottler: this.sendThrottler },
);

return {
ixs,
txId: signature,
metadataId: distributorPublicKey.toBase58(),
};
}

public async prepareCreateInstructions(
data: ICreateDistributorData,
extParams: ICreateSolanaExt,
): Promise<{ distributorPublicKey: PublicKey; ixs: TransactionInstruction[] }> {
if (!extParams.invoker.publicKey) {
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
}
Expand Down Expand Up @@ -149,6 +174,11 @@ export default class SolanaDistributorClient {
),
);

return { distributorPublicKey, ixs };
}

public async claim(data: IClaimData, extParams: IInteractSolanaExt): Promise<ITransactionResult> {
const ixs = await this.prepareClaimInstructions(data, extParams);
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
const signature = await wrappedSignAndExecuteTransaction(
this.connection,
Expand All @@ -162,14 +192,13 @@ export default class SolanaDistributorClient {
{ sendThrottler: this.sendThrottler },
);

return {
ixs,
txId: signature,
metadataId: distributorPublicKey.toBase58(),
};
return { ixs, txId: signature };
}

public async claim(data: IClaimData, extParams: IInteractSolanaExt): Promise<ITransactionResult> {
public async prepareClaimInstructions(
data: IClaimData,
extParams: IInteractSolanaExt,
): Promise<TransactionInstruction[]> {
if (!extParams.invoker.publicKey) {
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
}
Expand Down Expand Up @@ -228,6 +257,11 @@ export default class SolanaDistributorClient {
ixs.push(claimLocked(accounts, this.programId));
}

return ixs;
}

public async clawback(data: IClawbackData, extParams: IInteractSolanaExt): Promise<ITransactionResult> {
const ixs = await this.prepareClawbackInstructions(data, extParams);
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
const signature = await wrappedSignAndExecuteTransaction(
this.connection,
Expand All @@ -244,7 +278,10 @@ export default class SolanaDistributorClient {
return { ixs, txId: signature };
}

public async clawback(data: IClawbackData, extParams: IInteractSolanaExt): Promise<ITransactionResult> {
public async prepareClawbackInstructions(
data: IClawbackData,
extParams: IInteractSolanaExt,
): Promise<TransactionInstruction[]> {
if (!extParams.invoker.publicKey) {
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
}
Expand Down Expand Up @@ -279,20 +316,7 @@ export default class SolanaDistributorClient {

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

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

return { ixs, txId: signature };
return ixs;
}

public async getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]> {
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.3.5",
"version": "6.3.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.3.5",
"version": "6.3.6",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down

0 comments on commit 9b68da5

Please sign in to comment.