flash-sdk 2.52.0 → 2.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PerpetualsClient.d.ts +9 -9
- package/dist/PerpetualsClient.js +1066 -914
- package/dist/ViewHelper.js +3 -3
- package/dist/backupOracle.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/alt.d.ts +0 -1
- package/dist/utils/rpc.js +50 -50
- package/package.json +1 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -1816,11 +1816,15 @@ var PerpetualsClient = (function () {
|
|
1816
1816
|
}
|
1817
1817
|
return finalIndexPriceAtT1.toString();
|
1818
1818
|
};
|
1819
|
-
this.getUserClaimableRevenueAmount = function (
|
1820
|
-
|
1821
|
-
|
1819
|
+
this.getUserClaimableRevenueAmount = function (POOL_CONFIG_1, userPublicKey_1) {
|
1820
|
+
var args_1 = [];
|
1821
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
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) {
|
1822
1825
|
var fafTokenVaultPk, fafTokenVaultAccountInfo, fafTokenVaultAccount, fafTokenVault, tokenStakeAccount, accountInfo, fafStakeData, tokenStakeFafAccount, activeStakeAmount, revenuePerFafStaked, revenueWatermark, revenueSnapshot, unclaimedRevenue, revenueAmount;
|
1823
1826
|
var _a, _b, _c, _d;
|
1827
|
+
if (enableDebuglogs === void 0) { enableDebuglogs = false; }
|
1824
1828
|
return __generator(this, function (_e) {
|
1825
1829
|
switch (_e.label) {
|
1826
1830
|
case 0:
|
@@ -1977,34 +1981,38 @@ var PerpetualsClient = (function () {
|
|
1977
1981
|
}
|
1978
1982
|
});
|
1979
1983
|
}); };
|
1980
|
-
this.getAddLiquidityAmountAndFeeView = function (
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1984
|
+
this.getAddLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
1985
|
+
var args_1 = [];
|
1986
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
1987
|
+
args_1[_i - 4] = arguments[_i];
|
1988
|
+
}
|
1989
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
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) {
|
1986
1994
|
case 0:
|
1987
1995
|
custodies = POOL_CONFIG.custodies;
|
1988
1996
|
custodyMetas = [];
|
1989
1997
|
marketMetas = [];
|
1990
|
-
for (
|
1991
|
-
token = custodies_5[
|
1998
|
+
for (_a = 0, custodies_5 = custodies; _a < custodies_5.length; _a++) {
|
1999
|
+
token = custodies_5[_a];
|
1992
2000
|
custodyMetas.push({
|
1993
2001
|
isSigner: false,
|
1994
2002
|
isWritable: false,
|
1995
2003
|
pubkey: token.custodyAccount,
|
1996
2004
|
});
|
1997
2005
|
}
|
1998
|
-
for (
|
1999
|
-
custody = custodies_6[
|
2006
|
+
for (_b = 0, custodies_6 = custodies; _b < custodies_6.length; _b++) {
|
2007
|
+
custody = custodies_6[_b];
|
2000
2008
|
custodyMetas.push({
|
2001
2009
|
isSigner: false,
|
2002
2010
|
isWritable: false,
|
2003
2011
|
pubkey: custody.intOracleAccount,
|
2004
2012
|
});
|
2005
2013
|
}
|
2006
|
-
for (
|
2007
|
-
market = _c
|
2014
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2015
|
+
market = _d[_c];
|
2008
2016
|
marketMetas.push({
|
2009
2017
|
pubkey: market.marketAccount,
|
2010
2018
|
isSigner: false,
|
@@ -2027,10 +2035,10 @@ var PerpetualsClient = (function () {
|
|
2027
2035
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2028
2036
|
.transaction()];
|
2029
2037
|
case 1:
|
2030
|
-
transaction =
|
2038
|
+
transaction = _e.sent();
|
2031
2039
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2032
2040
|
case 2:
|
2033
|
-
result =
|
2041
|
+
result = _e.sent();
|
2034
2042
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddLiquidityAmountAndFee'; });
|
2035
2043
|
res = this.viewHelper.decodeLogs(result, index, 'getAddLiquidityAmountAndFee');
|
2036
2044
|
return [2, {
|
@@ -2041,34 +2049,38 @@ var PerpetualsClient = (function () {
|
|
2041
2049
|
});
|
2042
2050
|
});
|
2043
2051
|
};
|
2044
|
-
this.getRemoveLiquidityAmountAndFeeView = function (
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2052
|
+
this.getRemoveLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2053
|
+
var args_1 = [];
|
2054
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2055
|
+
args_1[_i - 4] = arguments[_i];
|
2056
|
+
}
|
2057
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
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) {
|
2050
2062
|
case 0:
|
2051
2063
|
custodies = POOL_CONFIG.custodies;
|
2052
2064
|
custodyMetas = [];
|
2053
2065
|
marketMetas = [];
|
2054
|
-
for (
|
2055
|
-
token = custodies_7[
|
2066
|
+
for (_a = 0, custodies_7 = custodies; _a < custodies_7.length; _a++) {
|
2067
|
+
token = custodies_7[_a];
|
2056
2068
|
custodyMetas.push({
|
2057
2069
|
isSigner: false,
|
2058
2070
|
isWritable: false,
|
2059
2071
|
pubkey: token.custodyAccount,
|
2060
2072
|
});
|
2061
2073
|
}
|
2062
|
-
for (
|
2063
|
-
custody = custodies_8[
|
2074
|
+
for (_b = 0, custodies_8 = custodies; _b < custodies_8.length; _b++) {
|
2075
|
+
custody = custodies_8[_b];
|
2064
2076
|
custodyMetas.push({
|
2065
2077
|
isSigner: false,
|
2066
2078
|
isWritable: false,
|
2067
2079
|
pubkey: custody.intOracleAccount,
|
2068
2080
|
});
|
2069
2081
|
}
|
2070
|
-
for (
|
2071
|
-
market = _c
|
2082
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2083
|
+
market = _d[_c];
|
2072
2084
|
marketMetas.push({
|
2073
2085
|
pubkey: market.marketAccount,
|
2074
2086
|
isSigner: false,
|
@@ -2091,10 +2103,10 @@ var PerpetualsClient = (function () {
|
|
2091
2103
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2092
2104
|
.transaction()];
|
2093
2105
|
case 1:
|
2094
|
-
transaction =
|
2106
|
+
transaction = _e.sent();
|
2095
2107
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2096
2108
|
case 2:
|
2097
|
-
result =
|
2109
|
+
result = _e.sent();
|
2098
2110
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveLiquidityAmountAndFee'; });
|
2099
2111
|
if (result.value.err) {
|
2100
2112
|
return [2, {
|
@@ -2170,34 +2182,38 @@ var PerpetualsClient = (function () {
|
|
2170
2182
|
}
|
2171
2183
|
});
|
2172
2184
|
}); };
|
2173
|
-
this.getAddCompoundingLiquidityAmountAndFeeView = function (
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2185
|
+
this.getAddCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1) {
|
2186
|
+
var args_1 = [];
|
2187
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2188
|
+
args_1[_i - 4] = arguments[_i];
|
2189
|
+
}
|
2190
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, depositCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, depositCustodyKey, POOL_CONFIG, userPublicKey) {
|
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) {
|
2179
2195
|
case 0:
|
2180
2196
|
custodies = POOL_CONFIG.custodies;
|
2181
2197
|
custodyMetas = [];
|
2182
2198
|
marketMetas = [];
|
2183
|
-
for (
|
2184
|
-
token = custodies_11[
|
2199
|
+
for (_a = 0, custodies_11 = custodies; _a < custodies_11.length; _a++) {
|
2200
|
+
token = custodies_11[_a];
|
2185
2201
|
custodyMetas.push({
|
2186
2202
|
isSigner: false,
|
2187
2203
|
isWritable: false,
|
2188
2204
|
pubkey: token.custodyAccount,
|
2189
2205
|
});
|
2190
2206
|
}
|
2191
|
-
for (
|
2192
|
-
custody = custodies_12[
|
2207
|
+
for (_b = 0, custodies_12 = custodies; _b < custodies_12.length; _b++) {
|
2208
|
+
custody = custodies_12[_b];
|
2193
2209
|
custodyMetas.push({
|
2194
2210
|
isSigner: false,
|
2195
2211
|
isWritable: false,
|
2196
2212
|
pubkey: custody.intOracleAccount,
|
2197
2213
|
});
|
2198
2214
|
}
|
2199
|
-
for (
|
2200
|
-
market = _c
|
2215
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2216
|
+
market = _d[_c];
|
2201
2217
|
marketMetas.push({
|
2202
2218
|
pubkey: market.marketAccount,
|
2203
2219
|
isSigner: false,
|
@@ -2224,10 +2240,10 @@ var PerpetualsClient = (function () {
|
|
2224
2240
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2225
2241
|
.transaction()];
|
2226
2242
|
case 1:
|
2227
|
-
transaction =
|
2243
|
+
transaction = _e.sent();
|
2228
2244
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2229
2245
|
case 2:
|
2230
|
-
result =
|
2246
|
+
result = _e.sent();
|
2231
2247
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getAddCompoundingLiquidityAmountAndFee'; });
|
2232
2248
|
res = this.viewHelper.decodeLogs(result, index, 'getAddCompoundingLiquidityAmountAndFee');
|
2233
2249
|
return [2, {
|
@@ -2238,34 +2254,38 @@ var PerpetualsClient = (function () {
|
|
2238
2254
|
});
|
2239
2255
|
});
|
2240
2256
|
};
|
2241
|
-
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2257
|
+
this.getRemoveCompoundingLiquidityAmountAndFeeView = function (amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1) {
|
2258
|
+
var args_1 = [];
|
2259
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
2260
|
+
args_1[_i - 4] = arguments[_i];
|
2261
|
+
}
|
2262
|
+
return __awaiter(_this, __spreadArray([amount_1, poolKey_1, removeTokenCustodyKey_1, POOL_CONFIG_1], args_1, true), void 0, function (amount, poolKey, removeTokenCustodyKey, POOL_CONFIG, userPublicKey) {
|
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) {
|
2247
2267
|
case 0:
|
2248
2268
|
custodies = POOL_CONFIG.custodies;
|
2249
2269
|
custodyMetas = [];
|
2250
2270
|
marketMetas = [];
|
2251
|
-
for (
|
2252
|
-
token = custodies_13[
|
2271
|
+
for (_a = 0, custodies_13 = custodies; _a < custodies_13.length; _a++) {
|
2272
|
+
token = custodies_13[_a];
|
2253
2273
|
custodyMetas.push({
|
2254
2274
|
isSigner: false,
|
2255
2275
|
isWritable: false,
|
2256
2276
|
pubkey: token.custodyAccount,
|
2257
2277
|
});
|
2258
2278
|
}
|
2259
|
-
for (
|
2260
|
-
custody = custodies_14[
|
2279
|
+
for (_b = 0, custodies_14 = custodies; _b < custodies_14.length; _b++) {
|
2280
|
+
custody = custodies_14[_b];
|
2261
2281
|
custodyMetas.push({
|
2262
2282
|
isSigner: false,
|
2263
2283
|
isWritable: false,
|
2264
2284
|
pubkey: custody.intOracleAccount,
|
2265
2285
|
});
|
2266
2286
|
}
|
2267
|
-
for (
|
2268
|
-
market = _c
|
2287
|
+
for (_c = 0, _d = POOL_CONFIG.markets; _c < _d.length; _c++) {
|
2288
|
+
market = _d[_c];
|
2269
2289
|
marketMetas.push({
|
2270
2290
|
pubkey: market.marketAccount,
|
2271
2291
|
isSigner: false,
|
@@ -2292,10 +2312,10 @@ var PerpetualsClient = (function () {
|
|
2292
2312
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyMetas, true), marketMetas, true))
|
2293
2313
|
.transaction()];
|
2294
2314
|
case 1:
|
2295
|
-
transaction =
|
2315
|
+
transaction = _e.sent();
|
2296
2316
|
return [4, this.viewHelper.simulateTransaction(transaction, userPublicKey)];
|
2297
2317
|
case 2:
|
2298
|
-
result =
|
2318
|
+
result = _e.sent();
|
2299
2319
|
index = perpetuals_1.IDL.instructions.findIndex(function (f) { return f.name === 'getRemoveCompoundingLiquidityAmountAndFee'; });
|
2300
2320
|
if (result.value.err) {
|
2301
2321
|
return [2, {
|
@@ -2476,14 +2496,18 @@ var PerpetualsClient = (function () {
|
|
2476
2496
|
}
|
2477
2497
|
});
|
2478
2498
|
}); };
|
2479
|
-
this.openPosition = function (
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2499
|
+
this.openPosition = function (targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1) {
|
2500
|
+
var args_1 = [];
|
2501
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
2502
|
+
args_1[_i - 8] = arguments[_i];
|
2503
|
+
}
|
2504
|
+
return __awaiter(_this, __spreadArray([targetSymbol_1, collateralSymbol_1, priceWithSlippage_1, collateralWithfee_1, size_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetSymbol, collateralSymbol, priceWithSlippage, collateralWithfee, size, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2486
2505
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userCollateralTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, params, instruction;
|
2506
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
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; }
|
2487
2511
|
return __generator(this, function (_c) {
|
2488
2512
|
switch (_c.label) {
|
2489
2513
|
case 0:
|
@@ -2587,15 +2611,19 @@ var PerpetualsClient = (function () {
|
|
2587
2611
|
});
|
2588
2612
|
});
|
2589
2613
|
};
|
2590
|
-
this.closePosition = function (
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2597
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2614
|
+
this.closePosition = function (marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2615
|
+
var args_1 = [];
|
2616
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
2617
|
+
args_1[_i - 6] = arguments[_i];
|
2618
|
+
}
|
2619
|
+
return __awaiter(_this, __spreadArray([marketSymbol_1, collateralSymbol_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (marketSymbol, collateralSymbol, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
2598
2620
|
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; }
|
2599
2627
|
return __generator(this, function (_b) {
|
2600
2628
|
switch (_b.label) {
|
2601
2629
|
case 0:
|
@@ -2692,14 +2720,18 @@ var PerpetualsClient = (function () {
|
|
2692
2720
|
});
|
2693
2721
|
});
|
2694
2722
|
};
|
2695
|
-
this.swapAndOpen = function (
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
2701
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2723
|
+
this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
|
2724
|
+
var args_1 = [];
|
2725
|
+
for (var _i = 10; _i < arguments.length; _i++) {
|
2726
|
+
args_1[_i - 10] = arguments[_i];
|
2727
|
+
}
|
2728
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, collateralTokenSymbol, userInputTokenSymbol, amountIn, minCollateralAmountOut, priceWithSlippage, sizeAmount, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, skipBalanceChecks, ephemeralSignerPubkey) {
|
2702
2729
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, inx, err_3;
|
2730
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
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; }
|
2703
2735
|
return __generator(this, function (_c) {
|
2704
2736
|
switch (_c.label) {
|
2705
2737
|
case 0:
|
@@ -2839,13 +2871,17 @@ var PerpetualsClient = (function () {
|
|
2839
2871
|
});
|
2840
2872
|
});
|
2841
2873
|
};
|
2842
|
-
this.closeAndSwap = function (
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
2847
|
-
return __awaiter(_this,
|
2874
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2875
|
+
var args_1 = [];
|
2876
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
2877
|
+
args_1[_i - 8] = arguments[_i];
|
2878
|
+
}
|
2879
|
+
return __awaiter(_this, __spreadArray([targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1], args_1, true), void 0, function (targetTokenSymbol, userOutputTokenSymbol, collateralTokenSymbol, minSwapAmountOut, priceWithSlippage, side, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount, ephemeralSignerPubkey) {
|
2848
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; }
|
2849
2885
|
return __generator(this, function (_a) {
|
2850
2886
|
switch (_a.label) {
|
2851
2887
|
case 0:
|
@@ -2959,92 +2995,48 @@ var PerpetualsClient = (function () {
|
|
2959
2995
|
});
|
2960
2996
|
});
|
2961
2997
|
};
|
2962
|
-
this.
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2998
|
+
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
2999
|
+
var args_1 = [];
|
3000
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3001
|
+
args_1[_i - 6] = arguments[_i];
|
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) {
|
3004
|
+
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
|
+
return __generator(this, function (_c) {
|
3008
|
+
switch (_c.label) {
|
2972
3009
|
case 0:
|
2973
|
-
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
2974
|
-
if (!userInputCustodyConfig) {
|
2975
|
-
throw "userInputCustodyConfig not found";
|
2976
|
-
}
|
2977
|
-
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
2978
|
-
if (!userOutputCustodyConfig) {
|
2979
|
-
throw "userOutputCustodyConfig not found";
|
2980
|
-
}
|
2981
3010
|
publicKey = this.provider.wallet.publicKey;
|
3011
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3012
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3013
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3014
|
+
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3015
|
+
throw "payTokenCustody not found";
|
3016
|
+
}
|
3017
|
+
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
2982
3018
|
preInstructions = [];
|
2983
3019
|
instructions = [];
|
2984
3020
|
postInstructions = [];
|
2985
3021
|
additionalSigners = [];
|
2986
|
-
if (!(
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
return [
|
2991
|
-
case 2:
|
2992
|
-
wsolATAExist = _f.sent();
|
2993
|
-
if (!wsolATAExist) {
|
2994
|
-
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
2995
|
-
}
|
2996
|
-
if (!!skipBalanceChecks) return [3, 4];
|
3022
|
+
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
3023
|
+
console.log("collateralSymbol === SOL", collateralSymbol);
|
3024
|
+
lamports = collateralWithFee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3025
|
+
console.log("lamports:", lamports.toNumber());
|
3026
|
+
if (!!skipBalanceChecks) return [3, 2];
|
2997
3027
|
_a = anchor_1.BN.bind;
|
2998
3028
|
return [4, this.provider.connection.getBalance(publicKey)];
|
2999
|
-
case
|
3000
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3001
|
-
if (unWrappedSolBalance.lt(
|
3002
|
-
throw "Insufficient SOL Funds";
|
3003
|
-
}
|
3004
|
-
_f.label = 4;
|
3005
|
-
case 4:
|
3006
|
-
instructions.push(web3_js_1.SystemProgram.transfer({
|
3007
|
-
fromPubkey: publicKey,
|
3008
|
-
toPubkey: wsolAssociatedTokenAccount,
|
3009
|
-
lamports: amountIn.toNumber(),
|
3010
|
-
}), (0, spl_token_1.createSyncNativeInstruction)(wsolAssociatedTokenAccount));
|
3011
|
-
return [2, {
|
3012
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3013
|
-
additionalSigners: additionalSigners
|
3014
|
-
}];
|
3015
|
-
case 5:
|
3016
|
-
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
3017
|
-
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
3018
|
-
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
3019
|
-
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
|
3020
|
-
instructions.push(closeWsolATAIns);
|
3021
|
-
return [2, {
|
3022
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3023
|
-
additionalSigners: additionalSigners
|
3024
|
-
}];
|
3025
|
-
}
|
3026
|
-
_f.label = 6;
|
3027
|
-
case 6:
|
3028
|
-
_f.trys.push([6, 19, , 20]);
|
3029
|
-
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
3030
|
-
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
3031
|
-
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
3032
|
-
case 7:
|
3033
|
-
accCreationLamports = (_f.sent());
|
3034
|
-
console.log("accCreationLamports:", accCreationLamports);
|
3035
|
-
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
3036
|
-
_b = anchor_1.BN.bind;
|
3037
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3038
|
-
case 8:
|
3039
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
3040
|
-
if (unWrappedSolBalance.lt(amountIn)) {
|
3029
|
+
case 1:
|
3030
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3031
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3041
3032
|
throw "Insufficient SOL Funds";
|
3042
3033
|
}
|
3034
|
+
_c.label = 2;
|
3035
|
+
case 2:
|
3043
3036
|
if (!ephemeralSignerPubkey) {
|
3044
3037
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3045
3038
|
additionalSigners.push(wrappedSolAccount);
|
3046
3039
|
}
|
3047
|
-
;
|
3048
3040
|
preInstructions = [
|
3049
3041
|
web3_js_1.SystemProgram.createAccount({
|
3050
3042
|
fromPubkey: publicKey,
|
@@ -3058,36 +3050,102 @@ var PerpetualsClient = (function () {
|
|
3058
3050
|
postInstructions = [
|
3059
3051
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3060
3052
|
];
|
3061
|
-
return [3,
|
3062
|
-
case
|
3063
|
-
|
3064
|
-
return [4, (0, utils_1.checkIfAccountExists)(
|
3065
|
-
case
|
3066
|
-
if (!(
|
3067
|
-
throw "Insufficient Funds ,
|
3053
|
+
return [3, 6];
|
3054
|
+
case 3:
|
3055
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3056
|
+
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3057
|
+
case 4:
|
3058
|
+
if (!(_c.sent())) {
|
3059
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3068
3060
|
}
|
3069
|
-
|
3070
|
-
|
3071
|
-
|
3072
|
-
|
3073
|
-
|
3074
|
-
|
3075
|
-
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3061
|
+
_b = anchor_1.BN.bind;
|
3062
|
+
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3063
|
+
case 5:
|
3064
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3065
|
+
if (tokenAccountBalance.lt(collateralWithFee)) {
|
3066
|
+
throw "Insufficient Funds need more ".concat(collateralWithFee.sub(tokenAccountBalance), " tokens");
|
3076
3067
|
}
|
3077
|
-
|
3078
|
-
case
|
3079
|
-
|
3080
|
-
|
3068
|
+
_c.label = 6;
|
3069
|
+
case 6: return [4, this.program.methods.addCollateral({
|
3070
|
+
collateralDelta: collateralWithFee
|
3071
|
+
}).accounts({
|
3072
|
+
owner: publicKey,
|
3073
|
+
position: positionPubKey,
|
3074
|
+
market: marketAccount,
|
3075
|
+
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3076
|
+
perpetuals: poolConfig.perpetuals,
|
3077
|
+
pool: poolConfig.poolAddress,
|
3078
|
+
targetCustody: targetCustodyConfig.custodyAccount,
|
3079
|
+
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3080
|
+
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3081
|
+
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3082
|
+
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3083
|
+
eventAuthority: this.eventAuthority.publicKey,
|
3084
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3085
|
+
program: this.programId,
|
3086
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3087
|
+
})
|
3088
|
+
.instruction()];
|
3089
|
+
case 7:
|
3090
|
+
instruction = _c.sent();
|
3091
|
+
instructions.push(instruction);
|
3092
|
+
return [2, {
|
3093
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3094
|
+
additionalSigners: additionalSigners
|
3095
|
+
}];
|
3096
|
+
}
|
3097
|
+
});
|
3098
|
+
});
|
3099
|
+
};
|
3100
|
+
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3101
|
+
var args_1 = [];
|
3102
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3103
|
+
args_1[_i - 8] = arguments[_i];
|
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) {
|
3106
|
+
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
|
+
return __generator(this, function (_c) {
|
3110
|
+
switch (_c.label) {
|
3111
|
+
case 0:
|
3112
|
+
publicKey = this.provider.wallet.publicKey;
|
3113
|
+
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3114
|
+
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3115
|
+
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3116
|
+
if (!collateralCustodyConfig || !targetCustodyConfig || !inputCustodyConfig) {
|
3117
|
+
throw "payTokenCustody not found";
|
3118
|
+
}
|
3119
|
+
if (inputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3120
|
+
throw "Use Simple Swap";
|
3121
|
+
}
|
3122
|
+
preInstructions = [];
|
3123
|
+
instructions = [];
|
3124
|
+
postInstructions = [];
|
3125
|
+
additionalSigners = [];
|
3126
|
+
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3127
|
+
console.log("inputSymbol === SOL", inputSymbol);
|
3128
|
+
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3129
|
+
console.log("lamports:", lamports.toNumber());
|
3130
|
+
if (!!skipBalanceChecks) return [3, 2];
|
3131
|
+
_a = anchor_1.BN.bind;
|
3132
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
3133
|
+
case 1:
|
3134
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3135
|
+
if (unWrappedSolBalance.lt(lamports)) {
|
3136
|
+
throw "Insufficient SOL Funds";
|
3137
|
+
}
|
3138
|
+
_c.label = 2;
|
3139
|
+
case 2:
|
3081
3140
|
if (!ephemeralSignerPubkey) {
|
3082
3141
|
wrappedSolAccount = new web3_js_1.Keypair();
|
3083
3142
|
additionalSigners.push(wrappedSolAccount);
|
3084
3143
|
}
|
3085
|
-
;
|
3086
3144
|
preInstructions = [
|
3087
3145
|
web3_js_1.SystemProgram.createAccount({
|
3088
3146
|
fromPubkey: publicKey,
|
3089
3147
|
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3090
|
-
lamports: lamports,
|
3148
|
+
lamports: lamports.toNumber(),
|
3091
3149
|
space: 165,
|
3092
3150
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3093
3151
|
}),
|
@@ -3096,338 +3154,38 @@ var PerpetualsClient = (function () {
|
|
3096
3154
|
postInstructions = [
|
3097
3155
|
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3098
3156
|
];
|
3099
|
-
return [3,
|
3100
|
-
case
|
3101
|
-
|
3102
|
-
|
3103
|
-
|
3104
|
-
|
3105
|
-
|
3106
|
-
|
3107
|
-
_d = !(_f.sent());
|
3108
|
-
_f.label = 16;
|
3109
|
-
case 16:
|
3110
|
-
if (_d) {
|
3111
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
3157
|
+
return [3, 6];
|
3158
|
+
case 3:
|
3159
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3160
|
+
if (!!skipBalanceChecks) return [3, 6];
|
3161
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3162
|
+
case 4:
|
3163
|
+
if (!(_c.sent())) {
|
3164
|
+
throw "Insufficient Funds , token Account doesn't exist";
|
3112
3165
|
}
|
3113
|
-
|
3114
|
-
|
3115
|
-
|
3116
|
-
|
3117
|
-
|
3118
|
-
|
3119
|
-
custodyAccountMetas.push({
|
3120
|
-
pubkey: custody.custodyAccount,
|
3121
|
-
isSigner: false,
|
3122
|
-
isWritable: false,
|
3123
|
-
});
|
3124
|
-
custodyOracleAccountMetas.push({
|
3125
|
-
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3126
|
-
isSigner: false,
|
3127
|
-
isWritable: false,
|
3128
|
-
});
|
3166
|
+
_b = anchor_1.BN.bind;
|
3167
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3168
|
+
case 5:
|
3169
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3170
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
3171
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3129
3172
|
}
|
3130
|
-
|
3131
|
-
|
3132
|
-
|
3133
|
-
|
3134
|
-
|
3135
|
-
|
3136
|
-
|
3137
|
-
|
3173
|
+
_c.label = 6;
|
3174
|
+
case 6:
|
3175
|
+
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3176
|
+
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3177
|
+
case 7:
|
3178
|
+
if (!(_c.sent())) {
|
3179
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3180
|
+
}
|
3181
|
+
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3182
|
+
return [4, this.program.methods.swapAndAddCollateral({
|
3183
|
+
amountIn: amountIn,
|
3184
|
+
minCollateralAmountOut: minCollateralAmountOut,
|
3185
|
+
}).accounts({
|
3138
3186
|
owner: publicKey,
|
3139
|
-
|
3140
|
-
|
3141
|
-
transferAuthority: poolConfig.transferAuthority,
|
3142
|
-
perpetuals: poolConfig.perpetuals,
|
3143
|
-
pool: poolConfig.poolAddress,
|
3144
|
-
receivingCustody: userInputCustodyConfig.custodyAccount,
|
3145
|
-
receivingCustodyOracleAccount: this.useExtOracleAccount ? userInputCustodyConfig.extOracleAccount : userInputCustodyConfig.intOracleAccount,
|
3146
|
-
receivingCustodyTokenAccount: userInputCustodyConfig.tokenAccount,
|
3147
|
-
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
3148
|
-
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
3149
|
-
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
3150
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3151
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3152
|
-
program: this.programId,
|
3153
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3154
|
-
})
|
3155
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3156
|
-
.instruction()];
|
3157
|
-
case 18:
|
3158
|
-
inx = _f.sent();
|
3159
|
-
instructions.push(inx);
|
3160
|
-
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
3161
|
-
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
3162
|
-
instructions.push(closeWsolATAIns);
|
3163
|
-
}
|
3164
|
-
return [3, 20];
|
3165
|
-
case 19:
|
3166
|
-
err_5 = _f.sent();
|
3167
|
-
console.error("perpClient Swap error:: ", err_5);
|
3168
|
-
throw err_5;
|
3169
|
-
case 20: return [2, {
|
3170
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3171
|
-
additionalSigners: additionalSigners
|
3172
|
-
}];
|
3173
|
-
}
|
3174
|
-
});
|
3175
|
-
});
|
3176
|
-
};
|
3177
|
-
this.swapFeeInternal = function (rewardTokenSymbol, swapTokenSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
3178
|
-
var rewardCustody, custody, publicKey, preInstructions, instructions, postInstructions, additionalSigners, custodyAccountMetas, custodyOracleAccountMetas, _i, _a, custody_1, params, inx, err_6;
|
3179
|
-
return __generator(this, function (_b) {
|
3180
|
-
switch (_b.label) {
|
3181
|
-
case 0:
|
3182
|
-
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
3183
|
-
if (!rewardCustody) {
|
3184
|
-
throw "rewardCustody not found";
|
3185
|
-
}
|
3186
|
-
custody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(swapTokenSymbol).mintKey); });
|
3187
|
-
if (!custody) {
|
3188
|
-
throw "custody not found";
|
3189
|
-
}
|
3190
|
-
publicKey = this.provider.wallet.publicKey;
|
3191
|
-
preInstructions = [];
|
3192
|
-
instructions = [];
|
3193
|
-
postInstructions = [];
|
3194
|
-
additionalSigners = [];
|
3195
|
-
_b.label = 1;
|
3196
|
-
case 1:
|
3197
|
-
_b.trys.push([1, 3, , 4]);
|
3198
|
-
custodyAccountMetas = [];
|
3199
|
-
custodyOracleAccountMetas = [];
|
3200
|
-
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
3201
|
-
custody_1 = _a[_i];
|
3202
|
-
custodyAccountMetas.push({
|
3203
|
-
pubkey: custody_1.custodyAccount,
|
3204
|
-
isSigner: false,
|
3205
|
-
isWritable: false,
|
3206
|
-
});
|
3207
|
-
custodyOracleAccountMetas.push({
|
3208
|
-
pubkey: this.useExtOracleAccount ? custody_1.extOracleAccount : custody_1.intOracleAccount,
|
3209
|
-
isSigner: false,
|
3210
|
-
isWritable: false,
|
3211
|
-
});
|
3212
|
-
}
|
3213
|
-
params = {};
|
3214
|
-
return [4, this.program.methods
|
3215
|
-
.swapFeeInternal(params)
|
3216
|
-
.accounts({
|
3217
|
-
owner: publicKey,
|
3218
|
-
perpetuals: poolConfig.perpetuals,
|
3219
|
-
pool: poolConfig.poolAddress,
|
3220
|
-
rewardCustody: rewardCustody.custodyAccount,
|
3221
|
-
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
3222
|
-
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
3223
|
-
custody: custody.custodyAccount,
|
3224
|
-
custodyOracleAccount: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
3225
|
-
custodyTokenAccount: custody.tokenAccount,
|
3226
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3227
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3228
|
-
program: this.programId,
|
3229
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3230
|
-
})
|
3231
|
-
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
3232
|
-
.instruction()];
|
3233
|
-
case 2:
|
3234
|
-
inx = _b.sent();
|
3235
|
-
instructions.push(inx);
|
3236
|
-
return [3, 4];
|
3237
|
-
case 3:
|
3238
|
-
err_6 = _b.sent();
|
3239
|
-
console.error("perpClient Swap error:: ", err_6);
|
3240
|
-
throw err_6;
|
3241
|
-
case 4: return [2, {
|
3242
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3243
|
-
additionalSigners: additionalSigners
|
3244
|
-
}];
|
3245
|
-
}
|
3246
|
-
});
|
3247
|
-
}); };
|
3248
|
-
this.addCollateral = function (collateralWithFee, targetSymbol, collateralSymbol, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3249
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3250
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3251
|
-
return __awaiter(_this, void 0, void 0, function () {
|
3252
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3253
|
-
return __generator(this, function (_c) {
|
3254
|
-
switch (_c.label) {
|
3255
|
-
case 0:
|
3256
|
-
publicKey = this.provider.wallet.publicKey;
|
3257
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3258
|
-
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3259
|
-
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3260
|
-
if (!collateralCustodyConfig || !targetCustodyConfig) {
|
3261
|
-
throw "payTokenCustody not found";
|
3262
|
-
}
|
3263
|
-
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3264
|
-
preInstructions = [];
|
3265
|
-
instructions = [];
|
3266
|
-
postInstructions = [];
|
3267
|
-
additionalSigners = [];
|
3268
|
-
if (!(collateralSymbol == 'SOL')) return [3, 3];
|
3269
|
-
console.log("collateralSymbol === SOL", collateralSymbol);
|
3270
|
-
lamports = collateralWithFee.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3271
|
-
console.log("lamports:", lamports.toNumber());
|
3272
|
-
if (!!skipBalanceChecks) return [3, 2];
|
3273
|
-
_a = anchor_1.BN.bind;
|
3274
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3275
|
-
case 1:
|
3276
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3277
|
-
if (unWrappedSolBalance.lt(lamports)) {
|
3278
|
-
throw "Insufficient SOL Funds";
|
3279
|
-
}
|
3280
|
-
_c.label = 2;
|
3281
|
-
case 2:
|
3282
|
-
if (!ephemeralSignerPubkey) {
|
3283
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3284
|
-
additionalSigners.push(wrappedSolAccount);
|
3285
|
-
}
|
3286
|
-
preInstructions = [
|
3287
|
-
web3_js_1.SystemProgram.createAccount({
|
3288
|
-
fromPubkey: publicKey,
|
3289
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3290
|
-
lamports: lamports.toNumber(),
|
3291
|
-
space: 165,
|
3292
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3293
|
-
}),
|
3294
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3295
|
-
];
|
3296
|
-
postInstructions = [
|
3297
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3298
|
-
];
|
3299
|
-
return [3, 6];
|
3300
|
-
case 3:
|
3301
|
-
if (!!skipBalanceChecks) return [3, 6];
|
3302
|
-
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3303
|
-
case 4:
|
3304
|
-
if (!(_c.sent())) {
|
3305
|
-
throw "Insufficient Funds , token Account doesn't exist";
|
3306
|
-
}
|
3307
|
-
_b = anchor_1.BN.bind;
|
3308
|
-
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3309
|
-
case 5:
|
3310
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3311
|
-
if (tokenAccountBalance.lt(collateralWithFee)) {
|
3312
|
-
throw "Insufficient Funds need more ".concat(collateralWithFee.sub(tokenAccountBalance), " tokens");
|
3313
|
-
}
|
3314
|
-
_c.label = 6;
|
3315
|
-
case 6: return [4, this.program.methods.addCollateral({
|
3316
|
-
collateralDelta: collateralWithFee
|
3317
|
-
}).accounts({
|
3318
|
-
owner: publicKey,
|
3319
|
-
position: positionPubKey,
|
3320
|
-
market: marketAccount,
|
3321
|
-
fundingAccount: collateralSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userPayingTokenAccount,
|
3322
|
-
perpetuals: poolConfig.perpetuals,
|
3323
|
-
pool: poolConfig.poolAddress,
|
3324
|
-
targetCustody: targetCustodyConfig.custodyAccount,
|
3325
|
-
targetOracleAccount: this.useExtOracleAccount ? targetCustodyConfig.extOracleAccount : targetCustodyConfig.intOracleAccount,
|
3326
|
-
collateralCustody: collateralCustodyConfig.custodyAccount,
|
3327
|
-
collateralOracleAccount: this.useExtOracleAccount ? collateralCustodyConfig.extOracleAccount : collateralCustodyConfig.intOracleAccount,
|
3328
|
-
collateralCustodyTokenAccount: collateralCustodyConfig.tokenAccount,
|
3329
|
-
eventAuthority: this.eventAuthority.publicKey,
|
3330
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
3331
|
-
program: this.programId,
|
3332
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3333
|
-
})
|
3334
|
-
.instruction()];
|
3335
|
-
case 7:
|
3336
|
-
instruction = _c.sent();
|
3337
|
-
instructions.push(instruction);
|
3338
|
-
return [2, {
|
3339
|
-
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3340
|
-
additionalSigners: additionalSigners
|
3341
|
-
}];
|
3342
|
-
}
|
3343
|
-
});
|
3344
|
-
});
|
3345
|
-
};
|
3346
|
-
this.swapAndAddCollateral = function (targetSymbol, inputSymbol, collateralSymbol, amountIn, minCollateralAmountOut, side, positionPubKey, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3347
|
-
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3348
|
-
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3349
|
-
return __awaiter(_this, void 0, void 0, function () {
|
3350
|
-
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3351
|
-
return __generator(this, function (_c) {
|
3352
|
-
switch (_c.label) {
|
3353
|
-
case 0:
|
3354
|
-
publicKey = this.provider.wallet.publicKey;
|
3355
|
-
collateralCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(collateralSymbol).mintKey); });
|
3356
|
-
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
3357
|
-
inputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(inputSymbol).mintKey); });
|
3358
|
-
if (!collateralCustodyConfig || !targetCustodyConfig || !inputCustodyConfig) {
|
3359
|
-
throw "payTokenCustody not found";
|
3360
|
-
}
|
3361
|
-
if (inputCustodyConfig.mintKey.equals(collateralCustodyConfig.mintKey)) {
|
3362
|
-
throw "Use Simple Swap";
|
3363
|
-
}
|
3364
|
-
preInstructions = [];
|
3365
|
-
instructions = [];
|
3366
|
-
postInstructions = [];
|
3367
|
-
additionalSigners = [];
|
3368
|
-
if (!(inputSymbol == 'SOL')) return [3, 3];
|
3369
|
-
console.log("inputSymbol === SOL", inputSymbol);
|
3370
|
-
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3371
|
-
console.log("lamports:", lamports.toNumber());
|
3372
|
-
if (!!skipBalanceChecks) return [3, 2];
|
3373
|
-
_a = anchor_1.BN.bind;
|
3374
|
-
return [4, this.provider.connection.getBalance(publicKey)];
|
3375
|
-
case 1:
|
3376
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _c.sent()]))();
|
3377
|
-
if (unWrappedSolBalance.lt(lamports)) {
|
3378
|
-
throw "Insufficient SOL Funds";
|
3379
|
-
}
|
3380
|
-
_c.label = 2;
|
3381
|
-
case 2:
|
3382
|
-
if (!ephemeralSignerPubkey) {
|
3383
|
-
wrappedSolAccount = new web3_js_1.Keypair();
|
3384
|
-
additionalSigners.push(wrappedSolAccount);
|
3385
|
-
}
|
3386
|
-
preInstructions = [
|
3387
|
-
web3_js_1.SystemProgram.createAccount({
|
3388
|
-
fromPubkey: publicKey,
|
3389
|
-
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
3390
|
-
lamports: lamports.toNumber(),
|
3391
|
-
space: 165,
|
3392
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
3393
|
-
}),
|
3394
|
-
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
3395
|
-
];
|
3396
|
-
postInstructions = [
|
3397
|
-
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
3398
|
-
];
|
3399
|
-
return [3, 6];
|
3400
|
-
case 3:
|
3401
|
-
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(inputCustodyConfig.mintKey, publicKey, true);
|
3402
|
-
if (!!skipBalanceChecks) return [3, 6];
|
3403
|
-
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3404
|
-
case 4:
|
3405
|
-
if (!(_c.sent())) {
|
3406
|
-
throw "Insufficient Funds , token Account doesn't exist";
|
3407
|
-
}
|
3408
|
-
_b = anchor_1.BN.bind;
|
3409
|
-
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3410
|
-
case 5:
|
3411
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_c.sent()).value.amount]))();
|
3412
|
-
if (tokenAccountBalance.lt(amountIn)) {
|
3413
|
-
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3414
|
-
}
|
3415
|
-
_c.label = 6;
|
3416
|
-
case 6:
|
3417
|
-
userCollateralTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(collateralCustodyConfig.mintKey, publicKey, true);
|
3418
|
-
return [4, (0, utils_1.checkIfAccountExists)(userCollateralTokenAccount, this.provider.connection)];
|
3419
|
-
case 7:
|
3420
|
-
if (!(_c.sent())) {
|
3421
|
-
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userCollateralTokenAccount, publicKey, collateralCustodyConfig.mintKey));
|
3422
|
-
}
|
3423
|
-
marketAccount = poolConfig.getMarketPk(targetCustodyConfig.custodyAccount, collateralCustodyConfig.custodyAccount, side);
|
3424
|
-
return [4, this.program.methods.swapAndAddCollateral({
|
3425
|
-
amountIn: amountIn,
|
3426
|
-
minCollateralAmountOut: minCollateralAmountOut,
|
3427
|
-
}).accounts({
|
3428
|
-
owner: publicKey,
|
3429
|
-
feePayer: publicKey,
|
3430
|
-
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3187
|
+
feePayer: publicKey,
|
3188
|
+
fundingAccount: inputSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
3431
3189
|
transferAuthority: poolConfig.transferAuthority,
|
3432
3190
|
perpetuals: poolConfig.perpetuals,
|
3433
3191
|
pool: poolConfig.poolAddress,
|
@@ -3458,12 +3216,16 @@ var PerpetualsClient = (function () {
|
|
3458
3216
|
});
|
3459
3217
|
});
|
3460
3218
|
};
|
3461
|
-
this.removeCollateral = function (
|
3462
|
-
|
3463
|
-
|
3464
|
-
|
3465
|
-
|
3219
|
+
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3220
|
+
var args_1 = [];
|
3221
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3222
|
+
args_1[_i - 6] = arguments[_i];
|
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) {
|
3466
3225
|
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; }
|
3467
3229
|
return __generator(this, function (_b) {
|
3468
3230
|
switch (_b.label) {
|
3469
3231
|
case 0:
|
@@ -3564,10 +3326,14 @@ var PerpetualsClient = (function () {
|
|
3564
3326
|
});
|
3565
3327
|
});
|
3566
3328
|
};
|
3567
|
-
this.removeCollateralAndSwap = function (
|
3568
|
-
|
3569
|
-
|
3329
|
+
this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
|
3330
|
+
var args_1 = [];
|
3331
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
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) {
|
3570
3335
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3336
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3571
3337
|
return __generator(this, function (_a) {
|
3572
3338
|
switch (_a.label) {
|
3573
3339
|
case 0:
|
@@ -3660,12 +3426,16 @@ var PerpetualsClient = (function () {
|
|
3660
3426
|
});
|
3661
3427
|
});
|
3662
3428
|
};
|
3663
|
-
this.increaseSize = function (
|
3664
|
-
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3429
|
+
this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3430
|
+
var args_1 = [];
|
3431
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3432
|
+
args_1[_i - 8] = arguments[_i];
|
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) {
|
3668
3435
|
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; }
|
3669
3439
|
return __generator(this, function (_a) {
|
3670
3440
|
switch (_a.label) {
|
3671
3441
|
case 0:
|
@@ -3720,12 +3490,16 @@ var PerpetualsClient = (function () {
|
|
3720
3490
|
});
|
3721
3491
|
});
|
3722
3492
|
};
|
3723
|
-
this.decreaseSize = function (
|
3724
|
-
|
3725
|
-
|
3726
|
-
|
3727
|
-
|
3493
|
+
this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3494
|
+
var args_1 = [];
|
3495
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3496
|
+
args_1[_i - 8] = arguments[_i];
|
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) {
|
3728
3499
|
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; }
|
3729
3503
|
return __generator(this, function (_a) {
|
3730
3504
|
switch (_a.label) {
|
3731
3505
|
case 0:
|
@@ -3780,13 +3554,17 @@ var PerpetualsClient = (function () {
|
|
3780
3554
|
});
|
3781
3555
|
});
|
3782
3556
|
};
|
3783
|
-
this.addLiquidity = function (
|
3784
|
-
|
3785
|
-
|
3786
|
-
|
3787
|
-
|
3788
|
-
|
3789
|
-
|
3557
|
+
this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3558
|
+
var args_1 = [];
|
3559
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3560
|
+
args_1[_i - 4] = arguments[_i];
|
3561
|
+
}
|
3562
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3563
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_5;
|
3564
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3565
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3566
|
+
return __generator(this, function (_g) {
|
3567
|
+
switch (_g.label) {
|
3790
3568
|
case 0:
|
3791
3569
|
publicKey = this.provider.wallet.publicKey;
|
3792
3570
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -3797,16 +3575,16 @@ var PerpetualsClient = (function () {
|
|
3797
3575
|
instructions = [];
|
3798
3576
|
postInstructions = [];
|
3799
3577
|
additionalSigners = [];
|
3800
|
-
|
3578
|
+
_g.label = 1;
|
3801
3579
|
case 1:
|
3802
|
-
|
3580
|
+
_g.trys.push([1, 10, , 11]);
|
3803
3581
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true);
|
3804
3582
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3805
3583
|
custodyAccountMetas = [];
|
3806
3584
|
custodyOracleAccountMetas = [];
|
3807
3585
|
markets = [];
|
3808
|
-
for (
|
3809
|
-
custody = _a
|
3586
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
3587
|
+
custody = _b[_a];
|
3810
3588
|
custodyAccountMetas.push({
|
3811
3589
|
pubkey: custody.custodyAccount,
|
3812
3590
|
isSigner: false,
|
@@ -3818,8 +3596,8 @@ var PerpetualsClient = (function () {
|
|
3818
3596
|
isWritable: false,
|
3819
3597
|
});
|
3820
3598
|
}
|
3821
|
-
for (
|
3822
|
-
market = _c
|
3599
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
3600
|
+
market = _d[_c];
|
3823
3601
|
markets.push({
|
3824
3602
|
pubkey: market.marketAccount,
|
3825
3603
|
isSigner: false,
|
@@ -3828,21 +3606,21 @@ var PerpetualsClient = (function () {
|
|
3828
3606
|
}
|
3829
3607
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3830
3608
|
case 2:
|
3831
|
-
if (!(
|
3609
|
+
if (!(_g.sent())) {
|
3832
3610
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3833
3611
|
}
|
3834
3612
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3835
3613
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3836
3614
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3837
3615
|
if (!!skipBalanceChecks) return [3, 4];
|
3838
|
-
|
3616
|
+
_e = anchor_1.BN.bind;
|
3839
3617
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3840
3618
|
case 3:
|
3841
|
-
unWrappedSolBalance = new (
|
3619
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3842
3620
|
if (unWrappedSolBalance.lt(lamports)) {
|
3843
3621
|
throw "Insufficient SOL Funds";
|
3844
3622
|
}
|
3845
|
-
|
3623
|
+
_g.label = 4;
|
3846
3624
|
case 4:
|
3847
3625
|
if (!ephemeralSignerPubkey) {
|
3848
3626
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -3866,17 +3644,17 @@ var PerpetualsClient = (function () {
|
|
3866
3644
|
if (!!skipBalanceChecks) return [3, 8];
|
3867
3645
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3868
3646
|
case 6:
|
3869
|
-
if (!(
|
3647
|
+
if (!(_g.sent())) {
|
3870
3648
|
throw "Insufficient Funds , token Account doesn't exist";
|
3871
3649
|
}
|
3872
|
-
|
3650
|
+
_f = anchor_1.BN.bind;
|
3873
3651
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3874
3652
|
case 7:
|
3875
|
-
tokenAccountBalance = new (
|
3653
|
+
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3876
3654
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
3877
3655
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
3878
3656
|
}
|
3879
|
-
|
3657
|
+
_g.label = 8;
|
3880
3658
|
case 8: return [4, this.program.methods
|
3881
3659
|
.addLiquidity({
|
3882
3660
|
amountIn: tokenAmountIn,
|
@@ -3901,13 +3679,13 @@ var PerpetualsClient = (function () {
|
|
3901
3679
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3902
3680
|
.instruction()];
|
3903
3681
|
case 9:
|
3904
|
-
instruction =
|
3682
|
+
instruction = _g.sent();
|
3905
3683
|
instructions.push(instruction);
|
3906
3684
|
return [3, 11];
|
3907
3685
|
case 10:
|
3908
|
-
|
3909
|
-
console.error("perpClient addLiquidity error:: ",
|
3910
|
-
throw
|
3686
|
+
err_5 = _g.sent();
|
3687
|
+
console.error("perpClient addLiquidity error:: ", err_5);
|
3688
|
+
throw err_5;
|
3911
3689
|
case 11: return [2, {
|
3912
3690
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
3913
3691
|
additionalSigners: additionalSigners
|
@@ -3916,14 +3694,18 @@ var PerpetualsClient = (function () {
|
|
3916
3694
|
});
|
3917
3695
|
});
|
3918
3696
|
};
|
3919
|
-
this.addLiquidityAndStake = function (
|
3920
|
-
|
3921
|
-
|
3922
|
-
|
3923
|
-
|
3924
|
-
|
3925
|
-
|
3926
|
-
|
3697
|
+
this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3698
|
+
var args_1 = [];
|
3699
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3700
|
+
args_1[_i - 4] = arguments[_i];
|
3701
|
+
}
|
3702
|
+
return __awaiter(_this, __spreadArray([inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (inputSymbol, amountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
3703
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
|
3704
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3705
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3706
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3707
|
+
return __generator(this, function (_g) {
|
3708
|
+
switch (_g.label) {
|
3927
3709
|
case 0:
|
3928
3710
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
3929
3711
|
preInstructions = [];
|
@@ -3943,14 +3725,14 @@ var PerpetualsClient = (function () {
|
|
3943
3725
|
_a = anchor_1.BN.bind;
|
3944
3726
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3945
3727
|
case 1:
|
3946
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3728
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3947
3729
|
if (unWrappedSolBalance.lt(lamports)) {
|
3948
3730
|
throw "Insufficient SOL Funds";
|
3949
3731
|
}
|
3950
|
-
|
3732
|
+
_g.label = 2;
|
3951
3733
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3952
3734
|
case 3:
|
3953
|
-
if (!(
|
3735
|
+
if (!(_g.sent())) {
|
3954
3736
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3955
3737
|
}
|
3956
3738
|
if (!ephemeralSignerPubkey) {
|
@@ -3976,23 +3758,23 @@ var PerpetualsClient = (function () {
|
|
3976
3758
|
if (!!skipBalanceChecks) return [3, 7];
|
3977
3759
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3978
3760
|
case 5:
|
3979
|
-
if (!(
|
3761
|
+
if (!(_g.sent())) {
|
3980
3762
|
throw "Insufficient Funds , token Account doesn't exist";
|
3981
3763
|
}
|
3982
3764
|
_b = anchor_1.BN.bind;
|
3983
3765
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3984
3766
|
case 6:
|
3985
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
3767
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3986
3768
|
if (tokenAccountBalance.lt(amountIn)) {
|
3987
3769
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3988
3770
|
}
|
3989
|
-
|
3771
|
+
_g.label = 7;
|
3990
3772
|
case 7:
|
3991
3773
|
custodyAccountMetas = [];
|
3992
3774
|
custodyOracleAccountMetas = [];
|
3993
3775
|
markets = [];
|
3994
|
-
for (
|
3995
|
-
custody = _c
|
3776
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
3777
|
+
custody = _d[_c];
|
3996
3778
|
custodyAccountMetas.push({
|
3997
3779
|
pubkey: custody.custodyAccount,
|
3998
3780
|
isSigner: false,
|
@@ -4004,8 +3786,8 @@ var PerpetualsClient = (function () {
|
|
4004
3786
|
isWritable: false,
|
4005
3787
|
});
|
4006
3788
|
}
|
4007
|
-
for (
|
4008
|
-
market = _e
|
3789
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
3790
|
+
market = _f[_e];
|
4009
3791
|
markets.push({
|
4010
3792
|
pubkey: market.marketAccount,
|
4011
3793
|
isSigner: false,
|
@@ -4037,7 +3819,7 @@ var PerpetualsClient = (function () {
|
|
4037
3819
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4038
3820
|
.instruction()];
|
4039
3821
|
case 8:
|
4040
|
-
instruction =
|
3822
|
+
instruction = _g.sent();
|
4041
3823
|
instructions.push(instruction);
|
4042
3824
|
return [2, {
|
4043
3825
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4047,16 +3829,20 @@ var PerpetualsClient = (function () {
|
|
4047
3829
|
});
|
4048
3830
|
});
|
4049
3831
|
};
|
4050
|
-
this.removeLiquidity = function (
|
4051
|
-
|
4052
|
-
|
4053
|
-
|
4054
|
-
|
4055
|
-
|
4056
|
-
|
4057
|
-
|
4058
|
-
|
4059
|
-
|
3832
|
+
this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
|
3833
|
+
var args_1 = [];
|
3834
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3835
|
+
args_1[_i - 4] = arguments[_i];
|
3836
|
+
}
|
3837
|
+
return __awaiter(_this, __spreadArray([recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1], args_1, true), void 0, function (recieveTokenSymbol, liquidityAmountIn, minTokenAmountOut, poolConfig, closeLpATA, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey, userPublicKey) {
|
3838
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
|
3839
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
3840
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3841
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3842
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3843
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3844
|
+
return __generator(this, function (_f) {
|
3845
|
+
switch (_f.label) {
|
4060
3846
|
case 0:
|
4061
3847
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
4062
3848
|
if (!recieveTokenCustodyConfig) {
|
@@ -4067,15 +3853,15 @@ var PerpetualsClient = (function () {
|
|
4067
3853
|
instructions = [];
|
4068
3854
|
postInstructions = [];
|
4069
3855
|
additionalSigners = [];
|
4070
|
-
|
3856
|
+
_f.label = 1;
|
4071
3857
|
case 1:
|
4072
|
-
|
3858
|
+
_f.trys.push([1, 7, , 8]);
|
4073
3859
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
4074
3860
|
custodyAccountMetas = [];
|
4075
3861
|
custodyOracleAccountMetas = [];
|
4076
3862
|
markets = [];
|
4077
|
-
for (
|
4078
|
-
custody = _a
|
3863
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
3864
|
+
custody = _b[_a];
|
4079
3865
|
custodyAccountMetas.push({
|
4080
3866
|
pubkey: custody.custodyAccount,
|
4081
3867
|
isSigner: false,
|
@@ -4087,8 +3873,8 @@ var PerpetualsClient = (function () {
|
|
4087
3873
|
isWritable: false,
|
4088
3874
|
});
|
4089
3875
|
}
|
4090
|
-
for (
|
4091
|
-
market = _c
|
3876
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
3877
|
+
market = _d[_c];
|
4092
3878
|
markets.push({
|
4093
3879
|
pubkey: market.marketAccount,
|
4094
3880
|
isSigner: false,
|
@@ -4117,17 +3903,17 @@ var PerpetualsClient = (function () {
|
|
4117
3903
|
return [3, 5];
|
4118
3904
|
case 2:
|
4119
3905
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey, publicKey, true);
|
4120
|
-
|
4121
|
-
if (!
|
3906
|
+
_e = createUserATA;
|
3907
|
+
if (!_e) return [3, 4];
|
4122
3908
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4123
3909
|
case 3:
|
4124
|
-
|
4125
|
-
|
3910
|
+
_e = !(_f.sent());
|
3911
|
+
_f.label = 4;
|
4126
3912
|
case 4:
|
4127
|
-
if (
|
3913
|
+
if (_e) {
|
4128
3914
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey));
|
4129
3915
|
}
|
4130
|
-
|
3916
|
+
_f.label = 5;
|
4131
3917
|
case 5: return [4, this.program.methods
|
4132
3918
|
.removeLiquidity({
|
4133
3919
|
lpAmountIn: liquidityAmountIn,
|
@@ -4152,7 +3938,7 @@ var PerpetualsClient = (function () {
|
|
4152
3938
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4153
3939
|
.instruction()];
|
4154
3940
|
case 6:
|
4155
|
-
removeLiquidityTx =
|
3941
|
+
removeLiquidityTx = _f.sent();
|
4156
3942
|
instructions.push(removeLiquidityTx);
|
4157
3943
|
if (closeLpATA) {
|
4158
3944
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -4164,9 +3950,9 @@ var PerpetualsClient = (function () {
|
|
4164
3950
|
}
|
4165
3951
|
return [3, 8];
|
4166
3952
|
case 7:
|
4167
|
-
|
4168
|
-
console.log("perpClient removeLiquidity error:: ",
|
4169
|
-
throw
|
3953
|
+
err_6 = _f.sent();
|
3954
|
+
console.log("perpClient removeLiquidity error:: ", err_6);
|
3955
|
+
throw err_6;
|
4170
3956
|
case 8: return [2, {
|
4171
3957
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4172
3958
|
additionalSigners: additionalSigners
|
@@ -4176,7 +3962,7 @@ var PerpetualsClient = (function () {
|
|
4176
3962
|
});
|
4177
3963
|
};
|
4178
3964
|
this.addReferral = function (tokenStakeAccount, nftReferralAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4179
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction,
|
3965
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, addReferralInstruction, err_7;
|
4180
3966
|
return __generator(this, function (_a) {
|
4181
3967
|
switch (_a.label) {
|
4182
3968
|
case 0:
|
@@ -4203,9 +3989,9 @@ var PerpetualsClient = (function () {
|
|
4203
3989
|
instructions.push(addReferralInstruction);
|
4204
3990
|
return [3, 4];
|
4205
3991
|
case 3:
|
4206
|
-
|
4207
|
-
console.log("perpClient addReferral error:: ",
|
4208
|
-
throw
|
3992
|
+
err_7 = _a.sent();
|
3993
|
+
console.log("perpClient addReferral error:: ", err_7);
|
3994
|
+
throw err_7;
|
4209
3995
|
case 4: return [2, {
|
4210
3996
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4211
3997
|
additionalSigners: additionalSigners
|
@@ -4214,7 +4000,7 @@ var PerpetualsClient = (function () {
|
|
4214
4000
|
});
|
4215
4001
|
}); };
|
4216
4002
|
this.createNftTradingAccount = function (nftMint, owner, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4217
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, createNftTradingAccountInstruction,
|
4003
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, createNftTradingAccountInstruction, err_8;
|
4218
4004
|
return __generator(this, function (_a) {
|
4219
4005
|
switch (_a.label) {
|
4220
4006
|
case 0:
|
@@ -4249,9 +4035,9 @@ var PerpetualsClient = (function () {
|
|
4249
4035
|
instructions.push(createNftTradingAccountInstruction);
|
4250
4036
|
return [3, 4];
|
4251
4037
|
case 3:
|
4252
|
-
|
4253
|
-
console.log("perpClient createNftAccount error:: ",
|
4254
|
-
throw
|
4038
|
+
err_8 = _a.sent();
|
4039
|
+
console.log("perpClient createNftAccount error:: ", err_8);
|
4040
|
+
throw err_8;
|
4255
4041
|
case 4: return [2, {
|
4256
4042
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4257
4043
|
additionalSigners: additionalSigners
|
@@ -4260,7 +4046,7 @@ var PerpetualsClient = (function () {
|
|
4260
4046
|
});
|
4261
4047
|
}); };
|
4262
4048
|
this.updateNftAccount = function (nftMint, updateReferer, updateBooster, flpStakeAccounts) { return __awaiter(_this, void 0, void 0, function () {
|
4263
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction,
|
4049
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, nftReferralAccount, nftTokenAccount, flpStakeAccountMetas, _i, flpStakeAccounts_1, flpStakeAccountPk, updateNftTradingAccountInstruction, err_9;
|
4264
4050
|
return __generator(this, function (_a) {
|
4265
4051
|
switch (_a.label) {
|
4266
4052
|
case 0:
|
@@ -4310,9 +4096,9 @@ var PerpetualsClient = (function () {
|
|
4310
4096
|
instructions.push(updateNftTradingAccountInstruction);
|
4311
4097
|
return [3, 5];
|
4312
4098
|
case 4:
|
4313
|
-
|
4314
|
-
console.log("perpClient updateNftAccount error:: ",
|
4315
|
-
throw
|
4099
|
+
err_9 = _a.sent();
|
4100
|
+
console.log("perpClient updateNftAccount error:: ", err_9);
|
4101
|
+
throw err_9;
|
4316
4102
|
case 5: return [2, {
|
4317
4103
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4318
4104
|
additionalSigners: additionalSigners
|
@@ -4321,7 +4107,7 @@ var PerpetualsClient = (function () {
|
|
4321
4107
|
});
|
4322
4108
|
}); };
|
4323
4109
|
this.levelUp = function (poolConfig, nftMint, authorizationRulesAccount) { return __awaiter(_this, void 0, void 0, function () {
|
4324
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction,
|
4110
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, nftTradingAccount, metadataAccount, levelUpInstruction, err_10;
|
4325
4111
|
return __generator(this, function (_a) {
|
4326
4112
|
switch (_a.label) {
|
4327
4113
|
case 0:
|
@@ -4360,9 +4146,9 @@ var PerpetualsClient = (function () {
|
|
4360
4146
|
instructions.push(levelUpInstruction);
|
4361
4147
|
return [3, 4];
|
4362
4148
|
case 3:
|
4363
|
-
|
4364
|
-
console.log("perpClient levelUp error:: ",
|
4365
|
-
throw
|
4149
|
+
err_10 = _a.sent();
|
4150
|
+
console.log("perpClient levelUp error:: ", err_10);
|
4151
|
+
throw err_10;
|
4366
4152
|
case 4: return [2, {
|
4367
4153
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4368
4154
|
additionalSigners: additionalSigners
|
@@ -4371,7 +4157,7 @@ var PerpetualsClient = (function () {
|
|
4371
4157
|
});
|
4372
4158
|
}); };
|
4373
4159
|
this.depositStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4374
|
-
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction,
|
4160
|
+
var preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, depositStakeInstruction, err_11;
|
4375
4161
|
return __generator(this, function (_a) {
|
4376
4162
|
switch (_a.label) {
|
4377
4163
|
case 0:
|
@@ -4412,9 +4198,9 @@ var PerpetualsClient = (function () {
|
|
4412
4198
|
instructions.push(depositStakeInstruction);
|
4413
4199
|
return [3, 5];
|
4414
4200
|
case 4:
|
4415
|
-
|
4416
|
-
console.log("perpClient depositStaking error:: ",
|
4417
|
-
throw
|
4201
|
+
err_11 = _a.sent();
|
4202
|
+
console.log("perpClient depositStaking error:: ", err_11);
|
4203
|
+
throw err_11;
|
4418
4204
|
case 5: return [2, {
|
4419
4205
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4420
4206
|
additionalSigners: additionalSigners
|
@@ -4423,7 +4209,7 @@ var PerpetualsClient = (function () {
|
|
4423
4209
|
});
|
4424
4210
|
}); };
|
4425
4211
|
this.refreshStakeWithAllFlpStakeAccounts = function (rewardSymbol, poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4426
|
-
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction,
|
4212
|
+
var rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_1, flpStakeAccountPk, refreshStakeInstruction, err_12;
|
4427
4213
|
return __generator(this, function (_c) {
|
4428
4214
|
switch (_c.label) {
|
4429
4215
|
case 0:
|
@@ -4470,29 +4256,33 @@ var PerpetualsClient = (function () {
|
|
4470
4256
|
refreshStakeInstruction = _c.sent();
|
4471
4257
|
return [2, refreshStakeInstruction];
|
4472
4258
|
case 2:
|
4473
|
-
|
4474
|
-
console.log("perpClient refreshStaking error:: ",
|
4475
|
-
throw
|
4259
|
+
err_12 = _c.sent();
|
4260
|
+
console.log("perpClient refreshStaking error:: ", err_12);
|
4261
|
+
throw err_12;
|
4476
4262
|
case 3: return [2];
|
4477
4263
|
}
|
4478
4264
|
});
|
4479
4265
|
}); };
|
4480
|
-
this.refreshStakeWithTokenStake = function (
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4485
|
-
|
4266
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
|
4267
|
+
var args_1 = [];
|
4268
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4269
|
+
args_1[_i - 3] = arguments[_i];
|
4270
|
+
}
|
4271
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
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) {
|
4486
4276
|
case 0:
|
4487
|
-
|
4277
|
+
_c.trys.push([0, 2, , 3]);
|
4488
4278
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4489
4279
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4490
4280
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4491
4281
|
pool = poolConfig.poolAddress;
|
4492
4282
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4493
4283
|
custodyAccountMetas = [];
|
4494
|
-
for (
|
4495
|
-
custody = _a
|
4284
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4285
|
+
custody = _b[_a];
|
4496
4286
|
custodyAccountMetas.push({
|
4497
4287
|
pubkey: custody.custodyAccount,
|
4498
4288
|
isSigner: false,
|
@@ -4524,21 +4314,25 @@ var PerpetualsClient = (function () {
|
|
4524
4314
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4525
4315
|
.instruction()];
|
4526
4316
|
case 1:
|
4527
|
-
refreshStakeInstruction =
|
4317
|
+
refreshStakeInstruction = _c.sent();
|
4528
4318
|
return [2, refreshStakeInstruction];
|
4529
4319
|
case 2:
|
4530
|
-
|
4531
|
-
console.log("perpClient refreshStaking error:: ",
|
4532
|
-
throw
|
4320
|
+
err_13 = _c.sent();
|
4321
|
+
console.log("perpClient refreshStaking error:: ", err_13);
|
4322
|
+
throw err_13;
|
4533
4323
|
case 3: return [2];
|
4534
4324
|
}
|
4535
4325
|
});
|
4536
4326
|
});
|
4537
4327
|
};
|
4538
|
-
this.unstakeInstant = function (
|
4539
|
-
|
4540
|
-
|
4541
|
-
|
4328
|
+
this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
|
4329
|
+
var args_1 = [];
|
4330
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4331
|
+
args_1[_i - 3] = arguments[_i];
|
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; }
|
4542
4336
|
return __generator(this, function (_b) {
|
4543
4337
|
switch (_b.label) {
|
4544
4338
|
case 0:
|
@@ -4589,9 +4383,9 @@ var PerpetualsClient = (function () {
|
|
4589
4383
|
instructions.push(unstakeInstantInstruction);
|
4590
4384
|
return [3, 6];
|
4591
4385
|
case 5:
|
4592
|
-
|
4593
|
-
console.log("perpClient unstakeInstant error:: ",
|
4594
|
-
throw
|
4386
|
+
err_14 = _b.sent();
|
4387
|
+
console.log("perpClient unstakeInstant error:: ", err_14);
|
4388
|
+
throw err_14;
|
4595
4389
|
case 6: return [2, {
|
4596
4390
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4597
4391
|
additionalSigners: additionalSigners
|
@@ -4601,7 +4395,7 @@ var PerpetualsClient = (function () {
|
|
4601
4395
|
});
|
4602
4396
|
};
|
4603
4397
|
this.setFeeShareBps = function (poolConfig, flpStakeAccountPks) { return __awaiter(_this, void 0, void 0, function () {
|
4604
|
-
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction,
|
4398
|
+
var publicKey, pool, custodyAccountMetas, _i, _a, custody, maxFlpStakeAccountPkLength, flpStakeAccountMetas, _b, flpStakeAccountPks_2, flpStakeAccountPk, refreshStakeInstruction, err_15;
|
4605
4399
|
return __generator(this, function (_c) {
|
4606
4400
|
switch (_c.label) {
|
4607
4401
|
case 0:
|
@@ -4645,15 +4439,15 @@ var PerpetualsClient = (function () {
|
|
4645
4439
|
refreshStakeInstruction = _c.sent();
|
4646
4440
|
return [2, refreshStakeInstruction];
|
4647
4441
|
case 2:
|
4648
|
-
|
4649
|
-
console.log("perpClient refreshStaking error:: ",
|
4650
|
-
throw
|
4442
|
+
err_15 = _c.sent();
|
4443
|
+
console.log("perpClient refreshStaking error:: ", err_15);
|
4444
|
+
throw err_15;
|
4651
4445
|
case 3: return [2];
|
4652
4446
|
}
|
4653
4447
|
});
|
4654
4448
|
}); };
|
4655
4449
|
this.unstakeRequest = function (unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
4656
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction,
|
4450
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, unstakeRequestInstruction, err_16;
|
4657
4451
|
return __generator(this, function (_a) {
|
4658
4452
|
switch (_a.label) {
|
4659
4453
|
case 0:
|
@@ -4687,9 +4481,9 @@ var PerpetualsClient = (function () {
|
|
4687
4481
|
instructions.push(unstakeRequestInstruction);
|
4688
4482
|
return [3, 4];
|
4689
4483
|
case 3:
|
4690
|
-
|
4691
|
-
console.log("perpClient unstakeRequest error:: ",
|
4692
|
-
throw
|
4484
|
+
err_16 = _a.sent();
|
4485
|
+
console.log("perpClient unstakeRequest error:: ", err_16);
|
4486
|
+
throw err_16;
|
4693
4487
|
case 4: return [2, {
|
4694
4488
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4695
4489
|
additionalSigners: additionalSigners
|
@@ -4697,13 +4491,17 @@ var PerpetualsClient = (function () {
|
|
4697
4491
|
}
|
4698
4492
|
});
|
4699
4493
|
}); };
|
4700
|
-
this.withdrawStake = function (
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
return __awaiter(_this,
|
4706
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction,
|
4494
|
+
this.withdrawStake = function (poolConfig_1) {
|
4495
|
+
var args_1 = [];
|
4496
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
4497
|
+
args_1[_i - 1] = arguments[_i];
|
4498
|
+
}
|
4499
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4500
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_17;
|
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; }
|
4707
4505
|
return __generator(this, function (_b) {
|
4708
4506
|
switch (_b.label) {
|
4709
4507
|
case 0:
|
@@ -4754,9 +4552,9 @@ var PerpetualsClient = (function () {
|
|
4754
4552
|
instructions.push(withdrawStakeInstruction);
|
4755
4553
|
return [3, 6];
|
4756
4554
|
case 5:
|
4757
|
-
|
4758
|
-
console.log("perpClient withdrawStake error:: ",
|
4759
|
-
throw
|
4555
|
+
err_17 = _b.sent();
|
4556
|
+
console.log("perpClient withdrawStake error:: ", err_17);
|
4557
|
+
throw err_17;
|
4760
4558
|
case 6: return [2, {
|
4761
4559
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4762
4560
|
additionalSigners: additionalSigners
|
@@ -4765,10 +4563,14 @@ var PerpetualsClient = (function () {
|
|
4765
4563
|
});
|
4766
4564
|
});
|
4767
4565
|
};
|
4768
|
-
this.collectStakeFees = function (
|
4769
|
-
|
4770
|
-
|
4771
|
-
|
4566
|
+
this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
|
4567
|
+
var args_1 = [];
|
4568
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4569
|
+
args_1[_i - 3] = arguments[_i];
|
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; }
|
4772
4574
|
return __generator(this, function (_b) {
|
4773
4575
|
switch (_b.label) {
|
4774
4576
|
case 0:
|
@@ -4827,9 +4629,9 @@ var PerpetualsClient = (function () {
|
|
4827
4629
|
instructions.push(withdrawStakeInstruction);
|
4828
4630
|
return [3, 6];
|
4829
4631
|
case 5:
|
4830
|
-
|
4831
|
-
console.log("perpClient withdrawStake error:: ",
|
4832
|
-
throw
|
4632
|
+
err_18 = _b.sent();
|
4633
|
+
console.log("perpClient withdrawStake error:: ", err_18);
|
4634
|
+
throw err_18;
|
4833
4635
|
case 6: return [2, {
|
4834
4636
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
4835
4637
|
additionalSigners: additionalSigners
|
@@ -4838,14 +4640,18 @@ var PerpetualsClient = (function () {
|
|
4838
4640
|
});
|
4839
4641
|
});
|
4840
4642
|
};
|
4841
|
-
this.addCompoundingLiquidity = function (
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4643
|
+
this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
4644
|
+
var args_1 = [];
|
4645
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
4646
|
+
args_1[_i - 5] = arguments[_i];
|
4647
|
+
}
|
4648
|
+
return __awaiter(_this, __spreadArray([amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amountIn, minCompoundingAmountOut, inTokenSymbol, rewardTokenMint, poolConfig, skipBalanceChecks, ephemeralSignerPubkey, userPublicKey) {
|
4649
|
+
var publicKey, preInstructions, instructions, additionalSigners, postInstructions, rewardCustody, inCustodyConfig, lpTokenMint, compoundingTokenMint, wrappedSolAccount, lpTokenAccount, compoundingTokenAccount, fundingAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, addCompoundingLiquidity, err_19;
|
4650
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4651
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4652
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4653
|
+
return __generator(this, function (_f) {
|
4654
|
+
switch (_f.label) {
|
4849
4655
|
case 0:
|
4850
4656
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4851
4657
|
preInstructions = [];
|
@@ -4862,8 +4668,8 @@ var PerpetualsClient = (function () {
|
|
4862
4668
|
custodyAccountMetas = [];
|
4863
4669
|
custodyOracleAccountMetas = [];
|
4864
4670
|
markets = [];
|
4865
|
-
for (
|
4866
|
-
custody = _a
|
4671
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4672
|
+
custody = _b[_a];
|
4867
4673
|
custodyAccountMetas.push({
|
4868
4674
|
pubkey: custody.custodyAccount,
|
4869
4675
|
isSigner: false,
|
@@ -4875,8 +4681,8 @@ var PerpetualsClient = (function () {
|
|
4875
4681
|
isWritable: false,
|
4876
4682
|
});
|
4877
4683
|
}
|
4878
|
-
for (
|
4879
|
-
market = _c
|
4684
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4685
|
+
market = _d[_c];
|
4880
4686
|
markets.push({
|
4881
4687
|
pubkey: market.marketAccount,
|
4882
4688
|
isSigner: false,
|
@@ -4885,26 +4691,26 @@ var PerpetualsClient = (function () {
|
|
4885
4691
|
}
|
4886
4692
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4887
4693
|
case 1:
|
4888
|
-
if (!(
|
4694
|
+
if (!(_f.sent())) {
|
4889
4695
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4890
4696
|
}
|
4891
4697
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
4892
4698
|
case 2:
|
4893
|
-
if (!(
|
4699
|
+
if (!(_f.sent())) {
|
4894
4700
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
4895
4701
|
}
|
4896
4702
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
4897
4703
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
4898
4704
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4899
4705
|
if (!!skipBalanceChecks) return [3, 4];
|
4900
|
-
|
4706
|
+
_e = anchor_1.BN.bind;
|
4901
4707
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4902
4708
|
case 3:
|
4903
|
-
unWrappedSolBalance = new (
|
4709
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4904
4710
|
if (unWrappedSolBalance.lt(lamports)) {
|
4905
4711
|
throw "Insufficient SOL Funds";
|
4906
4712
|
}
|
4907
|
-
|
4713
|
+
_f.label = 4;
|
4908
4714
|
case 4:
|
4909
4715
|
if (!ephemeralSignerPubkey) {
|
4910
4716
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4928,12 +4734,12 @@ var PerpetualsClient = (function () {
|
|
4928
4734
|
if (!!skipBalanceChecks) return [3, 7];
|
4929
4735
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
4930
4736
|
case 6:
|
4931
|
-
if (!(
|
4737
|
+
if (!(_f.sent())) {
|
4932
4738
|
throw "Insufficient Funds , token Account doesn't exist";
|
4933
4739
|
}
|
4934
|
-
|
4740
|
+
_f.label = 7;
|
4935
4741
|
case 7:
|
4936
|
-
|
4742
|
+
_f.trys.push([7, 9, , 10]);
|
4937
4743
|
return [4, this.program.methods
|
4938
4744
|
.addCompoundingLiquidity({
|
4939
4745
|
amountIn: amountIn,
|
@@ -4962,12 +4768,12 @@ var PerpetualsClient = (function () {
|
|
4962
4768
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4963
4769
|
.instruction()];
|
4964
4770
|
case 8:
|
4965
|
-
addCompoundingLiquidity =
|
4771
|
+
addCompoundingLiquidity = _f.sent();
|
4966
4772
|
instructions.push(addCompoundingLiquidity);
|
4967
4773
|
return [3, 10];
|
4968
4774
|
case 9:
|
4969
|
-
|
4970
|
-
console.log("perpClient addCompoundingLiquidity error:: ",
|
4775
|
+
err_19 = _f.sent();
|
4776
|
+
console.log("perpClient addCompoundingLiquidity error:: ", err_19);
|
4971
4777
|
return [3, 10];
|
4972
4778
|
case 10: return [2, {
|
4973
4779
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -4977,14 +4783,18 @@ var PerpetualsClient = (function () {
|
|
4977
4783
|
});
|
4978
4784
|
});
|
4979
4785
|
};
|
4980
|
-
this.removeCompoundingLiquidity = function (
|
4981
|
-
|
4982
|
-
|
4983
|
-
|
4984
|
-
|
4985
|
-
|
4986
|
-
|
4987
|
-
|
4786
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
4787
|
+
var args_1 = [];
|
4788
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
4789
|
+
args_1[_i - 5] = arguments[_i];
|
4790
|
+
}
|
4791
|
+
return __awaiter(_this, __spreadArray([compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (compoundingAmountIn, minAmountOut, outTokenSymbol, rewardTokenMint, poolConfig, createUserATA, ephemeralSignerPubkey, userPublicKey) {
|
4792
|
+
var publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, outCustodyConfig, lpTokenMint, compoundingTokenMint, lamports, _a, custodyAccountMetas, custodyOracleAccountMetas, markets, _b, _c, custody, _d, _e, market, compoundingTokenAccount, removeCompoundingLiquidity, err_20;
|
4793
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4794
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4795
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4796
|
+
return __generator(this, function (_f) {
|
4797
|
+
switch (_f.label) {
|
4988
4798
|
case 0:
|
4989
4799
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4990
4800
|
preInstructions = [];
|
@@ -5021,19 +4831,19 @@ var PerpetualsClient = (function () {
|
|
5021
4831
|
if (!_a) return [3, 3];
|
5022
4832
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
5023
4833
|
case 2:
|
5024
|
-
_a = !(
|
5025
|
-
|
4834
|
+
_a = !(_f.sent());
|
4835
|
+
_f.label = 3;
|
5026
4836
|
case 3:
|
5027
4837
|
if (_a) {
|
5028
4838
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
5029
4839
|
}
|
5030
|
-
|
4840
|
+
_f.label = 4;
|
5031
4841
|
case 4:
|
5032
4842
|
custodyAccountMetas = [];
|
5033
4843
|
custodyOracleAccountMetas = [];
|
5034
4844
|
markets = [];
|
5035
|
-
for (
|
5036
|
-
custody = _b
|
4845
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
4846
|
+
custody = _c[_b];
|
5037
4847
|
custodyAccountMetas.push({
|
5038
4848
|
pubkey: custody.custodyAccount,
|
5039
4849
|
isSigner: false,
|
@@ -5045,8 +4855,8 @@ var PerpetualsClient = (function () {
|
|
5045
4855
|
isWritable: false,
|
5046
4856
|
});
|
5047
4857
|
}
|
5048
|
-
for (
|
5049
|
-
market = _d
|
4858
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
4859
|
+
market = _e[_d];
|
5050
4860
|
markets.push({
|
5051
4861
|
pubkey: market.marketAccount,
|
5052
4862
|
isSigner: false,
|
@@ -5054,9 +4864,9 @@ var PerpetualsClient = (function () {
|
|
5054
4864
|
});
|
5055
4865
|
}
|
5056
4866
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
5057
|
-
|
4867
|
+
_f.label = 5;
|
5058
4868
|
case 5:
|
5059
|
-
|
4869
|
+
_f.trys.push([5, 7, , 8]);
|
5060
4870
|
return [4, this.program.methods
|
5061
4871
|
.removeCompoundingLiquidity({
|
5062
4872
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -5085,12 +4895,12 @@ var PerpetualsClient = (function () {
|
|
5085
4895
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5086
4896
|
.instruction()];
|
5087
4897
|
case 6:
|
5088
|
-
removeCompoundingLiquidity =
|
4898
|
+
removeCompoundingLiquidity = _f.sent();
|
5089
4899
|
instructions.push(removeCompoundingLiquidity);
|
5090
4900
|
return [3, 8];
|
5091
4901
|
case 7:
|
5092
|
-
|
5093
|
-
console.log("perpClient removeCompoundingLiquidity error:: ",
|
4902
|
+
err_20 = _f.sent();
|
4903
|
+
console.log("perpClient removeCompoundingLiquidity error:: ", err_20);
|
5094
4904
|
return [3, 8];
|
5095
4905
|
case 8: return [2, {
|
5096
4906
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5100,12 +4910,16 @@ var PerpetualsClient = (function () {
|
|
5100
4910
|
});
|
5101
4911
|
});
|
5102
4912
|
};
|
5103
|
-
this.migrateStake = function (
|
5104
|
-
|
5105
|
-
|
5106
|
-
|
5107
|
-
|
5108
|
-
|
4913
|
+
this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
|
4914
|
+
var args_1 = [];
|
4915
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4916
|
+
args_1[_i - 3] = arguments[_i];
|
4917
|
+
}
|
4918
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
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) {
|
5109
4923
|
case 0:
|
5110
4924
|
publicKey = this.provider.wallet.publicKey;
|
5111
4925
|
preInstructions = [];
|
@@ -5120,8 +4934,8 @@ var PerpetualsClient = (function () {
|
|
5120
4934
|
if (!_a) return [3, 2];
|
5121
4935
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
5122
4936
|
case 1:
|
5123
|
-
_a = !(
|
5124
|
-
|
4937
|
+
_a = !(_g.sent());
|
4938
|
+
_g.label = 2;
|
5125
4939
|
case 2:
|
5126
4940
|
if (_a) {
|
5127
4941
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -5133,8 +4947,8 @@ var PerpetualsClient = (function () {
|
|
5133
4947
|
if (!_b) return [3, 4];
|
5134
4948
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
5135
4949
|
case 3:
|
5136
|
-
_b = (
|
5137
|
-
|
4950
|
+
_b = (_g.sent());
|
4951
|
+
_g.label = 4;
|
5138
4952
|
case 4:
|
5139
4953
|
if (_b) {
|
5140
4954
|
tokenStakeAccounts.push({
|
@@ -5147,8 +4961,8 @@ var PerpetualsClient = (function () {
|
|
5147
4961
|
custodyAccountMetas = [];
|
5148
4962
|
custodyOracleAccountMetas = [];
|
5149
4963
|
markets = [];
|
5150
|
-
for (
|
5151
|
-
custody = _c
|
4964
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
4965
|
+
custody = _d[_c];
|
5152
4966
|
custodyAccountMetas.push({
|
5153
4967
|
pubkey: custody.custodyAccount,
|
5154
4968
|
isSigner: false,
|
@@ -5160,17 +4974,17 @@ var PerpetualsClient = (function () {
|
|
5160
4974
|
isWritable: false,
|
5161
4975
|
});
|
5162
4976
|
}
|
5163
|
-
for (
|
5164
|
-
market = _e
|
4977
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
4978
|
+
market = _f[_e];
|
5165
4979
|
markets.push({
|
5166
4980
|
pubkey: market.marketAccount,
|
5167
4981
|
isSigner: false,
|
5168
4982
|
isWritable: false,
|
5169
4983
|
});
|
5170
4984
|
}
|
5171
|
-
|
4985
|
+
_g.label = 5;
|
5172
4986
|
case 5:
|
5173
|
-
|
4987
|
+
_g.trys.push([5, 7, , 8]);
|
5174
4988
|
return [4, this.program.methods
|
5175
4989
|
.migrateStake({
|
5176
4990
|
amount: amount
|
@@ -5196,12 +5010,12 @@ var PerpetualsClient = (function () {
|
|
5196
5010
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
5197
5011
|
.instruction()];
|
5198
5012
|
case 6:
|
5199
|
-
migrateStake =
|
5013
|
+
migrateStake = _g.sent();
|
5200
5014
|
instructions.push(migrateStake);
|
5201
5015
|
return [3, 8];
|
5202
5016
|
case 7:
|
5203
|
-
|
5204
|
-
console.log("perpClient migrateStake error:: ",
|
5017
|
+
err_21 = _g.sent();
|
5018
|
+
console.log("perpClient migrateStake error:: ", err_21);
|
5205
5019
|
return [3, 8];
|
5206
5020
|
case 8: return [2, {
|
5207
5021
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5212,7 +5026,7 @@ var PerpetualsClient = (function () {
|
|
5212
5026
|
});
|
5213
5027
|
};
|
5214
5028
|
this.migrateFlp = function (amount, rewardTokenMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5215
|
-
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp,
|
5029
|
+
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustody, lpTokenMint, compoundingTokenMint, compoudingTokenAccount, flpStakeAccount, poolStakedLpVault, custodyAccountMetas, custodyOracleAccountMetas, markets, _i, _a, custody, _b, _c, market, migrateFlp, err_22;
|
5216
5030
|
return __generator(this, function (_d) {
|
5217
5031
|
switch (_d.label) {
|
5218
5032
|
case 0:
|
@@ -5284,8 +5098,8 @@ var PerpetualsClient = (function () {
|
|
5284
5098
|
instructions.push(migrateFlp);
|
5285
5099
|
return [3, 4];
|
5286
5100
|
case 3:
|
5287
|
-
|
5288
|
-
console.log("perpClient migrateFlp error:: ",
|
5101
|
+
err_22 = _d.sent();
|
5102
|
+
console.log("perpClient migrateFlp error:: ", err_22);
|
5289
5103
|
return [3, 4];
|
5290
5104
|
case 4: return [2, {
|
5291
5105
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -5294,12 +5108,16 @@ var PerpetualsClient = (function () {
|
|
5294
5108
|
}
|
5295
5109
|
});
|
5296
5110
|
}); };
|
5297
|
-
this.compoundingFee = function (
|
5298
|
-
|
5299
|
-
|
5300
|
-
|
5301
|
-
|
5302
|
-
|
5111
|
+
this.compoundingFee = function (poolConfig_1) {
|
5112
|
+
var args_1 = [];
|
5113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
5114
|
+
args_1[_i - 1] = arguments[_i];
|
5115
|
+
}
|
5116
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
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) {
|
5303
5121
|
case 0:
|
5304
5122
|
instructions = [];
|
5305
5123
|
additionalSigners = [];
|
@@ -5308,8 +5126,8 @@ var PerpetualsClient = (function () {
|
|
5308
5126
|
custodyAccountMetas = [];
|
5309
5127
|
custodyOracleAccountMetas = [];
|
5310
5128
|
markets = [];
|
5311
|
-
for (
|
5312
|
-
custody = _a
|
5129
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
5130
|
+
custody = _b[_a];
|
5313
5131
|
custodyAccountMetas.push({
|
5314
5132
|
pubkey: custody.custodyAccount,
|
5315
5133
|
isSigner: false,
|
@@ -5321,17 +5139,17 @@ var PerpetualsClient = (function () {
|
|
5321
5139
|
isWritable: false,
|
5322
5140
|
});
|
5323
5141
|
}
|
5324
|
-
for (
|
5325
|
-
market = _c
|
5142
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
5143
|
+
market = _d[_c];
|
5326
5144
|
markets.push({
|
5327
5145
|
pubkey: market.marketAccount,
|
5328
5146
|
isSigner: false,
|
5329
5147
|
isWritable: false,
|
5330
5148
|
});
|
5331
5149
|
}
|
5332
|
-
|
5150
|
+
_e.label = 1;
|
5333
5151
|
case 1:
|
5334
|
-
|
5152
|
+
_e.trys.push([1, 3, , 4]);
|
5335
5153
|
return [4, this.program.methods
|
5336
5154
|
.compoundFees({})
|
5337
5155
|
.accounts({
|
@@ -5350,12 +5168,12 @@ var PerpetualsClient = (function () {
|
|
5350
5168
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5351
5169
|
.instruction()];
|
5352
5170
|
case 2:
|
5353
|
-
compoundingFee =
|
5171
|
+
compoundingFee = _e.sent();
|
5354
5172
|
instructions.push(compoundingFee);
|
5355
5173
|
return [3, 4];
|
5356
5174
|
case 3:
|
5357
|
-
|
5358
|
-
console.log("perpClient compoundingFee error:: ",
|
5175
|
+
err_23 = _e.sent();
|
5176
|
+
console.log("perpClient compoundingFee error:: ", err_23);
|
5359
5177
|
return [3, 4];
|
5360
5178
|
case 4: return [2, {
|
5361
5179
|
instructions: __spreadArray([], instructions, true),
|
@@ -5366,7 +5184,7 @@ var PerpetualsClient = (function () {
|
|
5366
5184
|
});
|
5367
5185
|
};
|
5368
5186
|
this.burnAndClaim = function (owner, nftMint, poolConfig, createAta) { return __awaiter(_this, void 0, void 0, function () {
|
5369
|
-
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction,
|
5187
|
+
var preInstructions, instructions, postInstructions, additionalSigners, userTokenAccount, _a, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndClaimInstruction, err_24;
|
5370
5188
|
return __generator(this, function (_b) {
|
5371
5189
|
switch (_b.label) {
|
5372
5190
|
case 0:
|
@@ -5430,9 +5248,9 @@ var PerpetualsClient = (function () {
|
|
5430
5248
|
instructions.push(burnAndClaimInstruction);
|
5431
5249
|
return [3, 8];
|
5432
5250
|
case 7:
|
5433
|
-
|
5434
|
-
console.log("perpClient burnAndClaimInstruction error:: ",
|
5435
|
-
throw
|
5251
|
+
err_24 = _b.sent();
|
5252
|
+
console.log("perpClient burnAndClaimInstruction error:: ", err_24);
|
5253
|
+
throw err_24;
|
5436
5254
|
case 8: return [2, {
|
5437
5255
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5438
5256
|
additionalSigners: additionalSigners
|
@@ -5441,7 +5259,7 @@ var PerpetualsClient = (function () {
|
|
5441
5259
|
});
|
5442
5260
|
}); };
|
5443
5261
|
this.burnAndStake = function (owner, feePayer, nftMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5444
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction,
|
5262
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, nftTokenAccount, nftTradingAccount, metadataAccount, collectionMetadata, edition, tokenRecord, burnAndStakeInstruction, err_25;
|
5445
5263
|
return __generator(this, function (_a) {
|
5446
5264
|
switch (_a.label) {
|
5447
5265
|
case 0:
|
@@ -5492,9 +5310,9 @@ var PerpetualsClient = (function () {
|
|
5492
5310
|
instructions.push(burnAndStakeInstruction);
|
5493
5311
|
return [3, 4];
|
5494
5312
|
case 3:
|
5495
|
-
|
5496
|
-
console.log("perpClient burnAndStakeInstruction error:: ",
|
5497
|
-
throw
|
5313
|
+
err_25 = _a.sent();
|
5314
|
+
console.log("perpClient burnAndStakeInstruction error:: ", err_25);
|
5315
|
+
throw err_25;
|
5498
5316
|
case 4: return [2, {
|
5499
5317
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5500
5318
|
additionalSigners: additionalSigners
|
@@ -5503,7 +5321,7 @@ var PerpetualsClient = (function () {
|
|
5503
5321
|
});
|
5504
5322
|
}); };
|
5505
5323
|
this.depositTokenStake = function (owner, feePayer, depositAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5506
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction,
|
5324
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, depositTokenStakeInstruction, err_26;
|
5507
5325
|
return __generator(this, function (_a) {
|
5508
5326
|
switch (_a.label) {
|
5509
5327
|
case 0:
|
@@ -5544,9 +5362,9 @@ var PerpetualsClient = (function () {
|
|
5544
5362
|
instructions.push(depositTokenStakeInstruction);
|
5545
5363
|
return [3, 5];
|
5546
5364
|
case 4:
|
5547
|
-
|
5548
|
-
console.log("perpClient depositStakingInstruction error:: ",
|
5549
|
-
throw
|
5365
|
+
err_26 = _a.sent();
|
5366
|
+
console.log("perpClient depositStakingInstruction error:: ", err_26);
|
5367
|
+
throw err_26;
|
5550
5368
|
case 5: return [2, {
|
5551
5369
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5552
5370
|
additionalSigners: additionalSigners
|
@@ -5555,7 +5373,7 @@ var PerpetualsClient = (function () {
|
|
5555
5373
|
});
|
5556
5374
|
}); };
|
5557
5375
|
this.unstakeTokenRequest = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5558
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction,
|
5376
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, unstakeTokenRequestInstruction, err_27;
|
5559
5377
|
return __generator(this, function (_a) {
|
5560
5378
|
switch (_a.label) {
|
5561
5379
|
case 0:
|
@@ -5584,9 +5402,9 @@ var PerpetualsClient = (function () {
|
|
5584
5402
|
instructions.push(unstakeTokenRequestInstruction);
|
5585
5403
|
return [3, 4];
|
5586
5404
|
case 3:
|
5587
|
-
|
5588
|
-
console.log("perpClient unstakeTokenRequestInstruction error:: ",
|
5589
|
-
throw
|
5405
|
+
err_27 = _a.sent();
|
5406
|
+
console.log("perpClient unstakeTokenRequestInstruction error:: ", err_27);
|
5407
|
+
throw err_27;
|
5590
5408
|
case 4: return [2, {
|
5591
5409
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5592
5410
|
additionalSigners: additionalSigners
|
@@ -5595,7 +5413,7 @@ var PerpetualsClient = (function () {
|
|
5595
5413
|
});
|
5596
5414
|
}); };
|
5597
5415
|
this.unstakeTokenInstant = function (owner, unstakeAmount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5598
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction,
|
5416
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, unstakeTokenInstantInstruction, err_28;
|
5599
5417
|
return __generator(this, function (_a) {
|
5600
5418
|
switch (_a.label) {
|
5601
5419
|
case 0:
|
@@ -5635,9 +5453,9 @@ var PerpetualsClient = (function () {
|
|
5635
5453
|
instructions.push(unstakeTokenInstantInstruction);
|
5636
5454
|
return [3, 5];
|
5637
5455
|
case 4:
|
5638
|
-
|
5639
|
-
console.log("perpClient unstakeTokenInstantInstruction error:: ",
|
5640
|
-
throw
|
5456
|
+
err_28 = _a.sent();
|
5457
|
+
console.log("perpClient unstakeTokenInstantInstruction error:: ", err_28);
|
5458
|
+
throw err_28;
|
5641
5459
|
case 5: return [2, {
|
5642
5460
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5643
5461
|
additionalSigners: additionalSigners
|
@@ -5646,7 +5464,7 @@ var PerpetualsClient = (function () {
|
|
5646
5464
|
});
|
5647
5465
|
}); };
|
5648
5466
|
this.withdrawToken = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5649
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction,
|
5467
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, withdrawTokenInstruction, err_29;
|
5650
5468
|
return __generator(this, function (_a) {
|
5651
5469
|
switch (_a.label) {
|
5652
5470
|
case 0:
|
@@ -5686,9 +5504,9 @@ var PerpetualsClient = (function () {
|
|
5686
5504
|
instructions.push(withdrawTokenInstruction);
|
5687
5505
|
return [3, 5];
|
5688
5506
|
case 4:
|
5689
|
-
|
5690
|
-
console.log("perpClient withdrawTokenInstruction error:: ",
|
5691
|
-
throw
|
5507
|
+
err_29 = _a.sent();
|
5508
|
+
console.log("perpClient withdrawTokenInstruction error:: ", err_29);
|
5509
|
+
throw err_29;
|
5692
5510
|
case 5: return [2, {
|
5693
5511
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5694
5512
|
additionalSigners: additionalSigners
|
@@ -5697,7 +5515,7 @@ var PerpetualsClient = (function () {
|
|
5697
5515
|
});
|
5698
5516
|
}); };
|
5699
5517
|
this.cancelUnstakeRequest = function (owner, withdrawRequestId, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5700
|
-
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction,
|
5518
|
+
var preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, cancelUnstakeRequestInstruction, err_30;
|
5701
5519
|
return __generator(this, function (_a) {
|
5702
5520
|
switch (_a.label) {
|
5703
5521
|
case 0:
|
@@ -5726,9 +5544,9 @@ var PerpetualsClient = (function () {
|
|
5726
5544
|
instructions.push(cancelUnstakeRequestInstruction);
|
5727
5545
|
return [3, 4];
|
5728
5546
|
case 3:
|
5729
|
-
|
5730
|
-
console.log("perpClient cancelUnstakeRequestInstruction error:: ",
|
5731
|
-
throw
|
5547
|
+
err_30 = _a.sent();
|
5548
|
+
console.log("perpClient cancelUnstakeRequestInstruction error:: ", err_30);
|
5549
|
+
throw err_30;
|
5732
5550
|
case 4: return [2, {
|
5733
5551
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5734
5552
|
additionalSigners: additionalSigners
|
@@ -5736,10 +5554,14 @@ var PerpetualsClient = (function () {
|
|
5736
5554
|
}
|
5737
5555
|
});
|
5738
5556
|
}); };
|
5739
|
-
this.collectTokenReward = function (
|
5740
|
-
|
5741
|
-
|
5742
|
-
|
5557
|
+
this.collectTokenReward = function (owner_1, poolConfig_1) {
|
5558
|
+
var args_1 = [];
|
5559
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5560
|
+
args_1[_i - 2] = arguments[_i];
|
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; }
|
5743
5565
|
return __generator(this, function (_b) {
|
5744
5566
|
switch (_b.label) {
|
5745
5567
|
case 0:
|
@@ -5783,9 +5605,9 @@ var PerpetualsClient = (function () {
|
|
5783
5605
|
instructions.push(collectTokenRewardInstruction);
|
5784
5606
|
return [3, 6];
|
5785
5607
|
case 5:
|
5786
|
-
|
5787
|
-
console.log("perpClient collectTokenRewardInstruction error:: ",
|
5788
|
-
throw
|
5608
|
+
err_31 = _b.sent();
|
5609
|
+
console.log("perpClient collectTokenRewardInstruction error:: ", err_31);
|
5610
|
+
throw err_31;
|
5789
5611
|
case 6: return [2, {
|
5790
5612
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5791
5613
|
additionalSigners: additionalSigners
|
@@ -5794,10 +5616,14 @@ var PerpetualsClient = (function () {
|
|
5794
5616
|
});
|
5795
5617
|
});
|
5796
5618
|
};
|
5797
|
-
this.collectRevenue = function (
|
5798
|
-
|
5799
|
-
|
5800
|
-
|
5619
|
+
this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
|
5620
|
+
var args_1 = [];
|
5621
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5622
|
+
args_1[_i - 3] = arguments[_i];
|
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; }
|
5801
5627
|
return __generator(this, function (_b) {
|
5802
5628
|
switch (_b.label) {
|
5803
5629
|
case 0:
|
@@ -5842,9 +5668,9 @@ var PerpetualsClient = (function () {
|
|
5842
5668
|
instructions.push(collectRevenueInstruction);
|
5843
5669
|
return [3, 6];
|
5844
5670
|
case 5:
|
5845
|
-
|
5846
|
-
console.log("perpClient collectRevenueInstruction error:: ",
|
5847
|
-
throw
|
5671
|
+
err_32 = _b.sent();
|
5672
|
+
console.log("perpClient collectRevenueInstruction error:: ", err_32);
|
5673
|
+
throw err_32;
|
5848
5674
|
case 6: return [2, {
|
5849
5675
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
5850
5676
|
additionalSigners: additionalSigners
|
@@ -5854,7 +5680,7 @@ var PerpetualsClient = (function () {
|
|
5854
5680
|
});
|
5855
5681
|
};
|
5856
5682
|
this.initRewardVault = function (nftCount, rewardSymbol, collectionMint, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5857
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault,
|
5683
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fbNftProgramData, rewardVault, rewardTokenAccount, nftTransferAuthority, initRewardVault, err_33;
|
5858
5684
|
return __generator(this, function (_a) {
|
5859
5685
|
switch (_a.label) {
|
5860
5686
|
case 0:
|
@@ -5891,9 +5717,9 @@ var PerpetualsClient = (function () {
|
|
5891
5717
|
instructions.push(initRewardVault);
|
5892
5718
|
return [3, 4];
|
5893
5719
|
case 3:
|
5894
|
-
|
5895
|
-
console.log("perpClient InitRewardVault error:: ",
|
5896
|
-
throw
|
5720
|
+
err_33 = _a.sent();
|
5721
|
+
console.log("perpClient InitRewardVault error:: ", err_33);
|
5722
|
+
throw err_33;
|
5897
5723
|
case 4: return [2, {
|
5898
5724
|
instructions: __spreadArray([], instructions, true),
|
5899
5725
|
additionalSigners: additionalSigners
|
@@ -5902,7 +5728,7 @@ var PerpetualsClient = (function () {
|
|
5902
5728
|
});
|
5903
5729
|
}); };
|
5904
5730
|
this.distributeReward = function (rewardAmount, rewardSymbol, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
5905
|
-
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward,
|
5731
|
+
var publicKey, rewardCustodyMint, instructions, additionalSigners, fundingAccount, rewardVault, rewardTokenAccount, distributeReward, err_34;
|
5906
5732
|
return __generator(this, function (_a) {
|
5907
5733
|
switch (_a.label) {
|
5908
5734
|
case 0:
|
@@ -5933,9 +5759,9 @@ var PerpetualsClient = (function () {
|
|
5933
5759
|
instructions.push(distributeReward);
|
5934
5760
|
return [3, 4];
|
5935
5761
|
case 3:
|
5936
|
-
|
5937
|
-
console.log("perpClient distributeReward error:: ",
|
5938
|
-
throw
|
5762
|
+
err_34 = _a.sent();
|
5763
|
+
console.log("perpClient distributeReward error:: ", err_34);
|
5764
|
+
throw err_34;
|
5939
5765
|
case 4: return [2, {
|
5940
5766
|
instructions: __spreadArray([], instructions, true),
|
5941
5767
|
additionalSigners: additionalSigners
|
@@ -5943,10 +5769,14 @@ var PerpetualsClient = (function () {
|
|
5943
5769
|
}
|
5944
5770
|
});
|
5945
5771
|
}); };
|
5946
|
-
this.collectNftReward = function (
|
5947
|
-
|
5948
|
-
|
5949
|
-
|
5772
|
+
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5773
|
+
var args_1 = [];
|
5774
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5775
|
+
args_1[_i - 3] = arguments[_i];
|
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; }
|
5950
5780
|
return __generator(this, function (_b) {
|
5951
5781
|
switch (_b.label) {
|
5952
5782
|
case 0:
|
@@ -5996,8 +5826,8 @@ var PerpetualsClient = (function () {
|
|
5996
5826
|
instructions.push(collectNftReward);
|
5997
5827
|
return [3, 6];
|
5998
5828
|
case 5:
|
5999
|
-
|
6000
|
-
throw
|
5829
|
+
err_35 = _b.sent();
|
5830
|
+
throw err_35;
|
6001
5831
|
case 6: return [2, {
|
6002
5832
|
instructions: __spreadArray([], instructions, true),
|
6003
5833
|
additionalSigners: additionalSigners
|
@@ -6006,10 +5836,14 @@ var PerpetualsClient = (function () {
|
|
6006
5836
|
});
|
6007
5837
|
});
|
6008
5838
|
};
|
6009
|
-
this.collectAndDistributeFee = function (
|
6010
|
-
|
6011
|
-
|
6012
|
-
|
5839
|
+
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5840
|
+
var args_1 = [];
|
5841
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5842
|
+
args_1[_i - 2] = arguments[_i];
|
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; }
|
6013
5847
|
return __generator(this, function (_b) {
|
6014
5848
|
switch (_b.label) {
|
6015
5849
|
case 0:
|
@@ -6073,9 +5907,9 @@ var PerpetualsClient = (function () {
|
|
6073
5907
|
instructions.push(withdrawStakeInstruction);
|
6074
5908
|
return [3, 6];
|
6075
5909
|
case 5:
|
6076
|
-
|
6077
|
-
console.log("perpClient withdrawStake error:: ",
|
6078
|
-
throw
|
5910
|
+
err_36 = _b.sent();
|
5911
|
+
console.log("perpClient withdrawStake error:: ", err_36);
|
5912
|
+
throw err_36;
|
6079
5913
|
case 6: return [2, {
|
6080
5914
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6081
5915
|
additionalSigners: additionalSigners
|
@@ -6085,7 +5919,7 @@ var PerpetualsClient = (function () {
|
|
6085
5919
|
});
|
6086
5920
|
};
|
6087
5921
|
this.setTriggerPrice = function (targetSymbol, collateralSymbol, side, triggerPrice, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6088
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice,
|
5922
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, positionAccount, instructions, additionalSigners, setTriggerPrice, err_37;
|
6089
5923
|
return __generator(this, function (_a) {
|
6090
5924
|
switch (_a.label) {
|
6091
5925
|
case 0:
|
@@ -6124,9 +5958,9 @@ var PerpetualsClient = (function () {
|
|
6124
5958
|
instructions.push(setTriggerPrice);
|
6125
5959
|
return [3, 4];
|
6126
5960
|
case 3:
|
6127
|
-
|
6128
|
-
console.log("perpClient setTriggerPrice error:: ",
|
6129
|
-
throw
|
5961
|
+
err_37 = _a.sent();
|
5962
|
+
console.log("perpClient setTriggerPrice error:: ", err_37);
|
5963
|
+
throw err_37;
|
6130
5964
|
case 4: return [2, {
|
6131
5965
|
instructions: __spreadArray([], instructions, true),
|
6132
5966
|
additionalSigners: additionalSigners
|
@@ -6134,12 +5968,16 @@ var PerpetualsClient = (function () {
|
|
6134
5968
|
}
|
6135
5969
|
});
|
6136
5970
|
}); };
|
6137
|
-
this.forceClosePosition = function (
|
6138
|
-
|
6139
|
-
|
6140
|
-
|
6141
|
-
|
6142
|
-
|
5971
|
+
this.forceClosePosition = function (positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
|
5972
|
+
var args_1 = [];
|
5973
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
5974
|
+
args_1[_i - 6] = arguments[_i];
|
5975
|
+
}
|
5976
|
+
return __awaiter(_this, __spreadArray([positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1], args_1, true), void 0, function (positionAccount, targetSymbol, collateralSymbol, side, isStopLoss, poolConfig, createUserATA, closeUsersWSOLATA, ephemeralSignerPubkey) {
|
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; }
|
6143
5981
|
return __generator(this, function (_b) {
|
6144
5982
|
switch (_b.label) {
|
6145
5983
|
case 0:
|
@@ -6200,9 +6038,9 @@ var PerpetualsClient = (function () {
|
|
6200
6038
|
}
|
6201
6039
|
return [3, 7];
|
6202
6040
|
case 6:
|
6203
|
-
|
6204
|
-
console.log("perpClient forceClosePosition error:: ",
|
6205
|
-
throw
|
6041
|
+
err_38 = _b.sent();
|
6042
|
+
console.log("perpClient forceClosePosition error:: ", err_38);
|
6043
|
+
throw err_38;
|
6206
6044
|
case 7: return [2, {
|
6207
6045
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6208
6046
|
additionalSigners: additionalSigners
|
@@ -6211,11 +6049,15 @@ var PerpetualsClient = (function () {
|
|
6211
6049
|
});
|
6212
6050
|
});
|
6213
6051
|
};
|
6214
|
-
this.placeLimitOrder = function (
|
6215
|
-
|
6216
|
-
|
6217
|
-
|
6218
|
-
|
6052
|
+
this.placeLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, limitPrice_1, reserveAmount_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6053
|
+
var args_1 = [];
|
6054
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6055
|
+
args_1[_i - 11] = arguments[_i];
|
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; }
|
6219
6061
|
return __generator(this, function (_c) {
|
6220
6062
|
switch (_c.label) {
|
6221
6063
|
case 0:
|
@@ -6320,9 +6162,9 @@ var PerpetualsClient = (function () {
|
|
6320
6162
|
instructions.push(placeLimitOrder);
|
6321
6163
|
return [3, 11];
|
6322
6164
|
case 10:
|
6323
|
-
|
6324
|
-
console.log("perpClient placeLimitOrder error:: ",
|
6325
|
-
throw
|
6165
|
+
err_39 = _c.sent();
|
6166
|
+
console.log("perpClient placeLimitOrder error:: ", err_39);
|
6167
|
+
throw err_39;
|
6326
6168
|
case 11: return [2, {
|
6327
6169
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6328
6170
|
additionalSigners: additionalSigners
|
@@ -6331,11 +6173,15 @@ var PerpetualsClient = (function () {
|
|
6331
6173
|
});
|
6332
6174
|
});
|
6333
6175
|
};
|
6334
|
-
this.editLimitOrder = function (
|
6335
|
-
|
6336
|
-
|
6337
|
-
|
6338
|
-
|
6176
|
+
this.editLimitOrder = function (targetSymbol_1, collateralSymbol_1, reserveSymbol_1, receiveSymbol_1, side_1, orderId_1, limitPrice_1, sizeAmount_1, stopLossPrice_1, takeProfitPrice_1, poolConfig_1) {
|
6177
|
+
var args_1 = [];
|
6178
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6179
|
+
args_1[_i - 11] = arguments[_i];
|
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; }
|
6339
6185
|
return __generator(this, function (_b) {
|
6340
6186
|
switch (_b.label) {
|
6341
6187
|
case 0:
|
@@ -6423,9 +6269,9 @@ var PerpetualsClient = (function () {
|
|
6423
6269
|
instructions.push(editLimitOrder);
|
6424
6270
|
return [3, 8];
|
6425
6271
|
case 7:
|
6426
|
-
|
6427
|
-
console.log("perpClient editLimitOrder error:: ",
|
6428
|
-
throw
|
6272
|
+
err_40 = _b.sent();
|
6273
|
+
console.log("perpClient editLimitOrder error:: ", err_40);
|
6274
|
+
throw err_40;
|
6429
6275
|
case 8: return [2, {
|
6430
6276
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6431
6277
|
additionalSigners: additionalSigners
|
@@ -6434,12 +6280,16 @@ var PerpetualsClient = (function () {
|
|
6434
6280
|
});
|
6435
6281
|
});
|
6436
6282
|
};
|
6437
|
-
this.executeLimitOrder = function (
|
6438
|
-
|
6439
|
-
|
6440
|
-
|
6441
|
-
|
6442
|
-
|
6283
|
+
this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6284
|
+
var args_1 = [];
|
6285
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
6286
|
+
args_1[_i - 7] = arguments[_i];
|
6287
|
+
}
|
6288
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
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; }
|
6443
6293
|
return __generator(this, function (_a) {
|
6444
6294
|
switch (_a.label) {
|
6445
6295
|
case 0:
|
@@ -6488,9 +6338,9 @@ var PerpetualsClient = (function () {
|
|
6488
6338
|
instructions.push(executeLimitOrder);
|
6489
6339
|
return [3, 4];
|
6490
6340
|
case 3:
|
6491
|
-
|
6492
|
-
console.log("perpClient executeLimitOrder error:: ",
|
6493
|
-
throw
|
6341
|
+
err_41 = _a.sent();
|
6342
|
+
console.log("perpClient executeLimitOrder error:: ", err_41);
|
6343
|
+
throw err_41;
|
6494
6344
|
case 4: return [2, {
|
6495
6345
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6496
6346
|
additionalSigners: additionalSigners
|
@@ -6499,12 +6349,16 @@ var PerpetualsClient = (function () {
|
|
6499
6349
|
});
|
6500
6350
|
});
|
6501
6351
|
};
|
6502
|
-
this.executeLimitWithSwap = function (
|
6503
|
-
|
6504
|
-
|
6505
|
-
|
6506
|
-
|
6507
|
-
|
6352
|
+
this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6353
|
+
var args_1 = [];
|
6354
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6355
|
+
args_1[_i - 8] = arguments[_i];
|
6356
|
+
}
|
6357
|
+
return __awaiter(_this, __spreadArray([userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1], args_1, true), void 0, function (userPubkey, targetSymbol, collateralSymbol, reserveSymbol, side, orderId, poolConfig, privilege, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
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; }
|
6508
6362
|
return __generator(this, function (_a) {
|
6509
6363
|
switch (_a.label) {
|
6510
6364
|
case 0:
|
@@ -6556,9 +6410,9 @@ var PerpetualsClient = (function () {
|
|
6556
6410
|
instructions.push(executeLimitWithSwap);
|
6557
6411
|
return [3, 4];
|
6558
6412
|
case 3:
|
6559
|
-
|
6560
|
-
console.log("perpClient executeLimitWithSwap error:: ",
|
6561
|
-
throw
|
6413
|
+
err_42 = _a.sent();
|
6414
|
+
console.log("perpClient executeLimitWithSwap error:: ", err_42);
|
6415
|
+
throw err_42;
|
6562
6416
|
case 4: return [2, {
|
6563
6417
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6564
6418
|
additionalSigners: additionalSigners
|
@@ -6568,7 +6422,7 @@ var PerpetualsClient = (function () {
|
|
6568
6422
|
});
|
6569
6423
|
};
|
6570
6424
|
this.placeTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6571
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder,
|
6425
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, placeTriggerOrder, err_43;
|
6572
6426
|
return __generator(this, function (_a) {
|
6573
6427
|
switch (_a.label) {
|
6574
6428
|
case 0:
|
@@ -6616,9 +6470,9 @@ var PerpetualsClient = (function () {
|
|
6616
6470
|
instructions.push(placeTriggerOrder);
|
6617
6471
|
return [3, 4];
|
6618
6472
|
case 3:
|
6619
|
-
|
6620
|
-
console.log("perpClient placeTriggerOrder error:: ",
|
6621
|
-
throw
|
6473
|
+
err_43 = _a.sent();
|
6474
|
+
console.log("perpClient placeTriggerOrder error:: ", err_43);
|
6475
|
+
throw err_43;
|
6622
6476
|
case 4: return [2, {
|
6623
6477
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6624
6478
|
additionalSigners: additionalSigners
|
@@ -6627,7 +6481,7 @@ var PerpetualsClient = (function () {
|
|
6627
6481
|
});
|
6628
6482
|
}); };
|
6629
6483
|
this.editTriggerOrder = function (targetSymbol, collateralSymbol, receiveSymbol, side, orderId, triggerPrice, deltaSizeAmount, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6630
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder,
|
6484
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, editTriggerOrder, err_44;
|
6631
6485
|
return __generator(this, function (_a) {
|
6632
6486
|
switch (_a.label) {
|
6633
6487
|
case 0:
|
@@ -6674,9 +6528,9 @@ var PerpetualsClient = (function () {
|
|
6674
6528
|
instructions.push(editTriggerOrder);
|
6675
6529
|
return [3, 4];
|
6676
6530
|
case 3:
|
6677
|
-
|
6678
|
-
console.log("perpClient editTriggerOrder error:: ",
|
6679
|
-
throw
|
6531
|
+
err_44 = _a.sent();
|
6532
|
+
console.log("perpClient editTriggerOrder error:: ", err_44);
|
6533
|
+
throw err_44;
|
6680
6534
|
case 4: return [2, {
|
6681
6535
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6682
6536
|
additionalSigners: additionalSigners
|
@@ -6685,7 +6539,7 @@ var PerpetualsClient = (function () {
|
|
6685
6539
|
});
|
6686
6540
|
}); };
|
6687
6541
|
this.cancelTriggerOrder = function (targetSymbol, collateralSymbol, side, orderId, isStopLoss, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6688
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder,
|
6542
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, cancelTriggerOrder, err_45;
|
6689
6543
|
return __generator(this, function (_a) {
|
6690
6544
|
switch (_a.label) {
|
6691
6545
|
case 0:
|
@@ -6718,9 +6572,9 @@ var PerpetualsClient = (function () {
|
|
6718
6572
|
instructions.push(cancelTriggerOrder);
|
6719
6573
|
return [3, 4];
|
6720
6574
|
case 3:
|
6721
|
-
|
6722
|
-
console.log("perpClient cancelTriggerOrder error:: ",
|
6723
|
-
throw
|
6575
|
+
err_45 = _a.sent();
|
6576
|
+
console.log("perpClient cancelTriggerOrder error:: ", err_45);
|
6577
|
+
throw err_45;
|
6724
6578
|
case 4: return [2, {
|
6725
6579
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6726
6580
|
additionalSigners: additionalSigners
|
@@ -6729,7 +6583,7 @@ var PerpetualsClient = (function () {
|
|
6729
6583
|
});
|
6730
6584
|
}); };
|
6731
6585
|
this.cancelAllTriggerOrders = function (targetSymbol, collateralSymbol, side, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6732
|
-
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders,
|
6586
|
+
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, orderAccount, positionAccount, cancelAllTriggerOrders, err_46;
|
6733
6587
|
return __generator(this, function (_a) {
|
6734
6588
|
switch (_a.label) {
|
6735
6589
|
case 0:
|
@@ -6760,9 +6614,9 @@ var PerpetualsClient = (function () {
|
|
6760
6614
|
instructions.push(cancelAllTriggerOrders);
|
6761
6615
|
return [3, 4];
|
6762
6616
|
case 3:
|
6763
|
-
|
6764
|
-
console.log("perpClient cancelAllTriggerOrders error:: ",
|
6765
|
-
throw
|
6617
|
+
err_46 = _a.sent();
|
6618
|
+
console.log("perpClient cancelAllTriggerOrders error:: ", err_46);
|
6619
|
+
throw err_46;
|
6766
6620
|
case 4: return [2, {
|
6767
6621
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6768
6622
|
additionalSigners: additionalSigners
|
@@ -6770,16 +6624,20 @@ var PerpetualsClient = (function () {
|
|
6770
6624
|
}
|
6771
6625
|
});
|
6772
6626
|
}); };
|
6773
|
-
this.executeTriggerWithSwap = function (
|
6774
|
-
|
6775
|
-
|
6776
|
-
|
6777
|
-
|
6778
|
-
|
6779
|
-
|
6780
|
-
|
6781
|
-
|
6782
|
-
|
6627
|
+
this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6628
|
+
var args_1 = [];
|
6629
|
+
for (var _i = 9; _i < arguments.length; _i++) {
|
6630
|
+
args_1[_i - 9] = arguments[_i];
|
6631
|
+
}
|
6632
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, receivingSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6633
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_47;
|
6634
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6635
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6636
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
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) {
|
6783
6641
|
case 0:
|
6784
6642
|
payerPubkey = this.provider.wallet.publicKey;
|
6785
6643
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6790,9 +6648,9 @@ var PerpetualsClient = (function () {
|
|
6790
6648
|
instructions = [];
|
6791
6649
|
postInstructions = [];
|
6792
6650
|
additionalSigners = [];
|
6793
|
-
|
6651
|
+
_e.label = 1;
|
6794
6652
|
case 1:
|
6795
|
-
|
6653
|
+
_e.trys.push([1, 9, , 10]);
|
6796
6654
|
if (!false) return [3, 2];
|
6797
6655
|
return [3, 7];
|
6798
6656
|
case 2:
|
@@ -6801,8 +6659,8 @@ var PerpetualsClient = (function () {
|
|
6801
6659
|
if (!_a) return [3, 4];
|
6802
6660
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6803
6661
|
case 3:
|
6804
|
-
_a = !(
|
6805
|
-
|
6662
|
+
_a = !(_e.sent());
|
6663
|
+
_e.label = 4;
|
6806
6664
|
case 4:
|
6807
6665
|
if (_a) {
|
6808
6666
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6812,20 +6670,20 @@ var PerpetualsClient = (function () {
|
|
6812
6670
|
if (!_b) return [3, 6];
|
6813
6671
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6814
6672
|
case 5:
|
6815
|
-
_b = !(
|
6816
|
-
|
6673
|
+
_b = !(_e.sent());
|
6674
|
+
_e.label = 6;
|
6817
6675
|
case 6:
|
6818
6676
|
if (_b) {
|
6819
6677
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6820
6678
|
}
|
6821
|
-
|
6679
|
+
_e.label = 7;
|
6822
6680
|
case 7:
|
6823
6681
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6824
6682
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6825
6683
|
custodyAccountMetas = [];
|
6826
6684
|
custodyOracleAccountMetas = [];
|
6827
|
-
for (
|
6828
|
-
custody = _c
|
6685
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
6686
|
+
custody = _d[_c];
|
6829
6687
|
custodyAccountMetas.push({
|
6830
6688
|
pubkey: custody.custodyAccount,
|
6831
6689
|
isSigner: false,
|
@@ -6870,13 +6728,13 @@ var PerpetualsClient = (function () {
|
|
6870
6728
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6871
6729
|
.instruction()];
|
6872
6730
|
case 8:
|
6873
|
-
executeTriggerWithSwap =
|
6731
|
+
executeTriggerWithSwap = _e.sent();
|
6874
6732
|
instructions.push(executeTriggerWithSwap);
|
6875
6733
|
return [3, 10];
|
6876
6734
|
case 9:
|
6877
|
-
|
6878
|
-
console.log("perpClient executeTriggerWithSwap error:: ",
|
6879
|
-
throw
|
6735
|
+
err_47 = _e.sent();
|
6736
|
+
console.log("perpClient executeTriggerWithSwap error:: ", err_47);
|
6737
|
+
throw err_47;
|
6880
6738
|
case 10: return [2, {
|
6881
6739
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6882
6740
|
additionalSigners: additionalSigners
|
@@ -6885,14 +6743,18 @@ var PerpetualsClient = (function () {
|
|
6885
6743
|
});
|
6886
6744
|
});
|
6887
6745
|
};
|
6888
|
-
this.executeTriggerOrder = function (
|
6889
|
-
|
6890
|
-
|
6891
|
-
|
6892
|
-
|
6893
|
-
|
6894
|
-
|
6895
|
-
|
6746
|
+
this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6747
|
+
var args_1 = [];
|
6748
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6749
|
+
args_1[_i - 8] = arguments[_i];
|
6750
|
+
}
|
6751
|
+
return __awaiter(_this, __spreadArray([owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1], args_1, true), void 0, function (owner, targetSymbol, collateralSymbol, side, orderId, isStopLoss, privilege, poolConfig, createUserATA, ephemeralSignerPubkey, tokenStakeAccount, userReferralAccount, rebateTokenAccount) {
|
6752
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_48;
|
6753
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
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; }
|
6896
6758
|
return __generator(this, function (_b) {
|
6897
6759
|
switch (_b.label) {
|
6898
6760
|
case 0:
|
@@ -6958,9 +6820,9 @@ var PerpetualsClient = (function () {
|
|
6958
6820
|
instructions.push(executeTriggerOrder);
|
6959
6821
|
return [3, 8];
|
6960
6822
|
case 7:
|
6961
|
-
|
6962
|
-
console.log("perpClient executeTriggerOrder error:: ",
|
6963
|
-
throw
|
6823
|
+
err_48 = _b.sent();
|
6824
|
+
console.log("perpClient executeTriggerOrder error:: ", err_48);
|
6825
|
+
throw err_48;
|
6964
6826
|
case 8: return [2, {
|
6965
6827
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6966
6828
|
additionalSigners: additionalSigners
|
@@ -6970,7 +6832,7 @@ var PerpetualsClient = (function () {
|
|
6970
6832
|
});
|
6971
6833
|
};
|
6972
6834
|
this.migrateTriggerOrder = function (owner, marketAccount, poolConfig) { return __awaiter(_this, void 0, void 0, function () {
|
6973
|
-
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder,
|
6835
|
+
var payerPubkey, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, migrateTriggerOrder, err_49;
|
6974
6836
|
return __generator(this, function (_a) {
|
6975
6837
|
switch (_a.label) {
|
6976
6838
|
case 0:
|
@@ -7000,8 +6862,298 @@ var PerpetualsClient = (function () {
|
|
7000
6862
|
instructions.push(migrateTriggerOrder);
|
7001
6863
|
return [3, 4];
|
7002
6864
|
case 3:
|
7003
|
-
|
7004
|
-
console.log("perpClient migrateTriggerOrder error:: ",
|
6865
|
+
err_49 = _a.sent();
|
6866
|
+
console.log("perpClient migrateTriggerOrder error:: ", err_49);
|
6867
|
+
throw err_49;
|
6868
|
+
case 4: return [2, {
|
6869
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6870
|
+
additionalSigners: additionalSigners
|
6871
|
+
}];
|
6872
|
+
}
|
6873
|
+
});
|
6874
|
+
}); };
|
6875
|
+
this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
|
6876
|
+
var args_1 = [];
|
6877
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
6878
|
+
args_1[_i - 5] = arguments[_i];
|
6879
|
+
}
|
6880
|
+
return __awaiter(_this, __spreadArray([userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1], args_1, true), void 0, function (userInputTokenSymbol, userOutputTokenSymbol, amountIn, minAmountOut, poolConfig, useFeesPool, createUserATA, unWrapSol, skipBalanceChecks, ephemeralSignerPubkey) {
|
6881
|
+
var userInputCustodyConfig, userOutputCustodyConfig, publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userOutputTokenAccount, userInputTokenAccount, wsolAssociatedTokenAccount, wsolATAExist, unWrappedSolBalance, _a, wsolAssociatedTokenAccount, closeWsolATAIns, accCreationLamports, lamports, unWrappedSolBalance, _b, tokenAccountBalance, _c, lamports, _d, custodyAccountMetas, custodyOracleAccountMetas, _e, _f, custody, params, inx, closeWsolATAIns, err_50;
|
6882
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
6883
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6884
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
6885
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6886
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6887
|
+
return __generator(this, function (_g) {
|
6888
|
+
switch (_g.label) {
|
6889
|
+
case 0:
|
6890
|
+
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
6891
|
+
if (!userInputCustodyConfig) {
|
6892
|
+
throw "userInputCustodyConfig not found";
|
6893
|
+
}
|
6894
|
+
userOutputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey); });
|
6895
|
+
if (!userOutputCustodyConfig) {
|
6896
|
+
throw "userOutputCustodyConfig not found";
|
6897
|
+
}
|
6898
|
+
publicKey = this.provider.wallet.publicKey;
|
6899
|
+
preInstructions = [];
|
6900
|
+
instructions = [];
|
6901
|
+
postInstructions = [];
|
6902
|
+
additionalSigners = [];
|
6903
|
+
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
6904
|
+
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
6905
|
+
case 1:
|
6906
|
+
wsolAssociatedTokenAccount = _g.sent();
|
6907
|
+
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
6908
|
+
case 2:
|
6909
|
+
wsolATAExist = _g.sent();
|
6910
|
+
if (!wsolATAExist) {
|
6911
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
6912
|
+
}
|
6913
|
+
if (!!skipBalanceChecks) return [3, 4];
|
6914
|
+
_a = anchor_1.BN.bind;
|
6915
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
6916
|
+
case 3:
|
6917
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6918
|
+
if (unWrappedSolBalance.lt(amountIn)) {
|
6919
|
+
throw "Insufficient SOL Funds";
|
6920
|
+
}
|
6921
|
+
_g.label = 4;
|
6922
|
+
case 4:
|
6923
|
+
instructions.push(web3_js_1.SystemProgram.transfer({
|
6924
|
+
fromPubkey: publicKey,
|
6925
|
+
toPubkey: wsolAssociatedTokenAccount,
|
6926
|
+
lamports: amountIn.toNumber(),
|
6927
|
+
}), (0, spl_token_1.createSyncNativeInstruction)(wsolAssociatedTokenAccount));
|
6928
|
+
return [2, {
|
6929
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6930
|
+
additionalSigners: additionalSigners
|
6931
|
+
}];
|
6932
|
+
case 5:
|
6933
|
+
if (userInputTokenSymbol == 'WSOL' && userOutputTokenSymbol == 'SOL') {
|
6934
|
+
console.log("WSOL=> SOL : NOTE : ONLY WAY IS TO CLOSE THE WSOL ATA and GET ALL SOL ");
|
6935
|
+
wsolAssociatedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, publicKey, true);
|
6936
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(wsolAssociatedTokenAccount, publicKey, publicKey);
|
6937
|
+
instructions.push(closeWsolATAIns);
|
6938
|
+
return [2, {
|
6939
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
6940
|
+
additionalSigners: additionalSigners
|
6941
|
+
}];
|
6942
|
+
}
|
6943
|
+
_g.label = 6;
|
6944
|
+
case 6:
|
6945
|
+
_g.trys.push([6, 19, , 20]);
|
6946
|
+
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
6947
|
+
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
6948
|
+
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
6949
|
+
case 7:
|
6950
|
+
accCreationLamports = (_g.sent());
|
6951
|
+
console.log("accCreationLamports:", accCreationLamports);
|
6952
|
+
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
6953
|
+
_b = anchor_1.BN.bind;
|
6954
|
+
return [4, this.provider.connection.getBalance(publicKey)];
|
6955
|
+
case 8:
|
6956
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6957
|
+
if (unWrappedSolBalance.lt(amountIn)) {
|
6958
|
+
throw "Insufficient SOL Funds";
|
6959
|
+
}
|
6960
|
+
if (!ephemeralSignerPubkey) {
|
6961
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
6962
|
+
additionalSigners.push(wrappedSolAccount);
|
6963
|
+
}
|
6964
|
+
;
|
6965
|
+
preInstructions = [
|
6966
|
+
web3_js_1.SystemProgram.createAccount({
|
6967
|
+
fromPubkey: publicKey,
|
6968
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
6969
|
+
lamports: lamports.toNumber(),
|
6970
|
+
space: 165,
|
6971
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
6972
|
+
}),
|
6973
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
6974
|
+
];
|
6975
|
+
postInstructions = [
|
6976
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
6977
|
+
];
|
6978
|
+
return [3, 12];
|
6979
|
+
case 9:
|
6980
|
+
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
6981
|
+
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
6982
|
+
case 10:
|
6983
|
+
if (!(_g.sent())) {
|
6984
|
+
throw "Insufficient Funds , Token Account doesn't exist";
|
6985
|
+
}
|
6986
|
+
if (!!skipBalanceChecks) return [3, 12];
|
6987
|
+
_c = anchor_1.BN.bind;
|
6988
|
+
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
6989
|
+
case 11:
|
6990
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
6991
|
+
if (tokenAccountBalance.lt(amountIn)) {
|
6992
|
+
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
6993
|
+
}
|
6994
|
+
_g.label = 12;
|
6995
|
+
case 12:
|
6996
|
+
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
6997
|
+
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
6998
|
+
if (!ephemeralSignerPubkey) {
|
6999
|
+
wrappedSolAccount = new web3_js_1.Keypair();
|
7000
|
+
additionalSigners.push(wrappedSolAccount);
|
7001
|
+
}
|
7002
|
+
;
|
7003
|
+
preInstructions = [
|
7004
|
+
web3_js_1.SystemProgram.createAccount({
|
7005
|
+
fromPubkey: publicKey,
|
7006
|
+
newAccountPubkey: (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey),
|
7007
|
+
lamports: lamports,
|
7008
|
+
space: 165,
|
7009
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
7010
|
+
}),
|
7011
|
+
(0, spl_token_1.createInitializeAccount3Instruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), spl_token_1.NATIVE_MINT, publicKey),
|
7012
|
+
];
|
7013
|
+
postInstructions = [
|
7014
|
+
(0, spl_token_1.createCloseAccountInstruction)((ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey), publicKey, publicKey),
|
7015
|
+
];
|
7016
|
+
return [3, 17];
|
7017
|
+
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
7018
|
+
case 14:
|
7019
|
+
userOutputTokenAccount = _g.sent();
|
7020
|
+
_d = createUserATA;
|
7021
|
+
if (!_d) return [3, 16];
|
7022
|
+
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
7023
|
+
case 15:
|
7024
|
+
_d = !(_g.sent());
|
7025
|
+
_g.label = 16;
|
7026
|
+
case 16:
|
7027
|
+
if (_d) {
|
7028
|
+
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
7029
|
+
}
|
7030
|
+
_g.label = 17;
|
7031
|
+
case 17:
|
7032
|
+
custodyAccountMetas = [];
|
7033
|
+
custodyOracleAccountMetas = [];
|
7034
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
7035
|
+
custody = _f[_e];
|
7036
|
+
custodyAccountMetas.push({
|
7037
|
+
pubkey: custody.custodyAccount,
|
7038
|
+
isSigner: false,
|
7039
|
+
isWritable: false,
|
7040
|
+
});
|
7041
|
+
custodyOracleAccountMetas.push({
|
7042
|
+
pubkey: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
7043
|
+
isSigner: false,
|
7044
|
+
isWritable: false,
|
7045
|
+
});
|
7046
|
+
}
|
7047
|
+
params = {
|
7048
|
+
amountIn: amountIn,
|
7049
|
+
minAmountOut: minAmountOut,
|
7050
|
+
useFeesPool: useFeesPool
|
7051
|
+
};
|
7052
|
+
return [4, this.program.methods
|
7053
|
+
.swap(params)
|
7054
|
+
.accounts({
|
7055
|
+
owner: publicKey,
|
7056
|
+
fundingAccount: userInputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userInputTokenAccount,
|
7057
|
+
receivingAccount: userOutputTokenSymbol == 'SOL' ? (ephemeralSignerPubkey ? ephemeralSignerPubkey : wrappedSolAccount.publicKey) : userOutputTokenAccount,
|
7058
|
+
transferAuthority: poolConfig.transferAuthority,
|
7059
|
+
perpetuals: poolConfig.perpetuals,
|
7060
|
+
pool: poolConfig.poolAddress,
|
7061
|
+
receivingCustody: userInputCustodyConfig.custodyAccount,
|
7062
|
+
receivingCustodyOracleAccount: this.useExtOracleAccount ? userInputCustodyConfig.extOracleAccount : userInputCustodyConfig.intOracleAccount,
|
7063
|
+
receivingCustodyTokenAccount: userInputCustodyConfig.tokenAccount,
|
7064
|
+
dispensingCustody: userOutputCustodyConfig.custodyAccount,
|
7065
|
+
dispensingCustodyOracleAccount: this.useExtOracleAccount ? userOutputCustodyConfig.extOracleAccount : userOutputCustodyConfig.intOracleAccount,
|
7066
|
+
dispensingCustodyTokenAccount: userOutputCustodyConfig.tokenAccount,
|
7067
|
+
eventAuthority: this.eventAuthority.publicKey,
|
7068
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7069
|
+
program: this.programId,
|
7070
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7071
|
+
})
|
7072
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
7073
|
+
.instruction()];
|
7074
|
+
case 18:
|
7075
|
+
inx = _g.sent();
|
7076
|
+
instructions.push(inx);
|
7077
|
+
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
7078
|
+
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
7079
|
+
instructions.push(closeWsolATAIns);
|
7080
|
+
}
|
7081
|
+
return [3, 20];
|
7082
|
+
case 19:
|
7083
|
+
err_50 = _g.sent();
|
7084
|
+
console.error("perpClient Swap error:: ", err_50);
|
7085
|
+
throw err_50;
|
7086
|
+
case 20: return [2, {
|
7087
|
+
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
7088
|
+
additionalSigners: additionalSigners
|
7089
|
+
}];
|
7090
|
+
}
|
7091
|
+
});
|
7092
|
+
});
|
7093
|
+
};
|
7094
|
+
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, err_51;
|
7096
|
+
return __generator(this, function (_b) {
|
7097
|
+
switch (_b.label) {
|
7098
|
+
case 0:
|
7099
|
+
rewardCustody = poolConfig.custodies.find(function (f) { return f.symbol == 'USDC'; });
|
7100
|
+
if (!rewardCustody) {
|
7101
|
+
throw "rewardCustody not found";
|
7102
|
+
}
|
7103
|
+
custody = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(swapTokenSymbol).mintKey); });
|
7104
|
+
if (!custody) {
|
7105
|
+
throw "custody not found";
|
7106
|
+
}
|
7107
|
+
publicKey = this.provider.wallet.publicKey;
|
7108
|
+
preInstructions = [];
|
7109
|
+
instructions = [];
|
7110
|
+
postInstructions = [];
|
7111
|
+
additionalSigners = [];
|
7112
|
+
_b.label = 1;
|
7113
|
+
case 1:
|
7114
|
+
_b.trys.push([1, 3, , 4]);
|
7115
|
+
custodyAccountMetas = [];
|
7116
|
+
custodyOracleAccountMetas = [];
|
7117
|
+
for (_i = 0, _a = poolConfig.custodies; _i < _a.length; _i++) {
|
7118
|
+
custody_1 = _a[_i];
|
7119
|
+
custodyAccountMetas.push({
|
7120
|
+
pubkey: custody_1.custodyAccount,
|
7121
|
+
isSigner: false,
|
7122
|
+
isWritable: false,
|
7123
|
+
});
|
7124
|
+
custodyOracleAccountMetas.push({
|
7125
|
+
pubkey: this.useExtOracleAccount ? custody_1.extOracleAccount : custody_1.intOracleAccount,
|
7126
|
+
isSigner: false,
|
7127
|
+
isWritable: false,
|
7128
|
+
});
|
7129
|
+
}
|
7130
|
+
params = {};
|
7131
|
+
return [4, this.program.methods
|
7132
|
+
.swapFeeInternal(params)
|
7133
|
+
.accounts({
|
7134
|
+
owner: publicKey,
|
7135
|
+
perpetuals: poolConfig.perpetuals,
|
7136
|
+
pool: poolConfig.poolAddress,
|
7137
|
+
rewardCustody: rewardCustody.custodyAccount,
|
7138
|
+
rewardCustodyOracleAccount: this.useExtOracleAccount ? rewardCustody.extOracleAccount : rewardCustody.intOracleAccount,
|
7139
|
+
rewardCustodyTokenAccount: rewardCustody.tokenAccount,
|
7140
|
+
custody: custody.custodyAccount,
|
7141
|
+
custodyOracleAccount: this.useExtOracleAccount ? custody.extOracleAccount : custody.intOracleAccount,
|
7142
|
+
custodyTokenAccount: custody.tokenAccount,
|
7143
|
+
eventAuthority: this.eventAuthority.publicKey,
|
7144
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
7145
|
+
program: this.programId,
|
7146
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
7147
|
+
})
|
7148
|
+
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
7149
|
+
.instruction()];
|
7150
|
+
case 2:
|
7151
|
+
inx = _b.sent();
|
7152
|
+
instructions.push(inx);
|
7153
|
+
return [3, 4];
|
7154
|
+
case 3:
|
7155
|
+
err_51 = _b.sent();
|
7156
|
+
console.error("perpClient Swap error:: ", err_51);
|
7005
7157
|
throw err_51;
|
7006
7158
|
case 4: return [2, {
|
7007
7159
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -8237,9 +8389,9 @@ var PerpetualsClient = (function () {
|
|
8237
8389
|
}
|
8238
8390
|
}
|
8239
8391
|
};
|
8240
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8241
|
-
|
8242
|
-
|
8392
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
|
8393
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8394
|
+
if (opts === void 0) { opts = {}; }
|
8243
8395
|
return __generator(this, function (_a) {
|
8244
8396
|
switch (_a.label) {
|
8245
8397
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8248,9 +8400,9 @@ var PerpetualsClient = (function () {
|
|
8248
8400
|
});
|
8249
8401
|
});
|
8250
8402
|
};
|
8251
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8252
|
-
|
8253
|
-
|
8403
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
|
8404
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8405
|
+
if (opts === void 0) { opts = {}; }
|
8254
8406
|
return __generator(this, function (_a) {
|
8255
8407
|
switch (_a.label) {
|
8256
8408
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|