@drift-labs/sdk 2.25.0-beta.1 → 2.25.0-beta.2

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.
Files changed (43) hide show
  1. package/lib/addresses/pda.d.ts +1 -0
  2. package/lib/adminClient.d.ts +1 -0
  3. package/lib/constants/numericConstants.d.ts +61 -59
  4. package/lib/constants/spotMarkets.d.ts +1 -0
  5. package/lib/dlob/DLOB.d.ts +1 -0
  6. package/lib/dlob/DLOBNode.d.ts +1 -0
  7. package/lib/dlob/NodeList.d.ts +1 -0
  8. package/lib/driftClient.d.ts +1 -0
  9. package/lib/factory/bigNum.d.ts +8 -7
  10. package/lib/idl/drift.json +1 -1
  11. package/lib/math/amm.d.ts +2 -1
  12. package/lib/math/auction.d.ts +1 -0
  13. package/lib/math/conversion.d.ts +2 -1
  14. package/lib/math/funding.d.ts +1 -0
  15. package/lib/math/insurance.d.ts +1 -0
  16. package/lib/math/margin.d.ts +1 -0
  17. package/lib/math/market.d.ts +1 -0
  18. package/lib/math/oracles.d.ts +1 -0
  19. package/lib/math/orders.d.ts +1 -0
  20. package/lib/math/position.d.ts +1 -0
  21. package/lib/math/repeg.d.ts +1 -0
  22. package/lib/math/spotBalance.d.ts +1 -0
  23. package/lib/math/spotMarket.d.ts +1 -0
  24. package/lib/math/spotPosition.d.ts +1 -0
  25. package/lib/math/trade.d.ts +1 -0
  26. package/lib/math/utils.d.ts +1 -0
  27. package/lib/oracles/pythClient.d.ts +2 -1
  28. package/lib/oracles/types.d.ts +1 -0
  29. package/lib/orderParams.d.ts +1 -0
  30. package/lib/serum/serumSubscriber.d.ts +1 -0
  31. package/lib/tokenFaucet.d.ts +1 -0
  32. package/lib/types.d.ts +1 -0
  33. package/lib/user.d.ts +1 -0
  34. package/lib/userMap/userMap.js +0 -1
  35. package/package.json +1 -1
  36. package/src/idl/drift.json +1 -1
  37. package/src/userMap/userMap.ts +0 -1
  38. package/src/assert/assert.js +0 -9
  39. package/src/token/index.js +0 -38
  40. package/src/util/computeUnits.js +0 -27
  41. package/src/util/getTokenAddress.js +0 -9
  42. package/src/util/promiseTimeout.js +0 -14
  43. package/src/util/tps.js +0 -27
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey, TransactionSignature } from '@solana/web3.js';
2
3
  import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
3
4
  import { BN } from '@coral-xyz/anchor';
