flash-sdk 2.46.6 → 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/OraclePrice.d.ts +1 -0
- package/dist/OrderAccount.d.ts +1 -0
- package/dist/PerpetualsClient.d.ts +11 -9
- package/dist/PerpetualsClient.js +380 -341
- package/dist/PoolAccount.d.ts +1 -0
- package/dist/PoolDataClient.d.ts +1 -0
- package/dist/PositionAccount.d.ts +1 -0
- package/dist/TokenVaultAccount.d.ts +1 -0
- package/dist/TradingAccount.d.ts +1 -0
- package/dist/ViewHelper.d.ts +2 -2
- package/dist/ViewHelper.js +6 -5
- package/dist/backupOracle.js +4 -4
- package/dist/constants/index.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -3
- package/dist/utils/IdlCoder.js +7 -17
- package/dist/utils/alt.js +6 -5
- package/dist/utils/anchorCpiEvents.d.ts +1 -0
- package/dist/utils/anchorCpiEvents.js +4 -4
- package/dist/utils/index.js +6 -6
- package/dist/utils/rpc.js +9 -9
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
20
20
|
});
|
21
21
|
};
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g
|
24
|
-
return g
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
26
|
function step(op) {
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
@@ -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) {
|
@@ -4111,14 +4139,15 @@ var PerpetualsClient = (function () {
|
|
4111
4139
|
for (var _i = 4; _i < arguments.length; _i++) {
|
4112
4140
|
args_1[_i - 4] = arguments[_i];
|
4113
4141
|
}
|
4114
|
-
return __awaiter(_this, __spreadArray([inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
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) {
|
4115
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;
|
4116
4144
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4117
4145
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4146
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4118
4147
|
return __generator(this, function (_g) {
|
4119
4148
|
switch (_g.label) {
|
4120
4149
|
case 0:
|
4121
|
-
publicKey = this.provider.wallet.publicKey;
|
4150
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4122
4151
|
preInstructions = [];
|
4123
4152
|
instructions = [];
|
4124
4153
|
postInstructions = [];
|
@@ -4245,12 +4274,13 @@ var PerpetualsClient = (function () {
|
|
4245
4274
|
for (var _i = 4; _i < arguments.length; _i++) {
|
4246
4275
|
args_1[_i - 4] = arguments[_i];
|
4247
4276
|
}
|
4248
|
-
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) {
|
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) {
|
4249
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;
|
4250
4279
|
if (closeLpATA === void 0) { closeLpATA = false; }
|
4251
4280
|
if (createUserATA === void 0) { createUserATA = true; }
|
4252
4281
|
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
4253
4282
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4283
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4254
4284
|
return __generator(this, function (_f) {
|
4255
4285
|
switch (_f.label) {
|
4256
4286
|
case 0:
|
@@ -4258,7 +4288,7 @@ var PerpetualsClient = (function () {
|
|
4258
4288
|
if (!recieveTokenCustodyConfig) {
|
4259
4289
|
throw "recieveTokenCustody not found";
|
4260
4290
|
}
|
4261
|
-
publicKey = this.provider.wallet.publicKey;
|
4291
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4262
4292
|
preInstructions = [];
|
4263
4293
|
instructions = [];
|
4264
4294
|
postInstructions = [];
|
@@ -4778,61 +4808,68 @@ var PerpetualsClient = (function () {
|
|
4778
4808
|
}
|
4779
4809
|
});
|
4780
4810
|
}); };
|
4781
|
-
this.refreshStakeWithTokenStake = function (
|
4782
|
-
var
|
4783
|
-
|
4784
|
-
|
4785
|
-
|
4786
|
-
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
|
4795
|
-
|
4796
|
-
|
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,
|
4797
4846
|
isSigner: false,
|
4798
4847
|
isWritable: false,
|
4799
4848
|
});
|
4800
|
-
|
4801
|
-
|
4802
|
-
|
4803
|
-
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4807
|
-
|
4808
|
-
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
})
|
4823
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4824
|
-
.instruction()];
|
4825
|
-
case 1:
|
4826
|
-
refreshStakeInstruction = _b.sent();
|
4827
|
-
return [2, refreshStakeInstruction];
|
4828
|
-
case 2:
|
4829
|
-
err_16 = _b.sent();
|
4830
|
-
console.log("perpClient refreshStaking error:: ", err_16);
|
4831
|
-
throw err_16;
|
4832
|
-
case 3: return [2];
|
4833
|
-
}
|
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
|
+
});
|
4834
4871
|
});
|
4835
|
-
}
|
4872
|
+
};
|
4836
4873
|
this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4837
4874
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_17;
|
4838
4875
|
return __generator(this, function (_b) {
|
@@ -7276,14 +7313,15 @@ var PerpetualsClient = (function () {
|
|
7276
7313
|
for (var _i = 5; _i < arguments.length; _i++) {
|
7277
7314
|
args_1[_i - 5] = arguments[_i];
|
7278
7315
|
}
|
7279
|
-
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) {
|
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) {
|
7280
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;
|
7281
7318
|
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
7282
7319
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7320
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7283
7321
|
return __generator(this, function (_f) {
|
7284
7322
|
switch (_f.label) {
|
7285
7323
|
case 0:
|
7286
|
-
publicKey = this.provider.wallet.publicKey;
|
7324
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7287
7325
|
preInstructions = [];
|
7288
7326
|
instructions = [];
|
7289
7327
|
additionalSigners = [];
|
@@ -7418,14 +7456,15 @@ var PerpetualsClient = (function () {
|
|
7418
7456
|
for (var _i = 5; _i < arguments.length; _i++) {
|
7419
7457
|
args_1[_i - 5] = arguments[_i];
|
7420
7458
|
}
|
7421
|
-
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) {
|
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) {
|
7422
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;
|
7423
7461
|
if (createUserATA === void 0) { createUserATA = true; }
|
7424
7462
|
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
7463
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
7425
7464
|
return __generator(this, function (_f) {
|
7426
7465
|
switch (_f.label) {
|
7427
7466
|
case 0:
|
7428
|
-
publicKey = this.provider.wallet.publicKey;
|
7467
|
+
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
7429
7468
|
preInstructions = [];
|
7430
7469
|
instructions = [];
|
7431
7470
|
postInstructions = [];
|