@drift-labs/sdk 0.2.0-master.12 → 0.2.0-master.15

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 (117) hide show
  1. package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
  2. package/lib/accounts/bulkUserStatsSubscription.js +21 -0
  3. package/lib/accounts/bulkUserSubscription.js +0 -1
  4. package/lib/accounts/fetch.d.ts +2 -1
  5. package/lib/accounts/fetch.js +9 -1
  6. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  7. package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
  8. package/lib/accounts/types.d.ts +14 -2
  9. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
  10. package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
  11. package/lib/addresses/pda.d.ts +1 -0
  12. package/lib/addresses/pda.js +8 -1
  13. package/lib/admin.d.ts +2 -0
  14. package/lib/admin.js +18 -0
  15. package/lib/clearingHouse.d.ts +17 -1
  16. package/lib/clearingHouse.js +195 -14
  17. package/lib/clearingHouseConfig.d.ts +1 -0
  18. package/lib/clearingHouseUser.d.ts +5 -0
  19. package/lib/clearingHouseUser.js +97 -3
  20. package/lib/clearingHouseUserStats.d.ts +17 -0
  21. package/lib/clearingHouseUserStats.js +36 -0
  22. package/lib/clearingHouseUserStatsConfig.d.ts +14 -0
  23. package/{src/clearingHouseConfig.js → lib/clearingHouseUserStatsConfig.js} +0 -0
  24. package/lib/config.js +1 -1
  25. package/lib/factory/bigNum.js +7 -9
  26. package/lib/idl/clearing_house.json +620 -64
  27. package/lib/math/amm.js +2 -2
  28. package/lib/math/bankBalance.d.ts +4 -0
  29. package/lib/math/bankBalance.js +24 -2
  30. package/lib/math/oracles.d.ts +3 -0
  31. package/lib/math/oracles.js +25 -5
  32. package/lib/math/position.js +2 -1
  33. package/lib/math/trade.js +2 -2
  34. package/lib/types.d.ts +57 -9
  35. package/lib/types.js +6 -0
  36. package/package.json +1 -1
  37. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  38. package/src/accounts/bulkUserSubscription.ts +0 -1
  39. package/src/accounts/fetch.ts +27 -2
  40. package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
  41. package/src/accounts/types.ts +18 -0
  42. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  43. package/src/addresses/pda.ts +13 -0
  44. package/src/admin.ts +29 -1
  45. package/src/clearingHouse.ts +318 -15
  46. package/src/clearingHouseConfig.ts +1 -0
  47. package/src/clearingHouseUser.ts +113 -10
  48. package/src/clearingHouseUserStats.ts +53 -0
  49. package/src/clearingHouseUserStatsConfig.ts +18 -0
  50. package/src/config.ts +1 -1
  51. package/src/factory/bigNum.ts +6 -7
  52. package/src/idl/clearing_house.json +620 -64
  53. package/src/math/amm.ts +8 -5
  54. package/src/math/bankBalance.ts +50 -1
  55. package/src/math/oracles.ts +42 -5
  56. package/src/math/position.ts +2 -1
  57. package/src/math/trade.ts +2 -2
  58. package/src/types.ts +61 -9
  59. package/tests/bn/test.ts +8 -0
  60. package/src/accounts/bulkAccountLoader.js +0 -197
  61. package/src/accounts/bulkUserSubscription.js +0 -33
  62. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
  63. package/src/accounts/pollingOracleSubscriber.js +0 -93
  64. package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
  65. package/src/accounts/pollingUserAccountSubscriber.js +0 -132
  66. package/src/accounts/types.js +0 -10
  67. package/src/accounts/utils.js +0 -7
  68. package/src/accounts/webSocketAccountSubscriber.js +0 -93
  69. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
  70. package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
  71. package/src/addresses/marketAddresses.js +0 -26
  72. package/src/assert/assert.js +0 -9
  73. package/src/clearingHouseUserConfig.js +0 -2
  74. package/src/constants/banks.js +0 -42
  75. package/src/constants/markets.js +0 -42
  76. package/src/constants/numericConstants.js +0 -41
  77. package/src/events/eventList.js +0 -77
  78. package/src/events/eventSubscriber.js +0 -139
  79. package/src/events/fetchLogs.js +0 -50
  80. package/src/events/pollingLogProvider.js +0 -64
  81. package/src/events/sort.js +0 -44
  82. package/src/events/txEventCache.js +0 -71
  83. package/src/events/types.js +0 -20
  84. package/src/events/webSocketLogProvider.js +0 -41
  85. package/src/examples/makeTradeExample.js +0 -80
  86. package/src/factory/bigNum.js +0 -390
  87. package/src/factory/oracleClient.js +0 -20
  88. package/src/index.js +0 -69
  89. package/src/math/amm.js +0 -369
  90. package/src/math/auction.js +0 -42
  91. package/src/math/conversion.js +0 -11
  92. package/src/math/funding.js +0 -248
  93. package/src/math/oracles.js +0 -26
  94. package/src/math/repeg.js +0 -128
  95. package/src/math/state.js +0 -15
  96. package/src/math/trade.js +0 -253
  97. package/src/math/utils.js +0 -26
  98. package/src/math/utils.js.map +0 -1
  99. package/src/mockUSDCFaucet.js +0 -280
  100. package/src/oracles/oracleClientCache.js +0 -19
  101. package/src/oracles/pythClient.js +0 -46
  102. package/src/oracles/quoteAssetOracleClient.js +0 -32
  103. package/src/oracles/switchboardClient.js +0 -69
  104. package/src/oracles/types.js +0 -2
  105. package/src/orderParams.js +0 -20
  106. package/src/slot/SlotSubscriber.js +0 -39
  107. package/src/token/index.js +0 -38
  108. package/src/tokenFaucet.js +0 -189
  109. package/src/tx/types.js +0 -2
  110. package/src/tx/utils.js +0 -17
  111. package/src/types.js +0 -125
  112. package/src/userName.js +0 -20
  113. package/src/util/computeUnits.js +0 -27
  114. package/src/util/getTokenAddress.js +0 -9
  115. package/src/util/promiseTimeout.js +0 -14
  116. package/src/util/tps.js +0 -27
  117. package/src/wallet.js +0 -35
