@streamflow/distributor 7.0.0-alpha.6 → 7.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,8 @@ or
19
19
  ## Documentation
20
20
  API Documentation available here: [docs site →](https://streamflow-finance.github.io/js-sdk/)
21
21
 
22
+ Automated Airdrop Creation: [notion doc →](https://streamflow.notion.site/Automated-Airdrop-Creation-45b84bfd2dda4d7196be5dd02eed29c8)
23
+
22
24
  ## Import SDK
23
25
 
24
26
  Most common imports:
@@ -111,6 +113,20 @@ const solanaParams = {
111
113
  const clawbackRes = await client.clawback({ id: res.metadataId }, solanaParams);
112
114
  ```
113
115
 
116
+ ## Search Airdrops
117
+
118
+ As all the data is stored on-chain you can also search Airdrops with `searchDistributors` method:
119
+
120
+ ```javascript
121
+ // All parameters are optional, so in theory you just fetch all Distributors
122
+ const params = {
123
+ mint: "BZLbGTNCSFfoth2GYDtwr7e4imWzpR5jqcUuGEwr646K",
124
+ admin: "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA"
125
+ };
126
+ // Return an Array of objects {publicKey: PublicKey, account: Distributor}
127
+ const disributors = await client.searchDistributors(params);
128
+ ```
129
+
114
130
  ## Handling errors
115
131
 
116
132
  `GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const bs58_1 = __importDefault(require("bs58"));
6
7
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
8
  const spl_token_1 = require("@solana/spl-token");
8
9
  const web3_js_1 = require("@solana/web3.js");
@@ -187,5 +188,29 @@ class SolanaDistributorClient {
187
188
  const distributorPublicKeys = data.ids.map((distributorId) => new web3_js_1.PublicKey(distributorId));
188
189
  return accounts_1.MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
189
190
  }
191
+ async searchDistributors(data) {
192
+ const filters = [{ memcmp: { offset: 0, bytes: bs58_1.default.encode(accounts_1.MerkleDistributor.discriminator) } }];
193
+ if (data.mint) {
194
+ filters.push({
195
+ memcmp: {
196
+ offset: constants_1.DISTRIBUTOR_MINT_OFFSET,
197
+ bytes: data.mint,
198
+ },
199
+ });
200
+ }
201
+ if (data.admin) {
202
+ filters.push({
203
+ memcmp: {
204
+ offset: constants_1.DISTRIBUTOR_ADMIN_OFFSET,
205
+ bytes: data.admin,
206
+ },
207
+ });
208
+ }
209
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
210
+ return accounts.map(({ pubkey, account }) => ({
211
+ publicKey: pubkey,
212
+ account: accounts_1.MerkleDistributor.decode(account.data),
213
+ }));
214
+ }
190
215
  }
191
216
  exports.default = SolanaDistributorClient;
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = void 0;
3
+ exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = exports.DISTRIBUTOR_ADMIN_OFFSET = exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET = void 0;
4
4
  const common_1 = require("@streamflow/common");
5
+ exports.ANCHOR_DISCRIMINATOR_OFFSET = 8;
6
+ exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 41;
7
+ exports.DISTRIBUTOR_ADMIN_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 201;
5
8
  exports.ONE_IN_BASIS_POINTS = BigInt(10000);
6
9
  exports.DISTRIBUTOR_PROGRAM_ID = {
7
10
  [common_1.ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
@@ -38,6 +38,9 @@ exports.layout = borsh.struct([
38
38
  borsh.u64("endVestingTs"),
39
39
  borsh.u64("clawbackStartTs"),
40
40
  borsh.bool("claimsClosable"),
41
+ borsh.option(borsh.bool(), "canUpdateDuration"),
42
+ borsh.option(borsh.u64(), "totalAmountUnlocked"),
43
+ borsh.option(borsh.u64(), "totalAmountLocked"),
41
44
  ]);
42
45
  /**
43
46
  * READ THE FOLLOWING:
@@ -86,6 +89,9 @@ function newDistributor(args, accounts, programId = programId_1.PROGRAM_ID) {
86
89
  endVestingTs: args.endVestingTs,
87
90
  clawbackStartTs: args.clawbackStartTs,
88
91
  claimsClosable: args.claimsClosable,
92
+ canUpdateDuration: null,
93
+ totalAmountUnlocked: null,
94
+ totalAmountLocked: null,
89
95
  }, buffer);
90
96
  const data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
91
97
  const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
@@ -1,7 +1,8 @@
1
1
  import PQueue from "p-queue";
2
2
  import { PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
3
  import { ICluster, ITransactionResult } from "@streamflow/common";
4
- import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt } from "./types";
4
+ import { IProgramAccount } from "@streamflow/common/solana";
5
+ import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt, ISearchDistributors } from "./types";
5
6
  import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
6
7
  interface IInitOptions {
7
8
  clusterUrl: string;
@@ -32,5 +33,6 @@ export default class SolanaDistributorClient {
32
33
  prepareClawbackInstructions(data: IClawbackData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
33
34
  getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]>;
34
35
  getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
36
+ searchDistributors(data: ISearchDistributors): Promise<IProgramAccount<MerkleDistributor>[]>;
35
37
  }
36
38
  export {};
@@ -1,9 +1,10 @@
1
+ import bs58 from "bs58";
1
2
  import BigNumber from "bignumber.js";
2
3
  import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, createTransferCheckedInstruction, createTransferCheckedWithFeeInstruction, getTransferFeeConfig, } from "@solana/spl-token";
3
4
  import { Connection, PublicKey, SystemProgram, } from "@solana/web3.js";
4
5
  import { ICluster } from "@streamflow/common";
5
6
  import { ata, checkOrCreateAtaBatch, prepareWrappedAccount, prepareBaseInstructions, prepareTransaction, getMintAndProgram, buildSendThrottler, } from "@streamflow/common/solana";
6
- import { DISTRIBUTOR_PROGRAM_ID } from "./constants";
7
+ import { DISTRIBUTOR_ADMIN_OFFSET, DISTRIBUTOR_MINT_OFFSET, DISTRIBUTOR_PROGRAM_ID } from "./constants";
7
8
  import { claimLocked, clawback, newClaim, newDistributor, } from "./generated/instructions";
8
9
  import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
9
10
  import { calculateAmountWithTransferFees, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, wrappedSignAndExecuteTransaction, } from "./utils";
@@ -186,4 +187,28 @@ export default class SolanaDistributorClient {
186
187
  const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
187
188
  return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
188
189
  }
190
+ async searchDistributors(data) {
191
+ const filters = [{ memcmp: { offset: 0, bytes: bs58.encode(MerkleDistributor.discriminator) } }];
192
+ if (data.mint) {
193
+ filters.push({
194
+ memcmp: {
195
+ offset: DISTRIBUTOR_MINT_OFFSET,
196
+ bytes: data.mint,
197
+ },
198
+ });
199
+ }
200
+ if (data.admin) {
201
+ filters.push({
202
+ memcmp: {
203
+ offset: DISTRIBUTOR_ADMIN_OFFSET,
204
+ bytes: data.admin,
205
+ },
206
+ });
207
+ }
208
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
209
+ return accounts.map(({ pubkey, account }) => ({
210
+ publicKey: pubkey,
211
+ account: MerkleDistributor.decode(account.data),
212
+ }));
213
+ }
189
214
  }
@@ -1,3 +1,6 @@
1
+ export declare const ANCHOR_DISCRIMINATOR_OFFSET = 8;
2
+ export declare const DISTRIBUTOR_MINT_OFFSET: number;
3
+ export declare const DISTRIBUTOR_ADMIN_OFFSET: number;
1
4
  export declare const ONE_IN_BASIS_POINTS: bigint;
2
5
  export declare const DISTRIBUTOR_PROGRAM_ID: {
3
6
  devnet: string;
@@ -1,4 +1,7 @@
1
1
  import { ICluster } from "@streamflow/common";
2
+ export const ANCHOR_DISCRIMINATOR_OFFSET = 8;
3
+ export const DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41;
4
+ export const DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201;
2
5
  export const ONE_IN_BASIS_POINTS = BigInt(10000);
3
6
  export const DISTRIBUTOR_PROGRAM_ID = {
4
7
  [ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
@@ -12,6 +12,9 @@ export const layout = borsh.struct([
12
12
  borsh.u64("endVestingTs"),
13
13
  borsh.u64("clawbackStartTs"),
14
14
  borsh.bool("claimsClosable"),
15
+ borsh.option(borsh.bool(), "canUpdateDuration"),
16
+ borsh.option(borsh.u64(), "totalAmountUnlocked"),
17
+ borsh.option(borsh.u64(), "totalAmountLocked"),
15
18
  ]);
16
19
  /**
17
20
  * READ THE FOLLOWING:
@@ -60,6 +63,9 @@ export function newDistributor(args, accounts, programId = PROGRAM_ID) {
60
63
  endVestingTs: args.endVestingTs,
61
64
  clawbackStartTs: args.clawbackStartTs,
62
65
  claimsClosable: args.claimsClosable,
66
+ canUpdateDuration: null,
67
+ totalAmountUnlocked: null,
68
+ totalAmountLocked: null,
63
69
  }, buffer);
64
70
  const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
65
71
  const ix = new TransactionInstruction({ keys, programId, data });
@@ -37,6 +37,10 @@ export interface IGetClaimData {
37
37
  export interface IGetDistributors {
38
38
  ids: string[];
39
39
  }
40
+ export interface ISearchDistributors {
41
+ mint?: string;
42
+ admin?: string;
43
+ }
40
44
  export interface ISetDataAdmin {
41
45
  id: string;
42
46
  newAdmin: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/distributor",
3
- "version": "7.0.0-alpha.6",
3
+ "version": "7.0.0-alpha.8",
4
4
  "description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "dist/esm/index.js",
@@ -26,19 +26,19 @@
26
26
  "lint": "eslint --fix .",
27
27
  "prepublishOnly": "npm run lint && npm run build"
28
28
  },
29
- "gitHead": "f789b5ddcc3d6fb9b84beb0b16f63c6348bd37ab",
29
+ "gitHead": "bfd24a83d47d64185c45845b262a6f8c842c00c7",
30
30
  "devDependencies": {
31
- "@streamflow/eslint-config": "7.0.0-alpha.6",
31
+ "@streamflow/eslint-config": "7.0.0-alpha.8",
32
32
  "date-fns": "2.28.0",
33
33
  "typescript": "^4.9.5"
34
34
  },
35
35
  "dependencies": {
36
- "@coral-xyz/borsh": "^0.29.0",
36
+ "@coral-xyz/borsh": "0.30.1",
37
37
  "@solana/buffer-layout": "4.0.1 ",
38
38
  "@solana/spl-token": "0.3.6",
39
39
  "@solana/wallet-adapter-base": "0.9.19",
40
- "@solana/web3.js": "1.70.1",
41
- "@streamflow/common": "7.0.0-alpha.6",
40
+ "@solana/web3.js": "1.90.2",
41
+ "@streamflow/common": "7.0.0-alpha.8",
42
42
  "bignumber.js": "^9.1.2",
43
43
  "borsh": "^2.0.0",
44
44
  "bs58": "5.0.0",