@@ -1,60 +1,62 @@
1
- export declare const ZERO: any;
2
- export declare const ONE: any;
3
- export declare const TWO: any;
4
- export declare const THREE: any;
5
- export declare const FOUR: any;
6
- export declare const FIVE: any;
7
- export declare const SIX: any;
8
- export declare const SEVEN: any;
9
- export declare const EIGHT: any;
10
- export declare const NINE: any;
11
- export declare const TEN: any;
12
- export declare const TEN_THOUSAND: any;
13
- export declare const BN_MAX: any;
14
- export declare const TEN_MILLION: any;
15
- export declare const MAX_LEVERAGE: any;
16
- export declare const MAX_LEVERAGE_ORDER_SIZE: any;
17
- export declare const PERCENTAGE_PRECISION_EXP: any;
18
- export declare const PERCENTAGE_PRECISION: any;
19
- export declare const CONCENTRATION_PRECISION: any;
20
- export declare const QUOTE_PRECISION_EXP: any;
21
- export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: any;
22
- export declare const PRICE_PRECISION_EXP: any;
23
- export declare const FUNDING_RATE_PRECISION_EXP: any;
24
- export declare const PEG_PRECISION_EXP: any;
25
- export declare const AMM_RESERVE_PRECISION_EXP: any;
26
- export declare const SPOT_MARKET_RATE_PRECISION_EXP: any;
27
- export declare const SPOT_MARKET_RATE_PRECISION: any;
28
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: any;
29
- export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: any;
30
- export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: any;
31
- export declare const SPOT_MARKET_UTILIZATION_PRECISION: any;
32
- export declare const SPOT_MARKET_WEIGHT_PRECISION: any;
33
- export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: any;
34
- export declare const SPOT_MARKET_BALANCE_PRECISION: any;
35
- export declare const SPOT_MARKET_IMF_PRECISION_EXP: any;
36
- export declare const SPOT_MARKET_IMF_PRECISION: any;
37
- export declare const LIQUIDATION_FEE_PRECISION: any;
38
- export declare const QUOTE_PRECISION: any;
39
- export declare const PRICE_PRECISION: any;
40
- export declare const FUNDING_RATE_PRECISION: any;
41
- export declare const FUNDING_RATE_BUFFER_PRECISION: any;
42
- export declare const PEG_PRECISION: any;
43
- export declare const AMM_RESERVE_PRECISION: any;
44
- export declare const BASE_PRECISION: any;
45
- export declare const BASE_PRECISION_EXP: any;
46
- export declare const AMM_TO_QUOTE_PRECISION_RATIO: any;
47
- export declare const PRICE_DIV_PEG: any;
48
- export declare const PRICE_TO_QUOTE_PRECISION: any;
49
- export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: any;
50
- export declare const MARGIN_PRECISION: any;
51
- export declare const BID_ASK_SPREAD_PRECISION: any;
52
- export declare const LIQUIDATION_PCT_PRECISION: any;
53
- export declare const FIVE_MINUTE: any;
54
- export declare const ONE_HOUR: any;
55
- export declare const ONE_YEAR: any;
1
+ /// <reference types="bn.js" />
2
+ import { BN } from '../';
3
+ export declare const ZERO: BN;
4
+ export declare const ONE: BN;
5
+ export declare const TWO: BN;
6
+ export declare const THREE: BN;
7
+ export declare const FOUR: BN;
8
+ export declare const FIVE: BN;
9
+ export declare const SIX: BN;
10
+ export declare const SEVEN: BN;
11
+ export declare const EIGHT: BN;
12
+ export declare const NINE: BN;
13
+ export declare const TEN: BN;
14
+ export declare const TEN_THOUSAND: BN;
15
+ export declare const BN_MAX: BN;
16
+ export declare const TEN_MILLION: BN;
17
+ export declare const MAX_LEVERAGE: BN;
18
+ export declare const MAX_LEVERAGE_ORDER_SIZE: BN;
19
+ export declare const PERCENTAGE_PRECISION_EXP: BN;
20
+ export declare const PERCENTAGE_PRECISION: BN;
21
+ export declare const CONCENTRATION_PRECISION: BN;
22
+ export declare const QUOTE_PRECISION_EXP: BN;
23
+ export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
24
+ export declare const PRICE_PRECISION_EXP: BN;
25
+ export declare const FUNDING_RATE_PRECISION_EXP: BN;
26
+ export declare const PEG_PRECISION_EXP: BN;
27
+ export declare const AMM_RESERVE_PRECISION_EXP: BN;
28
+ export declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
29
+ export declare const SPOT_MARKET_RATE_PRECISION: BN;
30
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: BN;
31
+ export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: BN;
32
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
33
+ export declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
34
+ export declare const SPOT_MARKET_WEIGHT_PRECISION: BN;
35
+ export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: BN;
36
+ export declare const SPOT_MARKET_BALANCE_PRECISION: BN;
37
+ export declare const SPOT_MARKET_IMF_PRECISION_EXP: BN;
38
+ export declare const SPOT_MARKET_IMF_PRECISION: BN;
39
+ export declare const LIQUIDATION_FEE_PRECISION: BN;
40
+ export declare const QUOTE_PRECISION: BN;
41
+ export declare const PRICE_PRECISION: BN;
42
+ export declare const FUNDING_RATE_PRECISION: BN;
43
+ export declare const FUNDING_RATE_BUFFER_PRECISION: BN;
44
+ export declare const PEG_PRECISION: BN;
45
+ export declare const AMM_RESERVE_PRECISION: BN;
46
+ export declare const BASE_PRECISION: BN;
47
+ export declare const BASE_PRECISION_EXP: BN;
48
+ export declare const AMM_TO_QUOTE_PRECISION_RATIO: BN;
49
+ export declare const PRICE_DIV_PEG: BN;
50
+ export declare const PRICE_TO_QUOTE_PRECISION: BN;
51
+ export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: BN;
52
+ export declare const MARGIN_PRECISION: BN;
53
+ export declare const BID_ASK_SPREAD_PRECISION: BN;
54
+ export declare const LIQUIDATION_PCT_PRECISION: BN;
55
+ export declare const FIVE_MINUTE: BN;
56
+ export declare const ONE_HOUR: BN;
57
+ export declare const ONE_YEAR: BN;
56
58
  export declare const QUOTE_SPOT_MARKET_INDEX = 0;
