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

add search distributors method #192

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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.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
Loading