@streamflow/distributor 11.0.0-alpha.p334.45cbb4e → 11.0.0-alpha.p334.ea83918

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.
@@ -1,8 +1,8 @@
1
1
  import { Keypair, PublicKey, Connection, Commitment, ConnectionConfig, TransactionInstruction } from '@solana/web3.js';
2
2
  import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
3
- import { ITransactionExt, ITransactionResult, PartnerOracleTypes, PartnerOracle, ICluster, ITransactionExtResolved, IProgramAccount, unwrapExecutionParams, signAndExecuteTransaction } from '@streamflow/common';
3
+ import { IdlAccountsOfMethod, ITransactionExt, ITransactionResult, PartnerOracleTypes, IdlArgsOfMethod, IdlInstruction, PartnerOracle, ICluster, ITransactionExtResolved, IProgramAccount, unwrapExecutionParams, signAndExecuteTransaction } from '@streamflow/common';
4
4
  import BN from 'bn.js';
5
- import { Program, IdlTypes, IdlAccounts, Idl } from '@coral-xyz/anchor';
5
+ import { IdlTypes, IdlAccounts, Program } from '@coral-xyz/anchor';
6
6
  import { AlignedDistributor } from './descriptor/aligned_distributor.cjs';
7
7
  import { MerkleDistributor as MerkleDistributor$1 } from './descriptor/merkle_distributor.cjs';
8
8
  import PQueue from 'p-queue';
