flash-sdk 2.46.5 → 2.46.7
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/dist/PerpetualsClient.d.ts +10 -10
- package/dist/PerpetualsClient.js +786 -627
- package/dist/ViewHelper.d.ts +2 -2
- package/dist/ViewHelper.js +4 -3
- package/dist/backupOracle.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/rpc.js +50 -50
- package/package.json +8 -5
package/dist/PerpetualsClient.js
CHANGED
@@ -2149,146 +2149,160 @@ var PerpetualsClient = (function () {
|
|
2149
2149
|
}
|
2150
2150
|
});
|
2151
2151
|
}); };
|
2152
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
2153
|
-
var
|
2154
|
-
var
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2152
|
+
this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
2153
|
+
var args_1 = [];
|
2154
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2155
|
+
args_1[_i - 4] = arguments[_i];
|
2156
|
+
}
|
2157
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2158
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2159
|
+
var _e;
|
2160
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2161
|
+
return __generator(this, function (_f) {
|
2162
|
+
switch (_f.label) {
|
2163
|
+
case 0:
|
2164
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2165
|
+
custodies = POOL_CONFIG.custodies;
|
2166
|
+
custodyMetas = [];
|
2167
|
+
marketMetas = [];
|
2168
|
+
for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
|
2169
|
+
token = custodies_5[_a];
|
2170
|
+
custodyMetas.push({
|
2171
|
+
isSigner: false,
|
2172
|
+
isWritable: false,
|
2173
|
+
pubkey: token.custodyAccount,
|
2174
|
+
});
|
2175
|
+
}
|
2176
|
+
for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
|
2177
|
+
custody = custodies_6[_b];
|
2178
|
+
custodyMetas.push({
|
2179
|
+
isSigner: false,
|
2180
|
+
isWritable: false,
|
2181
|
+
pubkey: custody.intOracleAccount,
|
2182
|
+
});
|
2183
|
+
}
|
2184
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2185
|
+
market = _d[_c];
|
2186
|
+
marketMetas.push({
|
2187
|
+
pubkey: market.marketAccount,
|
2188
|
+
isSigner: false,
|
2189
|
+
isWritable: false,
|
2190
|
+
});
|
2191
|
+
}
|
2192
|
+
depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
|
2193
|
+
return [4, this.program.methods
|
2194
|
+
.getAddLiquidityAmountAndFee({
|
2195
|
+
amountIn: amount,
|
2196
|
+
})
|
2197
|
+
.accounts({
|
2198
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2199
|
+
pool: poolKey,
|
2200
|
+
custody: depositCustodyKey,
|
2201
|
+
custodyOracleAccount: depositCustodyConfig.intOracleAccount,
|
2202
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2203
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2204
|
+
})
|
2205
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2206
|
+
.transaction()];
|
2207
|
+
case 1:
|
2208
|
+
transaction = _f.sent();
|
2209
|
+
return [4, backUpOracleInstructionPromise];
|
2210
|
+
case 2:
|
2211
|
+
backUpOracleInstruction = _f.sent();
|
2212
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2213
|
+
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2214
|
+
case 3:
|
2215
|
+
result = _f.sent();
|
2216
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2217
|
+
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2218
|
+
return [2, {
|
2219
|
+
amount: res.amount,
|
2220
|
+
fee: res.fee,
|
2221
|
+
}];
|
2222
|
+
}
|
2223
|
+
});
|
2217
2224
|
});
|
2218
|
-
}
|
2219
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2220
|
-
var
|
2221
|
-
var
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2225
|
+
};
|
2226
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2227
|
+
var args_1 = [];
|
2228
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2229
|
+
args_1[_i - 4] = arguments[_i];
|
2230
|
+
}
|
2231
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2232
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, backUpOracleInstruction, result, index, res;
|
2233
|
+
var _e;
|
2234
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2235
|
+
return __generator(this, function (_f) {
|
2236
|
+
switch (_f.label) {
|
2237
|
+
case 0:
|
2238
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2239
|
+
custodies = POOL_CONFIG.custodies;
|
2240
|
+
custodyMetas = [];
|
2241
|
+
marketMetas = [];
|
2242
|
+
for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
|
2243
|
+
token = custodies_7[_a];
|
2244
|
+
custodyMetas.push({
|
2245
|
+
isSigner: false,
|
2246
|
+
isWritable: false,
|
2247
|
+
pubkey: token.custodyAccount,
|
2248
|
+
});
|
2249
|
+
}
|
2250
|
+
for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
|
2251
|
+
custody = custodies_8[_b];
|
2252
|
+
custodyMetas.push({
|
2253
|
+
isSigner: false,
|
2254
|
+
isWritable: false,
|
2255
|
+
pubkey: custody.intOracleAccount,
|
2256
|
+
});
|
2257
|
+
}
|
2258
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2259
|
+
market = _d[_c];
|
2260
|
+
marketMetas.push({
|
2261
|
+
pubkey: market.marketAccount,
|
2262
|
+
isSigner: false,
|
2263
|
+
isWritable: false,
|
2264
|
+
});
|
2265
|
+
}
|
2266
|
+
removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
|
2267
|
+
return [4, this.program.methods
|
2268
|
+
.getRemoveLiquidityAmountAndFee({
|
2269
|
+
lpAmountIn: amount,
|
2270
|
+
})
|
2271
|
+
.accounts({
|
2272
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2273
|
+
pool: poolKey,
|
2274
|
+
custody: removeTokenCustodyKey,
|
2275
|
+
custodyOracleAccount: removeCustodyConfig.intOracleAccount,
|
2276
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2277
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2278
|
+
})
|
2279
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2280
|
+
.transaction()];
|
2281
|
+
case 1:
|
2282
|
+
transaction = _f.sent();
|
2283
|
+
return [4, backUpOracleInstructionPromise];
|
2284
|
+
case 2:
|
2285
|
+
backUpOracleInstruction = _f.sent();
|
2286
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2287
|
+
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2288
|
+
case 3:
|
2289
|
+
result = _f.sent();
|
2290
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2291
|
+
if (result.value.err) {
|
2292
|
+
return [2, {
|
2293
|
+
amount: new anchor_1.BN(0),
|
2294
|
+
fee: new anchor_1.BN(0),
|
2295
|
+
}];
|
2296
|
+
}
|
2297
|
+
res = this.viewHelper.decodeLogs(result, index, 'getRemoveLiquidityAmountAndFee');
|
2279
2298
|
return [2, {
|
2280
|
-
amount:
|
2281
|
-
fee:
|
2299
|
+
amount: res.amount,
|
2300
|
+
fee: res.fee,
|
2282
2301
|
}];
|
2283
|
-
|
2284
|
-
|
2285
|
-
return [2, {
|
2286
|
-
amount: res.amount,
|
2287
|
-
fee: res.fee,
|
2288
|
-
}];
|
2289
|
-
}
|
2302
|
+
}
|
2303
|
+
});
|
2290
2304
|
});
|
2291
|
-
}
|
2305
|
+
};
|
2292
2306
|
this.getCompoundingLPTokenPrice = function (poolKey, POOL_CONFIG) { return __awaiter(_this, void 0, void 0, function () {
|
2293
2307
|
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _i, custodies_9, token, _a, custodies_10, custody, _b, _c, market, backUpOracleInstruction, transaction, result, index, res;
|
2294
2308
|
var _d;
|
@@ -2348,154 +2362,168 @@ var PerpetualsClient = (function () {
|
|
2348
2362
|
}
|
2349
2363
|
});
|
2350
2364
|
}); };
|
2351
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2352
|
-
var
|
2353
|
-
var
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
|
2385
|
-
|
2386
|
-
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2397
|
-
|
2398
|
-
|
2399
|
-
|
2400
|
-
|
2401
|
-
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2365
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
2366
|
+
var args_1 = [];
|
2367
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2368
|
+
args_1[_i - 4] = arguments[_i];
|
2369
|
+
}
|
2370
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2371
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2372
|
+
var _e;
|
2373
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2374
|
+
return __generator(this, function (_f) {
|
2375
|
+
switch (_f.label) {
|
2376
|
+
case 0:
|
2377
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2378
|
+
custodies = POOL_CONFIG.custodies;
|
2379
|
+
custodyMetas = [];
|
2380
|
+
marketMetas = [];
|
2381
|
+
for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
|
2382
|
+
token = custodies_11[_a];
|
2383
|
+
custodyMetas.push({
|
2384
|
+
isSigner: false,
|
2385
|
+
isWritable: false,
|
2386
|
+
pubkey: token.custodyAccount,
|
2387
|
+
});
|
2388
|
+
}
|
2389
|
+
for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
|
2390
|
+
custody = custodies_12[_b];
|
2391
|
+
custodyMetas.push({
|
2392
|
+
isSigner: false,
|
2393
|
+
isWritable: false,
|
2394
|
+
pubkey: custody.intOracleAccount,
|
2395
|
+
});
|
2396
|
+
}
|
2397
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2398
|
+
market = _d[_c];
|
2399
|
+
marketMetas.push({
|
2400
|
+
pubkey: market.marketAccount,
|
2401
|
+
isSigner: false,
|
2402
|
+
isWritable: false,
|
2403
|
+
});
|
2404
|
+
}
|
2405
|
+
depositCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(depositCustodyKey); });
|
2406
|
+
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2407
|
+
return [4, backUpOracleInstructionPromise];
|
2408
|
+
case 1:
|
2409
|
+
backUpOracleInstruction = _f.sent();
|
2410
|
+
return [4, this.program.methods
|
2411
|
+
.getAddCompoundingLiquidityAmountAndFee({
|
2412
|
+
amountIn: amount,
|
2413
|
+
})
|
2414
|
+
.accounts({
|
2415
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2416
|
+
pool: poolKey,
|
2417
|
+
inCustody: depositCustodyKey,
|
2418
|
+
inCustodyOracleAccount: depositCustodyConfig.intOracleAccount,
|
2419
|
+
rewardCustody: rewardCustody.custodyAccount,
|
2420
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
2421
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2422
|
+
compoundingTokenMint: POOL_CONFIG.compoundingTokenMint,
|
2423
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2424
|
+
})
|
2425
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2426
|
+
.transaction()];
|
2427
|
+
case 2:
|
2428
|
+
transaction = _f.sent();
|
2429
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2430
|
+
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2431
|
+
case 3:
|
2432
|
+
result = _f.sent();
|
2433
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2434
|
+
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2435
|
+
return [2, {
|
2436
|
+
amount: res.amount,
|
2437
|
+
fee: res.fee,
|
2438
|
+
}];
|
2439
|
+
}
|
2440
|
+
});
|
2420
2441
|
});
|
2421
|
-
}
|
2422
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2423
|
-
var
|
2424
|
-
var
|
2425
|
-
|
2426
|
-
|
2427
|
-
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2438
|
-
|
2439
|
-
|
2440
|
-
|
2441
|
-
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
|
2450
|
-
|
2451
|
-
|
2452
|
-
|
2453
|
-
|
2454
|
-
|
2455
|
-
|
2456
|
-
|
2457
|
-
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
|
2462
|
-
|
2463
|
-
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2442
|
+
};
|
2443
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2444
|
+
var args_1 = [];
|
2445
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2446
|
+
args_1[_i - 4] = arguments[_i];
|
2447
|
+
}
|
2448
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2449
|
+
var backUpOracleInstructionPromise, custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, backUpOracleInstruction, transaction, result, index, res;
|
2450
|
+
var _e;
|
2451
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2452
|
+
return __generator(this, function (_f) {
|
2453
|
+
switch (_f.label) {
|
2454
|
+
case 0:
|
2455
|
+
backUpOracleInstructionPromise = (0, backupOracle_1.createBackupOracleInstruction)(POOL_CONFIG.poolAddress.toBase58(), true);
|
2456
|
+
custodies = POOL_CONFIG.custodies;
|
2457
|
+
custodyMetas = [];
|
2458
|
+
marketMetas = [];
|
2459
|
+
for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
|
2460
|
+
token = custodies_13[_a];
|
2461
|
+
custodyMetas.push({
|
2462
|
+
isSigner: false,
|
2463
|
+
isWritable: false,
|
2464
|
+
pubkey: token.custodyAccount,
|
2465
|
+
});
|
2466
|
+
}
|
2467
|
+
for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
|
2468
|
+
custody = custodies_14[_b];
|
2469
|
+
custodyMetas.push({
|
2470
|
+
isSigner: false,
|
2471
|
+
isWritable: false,
|
2472
|
+
pubkey: custody.intOracleAccount,
|
2473
|
+
});
|
2474
|
+
}
|
2475
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2476
|
+
market = _d[_c];
|
2477
|
+
marketMetas.push({
|
2478
|
+
pubkey: market.marketAccount,
|
2479
|
+
isSigner: false,
|
2480
|
+
isWritable: false,
|
2481
|
+
});
|
2482
|
+
}
|
2483
|
+
removeCustodyConfig = custodies.find(function (i) { return i.custodyAccount.equals(removeTokenCustodyKey); });
|
2484
|
+
rewardCustody = POOL_CONFIG.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
2485
|
+
return [4, backUpOracleInstructionPromise];
|
2486
|
+
case 1:
|
2487
|
+
backUpOracleInstruction = _f.sent();
|
2488
|
+
return [4, this.program.methods
|
2489
|
+
.getRemoveCompoundingLiquidityAmountAndFee({
|
2490
|
+
compoundingAmountIn: amount,
|
2491
|
+
})
|
2492
|
+
.accounts({
|
2493
|
+
perpetuals: POOL_CONFIG.perpetuals,
|
2494
|
+
pool: poolKey,
|
2495
|
+
outCustody: removeTokenCustodyKey,
|
2496
|
+
outCustodyOracleAccount: removeCustodyConfig.intOracleAccount,
|
2497
|
+
rewardCustody: rewardCustody.custodyAccount,
|
2498
|
+
rewardCustodyOracleAccount: rewardCustody.intOracleAccount,
|
2499
|
+
compoundingTokenMint: POOL_CONFIG.compoundingTokenMint,
|
2500
|
+
lpTokenMint: POOL_CONFIG.stakedLpTokenMint,
|
2501
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2502
|
+
})
|
2503
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2504
|
+
.transaction()];
|
2505
|
+
case 2:
|
2506
|
+
transaction = _f.sent();
|
2507
|
+
(_e = transaction.instructions).unshift.apply(_e, backUpOracleInstruction);
|
2508
|
+
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2509
|
+
case 3:
|
2510
|
+
result = _f.sent();
|
2511
|
+
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2512
|
+
if (result.value.err) {
|
2513
|
+
return [2, {
|
2514
|
+
amount: new anchor_1.BN(0),
|
2515
|
+
fee: new anchor_1.BN(0),
|
2516
|
+
}];
|
2517
|
+
}
|
2518
|
+
res = this.viewHelper.decodeLogs(result, index, 'getRemoveCompoundingLiquidityAmountAndFee');
|
2486
2519
|
return [2, {
|
2487
|
-
amount:
|
2488
|
-
fee:
|
2520
|
+
amount: res.amount,
|
2521
|
+
fee: res.fee,
|
2489
2522
|
}];
|
2490
|
-
|
2491
|
-
|
2492
|
-
return [2, {
|
2493
|
-
amount: res.amount,
|
2494
|
-
fee: res.fee,
|
2495
|
-
}];
|
2496
|
-
}
|
2523
|
+
}
|
2524
|
+
});
|
2497
2525
|
});
|
2498
|
-
}
|
2526
|
+
};
|
2499
2527
|
this.getLiquidationStateView = function (positionAccount, poolName, tokenMint, collateralMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
2500
2528
|
var targetCustodyConfig, collateralCustodyConfig;
|
2501
2529
|
return __generator(this, function (_a) {
|
@@ -2618,14 +2646,18 @@ var PerpetualsClient = (function () {
|
|
2618
2646
|
}
|
2619
2647
|
});
|
2620
2648
|
}); };
|
2621
|
-
this.openPosition = function (
|
2622
|
-
|
2623
|
-
|
2624
|
-
|
2625
|
-
|
2626
|
-
|
2627
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2649
|
+
this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
|
2650
|
+
var args_1 = [];
|
2651
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
2652
|
+
args_1[_i - 8] = arguments[_i];
|
2653
|
+
}
|
2654
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2628
2655
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2656
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2657
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2658
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2659
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2660
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2629
2661
|
return __generator(this, function (_c) {
|
2630
2662
|
switch (_c.label) {
|
2631
2663
|
case 0:
|
@@ -2729,15 +2761,19 @@ var PerpetualsClient = (function () {
|
|
2729
2761
|
});
|
2730
2762
|
});
|
2731
2763
|
};
|
2732
|
-
this.closePosition = function (
|
2733
|
-
|
2734
|
-
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2739
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2764
|
+
this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2765
|
+
var args_1 = [];
|
2766
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
2767
|
+
args_1[_i - 6] = arguments[_i];
|
2768
|
+
}
|
2769
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2740
2770
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_2;
|
2771
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2772
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2773
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2774
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
2775
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2776
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2741
2777
|
return __generator(this, function (_b) {
|
2742
2778
|
switch (_b.label) {
|
2743
2779
|
case 0:
|
@@ -2834,14 +2870,18 @@ var PerpetualsClient = (function () {
|
|
2834
2870
|
});
|
2835
2871
|
});
|
2836
2872
|
};
|
2837
|
-
this.swapAndOpen = function (
|
2838
|
-
|
2839
|
-
|
2840
|
-
|
2841
|
-
|
2842
|
-
|
2843
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2873
|
+
this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
|
2874
|
+
var args_1 = [];
|
2875
|
+
for (var _i = 10; _i < arguments.length; _i++) {
|
2876
|
+
args_1[_i - 10] = arguments[_i];
|
2877
|
+
}
|
2878
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2844
2879
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_2;
|
2880
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2881
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2882
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2883
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2884
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2845
2885
|
return __generator(this, function (_c) {
|
2846
2886
|
switch (_c.label) {
|
2847
2887
|
case 0:
|
@@ -2981,13 +3021,17 @@ var PerpetualsClient = (function () {
|
|
2981
3021
|
});
|
2982
3022
|
});
|
2983
3023
|
};
|
2984
|
-
this.closeAndSwap = function (
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
return __awaiter(_this,
|
3024
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
3025
|
+
var args_1 = [];
|
3026
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3027
|
+
args_1[_i - 8] = arguments[_i];
|
3028
|
+
}
|
3029
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
2990
3030
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_3;
|
3031
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3032
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3033
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3034
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2991
3035
|
return __generator(this, function (_a) {
|
2992
3036
|
switch (_a.label) {
|
2993
3037
|
case 0:
|
@@ -3101,16 +3145,20 @@ var PerpetualsClient = (function () {
|
|
3101
3145
|
});
|
3102
3146
|
});
|
3103
3147
|
};
|
3104
|
-
this.swap = function (
|
3105
|
-
|
3106
|
-
|
3107
|
-
|
3108
|
-
|
3109
|
-
|
3110
|
-
|
3111
|
-
|
3112
|
-
|
3113
|
-
|
3148
|
+
this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
|
3149
|
+
var args_1 = [];
|
3150
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
3151
|
+
args_1[_i - 5] = arguments[_i];
|
3152
|
+
}
|
3153
|
+
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
3154
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_4;
|
3155
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
3156
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3157
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
3158
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3159
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3160
|
+
return __generator(this, function (_g) {
|
3161
|
+
switch (_g.label) {
|
3114
3162
|
case 0:
|
3115
3163
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
3116
3164
|
if (!userInputCustodyConfig) {
|
@@ -3128,10 +3176,10 @@ var PerpetualsClient = (function () {
|
|
3128
3176
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
3129
3177
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
3130
3178
|
case 1:
|
3131
|
-
wsolAssociatedTokenAccount =
|
3179
|
+
wsolAssociatedTokenAccount = _g.sent();
|
3132
3180
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
3133
3181
|
case 2:
|
3134
|
-
wsolATAExist =
|
3182
|
+
wsolATAExist = _g.sent();
|
3135
3183
|
if (!wsolATAExist) {
|
3136
3184
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
3137
3185
|
}
|
@@ -3139,11 +3187,11 @@ var PerpetualsClient = (function () {
|
|
3139
3187
|
_a = anchor_1.BN.bind;
|
3140
3188
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3141
3189
|
case 3:
|
3142
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3190
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3143
3191
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3144
3192
|
throw "Insufficient SOL Funds";
|
3145
3193
|
}
|
3146
|
-
|
3194
|
+
_g.label = 4;
|
3147
3195
|
case 4:
|
3148
3196
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
3149
3197
|
fromPubkey: publicKey,
|
@@ -3165,20 +3213,20 @@ var PerpetualsClient = (function () {
|
|
3165
3213
|
additionalSigners: additionalSigners
|
3166
3214
|
}];
|
3167
3215
|
}
|
3168
|
-
|
3216
|
+
_g.label = 6;
|
3169
3217
|
case 6:
|
3170
|
-
|
3218
|
+
_g.trys.push([6, 19, , 20]);
|
3171
3219
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3172
3220
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3173
3221
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3174
3222
|
case 7:
|
3175
|
-
accCreationLamports = (
|
3223
|
+
accCreationLamports = (_g.sent());
|
3176
3224
|
console.log("accCreationLamports:", accCreationLamports);
|
3177
3225
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3178
3226
|
_b = anchor_1.BN.bind;
|
3179
3227
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3180
3228
|
case 8:
|
3181
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
3229
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3182
3230
|
if (unWrappedSolBalance.lt(amountIn)) {
|
3183
3231
|
throw "Insufficient SOL Funds";
|
3184
3232
|
}
|
@@ -3205,18 +3253,18 @@ var PerpetualsClient = (function () {
|
|
3205
3253
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
3206
3254
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3207
3255
|
case 10:
|
3208
|
-
if (!(
|
3256
|
+
if (!(_g.sent())) {
|
3209
3257
|
throw "Insufficient Funds , Token Account doesn't exist";
|
3210
3258
|
}
|
3211
3259
|
if (!!skipBalanceChecks) return [3, 12];
|
3212
3260
|
_c = anchor_1.BN.bind;
|
3213
3261
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3214
3262
|
case 11:
|
3215
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
3263
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3216
3264
|
if (tokenAccountBalance.lt(amountIn)) {
|
3217
3265
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3218
3266
|
}
|
3219
|
-
|
3267
|
+
_g.label = 12;
|
3220
3268
|
case 12:
|
3221
3269
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
3222
3270
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -3241,23 +3289,23 @@ var PerpetualsClient = (function () {
|
|
3241
3289
|
return [3, 17];
|
3242
3290
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
3243
3291
|
case 14:
|
3244
|
-
userOutputTokenAccount =
|
3292
|
+
userOutputTokenAccount = _g.sent();
|
3245
3293
|
_d = createUserATA;
|
3246
3294
|
if (!_d) return [3, 16];
|
3247
3295
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
3248
3296
|
case 15:
|
3249
|
-
_d = !(
|
3250
|
-
|
3297
|
+
_d = !(_g.sent());
|
3298
|
+
_g.label = 16;
|
3251
3299
|
case 16:
|
3252
3300
|
if (_d) {
|
3253
3301
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3254
3302
|
}
|
3255
|
-
|
3303
|
+
_g.label = 17;
|
3256
3304
|
case 17:
|
3257
3305
|
custodyAccountMetas = [];
|
3258
3306
|
custodyOracleAccountMetas = [];
|
3259
|
-
for (
|
3260
|
-
custody = _e
|
3307
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
3308
|
+
custody = _f[_e];
|
3261
3309
|
custodyAccountMetas.push({
|
3262
3310
|
pubkey: custody.custodyAccount,
|
3263
3311
|
isSigner: false,
|
@@ -3297,7 +3345,7 @@ var PerpetualsClient = (function () {
|
|
3297
3345
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3298
3346
|
.instruction()];
|
3299
3347
|
case 18:
|
3300
|
-
inx =
|
3348
|
+
inx = _g.sent();
|
3301
3349
|
instructions.push(inx);
|
3302
3350
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3303
3351
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -3305,7 +3353,7 @@ var PerpetualsClient = (function () {
|
|
3305
3353
|
}
|
3306
3354
|
return [3, 20];
|
3307
3355
|
case 19:
|
3308
|
-
err_4 =
|
3356
|
+
err_4 = _g.sent();
|
3309
3357
|
console.error("perpClient Swap error:: ", err_4);
|
3310
3358
|
throw err_4;
|
3311
3359
|
case 20: return [2, {
|
@@ -3387,11 +3435,15 @@ var PerpetualsClient = (function () {
|
|
3387
3435
|
}
|
3388
3436
|
});
|
3389
3437
|
}); };
|
3390
|
-
this.addCollateral = function (
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3438
|
+
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3439
|
+
var args_1 = [];
|
3440
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3441
|
+
args_1[_i - 6] = arguments[_i];
|
3442
|
+
}
|
3443
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3394
3444
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3445
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3446
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3395
3447
|
return __generator(this, function (_c) {
|
3396
3448
|
switch (_c.label) {
|
3397
3449
|
case 0:
|
@@ -3485,11 +3537,15 @@ var PerpetualsClient = (function () {
|
|
3485
3537
|
});
|
3486
3538
|
});
|
3487
3539
|
};
|
3488
|
-
this.swapAndAddCollateral = function (
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3540
|
+
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3541
|
+
var args_1 = [];
|
3542
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3543
|
+
args_1[_i - 8] = arguments[_i];
|
3544
|
+
}
|
3545
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3492
3546
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3547
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3548
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3493
3549
|
return __generator(this, function (_c) {
|
3494
3550
|
switch (_c.label) {
|
3495
3551
|
case 0:
|
@@ -3600,12 +3656,16 @@ var PerpetualsClient = (function () {
|
|
3600
3656
|
});
|
3601
3657
|
});
|
3602
3658
|
};
|
3603
|
-
this.removeCollateral = function (
|
3604
|
-
|
3605
|
-
|
3606
|
-
|
3607
|
-
|
3659
|
+
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3660
|
+
var args_1 = [];
|
3661
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3662
|
+
args_1[_i - 6] = arguments[_i];
|
3663
|
+
}
|
3664
|
+
return __awaiter(_this, __spreadArray([collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1], args_1, true), void 0, function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3608
3665
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_3;
|
3666
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3667
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3668
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3609
3669
|
return __generator(this, function (_b) {
|
3610
3670
|
switch (_b.label) {
|
3611
3671
|
case 0:
|
@@ -3706,10 +3766,14 @@ var PerpetualsClient = (function () {
|
|
3706
3766
|
});
|
3707
3767
|
});
|
3708
3768
|
};
|
3709
|
-
this.removeCollateralAndSwap = function (
|
3710
|
-
|
3711
|
-
|
3769
|
+
this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
|
3770
|
+
var args_1 = [];
|
3771
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
3772
|
+
args_1[_i - 7] = arguments[_i];
|
3773
|
+
}
|
3774
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3712
3775
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3776
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3713
3777
|
return __generator(this, function (_a) {
|
3714
3778
|
switch (_a.label) {
|
3715
3779
|
case 0:
|
@@ -3802,12 +3866,16 @@ var PerpetualsClient = (function () {
|
|
3802
3866
|
});
|
3803
3867
|
});
|
3804
3868
|
};
|
3805
|
-
this.increaseSize = function (
|
3806
|
-
|
3807
|
-
|
3808
|
-
|
3809
|
-
|
3869
|
+
this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3870
|
+
var args_1 = [];
|
3871
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3872
|
+
args_1[_i - 8] = arguments[_i];
|
3873
|
+
}
|
3874
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3810
3875
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3876
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3877
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3878
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3811
3879
|
return __generator(this, function (_a) {
|
3812
3880
|
switch (_a.label) {
|
3813
3881
|
case 0:
|
@@ -3862,12 +3930,16 @@ var PerpetualsClient = (function () {
|
|
3862
3930
|
});
|
3863
3931
|
});
|
3864
3932
|
};
|
3865
|
-
this.decreaseSize = function (
|
3866
|
-
|
3867
|
-
|
3868
|
-
|
3869
|
-
|
3933
|
+
this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3934
|
+
var args_1 = [];
|
3935
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3936
|
+
args_1[_i - 8] = arguments[_i];
|
3937
|
+
}
|
3938
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3870
3939
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3940
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3941
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3942
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3871
3943
|
return __generator(this, function (_a) {
|
3872
3944
|
switch (_a.label) {
|
3873
3945
|
case 0:
|
@@ -3922,13 +3994,17 @@ var PerpetualsClient = (function () {
|
|
3922
3994
|
});
|
3923
3995
|
});
|
3924
3996
|
};
|
3925
|
-
this.addLiquidity = function (
|
3926
|
-
|
3927
|
-
|
3928
|
-
|
3929
|
-
|
3930
|
-
|
3931
|
-
|
3997
|
+
this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3998
|
+
var args_1 = [];
|
3999
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
4000
|
+
args_1[_i - 4] = arguments[_i];
|
4001
|
+
}
|
4002
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
4003
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_6;
|
4004
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4005
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4006
|
+
return __generator(this, function (_g) {
|
4007
|
+
switch (_g.label) {
|
3932
4008
|
case 0:
|
3933
4009
|
publicKey = this.provider.wallet.publicKey;
|
3934
4010
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -3939,16 +4015,16 @@ var PerpetualsClient = (function () {
|
|
3939
4015
|
instructions = [];
|
3940
4016
|
postInstructions = [];
|
3941
4017
|
additionalSigners = [];
|
3942
|
-
|
4018
|
+
_g.label = 1;
|
3943
4019
|
case 1:
|
3944
|
-
|
4020
|
+
_g.trys.push([1, 10, , 11]);
|
3945
4021
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
3946
4022
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3947
4023
|
custodyAccountMetas = [];
|
3948
4024
|
custodyOracleAccountMetas = [];
|
3949
4025
|
markets = [];
|
3950
|
-
for (
|
3951
|
-
custody = _a
|
4026
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4027
|
+
custody = _b[_a];
|
3952
4028
|
custodyAccountMetas.push({
|
3953
4029
|
pubkey: custody.custodyAccount,
|
3954
4030
|
isSigner: false,
|
@@ -3960,8 +4036,8 @@ var PerpetualsClient = (function () {
|
|
3960
4036
|
isWritable: false,
|
3961
4037
|
});
|
3962
4038
|
}
|
3963
|
-
for (
|
3964
|
-
market = _c
|
4039
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4040
|
+
market = _d[_c];
|
3965
4041
|
markets.push({
|
3966
4042
|
pubkey: market.marketAccount,
|
3967
4043
|
isSigner: false,
|
@@ -3970,21 +4046,21 @@ var PerpetualsClient = (function () {
|
|
3970
4046
|
}
|
3971
4047
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3972
4048
|
case 2:
|
3973
|
-
if (!(
|
4049
|
+
if (!(_g.sent())) {
|
3974
4050
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3975
4051
|
}
|
3976
4052
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3977
4053
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3978
4054
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3979
4055
|
if (!!skipBalanceChecks) return [3, 4];
|
3980
|
-
|
4056
|
+
_e = anchor_1.BN.bind;
|
3981
4057
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3982
4058
|
case 3:
|
3983
|
-
unWrappedSolBalance = new (
|
4059
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3984
4060
|
if (unWrappedSolBalance.lt(lamports)) {
|
3985
4061
|
throw "Insufficient SOL Funds";
|
3986
4062
|
}
|
3987
|
-
|
4063
|
+
_g.label = 4;
|
3988
4064
|
case 4:
|
3989
4065
|
if (!ephemeralSignerPubkey) {
|
3990
4066
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4008,17 +4084,17 @@ var PerpetualsClient = (function () {
|
|
4008
4084
|
if (!!skipBalanceChecks) return [3, 8];
|
4009
4085
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
4010
4086
|
case 6:
|
4011
|
-
if (!(
|
4087
|
+
if (!(_g.sent())) {
|
4012
4088
|
throw "Insufficient Funds , token Account doesn't exist";
|
4013
4089
|
}
|
4014
|
-
|
4090
|
+
_f = anchor_1.BN.bind;
|
4015
4091
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
4016
4092
|
case 7:
|
4017
|
-
tokenAccountBalance = new (
|
4093
|
+
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
4018
4094
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
4019
4095
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
4020
4096
|
}
|
4021
|
-
|
4097
|
+
_g.label = 8;
|
4022
4098
|
case 8: return [4, this.program.methods
|
4023
4099
|
.addLiquidity({
|
4024
4100
|
amountIn: tokenAmountIn,
|
@@ -4043,11 +4119,11 @@ var PerpetualsClient = (function () {
|
|
4043
4119
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4044
4120
|
.instruction()];
|
4045
4121
|
case 9:
|
4046
|
-
instruction =
|
4122
|
+
instruction = _g.sent();
|
4047
4123
|
instructions.push(instruction);
|
4048
4124
|
return [3, 11];
|
4049
4125
|
case 10:
|
4050
|
-
err_6 =
|
4126
|
+
err_6 = _g.sent();
|
4051
4127
|
console.error("perpClient addLiquidity error:: ", err_6);
|
4052
4128
|
throw err_6;
|
4053
4129
|
case 11: return [2, {
|
@@ -4058,15 +4134,20 @@ var PerpetualsClient = (function () {
|
|
4058
4134
|
});
|
4059
4135
|
});
|
4060
4136
|
};
|
4061
|
-
this.addLiquidityAndStake = function (
|
4062
|
-
|
4063
|
-
|
4064
|
-
|
4065
|
-
|
4066
|
-
|
4067
|
-
|
4137
|
+
this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
|
4138
|
+
var args_1 = [];
|
4139
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
4140
|
+
args_1[_i - 4] = arguments[_i];
|
4141
|
+
}
|
4142
|
+
return __awaiter(_this, __spreadArray([inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4143
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
|
4144
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4145
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4146
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4147
|
+
return __generator(this, function (_g) {
|
4148
|
+
switch (_g.label) {
|
4068
4149
|
case 0:
|
4069
|
-
publicKey = this.provider.wallet.publicKey;
|
4150
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4070
4151
|
preInstructions = [];
|
4071
4152
|
instructions = [];
|
4072
4153
|
postInstructions = [];
|
@@ -4084,14 +4165,14 @@ var PerpetualsClient = (function () {
|
|
4084
4165
|
_a = anchor_1.BN.bind;
|
4085
4166
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4086
4167
|
case 1:
|
4087
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
4168
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
4088
4169
|
if (unWrappedSolBalance.lt(lamports)) {
|
4089
4170
|
throw "Insufficient SOL Funds";
|
4090
4171
|
}
|
4091
|
-
|
4172
|
+
_g.label = 2;
|
4092
4173
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4093
4174
|
case 3:
|
4094
|
-
if (!(
|
4175
|
+
if (!(_g.sent())) {
|
4095
4176
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4096
4177
|
}
|
4097
4178
|
if (!ephemeralSignerPubkey) {
|
@@ -4117,23 +4198,23 @@ var PerpetualsClient = (function () {
|
|
4117
4198
|
if (!!skipBalanceChecks) return [3, 7];
|
4118
4199
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
4119
4200
|
case 5:
|
4120
|
-
if (!(
|
4201
|
+
if (!(_g.sent())) {
|
4121
4202
|
throw "Insufficient Funds , token Account doesn't exist";
|
4122
4203
|
}
|
4123
4204
|
_b = anchor_1.BN.bind;
|
4124
4205
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
4125
4206
|
case 6:
|
4126
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
4207
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
4127
4208
|
if (tokenAccountBalance.lt(amountIn)) {
|
4128
4209
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
4129
4210
|
}
|
4130
|
-
|
4211
|
+
_g.label = 7;
|
4131
4212
|
case 7:
|
4132
4213
|
custodyAccountMetas = [];
|
4133
4214
|
custodyOracleAccountMetas = [];
|
4134
4215
|
markets = [];
|
4135
|
-
for (
|
4136
|
-
custody = _c
|
4216
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
4217
|
+
custody = _d[_c];
|
4137
4218
|
custodyAccountMetas.push({
|
4138
4219
|
pubkey: custody.custodyAccount,
|
4139
4220
|
isSigner: false,
|
@@ -4145,8 +4226,8 @@ var PerpetualsClient = (function () {
|
|
4145
4226
|
isWritable: false,
|
4146
4227
|
});
|
4147
4228
|
}
|
4148
|
-
for (
|
4149
|
-
market = _e
|
4229
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
4230
|
+
market = _f[_e];
|
4150
4231
|
markets.push({
|
4151
4232
|
pubkey: market.marketAccount,
|
4152
4233
|
isSigner: false,
|
@@ -4178,7 +4259,7 @@ var PerpetualsClient = (function () {
|
|
4178
4259
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4179
4260
|
.instruction()];
|
4180
4261
|
case 8:
|
4181
|
-
instruction =
|
4262
|
+
instruction = _g.sent();
|
4182
4263
|
instructions.push(instruction);
|
4183
4264
|
return [2, {
|
4184
4265
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4188,34 +4269,39 @@ var PerpetualsClient = (function () {
|
|
4188
4269
|
});
|
4189
4270
|
});
|
4190
4271
|
};
|
4191
|
-
this.removeLiquidity = function (
|
4192
|
-
|
4193
|
-
|
4194
|
-
|
4195
|
-
|
4196
|
-
return __awaiter(_this,
|
4197
|
-
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets,
|
4198
|
-
|
4199
|
-
|
4272
|
+
this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
|
4273
|
+
var args_1 = [];
|
4274
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
4275
|
+
args_1[_i - 4] = arguments[_i];
|
4276
|
+
}
|
4277
|
+
return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
4278
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_7;
|
4279
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
4280
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4281
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4282
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4283
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4284
|
+
return __generator(this, function (_f) {
|
4285
|
+
switch (_f.label) {
|
4200
4286
|
case 0:
|
4201
4287
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
4202
4288
|
if (!recieveTokenCustodyConfig) {
|
4203
4289
|
throw "recieveTokenCustody not found";
|
4204
4290
|
}
|
4205
|
-
publicKey = this.provider.wallet.publicKey;
|
4291
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4206
4292
|
preInstructions = [];
|
4207
4293
|
instructions = [];
|
4208
4294
|
postInstructions = [];
|
4209
4295
|
additionalSigners = [];
|
4210
|
-
|
4296
|
+
_f.label = 1;
|
4211
4297
|
case 1:
|
4212
|
-
|
4298
|
+
_f.trys.push([1, 7, , 8]);
|
4213
4299
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4214
4300
|
custodyAccountMetas = [];
|
4215
4301
|
custodyOracleAccountMetas = [];
|
4216
4302
|
markets = [];
|
4217
|
-
for (
|
4218
|
-
custody = _a
|
4303
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4304
|
+
custody = _b[_a];
|
4219
4305
|
custodyAccountMetas.push({
|
4220
4306
|
pubkey: custody.custodyAccount,
|
4221
4307
|
isSigner: false,
|
@@ -4227,8 +4313,8 @@ var PerpetualsClient = (function () {
|
|
4227
4313
|
isWritable: false,
|
4228
4314
|
});
|
4229
4315
|
}
|
4230
|
-
for (
|
4231
|
-
market = _c
|
4316
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4317
|
+
market = _d[_c];
|
4232
4318
|
markets.push({
|
4233
4319
|
pubkey: market.marketAccount,
|
4234
4320
|
isSigner: false,
|
@@ -4257,17 +4343,17 @@ var PerpetualsClient = (function () {
|
|
4257
4343
|
return [3, 5];
|
4258
4344
|
case 2:
|
4259
4345
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4260
|
-
|
4261
|
-
if (!
|
4346
|
+
_e = createUserATA;
|
4347
|
+
if (!_e) return [3, 4];
|
4262
4348
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4263
4349
|
case 3:
|
4264
|
-
|
4265
|
-
|
4350
|
+
_e = !(_f.sent());
|
4351
|
+
_f.label = 4;
|
4266
4352
|
case 4:
|
4267
|
-
if (
|
4353
|
+
if (_e) {
|
4268
4354
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4269
4355
|
}
|
4270
|
-
|
4356
|
+
_f.label = 5;
|
4271
4357
|
case 5: return [4, this.program.methods
|
4272
4358
|
.removeLiquidity({
|
4273
4359
|
lpAmountIn: liquidityAmountIn,
|
@@ -4292,7 +4378,7 @@ var PerpetualsClient = (function () {
|
|
4292
4378
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4293
4379
|
.instruction()];
|
4294
4380
|
case 6:
|
4295
|
-
removeLiquidityTx =
|
4381
|
+
removeLiquidityTx = _f.sent();
|
4296
4382
|
instructions.push(removeLiquidityTx);
|
4297
4383
|
if (closeLpATA) {
|
4298
4384
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -4304,7 +4390,7 @@ var PerpetualsClient = (function () {
|
|
4304
4390
|
}
|
4305
4391
|
return [3, 8];
|
4306
4392
|
case 7:
|
4307
|
-
err_7 =
|
4393
|
+
err_7 = _f.sent();
|
4308
4394
|
console.log("perpClient removeLiquidity error:: ", err_7);
|
4309
4395
|
throw err_7;
|
4310
4396
|
case 8: return [2, {
|
@@ -4722,61 +4808,68 @@ var PerpetualsClient = (function () {
|
|
4722
4808
|
}
|
4723
4809
|
});
|
4724
4810
|
}); };
|
4725
|
-
this.refreshStakeWithTokenStake = function (
|
4726
|
-
var
|
4727
|
-
|
4728
|
-
|
4729
|
-
|
4730
|
-
|
4731
|
-
|
4732
|
-
|
4733
|
-
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
|
4811
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
|
4812
|
+
var args_1 = [];
|
4813
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4814
|
+
args_1[_i - 3] = arguments[_i];
|
4815
|
+
}
|
4816
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4817
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_16;
|
4818
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4819
|
+
return __generator(this, function (_c) {
|
4820
|
+
switch (_c.label) {
|
4821
|
+
case 0:
|
4822
|
+
_c.trys.push([0, 2, , 3]);
|
4823
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4824
|
+
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4825
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4826
|
+
pool = poolConfig.poolAddress;
|
4827
|
+
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4828
|
+
custodyAccountMetas = [];
|
4829
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4830
|
+
custody = _b[_a];
|
4831
|
+
custodyAccountMetas.push({
|
4832
|
+
pubkey: custody.custodyAccount,
|
4833
|
+
isSigner: false,
|
4834
|
+
isWritable: false,
|
4835
|
+
});
|
4836
|
+
}
|
4837
|
+
stakeAccountMetas = [];
|
4838
|
+
stakeAccountMetas.push({
|
4839
|
+
pubkey: flpStakeAccountPk,
|
4840
|
+
isSigner: false,
|
4841
|
+
isWritable: true,
|
4842
|
+
});
|
4843
|
+
tokenStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("token_stake"), publicKey.toBuffer()], this.programId)[0];
|
4844
|
+
stakeAccountMetas.push({
|
4845
|
+
pubkey: tokenStakeAccount,
|
4741
4846
|
isSigner: false,
|
4742
4847
|
isWritable: false,
|
4743
4848
|
});
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4764
|
-
|
4765
|
-
|
4766
|
-
})
|
4767
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4768
|
-
.instruction()];
|
4769
|
-
case 1:
|
4770
|
-
refreshStakeInstruction = _b.sent();
|
4771
|
-
return [2, refreshStakeInstruction];
|
4772
|
-
case 2:
|
4773
|
-
err_16 = _b.sent();
|
4774
|
-
console.log("perpClient refreshStaking error:: ", err_16);
|
4775
|
-
throw err_16;
|
4776
|
-
case 3: return [2];
|
4777
|
-
}
|
4849
|
+
return [4, this.program.methods
|
4850
|
+
.refreshStake({})
|
4851
|
+
.accounts({
|
4852
|
+
perpetuals: this.perpetuals.publicKey,
|
4853
|
+
pool: pool,
|
4854
|
+
rewardCustody: rewardCustodyConfig.custodyAccount,
|
4855
|
+
feeDistributionTokenAccount: feeDistributionTokenAccount,
|
4856
|
+
eventAuthority: this.eventAuthority.publicKey,
|
4857
|
+
program: this.program.programId,
|
4858
|
+
})
|
4859
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4860
|
+
.instruction()];
|
4861
|
+
case 1:
|
4862
|
+
refreshStakeInstruction = _c.sent();
|
4863
|
+
return [2, refreshStakeInstruction];
|
4864
|
+
case 2:
|
4865
|
+
err_16 = _c.sent();
|
4866
|
+
console.log("perpClient refreshStaking error:: ", err_16);
|
4867
|
+
throw err_16;
|
4868
|
+
case 3: return [2];
|
4869
|
+
}
|
4870
|
+
});
|
4778
4871
|
});
|
4779
|
-
}
|
4872
|
+
};
|
4780
4873
|
this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4781
4874
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_17;
|
4782
4875
|
return __generator(this, function (_b) {
|
@@ -4936,12 +5029,16 @@ var PerpetualsClient = (function () {
|
|
4936
5029
|
}
|
4937
5030
|
});
|
4938
5031
|
}); };
|
4939
|
-
this.withdrawStake = function (
|
4940
|
-
|
4941
|
-
|
4942
|
-
|
4943
|
-
|
5032
|
+
this.withdrawStake = function (poolConfig_1) {
|
5033
|
+
var args_1 = [];
|
5034
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
5035
|
+
args_1[_i - 1] = arguments[_i];
|
5036
|
+
}
|
5037
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA) {
|
4944
5038
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_20;
|
5039
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
5040
|
+
if (deactivated === void 0) { deactivated = true; }
|
5041
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
4945
5042
|
return __generator(this, function (_b) {
|
4946
5043
|
switch (_b.label) {
|
4947
5044
|
case 0:
|
@@ -5003,10 +5100,14 @@ var PerpetualsClient = (function () {
|
|
5003
5100
|
});
|
5004
5101
|
});
|
5005
5102
|
};
|
5006
|
-
this.collectStakeFees = function (
|
5007
|
-
|
5008
|
-
|
5103
|
+
this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
|
5104
|
+
var args_1 = [];
|
5105
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5106
|
+
args_1[_i - 3] = arguments[_i];
|
5107
|
+
}
|
5108
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
5009
5109
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_21;
|
5110
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5010
5111
|
return __generator(this, function (_b) {
|
5011
5112
|
switch (_b.label) {
|
5012
5113
|
case 0:
|
@@ -5679,10 +5780,14 @@ var PerpetualsClient = (function () {
|
|
5679
5780
|
}
|
5680
5781
|
});
|
5681
5782
|
}); };
|
5682
|
-
this.collectTokenReward = function (
|
5683
|
-
|
5684
|
-
|
5783
|
+
this.collectTokenReward = function (owner_1, poolConfig_1) {
|
5784
|
+
var args_1 = [];
|
5785
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5786
|
+
args_1[_i - 2] = arguments[_i];
|
5787
|
+
}
|
5788
|
+
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5685
5789
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_34;
|
5790
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5686
5791
|
return __generator(this, function (_b) {
|
5687
5792
|
switch (_b.label) {
|
5688
5793
|
case 0:
|
@@ -5866,10 +5971,14 @@ var PerpetualsClient = (function () {
|
|
5866
5971
|
}
|
5867
5972
|
});
|
5868
5973
|
}); };
|
5869
|
-
this.collectNftReward = function (
|
5870
|
-
|
5871
|
-
|
5974
|
+
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5975
|
+
var args_1 = [];
|
5976
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5977
|
+
args_1[_i - 3] = arguments[_i];
|
5978
|
+
}
|
5979
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5872
5980
|
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_38;
|
5981
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5873
5982
|
return __generator(this, function (_b) {
|
5874
5983
|
switch (_b.label) {
|
5875
5984
|
case 0:
|
@@ -5929,10 +6038,14 @@ var PerpetualsClient = (function () {
|
|
5929
6038
|
});
|
5930
6039
|
});
|
5931
6040
|
};
|
5932
|
-
this.collectAndDistributeFee = function (
|
5933
|
-
|
5934
|
-
|
6041
|
+
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
6042
|
+
var args_1 = [];
|
6043
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
6044
|
+
args_1[_i - 2] = arguments[_i];
|
6045
|
+
}
|
6046
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5935
6047
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_39;
|
6048
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5936
6049
|
return __generator(this, function (_b) {
|
5937
6050
|
switch (_b.label) {
|
5938
6051
|
case 0:
|
@@ -6057,12 +6170,16 @@ var PerpetualsClient = (function () {
|
|
6057
6170
|
}
|
6058
6171
|
});
|
6059
6172
|
}); };
|
6060
|
-
this.forceClosePosition = function (
|
6061
|
-
|
6062
|
-
|
6063
|
-
|
6064
|
-
|
6173
|
+
this.forceClosePosition = function (positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
|
6174
|
+
var args_1 = [];
|
6175
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
6176
|
+
args_1[_i - 6] = arguments[_i];
|
6177
|
+
}
|
6178
|
+
return __awaiter(_this, __spreadArray([positionAccount_1, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
6065
6179
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_41;
|
6180
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6181
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
6182
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6066
6183
|
return __generator(this, function (_b) {
|
6067
6184
|
switch (_b.label) {
|
6068
6185
|
case 0:
|
@@ -6134,11 +6251,15 @@ var PerpetualsClient = (function () {
|
|
6134
6251
|
});
|
6135
6252
|
});
|
6136
6253
|
};
|
6137
|
-
this.placeLimitOrder = function (
|
6138
|
-
|
6139
|
-
|
6140
|
-
|
6254
|
+
this.placeLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6255
|
+
var args_1 = [];
|
6256
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6257
|
+
args_1[_i - 11] = arguments[_i];
|
6258
|
+
}
|
6259
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
6141
6260
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_42;
|
6261
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6262
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6142
6263
|
return __generator(this, function (_c) {
|
6143
6264
|
switch (_c.label) {
|
6144
6265
|
case 0:
|
@@ -6254,11 +6375,15 @@ var PerpetualsClient = (function () {
|
|
6254
6375
|
});
|
6255
6376
|
});
|
6256
6377
|
};
|
6257
|
-
this.editLimitOrder = function (
|
6258
|
-
|
6259
|
-
|
6260
|
-
|
6378
|
+
this.editLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6379
|
+
var args_1 = [];
|
6380
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6381
|
+
args_1[_i - 11] = arguments[_i];
|
6382
|
+
}
|
6383
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6261
6384
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_43;
|
6385
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6386
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6262
6387
|
return __generator(this, function (_b) {
|
6263
6388
|
switch (_b.label) {
|
6264
6389
|
case 0:
|
@@ -6357,12 +6482,16 @@ var PerpetualsClient = (function () {
|
|
6357
6482
|
});
|
6358
6483
|
});
|
6359
6484
|
};
|
6360
|
-
this.executeLimitOrder = function (
|
6361
|
-
|
6362
|
-
|
6363
|
-
|
6364
|
-
|
6485
|
+
this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6486
|
+
var args_1 = [];
|
6487
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
6488
|
+
args_1[_i - 7] = arguments[_i];
|
6489
|
+
}
|
6490
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6365
6491
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_44;
|
6492
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6493
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6494
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6366
6495
|
return __generator(this, function (_a) {
|
6367
6496
|
switch (_a.label) {
|
6368
6497
|
case 0:
|
@@ -6422,12 +6551,16 @@ var PerpetualsClient = (function () {
|
|
6422
6551
|
});
|
6423
6552
|
});
|
6424
6553
|
};
|
6425
|
-
this.executeLimitWithSwap = function (
|
6426
|
-
|
6427
|
-
|
6428
|
-
|
6429
|
-
|
6554
|
+
this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6555
|
+
var args_1 = [];
|
6556
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6557
|
+
args_1[_i - 8] = arguments[_i];
|
6558
|
+
}
|
6559
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6430
6560
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_45;
|
6561
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6562
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6563
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6431
6564
|
return __generator(this, function (_a) {
|
6432
6565
|
switch (_a.label) {
|
6433
6566
|
case 0:
|
@@ -6693,16 +6826,20 @@ var PerpetualsClient = (function () {
|
|
6693
6826
|
}
|
6694
6827
|
});
|
6695
6828
|
}); };
|
6696
|
-
this.executeTriggerWithSwap = function (
|
6697
|
-
|
6698
|
-
|
6699
|
-
|
6700
|
-
|
6701
|
-
|
6702
|
-
|
6703
|
-
|
6704
|
-
|
6705
|
-
|
6829
|
+
this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6830
|
+
var args_1 = [];
|
6831
|
+
for (var _i = 9; _i < arguments.length; _i++) {
|
6832
|
+
args_1[_i - 9] = arguments[_i];
|
6833
|
+
}
|
6834
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6835
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_50;
|
6836
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6837
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6838
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6839
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6840
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6841
|
+
return __generator(this, function (_e) {
|
6842
|
+
switch (_e.label) {
|
6706
6843
|
case 0:
|
6707
6844
|
payerPubkey = this.provider.wallet.publicKey;
|
6708
6845
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6713,9 +6850,9 @@ var PerpetualsClient = (function () {
|
|
6713
6850
|
instructions = [];
|
6714
6851
|
postInstructions = [];
|
6715
6852
|
additionalSigners = [];
|
6716
|
-
|
6853
|
+
_e.label = 1;
|
6717
6854
|
case 1:
|
6718
|
-
|
6855
|
+
_e.trys.push([1, 9, , 10]);
|
6719
6856
|
if (!false) return [3, 2];
|
6720
6857
|
return [3, 7];
|
6721
6858
|
case 2:
|
@@ -6724,8 +6861,8 @@ var PerpetualsClient = (function () {
|
|
6724
6861
|
if (!_a) return [3, 4];
|
6725
6862
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6726
6863
|
case 3:
|
6727
|
-
_a = !(
|
6728
|
-
|
6864
|
+
_a = !(_e.sent());
|
6865
|
+
_e.label = 4;
|
6729
6866
|
case 4:
|
6730
6867
|
if (_a) {
|
6731
6868
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6735,20 +6872,20 @@ var PerpetualsClient = (function () {
|
|
6735
6872
|
if (!_b) return [3, 6];
|
6736
6873
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6737
6874
|
case 5:
|
6738
|
-
_b = !(
|
6739
|
-
|
6875
|
+
_b = !(_e.sent());
|
6876
|
+
_e.label = 6;
|
6740
6877
|
case 6:
|
6741
6878
|
if (_b) {
|
6742
6879
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6743
6880
|
}
|
6744
|
-
|
6881
|
+
_e.label = 7;
|
6745
6882
|
case 7:
|
6746
6883
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6747
6884
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6748
6885
|
custodyAccountMetas = [];
|
6749
6886
|
custodyOracleAccountMetas = [];
|
6750
|
-
for (
|
6751
|
-
custody = _c
|
6887
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
6888
|
+
custody = _d[_c];
|
6752
6889
|
custodyAccountMetas.push({
|
6753
6890
|
pubkey: custody.custodyAccount,
|
6754
6891
|
isSigner: false,
|
@@ -6793,11 +6930,11 @@ var PerpetualsClient = (function () {
|
|
6793
6930
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6794
6931
|
.instruction()];
|
6795
6932
|
case 8:
|
6796
|
-
executeTriggerWithSwap =
|
6933
|
+
executeTriggerWithSwap = _e.sent();
|
6797
6934
|
instructions.push(executeTriggerWithSwap);
|
6798
6935
|
return [3, 10];
|
6799
6936
|
case 9:
|
6800
|
-
err_50 =
|
6937
|
+
err_50 = _e.sent();
|
6801
6938
|
console.log("perpClient executeTriggerWithSwap error:: ", err_50);
|
6802
6939
|
throw err_50;
|
6803
6940
|
case 10: return [2, {
|
@@ -6808,14 +6945,18 @@ var PerpetualsClient = (function () {
|
|
6808
6945
|
});
|
6809
6946
|
});
|
6810
6947
|
};
|
6811
|
-
this.executeTriggerOrder = function (
|
6812
|
-
|
6813
|
-
|
6814
|
-
|
6815
|
-
|
6816
|
-
|
6817
|
-
return __awaiter(_this, void 0, void 0, function () {
|
6948
|
+
this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6949
|
+
var args_1 = [];
|
6950
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6951
|
+
args_1[_i - 8] = arguments[_i];
|
6952
|
+
}
|
6953
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6818
6954
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_51;
|
6955
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6956
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6957
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6958
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6959
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6819
6960
|
return __generator(this, function (_b) {
|
6820
6961
|
switch (_b.label) {
|
6821
6962
|
case 0:
|
@@ -7167,15 +7308,20 @@ var PerpetualsClient = (function () {
|
|
7167
7308
|
}
|
7168
7309
|
});
|
7169
7310
|
}); };
|
7170
|
-
this.addCompoundingLiquidity = function (
|
7171
|
-
|
7172
|
-
|
7173
|
-
|
7174
|
-
|
7175
|
-
|
7176
|
-
|
7311
|
+
this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
7312
|
+
var args_1 = [];
|
7313
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
7314
|
+
args_1[_i - 5] = arguments[_i];
|
7315
|
+
}
|
7316
|
+
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
7317
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_58;
|
7318
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7319
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7320
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7321
|
+
return __generator(this, function (_f) {
|
7322
|
+
switch (_f.label) {
|
7177
7323
|
case 0:
|
7178
|
-
publicKey = this.provider.wallet.publicKey;
|
7324
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7179
7325
|
preInstructions = [];
|
7180
7326
|
instructions = [];
|
7181
7327
|
additionalSigners = [];
|
@@ -7190,8 +7336,8 @@ var PerpetualsClient = (function () {
|
|
7190
7336
|
custodyAccountMetas = [];
|
7191
7337
|
custodyOracleAccountMetas = [];
|
7192
7338
|
markets = [];
|
7193
|
-
for (
|
7194
|
-
custody = _a
|
7339
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
7340
|
+
custody = _b[_a];
|
7195
7341
|
custodyAccountMetas.push({
|
7196
7342
|
pubkey: custody.custodyAccount,
|
7197
7343
|
isSigner: false,
|
@@ -7203,8 +7349,8 @@ var PerpetualsClient = (function () {
|
|
7203
7349
|
isWritable: false,
|
7204
7350
|
});
|
7205
7351
|
}
|
7206
|
-
for (
|
7207
|
-
market = _c
|
7352
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
7353
|
+
market = _d[_c];
|
7208
7354
|
markets.push({
|
7209
7355
|
pubkey: market.marketAccount,
|
7210
7356
|
isSigner: false,
|
@@ -7213,26 +7359,26 @@ var PerpetualsClient = (function () {
|
|
7213
7359
|
}
|
7214
7360
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
7215
7361
|
case 1:
|
7216
|
-
if (!(
|
7362
|
+
if (!(_f.sent())) {
|
7217
7363
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
7218
7364
|
}
|
7219
7365
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
7220
7366
|
case 2:
|
7221
|
-
if (!(
|
7367
|
+
if (!(_f.sent())) {
|
7222
7368
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
7223
7369
|
}
|
7224
7370
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
7225
7371
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
7226
7372
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
7227
7373
|
if (!!skipBalanceChecks) return [3, 4];
|
7228
|
-
|
7374
|
+
_e = anchor_1.BN.bind;
|
7229
7375
|
return [4, this.provider.connection.getBalance(publicKey)];
|
7230
7376
|
case 3:
|
7231
|
-
unWrappedSolBalance = new (
|
7377
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
7232
7378
|
if (unWrappedSolBalance.lt(lamports)) {
|
7233
7379
|
throw "Insufficient SOL Funds";
|
7234
7380
|
}
|
7235
|
-
|
7381
|
+
_f.label = 4;
|
7236
7382
|
case 4:
|
7237
7383
|
if (!ephemeralSignerPubkey) {
|
7238
7384
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -7256,12 +7402,12 @@ var PerpetualsClient = (function () {
|
|
7256
7402
|
if (!!skipBalanceChecks) return [3, 7];
|
7257
7403
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
7258
7404
|
case 6:
|
7259
|
-
if (!(
|
7405
|
+
if (!(_f.sent())) {
|
7260
7406
|
throw "Insufficient Funds , token Account doesn't exist";
|
7261
7407
|
}
|
7262
|
-
|
7408
|
+
_f.label = 7;
|
7263
7409
|
case 7:
|
7264
|
-
|
7410
|
+
_f.trys.push([7, 9, , 10]);
|
7265
7411
|
return [4, this.program.methods
|
7266
7412
|
.addCompoundingLiquidity({
|
7267
7413
|
amountIn: amountIn,
|
@@ -7290,11 +7436,11 @@ var PerpetualsClient = (function () {
|
|
7290
7436
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7291
7437
|
.instruction()];
|
7292
7438
|
case 8:
|
7293
|
-
addCompoundingLiquidity =
|
7439
|
+
addCompoundingLiquidity = _f.sent();
|
7294
7440
|
instructions.push(addCompoundingLiquidity);
|
7295
7441
|
return [3, 10];
|
7296
7442
|
case 9:
|
7297
|
-
err_58 =
|
7443
|
+
err_58 = _f.sent();
|
7298
7444
|
console.log("perpClient addCompoundingLiquidity error:: ", err_58);
|
7299
7445
|
return [3, 10];
|
7300
7446
|
case 10: return [2, {
|
@@ -7305,15 +7451,20 @@ var PerpetualsClient = (function () {
|
|
7305
7451
|
});
|
7306
7452
|
});
|
7307
7453
|
};
|
7308
|
-
this.removeCompoundingLiquidity = function (
|
7309
|
-
|
7310
|
-
|
7311
|
-
|
7312
|
-
|
7313
|
-
|
7314
|
-
|
7454
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
7455
|
+
var args_1 = [];
|
7456
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
7457
|
+
args_1[_i - 5] = arguments[_i];
|
7458
|
+
}
|
7459
|
+
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
7460
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_59;
|
7461
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7462
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7463
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7464
|
+
return __generator(this, function (_f) {
|
7465
|
+
switch (_f.label) {
|
7315
7466
|
case 0:
|
7316
|
-
publicKey = this.provider.wallet.publicKey;
|
7467
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7317
7468
|
preInstructions = [];
|
7318
7469
|
instructions = [];
|
7319
7470
|
postInstructions = [];
|
@@ -7348,19 +7499,19 @@ var PerpetualsClient = (function () {
|
|
7348
7499
|
if (!_a) return [3, 3];
|
7349
7500
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
7350
7501
|
case 2:
|
7351
|
-
_a = !(
|
7352
|
-
|
7502
|
+
_a = !(_f.sent());
|
7503
|
+
_f.label = 3;
|
7353
7504
|
case 3:
|
7354
7505
|
if (_a) {
|
7355
7506
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
7356
7507
|
}
|
7357
|
-
|
7508
|
+
_f.label = 4;
|
7358
7509
|
case 4:
|
7359
7510
|
custodyAccountMetas = [];
|
7360
7511
|
custodyOracleAccountMetas = [];
|
7361
7512
|
markets = [];
|
7362
|
-
for (
|
7363
|
-
custody = _b
|
7513
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
7514
|
+
custody = _c[_b];
|
7364
7515
|
custodyAccountMetas.push({
|
7365
7516
|
pubkey: custody.custodyAccount,
|
7366
7517
|
isSigner: false,
|
@@ -7372,8 +7523,8 @@ var PerpetualsClient = (function () {
|
|
7372
7523
|
isWritable: false,
|
7373
7524
|
});
|
7374
7525
|
}
|
7375
|
-
for (
|
7376
|
-
market = _d
|
7526
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
7527
|
+
market = _e[_d];
|
7377
7528
|
markets.push({
|
7378
7529
|
pubkey: market.marketAccount,
|
7379
7530
|
isSigner: false,
|
@@ -7381,9 +7532,9 @@ var PerpetualsClient = (function () {
|
|
7381
7532
|
});
|
7382
7533
|
}
|
7383
7534
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
7384
|
-
|
7535
|
+
_f.label = 5;
|
7385
7536
|
case 5:
|
7386
|
-
|
7537
|
+
_f.trys.push([5, 7, , 8]);
|
7387
7538
|
return [4, this.program.methods
|
7388
7539
|
.removeCompoundingLiquidity({
|
7389
7540
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -7412,11 +7563,11 @@ var PerpetualsClient = (function () {
|
|
7412
7563
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7413
7564
|
.instruction()];
|
7414
7565
|
case 6:
|
7415
|
-
removeCompoundingLiquidity =
|
7566
|
+
removeCompoundingLiquidity = _f.sent();
|
7416
7567
|
instructions.push(removeCompoundingLiquidity);
|
7417
7568
|
return [3, 8];
|
7418
7569
|
case 7:
|
7419
|
-
err_59 =
|
7570
|
+
err_59 = _f.sent();
|
7420
7571
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_59);
|
7421
7572
|
return [3, 8];
|
7422
7573
|
case 8: return [2, {
|
@@ -7427,12 +7578,16 @@ var PerpetualsClient = (function () {
|
|
7427
7578
|
});
|
7428
7579
|
});
|
7429
7580
|
};
|
7430
|
-
this.migrateStake = function (
|
7431
|
-
|
7432
|
-
|
7433
|
-
|
7434
|
-
|
7435
|
-
|
7581
|
+
this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
|
7582
|
+
var args_1 = [];
|
7583
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
7584
|
+
args_1[_i - 3] = arguments[_i];
|
7585
|
+
}
|
7586
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
7587
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, migrateStake, err_60;
|
7588
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
7589
|
+
return __generator(this, function (_g) {
|
7590
|
+
switch (_g.label) {
|
7436
7591
|
case 0:
|
7437
7592
|
publicKey = this.provider.wallet.publicKey;
|
7438
7593
|
preInstructions = [];
|
@@ -7447,8 +7602,8 @@ var PerpetualsClient = (function () {
|
|
7447
7602
|
if (!_a) return [3, 2];
|
7448
7603
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
7449
7604
|
case 1:
|
7450
|
-
_a = !(
|
7451
|
-
|
7605
|
+
_a = !(_g.sent());
|
7606
|
+
_g.label = 2;
|
7452
7607
|
case 2:
|
7453
7608
|
if (_a) {
|
7454
7609
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -7460,8 +7615,8 @@ var PerpetualsClient = (function () {
|
|
7460
7615
|
if (!_b) return [3, 4];
|
7461
7616
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
7462
7617
|
case 3:
|
7463
|
-
_b = (
|
7464
|
-
|
7618
|
+
_b = (_g.sent());
|
7619
|
+
_g.label = 4;
|
7465
7620
|
case 4:
|
7466
7621
|
if (_b) {
|
7467
7622
|
tokenStakeAccounts.push({
|
@@ -7474,8 +7629,8 @@ var PerpetualsClient = (function () {
|
|
7474
7629
|
custodyAccountMetas = [];
|
7475
7630
|
custodyOracleAccountMetas = [];
|
7476
7631
|
markets = [];
|
7477
|
-
for (
|
7478
|
-
custody = _c
|
7632
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
7633
|
+
custody = _d[_c];
|
7479
7634
|
custodyAccountMetas.push({
|
7480
7635
|
pubkey: custody.custodyAccount,
|
7481
7636
|
isSigner: false,
|
@@ -7487,17 +7642,17 @@ var PerpetualsClient = (function () {
|
|
7487
7642
|
isWritable: false,
|
7488
7643
|
});
|
7489
7644
|
}
|
7490
|
-
for (
|
7491
|
-
market = _e
|
7645
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
7646
|
+
market = _f[_e];
|
7492
7647
|
markets.push({
|
7493
7648
|
pubkey: market.marketAccount,
|
7494
7649
|
isSigner: false,
|
7495
7650
|
isWritable: false,
|
7496
7651
|
});
|
7497
7652
|
}
|
7498
|
-
|
7653
|
+
_g.label = 5;
|
7499
7654
|
case 5:
|
7500
|
-
|
7655
|
+
_g.trys.push([5, 7, , 8]);
|
7501
7656
|
return [4, this.program.methods
|
7502
7657
|
.migrateStake({
|
7503
7658
|
amount: amount
|
@@ -7523,11 +7678,11 @@ var PerpetualsClient = (function () {
|
|
7523
7678
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
7524
7679
|
.instruction()];
|
7525
7680
|
case 6:
|
7526
|
-
migrateStake =
|
7681
|
+
migrateStake = _g.sent();
|
7527
7682
|
instructions.push(migrateStake);
|
7528
7683
|
return [3, 8];
|
7529
7684
|
case 7:
|
7530
|
-
err_60 =
|
7685
|
+
err_60 = _g.sent();
|
7531
7686
|
console.log("perpClient migrateStake error:: ", err_60);
|
7532
7687
|
return [3, 8];
|
7533
7688
|
case 8: return [2, {
|
@@ -7621,12 +7776,16 @@ var PerpetualsClient = (function () {
|
|
7621
7776
|
}
|
7622
7777
|
});
|
7623
7778
|
}); };
|
7624
|
-
this.compoundingFee = function (
|
7625
|
-
|
7626
|
-
|
7627
|
-
|
7628
|
-
|
7629
|
-
|
7779
|
+
this.compoundingFee = function (poolConfig_1) {
|
7780
|
+
var args_1 = [];
|
7781
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
7782
|
+
args_1[_i - 1] = arguments[_i];
|
7783
|
+
}
|
7784
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
7785
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_62;
|
7786
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
7787
|
+
return __generator(this, function (_e) {
|
7788
|
+
switch (_e.label) {
|
7630
7789
|
case 0:
|
7631
7790
|
instructions = [];
|
7632
7791
|
additionalSigners = [];
|
@@ -7635,8 +7794,8 @@ var PerpetualsClient = (function () {
|
|
7635
7794
|
custodyAccountMetas = [];
|
7636
7795
|
custodyOracleAccountMetas = [];
|
7637
7796
|
markets = [];
|
7638
|
-
for (
|
7639
|
-
custody = _a
|
7797
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
7798
|
+
custody = _b[_a];
|
7640
7799
|
custodyAccountMetas.push({
|
7641
7800
|
pubkey: custody.custodyAccount,
|
7642
7801
|
isSigner: false,
|
@@ -7648,17 +7807,17 @@ var PerpetualsClient = (function () {
|
|
7648
7807
|
isWritable: false,
|
7649
7808
|
});
|
7650
7809
|
}
|
7651
|
-
for (
|
7652
|
-
market = _c
|
7810
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
7811
|
+
market = _d[_c];
|
7653
7812
|
markets.push({
|
7654
7813
|
pubkey: market.marketAccount,
|
7655
7814
|
isSigner: false,
|
7656
7815
|
isWritable: false,
|
7657
7816
|
});
|
7658
7817
|
}
|
7659
|
-
|
7818
|
+
_e.label = 1;
|
7660
7819
|
case 1:
|
7661
|
-
|
7820
|
+
_e.trys.push([1, 3, , 4]);
|
7662
7821
|
return [4, this.program.methods
|
7663
7822
|
.compoundFees({})
|
7664
7823
|
.accounts({
|
@@ -7677,11 +7836,11 @@ var PerpetualsClient = (function () {
|
|
7677
7836
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
7678
7837
|
.instruction()];
|
7679
7838
|
case 2:
|
7680
|
-
compoundingFee =
|
7839
|
+
compoundingFee = _e.sent();
|
7681
7840
|
instructions.push(compoundingFee);
|
7682
7841
|
return [3, 4];
|
7683
7842
|
case 3:
|
7684
|
-
err_62 =
|
7843
|
+
err_62 = _e.sent();
|
7685
7844
|
console.log("perpClient compoundingFee error:: ", err_62);
|
7686
7845
|
return [3, 4];
|
7687
7846
|
case 4: return [2, {
|
@@ -7842,9 +8001,9 @@ var PerpetualsClient = (function () {
|
|
7842
8001
|
}
|
7843
8002
|
}
|
7844
8003
|
};
|
7845
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
7846
|
-
|
7847
|
-
|
8004
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
|
8005
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8006
|
+
if (opts === void 0) { opts = {}; }
|
7848
8007
|
return __generator(this, function (_a) {
|
7849
8008
|
switch (_a.label) {
|
7850
8009
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -7853,9 +8012,9 @@ var PerpetualsClient = (function () {
|
|
7853
8012
|
});
|
7854
8013
|
});
|
7855
8014
|
};
|
7856
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
7857
|
-
|
7858
|
-
|
8015
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
|
8016
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8017
|
+
if (opts === void 0) { opts = {}; }
|
7859
8018
|
return __generator(this, function (_a) {
|
7860
8019
|
switch (_a.label) {
|
7861
8020
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|