@drift-labs/sdk 2.96.0-beta.13 → 2.96.0-beta.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.
- package/VERSION +1 -1
- package/bun.lockb +0 -0
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +5 -3
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +24 -1
- package/lib/accounts/types.d.ts +5 -0
- package/lib/accounts/types.js +7 -1
- package/lib/accounts/utils.d.ts +7 -0
- package/lib/accounts/utils.js +33 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -4
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +24 -1
- package/lib/config.d.ts +2 -0
- package/lib/config.js +5 -1
- package/lib/constants/spotMarkets.js +10 -0
- package/lib/driftClient.d.ts +6 -7
- package/lib/driftClient.js +16 -15
- package/lib/driftClientConfig.d.ts +2 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/tokenFaucet.js +2 -1
- package/lib/tx/baseTxSender.js +2 -2
- package/lib/tx/fastSingleTxSender.js +2 -2
- package/lib/tx/forwardOnlyTxSender.js +2 -2
- package/lib/tx/retryTxSender.js +2 -2
- package/lib/tx/txHandler.js +10 -7
- package/lib/tx/whileValidTxSender.d.ts +2 -4
- package/lib/tx/whileValidTxSender.js +16 -17
- package/lib/types.d.ts +4 -0
- package/lib/types.js +6 -1
- package/lib/util/TransactionConfirmationManager.d.ts +14 -0
- package/lib/util/TransactionConfirmationManager.js +96 -0
- package/package.json +2 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +41 -5
- package/src/accounts/types.ts +6 -0
- package/src/accounts/utils.ts +42 -0
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +40 -5
- package/src/config.ts +6 -0
- package/src/constants/spotMarkets.ts +11 -0
- package/src/driftClient.ts +62 -46
- package/src/driftClientConfig.ts +2 -0
- package/src/index.ts +1 -0
- package/src/tokenFaucet.ts +2 -2
- package/src/tx/baseTxSender.ts +2 -2
- package/src/tx/fastSingleTxSender.ts +2 -2
- package/src/tx/forwardOnlyTxSender.ts +2 -2
- package/src/tx/retryTxSender.ts +2 -2
- package/src/tx/txHandler.ts +8 -1
- package/src/tx/whileValidTxSender.ts +23 -26
- package/src/types.ts +5 -0
- package/src/util/TransactionConfirmationManager.ts +155 -0
- package/tests/ci/verifyConstants.ts +13 -0
- package/tests/tx/TransactionConfirmationManager.test.ts +286 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.96.0-beta.
|
|
1
|
+
2.96.0-beta.15
|
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataAndSlot,
|
|
2
|
+
import { AccountToPoll, DataAndSlot, DelistedMarketSetting, DriftClientAccountEvents, DriftClientAccountSubscriber, OraclesToPoll } from './types';
|
|
3
3
|
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
|
-
import {
|
|
6
|
+
import { PerpMarketAccount, SpotMarketAccount, StateAccount, UserAccount } from '../types';
|
|
7
7
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
@@ -30,10 +30,11 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
30
30
|
spotOracleStringMap: Map<number, string>;
|
|
31
31
|
oracles: Map<string, DataAndSlot<OraclePriceData>>;
|
|
32
32
|
user?: DataAndSlot<UserAccount>;
|
|
33
|
+
delistedMarketSetting: DelistedMarketSetting;
|
|
33
34
|
private isSubscribing;
|
|
34
35
|
private subscriptionPromise;
|
|
35
36
|
private subscriptionPromiseResolver;
|
|
36
|
-
constructor(program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean);
|
|
37
|
+
constructor(program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting);
|
|
37
38
|
subscribe(): Promise<boolean>;
|
|
38
39
|
updateAccountsToPoll(): Promise<void>;
|
|
39
40
|
updatePerpMarketAccountsToPoll(): Promise<boolean>;
|
|
@@ -54,6 +55,7 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
54
55
|
private pauseForOracleToBeAdded;
|
|
55
56
|
setPerpOracleMap(): Promise<void>;
|
|
56
57
|
setSpotOracleMap(): Promise<void>;
|
|
58
|
+
handleDelistedMarkets(): void;
|
|
57
59
|
assertIsSubscribed(): void;
|
|
58
60
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
59
61
|
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
@@ -11,7 +11,7 @@ const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
13
13
|
class PollingDriftClientAccountSubscriber {
|
|
14
|
-
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles) {
|
|
14
|
+
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting) {
|
|
15
15
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
16
16
|
this.accountsToPoll = new Map();
|
|
17
17
|
this.oraclesToPoll = new Map();
|
|
@@ -31,6 +31,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
31
31
|
this.spotMarketIndexes = spotMarketIndexes;
|
|
32
32
|
this.oracleInfos = oracleInfos;
|
|
33
33
|
this.shouldFindAllMarketsAndOracles = shouldFindAllMarketsAndOracles;
|
|
34
|
+
this.delistedMarketSetting = delistedMarketSetting;
|
|
34
35
|
}
|
|
35
36
|
async subscribe() {
|
|
36
37
|
if (this.isSubscribed) {
|
|
@@ -62,6 +63,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
62
63
|
if (subscriptionSucceeded) {
|
|
63
64
|
this.eventEmitter.emit('update');
|
|
64
65
|
}
|
|
66
|
+
this.handleDelistedMarkets();
|
|
65
67
|
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
66
68
|
this.isSubscribing = false;
|
|
67
69
|
this.isSubscribed = subscriptionSucceeded;
|
|
@@ -325,6 +327,27 @@ class PollingDriftClientAccountSubscriber {
|
|
|
325
327
|
}
|
|
326
328
|
await Promise.all(oraclePromises);
|
|
327
329
|
}
|
|
330
|
+
handleDelistedMarkets() {
|
|
331
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Subscribe) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(this.getMarketAccountsAndSlots(), this.getSpotMarketAccountsAndSlots());
|
|
335
|
+
for (const perpMarketIndex of perpMarketIndexes) {
|
|
336
|
+
const perpMarketPubkey = this.perpMarket.get(perpMarketIndex).data.pubkey;
|
|
337
|
+
const callbackId = this.accountsToPoll.get(perpMarketPubkey.toBase58()).callbackId;
|
|
338
|
+
this.accountLoader.removeAccount(perpMarketPubkey, callbackId);
|
|
339
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
340
|
+
this.perpMarket.delete(perpMarketIndex);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (const oracle of oracles) {
|
|
344
|
+
const callbackId = this.oraclesToPoll.get(oracle.toBase58()).callbackId;
|
|
345
|
+
this.accountLoader.removeAccount(oracle, callbackId);
|
|
346
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
347
|
+
this.oracles.delete(oracle.toBase58());
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
328
351
|
assertIsSubscribed() {
|
|
329
352
|
if (!this.isSubscribed) {
|
|
330
353
|
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -50,6 +50,11 @@ export interface DriftClientAccountSubscriber {
|
|
|
50
50
|
getOraclePriceDataAndSlotForSpotMarket(marketIndex: number): DataAndSlot<OraclePriceData> | undefined;
|
|
51
51
|
updateAccountLoaderPollingFrequency?: (pollingFrequency: number) => void;
|
|
52
52
|
}
|
|
53
|
+
export declare enum DelistedMarketSetting {
|
|
54
|
+
Unsubscribe = 0,
|
|
55
|
+
Subscribe = 1,
|
|
56
|
+
Discard = 2
|
|
57
|
+
}
|
|
53
58
|
export interface UserAccountEvents {
|
|
54
59
|
userAccountUpdate: (payload: UserAccount) => void;
|
|
55
60
|
update: void;
|
package/lib/accounts/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotSubscribedError = void 0;
|
|
3
|
+
exports.DelistedMarketSetting = exports.NotSubscribedError = void 0;
|
|
4
4
|
class NotSubscribedError extends Error {
|
|
5
5
|
constructor() {
|
|
6
6
|
super(...arguments);
|
|
@@ -8,3 +8,9 @@ class NotSubscribedError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.NotSubscribedError = NotSubscribedError;
|
|
11
|
+
var DelistedMarketSetting;
|
|
12
|
+
(function (DelistedMarketSetting) {
|
|
13
|
+
DelistedMarketSetting[DelistedMarketSetting["Unsubscribe"] = 0] = "Unsubscribe";
|
|
14
|
+
DelistedMarketSetting[DelistedMarketSetting["Subscribe"] = 1] = "Subscribe";
|
|
15
|
+
DelistedMarketSetting[DelistedMarketSetting["Discard"] = 2] = "Discard";
|
|
16
|
+
})(DelistedMarketSetting = exports.DelistedMarketSetting || (exports.DelistedMarketSetting = {}));
|
package/lib/accounts/utils.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { DataAndSlot } from './types';
|
|
3
|
+
import { PerpMarketAccount, SpotMarketAccount } from '../types';
|
|
1
4
|
export declare function capitalize(value: string): string;
|
|
5
|
+
export declare function findDelistedPerpMarketsAndOracles(perpMarkets: DataAndSlot<PerpMarketAccount>[], spotMarkets: DataAndSlot<SpotMarketAccount>[]): {
|
|
6
|
+
perpMarketIndexes: number[];
|
|
7
|
+
oracles: PublicKey[];
|
|
8
|
+
};
|
package/lib/accounts/utils.js
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitalize = void 0;
|
|
3
|
+
exports.findDelistedPerpMarketsAndOracles = exports.capitalize = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
4
5
|
function capitalize(value) {
|
|
5
6
|
return value[0].toUpperCase() + value.slice(1);
|
|
6
7
|
}
|
|
7
8
|
exports.capitalize = capitalize;
|
|
9
|
+
function findDelistedPerpMarketsAndOracles(perpMarkets, spotMarkets) {
|
|
10
|
+
const delistedPerpMarketIndexes = [];
|
|
11
|
+
const delistedOracles = [];
|
|
12
|
+
for (const perpMarket of perpMarkets) {
|
|
13
|
+
if (!perpMarket.data) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if ((0, types_1.isVariant)(perpMarket.data.status, 'delisted')) {
|
|
17
|
+
delistedPerpMarketIndexes.push(perpMarket.data.marketIndex);
|
|
18
|
+
delistedOracles.push(perpMarket.data.amm.oracle);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// make sure oracle isn't used by spot market
|
|
22
|
+
const filteredDelistedOracles = [];
|
|
23
|
+
for (const delistedOracle of delistedOracles) {
|
|
24
|
+
for (const spotMarket of spotMarkets) {
|
|
25
|
+
if (!spotMarket.data) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (spotMarket.data.oracle.equals(delistedOracle)) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
filteredDelistedOracles.push(delistedOracle);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
perpMarketIndexes: delistedPerpMarketIndexes,
|
|
36
|
+
oracles: filteredDelistedOracles,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.findDelistedPerpMarketsAndOracles = findDelistedPerpMarketsAndOracles;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
2
|
+
import { AccountSubscriber, DataAndSlot, DelistedMarketSetting, DriftClientAccountEvents, DriftClientAccountSubscriber, ResubOpts } from './types';
|
|
3
|
+
import { PerpMarketAccount, SpotMarketAccount, StateAccount } from '../types';
|
|
5
4
|
import { Program } from '@coral-xyz/anchor';
|
|
6
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
6
|
import { EventEmitter } from 'events';
|
|
@@ -27,13 +26,14 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
27
26
|
spotOracleMap: Map<number, PublicKey>;
|
|
28
27
|
spotOracleStringMap: Map<number, string>;
|
|
29
28
|
oracleSubscribers: Map<string, AccountSubscriber<OraclePriceData>>;
|
|
29
|
+
delistedMarketSetting: DelistedMarketSetting;
|
|
30
30
|
initialPerpMarketAccountData: Map<number, PerpMarketAccount>;
|
|
31
31
|
initialSpotMarketAccountData: Map<number, SpotMarketAccount>;
|
|
32
32
|
initialOraclePriceData: Map<string, OraclePriceData>;
|
|
33
33
|
private isSubscribing;
|
|
34
34
|
private subscriptionPromise;
|
|
35
35
|
private subscriptionPromiseResolver;
|
|
36
|
-
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
36
|
+
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], shouldFindAllMarketsAndOracles: boolean, delistedMarketSetting: DelistedMarketSetting, resubOpts?: ResubOpts, commitment?: Commitment);
|
|
37
37
|
subscribe(): Promise<boolean>;
|
|
38
38
|
setInitialData(): Promise<void>;
|
|
39
39
|
removeInitialData(): void;
|
|
@@ -53,6 +53,7 @@ export declare class WebSocketDriftClientAccountSubscriber implements DriftClien
|
|
|
53
53
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
54
54
|
setPerpOracleMap(): Promise<void>;
|
|
55
55
|
setSpotOracleMap(): Promise<void>;
|
|
56
|
+
handleDelistedMarkets(): Promise<void>;
|
|
56
57
|
assertIsSubscribed(): void;
|
|
57
58
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
58
59
|
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
@@ -9,9 +9,10 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
12
13
|
const ORACLE_DEFAULT_KEY = web3_js_1.PublicKey.default.toBase58();
|
|
13
14
|
class WebSocketDriftClientAccountSubscriber {
|
|
14
|
-
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, resubOpts, commitment) {
|
|
15
|
+
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos, shouldFindAllMarketsAndOracles, delistedMarketSetting, resubOpts, commitment) {
|
|
15
16
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
16
17
|
this.perpMarketAccountSubscribers = new Map();
|
|
17
18
|
this.perpOracleMap = new Map();
|
|
@@ -28,6 +29,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
28
29
|
this.spotMarketIndexes = spotMarketIndexes;
|
|
29
30
|
this.oracleInfos = oracleInfos;
|
|
30
31
|
this.shouldFindAllMarketsAndOracles = shouldFindAllMarketsAndOracles;
|
|
32
|
+
this.delistedMarketSetting = delistedMarketSetting;
|
|
31
33
|
this.resubOpts = resubOpts;
|
|
32
34
|
this.commitment = commitment;
|
|
33
35
|
}
|
|
@@ -69,6 +71,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
69
71
|
this.subscribeToOracles(),
|
|
70
72
|
]);
|
|
71
73
|
this.eventEmitter.emit('update');
|
|
74
|
+
await this.handleDelistedMarkets();
|
|
72
75
|
await Promise.all([this.setPerpOracleMap(), this.setSpotOracleMap()]);
|
|
73
76
|
this.isSubscribing = false;
|
|
74
77
|
this.isSubscribed = true;
|
|
@@ -263,6 +266,26 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
263
266
|
}
|
|
264
267
|
await Promise.all(addOraclePromises);
|
|
265
268
|
}
|
|
269
|
+
async handleDelistedMarkets() {
|
|
270
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Subscribe) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const { perpMarketIndexes, oracles } = (0, utils_1.findDelistedPerpMarketsAndOracles)(this.getMarketAccountsAndSlots(), this.getSpotMarketAccountsAndSlots());
|
|
274
|
+
for (const perpMarketIndex of perpMarketIndexes) {
|
|
275
|
+
await this.perpMarketAccountSubscribers
|
|
276
|
+
.get(perpMarketIndex)
|
|
277
|
+
.unsubscribe();
|
|
278
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
279
|
+
this.perpMarketAccountSubscribers.delete(perpMarketIndex);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const oracle of oracles) {
|
|
283
|
+
await this.oracleSubscribers.get(oracle.toBase58()).unsubscribe();
|
|
284
|
+
if (this.delistedMarketSetting === types_1.DelistedMarketSetting.Discard) {
|
|
285
|
+
this.oracleSubscribers.delete(oracle.toBase58());
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
266
289
|
assertIsSubscribed() {
|
|
267
290
|
if (!this.isSubscribed) {
|
|
268
291
|
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
package/lib/config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfirmOptions } from '@solana/web3.js';
|
|
1
2
|
import { PerpMarketAccount, SpotMarketAccount } from '.';
|
|
2
3
|
import { PerpMarketConfig } from './constants/perpMarkets';
|
|
3
4
|
import { SpotMarketConfig } from './constants/spotMarkets';
|
|
@@ -23,6 +24,7 @@ type DriftConfig = {
|
|
|
23
24
|
export type DriftEnv = 'devnet' | 'mainnet-beta';
|
|
24
25
|
export declare const DRIFT_PROGRAM_ID = "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH";
|
|
25
26
|
export declare const DRIFT_ORACLE_RECEIVER_ID = "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha";
|
|
27
|
+
export declare const DEFAULT_CONFIRMATION_OPTS: ConfirmOptions;
|
|
26
28
|
export declare const configs: {
|
|
27
29
|
[key in DriftEnv]: DriftConfig;
|
|
28
30
|
};
|
package/lib/config.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
|
|
3
|
+
exports.findAllMarketAndOracles = exports.getMarketsAndOraclesForSubscription = exports.initialize = exports.getConfig = exports.configs = exports.DEFAULT_CONFIRMATION_OPTS = exports.DRIFT_ORACLE_RECEIVER_ID = exports.DRIFT_PROGRAM_ID = void 0;
|
|
4
4
|
const perpMarkets_1 = require("./constants/perpMarkets");
|
|
5
5
|
const spotMarkets_1 = require("./constants/spotMarkets");
|
|
6
6
|
exports.DRIFT_PROGRAM_ID = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
|
|
7
7
|
exports.DRIFT_ORACLE_RECEIVER_ID = 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha';
|
|
8
|
+
exports.DEFAULT_CONFIRMATION_OPTS = {
|
|
9
|
+
preflightCommitment: 'confirmed',
|
|
10
|
+
commitment: 'confirmed',
|
|
11
|
+
};
|
|
8
12
|
exports.configs = {
|
|
9
13
|
devnet: {
|
|
10
14
|
ENV: 'devnet',
|
|
@@ -344,6 +344,16 @@ exports.MainnetSpotMarkets = [
|
|
|
344
344
|
precisionExp: numericConstants_1.LAMPORTS_EXP,
|
|
345
345
|
pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
|
|
346
346
|
},
|
|
347
|
+
{
|
|
348
|
+
symbol: 'MOTHER',
|
|
349
|
+
marketIndex: 26,
|
|
350
|
+
oracle: new web3_js_1.PublicKey('56ap2coZG7FPWUigVm9XrpQs3xuCwnwQaWtjWZcffEUG'),
|
|
351
|
+
oracleSource: __1.OracleSource.PYTH_PULL,
|
|
352
|
+
mint: new web3_js_1.PublicKey('3S8qX1MsMqRbiwKg2cQyx7nis1oHMgaCuc9c4VfvVdPN'),
|
|
353
|
+
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
354
|
+
precisionExp: numericConstants_1.SIX,
|
|
355
|
+
pythFeedId: '0x62742a997d01f7524f791fdb2dd43aaf0e567d765ebf8fd0406a994239e874d4',
|
|
356
|
+
},
|
|
347
357
|
];
|
|
348
358
|
exports.SpotMarkets = {
|
|
349
359
|
devnet: exports.DevnetSpotMarkets,
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
4
5
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
5
6
|
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
7
|
+
import { DriftClientMetricsEvents, IWallet, MakerInfo, MappedRecord, MarketType, ModifyOrderPolicy, OpenbookV2FulfillmentConfigAccount, OptionalOrderParams, Order, OrderParams, OrderTriggerCondition, PerpMarketAccount, PerpMarketExtendedInfo, PhoenixV1FulfillmentConfigAccount, PlaceAndTakeOrderSuccessCondition, PositionDirection, ReferrerInfo, ReferrerNameAccount, SerumV3FulfillmentConfigAccount, SettlePnlMode, SignedTxData, SpotMarketAccount, SpotPosition, StateAccount, SwapReduceOnly, SwiftOrderParamsMessage, TakerInfo, TxParams, UserAccount, UserStatsAccount } from './types';
|
|
8
|
+
import { AccountMeta, AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, Connection, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
9
9
|
import { TokenFaucet } from './tokenFaucet';
|
|
10
10
|
import { EventEmitter } from 'events';
|
|
11
11
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
12
|
-
import {
|
|
13
|
-
import { DriftClientMetricsEvents } from './types';
|
|
12
|
+
import { DataAndSlot, DriftClientAccountEvents, DriftClientAccountSubscriber } from './accounts/types';
|
|
14
13
|
import { TxSender, TxSigAndSlot } from './tx/types';
|
|
15
14
|
import { OraclePriceData } from './oracles/types';
|
|
16
15
|
import { DriftClientConfig } from './driftClientConfig';
|
|
@@ -491,7 +490,7 @@ export declare class DriftClient {
|
|
|
491
490
|
getUpdateUserIdleIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
492
491
|
updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
493
492
|
getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
494
|
-
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
493
|
+
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
495
494
|
preparePlaceAndTakePerpOrderWithAdditionalOrders(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, bracketOrdersParams?: OptionalOrderParams[], txParams?: TxParams, subAccountId?: number, cancelExistingOrders?: boolean, settlePnl?: boolean, exitEarlyIfSimFails?: boolean): Promise<{
|
|
496
495
|
placeAndTakeTx: Transaction | VersionedTransaction;
|
|
497
496
|
cancelExistingOrdersTx: Transaction | VersionedTransaction;
|
|
@@ -502,7 +501,7 @@ export declare class DriftClient {
|
|
|
502
501
|
signedCancelExistingOrdersTx?: Transaction;
|
|
503
502
|
signedSettlePnlTx?: Transaction;
|
|
504
503
|
}>;
|
|
505
|
-
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
504
|
+
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, subAccountId?: number): Promise<TransactionInstruction>;
|
|
506
505
|
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
|
|
507
506
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
|
|
508
507
|
signTakerOrderParams(orderParamsMessage: SwiftOrderParamsMessage): Promise<Buffer>;
|
package/lib/driftClient.js
CHANGED
|
@@ -27,16 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.DriftClient = void 0;
|
|
30
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
30
31
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
31
32
|
const anchor_30_1 = require("@coral-xyz/anchor-30");
|
|
32
33
|
const bs58_1 = __importDefault(require("bs58"));
|
|
33
34
|
const spl_token_1 = require("@solana/spl-token");
|
|
34
35
|
const types_1 = require("./types");
|
|
35
|
-
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
36
36
|
const drift_json_1 = __importDefault(require("./idl/drift.json"));
|
|
37
37
|
const web3_js_1 = require("@solana/web3.js");
|
|
38
38
|
const events_1 = require("events");
|
|
39
39
|
const pda_1 = require("./addresses/pda");
|
|
40
|
+
const types_2 = require("./accounts/types");
|
|
40
41
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
41
42
|
const position_1 = require("./math/position");
|
|
42
43
|
const spotBalance_1 = require("./math/spotBalance");
|
|
@@ -62,7 +63,6 @@ const txHandler_1 = require("./tx/txHandler");
|
|
|
62
63
|
const pyth_solana_receiver_1 = require("@pythnetwork/pyth-solana-receiver");
|
|
63
64
|
const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
|
|
64
65
|
const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
|
|
65
|
-
const config_2 = require("./config");
|
|
66
66
|
const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
|
|
67
67
|
const utils_2 = require("./tx/utils");
|
|
68
68
|
const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
|
|
@@ -91,7 +91,7 @@ class DriftClient {
|
|
|
91
91
|
this.connection = config.connection;
|
|
92
92
|
this.wallet = config.wallet;
|
|
93
93
|
this.opts = config.opts || {
|
|
94
|
-
...
|
|
94
|
+
...config_1.DEFAULT_CONFIRMATION_OPTS,
|
|
95
95
|
commitment: (_a = config === null || config === void 0 ? void 0 : config.connection) === null || _a === void 0 ? void 0 : _a.commitment,
|
|
96
96
|
preflightCommitment: (_b = config === null || config === void 0 ? void 0 : config.connection) === null || _b === void 0 ? void 0 : _b.commitment, // At the moment this ensures that our transaction simulations (which use Connection object) will use the same commitment level as our Transaction blockhashes (which use these opts)
|
|
97
97
|
};
|
|
@@ -170,14 +170,15 @@ class DriftClient {
|
|
|
170
170
|
if (config.env && !this.marketLookupTable) {
|
|
171
171
|
this.marketLookupTable = new web3_js_1.PublicKey(config_1.configs[config.env].MARKET_LOOKUP_TABLE);
|
|
172
172
|
}
|
|
173
|
+
const delistedMarketSetting = config.delistedMarketSetting || types_2.DelistedMarketSetting.Subscribe;
|
|
173
174
|
const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
|
|
174
175
|
config.spotMarketIndexes === undefined &&
|
|
175
176
|
config.oracleInfos === undefined;
|
|
176
177
|
if (((_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.type) === 'polling') {
|
|
177
|
-
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_x = config.perpMarketIndexes) !== null && _x !== void 0 ? _x : [], (_y = config.spotMarketIndexes) !== null && _y !== void 0 ? _y : [], (_z = config.oracleInfos) !== null && _z !== void 0 ? _z : [], noMarketsAndOraclesSpecified);
|
|
178
|
+
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_x = config.perpMarketIndexes) !== null && _x !== void 0 ? _x : [], (_y = config.spotMarketIndexes) !== null && _y !== void 0 ? _y : [], (_z = config.oracleInfos) !== null && _z !== void 0 ? _z : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
|
|
178
179
|
}
|
|
179
180
|
else {
|
|
180
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_0 = config.perpMarketIndexes) !== null && _0 !== void 0 ? _0 : [], (_1 = config.spotMarketIndexes) !== null && _1 !== void 0 ? _1 : [], (_2 = config.oracleInfos) !== null && _2 !== void 0 ? _2 : [], noMarketsAndOraclesSpecified, {
|
|
181
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_0 = config.perpMarketIndexes) !== null && _0 !== void 0 ? _0 : [], (_1 = config.spotMarketIndexes) !== null && _1 !== void 0 ? _1 : [], (_2 = config.oracleInfos) !== null && _2 !== void 0 ? _2 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
|
|
181
182
|
resubTimeoutMs: (_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.resubTimeoutMs,
|
|
182
183
|
logResubMessages: (_4 = config.accountSubscription) === null || _4 === void 0 ? void 0 : _4.logResubMessages,
|
|
183
184
|
}, (_5 = config.accountSubscription) === null || _5 === void 0 ? void 0 : _5.commitment);
|
|
@@ -1608,7 +1609,7 @@ class DriftClient {
|
|
|
1608
1609
|
direction,
|
|
1609
1610
|
baseAssetAmount: amount,
|
|
1610
1611
|
price: limitPrice,
|
|
1611
|
-
}, undefined, undefined, undefined, subAccountId);
|
|
1612
|
+
}, undefined, undefined, undefined, undefined, subAccountId);
|
|
1612
1613
|
}
|
|
1613
1614
|
async sendSignedTx(tx, opts) {
|
|
1614
1615
|
const { txSig } = await this.sendTransaction(tx, undefined, opts !== null && opts !== void 0 ? opts : this.opts, true);
|
|
@@ -2726,8 +2727,8 @@ class DriftClient {
|
|
|
2726
2727
|
remainingAccounts,
|
|
2727
2728
|
});
|
|
2728
2729
|
}
|
|
2729
|
-
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
2730
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId), txParams), [], this.opts);
|
|
2730
|
+
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, successCondition, txParams, subAccountId) {
|
|
2731
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, subAccountId), txParams), [], this.opts);
|
|
2731
2732
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2732
2733
|
return txSig;
|
|
2733
2734
|
}
|
|
@@ -2743,7 +2744,7 @@ class DriftClient {
|
|
|
2743
2744
|
let earlyExitFailedPlaceAndTakeSim = false;
|
|
2744
2745
|
const prepPlaceAndTakeTx = async () => {
|
|
2745
2746
|
var _a;
|
|
2746
|
-
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId);
|
|
2747
|
+
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, undefined, subAccountId);
|
|
2747
2748
|
placeAndTakeIxs.push(placeAndTakeIx);
|
|
2748
2749
|
if (bracketOrdersParams.length > 0) {
|
|
2749
2750
|
const bracketOrdersIx = await this.getPlaceOrdersIx(bracketOrdersParams, subAccountId);
|
|
@@ -2813,7 +2814,7 @@ class DriftClient {
|
|
|
2813
2814
|
signedSettlePnlTx: signedTxs.settlePnlTx,
|
|
2814
2815
|
};
|
|
2815
2816
|
}
|
|
2816
|
-
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId) {
|
|
2817
|
+
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, subAccountId) {
|
|
2817
2818
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
2818
2819
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2819
2820
|
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
@@ -2859,7 +2860,7 @@ class DriftClient {
|
|
|
2859
2860
|
});
|
|
2860
2861
|
}
|
|
2861
2862
|
}
|
|
2862
|
-
return await this.program.instruction.placeAndTakePerpOrder(orderParams, null, {
|
|
2863
|
+
return await this.program.instruction.placeAndTakePerpOrder(orderParams, successCondition !== null && successCondition !== void 0 ? successCondition : null, {
|
|
2863
2864
|
accounts: {
|
|
2864
2865
|
state: await this.getStatePublicKey(),
|
|
2865
2866
|
user,
|
|
@@ -3133,7 +3134,7 @@ class DriftClient {
|
|
|
3133
3134
|
baseAssetAmount: userPosition.baseAssetAmount.abs(),
|
|
3134
3135
|
reduceOnly: true,
|
|
3135
3136
|
price: limitPrice,
|
|
3136
|
-
}, undefined, undefined, undefined, subAccountId);
|
|
3137
|
+
}, undefined, undefined, undefined, undefined, subAccountId);
|
|
3137
3138
|
}
|
|
3138
3139
|
/**
|
|
3139
3140
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
@@ -4070,7 +4071,7 @@ class DriftClient {
|
|
|
4070
4071
|
postIxs.push(this.program.instruction.postMultiPythPullOracleUpdatesAtomic(encodedParams, {
|
|
4071
4072
|
accounts: {
|
|
4072
4073
|
keeper: this.wallet.publicKey,
|
|
4073
|
-
pythSolanaReceiver:
|
|
4074
|
+
pythSolanaReceiver: config_1.DRIFT_ORACLE_RECEIVER_ID,
|
|
4074
4075
|
guardianSet,
|
|
4075
4076
|
},
|
|
4076
4077
|
remainingAccounts,
|
|
@@ -4093,7 +4094,7 @@ class DriftClient {
|
|
|
4093
4094
|
return this.program.instruction.postPythPullOracleUpdateAtomic(feedIdBuffer, encodedParams, {
|
|
4094
4095
|
accounts: {
|
|
4095
4096
|
keeper: this.wallet.publicKey,
|
|
4096
|
-
pythSolanaReceiver:
|
|
4097
|
+
pythSolanaReceiver: config_1.DRIFT_ORACLE_RECEIVER_ID,
|
|
4097
4098
|
guardianSet,
|
|
4098
4099
|
priceFeed: (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, feedIdBuffer),
|
|
4099
4100
|
},
|
|
@@ -4121,7 +4122,7 @@ class DriftClient {
|
|
|
4121
4122
|
return this.program.instruction.updatePythPullOracle(feedIdBuffer, encodedParams, {
|
|
4122
4123
|
accounts: {
|
|
4123
4124
|
keeper: this.wallet.publicKey,
|
|
4124
|
-
pythSolanaReceiver:
|
|
4125
|
+
pythSolanaReceiver: config_1.DRIFT_ORACLE_RECEIVER_ID,
|
|
4125
4126
|
encodedVaa: encodedVaaAddress,
|
|
4126
4127
|
priceFeed: (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, feedIdBuffer),
|
|
4127
4128
|
},
|
|
@@ -5,6 +5,7 @@ import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
|
5
5
|
import { DriftEnv } from './config';
|
|
6
6
|
import { TxSender } from './tx/types';
|
|
7
7
|
import { TxHandler, TxHandlerConfig } from './tx/txHandler';
|
|
8
|
+
import { DelistedMarketSetting } from './accounts/types';
|
|
8
9
|
export type DriftClientConfig = {
|
|
9
10
|
connection: Connection;
|
|
10
11
|
wallet: IWallet;
|
|
@@ -29,6 +30,7 @@ export type DriftClientConfig = {
|
|
|
29
30
|
txParams?: TxParams;
|
|
30
31
|
enableMetricsEvents?: boolean;
|
|
31
32
|
txHandlerConfig?: TxHandlerConfig;
|
|
33
|
+
delistedMarketSetting?: DelistedMarketSetting;
|
|
32
34
|
};
|
|
33
35
|
export type DriftClientSubscriptionConfig = {
|
|
34
36
|
type: 'websocket';
|
package/lib/index.d.ts
CHANGED
|
@@ -107,5 +107,6 @@ export * from './memcmp';
|
|
|
107
107
|
export * from './decode/user';
|
|
108
108
|
export * from './blockhashSubscriber';
|
|
109
109
|
export * from './util/chainClock';
|
|
110
|
+
export * from './util/TransactionConfirmationManager';
|
|
110
111
|
export * from './clock/clockSubscriber';
|
|
111
112
|
export { BN, PublicKey, pyth };
|
package/lib/index.js
CHANGED
|
@@ -130,4 +130,5 @@ __exportStar(require("./memcmp"), exports);
|
|
|
130
130
|
__exportStar(require("./decode/user"), exports);
|
|
131
131
|
__exportStar(require("./blockhashSubscriber"), exports);
|
|
132
132
|
__exportStar(require("./util/chainClock"), exports);
|
|
133
|
+
__exportStar(require("./util/TransactionConfirmationManager"), exports);
|
|
133
134
|
__exportStar(require("./clock/clockSubscriber"), exports);
|
package/lib/tokenFaucet.js
CHANGED
|
@@ -31,13 +31,14 @@ const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
|
31
31
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
32
32
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
33
|
const web3_js_1 = require("@solana/web3.js");
|
|
34
|
+
const _1 = require(".");
|
|
34
35
|
const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
|
|
35
36
|
class TokenFaucet {
|
|
36
37
|
constructor(connection, wallet, programId, mint, opts, context) {
|
|
37
38
|
this.connection = connection;
|
|
38
39
|
this.context = context;
|
|
39
40
|
this.wallet = wallet;
|
|
40
|
-
this.opts = opts ||
|
|
41
|
+
this.opts = opts || _1.DEFAULT_CONFIRMATION_OPTS;
|
|
41
42
|
// @ts-ignore
|
|
42
43
|
const provider = new anchor_1.AnchorProvider(context ? context.connection.toConnection() : this.connection,
|
|
43
44
|
// @ts-ignore
|
package/lib/tx/baseTxSender.js
CHANGED
|
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BaseTxSender = void 0;
|
|
7
7
|
const types_1 = require("./types");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
10
9
|
const assert_1 = __importDefault(require("assert"));
|
|
11
10
|
const bs58_1 = __importDefault(require("bs58"));
|
|
12
11
|
const txHandler_1 = require("./txHandler");
|
|
13
12
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
13
|
+
const config_1 = require("../config");
|
|
14
14
|
const BASELINE_TX_LAND_RATE = 0.9;
|
|
15
15
|
const DEFAULT_TIMEOUT = 35000;
|
|
16
16
|
const DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES = 10;
|
|
17
17
|
const NOT_CONFIRMED_ERROR_CODE = -1001;
|
|
18
18
|
class BaseTxSender {
|
|
19
|
-
constructor({ connection, wallet, opts =
|
|
19
|
+
constructor({ connection, wallet, opts = config_1.DEFAULT_CONFIRMATION_OPTS, timeout = DEFAULT_TIMEOUT, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES, landRateToFeeFunc, }) {
|
|
20
20
|
this.timeoutCount = 0;
|
|
21
21
|
this.txLandRate = 0;
|
|
22
22
|
this.lastPriorityFeeSuggestion = 1;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FastSingleTxSender = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
5
|
const baseTxSender_1 = require("./baseTxSender");
|
|
6
|
+
const config_1 = require("../config");
|
|
7
7
|
const DEFAULT_TIMEOUT = 35000;
|
|
8
8
|
const DEFAULT_BLOCKHASH_REFRESH = 10000;
|
|
9
9
|
class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
|
|
10
|
-
constructor({ connection, wallet, opts = { ...
|
|
10
|
+
constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH, additionalConnections = new Array(), skipConfirmation = false, confirmInBackground = false, blockhashCommitment = 'finalized', confirmationStrategy = types_1.ConfirmationStrategy.Combo, trackTxLandRate, txHandler, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
|
|
11
11
|
super({
|
|
12
12
|
connection,
|
|
13
13
|
wallet,
|
|
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ForwardOnlyTxSender = void 0;
|
|
7
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
8
|
const bs58_1 = __importDefault(require("bs58"));
|
|
10
9
|
const baseTxSender_1 = require("./baseTxSender");
|
|
11
10
|
const types_1 = require("./types");
|
|
11
|
+
const config_1 = require("../config");
|
|
12
12
|
const DEFAULT_TIMEOUT = 35000;
|
|
13
13
|
const DEFAULT_RETRY = 5000;
|
|
14
14
|
class ForwardOnlyTxSender extends baseTxSender_1.BaseTxSender {
|
|
15
|
-
constructor({ connection, wallet, opts = { ...
|
|
15
|
+
constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
|
|
16
16
|
super({
|
|
17
17
|
connection,
|
|
18
18
|
wallet,
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RetryTxSender = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
5
|
const baseTxSender_1 = require("./baseTxSender");
|
|
6
|
+
const config_1 = require("../config");
|
|
7
7
|
const DEFAULT_TIMEOUT = 35000;
|
|
8
8
|
const DEFAULT_RETRY = 2000;
|
|
9
9
|
class RetryTxSender extends baseTxSender_1.BaseTxSender {
|
|
10
|
-
constructor({ connection, wallet, opts = { ...
|
|
10
|
+
constructor({ connection, wallet, opts = { ...config_1.DEFAULT_CONFIRMATION_OPTS, maxRetries: 0 }, timeout = DEFAULT_TIMEOUT, retrySleep = DEFAULT_RETRY, additionalConnections = new Array(), confirmationStrategy = types_1.ConfirmationStrategy.Combo, additionalTxSenderCallbacks = [], txHandler, trackTxLandRate, txLandRateLookbackWindowMinutes, landRateToFeeFunc, }) {
|
|
11
11
|
super({
|
|
12
12
|
connection,
|
|
13
13
|
wallet,
|