@drift-labs/sdk 0.1.18-orders.1 → 0.1.19-master.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts +4 -7
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/defaultClearingHouseAccountSubscriber.js +2 -27
- package/lib/accounts/defaultUserAccountSubscriber.d.ts +2 -3
- package/lib/accounts/defaultUserAccountSubscriber.d.ts.map +1 -0
- package/lib/accounts/defaultUserAccountSubscriber.js +5 -14
- package/lib/accounts/types.d.ts +6 -32
- package/lib/accounts/types.d.ts.map +1 -0
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketAccountSubscriber.d.ts.map +1 -0
- package/lib/addresses.d.ts +1 -4
- package/lib/addresses.d.ts.map +1 -0
- package/lib/addresses.js +1 -28
- package/lib/admin.d.ts +7 -10
- package/lib/admin.d.ts.map +1 -0
- package/lib/admin.js +64 -53
- package/lib/assert/assert.d.ts +1 -0
- package/lib/assert/assert.d.ts.map +1 -0
- package/lib/clearingHouse.d.ts +3 -22
- package/lib/clearingHouse.d.ts.map +1 -0
- package/lib/clearingHouse.js +15 -246
- package/lib/clearingHouseUser.d.ts +17 -10
- package/lib/clearingHouseUser.d.ts.map +1 -0
- package/lib/clearingHouseUser.js +97 -111
- package/lib/config.d.ts +1 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +1 -1
- package/lib/constants/markets.d.ts +1 -0
- package/lib/constants/markets.d.ts.map +1 -0
- package/lib/constants/markets.js +16 -0
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.d.ts.map +1 -0
- package/lib/examples/makeTradeExample.d.ts +1 -0
- package/lib/examples/makeTradeExample.d.ts.map +1 -0
- package/lib/examples/makeTradeExample.js +6 -6
- package/lib/idl/clearing_house.json +233 -911
- package/lib/index.d.ts +1 -4
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +0 -4
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.d.ts.map +1 -0
- package/lib/math/amm.js +15 -38
- package/lib/math/conversion.d.ts +1 -0
- package/lib/math/conversion.d.ts.map +1 -0
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.d.ts +1 -0
- package/lib/math/funding.d.ts.map +1 -0
- package/lib/math/funding.js +5 -2
- package/lib/math/insuranceFund.d.ts +1 -0
- package/lib/math/insuranceFund.d.ts.map +1 -0
- package/lib/math/market.d.ts +2 -2
- package/lib/math/market.d.ts.map +1 -0
- package/lib/math/market.js +2 -12
- package/lib/math/position.d.ts +2 -4
- package/lib/math/position.d.ts.map +1 -0
- package/lib/math/position.js +5 -19
- package/lib/math/trade.d.ts +1 -0
- package/lib/math/trade.d.ts.map +1 -0
- package/lib/math/trade.js +16 -16
- package/lib/math/utils.d.ts +1 -0
- package/lib/math/utils.d.ts.map +1 -0
- package/lib/mockUSDCFaucet.d.ts +1 -0
- package/lib/mockUSDCFaucet.d.ts.map +1 -0
- package/lib/pythClient.d.ts +1 -0
- package/lib/pythClient.d.ts.map +1 -0
- package/lib/pythClient.js +1 -1
- package/lib/tx/defaultTxSender.d.ts +1 -0
- package/lib/tx/defaultTxSender.d.ts.map +1 -0
- package/lib/tx/types.d.ts +1 -0
- package/lib/tx/types.d.ts.map +1 -0
- package/lib/tx/utils.d.ts +1 -0
- package/lib/tx/utils.d.ts.map +1 -0
- package/lib/types.d.ts +9 -140
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -36
- package/lib/util/computeUnits.d.ts +1 -0
- package/lib/util/computeUnits.d.ts.map +1 -0
- package/lib/util/tps.d.ts +1 -0
- package/lib/util/tps.d.ts.map +1 -0
- package/lib/wallet.d.ts +1 -0
- package/lib/wallet.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/accounts/defaultClearingHouseAccountSubscriber.ts +5 -52
- package/src/accounts/defaultUserAccountSubscriber.ts +6 -31
- package/src/accounts/types.ts +5 -42
- package/src/addresses.ts +0 -35
- package/src/admin.ts +71 -86
- package/src/clearingHouse.ts +7 -340
- package/src/clearingHouseUser.ts +102 -154
- package/src/config.ts +1 -1
- package/src/constants/markets.ts +16 -0
- package/src/idl/clearing_house.json +233 -911
- package/src/index.ts +0 -4
- package/src/math/amm.ts +14 -47
- package/src/math/funding.ts +5 -1
- package/src/math/market.ts +2 -28
- package/src/math/position.ts +3 -23
- package/src/types.ts +8 -124
- package/tsconfig.json +1 -0
- package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +0 -28
- package/lib/accounts/defaultHistoryAccountSubscriber.js +0 -110
- package/lib/math/orders.d.ts +0 -3
- package/lib/math/orders.js +0 -30
- package/lib/orderParams.d.ts +0 -7
- package/lib/orderParams.js +0 -88
- package/lib/orders.d.ts +0 -5
- package/lib/orders.js +0 -136
- package/src/accounts/defaultHistoryAccountSubscriber.ts +0 -176
- package/src/math/orders.ts +0 -39
- package/src/orderParams.ts +0 -128
- package/src/orders.ts +0 -230
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
import { BN, Program, Provider } from '@project-serum/anchor';
|
|
4
|
-
import { MarketsAccount, StateAccount,
|
|
4
|
+
import { MarketsAccount, StateAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, ExtendedCurveHistoryAccount } from './types';
|
|
5
5
|
import { Connection, PublicKey, TransactionSignature, Keypair, ConfirmOptions, TransactionInstruction } from '@solana/web3.js';
|
|
6
6
|
import { MockUSDCFaucet } from './mockUSDCFaucet';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
@@ -56,11 +56,7 @@ export declare class ClearingHouse {
|
|
|
56
56
|
getTradeHistoryAccount(): TradeHistoryAccount;
|
|
57
57
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
58
58
|
getDepositHistoryAccount(): DepositHistoryAccount;
|
|
59
|
-
getCurveHistoryAccount():
|
|
60
|
-
getOrderHistoryAccount(): OrderHistoryAccount;
|
|
61
|
-
orderStatePublicKey?: PublicKey;
|
|
62
|
-
getOrderStatePublicKey(): Promise<PublicKey>;
|
|
63
|
-
getOrderStateAccount(): OrderStateAccount;
|
|
59
|
+
getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
|
|
64
60
|
/**
|
|
65
61
|
* Update the wallet to use for clearing house transactions and linked user account
|
|
66
62
|
* @param newWallet
|
|
@@ -73,10 +69,8 @@ export declare class ClearingHouse {
|
|
|
73
69
|
getInitializeUserInstructions(): Promise<[
|
|
74
70
|
Keypair,
|
|
75
71
|
PublicKey,
|
|
76
|
-
TransactionInstruction,
|
|
77
72
|
TransactionInstruction
|
|
78
73
|
]>;
|
|
79
|
-
getInitializeUserOrdersInstruction(userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
80
74
|
userAccountPublicKey?: PublicKey;
|
|
81
75
|
/**
|
|
82
76
|
* Get the address for the Clearing House User's account. NOT the user's wallet address.
|
|
@@ -85,12 +79,6 @@ export declare class ClearingHouse {
|
|
|
85
79
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
86
80
|
userAccount?: UserAccount;
|
|
87
81
|
getUserAccount(): Promise<UserAccount>;
|
|
88
|
-
userOrdersAccountPublicKey?: PublicKey;
|
|
89
|
-
/**
|
|
90
|
-
* Get the address for the Clearing House User Order's account. NOT the user's wallet address.
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
getUserOrdersAccountPublicKey(): Promise<PublicKey>;
|
|
94
82
|
depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
95
83
|
getDepositCollateralInstruction(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
96
84
|
/**
|
|
@@ -106,14 +94,6 @@ export declare class ClearingHouse {
|
|
|
106
94
|
getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
107
95
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
108
96
|
getOpenPositionIx(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
109
|
-
placeOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
110
|
-
getPlaceOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
111
|
-
cancelOrder(orderId: BN): Promise<TransactionSignature>;
|
|
112
|
-
getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
|
|
113
|
-
fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
|
|
114
|
-
getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
|
|
115
|
-
placeAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
116
|
-
getPlaceAndFillOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
117
97
|
/**
|
|
118
98
|
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
119
99
|
* @param marketIndex
|
|
@@ -131,3 +111,4 @@ export declare class ClearingHouse {
|
|
|
131
111
|
getSettleFundingPaymentIx(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionInstruction>;
|
|
132
112
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
133
113
|
}
|
|
114
|
+
//# sourceMappingURL=clearingHouse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clearingHouse.d.ts","sourceRoot":"","sources":["../src/clearingHouse.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,EAAE,EAAO,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMnE,OAAO,EACN,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,yBAAyB,EACzB,OAAO,EACP,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,MAAM,EACN,2BAA2B,EAC3B,MAAM,SAAS,CAAC;AAIjB,OAAO,EACN,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,OAAO,EACP,cAAc,EAEd,sBAAsB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAM5D,OAAO,EACN,8BAA8B,EAC9B,0BAA0B,EAC1B,yBAAyB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC;;;;;;GAMG;AACH,qBAAa,aAAa;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,iBAAiB,EAAE,8BAA8B,CAAC;IAClD,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC;IAC3E,YAAY,UAAS;IACrB,QAAQ,EAAE,QAAQ,CAAC;WAEL,IAAI,CACjB,UAAU,E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C,sBAAsB,CAAC;IAyDlC;;;;;;OAMG;IACU,aAAa,CACzB,WAAW,EAAE,EAAE,EACf,aAAa,CAAC,EAAE,SAAS,EACzB,QAAQ,CAAC,EAAE,SAAS,GAClB,OAAO,CAAC,oBAAoB,CAAC;IAUnB,kBAAkB,CAC9B,WAAW,EAAE,EAAE,EACf,aAAa,CAAC,EAAE,SAAS,EACzB,QAAQ,CAAC,EAAE,SAAS,GAClB,OAAO,CAAC,sBAAsB,CAAC;IAkDrB,SAAS,CACrB,8BAA8B,EAAE,SAAS,GACvC,OAAO,CAAC,oBAAoB,CAAC;IAQnB,cAAc,CAC1B,8BAA8B,EAAE,SAAS,GACvC,OAAO,CAAC,sBAAsB,CAAC;IA8CrB,iBAAiB,CAC7B,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,EAAE,GACb,OAAO,CAAC,oBAAoB,CAAC;IAQnB,sBAAsB,CAClC,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,EAAE,GACb,OAAO,CAAC,sBAAsB,CAAC;IAYrB,oBAAoB,CAChC,WAAW,EAAE,SAAS,EACtB,oBAAoB,EAAE,SAAS,GAC7B,OAAO,CAAC,oBAAoB,CAAC;IAUnB,yBAAyB,CACrC,WAAW,EAAE,SAAS,EACtB,oBAAoB,EAAE,SAAS,GAC7B,OAAO,CAAC,sBAAsB,CAAC;IAa3B,YAAY,CAAC,SAAS,EAAE,MAAM,0BAA0B,EAAE,IAAI,CAAC,EAAE,GAAG;CAG3E"}
|
package/lib/clearingHouse.js
CHANGED
|
@@ -90,7 +90,6 @@ class ClearingHouse {
|
|
|
90
90
|
'fundingRateHistoryAccount',
|
|
91
91
|
'liquidationHistoryAccount',
|
|
92
92
|
'tradeHistoryAccount',
|
|
93
|
-
'orderHistoryAccount',
|
|
94
93
|
]);
|
|
95
94
|
});
|
|
96
95
|
}
|
|
@@ -116,7 +115,7 @@ class ClearingHouse {
|
|
|
116
115
|
if (this.statePublicKey) {
|
|
117
116
|
return this.statePublicKey;
|
|
118
117
|
}
|
|
119
|
-
this.statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
|
|
118
|
+
this.statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
|
|
120
119
|
return this.statePublicKey;
|
|
121
120
|
});
|
|
122
121
|
}
|
|
@@ -150,21 +149,6 @@ class ClearingHouse {
|
|
|
150
149
|
getCurveHistoryAccount() {
|
|
151
150
|
return this.accountSubscriber.getCurveHistoryAccount();
|
|
152
151
|
}
|
|
153
|
-
getOrderHistoryAccount() {
|
|
154
|
-
return this.accountSubscriber.getOrderHistoryAccount();
|
|
155
|
-
}
|
|
156
|
-
getOrderStatePublicKey() {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
if (this.orderStatePublicKey) {
|
|
159
|
-
return this.orderStatePublicKey;
|
|
160
|
-
}
|
|
161
|
-
this.orderStatePublicKey = yield addresses_1.getOrderStateAccountPublicKey(this.program.programId);
|
|
162
|
-
return this.orderStatePublicKey;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
getOrderStateAccount() {
|
|
166
|
-
return this.accountSubscriber.getOrderStateAccount();
|
|
167
|
-
}
|
|
168
152
|
/**
|
|
169
153
|
* Update the wallet to use for clearing house transactions and linked user account
|
|
170
154
|
* @param newWallet
|
|
@@ -182,17 +166,15 @@ class ClearingHouse {
|
|
|
182
166
|
}
|
|
183
167
|
initializeUserAccount() {
|
|
184
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,
|
|
186
|
-
const tx = new web3_js_1.Transaction()
|
|
187
|
-
.add(initializeUserAccountIx)
|
|
188
|
-
.add(initializeUserOrdersAccountIx);
|
|
169
|
+
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,] = yield this.getInitializeUserInstructions();
|
|
170
|
+
const tx = new web3_js_1.Transaction().add(initializeUserAccountIx);
|
|
189
171
|
const txSig = yield this.txSender.send(tx, [userPositionsAccount], this.opts);
|
|
190
172
|
return [txSig, userAccountPublicKey];
|
|
191
173
|
});
|
|
192
174
|
}
|
|
193
175
|
getInitializeUserInstructions() {
|
|
194
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
const [
|
|
177
|
+
const [userPublicKey, userAccountNonce] = yield (0, addresses_1.getUserAccountPublicKeyAndNonce)(this.program.programId, this.wallet.publicKey);
|
|
196
178
|
const remainingAccounts = [];
|
|
197
179
|
const optionalAccounts = {
|
|
198
180
|
whitelistToken: false,
|
|
@@ -210,7 +192,7 @@ class ClearingHouse {
|
|
|
210
192
|
const userPositions = new web3_js_1.Keypair();
|
|
211
193
|
const initializeUserAccountIx = yield this.program.instruction.initializeUser(userAccountNonce, optionalAccounts, {
|
|
212
194
|
accounts: {
|
|
213
|
-
user:
|
|
195
|
+
user: userPublicKey,
|
|
214
196
|
authority: this.wallet.publicKey,
|
|
215
197
|
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
216
198
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -219,31 +201,7 @@ class ClearingHouse {
|
|
|
219
201
|
},
|
|
220
202
|
remainingAccounts: remainingAccounts,
|
|
221
203
|
});
|
|
222
|
-
|
|
223
|
-
return [
|
|
224
|
-
userPositions,
|
|
225
|
-
userAccountPublicKey,
|
|
226
|
-
initializeUserAccountIx,
|
|
227
|
-
initializeUserOrdersAccountIx,
|
|
228
|
-
];
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
getInitializeUserOrdersInstruction(userAccountPublicKey) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, this.wallet.publicKey);
|
|
234
|
-
if (!userAccountPublicKey) {
|
|
235
|
-
userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
236
|
-
}
|
|
237
|
-
return yield this.program.instruction.initializeUserOrders(userOrdersAccountNonce, {
|
|
238
|
-
accounts: {
|
|
239
|
-
user: userAccountPublicKey,
|
|
240
|
-
authority: this.wallet.publicKey,
|
|
241
|
-
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
242
|
-
systemProgram: anchor.web3.SystemProgram.programId,
|
|
243
|
-
userOrders: userOrdersAccountPublicKey,
|
|
244
|
-
state: yield this.getStatePublicKey(),
|
|
245
|
-
},
|
|
246
|
-
});
|
|
204
|
+
return [userPositions, userPublicKey, initializeUserAccountIx];
|
|
247
205
|
});
|
|
248
206
|
}
|
|
249
207
|
/**
|
|
@@ -255,7 +213,7 @@ class ClearingHouse {
|
|
|
255
213
|
if (this.userAccountPublicKey) {
|
|
256
214
|
return this.userAccountPublicKey;
|
|
257
215
|
}
|
|
258
|
-
this.userAccountPublicKey = yield addresses_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey);
|
|
216
|
+
this.userAccountPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey);
|
|
259
217
|
return this.userAccountPublicKey;
|
|
260
218
|
});
|
|
261
219
|
}
|
|
@@ -268,19 +226,6 @@ class ClearingHouse {
|
|
|
268
226
|
return this.userAccount;
|
|
269
227
|
});
|
|
270
228
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Get the address for the Clearing House User Order's account. NOT the user's wallet address.
|
|
273
|
-
* @returns
|
|
274
|
-
*/
|
|
275
|
-
getUserOrdersAccountPublicKey() {
|
|
276
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
if (this.userOrdersAccountPublicKey) {
|
|
278
|
-
return this.userOrdersAccountPublicKey;
|
|
279
|
-
}
|
|
280
|
-
this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, this.wallet.publicKey);
|
|
281
|
-
return this.userOrdersAccountPublicKey;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
229
|
depositCollateral(amount, collateralAccountPublicKey, userPositionsAccountPublicKey) {
|
|
285
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
286
231
|
const depositCollateralIx = yield this.getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccountPublicKey);
|
|
@@ -319,11 +264,10 @@ class ClearingHouse {
|
|
|
319
264
|
*/
|
|
320
265
|
initializeUserAccountAndDepositCollateral(amount, collateralAccountPublicKey) {
|
|
321
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,
|
|
267
|
+
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,] = yield this.getInitializeUserInstructions();
|
|
323
268
|
const depositCollateralIx = yield this.getDepositCollateralInstruction(amount, collateralAccountPublicKey, userPositionsAccount.publicKey);
|
|
324
269
|
const tx = new web3_js_1.Transaction()
|
|
325
270
|
.add(initializeUserAccountIx)
|
|
326
|
-
.add(initializeUserOrdersAccountIx)
|
|
327
271
|
.add(depositCollateralIx);
|
|
328
272
|
const txSig = yield this.program.provider.send(tx, [userPositionsAccount]);
|
|
329
273
|
return [txSig, userAccountPublicKey];
|
|
@@ -332,13 +276,12 @@ class ClearingHouse {
|
|
|
332
276
|
initializeUserAccountForDevnet(mockUSDCFaucet, amount) {
|
|
333
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334
278
|
const [associateTokenPublicKey, createAssociatedAccountIx, mintToIx] = yield mockUSDCFaucet.createAssociatedTokenAccountAndMintToInstructions(this.wallet.publicKey, amount);
|
|
335
|
-
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,
|
|
279
|
+
const [userPositionsAccount, userAccountPublicKey, initializeUserAccountIx,] = yield this.getInitializeUserInstructions();
|
|
336
280
|
const depositCollateralIx = yield this.getDepositCollateralInstruction(amount, associateTokenPublicKey, userPositionsAccount.publicKey);
|
|
337
281
|
const tx = new web3_js_1.Transaction()
|
|
338
282
|
.add(createAssociatedAccountIx)
|
|
339
283
|
.add(mintToIx)
|
|
340
284
|
.add(initializeUserAccountIx)
|
|
341
|
-
.add(initializeUserOrdersAccountIx)
|
|
342
285
|
.add(depositCollateralIx);
|
|
343
286
|
const txSig = yield this.program.provider.send(tx, [userPositionsAccount]);
|
|
344
287
|
return [txSig, userAccountPublicKey];
|
|
@@ -360,7 +303,7 @@ class ClearingHouse {
|
|
|
360
303
|
}
|
|
361
304
|
withdrawCollateral(amount, collateralAccountPublicKey) {
|
|
362
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
return this.txSender.send(utils_1.wrapInTx(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
|
|
306
|
+
return this.txSender.send((0, utils_1.wrapInTx)(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
|
|
364
307
|
});
|
|
365
308
|
}
|
|
366
309
|
getWithdrawCollateralIx(amount, collateralAccountPublicKey) {
|
|
@@ -389,7 +332,7 @@ class ClearingHouse {
|
|
|
389
332
|
}
|
|
390
333
|
openPosition(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
|
|
391
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
392
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
|
|
335
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
|
|
393
336
|
});
|
|
394
337
|
}
|
|
395
338
|
getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
|
|
@@ -438,180 +381,6 @@ class ClearingHouse {
|
|
|
438
381
|
});
|
|
439
382
|
});
|
|
440
383
|
}
|
|
441
|
-
placeOrder(orderParams, discountToken, referrer) {
|
|
442
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceOrderIx(orderParams, discountToken, referrer)), [], this.opts);
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
getPlaceOrderIx(orderParams, discountToken, referrer) {
|
|
447
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
-
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
449
|
-
const userAccount = yield this.getUserAccount();
|
|
450
|
-
const priceOracle = this.getMarketsAccount().markets[orderParams.marketIndex.toNumber()].amm
|
|
451
|
-
.oracle;
|
|
452
|
-
const remainingAccounts = [];
|
|
453
|
-
if (orderParams.optionalAccounts.discountToken) {
|
|
454
|
-
if (!discountToken) {
|
|
455
|
-
throw Error('Optional accounts specified discount token but no discount token present');
|
|
456
|
-
}
|
|
457
|
-
remainingAccounts.push({
|
|
458
|
-
pubkey: discountToken,
|
|
459
|
-
isWritable: false,
|
|
460
|
-
isSigner: false,
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
if (orderParams.optionalAccounts.referrer) {
|
|
464
|
-
if (!referrer) {
|
|
465
|
-
throw Error('Optional accounts specified referrer but no referrer present');
|
|
466
|
-
}
|
|
467
|
-
remainingAccounts.push({
|
|
468
|
-
pubkey: referrer,
|
|
469
|
-
isWritable: false,
|
|
470
|
-
isSigner: false,
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
const state = this.getStateAccount();
|
|
474
|
-
const orderState = this.getOrderStateAccount();
|
|
475
|
-
return yield this.program.instruction.placeOrder(orderParams, {
|
|
476
|
-
accounts: {
|
|
477
|
-
state: yield this.getStatePublicKey(),
|
|
478
|
-
user: userAccountPublicKey,
|
|
479
|
-
authority: this.wallet.publicKey,
|
|
480
|
-
markets: state.markets,
|
|
481
|
-
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
482
|
-
userPositions: userAccount.positions,
|
|
483
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
484
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
485
|
-
orderState: yield this.getOrderStatePublicKey(),
|
|
486
|
-
orderHistory: orderState.orderHistory,
|
|
487
|
-
oracle: priceOracle,
|
|
488
|
-
},
|
|
489
|
-
remainingAccounts,
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
cancelOrder(orderId) {
|
|
494
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getCancelOrderIx(orderId)), [], this.opts);
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
getCancelOrderIx(orderId) {
|
|
499
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
500
|
-
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
501
|
-
const userAccount = yield this.getUserAccount();
|
|
502
|
-
const state = this.getStateAccount();
|
|
503
|
-
const orderState = this.getOrderStateAccount();
|
|
504
|
-
return yield this.program.instruction.cancelOrder(orderId, {
|
|
505
|
-
accounts: {
|
|
506
|
-
state: yield this.getStatePublicKey(),
|
|
507
|
-
user: userAccountPublicKey,
|
|
508
|
-
authority: this.wallet.publicKey,
|
|
509
|
-
markets: state.markets,
|
|
510
|
-
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
511
|
-
userPositions: userAccount.positions,
|
|
512
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
513
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
514
|
-
orderState: yield this.getOrderStatePublicKey(),
|
|
515
|
-
orderHistory: orderState.orderHistory,
|
|
516
|
-
},
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
fillOrder(userAccountPublicKey, userOrdersAccountPublicKey, order) {
|
|
521
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
522
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order) {
|
|
526
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
-
const fillerPublicKey = yield this.getUserAccountPublicKey();
|
|
528
|
-
const userAccount = yield this.program.account.user.fetch(userAccountPublicKey);
|
|
529
|
-
const marketIndex = order.marketIndex;
|
|
530
|
-
const oracle = this.getMarket(marketIndex).amm.oracle;
|
|
531
|
-
const state = this.getStateAccount();
|
|
532
|
-
const orderState = this.getOrderStateAccount();
|
|
533
|
-
const remainingAccounts = [];
|
|
534
|
-
if (!order.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
535
|
-
remainingAccounts.push({
|
|
536
|
-
pubkey: order.referrer,
|
|
537
|
-
isWritable: true,
|
|
538
|
-
isSigner: false,
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
const orderId = order.orderId;
|
|
542
|
-
return yield this.program.instruction.fillOrder(orderId, {
|
|
543
|
-
accounts: {
|
|
544
|
-
state: yield this.getStatePublicKey(),
|
|
545
|
-
filler: fillerPublicKey,
|
|
546
|
-
user: userAccountPublicKey,
|
|
547
|
-
authority: this.wallet.publicKey,
|
|
548
|
-
markets: state.markets,
|
|
549
|
-
userPositions: userAccount.positions,
|
|
550
|
-
userOrders: userOrdersAccountPublicKey,
|
|
551
|
-
tradeHistory: state.tradeHistory,
|
|
552
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
553
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
554
|
-
orderState: yield this.getOrderStatePublicKey(),
|
|
555
|
-
orderHistory: orderState.orderHistory,
|
|
556
|
-
oracle: oracle,
|
|
557
|
-
},
|
|
558
|
-
remainingAccounts,
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
placeAndFillOrder(orderParams, discountToken, referrer) {
|
|
563
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
564
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer)), [], this.opts);
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
getPlaceAndFillOrderIx(orderParams, discountToken, referrer) {
|
|
568
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
569
|
-
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
570
|
-
const userAccount = yield this.getUserAccount();
|
|
571
|
-
const priceOracle = this.getMarketsAccount().markets[orderParams.marketIndex.toNumber()].amm
|
|
572
|
-
.oracle;
|
|
573
|
-
const remainingAccounts = [];
|
|
574
|
-
if (orderParams.optionalAccounts.discountToken) {
|
|
575
|
-
if (!discountToken) {
|
|
576
|
-
throw Error('Optional accounts specified discount token but no discount token present');
|
|
577
|
-
}
|
|
578
|
-
remainingAccounts.push({
|
|
579
|
-
pubkey: discountToken,
|
|
580
|
-
isWritable: false,
|
|
581
|
-
isSigner: false,
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
if (orderParams.optionalAccounts.referrer) {
|
|
585
|
-
if (!referrer) {
|
|
586
|
-
throw Error('Optional accounts specified referrer but no referrer present');
|
|
587
|
-
}
|
|
588
|
-
remainingAccounts.push({
|
|
589
|
-
pubkey: referrer,
|
|
590
|
-
isWritable: true,
|
|
591
|
-
isSigner: false,
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
const state = this.getStateAccount();
|
|
595
|
-
const orderState = this.getOrderStateAccount();
|
|
596
|
-
return yield this.program.instruction.placeAndFillOrder(orderParams, {
|
|
597
|
-
accounts: {
|
|
598
|
-
state: yield this.getStatePublicKey(),
|
|
599
|
-
user: userAccountPublicKey,
|
|
600
|
-
authority: this.wallet.publicKey,
|
|
601
|
-
markets: state.markets,
|
|
602
|
-
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
603
|
-
userPositions: userAccount.positions,
|
|
604
|
-
tradeHistory: state.tradeHistory,
|
|
605
|
-
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
606
|
-
fundingRateHistory: state.fundingRateHistory,
|
|
607
|
-
orderState: yield this.getOrderStatePublicKey(),
|
|
608
|
-
orderHistory: orderState.orderHistory,
|
|
609
|
-
oracle: priceOracle,
|
|
610
|
-
},
|
|
611
|
-
remainingAccounts,
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
384
|
/**
|
|
616
385
|
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
617
386
|
* @param marketIndex
|
|
@@ -621,7 +390,7 @@ class ClearingHouse {
|
|
|
621
390
|
*/
|
|
622
391
|
closePosition(marketIndex, discountToken, referrer) {
|
|
623
392
|
return __awaiter(this, void 0, void 0, function* () {
|
|
624
|
-
return yield this.txSender.send(utils_1.wrapInTx(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
|
|
393
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
|
|
625
394
|
});
|
|
626
395
|
}
|
|
627
396
|
getClosePositionIx(marketIndex, discountToken, referrer) {
|
|
@@ -669,7 +438,7 @@ class ClearingHouse {
|
|
|
669
438
|
}
|
|
670
439
|
liquidate(liquidateeUserAccountPublicKey) {
|
|
671
440
|
return __awaiter(this, void 0, void 0, function* () {
|
|
672
|
-
return this.txSender.send(utils_1.wrapInTx(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
|
|
441
|
+
return this.txSender.send((0, utils_1.wrapInTx)(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
|
|
673
442
|
});
|
|
674
443
|
}
|
|
675
444
|
getLiquidateIx(liquidateeUserAccountPublicKey) {
|
|
@@ -713,7 +482,7 @@ class ClearingHouse {
|
|
|
713
482
|
}
|
|
714
483
|
updateFundingRate(oracle, marketIndex) {
|
|
715
484
|
return __awaiter(this, void 0, void 0, function* () {
|
|
716
|
-
return this.txSender.send(utils_1.wrapInTx(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
|
|
485
|
+
return this.txSender.send((0, utils_1.wrapInTx)(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
|
|
717
486
|
});
|
|
718
487
|
}
|
|
719
488
|
getUpdateFundingRateIx(oracle, marketIndex) {
|
|
@@ -731,7 +500,7 @@ class ClearingHouse {
|
|
|
731
500
|
}
|
|
732
501
|
settleFundingPayment(userAccount, userPositionsAccount) {
|
|
733
502
|
return __awaiter(this, void 0, void 0, function* () {
|
|
734
|
-
return this.txSender.send(utils_1.wrapInTx(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
|
|
503
|
+
return this.txSender.send((0, utils_1.wrapInTx)(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
|
|
735
504
|
});
|
|
736
505
|
}
|
|
737
506
|
getSettleFundingPaymentIx(userAccount, userPositionsAccount) {
|
|
@@ -4,7 +4,7 @@ import BN from 'bn.js';
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
6
|
import { ClearingHouse } from './clearingHouse';
|
|
7
|
-
import {
|
|
7
|
+
import { UserAccount, UserPosition, UserPositionsAccount } from './types';
|
|
8
8
|
import { UserAccountSubscriber, UserAccountEvents } from './accounts/types';
|
|
9
9
|
import { PositionDirection } from '.';
|
|
10
10
|
export declare class ClearingHouseUser {
|
|
@@ -12,7 +12,6 @@ export declare class ClearingHouseUser {
|
|
|
12
12
|
authority: PublicKey;
|
|
13
13
|
accountSubscriber: UserAccountSubscriber;
|
|
14
14
|
userAccountPublicKey?: PublicKey;
|
|
15
|
-
userOrdersAccountPublicKey?: PublicKey;
|
|
16
15
|
isSubscribed: boolean;
|
|
17
16
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
18
17
|
static from(clearingHouse: ClearingHouse, authority: PublicKey): ClearingHouseUser;
|
|
@@ -29,7 +28,6 @@ export declare class ClearingHouseUser {
|
|
|
29
28
|
unsubscribe(): Promise<void>;
|
|
30
29
|
getUserAccount(): UserAccount;
|
|
31
30
|
getUserPositionsAccount(): UserPositionsAccount;
|
|
32
|
-
getUserOrdersAccount(): UserOrdersAccount;
|
|
33
31
|
/**
|
|
34
32
|
* Gets the user's current position for a given market. If the user has no position returns undefined
|
|
35
33
|
* @param marketIndex
|
|
@@ -37,13 +35,7 @@ export declare class ClearingHouseUser {
|
|
|
37
35
|
*/
|
|
38
36
|
getUserPosition(marketIndex: BN): UserPosition | undefined;
|
|
39
37
|
getEmptyPosition(marketIndex: BN): UserPosition;
|
|
40
|
-
/**
|
|
41
|
-
* @param orderId
|
|
42
|
-
* @returns Order
|
|
43
|
-
*/
|
|
44
|
-
getOrder(orderId: BN): Order | undefined;
|
|
45
38
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
46
|
-
getUserOrdersAccountPublicKey(): Promise<PublicKey>;
|
|
47
39
|
exists(): Promise<boolean>;
|
|
48
40
|
/**
|
|
49
41
|
* calculates Buying Power = FC * MAX_LEVERAGE
|
|
@@ -133,6 +125,21 @@ export declare class ClearingHouseUser {
|
|
|
133
125
|
liquidationPriceAfterClose(positionMarketIndex: BN, closeQuoteAmount: BN): BN;
|
|
134
126
|
/**
|
|
135
127
|
* Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
|
|
128
|
+
*
|
|
129
|
+
* To Calculate Max Quote Available:
|
|
130
|
+
*
|
|
131
|
+
* Case 1: SameSide
|
|
132
|
+
* => Remaining quote to get to maxLeverage
|
|
133
|
+
*
|
|
134
|
+
* Case 2: NOT SameSide && currentLeverage <= maxLeverage
|
|
135
|
+
* => Current opposite position x2 + remaining to get to maxLeverage
|
|
136
|
+
*
|
|
137
|
+
* Case 3: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition > maxLeverage
|
|
138
|
+
* => strictly reduce current position size
|
|
139
|
+
*
|
|
140
|
+
* Case 4: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition < maxLeverage
|
|
141
|
+
* => current position + remaining to get to maxLeverage
|
|
142
|
+
*
|
|
136
143
|
* @param marketIndex
|
|
137
144
|
* @param tradeSide
|
|
138
145
|
* @param userMaxLeverageSetting - leverage : Precision TEN_THOUSAND
|
|
@@ -159,5 +166,5 @@ export declare class ClearingHouseUser {
|
|
|
159
166
|
* @returns positionValue : Precision QUOTE_PRECISION
|
|
160
167
|
*/
|
|
161
168
|
private getTotalPositionValueExcludingMarket;
|
|
162
|
-
canFillOrder(order: Order): boolean;
|
|
163
169
|
}
|
|
170
|
+
//# sourceMappingURL=clearingHouseUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clearingHouseUser.d.ts","sourceRoot":"","sources":["../src/clearingHouseUser.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAc1E,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EAKN,iBAAiB,EAEjB,MAAM,GAAG,CAAC;AAGX,qBAAa,iBAAiB;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,iBAAiB,EAAE,qBAAqB,CAAC;IACzC,oBAAoB,CAAC,EAAE,SAAS,CAAC;IACjC,YAAY,UAAS;IACrB,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;WAEpD,IAAI,CACjB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,SAAS,GAClB,iBAAiB;gBASnB,aAAa,EAAE,aAAa,EAC5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