Skip to content

Commit

Permalink
add search distributors method (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yolley committed Sep 5, 2024
1 parent b1f7b91 commit 847bcc1
Show file tree
Hide file tree
Showing 10 changed files with 6,644 additions and 5,229 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.9",
"version": "6.3.10",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@
"typedoc": "0.25.11",
"typescript": "^5.3.3"
},
"version": "4.0.1",
"workspaces": [
"packages/*"
]
}
"version": "4.0.1"
}
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.9",
"version": "6.3.10",
"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.9",
"version": "6.3.10",
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
30 changes: 29 additions & 1 deletion packages/distributor/solana/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bs58 from "bs58";
import BN from "bn.js";
import PQueue from "p-queue";
import {
Expand All @@ -14,6 +15,7 @@ import {
TransactionInstruction,
Commitment,
ConnectionConfig,
MemcmpFilter,
} from "@solana/web3.js";
import { ICluster, ITransactionResult } from "@streamflow/common";
import {
Expand All @@ -26,7 +28,7 @@ import {
buildSendThrottler,
} from "@streamflow/common/solana";

import { DISTRIBUTOR_PROGRAM_ID } from "./constants";
import { DISTRIBUTOR_ADMIN_OFFSET, DISTRIBUTOR_MINT_OFFSET, DISTRIBUTOR_PROGRAM_ID } from "./constants";
import {
IClaimData,
IClawbackData,
Expand All @@ -36,6 +38,7 @@ import {
IGetDistributors,
ICreateSolanaExt,
IInteractSolanaExt,
ISearchDistributors,
} from "./types";
import {
ClaimLockedAccounts,
Expand Down Expand Up @@ -361,4 +364,29 @@ export default class SolanaDistributorClient {
const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
}

public async searchDistributors(data: ISearchDistributors): Promise<MerkleDistributor[]> {
const filters: MemcmpFilter[] = [{ memcmp: { offset: 0, bytes: bs58.encode(MerkleDistributor.discriminator) } }];
if (data.mint) {
filters.push({
memcmp: {
offset: DISTRIBUTOR_MINT_OFFSET,
bytes: data.mint,
},
});
}
if (data.admin) {
filters.push({
memcmp: {
offset: DISTRIBUTOR_ADMIN_OFFSET,
bytes: data.admin,
},
});
}
const accounts = await this.connection.getProgramAccounts(this.programId, { filters });

return accounts.map(({ account }) => {
return MerkleDistributor.decode(account.data);
});
}
}
4 changes: 4 additions & 0 deletions packages/distributor/solana/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ICluster } from "@streamflow/common";

export const ANCHOR_DISCRIMINATOR_OFFSET = 8;
export const DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41;
export const DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201;

export const ONE_IN_BASIS_POINTS = BigInt(10_000);

export const DISTRIBUTOR_PROGRAM_ID = {
Expand Down
5 changes: 5 additions & 0 deletions packages/distributor/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export interface IGetDistributors {
ids: string[];
}

export interface ISearchDistributors {
mint?: string;
admin?: string;
}

export interface ISetDataAdmin {
id: string;
newAdmin: string;
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.9",
"version": "6.3.10",
"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.9",
"version": "6.3.10",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
Loading

0 comments on commit 847bcc1

Please sign in to comment.