@@ -1,189 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.TokenFaucet = void 0;
35
- const anchor = __importStar(require("@project-serum/anchor"));
36
- const anchor_1 = require("@project-serum/anchor");
37
- const spl_token_1 = require("@solana/spl-token");
38
- const web3_js_1 = require("@solana/web3.js");
39
- const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
40
- class TokenFaucet {
41
- constructor(connection, wallet, programId, mint, opts) {
42
- this.connection = connection;
43
- this.wallet = wallet;
44
- this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
45
- const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
46
- this.provider = provider;
47
- this.program = new anchor_1.Program(token_faucet_json_1.default, programId, provider);
48
- this.mint = mint;
49
- }
50
- getFaucetConfigPublicKeyAndNonce() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- return anchor.web3.PublicKey.findProgramAddress([
53
- Buffer.from(anchor.utils.bytes.utf8.encode('faucet_config')),
54
- this.mint.toBuffer(),
55
- ], this.program.programId);
56
- });
57
- }
58
- getMintAuthority() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- return (yield anchor.web3.PublicKey.findProgramAddress([
61
- Buffer.from(anchor.utils.bytes.utf8.encode('mint_authority')),
62
- this.mint.toBuffer(),
63
- ], this.program.programId))[0];
64
- });
65
- }
66
- getFaucetConfigPublicKey() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- return (yield this.getFaucetConfigPublicKeyAndNonce())[0];
69
- });
70
- }
71
- initialize() {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const [faucetConfigPublicKey] = yield this.getFaucetConfigPublicKeyAndNonce();
74
- return yield this.program.rpc.initialize({
75
- accounts: {
76
- faucetConfig: faucetConfigPublicKey,
77
- admin: this.wallet.publicKey,
78
- mintAccount: this.mint,
79
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
80
- systemProgram: anchor.web3.SystemProgram.programId,
81
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
82
- },
83
- });
84
- });
85
- }
86
- fetchState() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- return yield this.program.account.faucetConfig.fetch(yield this.getFaucetConfigPublicKey());
89
- });
90
- }
91
- mintToUserIx(userTokenAccount, amount) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return this.program.instruction.mintToUser(amount, {
94
- accounts: {
95
- faucetConfig: yield this.getFaucetConfigPublicKey(),
96
- mintAccount: this.mint,
97
- userTokenAccount,
98
- mintAuthority: yield this.getMintAuthority(),
99
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
100
- },
101
- });
102
- });
103
- }
104
- mintToUser(userTokenAccount, amount) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const mintIx = yield this.mintToUserIx(userTokenAccount, amount);
107
- const tx = new web3_js_1.Transaction().add(mintIx);
108
- const txSig = yield this.program.provider.sendAndConfirm(tx, [], this.opts);
109
- return txSig;
110
- });
111
- }
112
- transferMintAuthority() {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- return yield this.program.rpc.transferMintAuthority({
115
- accounts: {
116
- faucetConfig: yield this.getFaucetConfigPublicKey(),
117
- mintAccount: this.mint,
118
- mintAuthority: yield this.getMintAuthority(),
119
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
120
- admin: this.wallet.publicKey,
121
- },
122
- });
123
- });
124
- }
125
- createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- const tx = new web3_js_1.Transaction();
128
- const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = yield this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
129
- let associatedTokenAccountExists = false;
130
- try {
131
- const assosciatedTokenAccount = yield this.connection.getAccountInfo(associatedTokenPublicKey);
132
- associatedTokenAccountExists = !!assosciatedTokenAccount;
133
- }
134
- catch (e) {
135
- // token account doesn't exist
136
- associatedTokenAccountExists = false;
137
- }
138
- const skipAccountCreation = associatedTokenAccountExists;
139
- if (!skipAccountCreation)
140
- tx.add(createAssociatedAccountIx);
141
- tx.add(mintToTx);
142
- const txSig = yield this.program.provider.sendAndConfirm(tx, [], this.opts);
143
- return [associatedTokenPublicKey, txSig];
144
- });
145
- }
146
- createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount) {
147
- return __awaiter(this, void 0, void 0, function* () {
148
- const state = yield this.fetchState();
149
- const associateTokenPublicKey = yield this.getAssosciatedMockUSDMintAddress({ userPubKey: userPublicKey });
150
- const createAssociatedAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, associateTokenPublicKey, userPublicKey, this.wallet.publicKey);
151
- const mintToIx = yield this.mintToUserIx(associateTokenPublicKey, amount);
152
- return [associateTokenPublicKey, createAssociatedAccountIx, mintToIx];
153
- });
154
- }
155
- getAssosciatedMockUSDMintAddress(props) {
156
- return __awaiter(this, void 0, void 0, function* () {
157
- const state = yield this.fetchState();
158
- return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, props.userPubKey);
159
- });
160
- }
161
- getTokenAccountInfo(props) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const assosciatedKey = yield this.getAssosciatedMockUSDMintAddress(props);
164
- const state = yield this.fetchState();
165
- const token = new spl_token_1.Token(this.connection, state.mint, spl_token_1.TOKEN_PROGRAM_ID,
166
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
167
- // @ts-ignore
168
- this.provider.payer);
169
- return yield token.getAccountInfo(assosciatedKey);
170
- });
171
- }
172
- subscribeToTokenAccount(props) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- try {
175
- const tokenAccountKey = yield this.getAssosciatedMockUSDMintAddress(props);
176
- props.callback(yield this.getTokenAccountInfo(props));
177
- // Couldn't find a way to do it using anchor framework subscription, someone on serum discord recommended this way
178
- this.connection.onAccountChange(tokenAccountKey, (_accountInfo /* accountInfo is a buffer which we don't know how to deserialize */) => __awaiter(this, void 0, void 0, function* () {
179
- props.callback(yield this.getTokenAccountInfo(props));
180
- }));
181
- return true;
182
- }
183
- catch (e) {
184
- return false;
185
- }
186
- });
187
- }
188
- }
189
- exports.TokenFaucet = TokenFaucet;
package/src/tx/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/src/tx/utils.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapInTx = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const COMPUTE_UNITS_DEFAULT = 200000;
6
- function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
7
- ) {
8
- const tx = new web3_js_1.Transaction();
9
- if (computeUnits != COMPUTE_UNITS_DEFAULT) {
10
- tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
11
- units: computeUnits,
12
- additionalFee: 0,
13
- }));
14
- }
15
- return tx.add(instruction);
16
- }
17
- exports.wrapInTx = wrapInTx;
package/src/types.js DELETED
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultOrderParams = exports.LiquidationType = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
4
- const _1 = require(".");
5
- // # Utility Types / Enums / Constants
6
- class SwapDirection {
7
- }
8
- exports.SwapDirection = SwapDirection;
9
- SwapDirection.ADD = { add: {} };
10
- SwapDirection.REMOVE = { remove: {} };
11
- class BankBalanceType {
12
- }
13
- exports.BankBalanceType = BankBalanceType;
14
- BankBalanceType.DEPOSIT = { deposit: {} };
15
- BankBalanceType.BORROW = { borrow: {} };
16
- class PositionDirection {
17
- }
18
- exports.PositionDirection = PositionDirection;
19
- PositionDirection.LONG = { long: {} };
20
- PositionDirection.SHORT = { short: {} };
21
- class DepositDirection {
22
- }
23
- exports.DepositDirection = DepositDirection;
24
- DepositDirection.DEPOSIT = { deposit: {} };
25
- DepositDirection.WITHDRAW = { withdraw: {} };
26
- class OracleSource {
27
- }
28
- exports.OracleSource = OracleSource;
29
- OracleSource.PYTH = { pyth: {} };
30
- OracleSource.SWITCHBOARD = { switchboard: {} };
31
- OracleSource.QUOTE_ASSET = { quoteAsset: {} };
32
- class OrderType {
33
- }
34
- exports.OrderType = OrderType;
35
- OrderType.LIMIT = { limit: {} };
36
- OrderType.TRIGGER_MARKET = { triggerMarket: {} };
37
- OrderType.TRIGGER_LIMIT = { triggerLimit: {} };
38
- OrderType.MARKET = { market: {} };
39
- class OrderStatus {
40
- }
41
- exports.OrderStatus = OrderStatus;
42
- OrderStatus.INIT = { init: {} };
43
- OrderStatus.OPEN = { open: {} };
44
- class OrderDiscountTier {
45
- }
46
- exports.OrderDiscountTier = OrderDiscountTier;
47
- OrderDiscountTier.NONE = { none: {} };
48
- OrderDiscountTier.FIRST = { first: {} };
49
- OrderDiscountTier.SECOND = { second: {} };
50
- OrderDiscountTier.THIRD = { third: {} };
51
- OrderDiscountTier.FOURTH = { fourth: {} };
52
- class OrderAction {
53
- }
54
- exports.OrderAction = OrderAction;
55
- OrderAction.PLACE = { place: {} };
56
- OrderAction.CANCEL = { cancel: {} };
57
- OrderAction.EXPIRE = { expire: {} };
58
- OrderAction.FILL = { fill: {} };
59
- OrderAction.TRIGGER = { trigger: {} };
60
- class OrderActionExplanation {
61
- }
62
- exports.OrderActionExplanation = OrderActionExplanation;
63
- OrderActionExplanation.NONE = { none: {} };
64
- OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
65
- breachedMarginRequirement: {},
66
- };
67
- OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
68
- oraclePriceBreachedLimitPrice: {},
69
- };
70
- OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
71
- marketOrderFilledToLimitPrice: {},
72
- };
73
- class OrderTriggerCondition {
74
- }
75
- exports.OrderTriggerCondition = OrderTriggerCondition;
76
- OrderTriggerCondition.ABOVE = { above: {} };
77
- OrderTriggerCondition.BELOW = { below: {} };
78
- function isVariant(object, type) {
79
- return object.hasOwnProperty(type);
80
- }
81
- exports.isVariant = isVariant;
82
- function isOneOfVariant(object, types) {
83
- return types.reduce((result, type) => {
84
- return result || object.hasOwnProperty(type);
85
- }, false);
86
- }
87
- exports.isOneOfVariant = isOneOfVariant;
88
- var TradeSide;
89
- (function (TradeSide) {
90
- TradeSide[TradeSide["None"] = 0] = "None";
91
- TradeSide[TradeSide["Buy"] = 1] = "Buy";
92
- TradeSide[TradeSide["Sell"] = 2] = "Sell";
93
- })(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
94
- class LiquidationType {
95
- }
96
- exports.LiquidationType = LiquidationType;
97
- LiquidationType.LIQUIDATE_PERP = { liquidatePerp: {} };
98
- LiquidationType.LIQUIDATE_BORROW = { liquidateBorrow: {} };
99
- LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
100
- liquidateBorrowForPerpPnl: {},
101
- };
102
- LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
103
- liquidatePerpPnlForDeposit: {},
104
- };
105
- exports.DefaultOrderParams = {
106
- orderType: OrderType.MARKET,
107
- userOrderId: 0,
108
- direction: PositionDirection.LONG,
109
- baseAssetAmount: _1.ZERO,
110
- price: _1.ZERO,
111
- marketIndex: _1.ZERO,
112
- reduceOnly: false,
113
- postOnly: false,
114
- immediateOrCancel: false,
115
- triggerPrice: _1.ZERO,
116
- triggerCondition: OrderTriggerCondition.ABOVE,
117
- positionLimit: _1.ZERO,
118
- oraclePriceOffset: _1.ZERO,
119
- padding0: _1.ZERO,
120
- padding1: _1.ZERO,
121
- optionalAccounts: {
122
- discountToken: false,
123
- referrer: false,
124
- },
125
- };
package/src/userName.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeName = exports.encodeName = exports.DEFAULT_USER_NAME = exports.MAX_NAME_LENGTH = void 0;
4
- exports.MAX_NAME_LENGTH = 32;
5
- exports.DEFAULT_USER_NAME = 'Main Account';
6
- function encodeName(name) {
7
- if (name.length > exports.MAX_NAME_LENGTH) {
8
- throw Error(`User name (${name}) longer than 32 characters`);
9
- }
10
- const buffer = Buffer.alloc(32);
11
- buffer.fill(name);
12
- buffer.fill(' ', name.length);
13
- return Array(...buffer);
14
- }
15
- exports.encodeName = encodeName;
16
- function decodeName(bytes) {
17
- const buffer = Buffer.from(bytes);
18
- return buffer.toString('utf8').trim();
19
- }
20
- exports.decodeName = decodeName;
@@ -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;
package/src/wallet.js DELETED
@@ -1,35 +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.Wallet = void 0;
13
- class Wallet {
14
- constructor(payer) {
15
- this.payer = payer;
16
- }
17
- signTransaction(tx) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- tx.partialSign(this.payer);
20
- return tx;
21
- });
22
- }
23
- signAllTransactions(txs) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- return txs.map((t) => {
26
- t.partialSign(this.payer);
27
- return t;
28
- });
29
- });
30
- }
31
- get publicKey() {
32
- return this.payer.publicKey;
33
- }
34
- }
35
- exports.Wallet = Wallet;