@drift-labs/sdk 0.1.27 → 0.1.29-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.js +13 -3
- package/lib/clearingHouse.d.ts +2 -0
- package/lib/clearingHouse.js +24 -0
- package/lib/constants/markets.js +12 -1
- package/lib/idl/clearing_house.json +66 -2
- package/lib/math/amm.d.ts +0 -18
- package/lib/math/amm.js +1 -88
- package/lib/math/repeg.d.ts +32 -0
- package/lib/math/repeg.js +178 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +14 -4
- package/src/clearingHouse.ts +40 -0
- package/src/constants/markets.ts +12 -1
- package/src/idl/clearing_house.json +66 -2
- package/src/math/amm.ts +2 -127
- package/src/math/repeg.ts +253 -0
- package/src/types.ts +1 -0
- package/src/accounts/bulkAccountLoader.js +0 -180
- package/src/accounts/bulkAccountLoader.js.map +0 -1
- package/src/addresses.js +0 -59
- package/src/addresses.js.map +0 -1
- package/src/admin.js +0 -443
- package/src/admin.js.map +0 -1
- package/src/clearingHouse.js +0 -769
- package/src/clearingHouse.js.map +0 -1
- package/src/clearingHouseUser.js +0 -581
- package/src/clearingHouseUser.js.map +0 -1
- package/src/config.js +0 -37
- package/src/config.js.map +0 -1
- package/src/index.js +0 -56
- package/src/index.js.map +0 -1
- package/src/mockUSDCFaucet.js +0 -143
- package/src/mockUSDCFaucet.js.map +0 -1
- package/src/orderParams.js +0 -109
- package/src/orderParams.js.map +0 -1
- package/src/orders.js +0 -172
- package/src/orders.js.map +0 -1
- package/src/types.js +0 -61
- package/src/types.js.map +0 -1
- package/src/wallet.js +0 -23
- package/src/wallet.js.map +0 -1
package/src/clearingHouse.js
DELETED
|
@@ -1,769 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ClearingHouse = void 0;
|
|
26
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
27
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
28
|
-
const anchor = __importStar(require("@project-serum/anchor"));
|
|
29
|
-
const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
|
|
30
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
31
|
-
const addresses_1 = require("./addresses");
|
|
32
|
-
const utils_1 = require("./tx/utils");
|
|
33
|
-
const clearingHouse_1 = require("./factory/clearingHouse");
|
|
34
|
-
const numericConstants_1 = require("./constants/numericConstants");
|
|
35
|
-
/**
|
|
36
|
-
* # ClearingHouse
|
|
37
|
-
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
38
|
-
*
|
|
39
|
-
* The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link WebSocketClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
|
|
40
|
-
* Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a {@link ClearingHouseAccountSubscriber} and use it in the {@link ClearingHouse.constructor}
|
|
41
|
-
*/
|
|
42
|
-
class ClearingHouse {
|
|
43
|
-
constructor(connection, wallet, program, accountSubscriber, txSender, opts) {
|
|
44
|
-
this._isSubscribed = false;
|
|
45
|
-
this.connection = connection;
|
|
46
|
-
this.wallet = wallet;
|
|
47
|
-
this.opts = opts;
|
|
48
|
-
this.program = program;
|
|
49
|
-
this.accountSubscriber = accountSubscriber;
|
|
50
|
-
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
51
|
-
this.txSender = txSender;
|
|
52
|
-
}
|
|
53
|
-
get isSubscribed() {
|
|
54
|
-
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
55
|
-
}
|
|
56
|
-
set isSubscribed(val) {
|
|
57
|
-
this._isSubscribed = val;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @deprecated You should use the getClearingHouse factory method instead
|
|
61
|
-
* @param connection
|
|
62
|
-
* @param wallet
|
|
63
|
-
* @param clearingHouseProgramId
|
|
64
|
-
* @param opts
|
|
65
|
-
* @returns
|
|
66
|
-
*/
|
|
67
|
-
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.Provider.defaultOptions()) {
|
|
68
|
-
const config = (0, clearingHouse_1.getWebSocketClearingHouseConfig)(connection, wallet, clearingHouseProgramId, opts);
|
|
69
|
-
return (0, clearingHouse_1.getClearingHouse)(config);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
* @param optionalSubscriptions - Optional extra accounts to subcribe to. Always subscribes to base clearing house state and market account state by default. You should only subscribe to optional extra accounts if required, to avoid overloading your RPC.
|
|
74
|
-
* @returns Promise<boolean> : SubscriptionSuccess
|
|
75
|
-
*/
|
|
76
|
-
async subscribe(optionalSubscriptions) {
|
|
77
|
-
this.isSubscribed = await this.accountSubscriber.subscribe(optionalSubscriptions);
|
|
78
|
-
return this.isSubscribed;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Shorthand function to subscribe to all available Clearing House State Accounts
|
|
82
|
-
* @returns Promise<boolean> : SubscriptionSuccess
|
|
83
|
-
*/
|
|
84
|
-
async subscribeToAll() {
|
|
85
|
-
return this.subscribe([
|
|
86
|
-
'curveHistoryAccount',
|
|
87
|
-
'depositHistoryAccount',
|
|
88
|
-
'fundingPaymentHistoryAccount',
|
|
89
|
-
'fundingRateHistoryAccount',
|
|
90
|
-
'liquidationHistoryAccount',
|
|
91
|
-
'tradeHistoryAccount',
|
|
92
|
-
'orderHistoryAccount',
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Forces the accountSubscriber to fetch account updates from rpc
|
|
97
|
-
*/
|
|
98
|
-
async fetchAccounts() {
|
|
99
|
-
await this.accountSubscriber.fetch();
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Unsubscribe from all currently subscribed state accounts
|
|
103
|
-
*/
|
|
104
|
-
async unsubscribe() {
|
|
105
|
-
await this.accountSubscriber.unsubscribe();
|
|
106
|
-
this.isSubscribed = false;
|
|
107
|
-
}
|
|
108
|
-
async getStatePublicKey() {
|
|
109
|
-
if (this.statePublicKey) {
|
|
110
|
-
return this.statePublicKey;
|
|
111
|
-
}
|
|
112
|
-
this.statePublicKey = await (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
|
|
113
|
-
return this.statePublicKey;
|
|
114
|
-
}
|
|
115
|
-
getStateAccount() {
|
|
116
|
-
return this.accountSubscriber.getStateAccount();
|
|
117
|
-
}
|
|
118
|
-
getMarketsAccount() {
|
|
119
|
-
return this.accountSubscriber.getMarketsAccount();
|
|
120
|
-
}
|
|
121
|
-
getMarket(marketIndex) {
|
|
122
|
-
if (marketIndex instanceof anchor_1.BN) {
|
|
123
|
-
marketIndex = marketIndex.toNumber();
|
|
124
|
-
}
|
|
125
|
-
return this.getMarketsAccount().markets[marketIndex];
|
|
126
|
-
}
|
|
127
|
-
getFundingPaymentHistoryAccount() {
|
|
128
|
-
return this.accountSubscriber.getFundingPaymentHistoryAccount();
|
|
129
|
-
}
|
|
130
|
-
getFundingRateHistoryAccount() {
|
|
131
|
-
return this.accountSubscriber.getFundingRateHistoryAccount();
|
|
132
|
-
}
|
|
133
|
-
getTradeHistoryAccount() {
|
|
134
|
-
return this.accountSubscriber.getTradeHistoryAccount();
|
|
135
|
-
}
|
|
136
|
-
getLiquidationHistoryAccount() {
|
|
137
|
-
return this.accountSubscriber.getLiquidationHistoryAccount();
|
|
138
|
-
}
|
|
139
|
-
getDepositHistoryAccount() {
|
|
140
|
-
return this.accountSubscriber.getDepositHistoryAccount();
|
|
141
|
-
}
|
|
142
|
-
getCurveHistoryAccount() {
|
|
143
|
-
return this.accountSubscriber.getCurveHistoryAccount();
|
|
144
|
-
}
|
|
145
|
-
getOrderHistoryAccount() {
|
|
146
|
-
return this.accountSubscriber.getOrderHistoryAccount();
|
|
147
|
-
}
|
|
148
|
-
async getOrderStatePublicKey() {
|
|
149
|
-
if (this.orderStatePublicKey) {
|
|
150
|
-
return this.orderStatePublicKey;
|
|
151
|
-
}
|
|
152
|
-
this.orderStatePublicKey = await (0, addresses_1.getOrderStateAccountPublicKey)(this.program.programId);
|
|
153
|
-
return this.orderStatePublicKey;
|
|
154
|
-
}
|
|
155
|
-
getOrderStateAccount() {
|
|
156
|
-
return this.accountSubscriber.getOrderStateAccount();
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Update the wallet to use for clearing house transactions and linked user account
|
|
160
|
-
* @param newWallet
|
|
161
|
-
*/
|
|
162
|
-
updateWallet(newWallet) {
|
|
163
|
-
const newProvider = new anchor_1.Provider(this.connection, newWallet, this.opts);
|
|
164
|
-
const newProgram = new anchor_1.Program(clearing_house_json_1.default, this.program.programId, newProvider);
|
|
165
|
-
// Update provider for txSender with new wallet details
|
|
166
|
-
this.txSender.provider = newProvider;
|
|
167
|
-
this.wallet = newWallet;
|
|
168
|
-
this.provider = newProvider;
|
|
169
|
-
this.program = newProgram;
|
|
170
|
-
this.userAccountPublicKey = undefined;
|
|
171
|
-
this.userAccount = undefined;
|
|
172
|
-
this.userOrdersAccountPublicKey = undefined;
|
|
173
|
-
this.userOrdersExist = undefined;
|
|
174
|
-
}
|
|
175
|
-
async initializeUserAccount() {
|
|
176
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx, initializeUserOrdersAccountIx,] = await this.getInitializeUserInstructions();
|
|
177
|
-
const tx = new web3_js_1.Transaction()
|
|
178
|
-
.add(initializeUserAccountIx)
|
|
179
|
-
.add(initializeUserOrdersAccountIx);
|
|
180
|
-
const txSig = await this.txSender.send(tx, [userPositionsAccount], this.opts);
|
|
181
|
-
return [txSig, userAccountPublicKey];
|
|
182
|
-
}
|
|
183
|
-
async getInitializeUserInstructions() {
|
|
184
|
-
const [userAccountPublicKey, userAccountNonce] = await (0, addresses_1.getUserAccountPublicKeyAndNonce)(this.program.programId, this.wallet.publicKey);
|
|
185
|
-
const remainingAccounts = [];
|
|
186
|
-
const optionalAccounts = {
|
|
187
|
-
whitelistToken: false,
|
|
188
|
-
};
|
|
189
|
-
const state = this.getStateAccount();
|
|
190
|
-
if (state.whitelistMint) {
|
|
191
|
-
optionalAccounts.whitelistToken = true;
|
|
192
|
-
const associatedTokenPublicKey = await spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.whitelistMint, this.wallet.publicKey);
|
|
193
|
-
remainingAccounts.push({
|
|
194
|
-
pubkey: associatedTokenPublicKey,
|
|
195
|
-
isWritable: false,
|
|
196
|
-
isSigner: false,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
const userPositions = new web3_js_1.Keypair();
|
|
200
|
-
const initializeUserAccountIx = await this.program.instruction.initializeUser(userAccountNonce, optionalAccounts, {
|
|
201
|
-
accounts: {
|
|
202
|
-
user: userAccountPublicKey,
|
|
203
|
-
authority: this.wallet.publicKey,
|
|
204
|
-
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
205
|
-
systemProgram: anchor.web3.SystemProgram.programId,
|
|
206
|
-
userPositions: userPositions.publicKey,
|
|
207
|
-
state: await this.getStatePublicKey(),
|
|
208
|
-
},
|
|
209
|
-
remainingAccounts: remainingAccounts,
|
|
210
|
-
});
|
|
211
|
-
const initializeUserOrdersAccountIx = await this.getInitializeUserOrdersInstruction(userAccountPublicKey);
|
|
212
|
-
return [
|
|
213
|
-
userPositions,
|
|
214
|
-
userAccountPublicKey,
|
|
215
|
-
initializeUserAccountIx,
|
|
216
|
-
initializeUserOrdersAccountIx,
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
|
-
async getInitializeUserOrdersInstruction(userAccountPublicKey) {
|
|
220
|
-
if (!userAccountPublicKey) {
|
|
221
|
-
userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
222
|
-
}
|
|
223
|
-
const [userOrdersAccountPublicKey, userOrdersAccountNonce] = await (0, addresses_1.getUserOrdersAccountPublicKeyAndNonce)(this.program.programId, userAccountPublicKey);
|
|
224
|
-
return await this.program.instruction.initializeUserOrders(userOrdersAccountNonce, {
|
|
225
|
-
accounts: {
|
|
226
|
-
user: userAccountPublicKey,
|
|
227
|
-
authority: this.wallet.publicKey,
|
|
228
|
-
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
229
|
-
systemProgram: anchor.web3.SystemProgram.programId,
|
|
230
|
-
userOrders: userOrdersAccountPublicKey,
|
|
231
|
-
state: await this.getStatePublicKey(),
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Get the address for the Clearing House User's account. NOT the user's wallet address.
|
|
237
|
-
* @returns
|
|
238
|
-
*/
|
|
239
|
-
async getUserAccountPublicKey() {
|
|
240
|
-
if (this.userAccountPublicKey) {
|
|
241
|
-
return this.userAccountPublicKey;
|
|
242
|
-
}
|
|
243
|
-
this.userAccountPublicKey = await (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey);
|
|
244
|
-
return this.userAccountPublicKey;
|
|
245
|
-
}
|
|
246
|
-
async getUserAccount() {
|
|
247
|
-
if (this.userAccount) {
|
|
248
|
-
return this.userAccount;
|
|
249
|
-
}
|
|
250
|
-
this.userAccount = (await this.program.account.user.fetch(await this.getUserAccountPublicKey()));
|
|
251
|
-
return this.userAccount;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Get the address for the Clearing House User Order's account. NOT the user's wallet address.
|
|
255
|
-
* @returns
|
|
256
|
-
*/
|
|
257
|
-
async getUserOrdersAccountPublicKey() {
|
|
258
|
-
if (this.userOrdersAccountPublicKey) {
|
|
259
|
-
return this.userOrdersAccountPublicKey;
|
|
260
|
-
}
|
|
261
|
-
this.userOrdersAccountPublicKey = await (0, addresses_1.getUserOrdersAccountPublicKey)(this.program.programId, await this.getUserAccountPublicKey());
|
|
262
|
-
return this.userOrdersAccountPublicKey;
|
|
263
|
-
}
|
|
264
|
-
async userOrdersAccountExists() {
|
|
265
|
-
if (this.userOrdersExist) {
|
|
266
|
-
return this.userOrdersExist;
|
|
267
|
-
}
|
|
268
|
-
const userOrdersAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getUserOrdersAccountPublicKey());
|
|
269
|
-
this.userOrdersExist = userOrdersAccountRPCResponse.value !== null;
|
|
270
|
-
return this.userOrdersExist;
|
|
271
|
-
}
|
|
272
|
-
async depositCollateral(amount, collateralAccountPublicKey, userPositionsAccountPublicKey) {
|
|
273
|
-
const depositCollateralIx = await this.getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccountPublicKey);
|
|
274
|
-
const tx = new web3_js_1.Transaction().add(depositCollateralIx);
|
|
275
|
-
return await this.txSender.send(tx);
|
|
276
|
-
}
|
|
277
|
-
async getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccountPublicKey) {
|
|
278
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
279
|
-
if (!userPositionsAccountPublicKey) {
|
|
280
|
-
userPositionsAccountPublicKey = (await this.getUserAccount()).positions;
|
|
281
|
-
}
|
|
282
|
-
const state = this.getStateAccount();
|
|
283
|
-
return await this.program.instruction.depositCollateral(amount, {
|
|
284
|
-
accounts: {
|
|
285
|
-
state: await this.getStatePublicKey(),
|
|
286
|
-
user: userAccountPublicKey,
|
|
287
|
-
collateralVault: state.collateralVault,
|
|
288
|
-
userCollateralAccount: collateralAccountPublicKey,
|
|
289
|
-
authority: this.wallet.publicKey,
|
|
290
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
291
|
-
markets: state.markets,
|
|
292
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
293
|
-
depositHistory: state.depositHistory,
|
|
294
|
-
userPositions: userPositionsAccountPublicKey,
|
|
295
|
-
},
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Creates the Clearing House User account for a user, and deposits some initial collateral
|
|
300
|
-
* @param amount
|
|
301
|
-
* @param collateralAccountPublicKey
|
|
302
|
-
* @returns
|
|
303
|
-
*/
|
|
304
|
-
async initializeUserAccountAndDepositCollateral(amount, collateralAccountPublicKey) {
|
|
305
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx, initializeUserOrdersAccountIx,] = await this.getInitializeUserInstructions();
|
|
306
|
-
const depositCollateralIx = await this.getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccount.publicKey);
|
|
307
|
-
const tx = new web3_js_1.Transaction()
|
|
308
|
-
.add(initializeUserAccountIx)
|
|
309
|
-
.add(initializeUserOrdersAccountIx)
|
|
310
|
-
.add(depositCollateralIx);
|
|
311
|
-
const txSig = await this.program.provider.send(tx, [userPositionsAccount]);
|
|
312
|
-
return [txSig, userAccountPublicKey];
|
|
313
|
-
}
|
|
314
|
-
async initializeUserAccountForDevnet(mockUSDCFaucet, amount) {
|
|
315
|
-
const [associateTokenPublicKey, createAssociatedAccountIx, mintToIx] = await mockUSDCFaucet.createAssociatedTokenAccountAndMintToInstructions(this.wallet.publicKey, amount);
|
|
316
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx, initializeUserOrdersAccountIx,] = await this.getInitializeUserInstructions();
|
|
317
|
-
const depositCollateralIx = await this.getDepositCollateralInstruction(amount, associateTokenPublicKey, userPositionsAccount.publicKey);
|
|
318
|
-
const tx = new web3_js_1.Transaction()
|
|
319
|
-
.add(createAssociatedAccountIx)
|
|
320
|
-
.add(mintToIx)
|
|
321
|
-
.add(initializeUserAccountIx)
|
|
322
|
-
.add(initializeUserOrdersAccountIx)
|
|
323
|
-
.add(depositCollateralIx);
|
|
324
|
-
const txSig = await this.program.provider.send(tx, [userPositionsAccount]);
|
|
325
|
-
return [txSig, userAccountPublicKey];
|
|
326
|
-
}
|
|
327
|
-
async deleteUser() {
|
|
328
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
329
|
-
const user = await this.program.account.user.fetch(userAccountPublicKey);
|
|
330
|
-
const deleteUserTx = await this.program.transaction.deleteUser({
|
|
331
|
-
accounts: {
|
|
332
|
-
user: userAccountPublicKey,
|
|
333
|
-
userPositions: user.positions,
|
|
334
|
-
authority: this.wallet.publicKey,
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
return this.txSender.send(deleteUserTx, [], this.opts);
|
|
338
|
-
}
|
|
339
|
-
async withdrawCollateral(amount, collateralAccountPublicKey) {
|
|
340
|
-
return this.txSender.send((0, utils_1.wrapInTx)(await this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
|
|
341
|
-
}
|
|
342
|
-
async getWithdrawCollateralIx(amount, collateralAccountPublicKey) {
|
|
343
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
344
|
-
const user = await this.program.account.user.fetch(userAccountPublicKey);
|
|
345
|
-
const state = this.getStateAccount();
|
|
346
|
-
return await this.program.instruction.withdrawCollateral(amount, {
|
|
347
|
-
accounts: {
|
|
348
|
-
state: await this.getStatePublicKey(),
|
|
349
|
-
user: userAccountPublicKey,
|
|
350
|
-
collateralVault: state.collateralVault,
|
|
351
|
-
collateralVaultAuthority: state.collateralVaultAuthority,
|
|
352
|
-
insuranceVault: state.insuranceVault,
|
|
353
|
-
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
354
|
-
userCollateralAccount: collateralAccountPublicKey,
|
|
355
|
-
authority: this.wallet.publicKey,
|
|
356
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
357
|
-
markets: state.markets,
|
|
358
|
-
userPositions: user.positions,
|
|
359
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
360
|
-
depositHistory: state.depositHistory,
|
|
361
|
-
},
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
async openPosition(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
|
|
365
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
|
|
366
|
-
}
|
|
367
|
-
async getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
|
|
368
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
369
|
-
const userAccount = await this.getUserAccount();
|
|
370
|
-
if (limitPrice == undefined) {
|
|
371
|
-
limitPrice = new anchor_1.BN(0); // no limit
|
|
372
|
-
}
|
|
373
|
-
const optionalAccounts = {
|
|
374
|
-
discountToken: false,
|
|
375
|
-
referrer: false,
|
|
376
|
-
};
|
|
377
|
-
const remainingAccounts = [];
|
|
378
|
-
if (discountToken) {
|
|
379
|
-
optionalAccounts.discountToken = true;
|
|
380
|
-
remainingAccounts.push({
|
|
381
|
-
pubkey: discountToken,
|
|
382
|
-
isWritable: false,
|
|
383
|
-
isSigner: false,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
if (referrer) {
|
|
387
|
-
optionalAccounts.referrer = true;
|
|
388
|
-
remainingAccounts.push({
|
|
389
|
-
pubkey: referrer,
|
|
390
|
-
isWritable: true,
|
|
391
|
-
isSigner: false,
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
const priceOracle = this.getMarketsAccount().markets[marketIndex.toNumber()].amm.oracle;
|
|
395
|
-
const state = this.getStateAccount();
|
|
396
|
-
return await this.program.instruction.openPosition(direction, amount, marketIndex, limitPrice, optionalAccounts, {
|
|
397
|
-
accounts: {
|
|
398
|
-
state: await this.getStatePublicKey(),
|
|
399
|
-
user: userAccountPublicKey,
|
|
400
|
-
authority: this.wallet.publicKey,
|
|
401
|
-
markets: state.markets,
|
|
402
|
-
userPositions: userAccount.positions,
|
|
403
|
-
tradeHistory: state.tradeHistory,
|
|
404
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
405
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
406
|
-
oracle: priceOracle,
|
|
407
|
-
},
|
|
408
|
-
remainingAccounts: remainingAccounts,
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
async initializeUserOrdersThenPlaceOrder(orderParams, discountToken, referrer) {
|
|
412
|
-
const instructions = [];
|
|
413
|
-
const userOrdersAccountExists = await this.userOrdersAccountExists();
|
|
414
|
-
if (!userOrdersAccountExists) {
|
|
415
|
-
instructions.push(await this.getInitializeUserOrdersInstruction());
|
|
416
|
-
}
|
|
417
|
-
instructions.push(await this.getPlaceOrderIx(orderParams, discountToken, referrer));
|
|
418
|
-
const tx = new web3_js_1.Transaction();
|
|
419
|
-
for (const instruction of instructions) {
|
|
420
|
-
tx.add(instruction);
|
|
421
|
-
}
|
|
422
|
-
return await this.txSender.send(tx, [], this.opts);
|
|
423
|
-
}
|
|
424
|
-
async placeOrder(orderParams, discountToken, referrer) {
|
|
425
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceOrderIx(orderParams, discountToken, referrer)), [], this.opts);
|
|
426
|
-
}
|
|
427
|
-
async getPlaceOrderIx(orderParams, discountToken, referrer) {
|
|
428
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
429
|
-
const userAccount = await this.getUserAccount();
|
|
430
|
-
const priceOracle = this.getMarketsAccount().markets[orderParams.marketIndex.toNumber()].amm
|
|
431
|
-
.oracle;
|
|
432
|
-
const remainingAccounts = [];
|
|
433
|
-
if (orderParams.optionalAccounts.discountToken) {
|
|
434
|
-
if (!discountToken) {
|
|
435
|
-
throw Error('Optional accounts specified discount token but no discount token present');
|
|
436
|
-
}
|
|
437
|
-
remainingAccounts.push({
|
|
438
|
-
pubkey: discountToken,
|
|
439
|
-
isWritable: false,
|
|
440
|
-
isSigner: false,
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if (orderParams.optionalAccounts.referrer) {
|
|
444
|
-
if (!referrer) {
|
|
445
|
-
throw Error('Optional accounts specified referrer but no referrer present');
|
|
446
|
-
}
|
|
447
|
-
remainingAccounts.push({
|
|
448
|
-
pubkey: referrer,
|
|
449
|
-
isWritable: false,
|
|
450
|
-
isSigner: false,
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
if (!orderParams.oraclePriceOffset.eq(numericConstants_1.ZERO)) {
|
|
454
|
-
remainingAccounts.push({
|
|
455
|
-
pubkey: priceOracle,
|
|
456
|
-
isWritable: false,
|
|
457
|
-
isSigner: false,
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
const state = this.getStateAccount();
|
|
461
|
-
const orderState = this.getOrderStateAccount();
|
|
462
|
-
return await this.program.instruction.placeOrder(orderParams, {
|
|
463
|
-
accounts: {
|
|
464
|
-
state: await this.getStatePublicKey(),
|
|
465
|
-
user: userAccountPublicKey,
|
|
466
|
-
authority: this.wallet.publicKey,
|
|
467
|
-
markets: state.markets,
|
|
468
|
-
userOrders: await this.getUserOrdersAccountPublicKey(),
|
|
469
|
-
userPositions: userAccount.positions,
|
|
470
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
471
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
472
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
473
|
-
orderHistory: orderState.orderHistory,
|
|
474
|
-
},
|
|
475
|
-
remainingAccounts,
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
async cancelOrder(orderId, oracle) {
|
|
479
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelOrderIx(orderId, oracle)), [], this.opts);
|
|
480
|
-
}
|
|
481
|
-
async getCancelOrderIx(orderId, oracle) {
|
|
482
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
483
|
-
const userAccount = await this.getUserAccount();
|
|
484
|
-
const state = this.getStateAccount();
|
|
485
|
-
const orderState = this.getOrderStateAccount();
|
|
486
|
-
const remainingAccounts = [];
|
|
487
|
-
if (oracle) {
|
|
488
|
-
remainingAccounts.push({
|
|
489
|
-
pubkey: oracle,
|
|
490
|
-
isWritable: false,
|
|
491
|
-
isSigner: false,
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return await this.program.instruction.cancelOrder(orderId, {
|
|
495
|
-
accounts: {
|
|
496
|
-
state: await this.getStatePublicKey(),
|
|
497
|
-
user: userAccountPublicKey,
|
|
498
|
-
authority: this.wallet.publicKey,
|
|
499
|
-
markets: state.markets,
|
|
500
|
-
userOrders: await this.getUserOrdersAccountPublicKey(),
|
|
501
|
-
userPositions: userAccount.positions,
|
|
502
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
503
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
504
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
505
|
-
orderHistory: orderState.orderHistory,
|
|
506
|
-
},
|
|
507
|
-
remainingAccounts,
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
async cancelOrderByUserId(userOrderId, oracle) {
|
|
511
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getCancelOrderByUserIdIx(userOrderId, oracle)), [], this.opts);
|
|
512
|
-
}
|
|
513
|
-
async getCancelOrderByUserIdIx(userOrderId, oracle) {
|
|
514
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
515
|
-
const userAccount = await this.getUserAccount();
|
|
516
|
-
const state = this.getStateAccount();
|
|
517
|
-
const orderState = this.getOrderStateAccount();
|
|
518
|
-
const remainingAccounts = [];
|
|
519
|
-
if (oracle) {
|
|
520
|
-
remainingAccounts.push({
|
|
521
|
-
pubkey: oracle,
|
|
522
|
-
isWritable: false,
|
|
523
|
-
isSigner: false,
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return await this.program.instruction.cancelOrderByUserId(userOrderId, {
|
|
527
|
-
accounts: {
|
|
528
|
-
state: await this.getStatePublicKey(),
|
|
529
|
-
user: userAccountPublicKey,
|
|
530
|
-
authority: this.wallet.publicKey,
|
|
531
|
-
markets: state.markets,
|
|
532
|
-
userOrders: await this.getUserOrdersAccountPublicKey(),
|
|
533
|
-
userPositions: userAccount.positions,
|
|
534
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
535
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
536
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
537
|
-
orderHistory: orderState.orderHistory,
|
|
538
|
-
},
|
|
539
|
-
remainingAccounts,
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
async fillOrder(userAccountPublicKey, userOrdersAccountPublicKey, order) {
|
|
543
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
|
|
544
|
-
}
|
|
545
|
-
async getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order) {
|
|
546
|
-
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
547
|
-
const userAccount = await this.program.account.user.fetch(userAccountPublicKey);
|
|
548
|
-
const marketIndex = order.marketIndex;
|
|
549
|
-
const oracle = this.getMarket(marketIndex).amm.oracle;
|
|
550
|
-
const state = this.getStateAccount();
|
|
551
|
-
const orderState = this.getOrderStateAccount();
|
|
552
|
-
const remainingAccounts = [];
|
|
553
|
-
if (!order.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
554
|
-
remainingAccounts.push({
|
|
555
|
-
pubkey: order.referrer,
|
|
556
|
-
isWritable: true,
|
|
557
|
-
isSigner: false,
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
const orderId = order.orderId;
|
|
561
|
-
return await this.program.instruction.fillOrder(orderId, {
|
|
562
|
-
accounts: {
|
|
563
|
-
state: await this.getStatePublicKey(),
|
|
564
|
-
filler: fillerPublicKey,
|
|
565
|
-
user: userAccountPublicKey,
|
|
566
|
-
authority: this.wallet.publicKey,
|
|
567
|
-
markets: state.markets,
|
|
568
|
-
userPositions: userAccount.positions,
|
|
569
|
-
userOrders: userOrdersAccountPublicKey,
|
|
570
|
-
tradeHistory: state.tradeHistory,
|
|
571
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
572
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
573
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
574
|
-
orderHistory: orderState.orderHistory,
|
|
575
|
-
extendedCurveHistory: state.extendedCurveHistory,
|
|
576
|
-
oracle: oracle,
|
|
577
|
-
},
|
|
578
|
-
remainingAccounts,
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
async initializeUserOrdersThenPlaceAndFillOrder(orderParams, discountToken, referrer) {
|
|
582
|
-
const instructions = [];
|
|
583
|
-
const userOrdersAccountExists = await this.userOrdersAccountExists();
|
|
584
|
-
if (!userOrdersAccountExists) {
|
|
585
|
-
instructions.push(await this.getInitializeUserOrdersInstruction());
|
|
586
|
-
}
|
|
587
|
-
instructions.push(await this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer));
|
|
588
|
-
const tx = new web3_js_1.Transaction();
|
|
589
|
-
for (const instruction of instructions) {
|
|
590
|
-
tx.add(instruction);
|
|
591
|
-
}
|
|
592
|
-
return await this.txSender.send(tx, [], this.opts);
|
|
593
|
-
}
|
|
594
|
-
async placeAndFillOrder(orderParams, discountToken, referrer) {
|
|
595
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer)), [], this.opts);
|
|
596
|
-
}
|
|
597
|
-
async getPlaceAndFillOrderIx(orderParams, discountToken, referrer) {
|
|
598
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
599
|
-
const userAccount = await this.getUserAccount();
|
|
600
|
-
const priceOracle = this.getMarketsAccount().markets[orderParams.marketIndex.toNumber()].amm
|
|
601
|
-
.oracle;
|
|
602
|
-
const remainingAccounts = [];
|
|
603
|
-
if (orderParams.optionalAccounts.discountToken) {
|
|
604
|
-
if (!discountToken) {
|
|
605
|
-
throw Error('Optional accounts specified discount token but no discount token present');
|
|
606
|
-
}
|
|
607
|
-
remainingAccounts.push({
|
|
608
|
-
pubkey: discountToken,
|
|
609
|
-
isWritable: false,
|
|
610
|
-
isSigner: false,
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
if (orderParams.optionalAccounts.referrer) {
|
|
614
|
-
if (!referrer) {
|
|
615
|
-
throw Error('Optional accounts specified referrer but no referrer present');
|
|
616
|
-
}
|
|
617
|
-
remainingAccounts.push({
|
|
618
|
-
pubkey: referrer,
|
|
619
|
-
isWritable: true,
|
|
620
|
-
isSigner: false,
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
const state = this.getStateAccount();
|
|
624
|
-
const orderState = this.getOrderStateAccount();
|
|
625
|
-
return await this.program.instruction.placeAndFillOrder(orderParams, {
|
|
626
|
-
accounts: {
|
|
627
|
-
state: await this.getStatePublicKey(),
|
|
628
|
-
user: userAccountPublicKey,
|
|
629
|
-
authority: this.wallet.publicKey,
|
|
630
|
-
markets: state.markets,
|
|
631
|
-
userOrders: await this.getUserOrdersAccountPublicKey(),
|
|
632
|
-
userPositions: userAccount.positions,
|
|
633
|
-
tradeHistory: state.tradeHistory,
|
|
634
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
635
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
636
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
637
|
-
orderHistory: orderState.orderHistory,
|
|
638
|
-
extendedCurveHistory: state.extendedCurveHistory,
|
|
639
|
-
oracle: priceOracle,
|
|
640
|
-
},
|
|
641
|
-
remainingAccounts,
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
646
|
-
* @param marketIndex
|
|
647
|
-
* @param discountToken
|
|
648
|
-
* @param referrer
|
|
649
|
-
* @returns
|
|
650
|
-
*/
|
|
651
|
-
async closePosition(marketIndex, discountToken, referrer) {
|
|
652
|
-
return await this.txSender.send((0, utils_1.wrapInTx)(await this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
|
|
653
|
-
}
|
|
654
|
-
async getClosePositionIx(marketIndex, discountToken, referrer) {
|
|
655
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
656
|
-
const userAccount = await this.getUserAccount();
|
|
657
|
-
const priceOracle = this.getMarketsAccount().markets[marketIndex.toNumber()].amm.oracle;
|
|
658
|
-
const optionalAccounts = {
|
|
659
|
-
discountToken: false,
|
|
660
|
-
referrer: false,
|
|
661
|
-
};
|
|
662
|
-
const remainingAccounts = [];
|
|
663
|
-
if (discountToken) {
|
|
664
|
-
optionalAccounts.discountToken = true;
|
|
665
|
-
remainingAccounts.push({
|
|
666
|
-
pubkey: discountToken,
|
|
667
|
-
isWritable: false,
|
|
668
|
-
isSigner: false,
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
if (referrer) {
|
|
672
|
-
optionalAccounts.referrer = true;
|
|
673
|
-
remainingAccounts.push({
|
|
674
|
-
pubkey: referrer,
|
|
675
|
-
isWritable: true,
|
|
676
|
-
isSigner: false,
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
const state = this.getStateAccount();
|
|
680
|
-
return await this.program.instruction.closePosition(marketIndex, optionalAccounts, {
|
|
681
|
-
accounts: {
|
|
682
|
-
state: await this.getStatePublicKey(),
|
|
683
|
-
user: userAccountPublicKey,
|
|
684
|
-
authority: this.wallet.publicKey,
|
|
685
|
-
markets: state.markets,
|
|
686
|
-
userPositions: userAccount.positions,
|
|
687
|
-
tradeHistory: state.tradeHistory,
|
|
688
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
689
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
690
|
-
oracle: priceOracle,
|
|
691
|
-
},
|
|
692
|
-
remainingAccounts: remainingAccounts,
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
async liquidate(liquidateeUserAccountPublicKey) {
|
|
696
|
-
return this.txSender.send((0, utils_1.wrapInTx)(await this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
|
|
697
|
-
}
|
|
698
|
-
async getLiquidateIx(liquidateeUserAccountPublicKey) {
|
|
699
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
700
|
-
const liquidateeUserAccount = await this.program.account.user.fetch(liquidateeUserAccountPublicKey);
|
|
701
|
-
const liquidateePositions = await this.program.account.userPositions.fetch(liquidateeUserAccount.positions);
|
|
702
|
-
const markets = this.getMarketsAccount();
|
|
703
|
-
const remainingAccounts = [];
|
|
704
|
-
for (const position of liquidateePositions.positions) {
|
|
705
|
-
if (!position.baseAssetAmount.eq(new anchor_1.BN(0))) {
|
|
706
|
-
const market = markets.markets[position.marketIndex.toNumber()];
|
|
707
|
-
remainingAccounts.push({
|
|
708
|
-
pubkey: market.amm.oracle,
|
|
709
|
-
isWritable: false,
|
|
710
|
-
isSigner: false,
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const state = this.getStateAccount();
|
|
715
|
-
return await this.program.instruction.liquidate({
|
|
716
|
-
accounts: {
|
|
717
|
-
state: await this.getStatePublicKey(),
|
|
718
|
-
authority: this.wallet.publicKey,
|
|
719
|
-
user: liquidateeUserAccountPublicKey,
|
|
720
|
-
liquidator: userAccountPublicKey,
|
|
721
|
-
collateralVault: state.collateralVault,
|
|
722
|
-
collateralVaultAuthority: state.collateralVaultAuthority,
|
|
723
|
-
insuranceVault: state.insuranceVault,
|
|
724
|
-
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
725
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
726
|
-
markets: state.markets,
|
|
727
|
-
userPositions: liquidateeUserAccount.positions,
|
|
728
|
-
tradeHistory: state.tradeHistory,
|
|
729
|
-
liquidationHistory: state.liquidationHistory,
|
|
730
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
731
|
-
},
|
|
732
|
-
remainingAccounts: remainingAccounts,
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
async updateFundingRate(oracle, marketIndex) {
|
|
736
|
-
return this.txSender.send((0, utils_1.wrapInTx)(await this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
|
|
737
|
-
}
|
|
738
|
-
async getUpdateFundingRateIx(oracle, marketIndex) {
|
|
739
|
-
const state = this.getStateAccount();
|
|
740
|
-
return await this.program.instruction.updateFundingRate(marketIndex, {
|
|
741
|
-
accounts: {
|
|
742
|
-
state: await this.getStatePublicKey(),
|
|
743
|
-
markets: state.markets,
|
|
744
|
-
oracle: oracle,
|
|
745
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
746
|
-
},
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
async settleFundingPayment(userAccount, userPositionsAccount) {
|
|
750
|
-
return this.txSender.send((0, utils_1.wrapInTx)(await this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
|
|
751
|
-
}
|
|
752
|
-
async getSettleFundingPaymentIx(userAccount, userPositionsAccount) {
|
|
753
|
-
const state = this.getStateAccount();
|
|
754
|
-
return await this.program.instruction.settleFundingPayment({
|
|
755
|
-
accounts: {
|
|
756
|
-
state: await this.getStatePublicKey(),
|
|
757
|
-
markets: state.markets,
|
|
758
|
-
user: userAccount,
|
|
759
|
-
userPositions: userPositionsAccount,
|
|
760
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
761
|
-
},
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
triggerEvent(eventName, data) {
|
|
765
|
-
this.eventEmitter.emit(eventName, data);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
exports.ClearingHouse = ClearingHouse;
|
|
769
|
-
//# sourceMappingURL=clearingHouse.js.map
|