@drift-labs/sdk 0.1.30-master.0 → 0.1.30-master.1
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/lib/accounts/bulkAccountLoader.d.ts +2 -2
- package/lib/accounts/bulkAccountLoader.js +20 -23
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +15 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +50 -23
- package/lib/clearingHouse.d.ts +0 -1
- package/lib/clearingHouse.js +0 -14
- package/lib/constants/accounts.d.ts +15 -0
- package/lib/constants/accounts.js +18 -0
- package/lib/factory/clearingHouse.d.ts +14 -4
- package/lib/factory/clearingHouse.js +23 -6
- package/lib/idl/clearing_house.json +2 -33
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/math/amm.d.ts +20 -0
- package/lib/math/amm.js +151 -1
- package/lib/util/promiseTimeout.d.ts +1 -0
- package/lib/util/promiseTimeout.js +14 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +21 -31
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +73 -30
- package/src/clearingHouse.ts +0 -13
- package/src/constants/accounts.ts +26 -0
- package/src/factory/clearingHouse.ts +47 -7
- package/src/idl/clearing_house.json +2 -33
- package/src/index.ts +0 -1
- package/src/math/amm.ts +212 -1
- package/src/util/promiseTimeout.ts +14 -0
- package/lib/math/repeg.d.ts +0 -32
- package/lib/math/repeg.js +0 -178
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -210
- package/src/accounts/pollingClearingHouseAccountSubscriber.js.map +0 -1
- package/src/accounts/pollingOracleSubscriber.js +0 -65
- package/src/accounts/pollingOracleSubscriber.js.map +0 -1
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -65
- package/src/accounts/pollingTokenAccountSubscriber.js.map +0 -1
- package/src/accounts/utils.js +0 -8
- package/src/accounts/utils.js.map +0 -1
- package/src/accounts/webSocketAccountSubscriber.js +0 -64
- package/src/accounts/webSocketAccountSubscriber.js.map +0 -1
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -212
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js.map +0 -1
- package/src/constants/markets.js +0 -167
- package/src/constants/markets.js.map +0 -1
- package/src/constants/numericConstants.js +0 -22
- package/src/constants/numericConstants.js.map +0 -1
- package/src/math/repeg.ts +0 -253
|
@@ -16,7 +16,7 @@ export declare class BulkAccountLoader {
|
|
|
16
16
|
loadPromise?: Promise<void>;
|
|
17
17
|
loadPromiseResolver: () => void;
|
|
18
18
|
loggingEnabled: boolean;
|
|
19
|
-
|
|
19
|
+
lastTimeLoadingPromiseCleared: number;
|
|
20
20
|
constructor(connection: Connection, commitment: Commitment, pollingFrequency: number);
|
|
21
21
|
addAccount(publicKey: PublicKey, callback: (buffer: Buffer) => void): string;
|
|
22
22
|
removeAccount(publicKey: PublicKey, callbackId: string): void;
|
|
@@ -29,6 +29,6 @@ export declare class BulkAccountLoader {
|
|
|
29
29
|
getAccountData(publicKey: PublicKey): Buffer | undefined;
|
|
30
30
|
startPolling(): void;
|
|
31
31
|
stopPolling(): void;
|
|
32
|
-
log(msg: string): void;
|
|
32
|
+
log(msg: string, force?: boolean): void;
|
|
33
33
|
}
|
|
34
34
|
export {};
|
|
@@ -10,18 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BulkAccountLoader = void 0;
|
|
13
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
14
13
|
const uuid_1 = require("uuid");
|
|
14
|
+
const promiseTimeout_1 = require("../util/promiseTimeout");
|
|
15
15
|
const GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = 99;
|
|
16
16
|
const oneMinute = 60 * 1000;
|
|
17
|
-
const fiveMinutes = 5 * 60 * 1000;
|
|
18
17
|
class BulkAccountLoader {
|
|
19
18
|
constructor(connection, commitment, pollingFrequency) {
|
|
20
19
|
this.accountsToLoad = new Map();
|
|
21
20
|
this.accountData = new Map();
|
|
22
21
|
this.errorCallbacks = new Map();
|
|
23
22
|
this.loggingEnabled = false;
|
|
24
|
-
this.
|
|
23
|
+
this.lastTimeLoadingPromiseCleared = Date.now();
|
|
25
24
|
this.connection = connection;
|
|
26
25
|
this.commitment = commitment;
|
|
27
26
|
this.pollingFrequency = pollingFrequency;
|
|
@@ -82,12 +81,20 @@ class BulkAccountLoader {
|
|
|
82
81
|
load() {
|
|
83
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
83
|
if (this.loadPromise) {
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
if (now - this.lastTimeLoadingPromiseCleared > oneMinute) {
|
|
86
|
+
this.log(`Load promise hasnt been clearing for one minute. Clearing.`);
|
|
87
|
+
this.loadPromise = undefined;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.log(`Load promise exists. Returning early`);
|
|
91
|
+
return this.loadPromise;
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
94
|
this.loadPromise = new Promise((resolver) => {
|
|
89
95
|
this.loadPromiseResolver = resolver;
|
|
90
96
|
});
|
|
97
|
+
this.lastTimeLoadingPromiseCleared = Date.now();
|
|
91
98
|
this.log(`Loading`);
|
|
92
99
|
try {
|
|
93
100
|
const chunks = this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE);
|
|
@@ -108,13 +115,6 @@ class BulkAccountLoader {
|
|
|
108
115
|
this.log(`resetting load promise`);
|
|
109
116
|
this.loadPromiseResolver();
|
|
110
117
|
this.loadPromise = undefined;
|
|
111
|
-
const now = Date.now();
|
|
112
|
-
if (now - this.lastUpdate > fiveMinutes) {
|
|
113
|
-
this.log("Haven't seen updated account in five minutes. Bulk account loader creating new Connection Object");
|
|
114
|
-
this.connection = new web3_js_1.Connection(
|
|
115
|
-
// @ts-ignore
|
|
116
|
-
this.connection._rpcEndpoint, this.connection.commitment);
|
|
117
|
-
}
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -130,11 +130,13 @@ class BulkAccountLoader {
|
|
|
130
130
|
}),
|
|
131
131
|
{ commitment: this.commitment },
|
|
132
132
|
];
|
|
133
|
+
const rpcResponse = yield (0, promiseTimeout_1.promiseTimeout)(
|
|
133
134
|
// @ts-ignore
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
this.log('
|
|
135
|
+
this.connection._rpcRequest('getMultipleAccounts', args), 10 * 1000 // 30 second timeout
|
|
136
|
+
);
|
|
137
|
+
if (rpcResponse === null) {
|
|
138
|
+
this.log('request to rpc timed out', true);
|
|
139
|
+
return;
|
|
138
140
|
}
|
|
139
141
|
const newSlot = rpcResponse.result.context.slot;
|
|
140
142
|
for (const i in accountsToLoad) {
|
|
@@ -147,9 +149,6 @@ class BulkAccountLoader {
|
|
|
147
149
|
const dataType = rpcResponse.result.value[i].data[1];
|
|
148
150
|
newBuffer = Buffer.from(raw, dataType);
|
|
149
151
|
}
|
|
150
|
-
if (oneMinuteSinceLastUpdate) {
|
|
151
|
-
this.log('oldRPCResponse' + oldRPCResponse);
|
|
152
|
-
}
|
|
153
152
|
if (!oldRPCResponse) {
|
|
154
153
|
this.log('No old rpc response, updating account data');
|
|
155
154
|
this.accountData.set(key, {
|
|
@@ -157,7 +156,6 @@ class BulkAccountLoader {
|
|
|
157
156
|
buffer: newBuffer,
|
|
158
157
|
});
|
|
159
158
|
this.handleAccountCallbacks(accountToLoad, newBuffer);
|
|
160
|
-
this.lastUpdate = Date.now();
|
|
161
159
|
continue;
|
|
162
160
|
}
|
|
163
161
|
if (newSlot <= oldRPCResponse.slot) {
|
|
@@ -172,7 +170,6 @@ class BulkAccountLoader {
|
|
|
172
170
|
buffer: newBuffer,
|
|
173
171
|
});
|
|
174
172
|
this.handleAccountCallbacks(accountToLoad, newBuffer);
|
|
175
|
-
this.lastUpdate = Date.now();
|
|
176
173
|
}
|
|
177
174
|
else {
|
|
178
175
|
this.log('unable to update account for newest slot');
|
|
@@ -208,8 +205,8 @@ class BulkAccountLoader {
|
|
|
208
205
|
this.log('stopPolling');
|
|
209
206
|
}
|
|
210
207
|
}
|
|
211
|
-
log(msg) {
|
|
212
|
-
if (this.loggingEnabled) {
|
|
208
|
+
log(msg, force = false) {
|
|
209
|
+
if (this.loggingEnabled || force) {
|
|
213
210
|
console.log(msg);
|
|
214
211
|
}
|
|
215
212
|
}
|
|
@@ -6,6 +6,7 @@ import { EventEmitter } from 'events';
|
|
|
6
6
|
import { DepositHistoryAccount, ExtendedCurveHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, OrderHistoryAccount, OrderStateAccount, StateAccount, TradeHistoryAccount } from '../types';
|
|
7
7
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
8
8
|
import { ClearingHouseConfigType } from '../factory/clearingHouse';
|
|
9
|
+
import { PublicKey } from '@solana/web3.js';
|
|
9
10
|
export declare class PollingClearingHouseAccountSubscriber implements ClearingHouseAccountSubscriber {
|
|
10
11
|
isSubscribed: boolean;
|
|
11
12
|
program: Program;
|
|
@@ -31,6 +32,7 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
31
32
|
constructor(program: Program, accountLoader: BulkAccountLoader);
|
|
32
33
|
subscribe(optionalSubscriptions?: ClearingHouseAccountTypes[]): Promise<boolean>;
|
|
33
34
|
updateAccountsToPoll(): Promise<void>;
|
|
35
|
+
getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
|
|
34
36
|
addToAccountLoader(): Promise<void>;
|
|
35
37
|
fetch(): Promise<void>;
|
|
36
38
|
unsubscribe(): Promise<void>;
|
|
@@ -47,3 +49,16 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
47
49
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
48
50
|
getOrderHistoryAccount(): OrderHistoryAccount;
|
|
49
51
|
}
|
|
52
|
+
declare type ClearingHouseAccounts = {
|
|
53
|
+
state: PublicKey;
|
|
54
|
+
markets: PublicKey;
|
|
55
|
+
orderState: PublicKey;
|
|
56
|
+
tradeHistory?: PublicKey;
|
|
57
|
+
depositHistory?: PublicKey;
|
|
58
|
+
fundingPaymentHistory?: PublicKey;
|
|
59
|
+
fundingRateHistory?: PublicKey;
|
|
60
|
+
extendedCurveHistory?: PublicKey;
|
|
61
|
+
liquidationHistory?: PublicKey;
|
|
62
|
+
orderHistory?: PublicKey;
|
|
63
|
+
};
|
|
64
|
+
export {};
|
|
@@ -14,6 +14,7 @@ const types_1 = require("./types");
|
|
|
14
14
|
const events_1 = require("events");
|
|
15
15
|
const addresses_1 = require("../addresses");
|
|
16
16
|
const utils_1 = require("./utils");
|
|
17
|
+
const accounts_1 = require("../constants/accounts");
|
|
17
18
|
class PollingClearingHouseAccountSubscriber {
|
|
18
19
|
constructor(program, accountLoader) {
|
|
19
20
|
this.accountsToPoll = new Map();
|
|
@@ -54,75 +55,101 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
54
55
|
if (this.accountsToPoll.size > 0) {
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
this.accountsToPoll.set(statePublicKey.toString(), {
|
|
58
|
+
const accounts = yield this.getClearingHouseAccounts();
|
|
59
|
+
this.accountsToPoll.set(accounts.state.toString(), {
|
|
60
60
|
key: 'state',
|
|
61
|
-
publicKey:
|
|
61
|
+
publicKey: accounts.state,
|
|
62
62
|
eventType: 'stateAccountUpdate',
|
|
63
63
|
});
|
|
64
|
-
this.accountsToPoll.set(
|
|
64
|
+
this.accountsToPoll.set(accounts.markets.toString(), {
|
|
65
65
|
key: 'markets',
|
|
66
|
-
publicKey:
|
|
66
|
+
publicKey: accounts.markets,
|
|
67
67
|
eventType: 'marketsAccountUpdate',
|
|
68
68
|
});
|
|
69
|
-
this.accountsToPoll.set(
|
|
69
|
+
this.accountsToPoll.set(accounts.orderState.toString(), {
|
|
70
70
|
key: 'orderState',
|
|
71
|
-
publicKey:
|
|
71
|
+
publicKey: accounts.orderState,
|
|
72
72
|
eventType: 'orderStateAccountUpdate',
|
|
73
73
|
});
|
|
74
74
|
if ((_a = this.optionalExtraSubscriptions) === null || _a === void 0 ? void 0 : _a.includes('tradeHistoryAccount')) {
|
|
75
|
-
this.accountsToPoll.set(
|
|
75
|
+
this.accountsToPoll.set(accounts.tradeHistory.toString(), {
|
|
76
76
|
key: 'tradeHistory',
|
|
77
|
-
publicKey:
|
|
77
|
+
publicKey: accounts.tradeHistory,
|
|
78
78
|
eventType: 'tradeHistoryAccountUpdate',
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
if ((_b = this.optionalExtraSubscriptions) === null || _b === void 0 ? void 0 : _b.includes('depositHistoryAccount')) {
|
|
82
|
-
this.accountsToPoll.set(
|
|
82
|
+
this.accountsToPoll.set(accounts.depositHistory.toString(), {
|
|
83
83
|
key: 'depositHistory',
|
|
84
|
-
publicKey:
|
|
84
|
+
publicKey: accounts.depositHistory,
|
|
85
85
|
eventType: 'depositHistoryAccountUpdate',
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
if ((_c = this.optionalExtraSubscriptions) === null || _c === void 0 ? void 0 : _c.includes('fundingPaymentHistoryAccount')) {
|
|
89
|
-
this.accountsToPoll.set(
|
|
89
|
+
this.accountsToPoll.set(accounts.fundingPaymentHistory.toString(), {
|
|
90
90
|
key: 'fundingPaymentHistory',
|
|
91
|
-
publicKey:
|
|
91
|
+
publicKey: accounts.fundingPaymentHistory,
|
|
92
92
|
eventType: 'fundingPaymentHistoryAccountUpdate',
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
if ((_d = this.optionalExtraSubscriptions) === null || _d === void 0 ? void 0 : _d.includes('fundingRateHistoryAccount')) {
|
|
96
|
-
this.accountsToPoll.set(
|
|
96
|
+
this.accountsToPoll.set(accounts.fundingRateHistory.toString(), {
|
|
97
97
|
key: 'fundingRateHistory',
|
|
98
|
-
publicKey:
|
|
98
|
+
publicKey: accounts.fundingRateHistory,
|
|
99
99
|
eventType: 'fundingRateHistoryAccountUpdate',
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
if ((_e = this.optionalExtraSubscriptions) === null || _e === void 0 ? void 0 : _e.includes('curveHistoryAccount')) {
|
|
103
|
-
this.accountsToPoll.set(
|
|
103
|
+
this.accountsToPoll.set(accounts.extendedCurveHistory.toString(), {
|
|
104
104
|
key: 'extendedCurveHistory',
|
|
105
|
-
publicKey:
|
|
105
|
+
publicKey: accounts.extendedCurveHistory,
|
|
106
106
|
eventType: 'curveHistoryAccountUpdate',
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
if ((_f = this.optionalExtraSubscriptions) === null || _f === void 0 ? void 0 : _f.includes('liquidationHistoryAccount')) {
|
|
110
|
-
this.accountsToPoll.set(
|
|
110
|
+
this.accountsToPoll.set(accounts.liquidationHistory.toString(), {
|
|
111
111
|
key: 'liquidationHistory',
|
|
112
|
-
publicKey:
|
|
112
|
+
publicKey: accounts.liquidationHistory,
|
|
113
113
|
eventType: 'liquidationHistoryAccountUpdate',
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
if ((_g = this.optionalExtraSubscriptions) === null || _g === void 0 ? void 0 : _g.includes('orderHistoryAccount')) {
|
|
117
|
-
|
|
118
|
-
this.accountsToPoll.set(orderState.orderHistory.toString(), {
|
|
117
|
+
this.accountsToPoll.set(accounts.orderHistory.toString(), {
|
|
119
118
|
key: 'orderHistory',
|
|
120
|
-
publicKey:
|
|
119
|
+
publicKey: accounts.orderHistory,
|
|
121
120
|
eventType: 'orderHistoryAccountUpdate',
|
|
122
121
|
});
|
|
123
122
|
}
|
|
124
123
|
});
|
|
125
124
|
}
|
|
125
|
+
getClearingHouseAccounts() {
|
|
126
|
+
var _a;
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
// Skip extra calls to rpc if we already know all the accounts
|
|
129
|
+
if (accounts_1.CLEARING_HOUSE_STATE_ACCOUNTS[this.program.programId.toString()]) {
|
|
130
|
+
return accounts_1.CLEARING_HOUSE_STATE_ACCOUNTS[this.program.programId.toString()];
|
|
131
|
+
}
|
|
132
|
+
const statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
|
|
133
|
+
const state = (yield this.program.account.state.fetch(statePublicKey));
|
|
134
|
+
const accounts = {
|
|
135
|
+
state: statePublicKey,
|
|
136
|
+
markets: state.markets,
|
|
137
|
+
orderState: state.orderState,
|
|
138
|
+
tradeHistory: state.tradeHistory,
|
|
139
|
+
depositHistory: state.depositHistory,
|
|
140
|
+
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
141
|
+
fundingRateHistory: state.fundingRateHistory,
|
|
142
|
+
extendedCurveHistory: state.extendedCurveHistory,
|
|
143
|
+
liquidationHistory: state.liquidationHistory,
|
|
144
|
+
orderHistory: undefined,
|
|
145
|
+
};
|
|
146
|
+
if ((_a = this.optionalExtraSubscriptions) === null || _a === void 0 ? void 0 : _a.includes('orderHistoryAccount')) {
|
|
147
|
+
const orderState = (yield this.program.account.orderState.fetch(state.orderState));
|
|
148
|
+
accounts.orderHistory = orderState.orderHistory;
|
|
149
|
+
}
|
|
150
|
+
return accounts;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
126
153
|
addToAccountLoader() {
|
|
127
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
155
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -113,7 +113,6 @@ export declare class ClearingHouse {
|
|
|
113
113
|
*/
|
|
114
114
|
initializeUserAccountAndDepositCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<[TransactionSignature, PublicKey]>;
|
|
115
115
|
initializeUserAccountForDevnet(mockUSDCFaucet: MockUSDCFaucet, amount: BN): Promise<[TransactionSignature, PublicKey]>;
|
|
116
|
-
deleteUser(): Promise<TransactionSignature>;
|
|
117
116
|
withdrawCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
118
117
|
getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
119
118
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
package/lib/clearingHouse.js
CHANGED
|
@@ -371,20 +371,6 @@ class ClearingHouse {
|
|
|
371
371
|
return [txSig, userAccountPublicKey];
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
|
-
deleteUser() {
|
|
375
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
-
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
377
|
-
const user = yield this.program.account.user.fetch(userAccountPublicKey);
|
|
378
|
-
const deleteUserTx = yield this.program.transaction.deleteUser({
|
|
379
|
-
accounts: {
|
|
380
|
-
user: userAccountPublicKey,
|
|
381
|
-
userPositions: user.positions,
|
|
382
|
-
authority: this.wallet.publicKey,
|
|
383
|
-
},
|
|
384
|
-
});
|
|
385
|
-
return this.txSender.send(deleteUserTx, [], this.opts);
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
374
|
withdrawCollateral(amount, collateralAccountPublicKey) {
|
|
389
375
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
376
|
return this.txSender.send((0, utils_1.wrapInTx)(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export declare const CLEARING_HOUSE_STATE_ACCOUNTS: {
|
|
3
|
+
dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
|
|
4
|
+
state: PublicKey;
|
|
5
|
+
markets: PublicKey;
|
|
6
|
+
orderState: PublicKey;
|
|
7
|
+
tradeHistory: PublicKey;
|
|
8
|
+
depositHistory: PublicKey;
|
|
9
|
+
fundingPaymentHistory: PublicKey;
|
|
10
|
+
fundingRateHistory: PublicKey;
|
|
11
|
+
extendedCurveHistory: PublicKey;
|
|
12
|
+
liquidationHistory: PublicKey;
|
|
13
|
+
orderHistory: PublicKey;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLEARING_HOUSE_STATE_ACCOUNTS = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
exports.CLEARING_HOUSE_STATE_ACCOUNTS = {
|
|
6
|
+
dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
|
|
7
|
+
state: new web3_js_1.PublicKey('FExhvPycCCwYnZGeDsVtLhpEQ3yEkVY2k1HuPyfLj91L'),
|
|
8
|
+
markets: new web3_js_1.PublicKey('773hq3SbGPKVj93TXi5qV5CREuhxobywfALjS3XVHhLH'),
|
|
9
|
+
orderState: new web3_js_1.PublicKey('4cC34bWwTPGncBaX2S6v5mH3Lj4Nb3byPMrxQSDcY985'),
|
|
10
|
+
tradeHistory: new web3_js_1.PublicKey('FCuCXEoQppoaCYdttA7rK3HNQfYkTNEGpwuBESzYcENp'),
|
|
11
|
+
depositHistory: new web3_js_1.PublicKey('C7rF2Qy2rnDGQLRijBRRArJyaeuQcFi81BXDrUCQ45ya'),
|
|
12
|
+
fundingPaymentHistory: new web3_js_1.PublicKey('895iPhzwT2tBufLnRpYtBG3gif1HDDUfpH2AqbS5joo4'),
|
|
13
|
+
fundingRateHistory: new web3_js_1.PublicKey('BWiJLMbmrwfqHVpcPJa8715XamNyNYamDDKQVQMnduEC'),
|
|
14
|
+
extendedCurveHistory: new web3_js_1.PublicKey('7vBbqvMdtZLQdTVdzt5y63pZdAFE5W42kP3avngSJKCk'),
|
|
15
|
+
liquidationHistory: new web3_js_1.PublicKey('CSFaaf8yVoTx6NcXUKtNPYAewv76CH2jATqSVRBvUWKM'),
|
|
16
|
+
orderHistory: new web3_js_1.PublicKey('DZ7XfUqyHoRKnJLRApxmJ943xHJ7NDBUTqpbooviEtbU'),
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { IWallet } from '../types';
|
|
3
3
|
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
-
import { TxSender } from '../tx/types';
|
|
5
4
|
import { ClearingHouse } from '../clearingHouse';
|
|
6
5
|
import { Admin } from '../admin';
|
|
7
6
|
export declare type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
|
|
@@ -11,15 +10,26 @@ declare type BaseClearingHouseConfig = {
|
|
|
11
10
|
wallet: IWallet;
|
|
12
11
|
programID: PublicKey;
|
|
13
12
|
opts?: ConfirmOptions;
|
|
14
|
-
|
|
13
|
+
txSenderConfig?: TxSenderConfig;
|
|
15
14
|
};
|
|
16
15
|
declare type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
|
|
17
16
|
declare type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
|
|
18
17
|
accountLoader: BulkAccountLoader;
|
|
19
18
|
};
|
|
20
19
|
declare type ClearingHouseConfig = PollingClearingHouseConfiguration | WebSocketClearingHouseConfiguration;
|
|
21
|
-
export declare
|
|
22
|
-
|
|
20
|
+
export declare type TxSenderType = 'default' | 'retry';
|
|
21
|
+
declare type BaseTxSenderConfig = {
|
|
22
|
+
type: TxSenderType;
|
|
23
|
+
};
|
|
24
|
+
declare type DefaultTxSenderConfig = BaseTxSenderConfig;
|
|
25
|
+
declare type RetryTxSenderConfig = BaseTxSenderConfig & {
|
|
26
|
+
timeout?: number;
|
|
27
|
+
retrySleep?: number;
|
|
28
|
+
additionalConnections?: Connection[];
|
|
29
|
+
};
|
|
30
|
+
declare type TxSenderConfig = DefaultTxSenderConfig | RetryTxSenderConfig;
|
|
31
|
+
export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): WebSocketClearingHouseConfiguration;
|
|
32
|
+
export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): PollingClearingHouseConfiguration;
|
|
23
33
|
export declare function getClearingHouse(config: ClearingHouseConfig): ClearingHouse;
|
|
24
34
|
export declare function getAdmin(config: ClearingHouseConfig): Admin;
|
|
25
35
|
export {};
|
|
@@ -11,18 +11,19 @@ const webSocketClearingHouseAccountSubscriber_1 = require("../accounts/webSocket
|
|
|
11
11
|
const defaultTxSender_1 = require("../tx/defaultTxSender");
|
|
12
12
|
const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
|
|
13
13
|
const admin_1 = require("../admin");
|
|
14
|
-
|
|
14
|
+
const retryTxSender_1 = require("../tx/retryTxSender");
|
|
15
|
+
function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.Provider.defaultOptions(), txSenderConfig) {
|
|
15
16
|
return {
|
|
16
17
|
type: 'websocket',
|
|
17
18
|
connection,
|
|
18
19
|
wallet,
|
|
19
20
|
programID,
|
|
20
21
|
opts,
|
|
21
|
-
|
|
22
|
+
txSenderConfig,
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
|
|
25
|
-
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.Provider.defaultOptions(),
|
|
26
|
+
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.Provider.defaultOptions(), txSenderConfig) {
|
|
26
27
|
return {
|
|
27
28
|
type: 'polling',
|
|
28
29
|
connection,
|
|
@@ -30,11 +31,12 @@ function getPollingClearingHouseConfig(connection, wallet, programID, accountLoa
|
|
|
30
31
|
programID,
|
|
31
32
|
accountLoader,
|
|
32
33
|
opts,
|
|
33
|
-
|
|
34
|
+
txSenderConfig,
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
|
|
37
38
|
function getClearingHouse(config) {
|
|
39
|
+
var _a;
|
|
38
40
|
const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
|
|
39
41
|
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
40
42
|
let accountSubscriber;
|
|
@@ -44,11 +46,19 @@ function getClearingHouse(config) {
|
|
|
44
46
|
else if (config.type === 'polling') {
|
|
45
47
|
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
let txSender;
|
|
50
|
+
if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
|
|
51
|
+
const txSenderConfig = config.txSenderConfig;
|
|
52
|
+
txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
txSender = new defaultTxSender_1.DefaultTxSender(provider);
|
|
56
|
+
}
|
|
48
57
|
return new clearingHouse_1.ClearingHouse(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
49
58
|
}
|
|
50
59
|
exports.getClearingHouse = getClearingHouse;
|
|
51
60
|
function getAdmin(config) {
|
|
61
|
+
var _a;
|
|
52
62
|
const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
|
|
53
63
|
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
54
64
|
let accountSubscriber;
|
|
@@ -58,7 +68,14 @@ function getAdmin(config) {
|
|
|
58
68
|
else if (config.type === 'polling') {
|
|
59
69
|
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
60
70
|
}
|
|
61
|
-
|
|
71
|
+
let txSender;
|
|
72
|
+
if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
|
|
73
|
+
const txSenderConfig = config.txSenderConfig;
|
|
74
|
+
txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
txSender = new defaultTxSender_1.DefaultTxSender(provider);
|
|
78
|
+
}
|
|
62
79
|
return new admin_1.Admin(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
63
80
|
}
|
|
64
81
|
exports.getAdmin = getAdmin;
|
|
@@ -1482,32 +1482,6 @@
|
|
|
1482
1482
|
}
|
|
1483
1483
|
]
|
|
1484
1484
|
},
|
|
1485
|
-
{
|
|
1486
|
-
"name": "deleteUser",
|
|
1487
|
-
"accounts": [
|
|
1488
|
-
{
|
|
1489
|
-
"name": "user",
|
|
1490
|
-
"isMut": true,
|
|
1491
|
-
"isSigner": false
|
|
1492
|
-
},
|
|
1493
|
-
{
|
|
1494
|
-
"name": "userPositions",
|
|
1495
|
-
"isMut": true,
|
|
1496
|
-
"isSigner": false
|
|
1497
|
-
},
|
|
1498
|
-
{
|
|
1499
|
-
"name": "userOrders",
|
|
1500
|
-
"isMut": true,
|
|
1501
|
-
"isSigner": false
|
|
1502
|
-
},
|
|
1503
|
-
{
|
|
1504
|
-
"name": "authority",
|
|
1505
|
-
"isMut": false,
|
|
1506
|
-
"isSigner": true
|
|
1507
|
-
}
|
|
1508
|
-
],
|
|
1509
|
-
"args": []
|
|
1510
|
-
},
|
|
1511
1485
|
{
|
|
1512
1486
|
"name": "settleFundingPayment",
|
|
1513
1487
|
"accounts": [
|
|
@@ -3292,8 +3266,8 @@
|
|
|
3292
3266
|
"type": "u128"
|
|
3293
3267
|
},
|
|
3294
3268
|
{
|
|
3295
|
-
"name": "
|
|
3296
|
-
"type": "
|
|
3269
|
+
"name": "padding1",
|
|
3270
|
+
"type": "u64"
|
|
3297
3271
|
},
|
|
3298
3272
|
{
|
|
3299
3273
|
"name": "padding2",
|
|
@@ -4300,11 +4274,6 @@
|
|
|
4300
4274
|
"code": 6060,
|
|
4301
4275
|
"name": "CantExpireOrders",
|
|
4302
4276
|
"msg": "CantExpireOrders"
|
|
4303
|
-
},
|
|
4304
|
-
{
|
|
4305
|
-
"code": 6061,
|
|
4306
|
-
"name": "InvalidRepegPriceImpact",
|
|
4307
|
-
"msg": "AMM repeg mark price impact vs oracle too large"
|
|
4308
4277
|
}
|
|
4309
4278
|
]
|
|
4310
4279
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -47,7 +47,6 @@ __exportStar(require("./math/position"), exports);
|
|
|
47
47
|
__exportStar(require("./math/amm"), exports);
|
|
48
48
|
__exportStar(require("./math/trade"), exports);
|
|
49
49
|
__exportStar(require("./math/orders"), exports);
|
|
50
|
-
__exportStar(require("./math/repeg"), exports);
|
|
51
50
|
__exportStar(require("./orders"), exports);
|
|
52
51
|
__exportStar(require("./orderParams"), exports);
|
|
53
52
|
__exportStar(require("./wallet"), exports);
|
package/lib/math/amm.d.ts
CHANGED
|
@@ -38,6 +38,24 @@ export declare function calculateSwapOutput(inputAssetReserve: BN, swapAmount: B
|
|
|
38
38
|
* @param positionDirection
|
|
39
39
|
*/
|
|
40
40
|
export declare function getSwapDirection(inputAssetType: AssetType, positionDirection: PositionDirection): SwapDirection;
|
|
41
|
+
/**
|
|
42
|
+
* Helper function calculating adjust k cost
|
|
43
|
+
* @param market
|
|
44
|
+
* @param marketIndex
|
|
45
|
+
* @param numerator
|
|
46
|
+
* @param denomenator
|
|
47
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
48
|
+
*/
|
|
49
|
+
export declare function calculateAdjustKCost(market: Market, marketIndex: BN, numerator: BN, denomenator: BN): BN;
|
|
50
|
+
/**
|
|
51
|
+
* Helper function calculating adjust pegMultiplier (repeg) cost
|
|
52
|
+
*
|
|
53
|
+
* @param market
|
|
54
|
+
* @param marketIndex
|
|
55
|
+
* @param newPeg
|
|
56
|
+
* @returns cost : Precision QUOTE_ASSET_PRECISION
|
|
57
|
+
*/
|
|
58
|
+
export declare function calculateRepegCost(market: Market, marketIndex: BN, newPeg: BN): BN;
|
|
41
59
|
/**
|
|
42
60
|
* Helper function calculating terminal price of amm
|
|
43
61
|
*
|
|
@@ -46,3 +64,5 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
|
|
|
46
64
|
*/
|
|
47
65
|
export declare function calculateTerminalPrice(market: Market): BN;
|
|
48
66
|
export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN): [BN, PositionDirection];
|
|
67
|
+
export declare function calculateBudgetedK(market: Market, cost: BN): [BN, BN];
|
|
68
|
+
export declare function calculateBudgetedPeg(market: Market, cost: BN): BN;
|