flash-sdk 2.52.3 → 2.54.0
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/CustodyAccount.d.ts +1 -1
- package/dist/PerpetualsClient.d.ts +93 -32
- package/dist/PerpetualsClient.js +776 -932
- package/dist/PoolAccount.d.ts +6 -0
- package/dist/PoolConfig.d.ts +1 -0
- package/dist/PoolConfig.json +112 -58
- package/dist/ViewHelper.js +3 -3
- package/dist/backupOracle.js +3 -3
- package/dist/idl/perpetuals.d.ts +380 -69
- package/dist/idl/perpetuals.js +380 -69
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/alt.d.ts +1 -0
- package/dist/utils/rpc.js +50 -50
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -1816,15 +1816,11 @@ var PerpetualsClient = (function () {
|
|
1816
1816
|
}
|
1817
1817
|
return finalIndexPriceAtT1.toString();
|
1818
1818
|
};
|
1819
|
-
this.getUserClaimableRevenueAmount = function (
|
1820
|
-
|
1821
|
-
|
1822
|
-
args_1[_i - 2] = arguments[_i];
|
1823
|
-
}
|
1824
|
-
return __awaiter(_this, __spreadArray([POOL_CONFIG_1, userPublicKey_1], args_1, true), void 0, function (POOL_CONFIG, userPublicKey, enableDebuglogs) {
|
1819
|
+
this.getUserClaimableRevenueAmount = function (POOL_CONFIG, userPublicKey, enableDebuglogs) {
|
1820
|
+
if (enableDebuglogs === void 0) { enableDebuglogs = false; }
|
1821
|
+
return __awaiter(_this, void 0, void 0, function () {
|
1825
1822
|
var fafTokenVaultPk, fafTokenVaultAccountInfo, fafTokenVaultAccount, fafTokenVault, tokenStakeAccount, accountInfo, fafStakeData, tokenStakeFafAccount, activeStakeAmount, revenuePerFafStaked, revenueWatermark, revenueSnapshot, unclaimedRevenue, revenueAmount;
|
1826
1823
|
var _a, _b, _c, _d;
|
1827
|
-
if (enableDebuglogs === void 0) { enableDebuglogs = false; }
|
1828
1824
|
return __generator(this, function (_e) {
|
1829
1825
|
switch (_e.label) {
|
1830
1826
|
case 0:
|
@@ -1981,38 +1977,34 @@ var PerpetualsClient = (function () {
|
|
1981
1977
|
}
|
1982
1978
|
});
|
1983
1979
|
}); };
|
1984
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_5, token, _b, custodies_6, custody, _c, _d, market, depositCustodyConfig, transaction, result, index, res;
|
1991
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
1992
|
-
return __generator(this, function (_e) {
|
1993
|
-
switch (_e.label) {
|
1980
|
+
this.getAddLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
1981
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
1982
|
+
return __awaiter(_this, void 0, void 0, function () {
|
1983
|
+
var custodies, custodyMetas, marketMetas, _i, custodies_5, token, _a, custodies_6, custody, _b, _c, market, depositCustodyConfig, transaction, result, index, res;
|
1984
|
+
return __generator(this, function (_d) {
|
1985
|
+
switch (_d.label) {
|
1994
1986
|
case 0:
|
1995
1987
|
custodies = POOL_CONFIG.custodies;
|
1996
1988
|
custodyMetas = [];
|
1997
1989
|
marketMetas = [];
|
1998
|
-
for (
|
1999
|
-
token = custodies_5[
|
1990
|
+
for (_i = 0, custodies_5 = custodies; _i < custodies_5.length; _i++) {
|
1991
|
+
token = custodies_5[_i];
|
2000
1992
|
custodyMetas.push({
|
2001
1993
|
isSigner: false,
|
2002
1994
|
isWritable: false,
|
2003
1995
|
pubkey: token.custodyAccount,
|
2004
1996
|
});
|
2005
1997
|
}
|
2006
|
-
for (
|
2007
|
-
custody = custodies_6[
|
1998
|
+
for (_a = 0, custodies_6 = custodies; _a < custodies_6.length; _a++) {
|
1999
|
+
custody = custodies_6[_a];
|
2008
2000
|
custodyMetas.push({
|
2009
2001
|
isSigner: false,
|
2010
2002
|
isWritable: false,
|
2011
2003
|
pubkey: custody.intOracleAccount,
|
2012
2004
|
});
|
2013
2005
|
}
|
2014
|
-
for (
|
2015
|
-
market =
|
2006
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2007
|
+
market = _c[_b];
|
2016
2008
|
marketMetas.push({
|
2017
2009
|
pubkey: market.marketAccount,
|
2018
2010
|
isSigner: false,
|
@@ -2035,10 +2027,10 @@ var PerpetualsClient = (function () {
|
|
2035
2027
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2036
2028
|
.transaction()];
|
2037
2029
|
case 1:
|
2038
|
-
transaction =
|
2030
|
+
transaction = _d.sent();
|
2039
2031
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2040
2032
|
case 2:
|
2041
|
-
result =
|
2033
|
+
result = _d.sent();
|
2042
2034
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2043
2035
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2044
2036
|
return [2, {
|
@@ -2049,38 +2041,34 @@ var PerpetualsClient = (function () {
|
|
2049
2041
|
});
|
2050
2042
|
});
|
2051
2043
|
};
|
2052
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_7, token, _b, custodies_8, custody, _c, _d, market, removeCustodyConfig, transaction, result, index, res;
|
2059
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2060
|
-
return __generator(this, function (_e) {
|
2061
|
-
switch (_e.label) {
|
2044
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2045
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2046
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2047
|
+
var custodies, custodyMetas, marketMetas, _i, custodies_7, token, _a, custodies_8, custody, _b, _c, market, removeCustodyConfig, transaction, result, index, res;
|
2048
|
+
return __generator(this, function (_d) {
|
2049
|
+
switch (_d.label) {
|
2062
2050
|
case 0:
|
2063
2051
|
custodies = POOL_CONFIG.custodies;
|
2064
2052
|
custodyMetas = [];
|
2065
2053
|
marketMetas = [];
|
2066
|
-
for (
|
2067
|
-
token = custodies_7[
|
2054
|
+
for (_i = 0, custodies_7 = custodies; _i < custodies_7.length; _i++) {
|
2055
|
+
token = custodies_7[_i];
|
2068
2056
|
custodyMetas.push({
|
2069
2057
|
isSigner: false,
|
2070
2058
|
isWritable: false,
|
2071
2059
|
pubkey: token.custodyAccount,
|
2072
2060
|
});
|
2073
2061
|
}
|
2074
|
-
for (
|
2075
|
-
custody = custodies_8[
|
2062
|
+
for (_a = 0, custodies_8 = custodies; _a < custodies_8.length; _a++) {
|
2063
|
+
custody = custodies_8[_a];
|
2076
2064
|
custodyMetas.push({
|
2077
2065
|
isSigner: false,
|
2078
2066
|
isWritable: false,
|
2079
2067
|
pubkey: custody.intOracleAccount,
|
2080
2068
|
});
|
2081
2069
|
}
|
2082
|
-
for (
|
2083
|
-
market =
|
2070
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2071
|
+
market = _c[_b];
|
2084
2072
|
marketMetas.push({
|
2085
2073
|
pubkey: market.marketAccount,
|
2086
2074
|
isSigner: false,
|
@@ -2103,10 +2091,10 @@ var PerpetualsClient = (function () {
|
|
2103
2091
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2104
2092
|
.transaction()];
|
2105
2093
|
case 1:
|
2106
|
-
transaction =
|
2094
|
+
transaction = _d.sent();
|
2107
2095
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2108
2096
|
case 2:
|
2109
|
-
result =
|
2097
|
+
result = _d.sent();
|
2110
2098
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2111
2099
|
if (result.value.err) {
|
2112
2100
|
return [2, {
|
@@ -2182,38 +2170,34 @@ var PerpetualsClient = (function () {
|
|
2182
2170
|
}
|
2183
2171
|
});
|
2184
2172
|
}); };
|
2185
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_11, token, _b, custodies_12, custody, _c, _d, market, depositCustodyConfig, rewardCustody, transaction, result, index, res;
|
2192
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2193
|
-
return __generator(this, function (_e) {
|
2194
|
-
switch (_e.label) {
|
2173
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
2174
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2175
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2176
|
+
var custodies, custodyMetas, marketMetas, _i, custodies_11, token, _a, custodies_12, custody, _b, _c, market, depositCustodyConfig, rewardCustody, transaction, result, index, res;
|
2177
|
+
return __generator(this, function (_d) {
|
2178
|
+
switch (_d.label) {
|
2195
2179
|
case 0:
|
2196
2180
|
custodies = POOL_CONFIG.custodies;
|
2197
2181
|
custodyMetas = [];
|
2198
2182
|
marketMetas = [];
|
2199
|
-
for (
|
2200
|
-
token = custodies_11[
|
2183
|
+
for (_i = 0, custodies_11 = custodies; _i < custodies_11.length; _i++) {
|
2184
|
+
token = custodies_11[_i];
|
2201
2185
|
custodyMetas.push({
|
2202
2186
|
isSigner: false,
|
2203
2187
|
isWritable: false,
|
2204
2188
|
pubkey: token.custodyAccount,
|
2205
2189
|
});
|
2206
2190
|
}
|
2207
|
-
for (
|
2208
|
-
custody = custodies_12[
|
2191
|
+
for (_a = 0, custodies_12 = custodies; _a < custodies_12.length; _a++) {
|
2192
|
+
custody = custodies_12[_a];
|
2209
2193
|
custodyMetas.push({
|
2210
2194
|
isSigner: false,
|
2211
2195
|
isWritable: false,
|
2212
2196
|
pubkey: custody.intOracleAccount,
|
2213
2197
|
});
|
2214
2198
|
}
|
2215
|
-
for (
|
2216
|
-
market =
|
2199
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2200
|
+
market = _c[_b];
|
2217
2201
|
marketMetas.push({
|
2218
2202
|
pubkey: market.marketAccount,
|
2219
2203
|
isSigner: false,
|
@@ -2240,10 +2224,10 @@ var PerpetualsClient = (function () {
|
|
2240
2224
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2241
2225
|
.transaction()];
|
2242
2226
|
case 1:
|
2243
|
-
transaction =
|
2227
|
+
transaction = _d.sent();
|
2244
2228
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2245
2229
|
case 2:
|
2246
|
-
result =
|
2230
|
+
result = _d.sent();
|
2247
2231
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2248
2232
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2249
2233
|
return [2, {
|
@@ -2254,38 +2238,34 @@ var PerpetualsClient = (function () {
|
|
2254
2238
|
});
|
2255
2239
|
});
|
2256
2240
|
};
|
2257
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
var custodies, custodyMetas, marketMetas, _a, custodies_13, token, _b, custodies_14, custody, _c, _d, market, removeCustodyConfig, rewardCustody, transaction, result, index, res;
|
2264
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2265
|
-
return __generator(this, function (_e) {
|
2266
|
-
switch (_e.label) {
|
2241
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
2242
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
2243
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2244
|
+
var custodies, custodyMetas, marketMetas, _i, custodies_13, token, _a, custodies_14, custody, _b, _c, market, removeCustodyConfig, rewardCustody, transaction, result, index, res;
|
2245
|
+
return __generator(this, function (_d) {
|
2246
|
+
switch (_d.label) {
|
2267
2247
|
case 0:
|
2268
2248
|
custodies = POOL_CONFIG.custodies;
|
2269
2249
|
custodyMetas = [];
|
2270
2250
|
marketMetas = [];
|
2271
|
-
for (
|
2272
|
-
token = custodies_13[
|
2251
|
+
for (_i = 0, custodies_13 = custodies; _i < custodies_13.length; _i++) {
|
2252
|
+
token = custodies_13[_i];
|
2273
2253
|
custodyMetas.push({
|
2274
2254
|
isSigner: false,
|
2275
2255
|
isWritable: false,
|
2276
2256
|
pubkey: token.custodyAccount,
|
2277
2257
|
});
|
2278
2258
|
}
|
2279
|
-
for (
|
2280
|
-
custody = custodies_14[
|
2259
|
+
for (_a = 0, custodies_14 = custodies; _a < custodies_14.length; _a++) {
|
2260
|
+
custody = custodies_14[_a];
|
2281
2261
|
custodyMetas.push({
|
2282
2262
|
isSigner: false,
|
2283
2263
|
isWritable: false,
|
2284
2264
|
pubkey: custody.intOracleAccount,
|
2285
2265
|
});
|
2286
2266
|
}
|
2287
|
-
for (
|
2288
|
-
market =
|
2267
|
+
for (_b = 0, _c = POOL_CONFIG.markets; _b < _c.length; _b++) {
|
2268
|
+
market = _c[_b];
|
2289
2269
|
marketMetas.push({
|
2290
2270
|
pubkey: market.marketAccount,
|
2291
2271
|
isSigner: false,
|
@@ -2312,10 +2292,10 @@ var PerpetualsClient = (function () {
|
|
2312
2292
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2313
2293
|
.transaction()];
|
2314
2294
|
case 1:
|
2315
|
-
transaction =
|
2295
|
+
transaction = _d.sent();
|
2316
2296
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2317
2297
|
case 2:
|
2318
|
-
result =
|
2298
|
+
result = _d.sent();
|
2319
2299
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2320
2300
|
if (result.value.err) {
|
2321
2301
|
return [2, {
|
@@ -2496,45 +2476,40 @@ var PerpetualsClient = (function () {
|
|
2496
2476
|
}
|
2497
2477
|
});
|
2498
2478
|
}); };
|
2499
|
-
this.openPosition = function (
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
}
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2508
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2509
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2510
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2479
|
+
this.openPosition = function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2480
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2481
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2482
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2483
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2484
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2485
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2486
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, collateralToken, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2511
2487
|
return __generator(this, function (_c) {
|
2512
2488
|
switch (_c.label) {
|
2513
2489
|
case 0:
|
2514
2490
|
publicKey = this.provider.wallet.publicKey;
|
2515
2491
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
2516
2492
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
2493
|
+
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
2517
2494
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
2518
|
-
|
2519
|
-
case 1:
|
2520
|
-
userCollateralTokenAccount = _c.sent();
|
2495
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2521
2496
|
preInstructions = [];
|
2522
2497
|
instructions = [];
|
2523
2498
|
postInstructions = [];
|
2524
2499
|
additionalSigners = [];
|
2525
|
-
if (!(collateralSymbol == 'SOL')) return [3,
|
2500
|
+
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
2526
2501
|
console.log("collateralSymbol === SOL", collateralSymbol);
|
2527
2502
|
lamports = collateralWithfee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
2528
|
-
if (!!skipBalanceChecks) return [3,
|
2503
|
+
if (!!skipBalanceChecks) return [3, 2];
|
2529
2504
|
_a = anchor_1.BN.bind;
|
2530
2505
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2531
|
-
case
|
2506
|
+
case 1:
|
2532
2507
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
2533
2508
|
if (unWrappedSolBalance.lt(lamports)) {
|
2534
2509
|
throw "Insufficient SOL Funds";
|
2535
2510
|
}
|
2536
|
-
_c.label =
|
2537
|
-
case
|
2511
|
+
_c.label = 2;
|
2512
|
+
case 2:
|
2538
2513
|
if (!ephemeralSignerPubkey) {
|
2539
2514
|
wrappedSolAccount = new web3_js_1.Keypair();
|
2540
2515
|
additionalSigners.push(wrappedSolAccount);
|
@@ -2552,23 +2527,23 @@ var PerpetualsClient = (function () {
|
|
2552
2527
|
postInstructions = [
|
2553
2528
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2554
2529
|
];
|
2555
|
-
return [3,
|
2556
|
-
case
|
2557
|
-
if (!!skipBalanceChecks) return [3,
|
2530
|
+
return [3, 6];
|
2531
|
+
case 3:
|
2532
|
+
if (!!skipBalanceChecks) return [3, 6];
|
2558
2533
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2559
|
-
case
|
2534
|
+
case 4:
|
2560
2535
|
if (!(_c.sent())) {
|
2561
2536
|
throw "Insufficient Funds , token Account doesn't exist";
|
2562
2537
|
}
|
2563
2538
|
_b = anchor_1.BN.bind;
|
2564
2539
|
return [4, this.provider.connection.getTokenAccountBalance(userCollateralTokenAccount)];
|
2565
|
-
case
|
2540
|
+
case 5:
|
2566
2541
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
2567
2542
|
if (tokenAccountBalance.lt(collateralWithfee)) {
|
2568
2543
|
throw "Insufficient Funds need more ".concat(collateralWithfee.sub(tokenAccountBalance), " tokens");
|
2569
2544
|
}
|
2570
|
-
_c.label =
|
2571
|
-
case
|
2545
|
+
_c.label = 6;
|
2546
|
+
case 6:
|
2572
2547
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
2573
2548
|
params = {
|
2574
2549
|
priceWithSlippage: priceWithSlippage,
|
@@ -2596,11 +2571,12 @@ var PerpetualsClient = (function () {
|
|
2596
2571
|
eventAuthority: this.eventAuthority.publicKey,
|
2597
2572
|
program: this.programId,
|
2598
2573
|
transferAuthority: this.authority.publicKey,
|
2599
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2574
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2575
|
+
fundingMint: collateralCustodyConfig.mintKey
|
2600
2576
|
})
|
2601
2577
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
2602
2578
|
.instruction()];
|
2603
|
-
case
|
2579
|
+
case 7:
|
2604
2580
|
instruction = _c.sent();
|
2605
2581
|
instructions.push(instruction);
|
2606
2582
|
return [2, {
|
@@ -2611,19 +2587,15 @@ var PerpetualsClient = (function () {
|
|
2611
2587
|
});
|
2612
2588
|
});
|
2613
2589
|
};
|
2614
|
-
this.closePosition = function (
|
2615
|
-
|
2616
|
-
|
2617
|
-
|
2618
|
-
}
|
2619
|
-
|
2590
|
+
this.closePosition = function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2591
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2592
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2593
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2594
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
2595
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2596
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2597
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2620
2598
|
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, instruction, closeWsolATAIns, error_1;
|
2621
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2622
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2623
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2624
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
2625
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
2626
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2627
2599
|
return __generator(this, function (_b) {
|
2628
2600
|
switch (_b.label) {
|
2629
2601
|
case 0:
|
@@ -2657,7 +2629,7 @@ var PerpetualsClient = (function () {
|
|
2657
2629
|
];
|
2658
2630
|
return [3, 5];
|
2659
2631
|
case 2:
|
2660
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
2632
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2661
2633
|
_a = createUserATA;
|
2662
2634
|
if (!_a) return [3, 4];
|
2663
2635
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -2666,7 +2638,7 @@ var PerpetualsClient = (function () {
|
|
2666
2638
|
_b.label = 4;
|
2667
2639
|
case 4:
|
2668
2640
|
if (_a) {
|
2669
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
2641
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2670
2642
|
}
|
2671
2643
|
_b.label = 5;
|
2672
2644
|
case 5:
|
@@ -2696,7 +2668,7 @@ var PerpetualsClient = (function () {
|
|
2696
2668
|
eventAuthority: this.eventAuthority.publicKey,
|
2697
2669
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2698
2670
|
program: this.programId,
|
2699
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2671
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2700
2672
|
})
|
2701
2673
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
2702
2674
|
.instruction()];
|
@@ -2720,18 +2692,14 @@ var PerpetualsClient = (function () {
|
|
2720
2692
|
});
|
2721
2693
|
});
|
2722
2694
|
};
|
2723
|
-
this.swapAndOpen = function (
|
2724
|
-
|
2725
|
-
|
2726
|
-
|
2727
|
-
}
|
2728
|
-
|
2729
|
-
|
2730
|
-
|
2731
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2732
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2733
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2734
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2695
|
+
this.swapAndOpen = function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2696
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2697
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2698
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2699
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2700
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2701
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2702
|
+
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
|
2735
2703
|
return __generator(this, function (_c) {
|
2736
2704
|
switch (_c.label) {
|
2737
2705
|
case 0:
|
@@ -2757,6 +2725,8 @@ var PerpetualsClient = (function () {
|
|
2757
2725
|
instructions = [];
|
2758
2726
|
postInstructions = [];
|
2759
2727
|
additionalSigners = [];
|
2728
|
+
targetToken = poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol);
|
2729
|
+
userInputToken = poolConfig.getTokenFromSymbol(userInputTokenSymbol);
|
2760
2730
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 5];
|
2761
2731
|
console.log("inputSymbol === SOL", userInputTokenSymbol);
|
2762
2732
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
@@ -2788,7 +2758,7 @@ var PerpetualsClient = (function () {
|
|
2788
2758
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2789
2759
|
];
|
2790
2760
|
if (!!poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey.equals(spl_token_1.NATIVE_MINT)) return [3, 4];
|
2791
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
|
2761
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2792
2762
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
2793
2763
|
case 3:
|
2794
2764
|
if (!(_c.sent())) {
|
@@ -2797,7 +2767,7 @@ var PerpetualsClient = (function () {
|
|
2797
2767
|
_c.label = 4;
|
2798
2768
|
case 4: return [3, 10];
|
2799
2769
|
case 5:
|
2800
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
2770
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2801
2771
|
if (!!skipBalanceChecks) return [3, 8];
|
2802
2772
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
2803
2773
|
case 6:
|
@@ -2813,15 +2783,22 @@ var PerpetualsClient = (function () {
|
|
2813
2783
|
}
|
2814
2784
|
_c.label = 8;
|
2815
2785
|
case 8:
|
2816
|
-
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true);
|
2786
|
+
userOutputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2817
2787
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
2818
2788
|
case 9:
|
2819
2789
|
if (!(_c.sent())) {
|
2820
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey));
|
2790
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).mintKey, poolConfig.getTokenFromSymbol(targetCustodyConfig.symbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2821
2791
|
}
|
2822
2792
|
_c.label = 10;
|
2823
2793
|
case 10:
|
2824
|
-
|
2794
|
+
rebateMintAccount = {
|
2795
|
+
pubkey: collateralCustodyConfig.mintKey,
|
2796
|
+
isSigner: false,
|
2797
|
+
isWritable: false
|
2798
|
+
};
|
2799
|
+
_c.label = 11;
|
2800
|
+
case 11:
|
2801
|
+
_c.trys.push([11, 13, , 14]);
|
2825
2802
|
return [4, this.program.methods
|
2826
2803
|
.swapAndOpen({
|
2827
2804
|
amountIn: amountIn,
|
@@ -2848,22 +2825,24 @@ var PerpetualsClient = (function () {
|
|
2848
2825
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
2849
2826
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
2850
2827
|
systemProgram: web3_js_1.SystemProgram.programId,
|
2851
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2828
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
2852
2829
|
eventAuthority: this.eventAuthority.publicKey,
|
2853
2830
|
program: this.programId,
|
2854
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2831
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2832
|
+
fundingMint: userInputCustodyConfig.mintKey,
|
2833
|
+
fundingTokenProgram: targetToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2855
2834
|
})
|
2856
2835
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
2857
2836
|
.instruction()];
|
2858
|
-
case
|
2837
|
+
case 12:
|
2859
2838
|
inx = _c.sent();
|
2860
2839
|
instructions.push(inx);
|
2861
|
-
return [3,
|
2862
|
-
case
|
2840
|
+
return [3, 14];
|
2841
|
+
case 13:
|
2863
2842
|
err_3 = _c.sent();
|
2864
2843
|
console.error("perpClient SwapAndOpen error:: ", err_3);
|
2865
2844
|
throw err_3;
|
2866
|
-
case
|
2845
|
+
case 14: return [2, {
|
2867
2846
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2868
2847
|
additionalSigners: additionalSigners
|
2869
2848
|
}];
|
@@ -2871,17 +2850,13 @@ var PerpetualsClient = (function () {
|
|
2871
2850
|
});
|
2872
2851
|
});
|
2873
2852
|
};
|
2874
|
-
this.closeAndSwap = function (
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
}
|
2879
|
-
return __awaiter(_this,
|
2880
|
-
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, inx, err_4;
|
2881
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2882
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2883
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2884
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2853
|
+
this.closeAndSwap = function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
2854
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2855
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2856
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2857
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2858
|
+
return __awaiter(_this, void 0, void 0, function () {
|
2859
|
+
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, rebateMintAccount, inx, err_4;
|
2885
2860
|
return __generator(this, function (_a) {
|
2886
2861
|
switch (_a.label) {
|
2887
2862
|
case 0:
|
@@ -2907,6 +2882,8 @@ var PerpetualsClient = (function () {
|
|
2907
2882
|
instructions = [];
|
2908
2883
|
postInstructions = [];
|
2909
2884
|
additionalSigners = [];
|
2885
|
+
collateralToken = poolConfig.getTokenFromSymbol(collateralTokenSymbol);
|
2886
|
+
userOutputToken = poolConfig.getTokenFromSymbol(userOutputTokenSymbol);
|
2910
2887
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 1];
|
2911
2888
|
console.log("outputSymbol === SOL", userOutputTokenSymbol);
|
2912
2889
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -2928,26 +2905,30 @@ var PerpetualsClient = (function () {
|
|
2928
2905
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
2929
2906
|
];
|
2930
2907
|
additionalSigners.push(wrappedSolAccount);
|
2931
|
-
return [3,
|
2932
|
-
case 1:
|
2933
|
-
|
2934
|
-
userReceivingTokenAccount = _a.sent();
|
2908
|
+
return [3, 3];
|
2909
|
+
case 1:
|
2910
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(userOutputToken.mintKey, publicKey, true, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
2935
2911
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
2936
|
-
case
|
2912
|
+
case 2:
|
2937
2913
|
if (!(_a.sent())) {
|
2938
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey,
|
2914
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, userOutputToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2939
2915
|
}
|
2940
|
-
_a.label =
|
2941
|
-
case
|
2942
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
2916
|
+
_a.label = 3;
|
2917
|
+
case 3:
|
2918
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralToken.mintKey, publicKey, true);
|
2943
2919
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
2944
|
-
case
|
2920
|
+
case 4:
|
2945
2921
|
if (!(_a.sent())) {
|
2946
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey,
|
2922
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralToken.mintKey, userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
2947
2923
|
}
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2924
|
+
rebateMintAccount = {
|
2925
|
+
pubkey: collateralCustodyConfig.mintKey,
|
2926
|
+
isSigner: false,
|
2927
|
+
isWritable: false
|
2928
|
+
};
|
2929
|
+
_a.label = 5;
|
2930
|
+
case 5:
|
2931
|
+
_a.trys.push([5, 7, , 8]);
|
2951
2932
|
return [4, this.program.methods
|
2952
2933
|
.closeAndSwap({
|
2953
2934
|
priceWithSlippage: priceWithSlippage,
|
@@ -2972,22 +2953,25 @@ var PerpetualsClient = (function () {
|
|
2972
2953
|
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
2973
2954
|
dispensingOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
2974
2955
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
2975
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2976
2956
|
eventAuthority: this.eventAuthority.publicKey,
|
2977
2957
|
program: this.programId,
|
2978
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
2958
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2959
|
+
receivingMint: userOutputCustodyConfig.mintKey,
|
2960
|
+
receivingTokenProgram: userOutputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
2961
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
2962
|
+
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2979
2963
|
})
|
2980
2964
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
2981
2965
|
.instruction()];
|
2982
|
-
case
|
2966
|
+
case 6:
|
2983
2967
|
inx = _a.sent();
|
2984
2968
|
instructions.push(inx);
|
2985
|
-
return [3,
|
2986
|
-
case
|
2969
|
+
return [3, 8];
|
2970
|
+
case 7:
|
2987
2971
|
err_4 = _a.sent();
|
2988
2972
|
console.error("perpClient CloseAndSwap error:: ", err_4);
|
2989
2973
|
throw err_4;
|
2990
|
-
case
|
2974
|
+
case 8: return [2, {
|
2991
2975
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
2992
2976
|
additionalSigners: additionalSigners
|
2993
2977
|
}];
|
@@ -2995,15 +2979,11 @@ var PerpetualsClient = (function () {
|
|
2995
2979
|
});
|
2996
2980
|
});
|
2997
2981
|
};
|
2998
|
-
this.addCollateral = function (
|
2999
|
-
|
3000
|
-
|
3001
|
-
|
3002
|
-
}
|
3003
|
-
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) {
|
2982
|
+
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
2983
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2984
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2985
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3004
2986
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3005
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3006
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3007
2987
|
return __generator(this, function (_c) {
|
3008
2988
|
switch (_c.label) {
|
3009
2989
|
case 0:
|
@@ -3081,9 +3061,10 @@ var PerpetualsClient = (function () {
|
|
3081
3061
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3082
3062
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3083
3063
|
eventAuthority: this.eventAuthority.publicKey,
|
3084
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3064
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3085
3065
|
program: this.programId,
|
3086
3066
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3067
|
+
fundingMint: collateralCustodyConfig.mintKey
|
3087
3068
|
})
|
3088
3069
|
.instruction()];
|
3089
3070
|
case 7:
|
@@ -3097,15 +3078,11 @@ var PerpetualsClient = (function () {
|
|
3097
3078
|
});
|
3098
3079
|
});
|
3099
3080
|
};
|
3100
|
-
this.swapAndAddCollateral = function (
|
3101
|
-
|
3102
|
-
|
3103
|
-
|
3104
|
-
}
|
3105
|
-
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) {
|
3081
|
+
this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3082
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3083
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3084
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3106
3085
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3107
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3108
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3109
3086
|
return __generator(this, function (_c) {
|
3110
3087
|
switch (_c.label) {
|
3111
3088
|
case 0:
|
@@ -3156,7 +3133,7 @@ var PerpetualsClient = (function () {
|
|
3156
3133
|
];
|
3157
3134
|
return [3, 6];
|
3158
3135
|
case 3:
|
3159
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3136
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(inputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3160
3137
|
if (!!skipBalanceChecks) return [3, 6];
|
3161
3138
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3162
3139
|
case 4:
|
@@ -3172,11 +3149,11 @@ var PerpetualsClient = (function () {
|
|
3172
3149
|
}
|
3173
3150
|
_c.label = 6;
|
3174
3151
|
case 6:
|
3175
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3152
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3176
3153
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3177
3154
|
case 7:
|
3178
3155
|
if (!(_c.sent())) {
|
3179
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3156
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3180
3157
|
}
|
3181
3158
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3182
3159
|
return [4, this.program.methods.swapAndAddCollateral({
|
@@ -3216,16 +3193,12 @@ var PerpetualsClient = (function () {
|
|
3216
3193
|
});
|
3217
3194
|
});
|
3218
3195
|
};
|
3219
|
-
this.removeCollateral = function (
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3223
|
-
|
3224
|
-
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) {
|
3196
|
+
this.removeCollateral = function (collateralWithFee, marketSymbol, collateralSymbol, side, positionPubKey, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
3197
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3198
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3199
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3200
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3225
3201
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
3226
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
3227
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3228
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3229
3202
|
return __generator(this, function (_b) {
|
3230
3203
|
switch (_b.label) {
|
3231
3204
|
case 0:
|
@@ -3269,7 +3242,7 @@ var PerpetualsClient = (function () {
|
|
3269
3242
|
];
|
3270
3243
|
return [3, 5];
|
3271
3244
|
case 2:
|
3272
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3245
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3273
3246
|
_a = createUserATA;
|
3274
3247
|
if (!_a) return [3, 4];
|
3275
3248
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -3278,7 +3251,7 @@ var PerpetualsClient = (function () {
|
|
3278
3251
|
_b.label = 4;
|
3279
3252
|
case 4:
|
3280
3253
|
if (_a) {
|
3281
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3254
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3282
3255
|
}
|
3283
3256
|
_b.label = 5;
|
3284
3257
|
case 5:
|
@@ -3301,9 +3274,10 @@ var PerpetualsClient = (function () {
|
|
3301
3274
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3302
3275
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3303
3276
|
eventAuthority: this.eventAuthority.publicKey,
|
3304
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3277
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3305
3278
|
program: this.programId,
|
3306
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3279
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3280
|
+
receivingMint: collateralCustodyConfig.mintKey
|
3307
3281
|
})
|
3308
3282
|
.instruction()];
|
3309
3283
|
case 6:
|
@@ -3326,14 +3300,10 @@ var PerpetualsClient = (function () {
|
|
3326
3300
|
});
|
3327
3301
|
});
|
3328
3302
|
};
|
3329
|
-
this.removeCollateralAndSwap = function (
|
3330
|
-
|
3331
|
-
|
3332
|
-
args_1[_i - 7] = arguments[_i];
|
3333
|
-
}
|
3334
|
-
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) {
|
3303
|
+
this.removeCollateralAndSwap = function (targetSymbol, collateralSymbol, outputSymbol, minSwapAmountOut, collateralDelta, side, poolConfig, ephemeralSignerPubkey) {
|
3304
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3305
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3335
3306
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3336
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3337
3307
|
return __generator(this, function (_a) {
|
3338
3308
|
switch (_a.label) {
|
3339
3309
|
case 0:
|
@@ -3370,19 +3340,19 @@ var PerpetualsClient = (function () {
|
|
3370
3340
|
];
|
3371
3341
|
return [3, 3];
|
3372
3342
|
case 1:
|
3373
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true);
|
3343
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(outputSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3374
3344
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3375
3345
|
case 2:
|
3376
3346
|
if (!(_a.sent())) {
|
3377
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey));
|
3347
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(outputSymbol).mintKey, poolConfig.getTokenFromSymbol(outputSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3378
3348
|
}
|
3379
3349
|
_a.label = 3;
|
3380
3350
|
case 3:
|
3381
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true);
|
3351
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3382
3352
|
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3383
3353
|
case 4:
|
3384
3354
|
if (!(_a.sent())) {
|
3385
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
3355
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3386
3356
|
}
|
3387
3357
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3388
3358
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
@@ -3409,7 +3379,7 @@ var PerpetualsClient = (function () {
|
|
3409
3379
|
dispensingCustody: outputCustodyConfig.custodyAccount,
|
3410
3380
|
dispensingOracleAccount: this.useExtOracleAccount ? outputCustodyConfig.extOracleAccount : outputCustodyConfig.intOracleAccount,
|
3411
3381
|
dispensingCustodyTokenAccount: outputCustodyConfig.tokenAccount,
|
3412
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3382
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3413
3383
|
eventAuthority: this.eventAuthority.publicKey,
|
3414
3384
|
program: this.programId,
|
3415
3385
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
@@ -3426,16 +3396,12 @@ var PerpetualsClient = (function () {
|
|
3426
3396
|
});
|
3427
3397
|
});
|
3428
3398
|
};
|
3429
|
-
this.increaseSize = function (
|
3430
|
-
|
3431
|
-
|
3432
|
-
|
3433
|
-
|
3434
|
-
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) {
|
3399
|
+
this.increaseSize = function (targetSymbol, collateralSymbol, positionPubKey, side, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3400
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3401
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3402
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3403
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3435
3404
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3436
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3437
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3438
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3439
3405
|
return __generator(this, function (_a) {
|
3440
3406
|
switch (_a.label) {
|
3441
3407
|
case 0:
|
@@ -3472,7 +3438,7 @@ var PerpetualsClient = (function () {
|
|
3472
3438
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3473
3439
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3474
3440
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3475
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3441
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3476
3442
|
eventAuthority: this.eventAuthority.publicKey,
|
3477
3443
|
program: this.programId,
|
3478
3444
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
@@ -3490,16 +3456,12 @@ var PerpetualsClient = (function () {
|
|
3490
3456
|
});
|
3491
3457
|
});
|
3492
3458
|
};
|
3493
|
-
this.decreaseSize = function (
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
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) {
|
3459
|
+
this.decreaseSize = function (targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, priceWithSlippage, sizeDelta, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
3460
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3461
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3462
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3463
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3499
3464
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3500
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3501
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3502
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3503
3465
|
return __generator(this, function (_a) {
|
3504
3466
|
switch (_a.label) {
|
3505
3467
|
case 0:
|
@@ -3536,7 +3498,7 @@ var PerpetualsClient = (function () {
|
|
3536
3498
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3537
3499
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3538
3500
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3539
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3501
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3540
3502
|
eventAuthority: this.eventAuthority.publicKey,
|
3541
3503
|
program: this.programId,
|
3542
3504
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
@@ -3554,17 +3516,13 @@ var PerpetualsClient = (function () {
|
|
3554
3516
|
});
|
3555
3517
|
});
|
3556
3518
|
};
|
3557
|
-
this.addLiquidity = function (
|
3558
|
-
|
3559
|
-
|
3560
|
-
|
3561
|
-
|
3562
|
-
|
3563
|
-
|
3564
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3565
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3566
|
-
return __generator(this, function (_g) {
|
3567
|
-
switch (_g.label) {
|
3519
|
+
this.addLiquidity = function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3520
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3521
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3522
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3523
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, tokenAccountBalance, _e, instruction, err_5;
|
3524
|
+
return __generator(this, function (_f) {
|
3525
|
+
switch (_f.label) {
|
3568
3526
|
case 0:
|
3569
3527
|
publicKey = this.provider.wallet.publicKey;
|
3570
3528
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -3575,16 +3533,17 @@ var PerpetualsClient = (function () {
|
|
3575
3533
|
instructions = [];
|
3576
3534
|
postInstructions = [];
|
3577
3535
|
additionalSigners = [];
|
3578
|
-
|
3536
|
+
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
3537
|
+
_f.label = 1;
|
3579
3538
|
case 1:
|
3580
|
-
|
3581
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
3539
|
+
_f.trys.push([1, 10, , 11]);
|
3540
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3582
3541
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3583
3542
|
custodyAccountMetas = [];
|
3584
3543
|
custodyOracleAccountMetas = [];
|
3585
3544
|
markets = [];
|
3586
|
-
for (
|
3587
|
-
custody =
|
3545
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
3546
|
+
custody = _a[_i];
|
3588
3547
|
custodyAccountMetas.push({
|
3589
3548
|
pubkey: custody.custodyAccount,
|
3590
3549
|
isSigner: false,
|
@@ -3596,8 +3555,8 @@ var PerpetualsClient = (function () {
|
|
3596
3555
|
isWritable: false,
|
3597
3556
|
});
|
3598
3557
|
}
|
3599
|
-
for (
|
3600
|
-
market =
|
3558
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
3559
|
+
market = _c[_b];
|
3601
3560
|
markets.push({
|
3602
3561
|
pubkey: market.marketAccount,
|
3603
3562
|
isSigner: false,
|
@@ -3606,21 +3565,21 @@ var PerpetualsClient = (function () {
|
|
3606
3565
|
}
|
3607
3566
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3608
3567
|
case 2:
|
3609
|
-
if (!(
|
3568
|
+
if (!(_f.sent())) {
|
3610
3569
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3611
3570
|
}
|
3612
3571
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3613
3572
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3614
3573
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3615
3574
|
if (!!skipBalanceChecks) return [3, 4];
|
3616
|
-
|
3575
|
+
_d = anchor_1.BN.bind;
|
3617
3576
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3618
3577
|
case 3:
|
3619
|
-
unWrappedSolBalance = new (
|
3578
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3620
3579
|
if (unWrappedSolBalance.lt(lamports)) {
|
3621
3580
|
throw "Insufficient SOL Funds";
|
3622
3581
|
}
|
3623
|
-
|
3582
|
+
_f.label = 4;
|
3624
3583
|
case 4:
|
3625
3584
|
if (!ephemeralSignerPubkey) {
|
3626
3585
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -3644,17 +3603,17 @@ var PerpetualsClient = (function () {
|
|
3644
3603
|
if (!!skipBalanceChecks) return [3, 8];
|
3645
3604
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3646
3605
|
case 6:
|
3647
|
-
if (!(
|
3606
|
+
if (!(_f.sent())) {
|
3648
3607
|
throw "Insufficient Funds , token Account doesn't exist";
|
3649
3608
|
}
|
3650
|
-
|
3609
|
+
_e = anchor_1.BN.bind;
|
3651
3610
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3652
3611
|
case 7:
|
3653
|
-
tokenAccountBalance = new (
|
3612
|
+
tokenAccountBalance = new (_e.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3654
3613
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
3655
3614
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
3656
3615
|
}
|
3657
|
-
|
3616
|
+
_f.label = 8;
|
3658
3617
|
case 8: return [4, this.program.methods
|
3659
3618
|
.addLiquidity({
|
3660
3619
|
amountIn: tokenAmountIn,
|
@@ -3674,16 +3633,18 @@ var PerpetualsClient = (function () {
|
|
3674
3633
|
eventAuthority: this.eventAuthority.publicKey,
|
3675
3634
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3676
3635
|
program: this.programId,
|
3677
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3636
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3637
|
+
fundingMint: payTokenCustodyConfig.mintKey,
|
3638
|
+
fundingTokenProgram: payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3678
3639
|
})
|
3679
3640
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3680
3641
|
.instruction()];
|
3681
3642
|
case 9:
|
3682
|
-
instruction =
|
3643
|
+
instruction = _f.sent();
|
3683
3644
|
instructions.push(instruction);
|
3684
3645
|
return [3, 11];
|
3685
3646
|
case 10:
|
3686
|
-
err_5 =
|
3647
|
+
err_5 = _f.sent();
|
3687
3648
|
console.error("perpClient addLiquidity error:: ", err_5);
|
3688
3649
|
throw err_5;
|
3689
3650
|
case 11: return [2, {
|
@@ -3694,18 +3655,14 @@ var PerpetualsClient = (function () {
|
|
3694
3655
|
});
|
3695
3656
|
});
|
3696
3657
|
};
|
3697
|
-
this.addLiquidityAndStake = function (
|
3698
|
-
|
3699
|
-
|
3700
|
-
|
3701
|
-
|
3702
|
-
|
3703
|
-
|
3704
|
-
|
3705
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3706
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3707
|
-
return __generator(this, function (_g) {
|
3708
|
-
switch (_g.label) {
|
3658
|
+
this.addLiquidityAndStake = function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
3659
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3660
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3661
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3662
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3663
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, inputToken, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, instruction;
|
3664
|
+
return __generator(this, function (_f) {
|
3665
|
+
switch (_f.label) {
|
3709
3666
|
case 0:
|
3710
3667
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
3711
3668
|
preInstructions = [];
|
@@ -3715,6 +3672,7 @@ var PerpetualsClient = (function () {
|
|
3715
3672
|
lpTokenMint = poolConfig.stakedLpTokenMint;
|
3716
3673
|
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3717
3674
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lpTokenMint, publicKey, true);
|
3675
|
+
inputToken = poolConfig.getTokenFromSymbol(inputSymbol);
|
3718
3676
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), poolConfig.poolAddress.toBuffer()], this.programId)[0];
|
3719
3677
|
poolStakedLpVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("staked_lp_token_account"), poolConfig.poolAddress.toBuffer(), lpTokenMint.toBuffer()], this.programId)[0];
|
3720
3678
|
if (!(inputSymbol == 'SOL')) return [3, 4];
|
@@ -3725,14 +3683,14 @@ var PerpetualsClient = (function () {
|
|
3725
3683
|
_a = anchor_1.BN.bind;
|
3726
3684
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3727
3685
|
case 1:
|
3728
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3686
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3729
3687
|
if (unWrappedSolBalance.lt(lamports)) {
|
3730
3688
|
throw "Insufficient SOL Funds";
|
3731
3689
|
}
|
3732
|
-
|
3690
|
+
_f.label = 2;
|
3733
3691
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3734
3692
|
case 3:
|
3735
|
-
if (!(
|
3693
|
+
if (!(_f.sent())) {
|
3736
3694
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3737
3695
|
}
|
3738
3696
|
if (!ephemeralSignerPubkey) {
|
@@ -3754,27 +3712,27 @@ var PerpetualsClient = (function () {
|
|
3754
3712
|
];
|
3755
3713
|
return [3, 7];
|
3756
3714
|
case 4:
|
3757
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3715
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true, inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3758
3716
|
if (!!skipBalanceChecks) return [3, 7];
|
3759
3717
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3760
3718
|
case 5:
|
3761
|
-
if (!(
|
3719
|
+
if (!(_f.sent())) {
|
3762
3720
|
throw "Insufficient Funds , token Account doesn't exist";
|
3763
3721
|
}
|
3764
3722
|
_b = anchor_1.BN.bind;
|
3765
3723
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3766
3724
|
case 6:
|
3767
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
3725
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
3768
3726
|
if (tokenAccountBalance.lt(amountIn)) {
|
3769
3727
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3770
3728
|
}
|
3771
|
-
|
3729
|
+
_f.label = 7;
|
3772
3730
|
case 7:
|
3773
3731
|
custodyAccountMetas = [];
|
3774
3732
|
custodyOracleAccountMetas = [];
|
3775
3733
|
markets = [];
|
3776
|
-
for (
|
3777
|
-
custody =
|
3734
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
3735
|
+
custody = _c[_i];
|
3778
3736
|
custodyAccountMetas.push({
|
3779
3737
|
pubkey: custody.custodyAccount,
|
3780
3738
|
isSigner: false,
|
@@ -3786,8 +3744,8 @@ var PerpetualsClient = (function () {
|
|
3786
3744
|
isWritable: false,
|
3787
3745
|
});
|
3788
3746
|
}
|
3789
|
-
for (
|
3790
|
-
market =
|
3747
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
3748
|
+
market = _e[_d];
|
3791
3749
|
markets.push({
|
3792
3750
|
pubkey: market.marketAccount,
|
3793
3751
|
isSigner: false,
|
@@ -3814,12 +3772,14 @@ var PerpetualsClient = (function () {
|
|
3814
3772
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3815
3773
|
eventAuthority: this.eventAuthority.publicKey,
|
3816
3774
|
program: this.programId,
|
3817
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3775
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3776
|
+
fundingMint: inputCustodyConfig.mintKey,
|
3777
|
+
fundingTokenProgram: inputToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3818
3778
|
})
|
3819
3779
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3820
3780
|
.instruction()];
|
3821
3781
|
case 8:
|
3822
|
-
instruction =
|
3782
|
+
instruction = _f.sent();
|
3823
3783
|
instructions.push(instruction);
|
3824
3784
|
return [2, {
|
3825
3785
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -3829,20 +3789,16 @@ var PerpetualsClient = (function () {
|
|
3829
3789
|
});
|
3830
3790
|
});
|
3831
3791
|
};
|
3832
|
-
this.removeLiquidity = function (
|
3833
|
-
|
3834
|
-
|
3835
|
-
|
3836
|
-
}
|
3837
|
-
|
3838
|
-
|
3839
|
-
|
3840
|
-
|
3841
|
-
|
3842
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3843
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3844
|
-
return __generator(this, function (_f) {
|
3845
|
-
switch (_f.label) {
|
3792
|
+
this.removeLiquidity = function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
3793
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
3794
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3795
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3796
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3797
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3798
|
+
return __awaiter(_this, void 0, void 0, function () {
|
3799
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, _d, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
|
3800
|
+
return __generator(this, function (_e) {
|
3801
|
+
switch (_e.label) {
|
3846
3802
|
case 0:
|
3847
3803
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
3848
3804
|
if (!recieveTokenCustodyConfig) {
|
@@ -3853,15 +3809,16 @@ var PerpetualsClient = (function () {
|
|
3853
3809
|
instructions = [];
|
3854
3810
|
postInstructions = [];
|
3855
3811
|
additionalSigners = [];
|
3856
|
-
|
3812
|
+
recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
|
3813
|
+
_e.label = 1;
|
3857
3814
|
case 1:
|
3858
|
-
|
3815
|
+
_e.trys.push([1, 7, , 8]);
|
3859
3816
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3860
3817
|
custodyAccountMetas = [];
|
3861
3818
|
custodyOracleAccountMetas = [];
|
3862
3819
|
markets = [];
|
3863
|
-
for (
|
3864
|
-
custody =
|
3820
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
3821
|
+
custody = _a[_i];
|
3865
3822
|
custodyAccountMetas.push({
|
3866
3823
|
pubkey: custody.custodyAccount,
|
3867
3824
|
isSigner: false,
|
@@ -3873,8 +3830,8 @@ var PerpetualsClient = (function () {
|
|
3873
3830
|
isWritable: false,
|
3874
3831
|
});
|
3875
3832
|
}
|
3876
|
-
for (
|
3877
|
-
market =
|
3833
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
3834
|
+
market = _c[_b];
|
3878
3835
|
markets.push({
|
3879
3836
|
pubkey: market.marketAccount,
|
3880
3837
|
isSigner: false,
|
@@ -3902,18 +3859,18 @@ var PerpetualsClient = (function () {
|
|
3902
3859
|
];
|
3903
3860
|
return [3, 5];
|
3904
3861
|
case 2:
|
3905
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(
|
3906
|
-
|
3907
|
-
if (!
|
3862
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3863
|
+
_d = createUserATA;
|
3864
|
+
if (!_d) return [3, 4];
|
3908
3865
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3909
3866
|
case 3:
|
3910
|
-
|
3911
|
-
|
3867
|
+
_d = !(_e.sent());
|
3868
|
+
_e.label = 4;
|
3912
3869
|
case 4:
|
3913
|
-
if (
|
3914
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey,
|
3870
|
+
if (_d) {
|
3871
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3915
3872
|
}
|
3916
|
-
|
3873
|
+
_e.label = 5;
|
3917
3874
|
case 5: return [4, this.program.methods
|
3918
3875
|
.removeLiquidity({
|
3919
3876
|
lpAmountIn: liquidityAmountIn,
|
@@ -3933,12 +3890,14 @@ var PerpetualsClient = (function () {
|
|
3933
3890
|
eventAuthority: this.eventAuthority.publicKey,
|
3934
3891
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3935
3892
|
program: this.programId,
|
3936
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3893
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3894
|
+
receivingMint: recieveTokenCustodyConfig.mintKey,
|
3895
|
+
receivingTokenProgram: recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
3937
3896
|
})
|
3938
3897
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3939
3898
|
.instruction()];
|
3940
3899
|
case 6:
|
3941
|
-
removeLiquidityTx =
|
3900
|
+
removeLiquidityTx = _e.sent();
|
3942
3901
|
instructions.push(removeLiquidityTx);
|
3943
3902
|
if (closeLpATA) {
|
3944
3903
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -3950,7 +3909,7 @@ var PerpetualsClient = (function () {
|
|
3950
3909
|
}
|
3951
3910
|
return [3, 8];
|
3952
3911
|
case 7:
|
3953
|
-
err_6 =
|
3912
|
+
err_6 = _e.sent();
|
3954
3913
|
console.log("perpClient removeLiquidity error:: ", err_6);
|
3955
3914
|
throw err_6;
|
3956
3915
|
case 8: return [2, {
|
@@ -3999,54 +3958,8 @@ var PerpetualsClient = (function () {
|
|
3999
3958
|
}
|
4000
3959
|
});
|
4001
3960
|
}); };
|
4002
|
-
this.createNftTradingAccount = function (nftMint, owner, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4003
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, createNftTradingAccountInstruction, err_8;
|
4004
|
-
return __generator(this, function (_a) {
|
4005
|
-
switch (_a.label) {
|
4006
|
-
case 0:
|
4007
|
-
publicKey = this.provider.wallet.publicKey;
|
4008
|
-
preInstructions = [];
|
4009
|
-
instructions = [];
|
4010
|
-
postInstructions = [];
|
4011
|
-
additionalSigners = [];
|
4012
|
-
_a.label = 1;
|
4013
|
-
case 1:
|
4014
|
-
_a.trys.push([1, 3, , 4]);
|
4015
|
-
nftTradingAccount = web3_js_1.PublicKey.findProgramAddressSync([
|
4016
|
-
Buffer.from("trading"),
|
4017
|
-
nftMint.toBuffer(),
|
4018
|
-
], this.programId)[0];
|
4019
|
-
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
4020
|
-
return [4, this.program.methods
|
4021
|
-
.createTradingAccount({
|
4022
|
-
collectionIndex: 1
|
4023
|
-
})
|
4024
|
-
.accounts({
|
4025
|
-
feePayer: publicKey,
|
4026
|
-
perpetuals: poolConfig.perpetuals,
|
4027
|
-
nftMint: nftMint,
|
4028
|
-
tradingAccount: nftTradingAccount,
|
4029
|
-
metadataAccount: metadataAccount,
|
4030
|
-
systemProgram: web3_js_1.SystemProgram.programId
|
4031
|
-
})
|
4032
|
-
.instruction()];
|
4033
|
-
case 2:
|
4034
|
-
createNftTradingAccountInstruction = _a.sent();
|
4035
|
-
instructions.push(createNftTradingAccountInstruction);
|
4036
|
-
return [3, 4];
|
4037
|
-
case 3:
|
4038
|
-
err_8 = _a.sent();
|
4039
|
-
console.log("perpClient createNftAccount error:: ", err_8);
|
4040
|
-
throw err_8;
|
4041
|
-
case 4: return [2, {
|
4042
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4043
|
-
additionalSigners: additionalSigners
|
4044
|
-
}];
|
4045
|
-
}
|
4046
|
-
});
|
4047
|
-
}); };
|
4048
3961
|
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4049
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction,
|
3962
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_8;
|
4050
3963
|
return __generator(this, function (_a) {
|
4051
3964
|
switch (_a.label) {
|
4052
3965
|
case 0:
|
@@ -4096,9 +4009,9 @@ var PerpetualsClient = (function () {
|
|
4096
4009
|
instructions.push(updateNftTradingAccountInstruction);
|
4097
4010
|
return [3, 5];
|
4098
4011
|
case 4:
|
4099
|
-
|
4100
|
-
console.log("perpClient updateNftAccount error:: ",
|
4101
|
-
throw
|
4012
|
+
err_8 = _a.sent();
|
4013
|
+
console.log("perpClient updateNftAccount error:: ", err_8);
|
4014
|
+
throw err_8;
|
4102
4015
|
case 5: return [2, {
|
4103
4016
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4104
4017
|
additionalSigners: additionalSigners
|
@@ -4107,7 +4020,7 @@ var PerpetualsClient = (function () {
|
|
4107
4020
|
});
|
4108
4021
|
}); };
|
4109
4022
|
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4110
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction,
|
4023
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_9;
|
4111
4024
|
return __generator(this, function (_a) {
|
4112
4025
|
switch (_a.label) {
|
4113
4026
|
case 0:
|
@@ -4146,9 +4059,9 @@ var PerpetualsClient = (function () {
|
|
4146
4059
|
instructions.push(levelUpInstruction);
|
4147
4060
|
return [3, 4];
|
4148
4061
|
case 3:
|
4149
|
-
|
4150
|
-
console.log("perpClient levelUp error:: ",
|
4151
|
-
throw
|
4062
|
+
err_9 = _a.sent();
|
4063
|
+
console.log("perpClient levelUp error:: ", err_9);
|
4064
|
+
throw err_9;
|
4152
4065
|
case 4: return [2, {
|
4153
4066
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4154
4067
|
additionalSigners: additionalSigners
|
@@ -4157,7 +4070,7 @@ var PerpetualsClient = (function () {
|
|
4157
4070
|
});
|
4158
4071
|
}); };
|
4159
4072
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4160
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
4073
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_10;
|
4161
4074
|
return __generator(this, function (_a) {
|
4162
4075
|
switch (_a.label) {
|
4163
4076
|
case 0:
|
@@ -4190,7 +4103,8 @@ var PerpetualsClient = (function () {
|
|
4190
4103
|
systemProgram: web3_js_1.SystemProgram.programId,
|
4191
4104
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4192
4105
|
eventAuthority: this.eventAuthority.publicKey,
|
4193
|
-
program: this.programId
|
4106
|
+
program: this.programId,
|
4107
|
+
lpTokenMint: poolConfig.stakedLpTokenMint,
|
4194
4108
|
})
|
4195
4109
|
.instruction()];
|
4196
4110
|
case 3:
|
@@ -4198,9 +4112,9 @@ var PerpetualsClient = (function () {
|
|
4198
4112
|
instructions.push(depositStakeInstruction);
|
4199
4113
|
return [3, 5];
|
4200
4114
|
case 4:
|
4201
|
-
|
4202
|
-
console.log("perpClient depositStaking error:: ",
|
4203
|
-
throw
|
4115
|
+
err_10 = _a.sent();
|
4116
|
+
console.log("perpClient depositStaking error:: ", err_10);
|
4117
|
+
throw err_10;
|
4204
4118
|
case 5: return [2, {
|
4205
4119
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4206
4120
|
additionalSigners: additionalSigners
|
@@ -4209,7 +4123,7 @@ var PerpetualsClient = (function () {
|
|
4209
4123
|
});
|
4210
4124
|
}); };
|
4211
4125
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4212
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4126
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_11;
|
4213
4127
|
return __generator(this, function (_c) {
|
4214
4128
|
switch (_c.label) {
|
4215
4129
|
case 0:
|
@@ -4256,33 +4170,29 @@ var PerpetualsClient = (function () {
|
|
4256
4170
|
refreshStakeInstruction = _c.sent();
|
4257
4171
|
return [2, refreshStakeInstruction];
|
4258
4172
|
case 2:
|
4259
|
-
|
4260
|
-
console.log("perpClient refreshStaking error:: ",
|
4261
|
-
throw
|
4173
|
+
err_11 = _c.sent();
|
4174
|
+
console.log("perpClient refreshStaking error:: ", err_11);
|
4175
|
+
throw err_11;
|
4262
4176
|
case 3: return [2];
|
4263
4177
|
}
|
4264
4178
|
});
|
4265
4179
|
}); };
|
4266
|
-
this.refreshStakeWithTokenStake = function (
|
4267
|
-
|
4268
|
-
|
4269
|
-
|
4270
|
-
|
4271
|
-
|
4272
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_13;
|
4273
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4274
|
-
return __generator(this, function (_c) {
|
4275
|
-
switch (_c.label) {
|
4180
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4181
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4182
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4183
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_12;
|
4184
|
+
return __generator(this, function (_b) {
|
4185
|
+
switch (_b.label) {
|
4276
4186
|
case 0:
|
4277
|
-
|
4187
|
+
_b.trys.push([0, 2, , 3]);
|
4278
4188
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4279
4189
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4280
4190
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4281
4191
|
pool = poolConfig.poolAddress;
|
4282
4192
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4283
4193
|
custodyAccountMetas = [];
|
4284
|
-
for (
|
4285
|
-
custody =
|
4194
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4195
|
+
custody = _a[_i];
|
4286
4196
|
custodyAccountMetas.push({
|
4287
4197
|
pubkey: custody.custodyAccount,
|
4288
4198
|
isSigner: false,
|
@@ -4314,25 +4224,21 @@ var PerpetualsClient = (function () {
|
|
4314
4224
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4315
4225
|
.instruction()];
|
4316
4226
|
case 1:
|
4317
|
-
refreshStakeInstruction =
|
4227
|
+
refreshStakeInstruction = _b.sent();
|
4318
4228
|
return [2, refreshStakeInstruction];
|
4319
4229
|
case 2:
|
4320
|
-
|
4321
|
-
console.log("perpClient refreshStaking error:: ",
|
4322
|
-
throw
|
4230
|
+
err_12 = _b.sent();
|
4231
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4232
|
+
throw err_12;
|
4323
4233
|
case 3: return [2];
|
4324
4234
|
}
|
4325
4235
|
});
|
4326
4236
|
});
|
4327
4237
|
};
|
4328
|
-
this.unstakeInstant = function (
|
4329
|
-
|
4330
|
-
|
4331
|
-
|
4332
|
-
}
|
4333
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4334
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_14;
|
4335
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4238
|
+
this.unstakeInstant = function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4239
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4240
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4241
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_13;
|
4336
4242
|
return __generator(this, function (_b) {
|
4337
4243
|
switch (_b.label) {
|
4338
4244
|
case 0:
|
@@ -4383,9 +4289,9 @@ var PerpetualsClient = (function () {
|
|
4383
4289
|
instructions.push(unstakeInstantInstruction);
|
4384
4290
|
return [3, 6];
|
4385
4291
|
case 5:
|
4386
|
-
|
4387
|
-
console.log("perpClient unstakeInstant error:: ",
|
4388
|
-
throw
|
4292
|
+
err_13 = _b.sent();
|
4293
|
+
console.log("perpClient unstakeInstant error:: ", err_13);
|
4294
|
+
throw err_13;
|
4389
4295
|
case 6: return [2, {
|
4390
4296
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4391
4297
|
additionalSigners: additionalSigners
|
@@ -4395,7 +4301,7 @@ var PerpetualsClient = (function () {
|
|
4395
4301
|
});
|
4396
4302
|
};
|
4397
4303
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4398
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4304
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_14;
|
4399
4305
|
return __generator(this, function (_c) {
|
4400
4306
|
switch (_c.label) {
|
4401
4307
|
case 0:
|
@@ -4439,15 +4345,15 @@ var PerpetualsClient = (function () {
|
|
4439
4345
|
refreshStakeInstruction = _c.sent();
|
4440
4346
|
return [2, refreshStakeInstruction];
|
4441
4347
|
case 2:
|
4442
|
-
|
4443
|
-
console.log("perpClient refreshStaking error:: ",
|
4444
|
-
throw
|
4348
|
+
err_14 = _c.sent();
|
4349
|
+
console.log("perpClient refreshStaking error:: ", err_14);
|
4350
|
+
throw err_14;
|
4445
4351
|
case 3: return [2];
|
4446
4352
|
}
|
4447
4353
|
});
|
4448
4354
|
}); };
|
4449
4355
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4450
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4356
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_15;
|
4451
4357
|
return __generator(this, function (_a) {
|
4452
4358
|
switch (_a.label) {
|
4453
4359
|
case 0:
|
@@ -4481,9 +4387,9 @@ var PerpetualsClient = (function () {
|
|
4481
4387
|
instructions.push(unstakeRequestInstruction);
|
4482
4388
|
return [3, 4];
|
4483
4389
|
case 3:
|
4484
|
-
|
4485
|
-
console.log("perpClient unstakeRequest error:: ",
|
4486
|
-
throw
|
4390
|
+
err_15 = _a.sent();
|
4391
|
+
console.log("perpClient unstakeRequest error:: ", err_15);
|
4392
|
+
throw err_15;
|
4487
4393
|
case 4: return [2, {
|
4488
4394
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4489
4395
|
additionalSigners: additionalSigners
|
@@ -4491,17 +4397,13 @@ var PerpetualsClient = (function () {
|
|
4491
4397
|
}
|
4492
4398
|
});
|
4493
4399
|
}); };
|
4494
|
-
this.withdrawStake = function (
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4498
|
-
}
|
4499
|
-
return __awaiter(_this,
|
4500
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4501
|
-
if (pendingActivation === void 0) { pendingActivation = true; }
|
4502
|
-
if (deactivated === void 0) { deactivated = true; }
|
4503
|
-
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
4504
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4400
|
+
this.withdrawStake = function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4401
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
4402
|
+
if (deactivated === void 0) { deactivated = true; }
|
4403
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
4404
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4405
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4406
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_16;
|
4505
4407
|
return __generator(this, function (_b) {
|
4506
4408
|
switch (_b.label) {
|
4507
4409
|
case 0:
|
@@ -4552,9 +4454,9 @@ var PerpetualsClient = (function () {
|
|
4552
4454
|
instructions.push(withdrawStakeInstruction);
|
4553
4455
|
return [3, 6];
|
4554
4456
|
case 5:
|
4555
|
-
|
4556
|
-
console.log("perpClient withdrawStake error:: ",
|
4557
|
-
throw
|
4457
|
+
err_16 = _b.sent();
|
4458
|
+
console.log("perpClient withdrawStake error:: ", err_16);
|
4459
|
+
throw err_16;
|
4558
4460
|
case 6: return [2, {
|
4559
4461
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4560
4462
|
additionalSigners: additionalSigners
|
@@ -4563,14 +4465,10 @@ var PerpetualsClient = (function () {
|
|
4563
4465
|
});
|
4564
4466
|
});
|
4565
4467
|
};
|
4566
|
-
this.collectStakeFees = function (
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
}
|
4571
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4572
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_18;
|
4573
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
4468
|
+
this.collectStakeFees = function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4469
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4470
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4471
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_17;
|
4574
4472
|
return __generator(this, function (_b) {
|
4575
4473
|
switch (_b.label) {
|
4576
4474
|
case 0:
|
@@ -4629,9 +4527,9 @@ var PerpetualsClient = (function () {
|
|
4629
4527
|
instructions.push(withdrawStakeInstruction);
|
4630
4528
|
return [3, 6];
|
4631
4529
|
case 5:
|
4632
|
-
|
4633
|
-
console.log("perpClient withdrawStake error:: ",
|
4634
|
-
throw
|
4530
|
+
err_17 = _b.sent();
|
4531
|
+
console.log("perpClient withdrawStake error:: ", err_17);
|
4532
|
+
throw err_17;
|
4635
4533
|
case 6: return [2, {
|
4636
4534
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4637
4535
|
additionalSigners: additionalSigners
|
@@ -4640,18 +4538,14 @@ var PerpetualsClient = (function () {
|
|
4640
4538
|
});
|
4641
4539
|
});
|
4642
4540
|
};
|
4643
|
-
this.addCompoundingLiquidity = function (
|
4644
|
-
|
4645
|
-
|
4646
|
-
|
4647
|
-
|
4648
|
-
|
4649
|
-
|
4650
|
-
|
4651
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4652
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4653
|
-
return __generator(this, function (_f) {
|
4654
|
-
switch (_f.label) {
|
4541
|
+
this.addCompoundingLiquidity = function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4542
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4543
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4544
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4545
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4546
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, lamports, unWrappedSolBalance, _d, addCompoundingLiquidity, err_18;
|
4547
|
+
return __generator(this, function (_e) {
|
4548
|
+
switch (_e.label) {
|
4655
4549
|
case 0:
|
4656
4550
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4657
4551
|
preInstructions = [];
|
@@ -4668,8 +4562,8 @@ var PerpetualsClient = (function () {
|
|
4668
4562
|
custodyAccountMetas = [];
|
4669
4563
|
custodyOracleAccountMetas = [];
|
4670
4564
|
markets = [];
|
4671
|
-
for (
|
4672
|
-
custody =
|
4565
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
4566
|
+
custody = _a[_i];
|
4673
4567
|
custodyAccountMetas.push({
|
4674
4568
|
pubkey: custody.custodyAccount,
|
4675
4569
|
isSigner: false,
|
@@ -4681,8 +4575,8 @@ var PerpetualsClient = (function () {
|
|
4681
4575
|
isWritable: false,
|
4682
4576
|
});
|
4683
4577
|
}
|
4684
|
-
for (
|
4685
|
-
market =
|
4578
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
4579
|
+
market = _c[_b];
|
4686
4580
|
markets.push({
|
4687
4581
|
pubkey: market.marketAccount,
|
4688
4582
|
isSigner: false,
|
@@ -4691,26 +4585,26 @@ var PerpetualsClient = (function () {
|
|
4691
4585
|
}
|
4692
4586
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4693
4587
|
case 1:
|
4694
|
-
if (!(
|
4588
|
+
if (!(_e.sent())) {
|
4695
4589
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4696
4590
|
}
|
4697
4591
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
4698
4592
|
case 2:
|
4699
|
-
if (!(
|
4593
|
+
if (!(_e.sent())) {
|
4700
4594
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
4701
4595
|
}
|
4702
4596
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
4703
4597
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
4704
4598
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4705
4599
|
if (!!skipBalanceChecks) return [3, 4];
|
4706
|
-
|
4600
|
+
_d = anchor_1.BN.bind;
|
4707
4601
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4708
4602
|
case 3:
|
4709
|
-
unWrappedSolBalance = new (
|
4603
|
+
unWrappedSolBalance = new (_d.apply(anchor_1.BN, [void 0, _e.sent()]))();
|
4710
4604
|
if (unWrappedSolBalance.lt(lamports)) {
|
4711
4605
|
throw "Insufficient SOL Funds";
|
4712
4606
|
}
|
4713
|
-
|
4607
|
+
_e.label = 4;
|
4714
4608
|
case 4:
|
4715
4609
|
if (!ephemeralSignerPubkey) {
|
4716
4610
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4734,12 +4628,12 @@ var PerpetualsClient = (function () {
|
|
4734
4628
|
if (!!skipBalanceChecks) return [3, 7];
|
4735
4629
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
4736
4630
|
case 6:
|
4737
|
-
if (!(
|
4631
|
+
if (!(_e.sent())) {
|
4738
4632
|
throw "Insufficient Funds , token Account doesn't exist";
|
4739
4633
|
}
|
4740
|
-
|
4634
|
+
_e.label = 7;
|
4741
4635
|
case 7:
|
4742
|
-
|
4636
|
+
_e.trys.push([7, 9, , 10]);
|
4743
4637
|
return [4, this.program.methods
|
4744
4638
|
.addCompoundingLiquidity({
|
4745
4639
|
amountIn: amountIn,
|
@@ -4768,12 +4662,12 @@ var PerpetualsClient = (function () {
|
|
4768
4662
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4769
4663
|
.instruction()];
|
4770
4664
|
case 8:
|
4771
|
-
addCompoundingLiquidity =
|
4665
|
+
addCompoundingLiquidity = _e.sent();
|
4772
4666
|
instructions.push(addCompoundingLiquidity);
|
4773
4667
|
return [3, 10];
|
4774
4668
|
case 9:
|
4775
|
-
|
4776
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4669
|
+
err_18 = _e.sent();
|
4670
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_18);
|
4777
4671
|
return [3, 10];
|
4778
4672
|
case 10: return [2, {
|
4779
4673
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4783,18 +4677,14 @@ var PerpetualsClient = (function () {
|
|
4783
4677
|
});
|
4784
4678
|
});
|
4785
4679
|
};
|
4786
|
-
this.removeCompoundingLiquidity = function (
|
4787
|
-
|
4788
|
-
|
4789
|
-
|
4790
|
-
|
4791
|
-
|
4792
|
-
|
4793
|
-
|
4794
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4795
|
-
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4796
|
-
return __generator(this, function (_f) {
|
4797
|
-
switch (_f.label) {
|
4680
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
4681
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4682
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4683
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4684
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4685
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _b, custody, _c, _d, market, compoundingTokenAccount, removeCompoundingLiquidity, err_19;
|
4686
|
+
return __generator(this, function (_e) {
|
4687
|
+
switch (_e.label) {
|
4798
4688
|
case 0:
|
4799
4689
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4800
4690
|
preInstructions = [];
|
@@ -4831,19 +4721,19 @@ var PerpetualsClient = (function () {
|
|
4831
4721
|
if (!_a) return [3, 3];
|
4832
4722
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4833
4723
|
case 2:
|
4834
|
-
_a = !(
|
4835
|
-
|
4724
|
+
_a = !(_e.sent());
|
4725
|
+
_e.label = 3;
|
4836
4726
|
case 3:
|
4837
4727
|
if (_a) {
|
4838
4728
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
4839
4729
|
}
|
4840
|
-
|
4730
|
+
_e.label = 4;
|
4841
4731
|
case 4:
|
4842
4732
|
custodyAccountMetas = [];
|
4843
4733
|
custodyOracleAccountMetas = [];
|
4844
4734
|
markets = [];
|
4845
|
-
for (
|
4846
|
-
custody =
|
4735
|
+
for (_i = 0, _b = poolConfig.custodies; _i < _b.length; _i++) {
|
4736
|
+
custody = _b[_i];
|
4847
4737
|
custodyAccountMetas.push({
|
4848
4738
|
pubkey: custody.custodyAccount,
|
4849
4739
|
isSigner: false,
|
@@ -4855,8 +4745,8 @@ var PerpetualsClient = (function () {
|
|
4855
4745
|
isWritable: false,
|
4856
4746
|
});
|
4857
4747
|
}
|
4858
|
-
for (
|
4859
|
-
market =
|
4748
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4749
|
+
market = _d[_c];
|
4860
4750
|
markets.push({
|
4861
4751
|
pubkey: market.marketAccount,
|
4862
4752
|
isSigner: false,
|
@@ -4864,9 +4754,9 @@ var PerpetualsClient = (function () {
|
|
4864
4754
|
});
|
4865
4755
|
}
|
4866
4756
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
4867
|
-
|
4757
|
+
_e.label = 5;
|
4868
4758
|
case 5:
|
4869
|
-
|
4759
|
+
_e.trys.push([5, 7, , 8]);
|
4870
4760
|
return [4, this.program.methods
|
4871
4761
|
.removeCompoundingLiquidity({
|
4872
4762
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -4895,12 +4785,12 @@ var PerpetualsClient = (function () {
|
|
4895
4785
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4896
4786
|
.instruction()];
|
4897
4787
|
case 6:
|
4898
|
-
removeCompoundingLiquidity =
|
4788
|
+
removeCompoundingLiquidity = _e.sent();
|
4899
4789
|
instructions.push(removeCompoundingLiquidity);
|
4900
4790
|
return [3, 8];
|
4901
4791
|
case 7:
|
4902
|
-
|
4903
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4792
|
+
err_19 = _e.sent();
|
4793
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_19);
|
4904
4794
|
return [3, 8];
|
4905
4795
|
case 8: return [2, {
|
4906
4796
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4910,16 +4800,12 @@ var PerpetualsClient = (function () {
|
|
4910
4800
|
});
|
4911
4801
|
});
|
4912
4802
|
};
|
4913
|
-
this.migrateStake = function (
|
4914
|
-
|
4915
|
-
|
4916
|
-
|
4917
|
-
|
4918
|
-
|
4919
|
-
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_21;
|
4920
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
4921
|
-
return __generator(this, function (_g) {
|
4922
|
-
switch (_g.label) {
|
4803
|
+
this.migrateStake = function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4804
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4805
|
+
return __awaiter(_this, void 0, void 0, function () {
|
4806
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, _a, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _b, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _c, custody, _d, _e, market, migrateStake, err_20;
|
4807
|
+
return __generator(this, function (_f) {
|
4808
|
+
switch (_f.label) {
|
4923
4809
|
case 0:
|
4924
4810
|
publicKey = this.provider.wallet.publicKey;
|
4925
4811
|
preInstructions = [];
|
@@ -4934,8 +4820,8 @@ var PerpetualsClient = (function () {
|
|
4934
4820
|
if (!_a) return [3, 2];
|
4935
4821
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
4936
4822
|
case 1:
|
4937
|
-
_a = !(
|
4938
|
-
|
4823
|
+
_a = !(_f.sent());
|
4824
|
+
_f.label = 2;
|
4939
4825
|
case 2:
|
4940
4826
|
if (_a) {
|
4941
4827
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -4947,8 +4833,8 @@ var PerpetualsClient = (function () {
|
|
4947
4833
|
if (!_b) return [3, 4];
|
4948
4834
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
4949
4835
|
case 3:
|
4950
|
-
_b = (
|
4951
|
-
|
4836
|
+
_b = (_f.sent());
|
4837
|
+
_f.label = 4;
|
4952
4838
|
case 4:
|
4953
4839
|
if (_b) {
|
4954
4840
|
tokenStakeAccounts.push({
|
@@ -4961,8 +4847,8 @@ var PerpetualsClient = (function () {
|
|
4961
4847
|
custodyAccountMetas = [];
|
4962
4848
|
custodyOracleAccountMetas = [];
|
4963
4849
|
markets = [];
|
4964
|
-
for (
|
4965
|
-
custody =
|
4850
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
4851
|
+
custody = _c[_i];
|
4966
4852
|
custodyAccountMetas.push({
|
4967
4853
|
pubkey: custody.custodyAccount,
|
4968
4854
|
isSigner: false,
|
@@ -4974,17 +4860,17 @@ var PerpetualsClient = (function () {
|
|
4974
4860
|
isWritable: false,
|
4975
4861
|
});
|
4976
4862
|
}
|
4977
|
-
for (
|
4978
|
-
market =
|
4863
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
4864
|
+
market = _e[_d];
|
4979
4865
|
markets.push({
|
4980
4866
|
pubkey: market.marketAccount,
|
4981
4867
|
isSigner: false,
|
4982
4868
|
isWritable: false,
|
4983
4869
|
});
|
4984
4870
|
}
|
4985
|
-
|
4871
|
+
_f.label = 5;
|
4986
4872
|
case 5:
|
4987
|
-
|
4873
|
+
_f.trys.push([5, 7, , 8]);
|
4988
4874
|
return [4, this.program.methods
|
4989
4875
|
.migrateStake({
|
4990
4876
|
amount: amount
|
@@ -5010,12 +4896,12 @@ var PerpetualsClient = (function () {
|
|
5010
4896
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
5011
4897
|
.instruction()];
|
5012
4898
|
case 6:
|
5013
|
-
migrateStake =
|
4899
|
+
migrateStake = _f.sent();
|
5014
4900
|
instructions.push(migrateStake);
|
5015
4901
|
return [3, 8];
|
5016
4902
|
case 7:
|
5017
|
-
|
5018
|
-
console.log("perpClient migrateStake error:: ",
|
4903
|
+
err_20 = _f.sent();
|
4904
|
+
console.log("perpClient migrateStake error:: ", err_20);
|
5019
4905
|
return [3, 8];
|
5020
4906
|
case 8: return [2, {
|
5021
4907
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5026,7 +4912,7 @@ var PerpetualsClient = (function () {
|
|
5026
4912
|
});
|
5027
4913
|
};
|
5028
4914
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5029
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
4915
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_21;
|
5030
4916
|
return __generator(this, function (_d) {
|
5031
4917
|
switch (_d.label) {
|
5032
4918
|
case 0:
|
@@ -5098,8 +4984,8 @@ var PerpetualsClient = (function () {
|
|
5098
4984
|
instructions.push(migrateFlp);
|
5099
4985
|
return [3, 4];
|
5100
4986
|
case 3:
|
5101
|
-
|
5102
|
-
console.log("perpClient migrateFlp error:: ",
|
4987
|
+
err_21 = _d.sent();
|
4988
|
+
console.log("perpClient migrateFlp error:: ", err_21);
|
5103
4989
|
return [3, 4];
|
5104
4990
|
case 4: return [2, {
|
5105
4991
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5108,16 +4994,12 @@ var PerpetualsClient = (function () {
|
|
5108
4994
|
}
|
5109
4995
|
});
|
5110
4996
|
}); };
|
5111
|
-
this.compoundingFee = function (
|
5112
|
-
|
5113
|
-
|
5114
|
-
|
5115
|
-
|
5116
|
-
|
5117
|
-
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_23;
|
5118
|
-
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5119
|
-
return __generator(this, function (_e) {
|
5120
|
-
switch (_e.label) {
|
4997
|
+
this.compoundingFee = function (poolConfig, rewardTokenSymbol) {
|
4998
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
4999
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5000
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, compoundingFee, err_22;
|
5001
|
+
return __generator(this, function (_d) {
|
5002
|
+
switch (_d.label) {
|
5121
5003
|
case 0:
|
5122
5004
|
instructions = [];
|
5123
5005
|
additionalSigners = [];
|
@@ -5126,8 +5008,8 @@ var PerpetualsClient = (function () {
|
|
5126
5008
|
custodyAccountMetas = [];
|
5127
5009
|
custodyOracleAccountMetas = [];
|
5128
5010
|
markets = [];
|
5129
|
-
for (
|
5130
|
-
custody =
|
5011
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
5012
|
+
custody = _a[_i];
|
5131
5013
|
custodyAccountMetas.push({
|
5132
5014
|
pubkey: custody.custodyAccount,
|
5133
5015
|
isSigner: false,
|
@@ -5139,17 +5021,17 @@ var PerpetualsClient = (function () {
|
|
5139
5021
|
isWritable: false,
|
5140
5022
|
});
|
5141
5023
|
}
|
5142
|
-
for (
|
5143
|
-
market =
|
5024
|
+
for (_b = 0, _c = poolConfig.markets; _b < _c.length; _b++) {
|
5025
|
+
market = _c[_b];
|
5144
5026
|
markets.push({
|
5145
5027
|
pubkey: market.marketAccount,
|
5146
5028
|
isSigner: false,
|
5147
5029
|
isWritable: false,
|
5148
5030
|
});
|
5149
5031
|
}
|
5150
|
-
|
5032
|
+
_d.label = 1;
|
5151
5033
|
case 1:
|
5152
|
-
|
5034
|
+
_d.trys.push([1, 3, , 4]);
|
5153
5035
|
return [4, this.program.methods
|
5154
5036
|
.compoundFees({})
|
5155
5037
|
.accounts({
|
@@ -5168,12 +5050,12 @@ var PerpetualsClient = (function () {
|
|
5168
5050
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5169
5051
|
.instruction()];
|
5170
5052
|
case 2:
|
5171
|
-
compoundingFee =
|
5053
|
+
compoundingFee = _d.sent();
|
5172
5054
|
instructions.push(compoundingFee);
|
5173
5055
|
return [3, 4];
|
5174
5056
|
case 3:
|
5175
|
-
|
5176
|
-
console.log("perpClient compoundingFee error:: ",
|
5057
|
+
err_22 = _d.sent();
|
5058
|
+
console.log("perpClient compoundingFee error:: ", err_22);
|
5177
5059
|
return [3, 4];
|
5178
5060
|
case 4: return [2, {
|
5179
5061
|
instructions: __spreadArray([], instructions, true),
|
@@ -5184,7 +5066,7 @@ var PerpetualsClient = (function () {
|
|
5184
5066
|
});
|
5185
5067
|
};
|
5186
5068
|
this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
|
5187
|
-
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction,
|
5069
|
+
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_23;
|
5188
5070
|
return __generator(this, function (_b) {
|
5189
5071
|
switch (_b.label) {
|
5190
5072
|
case 0:
|
@@ -5248,9 +5130,9 @@ var PerpetualsClient = (function () {
|
|
5248
5130
|
instructions.push(burnAndClaimInstruction);
|
5249
5131
|
return [3, 8];
|
5250
5132
|
case 7:
|
5251
|
-
|
5252
|
-
console.log("perpClient burnAndClaimInstruction error:: ",
|
5253
|
-
throw
|
5133
|
+
err_23 = _b.sent();
|
5134
|
+
console.log("perpClient burnAndClaimInstruction error:: ", err_23);
|
5135
|
+
throw err_23;
|
5254
5136
|
case 8: return [2, {
|
5255
5137
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5256
5138
|
additionalSigners: additionalSigners
|
@@ -5259,7 +5141,7 @@ var PerpetualsClient = (function () {
|
|
5259
5141
|
});
|
5260
5142
|
}); };
|
5261
5143
|
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5262
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction,
|
5144
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_24;
|
5263
5145
|
return __generator(this, function (_a) {
|
5264
5146
|
switch (_a.label) {
|
5265
5147
|
case 0:
|
@@ -5310,9 +5192,9 @@ var PerpetualsClient = (function () {
|
|
5310
5192
|
instructions.push(burnAndStakeInstruction);
|
5311
5193
|
return [3, 4];
|
5312
5194
|
case 3:
|
5313
|
-
|
5314
|
-
console.log("perpClient burnAndStakeInstruction error:: ",
|
5315
|
-
throw
|
5195
|
+
err_24 = _a.sent();
|
5196
|
+
console.log("perpClient burnAndStakeInstruction error:: ", err_24);
|
5197
|
+
throw err_24;
|
5316
5198
|
case 4: return [2, {
|
5317
5199
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5318
5200
|
additionalSigners: additionalSigners
|
@@ -5321,7 +5203,7 @@ var PerpetualsClient = (function () {
|
|
5321
5203
|
});
|
5322
5204
|
}); };
|
5323
5205
|
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5324
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction,
|
5206
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_25;
|
5325
5207
|
return __generator(this, function (_a) {
|
5326
5208
|
switch (_a.label) {
|
5327
5209
|
case 0:
|
@@ -5362,9 +5244,9 @@ var PerpetualsClient = (function () {
|
|
5362
5244
|
instructions.push(depositTokenStakeInstruction);
|
5363
5245
|
return [3, 5];
|
5364
5246
|
case 4:
|
5365
|
-
|
5366
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5367
|
-
throw
|
5247
|
+
err_25 = _a.sent();
|
5248
|
+
console.log("perpClient depositStakingInstruction error:: ", err_25);
|
5249
|
+
throw err_25;
|
5368
5250
|
case 5: return [2, {
|
5369
5251
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5370
5252
|
additionalSigners: additionalSigners
|
@@ -5373,7 +5255,7 @@ var PerpetualsClient = (function () {
|
|
5373
5255
|
});
|
5374
5256
|
}); };
|
5375
5257
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5376
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5258
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_26;
|
5377
5259
|
return __generator(this, function (_a) {
|
5378
5260
|
switch (_a.label) {
|
5379
5261
|
case 0:
|
@@ -5402,9 +5284,9 @@ var PerpetualsClient = (function () {
|
|
5402
5284
|
instructions.push(unstakeTokenRequestInstruction);
|
5403
5285
|
return [3, 4];
|
5404
5286
|
case 3:
|
5405
|
-
|
5406
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5407
|
-
throw
|
5287
|
+
err_26 = _a.sent();
|
5288
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_26);
|
5289
|
+
throw err_26;
|
5408
5290
|
case 4: return [2, {
|
5409
5291
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5410
5292
|
additionalSigners: additionalSigners
|
@@ -5413,7 +5295,7 @@ var PerpetualsClient = (function () {
|
|
5413
5295
|
});
|
5414
5296
|
}); };
|
5415
5297
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5416
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5298
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_27;
|
5417
5299
|
return __generator(this, function (_a) {
|
5418
5300
|
switch (_a.label) {
|
5419
5301
|
case 0:
|
@@ -5453,9 +5335,9 @@ var PerpetualsClient = (function () {
|
|
5453
5335
|
instructions.push(unstakeTokenInstantInstruction);
|
5454
5336
|
return [3, 5];
|
5455
5337
|
case 4:
|
5456
|
-
|
5457
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5458
|
-
throw
|
5338
|
+
err_27 = _a.sent();
|
5339
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_27);
|
5340
|
+
throw err_27;
|
5459
5341
|
case 5: return [2, {
|
5460
5342
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5461
5343
|
additionalSigners: additionalSigners
|
@@ -5464,7 +5346,7 @@ var PerpetualsClient = (function () {
|
|
5464
5346
|
});
|
5465
5347
|
}); };
|
5466
5348
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5467
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5349
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_28;
|
5468
5350
|
return __generator(this, function (_a) {
|
5469
5351
|
switch (_a.label) {
|
5470
5352
|
case 0:
|
@@ -5504,9 +5386,9 @@ var PerpetualsClient = (function () {
|
|
5504
5386
|
instructions.push(withdrawTokenInstruction);
|
5505
5387
|
return [3, 5];
|
5506
5388
|
case 4:
|
5507
|
-
|
5508
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5509
|
-
throw
|
5389
|
+
err_28 = _a.sent();
|
5390
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_28);
|
5391
|
+
throw err_28;
|
5510
5392
|
case 5: return [2, {
|
5511
5393
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5512
5394
|
additionalSigners: additionalSigners
|
@@ -5515,7 +5397,7 @@ var PerpetualsClient = (function () {
|
|
5515
5397
|
});
|
5516
5398
|
}); };
|
5517
5399
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5518
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5400
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_29;
|
5519
5401
|
return __generator(this, function (_a) {
|
5520
5402
|
switch (_a.label) {
|
5521
5403
|
case 0:
|
@@ -5544,9 +5426,9 @@ var PerpetualsClient = (function () {
|
|
5544
5426
|
instructions.push(cancelUnstakeRequestInstruction);
|
5545
5427
|
return [3, 4];
|
5546
5428
|
case 3:
|
5547
|
-
|
5548
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5549
|
-
throw
|
5429
|
+
err_29 = _a.sent();
|
5430
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_29);
|
5431
|
+
throw err_29;
|
5550
5432
|
case 4: return [2, {
|
5551
5433
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5552
5434
|
additionalSigners: additionalSigners
|
@@ -5554,14 +5436,10 @@ var PerpetualsClient = (function () {
|
|
5554
5436
|
}
|
5555
5437
|
});
|
5556
5438
|
}); };
|
5557
|
-
this.collectTokenReward = function (
|
5558
|
-
|
5559
|
-
|
5560
|
-
|
5561
|
-
}
|
5562
|
-
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5563
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_31;
|
5564
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5439
|
+
this.collectTokenReward = function (owner, poolConfig, createUserATA) {
|
5440
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5441
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5442
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_30;
|
5565
5443
|
return __generator(this, function (_b) {
|
5566
5444
|
switch (_b.label) {
|
5567
5445
|
case 0:
|
@@ -5605,9 +5483,9 @@ var PerpetualsClient = (function () {
|
|
5605
5483
|
instructions.push(collectTokenRewardInstruction);
|
5606
5484
|
return [3, 6];
|
5607
5485
|
case 5:
|
5608
|
-
|
5609
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5610
|
-
throw
|
5486
|
+
err_30 = _b.sent();
|
5487
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_30);
|
5488
|
+
throw err_30;
|
5611
5489
|
case 6: return [2, {
|
5612
5490
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5613
5491
|
additionalSigners: additionalSigners
|
@@ -5616,14 +5494,10 @@ var PerpetualsClient = (function () {
|
|
5616
5494
|
});
|
5617
5495
|
});
|
5618
5496
|
};
|
5619
|
-
this.collectRevenue = function (
|
5620
|
-
|
5621
|
-
|
5622
|
-
|
5623
|
-
}
|
5624
|
-
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5625
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_32;
|
5626
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5497
|
+
this.collectRevenue = function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5498
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5499
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5500
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_31;
|
5627
5501
|
return __generator(this, function (_b) {
|
5628
5502
|
switch (_b.label) {
|
5629
5503
|
case 0:
|
@@ -5668,9 +5542,9 @@ var PerpetualsClient = (function () {
|
|
5668
5542
|
instructions.push(collectRevenueInstruction);
|
5669
5543
|
return [3, 6];
|
5670
5544
|
case 5:
|
5671
|
-
|
5672
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5673
|
-
throw
|
5545
|
+
err_31 = _b.sent();
|
5546
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_31);
|
5547
|
+
throw err_31;
|
5674
5548
|
case 6: return [2, {
|
5675
5549
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5676
5550
|
additionalSigners: additionalSigners
|
@@ -5680,7 +5554,7 @@ var PerpetualsClient = (function () {
|
|
5680
5554
|
});
|
5681
5555
|
};
|
5682
5556
|
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5683
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault,
|
5557
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_32;
|
5684
5558
|
return __generator(this, function (_a) {
|
5685
5559
|
switch (_a.label) {
|
5686
5560
|
case 0:
|
@@ -5717,9 +5591,9 @@ var PerpetualsClient = (function () {
|
|
5717
5591
|
instructions.push(initRewardVault);
|
5718
5592
|
return [3, 4];
|
5719
5593
|
case 3:
|
5720
|
-
|
5721
|
-
console.log("perpClient InitRewardVault error:: ",
|
5722
|
-
throw
|
5594
|
+
err_32 = _a.sent();
|
5595
|
+
console.log("perpClient InitRewardVault error:: ", err_32);
|
5596
|
+
throw err_32;
|
5723
5597
|
case 4: return [2, {
|
5724
5598
|
instructions: __spreadArray([], instructions, true),
|
5725
5599
|
additionalSigners: additionalSigners
|
@@ -5728,7 +5602,7 @@ var PerpetualsClient = (function () {
|
|
5728
5602
|
});
|
5729
5603
|
}); };
|
5730
5604
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5731
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward,
|
5605
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_33;
|
5732
5606
|
return __generator(this, function (_a) {
|
5733
5607
|
switch (_a.label) {
|
5734
5608
|
case 0:
|
@@ -5759,9 +5633,9 @@ var PerpetualsClient = (function () {
|
|
5759
5633
|
instructions.push(distributeReward);
|
5760
5634
|
return [3, 4];
|
5761
5635
|
case 3:
|
5762
|
-
|
5763
|
-
console.log("perpClient distributeReward error:: ",
|
5764
|
-
throw
|
5636
|
+
err_33 = _a.sent();
|
5637
|
+
console.log("perpClient distributeReward error:: ", err_33);
|
5638
|
+
throw err_33;
|
5765
5639
|
case 4: return [2, {
|
5766
5640
|
instructions: __spreadArray([], instructions, true),
|
5767
5641
|
additionalSigners: additionalSigners
|
@@ -5769,19 +5643,16 @@ var PerpetualsClient = (function () {
|
|
5769
5643
|
}
|
5770
5644
|
});
|
5771
5645
|
}); };
|
5772
|
-
this.collectNftReward = function (
|
5773
|
-
|
5774
|
-
|
5775
|
-
|
5776
|
-
}
|
5777
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5778
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_35;
|
5779
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5646
|
+
this.collectNftReward = function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5647
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5648
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5649
|
+
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5780
5650
|
return __generator(this, function (_b) {
|
5781
5651
|
switch (_b.label) {
|
5782
5652
|
case 0:
|
5783
5653
|
publicKey = this.provider.wallet.publicKey;
|
5784
|
-
|
5654
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5655
|
+
rewardCustodyMint = rewardToken.mintKey;
|
5785
5656
|
instructions = [];
|
5786
5657
|
additionalSigners = [];
|
5787
5658
|
_b.label = 1;
|
@@ -5789,7 +5660,7 @@ var PerpetualsClient = (function () {
|
|
5789
5660
|
_b.trys.push([1, 5, , 6]);
|
5790
5661
|
nftTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(nftMint, publicKey, true);
|
5791
5662
|
metadataAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), constants_1.METAPLEX_PROGRAM_ID.toBuffer(), nftMint.toBuffer()], constants_1.METAPLEX_PROGRAM_ID)[0];
|
5792
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5663
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5793
5664
|
_a = createUserATA;
|
5794
5665
|
if (!_a) return [3, 3];
|
5795
5666
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5798,7 +5669,7 @@ var PerpetualsClient = (function () {
|
|
5798
5669
|
_b.label = 3;
|
5799
5670
|
case 3:
|
5800
5671
|
if (_a) {
|
5801
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint));
|
5672
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, receivingTokenAccount, publicKey, rewardCustodyMint, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
5802
5673
|
}
|
5803
5674
|
rewardRecord = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_record"), nftMint.toBuffer()], this.programFbnftReward.programId)[0];
|
5804
5675
|
rewardVault = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("reward_vault")], this.programFbnftReward.programId)[0];
|
@@ -5818,7 +5689,7 @@ var PerpetualsClient = (function () {
|
|
5818
5689
|
rewardTokenAccount: rewardTokenAccount,
|
5819
5690
|
transferAuthority: nftTransferAuthority,
|
5820
5691
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5821
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5692
|
+
tokenProgram: rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
5822
5693
|
})
|
5823
5694
|
.instruction()];
|
5824
5695
|
case 4:
|
@@ -5826,8 +5697,8 @@ var PerpetualsClient = (function () {
|
|
5826
5697
|
instructions.push(collectNftReward);
|
5827
5698
|
return [3, 6];
|
5828
5699
|
case 5:
|
5829
|
-
|
5830
|
-
throw
|
5700
|
+
err_34 = _b.sent();
|
5701
|
+
throw err_34;
|
5831
5702
|
case 6: return [2, {
|
5832
5703
|
instructions: __spreadArray([], instructions, true),
|
5833
5704
|
additionalSigners: additionalSigners
|
@@ -5836,20 +5707,17 @@ var PerpetualsClient = (function () {
|
|
5836
5707
|
});
|
5837
5708
|
});
|
5838
5709
|
};
|
5839
|
-
this.collectAndDistributeFee = function (
|
5840
|
-
|
5841
|
-
|
5842
|
-
|
5843
|
-
}
|
5844
|
-
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5845
|
-
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_36;
|
5846
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5710
|
+
this.collectAndDistributeFee = function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5711
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5712
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5713
|
+
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5847
5714
|
return __generator(this, function (_b) {
|
5848
5715
|
switch (_b.label) {
|
5849
5716
|
case 0:
|
5850
5717
|
publicKey = this.provider.wallet.publicKey;
|
5851
|
-
|
5852
|
-
|
5718
|
+
rewardToken = poolConfig.getTokenFromSymbol(rewardSymbol);
|
5719
|
+
rewardCustodyMint = rewardToken.mintKey;
|
5720
|
+
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(rewardToken.mintKey); });
|
5853
5721
|
preInstructions = [];
|
5854
5722
|
instructions = [];
|
5855
5723
|
postInstructions = [];
|
@@ -5859,7 +5727,7 @@ var PerpetualsClient = (function () {
|
|
5859
5727
|
_b.trys.push([1, 5, , 6]);
|
5860
5728
|
pool = poolConfig.poolAddress;
|
5861
5729
|
flpStakeAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("stake"), publicKey.toBuffer(), pool.toBuffer()], this.program.programId)[0];
|
5862
|
-
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true);
|
5730
|
+
receivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(rewardCustodyMint, publicKey, true, rewardToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5863
5731
|
_a = createUserATA;
|
5864
5732
|
if (!_a) return [3, 3];
|
5865
5733
|
return [4, (0, utils_1.checkIfAccountExists)(receivingTokenAccount, this.provider.connection)];
|
@@ -5907,9 +5775,9 @@ var PerpetualsClient = (function () {
|
|
5907
5775
|
instructions.push(withdrawStakeInstruction);
|
5908
5776
|
return [3, 6];
|
5909
5777
|
case 5:
|
5910
|
-
|
5911
|
-
console.log("perpClient withdrawStake error:: ",
|
5912
|
-
throw
|
5778
|
+
err_35 = _b.sent();
|
5779
|
+
console.log("perpClient withdrawStake error:: ", err_35);
|
5780
|
+
throw err_35;
|
5913
5781
|
case 6: return [2, {
|
5914
5782
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5915
5783
|
additionalSigners: additionalSigners
|
@@ -5919,7 +5787,7 @@ var PerpetualsClient = (function () {
|
|
5919
5787
|
});
|
5920
5788
|
};
|
5921
5789
|
this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5922
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice,
|
5790
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_36;
|
5923
5791
|
return __generator(this, function (_a) {
|
5924
5792
|
switch (_a.label) {
|
5925
5793
|
case 0:
|
@@ -5958,9 +5826,9 @@ var PerpetualsClient = (function () {
|
|
5958
5826
|
instructions.push(setTriggerPrice);
|
5959
5827
|
return [3, 4];
|
5960
5828
|
case 3:
|
5961
|
-
|
5962
|
-
console.log("perpClient setTriggerPrice error:: ",
|
5963
|
-
throw
|
5829
|
+
err_36 = _a.sent();
|
5830
|
+
console.log("perpClient setTriggerPrice error:: ", err_36);
|
5831
|
+
throw err_36;
|
5964
5832
|
case 4: return [2, {
|
5965
5833
|
instructions: __spreadArray([], instructions, true),
|
5966
5834
|
additionalSigners: additionalSigners
|
@@ -5968,16 +5836,12 @@ var PerpetualsClient = (function () {
|
|
5968
5836
|
}
|
5969
5837
|
});
|
5970
5838
|
}); };
|
5971
|
-
this.forceClosePosition = function (
|
5972
|
-
|
5973
|
-
|
5974
|
-
|
5975
|
-
|
5976
|
-
|
5977
|
-
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_38;
|
5978
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
5979
|
-
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
5980
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5839
|
+
this.forceClosePosition = function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
5840
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5841
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
5842
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5843
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5844
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_37;
|
5981
5845
|
return __generator(this, function (_b) {
|
5982
5846
|
switch (_b.label) {
|
5983
5847
|
case 0:
|
@@ -5991,19 +5855,17 @@ var PerpetualsClient = (function () {
|
|
5991
5855
|
additionalSigners = [];
|
5992
5856
|
_b.label = 1;
|
5993
5857
|
case 1:
|
5994
|
-
_b.trys.push([1,
|
5995
|
-
|
5996
|
-
case 2:
|
5997
|
-
userReceivingTokenAccount = _b.sent();
|
5858
|
+
_b.trys.push([1, 5, , 6]);
|
5859
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, positionAccount.owner, false, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
5998
5860
|
_a = createUserATA;
|
5999
|
-
if (!_a) return [3,
|
5861
|
+
if (!_a) return [3, 3];
|
6000
5862
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6001
|
-
case
|
5863
|
+
case 2:
|
6002
5864
|
_a = !(_b.sent());
|
6003
|
-
_b.label =
|
6004
|
-
case
|
5865
|
+
_b.label = 3;
|
5866
|
+
case 3:
|
6005
5867
|
if (_a) {
|
6006
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
5868
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, positionAccount.owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6007
5869
|
}
|
6008
5870
|
return [4, this.program.methods
|
6009
5871
|
.forceClosePosition({
|
@@ -6026,22 +5888,23 @@ var PerpetualsClient = (function () {
|
|
6026
5888
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6027
5889
|
eventAuthority: this.eventAuthority.publicKey,
|
6028
5890
|
program: this.programId,
|
6029
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
5891
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5892
|
+
receivingMint: collateralCustodyConfig.mintKey
|
6030
5893
|
})
|
6031
5894
|
.instruction()];
|
6032
|
-
case
|
5895
|
+
case 4:
|
6033
5896
|
forceClosePosition = _b.sent();
|
6034
5897
|
instructions.push(forceClosePosition);
|
6035
5898
|
if (collateralSymbol == 'WSOL' && closeUsersWSOLATA) {
|
6036
5899
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userReceivingTokenAccount, positionAccount.owner, positionAccount.owner);
|
6037
5900
|
postInstructions.push(closeWsolATAIns);
|
6038
5901
|
}
|
6039
|
-
return [3,
|
6040
|
-
case
|
6041
|
-
|
6042
|
-
console.log("perpClient forceClosePosition error:: ",
|
6043
|
-
throw
|
6044
|
-
case
|
5902
|
+
return [3, 6];
|
5903
|
+
case 5:
|
5904
|
+
err_37 = _b.sent();
|
5905
|
+
console.log("perpClient forceClosePosition error:: ", err_37);
|
5906
|
+
throw err_37;
|
5907
|
+
case 6: return [2, {
|
6045
5908
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6046
5909
|
additionalSigners: additionalSigners
|
6047
5910
|
}];
|
@@ -6049,15 +5912,11 @@ var PerpetualsClient = (function () {
|
|
6049
5912
|
});
|
6050
5913
|
});
|
6051
5914
|
};
|
6052
|
-
this.placeLimitOrder = function (
|
6053
|
-
|
6054
|
-
|
6055
|
-
|
6056
|
-
|
6057
|
-
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) {
|
6058
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_39;
|
6059
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6060
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5915
|
+
this.placeLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, limitPrice, reserveAmount, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
5916
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
5917
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5918
|
+
return __awaiter(_this, void 0, void 0, function () {
|
5919
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_38;
|
6061
5920
|
return __generator(this, function (_c) {
|
6062
5921
|
switch (_c.label) {
|
6063
5922
|
case 0:
|
@@ -6067,30 +5926,28 @@ var PerpetualsClient = (function () {
|
|
6067
5926
|
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
6068
5927
|
receiveCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(receiveSymbol).mintKey); });
|
6069
5928
|
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
6070
|
-
|
6071
|
-
case 1:
|
6072
|
-
userReserveTokenAccount = _c.sent();
|
5929
|
+
userReserveTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6073
5930
|
preInstructions = [];
|
6074
5931
|
instructions = [];
|
6075
5932
|
postInstructions = [];
|
6076
5933
|
additionalSigners = [];
|
6077
|
-
_c.label =
|
6078
|
-
case
|
6079
|
-
_c.trys.push([
|
6080
|
-
if (!(reserveSymbol == 'SOL')) return [3,
|
5934
|
+
_c.label = 1;
|
5935
|
+
case 1:
|
5936
|
+
_c.trys.push([1, 9, , 10]);
|
5937
|
+
if (!(reserveSymbol == 'SOL')) return [3, 4];
|
6081
5938
|
console.log("reserveSymbol === SOL", reserveSymbol);
|
6082
5939
|
accCreationLamports = this.minimumBalanceForRentExemptAccountLamports;
|
6083
5940
|
lamports = reserveAmount.add(new anchor_1.BN(accCreationLamports));
|
6084
|
-
if (!!skipBalanceChecks) return [3,
|
5941
|
+
if (!!skipBalanceChecks) return [3, 3];
|
6085
5942
|
_a = anchor_1.BN.bind;
|
6086
5943
|
return [4, this.provider.connection.getBalance(publicKey)];
|
6087
|
-
case
|
5944
|
+
case 2:
|
6088
5945
|
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
6089
5946
|
if (unWrappedSolBalance.lt(lamports)) {
|
6090
5947
|
throw "Insufficient SOL Funds";
|
6091
5948
|
}
|
6092
|
-
_c.label =
|
6093
|
-
case
|
5949
|
+
_c.label = 3;
|
5950
|
+
case 3:
|
6094
5951
|
if (!ephemeralSignerPubkey) {
|
6095
5952
|
wrappedSolAccount = new web3_js_1.Keypair();
|
6096
5953
|
additionalSigners.push(wrappedSolAccount);
|
@@ -6109,22 +5966,22 @@ var PerpetualsClient = (function () {
|
|
6109
5966
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
6110
5967
|
];
|
6111
5968
|
additionalSigners.push(wrappedSolAccount);
|
6112
|
-
return [3,
|
6113
|
-
case
|
6114
|
-
case
|
5969
|
+
return [3, 7];
|
5970
|
+
case 4: return [4, (0, utils_1.checkIfAccountExists)(userReserveTokenAccount, this.provider.connection)];
|
5971
|
+
case 5:
|
6115
5972
|
if (!(_c.sent())) {
|
6116
5973
|
throw "Insufficient Funds , token Account doesn't exist";
|
6117
5974
|
}
|
6118
|
-
if (!!skipBalanceChecks) return [3,
|
5975
|
+
if (!!skipBalanceChecks) return [3, 7];
|
6119
5976
|
_b = anchor_1.BN.bind;
|
6120
5977
|
return [4, this.provider.connection.getTokenAccountBalance(userReserveTokenAccount)];
|
6121
|
-
case
|
5978
|
+
case 6:
|
6122
5979
|
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
6123
5980
|
if (tokenAccountBalance.lt(reserveAmount)) {
|
6124
5981
|
throw "Insufficient Funds need more ".concat(reserveAmount.sub(tokenAccountBalance), " tokens");
|
6125
5982
|
}
|
6126
|
-
_c.label =
|
6127
|
-
case
|
5983
|
+
_c.label = 7;
|
5984
|
+
case 7:
|
6128
5985
|
positionAccount = poolConfig.getPositionFromMarketPk(publicKey, marketAccount);
|
6129
5986
|
orderAccount = poolConfig.getOrderFromMarketPk(publicKey, marketAccount);
|
6130
5987
|
return [4, this.program.methods
|
@@ -6151,21 +6008,22 @@ var PerpetualsClient = (function () {
|
|
6151
6008
|
reserveCustodyTokenAccount: reserveCustodyConfig.tokenAccount,
|
6152
6009
|
receiveCustody: receiveCustodyConfig.custodyAccount,
|
6153
6010
|
systemProgram: web3_js_1.SystemProgram.programId,
|
6154
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6011
|
+
tokenProgram: poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
6155
6012
|
eventAuthority: this.eventAuthority.publicKey,
|
6156
6013
|
program: this.programId,
|
6157
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6014
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6015
|
+
fundingMint: reserveCustodyConfig.mintKey,
|
6158
6016
|
})
|
6159
6017
|
.instruction()];
|
6160
|
-
case
|
6018
|
+
case 8:
|
6161
6019
|
placeLimitOrder = _c.sent();
|
6162
6020
|
instructions.push(placeLimitOrder);
|
6163
|
-
return [3,
|
6164
|
-
case
|
6165
|
-
|
6166
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6167
|
-
throw
|
6168
|
-
case
|
6021
|
+
return [3, 10];
|
6022
|
+
case 9:
|
6023
|
+
err_38 = _c.sent();
|
6024
|
+
console.log("perpClient placeLimitOrder error:: ", err_38);
|
6025
|
+
throw err_38;
|
6026
|
+
case 10: return [2, {
|
6169
6027
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6170
6028
|
additionalSigners: additionalSigners
|
6171
6029
|
}];
|
@@ -6173,15 +6031,11 @@ var PerpetualsClient = (function () {
|
|
6173
6031
|
});
|
6174
6032
|
});
|
6175
6033
|
};
|
6176
|
-
this.editLimitOrder = function (
|
6177
|
-
|
6178
|
-
|
6179
|
-
|
6180
|
-
|
6181
|
-
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) {
|
6182
|
-
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_40;
|
6183
|
-
if (createUserATA === void 0) { createUserATA = true; }
|
6184
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6034
|
+
this.editLimitOrder = function (targetSymbol, collateralSymbol, reserveSymbol, receiveSymbol, side, orderId, limitPrice, sizeAmount, stopLossPrice, takeProfitPrice, poolConfig, createUserATA, ephemeralSignerPubkey) {
|
6035
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6036
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6037
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6038
|
+
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_39;
|
6185
6039
|
return __generator(this, function (_b) {
|
6186
6040
|
switch (_b.label) {
|
6187
6041
|
case 0:
|
@@ -6219,7 +6073,7 @@ var PerpetualsClient = (function () {
|
|
6219
6073
|
];
|
6220
6074
|
return [3, 5];
|
6221
6075
|
case 2:
|
6222
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true);
|
6076
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, publicKey, true, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6223
6077
|
_a = createUserATA;
|
6224
6078
|
if (!_a) return [3, 4];
|
6225
6079
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6228,7 +6082,7 @@ var PerpetualsClient = (function () {
|
|
6228
6082
|
_b.label = 4;
|
6229
6083
|
case 4:
|
6230
6084
|
if (_a) {
|
6231
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey));
|
6085
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(reserveSymbol).mintKey, poolConfig.getTokenFromSymbol(reserveSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6232
6086
|
}
|
6233
6087
|
_b.label = 5;
|
6234
6088
|
case 5:
|
@@ -6269,9 +6123,9 @@ var PerpetualsClient = (function () {
|
|
6269
6123
|
instructions.push(editLimitOrder);
|
6270
6124
|
return [3, 8];
|
6271
6125
|
case 7:
|
6272
|
-
|
6273
|
-
console.log("perpClient editLimitOrder error:: ",
|
6274
|
-
throw
|
6126
|
+
err_39 = _b.sent();
|
6127
|
+
console.log("perpClient editLimitOrder error:: ", err_39);
|
6128
|
+
throw err_39;
|
6275
6129
|
case 8: return [2, {
|
6276
6130
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6277
6131
|
additionalSigners: additionalSigners
|
@@ -6280,16 +6134,12 @@ var PerpetualsClient = (function () {
|
|
6280
6134
|
});
|
6281
6135
|
});
|
6282
6136
|
};
|
6283
|
-
this.executeLimitOrder = function (
|
6284
|
-
|
6285
|
-
|
6286
|
-
|
6287
|
-
|
6288
|
-
|
6289
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_41;
|
6290
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6291
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6292
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6137
|
+
this.executeLimitOrder = function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6138
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6139
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6140
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6141
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6142
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_40;
|
6293
6143
|
return __generator(this, function (_a) {
|
6294
6144
|
switch (_a.label) {
|
6295
6145
|
case 0:
|
@@ -6338,9 +6188,9 @@ var PerpetualsClient = (function () {
|
|
6338
6188
|
instructions.push(executeLimitOrder);
|
6339
6189
|
return [3, 4];
|
6340
6190
|
case 3:
|
6341
|
-
|
6342
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6343
|
-
throw
|
6191
|
+
err_40 = _a.sent();
|
6192
|
+
console.log("perpClient executeLimitOrder error:: ", err_40);
|
6193
|
+
throw err_40;
|
6344
6194
|
case 4: return [2, {
|
6345
6195
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6346
6196
|
additionalSigners: additionalSigners
|
@@ -6349,16 +6199,12 @@ var PerpetualsClient = (function () {
|
|
6349
6199
|
});
|
6350
6200
|
});
|
6351
6201
|
};
|
6352
|
-
this.executeLimitWithSwap = function (
|
6353
|
-
|
6354
|
-
|
6355
|
-
|
6356
|
-
|
6357
|
-
|
6358
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_42;
|
6359
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6360
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6361
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6202
|
+
this.executeLimitWithSwap = function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6203
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6204
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6205
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6206
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6207
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_41;
|
6362
6208
|
return __generator(this, function (_a) {
|
6363
6209
|
switch (_a.label) {
|
6364
6210
|
case 0:
|
@@ -6410,9 +6256,9 @@ var PerpetualsClient = (function () {
|
|
6410
6256
|
instructions.push(executeLimitWithSwap);
|
6411
6257
|
return [3, 4];
|
6412
6258
|
case 3:
|
6413
|
-
|
6414
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6415
|
-
throw
|
6259
|
+
err_41 = _a.sent();
|
6260
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_41);
|
6261
|
+
throw err_41;
|
6416
6262
|
case 4: return [2, {
|
6417
6263
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6418
6264
|
additionalSigners: additionalSigners
|
@@ -6422,7 +6268,7 @@ var PerpetualsClient = (function () {
|
|
6422
6268
|
});
|
6423
6269
|
};
|
6424
6270
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6425
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
6271
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_42;
|
6426
6272
|
return __generator(this, function (_a) {
|
6427
6273
|
switch (_a.label) {
|
6428
6274
|
case 0:
|
@@ -6470,9 +6316,9 @@ var PerpetualsClient = (function () {
|
|
6470
6316
|
instructions.push(placeTriggerOrder);
|
6471
6317
|
return [3, 4];
|
6472
6318
|
case 3:
|
6473
|
-
|
6474
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6475
|
-
throw
|
6319
|
+
err_42 = _a.sent();
|
6320
|
+
console.log("perpClient placeTriggerOrder error:: ", err_42);
|
6321
|
+
throw err_42;
|
6476
6322
|
case 4: return [2, {
|
6477
6323
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6478
6324
|
additionalSigners: additionalSigners
|
@@ -6481,7 +6327,7 @@ var PerpetualsClient = (function () {
|
|
6481
6327
|
});
|
6482
6328
|
}); };
|
6483
6329
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6484
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
6330
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_43;
|
6485
6331
|
return __generator(this, function (_a) {
|
6486
6332
|
switch (_a.label) {
|
6487
6333
|
case 0:
|
@@ -6528,9 +6374,9 @@ var PerpetualsClient = (function () {
|
|
6528
6374
|
instructions.push(editTriggerOrder);
|
6529
6375
|
return [3, 4];
|
6530
6376
|
case 3:
|
6531
|
-
|
6532
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6533
|
-
throw
|
6377
|
+
err_43 = _a.sent();
|
6378
|
+
console.log("perpClient editTriggerOrder error:: ", err_43);
|
6379
|
+
throw err_43;
|
6534
6380
|
case 4: return [2, {
|
6535
6381
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6536
6382
|
additionalSigners: additionalSigners
|
@@ -6539,7 +6385,7 @@ var PerpetualsClient = (function () {
|
|
6539
6385
|
});
|
6540
6386
|
}); };
|
6541
6387
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6542
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
6388
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_44;
|
6543
6389
|
return __generator(this, function (_a) {
|
6544
6390
|
switch (_a.label) {
|
6545
6391
|
case 0:
|
@@ -6572,9 +6418,9 @@ var PerpetualsClient = (function () {
|
|
6572
6418
|
instructions.push(cancelTriggerOrder);
|
6573
6419
|
return [3, 4];
|
6574
6420
|
case 3:
|
6575
|
-
|
6576
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6577
|
-
throw
|
6421
|
+
err_44 = _a.sent();
|
6422
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_44);
|
6423
|
+
throw err_44;
|
6578
6424
|
case 4: return [2, {
|
6579
6425
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6580
6426
|
additionalSigners: additionalSigners
|
@@ -6583,7 +6429,7 @@ var PerpetualsClient = (function () {
|
|
6583
6429
|
});
|
6584
6430
|
}); };
|
6585
6431
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6586
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
6432
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_45;
|
6587
6433
|
return __generator(this, function (_a) {
|
6588
6434
|
switch (_a.label) {
|
6589
6435
|
case 0:
|
@@ -6614,9 +6460,9 @@ var PerpetualsClient = (function () {
|
|
6614
6460
|
instructions.push(cancelAllTriggerOrders);
|
6615
6461
|
return [3, 4];
|
6616
6462
|
case 3:
|
6617
|
-
|
6618
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6619
|
-
throw
|
6463
|
+
err_45 = _a.sent();
|
6464
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_45);
|
6465
|
+
throw err_45;
|
6620
6466
|
case 4: return [2, {
|
6621
6467
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6622
6468
|
additionalSigners: additionalSigners
|
@@ -6624,20 +6470,16 @@ var PerpetualsClient = (function () {
|
|
6624
6470
|
}
|
6625
6471
|
});
|
6626
6472
|
}); };
|
6627
|
-
this.executeTriggerWithSwap = function (
|
6628
|
-
|
6629
|
-
|
6630
|
-
|
6631
|
-
}
|
6632
|
-
|
6633
|
-
|
6634
|
-
|
6635
|
-
|
6636
|
-
|
6637
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6638
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6639
|
-
return __generator(this, function (_e) {
|
6640
|
-
switch (_e.label) {
|
6473
|
+
this.executeTriggerWithSwap = function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6474
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6475
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6476
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6477
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6478
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6479
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6480
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _i, _c, custody, executeTriggerWithSwap, err_46;
|
6481
|
+
return __generator(this, function (_d) {
|
6482
|
+
switch (_d.label) {
|
6641
6483
|
case 0:
|
6642
6484
|
payerPubkey = this.provider.wallet.publicKey;
|
6643
6485
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6648,19 +6490,21 @@ var PerpetualsClient = (function () {
|
|
6648
6490
|
instructions = [];
|
6649
6491
|
postInstructions = [];
|
6650
6492
|
additionalSigners = [];
|
6651
|
-
|
6493
|
+
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
6494
|
+
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
6495
|
+
_d.label = 1;
|
6652
6496
|
case 1:
|
6653
|
-
|
6497
|
+
_d.trys.push([1, 9, , 10]);
|
6654
6498
|
if (!false) return [3, 2];
|
6655
6499
|
return [3, 7];
|
6656
6500
|
case 2:
|
6657
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true);
|
6501
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(receivingSymbol).mintKey, owner, true, receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6658
6502
|
_a = createUserATA;
|
6659
6503
|
if (!_a) return [3, 4];
|
6660
6504
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6661
6505
|
case 3:
|
6662
|
-
_a = !(
|
6663
|
-
|
6506
|
+
_a = !(_d.sent());
|
6507
|
+
_d.label = 4;
|
6664
6508
|
case 4:
|
6665
6509
|
if (_a) {
|
6666
6510
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6670,20 +6514,20 @@ var PerpetualsClient = (function () {
|
|
6670
6514
|
if (!_b) return [3, 6];
|
6671
6515
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6672
6516
|
case 5:
|
6673
|
-
_b = !(
|
6674
|
-
|
6517
|
+
_b = !(_d.sent());
|
6518
|
+
_d.label = 6;
|
6675
6519
|
case 6:
|
6676
6520
|
if (_b) {
|
6677
6521
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6678
6522
|
}
|
6679
|
-
|
6523
|
+
_d.label = 7;
|
6680
6524
|
case 7:
|
6681
6525
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6682
6526
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6683
6527
|
custodyAccountMetas = [];
|
6684
6528
|
custodyOracleAccountMetas = [];
|
6685
|
-
for (
|
6686
|
-
custody =
|
6529
|
+
for (_i = 0, _c = poolConfig.custodies; _i < _c.length; _i++) {
|
6530
|
+
custody = _c[_i];
|
6687
6531
|
custodyAccountMetas.push({
|
6688
6532
|
pubkey: custody.custodyAccount,
|
6689
6533
|
isSigner: false,
|
@@ -6720,21 +6564,24 @@ var PerpetualsClient = (function () {
|
|
6720
6564
|
dispensingCustody: receivingCustodyConfig.custodyAccount,
|
6721
6565
|
dispensingOracleAccount: this.useExtOracleAccount ? receivingCustodyConfig.extOracleAccount : receivingCustodyConfig.intOracleAccount,
|
6722
6566
|
dispensingCustodyTokenAccount: receivingCustodyConfig.tokenAccount,
|
6723
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6724
6567
|
eventAuthority: this.eventAuthority.publicKey,
|
6725
6568
|
program: this.programId,
|
6726
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6569
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6570
|
+
receivingMint: receivingCustodyConfig.mintKey,
|
6571
|
+
receivingTokenProgram: receivingToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
6572
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
6573
|
+
collateralTokenProgram: collateralToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
6727
6574
|
})
|
6728
6575
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6729
6576
|
.instruction()];
|
6730
6577
|
case 8:
|
6731
|
-
executeTriggerWithSwap =
|
6578
|
+
executeTriggerWithSwap = _d.sent();
|
6732
6579
|
instructions.push(executeTriggerWithSwap);
|
6733
6580
|
return [3, 10];
|
6734
6581
|
case 9:
|
6735
|
-
|
6736
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6737
|
-
throw
|
6582
|
+
err_46 = _d.sent();
|
6583
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_46);
|
6584
|
+
throw err_46;
|
6738
6585
|
case 10: return [2, {
|
6739
6586
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6740
6587
|
additionalSigners: additionalSigners
|
@@ -6743,18 +6590,14 @@ var PerpetualsClient = (function () {
|
|
6743
6590
|
});
|
6744
6591
|
});
|
6745
6592
|
};
|
6746
|
-
this.executeTriggerOrder = function (
|
6747
|
-
|
6748
|
-
|
6749
|
-
|
6750
|
-
}
|
6751
|
-
|
6752
|
-
|
6753
|
-
|
6754
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6755
|
-
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6756
|
-
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6757
|
-
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6593
|
+
this.executeTriggerOrder = function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6594
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6595
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6596
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6597
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6598
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6599
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6600
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_47;
|
6758
6601
|
return __generator(this, function (_b) {
|
6759
6602
|
switch (_b.label) {
|
6760
6603
|
case 0:
|
@@ -6772,7 +6615,7 @@ var PerpetualsClient = (function () {
|
|
6772
6615
|
if (!false) return [3, 2];
|
6773
6616
|
return [3, 5];
|
6774
6617
|
case 2:
|
6775
|
-
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true);
|
6618
|
+
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, owner, true, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
6776
6619
|
_a = createUserATA;
|
6777
6620
|
if (!_a) return [3, 4];
|
6778
6621
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
@@ -6781,7 +6624,7 @@ var PerpetualsClient = (function () {
|
|
6781
6624
|
_b.label = 4;
|
6782
6625
|
case 4:
|
6783
6626
|
if (_a) {
|
6784
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6627
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey, poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
6785
6628
|
}
|
6786
6629
|
_b.label = 5;
|
6787
6630
|
case 5:
|
@@ -6808,10 +6651,11 @@ var PerpetualsClient = (function () {
|
|
6808
6651
|
collateralCustody: collateralCustodyConfig.custodyAccount,
|
6809
6652
|
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
6810
6653
|
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
6811
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6654
|
+
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
6812
6655
|
eventAuthority: this.eventAuthority.publicKey,
|
6813
6656
|
program: this.programId,
|
6814
6657
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6658
|
+
receivingMint: collateralCustodyConfig.mintKey
|
6815
6659
|
})
|
6816
6660
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6817
6661
|
.instruction()];
|
@@ -6820,9 +6664,9 @@ var PerpetualsClient = (function () {
|
|
6820
6664
|
instructions.push(executeTriggerOrder);
|
6821
6665
|
return [3, 8];
|
6822
6666
|
case 7:
|
6823
|
-
|
6824
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6825
|
-
throw
|
6667
|
+
err_47 = _b.sent();
|
6668
|
+
console.log("perpClient executeTriggerOrder error:: ", err_47);
|
6669
|
+
throw err_47;
|
6826
6670
|
case 8: return [2, {
|
6827
6671
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6828
6672
|
additionalSigners: additionalSigners
|
@@ -6832,7 +6676,7 @@ var PerpetualsClient = (function () {
|
|
6832
6676
|
});
|
6833
6677
|
};
|
6834
6678
|
this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6835
|
-
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder,
|
6679
|
+
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_48;
|
6836
6680
|
return __generator(this, function (_a) {
|
6837
6681
|
switch (_a.label) {
|
6838
6682
|
case 0:
|
@@ -6862,9 +6706,9 @@ var PerpetualsClient = (function () {
|
|
6862
6706
|
instructions.push(migrateTriggerOrder);
|
6863
6707
|
return [3, 4];
|
6864
6708
|
case 3:
|
6865
|
-
|
6866
|
-
console.log("perpClient migrateTriggerOrder error:: ",
|
6867
|
-
throw
|
6709
|
+
err_48 = _a.sent();
|
6710
|
+
console.log("perpClient migrateTriggerOrder error:: ", err_48);
|
6711
|
+
throw err_48;
|
6868
6712
|
case 4: return [2, {
|
6869
6713
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6870
6714
|
additionalSigners: additionalSigners
|
@@ -6872,20 +6716,16 @@ var PerpetualsClient = (function () {
|
|
6872
6716
|
}
|
6873
6717
|
});
|
6874
6718
|
}); };
|
6875
|
-
this.swap = function (
|
6876
|
-
|
6877
|
-
|
6878
|
-
|
6879
|
-
}
|
6880
|
-
|
6881
|
-
|
6882
|
-
|
6883
|
-
|
6884
|
-
|
6885
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6886
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6887
|
-
return __generator(this, function (_g) {
|
6888
|
-
switch (_g.label) {
|
6719
|
+
this.swap = function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
6720
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
6721
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6722
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
6723
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6724
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6725
|
+
return __awaiter(_this, void 0, void 0, function () {
|
6726
|
+
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, _i, _e, custody, params, inx, closeWsolATAIns, err_49;
|
6727
|
+
return __generator(this, function (_f) {
|
6728
|
+
switch (_f.label) {
|
6889
6729
|
case 0:
|
6890
6730
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
6891
6731
|
if (!userInputCustodyConfig) {
|
@@ -6903,10 +6743,10 @@ var PerpetualsClient = (function () {
|
|
6903
6743
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
6904
6744
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
6905
6745
|
case 1:
|
6906
|
-
wsolAssociatedTokenAccount =
|
6746
|
+
wsolAssociatedTokenAccount = _f.sent();
|
6907
6747
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
6908
6748
|
case 2:
|
6909
|
-
wsolATAExist =
|
6749
|
+
wsolATAExist = _f.sent();
|
6910
6750
|
if (!wsolATAExist) {
|
6911
6751
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
6912
6752
|
}
|
@@ -6914,11 +6754,11 @@ var PerpetualsClient = (function () {
|
|
6914
6754
|
_a = anchor_1.BN.bind;
|
6915
6755
|
return [4, this.provider.connection.getBalance(publicKey)];
|
6916
6756
|
case 3:
|
6917
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
6757
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
6918
6758
|
if (unWrappedSolBalance.lt(amountIn)) {
|
6919
6759
|
throw "Insufficient SOL Funds";
|
6920
6760
|
}
|
6921
|
-
|
6761
|
+
_f.label = 4;
|
6922
6762
|
case 4:
|
6923
6763
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
6924
6764
|
fromPubkey: publicKey,
|
@@ -6940,20 +6780,20 @@ var PerpetualsClient = (function () {
|
|
6940
6780
|
additionalSigners: additionalSigners
|
6941
6781
|
}];
|
6942
6782
|
}
|
6943
|
-
|
6783
|
+
_f.label = 6;
|
6944
6784
|
case 6:
|
6945
|
-
|
6785
|
+
_f.trys.push([6, 19, , 20]);
|
6946
6786
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
6947
6787
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
6948
6788
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
6949
6789
|
case 7:
|
6950
|
-
accCreationLamports = (
|
6790
|
+
accCreationLamports = (_f.sent());
|
6951
6791
|
console.log("accCreationLamports:", accCreationLamports);
|
6952
6792
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
6953
6793
|
_b = anchor_1.BN.bind;
|
6954
6794
|
return [4, this.provider.connection.getBalance(publicKey)];
|
6955
6795
|
case 8:
|
6956
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
6796
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
6957
6797
|
if (unWrappedSolBalance.lt(amountIn)) {
|
6958
6798
|
throw "Insufficient SOL Funds";
|
6959
6799
|
}
|
@@ -6980,18 +6820,18 @@ var PerpetualsClient = (function () {
|
|
6980
6820
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
6981
6821
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
6982
6822
|
case 10:
|
6983
|
-
if (!(
|
6823
|
+
if (!(_f.sent())) {
|
6984
6824
|
throw "Insufficient Funds , Token Account doesn't exist";
|
6985
6825
|
}
|
6986
6826
|
if (!!skipBalanceChecks) return [3, 12];
|
6987
6827
|
_c = anchor_1.BN.bind;
|
6988
6828
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
6989
6829
|
case 11:
|
6990
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
6830
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_f.sent()).value.amount]))();
|
6991
6831
|
if (tokenAccountBalance.lt(amountIn)) {
|
6992
6832
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
6993
6833
|
}
|
6994
|
-
|
6834
|
+
_f.label = 12;
|
6995
6835
|
case 12:
|
6996
6836
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
6997
6837
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -7016,23 +6856,23 @@ var PerpetualsClient = (function () {
|
|
7016
6856
|
return [3, 17];
|
7017
6857
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
7018
6858
|
case 14:
|
7019
|
-
userOutputTokenAccount =
|
6859
|
+
userOutputTokenAccount = _f.sent();
|
7020
6860
|
_d = createUserATA;
|
7021
6861
|
if (!_d) return [3, 16];
|
7022
6862
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
7023
6863
|
case 15:
|
7024
|
-
_d = !(
|
7025
|
-
|
6864
|
+
_d = !(_f.sent());
|
6865
|
+
_f.label = 16;
|
7026
6866
|
case 16:
|
7027
6867
|
if (_d) {
|
7028
6868
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
7029
6869
|
}
|
7030
|
-
|
6870
|
+
_f.label = 17;
|
7031
6871
|
case 17:
|
7032
6872
|
custodyAccountMetas = [];
|
7033
6873
|
custodyOracleAccountMetas = [];
|
7034
|
-
for (
|
7035
|
-
custody =
|
6874
|
+
for (_i = 0, _e = poolConfig.custodies; _i < _e.length; _i++) {
|
6875
|
+
custody = _e[_i];
|
7036
6876
|
custodyAccountMetas.push({
|
7037
6877
|
pubkey: custody.custodyAccount,
|
7038
6878
|
isSigner: false,
|
@@ -7065,14 +6905,17 @@ var PerpetualsClient = (function () {
|
|
7065
6905
|
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
7066
6906
|
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
7067
6907
|
eventAuthority: this.eventAuthority.publicKey,
|
7068
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7069
6908
|
program: this.programId,
|
7070
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6909
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6910
|
+
fundingMint: userInputCustodyConfig.mintKey,
|
6911
|
+
fundingTokenProgram: poolConfig.getTokenFromSymbol(userInputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
6912
|
+
receivingMint: userOutputCustodyConfig.mintKey,
|
6913
|
+
receivingTokenProgram: poolConfig.getTokenFromSymbol(userOutputTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
7071
6914
|
})
|
7072
6915
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
7073
6916
|
.instruction()];
|
7074
6917
|
case 18:
|
7075
|
-
inx =
|
6918
|
+
inx = _f.sent();
|
7076
6919
|
instructions.push(inx);
|
7077
6920
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
7078
6921
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -7080,9 +6923,9 @@ var PerpetualsClient = (function () {
|
|
7080
6923
|
}
|
7081
6924
|
return [3, 20];
|
7082
6925
|
case 19:
|
7083
|
-
|
7084
|
-
console.error("perpClient Swap error:: ",
|
7085
|
-
throw
|
6926
|
+
err_49 = _f.sent();
|
6927
|
+
console.error("perpClient Swap error:: ", err_49);
|
6928
|
+
throw err_49;
|
7086
6929
|
case 20: return [2, {
|
7087
6930
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7088
6931
|
additionalSigners: additionalSigners
|
@@ -7092,7 +6935,7 @@ var PerpetualsClient = (function () {
|
|
7092
6935
|
});
|
7093
6936
|
};
|
7094
6937
|
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7095
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx,
|
6938
|
+
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_50;
|
7096
6939
|
return __generator(this, function (_b) {
|
7097
6940
|
switch (_b.label) {
|
7098
6941
|
case 0:
|
@@ -7152,9 +6995,9 @@ var PerpetualsClient = (function () {
|
|
7152
6995
|
instructions.push(inx);
|
7153
6996
|
return [3, 4];
|
7154
6997
|
case 3:
|
7155
|
-
|
7156
|
-
console.error("perpClient Swap error:: ",
|
7157
|
-
throw
|
6998
|
+
err_50 = _b.sent();
|
6999
|
+
console.error("perpClient Swap error:: ", err_50);
|
7000
|
+
throw err_50;
|
7158
7001
|
case 4: return [2, {
|
7159
7002
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7160
7003
|
additionalSigners: additionalSigners
|
@@ -7202,7 +7045,7 @@ var PerpetualsClient = (function () {
|
|
7202
7045
|
});
|
7203
7046
|
}); };
|
7204
7047
|
this.setAdminSigners = function (admins, minSignatures) { return __awaiter(_this, void 0, void 0, function () {
|
7205
|
-
var adminMetas, _i, admins_2, admin,
|
7048
|
+
var adminMetas, _i, admins_2, admin, err_51;
|
7206
7049
|
return __generator(this, function (_a) {
|
7207
7050
|
switch (_a.label) {
|
7208
7051
|
case 0:
|
@@ -7232,11 +7075,11 @@ var PerpetualsClient = (function () {
|
|
7232
7075
|
_a.sent();
|
7233
7076
|
return [3, 4];
|
7234
7077
|
case 3:
|
7235
|
-
|
7078
|
+
err_51 = _a.sent();
|
7236
7079
|
if (this.printErrors) {
|
7237
|
-
console.error("setAdminSigners err:",
|
7080
|
+
console.error("setAdminSigners err:", err_51);
|
7238
7081
|
}
|
7239
|
-
throw
|
7082
|
+
throw err_51;
|
7240
7083
|
case 4: return [2];
|
7241
7084
|
}
|
7242
7085
|
});
|
@@ -7301,7 +7144,7 @@ var PerpetualsClient = (function () {
|
|
7301
7144
|
}
|
7302
7145
|
});
|
7303
7146
|
}); };
|
7304
|
-
this.addCustody = function (poolName, tokenMint, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
7147
|
+
this.addCustody = function (poolName, tokenMint, isToken222, isStable, isVirtual, oracle, pricing, permissions, fees, borrowRate, ratios, depegAdjustment) { return __awaiter(_this, void 0, void 0, function () {
|
7305
7148
|
var trx_id, error_3;
|
7306
7149
|
return __generator(this, function (_a) {
|
7307
7150
|
switch (_a.label) {
|
@@ -7310,14 +7153,15 @@ var PerpetualsClient = (function () {
|
|
7310
7153
|
return [4, this.program.methods
|
7311
7154
|
.addCustody({
|
7312
7155
|
isStable: isStable,
|
7156
|
+
depegAdjustment: depegAdjustment,
|
7313
7157
|
isVirtual: isVirtual,
|
7158
|
+
token22: isToken222,
|
7314
7159
|
oracle: oracle,
|
7315
7160
|
pricing: pricing,
|
7316
7161
|
permissions: permissions,
|
7317
7162
|
fees: fees,
|
7318
7163
|
borrowRate: borrowRate,
|
7319
7164
|
ratios: ratios,
|
7320
|
-
depegAdjustment: depegAdjustment
|
7321
7165
|
})
|
7322
7166
|
.accounts({
|
7323
7167
|
admin: this.admin,
|
@@ -7423,7 +7267,7 @@ var PerpetualsClient = (function () {
|
|
7423
7267
|
});
|
7424
7268
|
}); };
|
7425
7269
|
this.protocolWithdrawFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7426
|
-
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx,
|
7270
|
+
var publicKey, custodyConfig, receivingTokenAccount, instructions, additionalSigners, withdrawFeesIx, err_52;
|
7427
7271
|
return __generator(this, function (_a) {
|
7428
7272
|
switch (_a.label) {
|
7429
7273
|
case 0:
|
@@ -7455,9 +7299,9 @@ var PerpetualsClient = (function () {
|
|
7455
7299
|
instructions.push(withdrawFeesIx);
|
7456
7300
|
return [3, 5];
|
7457
7301
|
case 4:
|
7458
|
-
|
7459
|
-
console.log("perpClient setPool error:: ",
|
7460
|
-
throw
|
7302
|
+
err_52 = _a.sent();
|
7303
|
+
console.log("perpClient setPool error:: ", err_52);
|
7304
|
+
throw err_52;
|
7461
7305
|
case 5: return [2, {
|
7462
7306
|
instructions: __spreadArray([], instructions, true),
|
7463
7307
|
additionalSigners: additionalSigners
|
@@ -7466,7 +7310,7 @@ var PerpetualsClient = (function () {
|
|
7466
7310
|
});
|
7467
7311
|
}); };
|
7468
7312
|
this.moveProtocolFees = function (rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7469
|
-
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx,
|
7313
|
+
var publicKey, custodyConfig, instructions, additionalSigners, moveProtocolFeesIx, err_53;
|
7470
7314
|
return __generator(this, function (_a) {
|
7471
7315
|
switch (_a.label) {
|
7472
7316
|
case 0:
|
@@ -7499,9 +7343,9 @@ var PerpetualsClient = (function () {
|
|
7499
7343
|
instructions.push(moveProtocolFeesIx);
|
7500
7344
|
return [3, 4];
|
7501
7345
|
case 3:
|
7502
|
-
|
7503
|
-
console.log("perpClient setPool error:: ",
|
7504
|
-
throw
|
7346
|
+
err_53 = _a.sent();
|
7347
|
+
console.log("perpClient setPool error:: ", err_53);
|
7348
|
+
throw err_53;
|
7505
7349
|
case 4: return [2, {
|
7506
7350
|
instructions: __spreadArray([], instructions, true),
|
7507
7351
|
additionalSigners: additionalSigners
|
@@ -7510,7 +7354,7 @@ var PerpetualsClient = (function () {
|
|
7510
7354
|
});
|
7511
7355
|
}); };
|
7512
7356
|
this.setProtocolFeeShareBps = function (feeShareBps, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7513
|
-
var publicKey, setProtocolFeeShareBpsIx,
|
7357
|
+
var publicKey, setProtocolFeeShareBpsIx, err_54;
|
7514
7358
|
return __generator(this, function (_a) {
|
7515
7359
|
switch (_a.label) {
|
7516
7360
|
case 0:
|
@@ -7530,15 +7374,15 @@ var PerpetualsClient = (function () {
|
|
7530
7374
|
setProtocolFeeShareBpsIx = _a.sent();
|
7531
7375
|
return [2, setProtocolFeeShareBpsIx];
|
7532
7376
|
case 2:
|
7533
|
-
|
7534
|
-
console.log("perpClient setProtocolFeeShareBpsIx error:: ",
|
7535
|
-
throw
|
7377
|
+
err_54 = _a.sent();
|
7378
|
+
console.log("perpClient setProtocolFeeShareBpsIx error:: ", err_54);
|
7379
|
+
throw err_54;
|
7536
7380
|
case 3: return [2];
|
7537
7381
|
}
|
7538
7382
|
});
|
7539
7383
|
}); };
|
7540
7384
|
this.setPermissions = function (permissions) { return __awaiter(_this, void 0, void 0, function () {
|
7541
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction,
|
7385
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setPermissionsInstruction, err_55;
|
7542
7386
|
return __generator(this, function (_a) {
|
7543
7387
|
switch (_a.label) {
|
7544
7388
|
case 0:
|
@@ -7565,9 +7409,9 @@ var PerpetualsClient = (function () {
|
|
7565
7409
|
instructions.push(setPermissionsInstruction);
|
7566
7410
|
return [3, 4];
|
7567
7411
|
case 3:
|
7568
|
-
|
7569
|
-
console.log("perpClient setPool error:: ",
|
7570
|
-
throw
|
7412
|
+
err_55 = _a.sent();
|
7413
|
+
console.log("perpClient setPool error:: ", err_55);
|
7414
|
+
throw err_55;
|
7571
7415
|
case 4: return [2, {
|
7572
7416
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7573
7417
|
additionalSigners: additionalSigners
|
@@ -7576,7 +7420,7 @@ var PerpetualsClient = (function () {
|
|
7576
7420
|
});
|
7577
7421
|
}); };
|
7578
7422
|
this.reimburse = function (tokenMint, amountIn, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7579
|
-
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e,
|
7423
|
+
var custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, instructions, additionalSigners, custodyConfig, reimburse, _d, _e, err_56;
|
7580
7424
|
var _f;
|
7581
7425
|
return __generator(this, function (_g) {
|
7582
7426
|
switch (_g.label) {
|
@@ -7636,9 +7480,9 @@ var PerpetualsClient = (function () {
|
|
7636
7480
|
instructions.push(reimburse);
|
7637
7481
|
return [3, 5];
|
7638
7482
|
case 4:
|
7639
|
-
|
7640
|
-
console.log("perpClient setPool error:: ",
|
7641
|
-
throw
|
7483
|
+
err_56 = _g.sent();
|
7484
|
+
console.log("perpClient setPool error:: ", err_56);
|
7485
|
+
throw err_56;
|
7642
7486
|
case 5: return [2, {
|
7643
7487
|
instructions: __spreadArray([], instructions, true),
|
7644
7488
|
additionalSigners: additionalSigners
|
@@ -7647,7 +7491,7 @@ var PerpetualsClient = (function () {
|
|
7647
7491
|
});
|
7648
7492
|
}); };
|
7649
7493
|
this.setInternalOraclePrice = function (tokenMint, price, expo, conf, ema, publishTime, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7650
|
-
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice,
|
7494
|
+
var instructions, additionalSigners, custodyConfig, setInternalOraclePrice, err_57;
|
7651
7495
|
return __generator(this, function (_a) {
|
7652
7496
|
switch (_a.label) {
|
7653
7497
|
case 0:
|
@@ -7680,9 +7524,9 @@ var PerpetualsClient = (function () {
|
|
7680
7524
|
instructions.push(setInternalOraclePrice);
|
7681
7525
|
return [3, 4];
|
7682
7526
|
case 3:
|
7683
|
-
|
7684
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7685
|
-
throw
|
7527
|
+
err_57 = _a.sent();
|
7528
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_57);
|
7529
|
+
throw err_57;
|
7686
7530
|
case 4: return [2, {
|
7687
7531
|
instructions: __spreadArray([], instructions, true),
|
7688
7532
|
additionalSigners: additionalSigners
|
@@ -7691,7 +7535,7 @@ var PerpetualsClient = (function () {
|
|
7691
7535
|
});
|
7692
7536
|
}); };
|
7693
7537
|
this.setInternalOraclePriceBatch = function (tokenMintList, tokenInternalPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7694
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7538
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_1, _i, tokenMintList_1, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_58;
|
7695
7539
|
return __generator(this, function (_a) {
|
7696
7540
|
switch (_a.label) {
|
7697
7541
|
case 0:
|
@@ -7741,9 +7585,9 @@ var PerpetualsClient = (function () {
|
|
7741
7585
|
instructions.push(setInternalOraclePrice);
|
7742
7586
|
return [3, 4];
|
7743
7587
|
case 3:
|
7744
|
-
|
7745
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7746
|
-
throw
|
7588
|
+
err_58 = _a.sent();
|
7589
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_58);
|
7590
|
+
throw err_58;
|
7747
7591
|
case 4: return [2, {
|
7748
7592
|
instructions: __spreadArray([], instructions, true),
|
7749
7593
|
additionalSigners: additionalSigners
|
@@ -7752,7 +7596,7 @@ var PerpetualsClient = (function () {
|
|
7752
7596
|
});
|
7753
7597
|
}); };
|
7754
7598
|
this.setInternalOracleEmaPriceBatch = function (tokenMintList, tokenInternalEmaPrices, POOL_CONFIGS) { return __awaiter(_this, void 0, void 0, function () {
|
7755
|
-
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice,
|
7599
|
+
var ALL_CUSTODY_CONFIGS, accountMetas, _loop_2, _i, tokenMintList_2, tokenMint, instructions, additionalSigners, setInternalOraclePrice, err_59;
|
7756
7600
|
return __generator(this, function (_a) {
|
7757
7601
|
switch (_a.label) {
|
7758
7602
|
case 0:
|
@@ -7802,9 +7646,9 @@ var PerpetualsClient = (function () {
|
|
7802
7646
|
instructions.push(setInternalOraclePrice);
|
7803
7647
|
return [3, 4];
|
7804
7648
|
case 3:
|
7805
|
-
|
7806
|
-
console.log("perpClient setInternalOracleAccount error:: ",
|
7807
|
-
throw
|
7649
|
+
err_59 = _a.sent();
|
7650
|
+
console.log("perpClient setInternalOracleAccount error:: ", err_59);
|
7651
|
+
throw err_59;
|
7808
7652
|
case 4: return [2, {
|
7809
7653
|
instructions: __spreadArray([], instructions, true),
|
7810
7654
|
additionalSigners: additionalSigners
|
@@ -7813,7 +7657,7 @@ var PerpetualsClient = (function () {
|
|
7813
7657
|
});
|
7814
7658
|
}); };
|
7815
7659
|
this.renameFlp = function (flag, lpTokenName, lpTokenSymbol, lpTokenUri, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7816
|
-
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp,
|
7660
|
+
var publicKey, instructions, additionalSigners, lpTokenMint, lpMetadataAccount, renameFlp, err_60;
|
7817
7661
|
return __generator(this, function (_a) {
|
7818
7662
|
switch (_a.label) {
|
7819
7663
|
case 0:
|
@@ -7851,8 +7695,8 @@ var PerpetualsClient = (function () {
|
|
7851
7695
|
instructions.push(renameFlp);
|
7852
7696
|
return [3, 4];
|
7853
7697
|
case 3:
|
7854
|
-
|
7855
|
-
console.log("perpClient renameFlp error:: ",
|
7698
|
+
err_60 = _a.sent();
|
7699
|
+
console.log("perpClient renameFlp error:: ", err_60);
|
7856
7700
|
return [3, 4];
|
7857
7701
|
case 4: return [2, {
|
7858
7702
|
instructions: __spreadArray([], instructions, true),
|
@@ -7862,7 +7706,7 @@ var PerpetualsClient = (function () {
|
|
7862
7706
|
});
|
7863
7707
|
}); };
|
7864
7708
|
this.initStake = function (stakingFeeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7865
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction,
|
7709
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, stakedLpTokenAccount, rewardCustodyConfig, initStakeInstruction, err_61;
|
7866
7710
|
return __generator(this, function (_a) {
|
7867
7711
|
switch (_a.label) {
|
7868
7712
|
case 0:
|
@@ -7900,9 +7744,9 @@ var PerpetualsClient = (function () {
|
|
7900
7744
|
instructions.push(initStakeInstruction);
|
7901
7745
|
return [3, 4];
|
7902
7746
|
case 3:
|
7903
|
-
|
7904
|
-
console.log("perpClient InitStaking error:: ",
|
7905
|
-
throw
|
7747
|
+
err_61 = _a.sent();
|
7748
|
+
console.log("perpClient InitStaking error:: ", err_61);
|
7749
|
+
throw err_61;
|
7906
7750
|
case 4: return [2, {
|
7907
7751
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7908
7752
|
additionalSigners: additionalSigners
|
@@ -7911,7 +7755,7 @@ var PerpetualsClient = (function () {
|
|
7911
7755
|
});
|
7912
7756
|
}); };
|
7913
7757
|
this.initCompounding = function (feeShareBps, metadataTitle, metadataSymbol, metadataUri, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7914
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction,
|
7758
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, compoundingTokenMint, compoundingVault, metadataAccount, initCompoundingInstruction, err_62;
|
7915
7759
|
return __generator(this, function (_a) {
|
7916
7760
|
switch (_a.label) {
|
7917
7761
|
case 0:
|
@@ -7956,9 +7800,9 @@ var PerpetualsClient = (function () {
|
|
7956
7800
|
instructions.push(initCompoundingInstruction);
|
7957
7801
|
return [3, 4];
|
7958
7802
|
case 3:
|
7959
|
-
|
7960
|
-
console.log("perpClient initCompounding error:: ",
|
7961
|
-
throw
|
7803
|
+
err_62 = _a.sent();
|
7804
|
+
console.log("perpClient initCompounding error:: ", err_62);
|
7805
|
+
throw err_62;
|
7962
7806
|
case 4: return [2, {
|
7963
7807
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7964
7808
|
additionalSigners: additionalSigners
|
@@ -7967,7 +7811,7 @@ var PerpetualsClient = (function () {
|
|
7967
7811
|
});
|
7968
7812
|
}); };
|
7969
7813
|
this.initTokenVault = function (token_permissions, tokens_to_distribute, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
7970
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction,
|
7814
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenMint, fundingTokenAccount, initTokenVaultInstruction, err_63;
|
7971
7815
|
return __generator(this, function (_a) {
|
7972
7816
|
switch (_a.label) {
|
7973
7817
|
case 0:
|
@@ -8008,9 +7852,9 @@ var PerpetualsClient = (function () {
|
|
8008
7852
|
instructions.push(initTokenVaultInstruction);
|
8009
7853
|
return [3, 4];
|
8010
7854
|
case 3:
|
8011
|
-
|
8012
|
-
console.log("perpClient InitTokenVaultInstruction error:: ",
|
8013
|
-
throw
|
7855
|
+
err_63 = _a.sent();
|
7856
|
+
console.log("perpClient InitTokenVaultInstruction error:: ", err_63);
|
7857
|
+
throw err_63;
|
8014
7858
|
case 4: return [2, {
|
8015
7859
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8016
7860
|
additionalSigners: additionalSigners
|
@@ -8019,7 +7863,7 @@ var PerpetualsClient = (function () {
|
|
8019
7863
|
});
|
8020
7864
|
}); };
|
8021
7865
|
this.setTokenVaultConfig = function (token_permissions, withdrawTimeLimit, withdrawInstantFee, stakeLevel, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8022
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction,
|
7866
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, setTokenVaultConfigInstruction, err_64;
|
8023
7867
|
return __generator(this, function (_a) {
|
8024
7868
|
switch (_a.label) {
|
8025
7869
|
case 0:
|
@@ -8050,9 +7894,9 @@ var PerpetualsClient = (function () {
|
|
8050
7894
|
instructions.push(setTokenVaultConfigInstruction);
|
8051
7895
|
return [3, 4];
|
8052
7896
|
case 3:
|
8053
|
-
|
8054
|
-
console.log("perpClient setTokenVaultConfigInstruction error:: ",
|
8055
|
-
throw
|
7897
|
+
err_64 = _a.sent();
|
7898
|
+
console.log("perpClient setTokenVaultConfigInstruction error:: ", err_64);
|
7899
|
+
throw err_64;
|
8056
7900
|
case 4: return [2, {
|
8057
7901
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8058
7902
|
additionalSigners: additionalSigners
|
@@ -8061,7 +7905,7 @@ var PerpetualsClient = (function () {
|
|
8061
7905
|
});
|
8062
7906
|
}); };
|
8063
7907
|
this.withdrawInstantFee = function (poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8064
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction,
|
7908
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, receivingTokenAccount, withdrawInstantFeeInstruction, err_65;
|
8065
7909
|
return __generator(this, function (_a) {
|
8066
7910
|
switch (_a.label) {
|
8067
7911
|
case 0:
|
@@ -8099,9 +7943,9 @@ var PerpetualsClient = (function () {
|
|
8099
7943
|
instructions.push(withdrawInstantFeeInstruction);
|
8100
7944
|
return [3, 6];
|
8101
7945
|
case 5:
|
8102
|
-
|
8103
|
-
console.log("perpClient withdrawInstantFeeInstruction error:: ",
|
8104
|
-
throw
|
7946
|
+
err_65 = _a.sent();
|
7947
|
+
console.log("perpClient withdrawInstantFeeInstruction error:: ", err_65);
|
7948
|
+
throw err_65;
|
8105
7949
|
case 6: return [2, {
|
8106
7950
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8107
7951
|
additionalSigners: additionalSigners
|
@@ -8110,7 +7954,7 @@ var PerpetualsClient = (function () {
|
|
8110
7954
|
});
|
8111
7955
|
}); };
|
8112
7956
|
this.initRevenueTokenAccount = function (feeShareBps, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8113
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction,
|
7957
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, initRevenueTokenAccountInstruction, err_66;
|
8114
7958
|
return __generator(this, function (_a) {
|
8115
7959
|
switch (_a.label) {
|
8116
7960
|
case 0:
|
@@ -8147,9 +7991,9 @@ var PerpetualsClient = (function () {
|
|
8147
7991
|
instructions.push(initRevenueTokenAccountInstruction);
|
8148
7992
|
return [3, 4];
|
8149
7993
|
case 3:
|
8150
|
-
|
8151
|
-
console.log("perpClient initRevenueTokenAccountInstruction error:: ",
|
8152
|
-
throw
|
7994
|
+
err_66 = _a.sent();
|
7995
|
+
console.log("perpClient initRevenueTokenAccountInstruction error:: ", err_66);
|
7996
|
+
throw err_66;
|
8153
7997
|
case 4: return [2, {
|
8154
7998
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8155
7999
|
additionalSigners: additionalSigners
|
@@ -8158,7 +8002,7 @@ var PerpetualsClient = (function () {
|
|
8158
8002
|
});
|
8159
8003
|
}); };
|
8160
8004
|
this.distributeTokenReward = function (amount, epochCount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8161
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction,
|
8005
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, fundingTokenAccount, revenueFundingTokenAccount, distributeTokenRewardInstruction, err_67;
|
8162
8006
|
return __generator(this, function (_a) {
|
8163
8007
|
switch (_a.label) {
|
8164
8008
|
case 0:
|
@@ -8196,9 +8040,9 @@ var PerpetualsClient = (function () {
|
|
8196
8040
|
instructions.push(distributeTokenRewardInstruction);
|
8197
8041
|
return [3, 4];
|
8198
8042
|
case 3:
|
8199
|
-
|
8200
|
-
console.log("perpClient distributeTokenRewardInstruction error:: ",
|
8201
|
-
throw
|
8043
|
+
err_67 = _a.sent();
|
8044
|
+
console.log("perpClient distributeTokenRewardInstruction error:: ", err_67);
|
8045
|
+
throw err_67;
|
8202
8046
|
case 4: return [2, {
|
8203
8047
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8204
8048
|
additionalSigners: additionalSigners
|
@@ -8207,7 +8051,7 @@ var PerpetualsClient = (function () {
|
|
8207
8051
|
});
|
8208
8052
|
}); };
|
8209
8053
|
this.setTokenStakeLevel = function (owner, stakeLevel) { return __awaiter(_this, void 0, void 0, function () {
|
8210
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction,
|
8054
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenStakeLevelInstruction, err_68;
|
8211
8055
|
return __generator(this, function (_a) {
|
8212
8056
|
switch (_a.label) {
|
8213
8057
|
case 0:
|
@@ -8235,9 +8079,9 @@ var PerpetualsClient = (function () {
|
|
8235
8079
|
instructions.push(setTokenStakeLevelInstruction);
|
8236
8080
|
return [3, 4];
|
8237
8081
|
case 3:
|
8238
|
-
|
8239
|
-
console.log("perpClient setTokenStakeLevelInstruction error:: ",
|
8240
|
-
throw
|
8082
|
+
err_68 = _a.sent();
|
8083
|
+
console.log("perpClient setTokenStakeLevelInstruction error:: ", err_68);
|
8084
|
+
throw err_68;
|
8241
8085
|
case 4: return [2, {
|
8242
8086
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8243
8087
|
additionalSigners: additionalSigners
|
@@ -8246,7 +8090,7 @@ var PerpetualsClient = (function () {
|
|
8246
8090
|
});
|
8247
8091
|
}); };
|
8248
8092
|
this.setTokenReward = function (owner, amount, epochCount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
8249
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction,
|
8093
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, setTokenRewardInstruction, err_69;
|
8250
8094
|
return __generator(this, function (_a) {
|
8251
8095
|
switch (_a.label) {
|
8252
8096
|
case 0:
|
@@ -8278,9 +8122,9 @@ var PerpetualsClient = (function () {
|
|
8278
8122
|
instructions.push(setTokenRewardInstruction);
|
8279
8123
|
return [3, 4];
|
8280
8124
|
case 3:
|
8281
|
-
|
8282
|
-
console.log("perpClient setTokenRewardInstruction error:: ",
|
8283
|
-
throw
|
8125
|
+
err_69 = _a.sent();
|
8126
|
+
console.log("perpClient setTokenRewardInstruction error:: ", err_69);
|
8127
|
+
throw err_69;
|
8284
8128
|
case 4: return [2, {
|
8285
8129
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
8286
8130
|
additionalSigners: additionalSigners
|
@@ -8389,9 +8233,9 @@ var PerpetualsClient = (function () {
|
|
8389
8233
|
}
|
8390
8234
|
}
|
8391
8235
|
};
|
8392
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8393
|
-
|
8394
|
-
|
8236
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs, opts) {
|
8237
|
+
if (opts === void 0) { opts = {}; }
|
8238
|
+
return __awaiter(this, void 0, void 0, function () {
|
8395
8239
|
return __generator(this, function (_a) {
|
8396
8240
|
switch (_a.label) {
|
8397
8241
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8400,9 +8244,9 @@ var PerpetualsClient = (function () {
|
|
8400
8244
|
});
|
8401
8245
|
});
|
8402
8246
|
};
|
8403
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8404
|
-
|
8405
|
-
|
8247
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs, opts) {
|
8248
|
+
if (opts === void 0) { opts = {}; }
|
8249
|
+
return __awaiter(this, void 0, void 0, function () {
|
8406
8250
|
return __generator(this, function (_a) {
|
8407
8251
|
switch (_a.label) {
|
8408
8252
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|