Skip to content

Commit

Permalink
STREAM-1465: update distributor client, support event authority (#164)
Browse files Browse the repository at this point in the history
* STREAM-1465: update distributor client, support even authority

* bump

* v6.3.0

---------

Co-authored-by: roman.rolgin <irolgin@gmail.com>
  • Loading branch information
Yolley and RolginRoman committed Apr 17, 2024
1 parent bd8cb2d commit 3e9b32a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 6 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.2.1",
"version": "6.3.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"pack": "lerna run pack",
"test": "lerna run test",
"lint": "lerna run lint",
"version-all": "lerna version --force-publish",
"publish": "lerna publish from-package --yes",
"local-publish": "lerna publish --no-git-tag-version --no-push --registry=\"http://localhost:4873/\" from-package --yes",
"local-unpublish": "lerna exec -- npm unpublish --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}@\\$(npm view \\$LERNA_PACKAGE_NAME version)\"",
Expand Down
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.2.1",
"version": "6.3.0",
"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.2.1",
"version": "6.3.0",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
10 changes: 9 additions & 1 deletion packages/distributor/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ import {
newDistributor,
} from "./generated/instructions";
import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
import { getClaimantStatusPda, getDistributorPda, wrappedSignAndExecuteTransaction } from "./utils";
import {
getClaimantStatusPda,
getDistributorPda,
getEventAuthorityPda,
wrappedSignAndExecuteTransaction,
} from "./utils";

interface IInitOptions {
clusterUrl: string;
Expand Down Expand Up @@ -169,6 +174,7 @@ export default class SolanaDistributorClient {
);
const invokerTokens = await ata(distributor.mint, invoker.publicKey, tokenProgramId);
const claimStatusPublicKey = getClaimantStatusPda(this.programId, distributorPublicKey, invoker.publicKey);
const eventAuthorityPublicKey = getEventAuthorityPda(this.programId);
const claimStatus = await ClaimStatus.fetch(this.connection, claimStatusPublicKey);

const accounts: ClaimLockedAccounts | NewClaimAccounts = {
Expand All @@ -180,6 +186,8 @@ export default class SolanaDistributorClient {
mint: distributor.mint,
tokenProgram: tokenProgramId,
systemProgram: SystemProgram.programId,
eventAuthority: eventAuthorityPublicKey,
program: this.programId,
};

if (!claimStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface ClaimLockedAccounts {
mint: PublicKey;
/** SPL [Token] program. */
tokenProgram: PublicKey;
eventAuthority: PublicKey;
program: PublicKey;
}

export function claimLocked(accounts: ClaimLockedAccounts, programId: PublicKey = PROGRAM_ID) {
Expand All @@ -33,6 +35,8 @@ export function claimLocked(accounts: ClaimLockedAccounts, programId: PublicKey
{ pubkey: accounts.claimant, isSigner: true, isWritable: true },
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
{ pubkey: accounts.program, isSigner: false, isWritable: false },
];
const identifier = Buffer.from([34, 206, 181, 23, 11, 207, 147, 90]);
const data = identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface CloseClaimAccounts {
claimStatus: PublicKey;
/** The [System] program. */
systemProgram: PublicKey;
eventAuthority: PublicKey;
program: PublicKey;
}

export function closeClaim(accounts: CloseClaimAccounts, programId: PublicKey = PROGRAM_ID) {
Expand All @@ -23,6 +25,8 @@ export function closeClaim(accounts: CloseClaimAccounts, programId: PublicKey =
{ pubkey: accounts.claimant, isSigner: false, isWritable: false },
{ pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
{ pubkey: accounts.program, isSigner: false, isWritable: false },
];
const identifier = Buffer.from([42, 177, 165, 35, 213, 179, 211, 19]);
const data = identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface NewClaimAccounts {
tokenProgram: PublicKey;
/** The [System] program. */
systemProgram: PublicKey;
eventAuthority: PublicKey;
program: PublicKey;
}

export const layout = borsh.struct([
Expand All @@ -45,6 +47,8 @@ export function newClaim(args: NewClaimArgs, accounts: NewClaimAccounts, program
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
{ pubkey: accounts.program, isSigner: false, isWritable: false },
];
const identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
const buffer = Buffer.alloc(1000);
Expand Down
8 changes: 8 additions & 0 deletions packages/distributor/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export function getClaimantStatusPda(programId: PublicKey, distributor: PublicKe
return PublicKey.findProgramAddressSync(seeds, programId)[0];
}

export function getEventAuthorityPda(programId: PublicKey): PublicKey {
// Constructing the seed for the PDA
const seeds = [Buffer.from("__event_authority")];

// Finding the PDA
return PublicKey.findProgramAddressSync(seeds, programId)[0];
}

export async function wrappedSignAndExecuteTransaction(
connection: Connection,
invoker: Keypair | SignerWalletAdapter,
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",
"version": "6.3.0",
"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.2.1",
"version": "6.3.0",
"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 3e9b32a

Please sign in to comment.