@@ -25,19 +25,14 @@ type CompressedClaimStatus = MerkleDistributorAccountTypes["compressedClaimStatu
25
25
  * @inline
26
26
  */
27
27
  type MerkleDistributor = MerkleDistributorAccountTypes["merkleDistributor"];
28
- type IdlInstruction<IDL extends Idl, Name extends IDL["instructions"][number]["name"]> = Extract<IDL["instructions"][number], {
29
- name: Name;
30
- }>;
31
- type AccountsOfMethod<M extends keyof Program<MerkleDistributor$1>["methods"]> = Parameters<ReturnType<Program<MerkleDistributor$1>["methods"][M]>["accounts"]>[0];
32
- type ArgsOfMethod<M extends keyof Program<MerkleDistributor$1>["methods"]> = Parameters<Program<MerkleDistributor$1>["methods"][M]>;
33
- type NewDistributorAccounts = AccountsOfMethod<"newDistributor">;
34
- type NewDistributorArgs = ArgsOfMethod<"newDistributor">;
35
- type NewClaimAccounts = AccountsOfMethod<"newClaim">;
28
+ type NewDistributorAccounts = IdlAccountsOfMethod<MerkleDistributor$1, "newDistributor">;
29
+ type NewDistributorArgs = IdlArgsOfMethod<MerkleDistributor$1, "newDistributor">;
30
+ type NewClaimAccounts = IdlAccountsOfMethod<MerkleDistributor$1, "newClaim">;
36
31
  type NewClaimArgs = IdlInstruction<MerkleDistributor$1, "newClaim">["args"];
37
- type ClaimLockedV2Accounts = AccountsOfMethod<"claimLockedV2">;
38
- type ClaimLockedAccounts = AccountsOfMethod<"claimLocked">;
39
- type ClawbackAccounts = AccountsOfMethod<"clawback">;
40
- type CloseClaimAccounts = AccountsOfMethod<"closeClaim">;
32
+ type ClaimLockedV2Accounts = IdlAccountsOfMethod<MerkleDistributor$1, "claimLockedV2">;
33
+ type ClaimLockedAccounts = IdlAccountsOfMethod<MerkleDistributor$1, "claimLocked">;
34
+ type ClawbackAccounts = IdlAccountsOfMethod<MerkleDistributor$1, "clawback">;
35
+ type CloseClaimAccounts = IdlAccountsOfMethod<MerkleDistributor$1, "closeClaim">;
41
36
  type CloseClaimArgs = IdlInstruction<MerkleDistributor$1, "closeClaim">["args"];
42
37
  /**
43
38
  * @type
@@ -322,7 +317,7 @@ declare abstract class BaseDistributorClient {
322
317
  protected apiUrl: string;
323
318
  protected apiKey?: string;
324
319
  constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, apiUrl, apiKey, }: IInitOptions);
325
- protected abstract getNewDistributorInstruction(data: ICreateDistributorData | ICreateAlignedDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
320
+ protected abstract getNewDistributorInstruction(data: ICreateDistributorData | ICreateAlignedDistributorData, accounts: Required<NewDistributorAccounts>): Promise<TransactionInstruction>;
326
321
  protected abstract getClawbackInstruction(account: ClawbackAccounts): Promise<TransactionInstruction>;
327
322
  getConnection(): Connection;
328
323
  getCommitment(): Commitment | undefined;
@@ -379,7 +374,7 @@ declare abstract class BaseDistributorClient {
379
374
  }
380
375
 
381
376
  declare class SolanaDistributorClient extends BaseDistributorClient {
382
- protected getNewDistributorInstruction(data: ICreateDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
377
+ protected getNewDistributorInstruction(data: ICreateDistributorData, accounts: Required<NewDistributorAccounts>): Promise<TransactionInstruction>;
383
378
  protected getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction>;
384
379
  }
385
380
 
@@ -389,7 +384,7 @@ declare class SolanaAlignedDistributorClient extends BaseDistributorClient {
389
384
  getAlignedDistributorProgramId(): PublicKey;
390
385
  getAlignedDistributorAddress(distributorAddress: string): PublicKey;
391
386
  getAlignedDistributorData(distributorAddress: string): Promise<AlignedDistributorData>;
392
- protected getNewDistributorInstruction(data: ICreateAlignedDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
387
+ protected getNewDistributorInstruction(data: ICreateAlignedDistributorData, accounts: Required<NewDistributorAccounts>): Promise<TransactionInstruction>;
393
388
  protected getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction>;
394
389
  protected getNewAlignedDistributorArgs(data: ICreateAlignedDistributorData): NewAlignedDistributorArgs;
395
390
  }
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { PublicKey, Connection, SystemProgram } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
3
  import '@solana/wallet-adapter-base';
4
- import { ICluster, multiplyBigIntByNumber, fetchTokenPrice, signAndExecuteTransaction, ContractError, divCeilN, invariant, getNumberFromBN, pk, getBN, buildPartnerOracle, buildSendThrottler, prepareBaseInstructions, getMintAndProgram, ata, prepareWrappedAccount, createAndEstimateTransaction, prepareTransaction, checkOrCreateAtaBatch, unwrapExecutionParams } from '@streamflow/common';
5
4
  import { parseIdlErrors, translateError, Program } from '@coral-xyz/anchor';
6
5
  import { NATIVE_MINT, getAssociatedTokenAddressSync, getTransferFeeConfig, createTransferCheckedWithFeeInstruction, createTransferCheckedInstruction } from '@solana/spl-token';
6
+ import { ICluster, multiplyBigIntByNumber, fetchTokenPrice, signAndExecuteTransaction, ContractError, divCeilN, invariant, getNumberFromBN, pk, getBN, buildPartnerOracle, buildSendThrottler, prepareBaseInstructions, getMintAndProgram, ata, prepareWrappedAccount, createAndEstimateTransaction, prepareTransaction, checkOrCreateAtaBatch, unwrapExecutionParams } from '@streamflow/common';
7
7
  import { Buffer as Buffer$1 } from 'buffer';
8
8
 
9
9
  var __defProp = Object.defineProperty;
@@ -4797,7 +4797,13 @@ var BaseDistributorClient = class {
4797
4797
  async getFees(pubkey) {
4798
4798
  const feeConfig = await this.getFeeConfig();
4799
4799
  const nowTs = new BN(Math.trunc(Date.now() / 1e3));
4800
- return feeConfig.partners.filter((partner) => partner.pubkey.equals(pubkey) && partner.expiryTs.gt(nowTs))[0] ?? null;
4800
+ const filteredPartners = feeConfig.partners.filter(
4801
+ (partner) => partner.pubkey.equals(pubkey) && (partner.expiryTs.eqn(0) || partner.expiryTs.gt(nowTs))
4802
+ );
4803
+ if (filteredPartners.length > 1) {
4804
+ throw new Error("More than one partner found, fees fetching is not possible.");
4805
+ }
4806
+ return filteredPartners[0] ?? null;
4801
4807
  }
4802
4808
  prepareClaimFeeInstruction(payer, fee = AIRDROP_CLAIM_FEE) {
4803
4809
  return SystemProgram.transfer({
@@ -4865,7 +4871,7 @@ var SolanaDistributorClient = class extends BaseDistributorClient {
4865
4871
  // total_amount_locked
4866
4872
  data.claimsClosableByClaimant ?? null,
4867
4873
  data.claimsLimit ?? null
4868
- ).accounts(accounts).instruction();
4874
+ ).accounts(accounts).accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey }).instruction();
4869
4875
  }
4870
4876
  async getClawbackInstruction(accounts) {
4871
4877
  return this.merkleDistributorProgram.methods.clawback().accounts(accounts).instruction();
@@ -4942,7 +4948,7 @@ var SolanaAlignedDistributorClient = class extends BaseDistributorClient {
4942
4948
  mint,
4943
4949
  tokenProgram,
4944
4950
  priceOracle: oracle
4945
- }).instruction();
4951
+ }).accountsPartial({ partnerOracle: this.partnerOracleProgramId, partnerOracleConfig: this.feeConfigPublicKey }).instruction();
4946
4952
  }
4947
4953
  async getClawbackInstruction(accounts) {
4948
4954
  const { distributor, from, to, mint, tokenProgram, admin } = accounts;