@streamflow/distributor 6.3.7 → 6.3.9

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.
@@ -116,9 +116,9 @@ var SolanaDistributorClient = /** @class */ (function () {
116
116
  };
117
117
  SolanaDistributorClient.prototype.prepareCreateInstructions = function (data, extParams) {
118
118
  return __awaiter(this, void 0, void 0, function () {
119
- var ixs, mint, _a, mintAccount, tokenProgramId, distributorPublicKey, tokenVault, senderTokens, args, accounts, _b, _c, _d, _e, nowTs, endVestingTs, startVestingTs;
120
- return __generator(this, function (_f) {
121
- switch (_f.label) {
119
+ var ixs, mint, _a, mintAccount, tokenProgramId, transferFeeConfig, distributorPublicKey, tokenVault, senderTokens, args, accounts, _b, _c, _d, _e, nowTs, endVestingTs, startVestingTs, _f, transferAmount, feeCharged;
120
+ return __generator(this, function (_g) {
121
+ switch (_g.label) {
122
122
  case 0:
123
123
  if (!extParams.invoker.publicKey) {
124
124
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -127,14 +127,15 @@ var SolanaDistributorClient = /** @class */ (function () {
127
127
  mint = extParams.isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(data.mint);
128
128
  return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
129
129
  case 1:
130
- _a = _f.sent(), mintAccount = _a.mint, tokenProgramId = _a.tokenProgramId;
130
+ _a = _g.sent(), mintAccount = _a.mint, tokenProgramId = _a.tokenProgramId;
131
+ transferFeeConfig = (0, spl_token_1.getTransferFeeConfig)(mintAccount);
131
132
  distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId, mint, data.version);
132
133
  return [4 /*yield*/, (0, solana_1.ata)(mint, distributorPublicKey, tokenProgramId)];
133
134
  case 2:
134
- tokenVault = _f.sent();
135
+ tokenVault = _g.sent();
135
136
  return [4 /*yield*/, (0, solana_1.ata)(mint, extParams.invoker.publicKey, tokenProgramId)];
136
137
  case 3:
137
- senderTokens = _f.sent();
138
+ senderTokens = _g.sent();
138
139
  args = {
139
140
  version: new bn_js_1.default(data.version, 10),
140
141
  root: data.root,
@@ -162,8 +163,8 @@ var SolanaDistributorClient = /** @class */ (function () {
162
163
  _e = [[]];
163
164
  return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, data.maxTotalClaim)];
164
165
  case 4:
165
- _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
166
- _f.label = 5;
166
+ _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent())]), false]))]));
167
+ _g.label = 5;
167
168
  case 5:
168
169
  nowTs = new bn_js_1.default(Math.floor(Date.now() / 1000));
169
170
  endVestingTs = args.endVestingTs.eqn(0) ? nowTs : args.endVestingTs;
@@ -172,8 +173,16 @@ var SolanaDistributorClient = /** @class */ (function () {
172
173
  throw new Error("The unlock period cannot be longer than the total vesting duration!");
173
174
  }
174
175
  ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
176
+ if (!transferFeeConfig) return [3 /*break*/, 7];
177
+ return [4 /*yield*/, (0, utils_1.calculateAmountWithTransferFees)(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()))];
178
+ case 6:
179
+ _f = _g.sent(), transferAmount = _f.transferAmount, feeCharged = _f.feeCharged;
180
+ ixs.push((0, spl_token_1.createTransferCheckedWithFeeInstruction)(senderTokens, mint, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
181
+ return [3 /*break*/, 8];
182
+ case 7:
175
183
  ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mint, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
176
- return [2 /*return*/, { distributorPublicKey: distributorPublicKey, ixs: ixs }];
184
+ _g.label = 8;
185
+ case 8: return [2 /*return*/, { distributorPublicKey: distributorPublicKey, ixs: ixs }];
177
186
  }
178
187
  });
179
188
  });
@@ -1,3 +1,4 @@
1
+ export declare const ONE_IN_BASIS_POINTS: bigint;
1
2
  export declare const DISTRIBUTOR_PROGRAM_ID: {
2
3
  devnet: string;
3
4
  mainnet: string;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DISTRIBUTOR_PROGRAM_ID = void 0;
4
+ exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = void 0;
5
5
  var common_1 = require("@streamflow/common");
6
+ exports.ONE_IN_BASIS_POINTS = BigInt(10000);
6
7
  exports.DISTRIBUTOR_PROGRAM_ID = (_a = {},
7
8
  _a[common_1.ICluster.Devnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
8
9
  _a[common_1.ICluster.Mainnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
@@ -1,7 +1,13 @@
1
+ import { TransferFeeConfig } from "@solana/spl-token";
1
2
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
2
3
  import { Connection, Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
3
4
  import { ConfirmationParams, ThrottleParams } from "@streamflow/common/solana";
5
+ export declare const divCeilN: (n: bigint, d: bigint) => bigint;
4
6
  export declare function getDistributorPda(programId: PublicKey, mint: PublicKey, version: number): PublicKey;
5
7
  export declare function getClaimantStatusPda(programId: PublicKey, distributor: PublicKey, claimant: PublicKey): PublicKey;
6
8
  export declare function getEventAuthorityPda(programId: PublicKey): PublicKey;
7
9
  export declare function wrappedSignAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
10
+ export declare function calculateAmountWithTransferFees(connection: Connection, transferFeeConfig: TransferFeeConfig, transferAmount: bigint): Promise<{
11
+ transferAmount: bigint;
12
+ feeCharged: bigint;
13
+ }>;
@@ -36,11 +36,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = void 0;
39
+ exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.divCeilN = void 0;
40
40
  var web3_js_1 = require("@solana/web3.js");
41
41
  var common_1 = require("@streamflow/common");
42
42
  var solana_1 = require("@streamflow/common/solana");
43
43
  var errors_1 = require("./generated/errors");
44
+ var constants_1 = require("./constants");
45
+ var divCeilN = function (n, d) { return n / d + (n % d ? BigInt(1) : BigInt(0)); };
46
+ exports.divCeilN = divCeilN;
44
47
  function getDistributorPda(programId, mint, version) {
45
48
  // Constructing the seed for the PDA
46
49
  var seeds = [
@@ -90,3 +93,30 @@ function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationP
90
93
  });
91
94
  }
92
95
  exports.wrappedSignAndExecuteTransaction = wrappedSignAndExecuteTransaction;
96
+ function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var epoch, transferFee, transferFeeBasisPoints, feeCharged, numerator, denominator, rawPreFeeAmount, fee;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, connection.getEpochInfo()];
102
+ case 1:
103
+ epoch = _a.sent();
104
+ transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
105
+ ? transferFeeConfig.newerTransferFee
106
+ : transferFeeConfig.olderTransferFee;
107
+ transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
108
+ feeCharged = BigInt(0);
109
+ if (transferFeeBasisPoints !== BigInt(0)) {
110
+ numerator = transferAmount * constants_1.ONE_IN_BASIS_POINTS;
111
+ denominator = constants_1.ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
112
+ rawPreFeeAmount = (0, exports.divCeilN)(numerator, denominator);
113
+ fee = rawPreFeeAmount - transferAmount;
114
+ transferAmount = rawPreFeeAmount;
115
+ feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
116
+ }
117
+ return [2 /*return*/, { transferAmount: transferAmount, feeCharged: feeCharged }];
118
+ }
119
+ });
120
+ });
121
+ }
122
+ exports.calculateAmountWithTransferFees = calculateAmountWithTransferFees;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/distributor",
3
- "version": "6.3.7",
3
+ "version": "6.3.9",
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/index.js",
@@ -22,9 +22,9 @@
22
22
  "lint": "eslint --fix .",
23
23
  "prepublishOnly": "npm run lint && npm run build"
24
24
  },
25
- "gitHead": "c769b8b4a16b9161b74874322fa02f20050ee8f0",
25
+ "gitHead": "b1f7b91920868a65feee3e04837357a1cb521f5b",
26
26
  "devDependencies": {
27
- "@streamflow/eslint-config": "6.3.7",
27
+ "@streamflow/eslint-config": "6.3.9",
28
28
  "@types/bn.js": "5.1.1",
29
29
  "@types/jest": "29.2.4",
30
30
  "date-fns": "2.28.0",
@@ -38,7 +38,7 @@
38
38
  "@solana/spl-token": "0.3.6",
39
39
  "@solana/wallet-adapter-base": "0.9.19",
40
40
  "@solana/web3.js": "1.70.1",
41
- "@streamflow/common": "6.3.7",
41
+ "@streamflow/common": "6.3.9",
42
42
  "bn.js": "5.2.1",
43
43
  "borsh": "^2.0.0",
44
44
  "bs58": "5.0.0",