57
- export declare const LAMPORTS_PRECISION: any;
58
- export declare const LAMPORTS_EXP: any;
59
- export declare const OPEN_ORDER_MARGIN_REQUIREMENT: any;
60
- export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: any;
59
+ export declare const LAMPORTS_PRECISION: BN;
60
+ export declare const LAMPORTS_EXP: BN;
61
+ export declare const OPEN_ORDER_MARGIN_REQUIREMENT: BN;
62
+ export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey } from '@solana/web3.js';
2
3
  import { BN, DriftEnv, OracleSource } from '../';
3
4
  export type SpotMarketConfig = {
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { NodeList } from './NodeList';
2
3
  import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, MarketTypeStr, StateAccount, UserMap, OrderRecord, OrderActionRecord } from '..';
3
4
  import { PublicKey } from '@solana/web3.js';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN, OraclePriceData, Order } from '..';
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  export interface DLOBNode {
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN, MarketTypeStr, Order } from '..';
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  import { DLOBNode, DLOBNodeMap } from './DLOBNode';
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="bn.js" />
2
3
  import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
3
4
  import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams } from './types';
4
5
  import * as anchor from '@coral-xyz/anchor';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  export declare class BigNum {
3
4
  val: BN;
@@ -43,11 +44,11 @@ export declare class BigNum {
43
44
  gte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
44
45
  lte(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
45
46
  eq(bn: BigNum | BN, ignorePrecision?: boolean): boolean;
46
- eqZero(): any;
47
- gtZero(): any;
48
- ltZero(): any;
49
- gteZero(): any;
50
- lteZero(): any;
47
+ eqZero(): boolean;
48
+ gtZero(): boolean;
49
+ ltZero(): boolean;
50
+ gteZero(): boolean;
51
+ lteZero(): boolean;
51
52
  abs(): BigNum;
52
53
  neg(): BigNum;
53
54
  toString: (base?: number | 'hex', length?: number) => string;
@@ -87,8 +88,8 @@ export declare class BigNum {
87
88
  toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
88
89
  toMillified(precision?: number, rounded?: boolean): string;
89
90
  toJSON(): {
90
- val: any;
91
- precision: any;
91
+ val: string;
92
+ precision: string;
92
93
  };
93
94
  isNeg(): boolean;
94
95
  isPos(): boolean;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0-beta.1",
2
+ "version": "2.25.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/math/amm.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -86,7 +87,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
86
87
  * @param market
87
88
  * @returns cost : Precision PRICE_PRECISION
88
89
  */
89
- export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
90
+ export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
90
91
  export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
91
92
  export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
92
93
  export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { Order } from '../types';
2
3
  import { BN } from '../.';
3
4
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
@@ -1 +1,2 @@
1
- export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
1
+ import { BN } from '../';
2
+ export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { PerpMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '../index';
2
3
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
3
4
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { PerpMarketAccount, PerpPosition } from '..';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AMM, OracleGuardRails } from '../types';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { User } from '../user';
2
3
  import { PerpMarketAccount, AMM, Order } from '../types';
3
4
  import { BN } from '@coral-xyz/anchor';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN, SpotMarketAccount } from '../';
2
3
  import { OraclePriceData } from '../oracles/types';
3
4
  import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { AMM } from '../types';
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '@coral-xyz/anchor';
2
3
  import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
3
4
  export declare function castNumberToSpotPrecision(value: number, spotMarket: SpotMarketAccount): BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { SpotMarketAccount, SpotPosition } from '../types';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  import { OraclePriceData } from '../oracles/types';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  import { AssetType } from './amm';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { BN } from '../';
2
3
  export declare function clampBN(x: BN, min: BN, max: BN): BN;
3
4
  export declare const squareRootBN: (n: BN) => BN;
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  /// <reference types="node" />
2
3
  import { Connection, PublicKey } from '@solana/web3.js';
3
4
  import { OracleClient, OraclePriceData } from './types';
@@ -6,7 +7,7 @@ export declare class PythClient implements OracleClient {
6
7
  private connection;
7
8
  private multiple;
8
9
  private stableCoin;
9
- constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
10
+ constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
10
11
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
11
12
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
12
13
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  /// <reference types="node" />
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  import { PublicKey } from '@solana/web3.js';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { OptionalOrderParams, OrderTriggerCondition } from './types';
2
3
  import { BN } from '@coral-xyz/anchor';
3
4
  export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { Connection, PublicKey } from '@solana/web3.js';
2
3
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
3
4
  import { Market, Orderbook } from '@project-serum/serum';
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import * as anchor from '@coral-xyz/anchor';
2
3
  import { AnchorProvider, Program } from '@coral-xyz/anchor';
3
4
  import { AccountInfo } from '@solana/spl-token';
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import { PublicKey, Transaction } from '@solana/web3.js';
2
3
  import { BN } from '.';
3
4
  export declare enum ExchangeStatus {
package/lib/user.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="bn.js" />
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  import { EventEmitter } from 'events';
4
5
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -69,7 +69,6 @@ class UserMap {
69
69
  await this.addPubkey(new web3_js_1.PublicKey(key));
70
70
  }
71
71
  const user = this.userMap.get(key);
72
- await user.fetchAccounts();
73
72
  return user;
74
73
  }
75
74
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.25.0-beta.1",
3
+ "version": "2.25.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.25.0-beta.1",
2
+ "version": "2.25.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -113,7 +113,6 @@ export class UserMap implements UserMapInterface {
113
113
  await this.addPubkey(new PublicKey(key));
114
114
  }
115
115
  const user = this.userMap.get(key);
116
- await user.fetchAccounts();
117
116
  return user;
118
117
  }
119
118
 
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assert = void 0;
4
- function assert(condition, error) {
5
- if (!condition) {
6
- throw new Error(error || 'Unspecified AssertionError');
7
- }
8
- }
9
- exports.assert = assert;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTokenAccount = void 0;
4
- const spl_token_1 = require("@solana/spl-token");
5
- const web3_js_1 = require("@solana/web3.js");
6
- function parseTokenAccount(data) {
7
- const accountInfo = spl_token_1.AccountLayout.decode(data);
8
- accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
9
- accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
10
- accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
11
- if (accountInfo.delegateOption === 0) {
12
- accountInfo.delegate = null;
13
- // eslint-disable-next-line new-cap
14
- accountInfo.delegatedAmount = new spl_token_1.u64(0);
15
- }
16
- else {
17
- accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
18
- accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
19
- }
20
- accountInfo.isInitialized = accountInfo.state !== 0;
21
- accountInfo.isFrozen = accountInfo.state === 2;
22
- if (accountInfo.isNativeOption === 1) {
23
- accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
24
- accountInfo.isNative = true;
25
- }
26
- else {
27
- accountInfo.rentExemptReserve = null;
28
- accountInfo.isNative = false;
29
- }
30
- if (accountInfo.closeAuthorityOption === 0) {
31
- accountInfo.closeAuthority = null;
32
- }
33
- else {
34
- accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
35
- }
36
- return accountInfo;
37
- }
38
- exports.parseTokenAccount = parseTokenAccount;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.findComputeUnitConsumption = void 0;
13
- function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const tx = yield connection.getTransaction(txSignature, { commitment });
16
- const computeUnits = [];
17
- const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
18
- tx.meta.logMessages.forEach((logMessage) => {
19
- const match = logMessage.match(regex);
20
- if (match && match[1]) {
21
- computeUnits.push(match[1]);
22
- }
23
- });
24
- return computeUnits;
25
- });
26
- }
27
- exports.findComputeUnitConsumption = findComputeUnitConsumption;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokenAddress = void 0;
4
- const spl_token_1 = require("@solana/spl-token");
5
- const web3_js_1 = require("@solana/web3.js");
6
- const getTokenAddress = (mintAddress, userPubKey) => {
7
- return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
8
- };
9
- exports.getTokenAddress = getTokenAddress;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promiseTimeout = void 0;
4
- function promiseTimeout(promise, timeoutMs) {
5
- let timeoutId;
6
- const timeoutPromise = new Promise((resolve) => {
7
- timeoutId = setTimeout(() => resolve(null), timeoutMs);
8
- });
9
- return Promise.race([promise, timeoutPromise]).then((result) => {
10
- clearTimeout(timeoutId);
11
- return result;
12
- });
13
- }
14
- exports.promiseTimeout = promiseTimeout;
package/src/util/tps.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.estimateTps = void 0;
13
- function estimateTps(programId, connection, failed) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
16
- if (failed) {
17
- signatures = signatures.filter((signature) => signature.err);
18
- }
19
- const numberOfSignatures = signatures.length;
20
- if (numberOfSignatures === 0) {
21
- return 0;
22
- }
23
- return (numberOfSignatures /
24
- (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
25
- });
26
- }
27
- exports.estimateTps = estimateTps;