flash-sdk 2.54.1 → 2.54.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OraclePrice.d.ts +0 -1
- package/dist/OrderAccount.d.ts +0 -1
- package/dist/PerpetualsClient.d.ts +0 -2
- package/dist/PerpetualsClient.js +547 -383
- package/dist/PoolAccount.d.ts +0 -1
- package/dist/PoolDataClient.d.ts +0 -1
- package/dist/PositionAccount.d.ts +0 -1
- package/dist/TokenStakeAccount.d.ts +0 -1
- package/dist/TokenVaultAccount.d.ts +0 -1
- package/dist/TradingAccount.d.ts +0 -1
- package/dist/ViewHelper.js +5 -5
- package/dist/backupOracle.js +7 -7
- package/dist/constants/index.d.ts +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +3 -3
- package/dist/utils/IdlCoder.js +17 -7
- package/dist/utils/alt.d.ts +0 -1
- package/dist/utils/alt.js +5 -6
- package/dist/utils/anchorCpiEvents.d.ts +0 -1
- package/dist/utils/anchorCpiEvents.js +4 -4
- package/dist/utils/index.js +6 -6
- package/dist/utils/rpc.js +59 -59
- package/package.json +2 -1
package/dist/PerpetualsClient.js
CHANGED
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
20
20
|
});
|
21
21
|
};
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
24
|
-
return g =
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
26
|
function step(op) {
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
@@ -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, collateralToken, 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:
|
@@ -2669,6 +2697,8 @@ var PerpetualsClient = (function () {
|
|
2669
2697
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
2670
2698
|
program: this.programId,
|
2671
2699
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
2700
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
2701
|
+
collateralTokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID
|
2672
2702
|
})
|
2673
2703
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
2674
2704
|
.instruction()];
|
@@ -2692,14 +2722,18 @@ var PerpetualsClient = (function () {
|
|
2692
2722
|
});
|
2693
2723
|
});
|
2694
2724
|
};
|
2695
|
-
this.swapAndOpen = function (
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
2701
|
-
return __awaiter(_this, void 0, void 0, function () {
|
2725
|
+
this.swapAndOpen = function (targetTokenSymbol_1, collateralTokenSymbol_1, userInputTokenSymbol_1, amountIn_1, minCollateralAmountOut_1, priceWithSlippage_1, sizeAmount_1, side_1, poolConfig_1, privilege_1) {
|
2726
|
+
var args_1 = [];
|
2727
|
+
for (var _i = 10; _i < arguments.length; _i++) {
|
2728
|
+
args_1[_i - 10] = arguments[_i];
|
2729
|
+
}
|
2730
|
+
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
2731
|
var publicKey, userInputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, targetToken, userInputTokenAccount, userInputToken, lamports, unWrappedSolBalance, _a, userOutputTokenAccount, tokenAccountBalance, _b, userOutputTokenAccount, rebateMintAccount, inx, err_3;
|
2732
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2733
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2734
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2735
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
2736
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2703
2737
|
return __generator(this, function (_c) {
|
2704
2738
|
switch (_c.label) {
|
2705
2739
|
case 0:
|
@@ -2850,13 +2884,17 @@ var PerpetualsClient = (function () {
|
|
2850
2884
|
});
|
2851
2885
|
});
|
2852
2886
|
};
|
2853
|
-
this.closeAndSwap = function (
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
return __awaiter(_this,
|
2887
|
+
this.closeAndSwap = function (targetTokenSymbol_1, userOutputTokenSymbol_1, collateralTokenSymbol_1, minSwapAmountOut_1, priceWithSlippage_1, side_1, poolConfig_1, privilege_1) {
|
2888
|
+
var args_1 = [];
|
2889
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
2890
|
+
args_1[_i - 8] = arguments[_i];
|
2891
|
+
}
|
2892
|
+
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) {
|
2859
2893
|
var publicKey, userOutputCustodyConfig, collateralCustodyConfig, targetCustodyConfig, marketAccount, positionAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, collateralToken, userOutputToken, lamports, userCollateralTokenAccount, rebateMintAccount, inx, err_4;
|
2894
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
2895
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
2896
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
2897
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2860
2898
|
return __generator(this, function (_a) {
|
2861
2899
|
switch (_a.label) {
|
2862
2900
|
case 0:
|
@@ -2979,11 +3017,15 @@ var PerpetualsClient = (function () {
|
|
2979
3017
|
});
|
2980
3018
|
});
|
2981
3019
|
};
|
2982
|
-
this.addCollateral = function (
|
2983
|
-
|
2984
|
-
|
2985
|
-
|
3020
|
+
this.addCollateral = function (collateralWithFee_1, targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3021
|
+
var args_1 = [];
|
3022
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3023
|
+
args_1[_i - 6] = arguments[_i];
|
3024
|
+
}
|
3025
|
+
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) {
|
2986
3026
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, userPayingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, instruction;
|
3027
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3028
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
2987
3029
|
return __generator(this, function (_c) {
|
2988
3030
|
switch (_c.label) {
|
2989
3031
|
case 0:
|
@@ -3078,11 +3120,15 @@ var PerpetualsClient = (function () {
|
|
3078
3120
|
});
|
3079
3121
|
});
|
3080
3122
|
};
|
3081
|
-
this.swapAndAddCollateral = function (
|
3082
|
-
|
3083
|
-
|
3084
|
-
|
3123
|
+
this.swapAndAddCollateral = function (targetSymbol_1, inputSymbol_1, collateralSymbol_1, amountIn_1, minCollateralAmountOut_1, side_1, positionPubKey_1, poolConfig_1) {
|
3124
|
+
var args_1 = [];
|
3125
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3126
|
+
args_1[_i - 8] = arguments[_i];
|
3127
|
+
}
|
3128
|
+
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) {
|
3085
3129
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, inputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, userCollateralTokenAccount, marketAccount, instruction;
|
3130
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3131
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3086
3132
|
return __generator(this, function (_c) {
|
3087
3133
|
switch (_c.label) {
|
3088
3134
|
case 0:
|
@@ -3193,12 +3239,16 @@ var PerpetualsClient = (function () {
|
|
3193
3239
|
});
|
3194
3240
|
});
|
3195
3241
|
};
|
3196
|
-
this.removeCollateral = function (
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3242
|
+
this.removeCollateral = function (collateralWithFee_1, marketSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1) {
|
3243
|
+
var args_1 = [];
|
3244
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
3245
|
+
args_1[_i - 6] = arguments[_i];
|
3246
|
+
}
|
3247
|
+
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) {
|
3201
3248
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, lamports, _a, marketAccount, instruction, closeWsolATAIns, error_2;
|
3249
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3250
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3251
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3202
3252
|
return __generator(this, function (_b) {
|
3203
3253
|
switch (_b.label) {
|
3204
3254
|
case 0:
|
@@ -3300,10 +3350,14 @@ var PerpetualsClient = (function () {
|
|
3300
3350
|
});
|
3301
3351
|
});
|
3302
3352
|
};
|
3303
|
-
this.removeCollateralAndSwap = function (
|
3304
|
-
|
3305
|
-
|
3353
|
+
this.removeCollateralAndSwap = function (targetSymbol_1, collateralSymbol_1, outputSymbol_1, minSwapAmountOut_1, collateralDelta_1, side_1, poolConfig_1) {
|
3354
|
+
var args_1 = [];
|
3355
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
3356
|
+
args_1[_i - 7] = arguments[_i];
|
3357
|
+
}
|
3358
|
+
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) {
|
3306
3359
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, outputCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userReceivingTokenAccount, lamports, userCollateralTokenAccount, marketAccount, positionAccount, instruction;
|
3360
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3307
3361
|
return __generator(this, function (_a) {
|
3308
3362
|
switch (_a.label) {
|
3309
3363
|
case 0:
|
@@ -3396,12 +3450,16 @@ var PerpetualsClient = (function () {
|
|
3396
3450
|
});
|
3397
3451
|
});
|
3398
3452
|
};
|
3399
|
-
this.increaseSize = function (
|
3400
|
-
|
3401
|
-
|
3402
|
-
|
3403
|
-
|
3453
|
+
this.increaseSize = function (targetSymbol_1, collateralSymbol_1, positionPubKey_1, side_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3454
|
+
var args_1 = [];
|
3455
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3456
|
+
args_1[_i - 8] = arguments[_i];
|
3457
|
+
}
|
3458
|
+
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) {
|
3404
3459
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3460
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3461
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3462
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3405
3463
|
return __generator(this, function (_a) {
|
3406
3464
|
switch (_a.label) {
|
3407
3465
|
case 0:
|
@@ -3456,12 +3514,16 @@ var PerpetualsClient = (function () {
|
|
3456
3514
|
});
|
3457
3515
|
});
|
3458
3516
|
};
|
3459
|
-
this.decreaseSize = function (
|
3460
|
-
|
3461
|
-
|
3462
|
-
|
3463
|
-
|
3517
|
+
this.decreaseSize = function (targetSymbol_1, collateralSymbol_1, side_1, positionPubKey_1, poolConfig_1, priceWithSlippage_1, sizeDelta_1, privilege_1) {
|
3518
|
+
var args_1 = [];
|
3519
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
3520
|
+
args_1[_i - 8] = arguments[_i];
|
3521
|
+
}
|
3522
|
+
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) {
|
3464
3523
|
var publicKey, collateralCustodyConfig, targetCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, instruction;
|
3524
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
3525
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
3526
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
3465
3527
|
return __generator(this, function (_a) {
|
3466
3528
|
switch (_a.label) {
|
3467
3529
|
case 0:
|
@@ -3501,7 +3563,8 @@ var PerpetualsClient = (function () {
|
|
3501
3563
|
tokenProgram: poolConfig.getTokenFromSymbol(collateralSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
3502
3564
|
eventAuthority: this.eventAuthority.publicKey,
|
3503
3565
|
program: this.programId,
|
3504
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
3566
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
3567
|
+
collateralMint: collateralCustodyConfig.mintKey
|
3505
3568
|
})
|
3506
3569
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
3507
3570
|
.instruction()];
|
@@ -3516,13 +3579,17 @@ var PerpetualsClient = (function () {
|
|
3516
3579
|
});
|
3517
3580
|
});
|
3518
3581
|
};
|
3519
|
-
this.addLiquidity = function (
|
3520
|
-
|
3521
|
-
|
3522
|
-
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3582
|
+
this.addLiquidity = function (payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3583
|
+
var args_1 = [];
|
3584
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3585
|
+
args_1[_i - 4] = arguments[_i];
|
3586
|
+
}
|
3587
|
+
return __awaiter(_this, __spreadArray([payTokenSymbol_1, tokenAmountIn_1, minLpAmountOut_1, poolConfig_1], args_1, true), void 0, function (payTokenSymbol, tokenAmountIn, minLpAmountOut, poolConfig, skipBalanceChecks, ephemeralSignerPubkey) {
|
3588
|
+
var publicKey, payTokenCustodyConfig, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, payToken, userPayingTokenAccount, lpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, unWrappedSolBalance, _e, tokenAccountBalance, _f, instruction, err_5;
|
3589
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3590
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3591
|
+
return __generator(this, function (_g) {
|
3592
|
+
switch (_g.label) {
|
3526
3593
|
case 0:
|
3527
3594
|
publicKey = this.provider.wallet.publicKey;
|
3528
3595
|
payTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(payTokenSymbol).mintKey); });
|
@@ -3534,16 +3601,16 @@ var PerpetualsClient = (function () {
|
|
3534
3601
|
postInstructions = [];
|
3535
3602
|
additionalSigners = [];
|
3536
3603
|
payToken = poolConfig.getTokenFromSymbol(payTokenSymbol);
|
3537
|
-
|
3604
|
+
_g.label = 1;
|
3538
3605
|
case 1:
|
3539
|
-
|
3606
|
+
_g.trys.push([1, 10, , 11]);
|
3540
3607
|
userPayingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(payTokenCustodyConfig.mintKey, publicKey, true, payToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3541
3608
|
lpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3542
3609
|
custodyAccountMetas = [];
|
3543
3610
|
custodyOracleAccountMetas = [];
|
3544
3611
|
markets = [];
|
3545
|
-
for (
|
3546
|
-
custody = _a
|
3612
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
3613
|
+
custody = _b[_a];
|
3547
3614
|
custodyAccountMetas.push({
|
3548
3615
|
pubkey: custody.custodyAccount,
|
3549
3616
|
isSigner: false,
|
@@ -3555,8 +3622,8 @@ var PerpetualsClient = (function () {
|
|
3555
3622
|
isWritable: false,
|
3556
3623
|
});
|
3557
3624
|
}
|
3558
|
-
for (
|
3559
|
-
market = _c
|
3625
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
3626
|
+
market = _d[_c];
|
3560
3627
|
markets.push({
|
3561
3628
|
pubkey: market.marketAccount,
|
3562
3629
|
isSigner: false,
|
@@ -3565,21 +3632,21 @@ var PerpetualsClient = (function () {
|
|
3565
3632
|
}
|
3566
3633
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3567
3634
|
case 2:
|
3568
|
-
if (!(
|
3635
|
+
if (!(_g.sent())) {
|
3569
3636
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3570
3637
|
}
|
3571
3638
|
if (!(payTokenSymbol == 'SOL')) return [3, 5];
|
3572
3639
|
console.log("payTokenSymbol === SOL", payTokenSymbol);
|
3573
3640
|
lamports = tokenAmountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
3574
3641
|
if (!!skipBalanceChecks) return [3, 4];
|
3575
|
-
|
3642
|
+
_e = anchor_1.BN.bind;
|
3576
3643
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3577
3644
|
case 3:
|
3578
|
-
unWrappedSolBalance = new (
|
3645
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3579
3646
|
if (unWrappedSolBalance.lt(lamports)) {
|
3580
3647
|
throw "Insufficient SOL Funds";
|
3581
3648
|
}
|
3582
|
-
|
3649
|
+
_g.label = 4;
|
3583
3650
|
case 4:
|
3584
3651
|
if (!ephemeralSignerPubkey) {
|
3585
3652
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -3603,17 +3670,17 @@ var PerpetualsClient = (function () {
|
|
3603
3670
|
if (!!skipBalanceChecks) return [3, 8];
|
3604
3671
|
return [4, (0, utils_1.checkIfAccountExists)(userPayingTokenAccount, this.provider.connection)];
|
3605
3672
|
case 6:
|
3606
|
-
if (!(
|
3673
|
+
if (!(_g.sent())) {
|
3607
3674
|
throw "Insufficient Funds , token Account doesn't exist";
|
3608
3675
|
}
|
3609
|
-
|
3676
|
+
_f = anchor_1.BN.bind;
|
3610
3677
|
return [4, this.provider.connection.getTokenAccountBalance(userPayingTokenAccount)];
|
3611
3678
|
case 7:
|
3612
|
-
tokenAccountBalance = new (
|
3679
|
+
tokenAccountBalance = new (_f.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3613
3680
|
if (tokenAccountBalance.lt(tokenAmountIn)) {
|
3614
3681
|
throw "Insufficient Funds need more ".concat(tokenAmountIn.sub(tokenAccountBalance), " tokens");
|
3615
3682
|
}
|
3616
|
-
|
3683
|
+
_g.label = 8;
|
3617
3684
|
case 8: return [4, this.program.methods
|
3618
3685
|
.addLiquidity({
|
3619
3686
|
amountIn: tokenAmountIn,
|
@@ -3640,11 +3707,11 @@ var PerpetualsClient = (function () {
|
|
3640
3707
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3641
3708
|
.instruction()];
|
3642
3709
|
case 9:
|
3643
|
-
instruction =
|
3710
|
+
instruction = _g.sent();
|
3644
3711
|
instructions.push(instruction);
|
3645
3712
|
return [3, 11];
|
3646
3713
|
case 10:
|
3647
|
-
err_5 =
|
3714
|
+
err_5 = _g.sent();
|
3648
3715
|
console.error("perpClient addLiquidity error:: ", err_5);
|
3649
3716
|
throw err_5;
|
3650
3717
|
case 11: return [2, {
|
@@ -3655,14 +3722,18 @@ var PerpetualsClient = (function () {
|
|
3655
3722
|
});
|
3656
3723
|
});
|
3657
3724
|
};
|
3658
|
-
this.addLiquidityAndStake = function (
|
3659
|
-
|
3660
|
-
|
3661
|
-
|
3662
|
-
|
3663
|
-
|
3664
|
-
|
3665
|
-
|
3725
|
+
this.addLiquidityAndStake = function (inputSymbol_1, amountIn_1, minLpAmountOut_1, poolConfig_1) {
|
3726
|
+
var args_1 = [];
|
3727
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3728
|
+
args_1[_i - 4] = arguments[_i];
|
3729
|
+
}
|
3730
|
+
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) {
|
3731
|
+
var publicKey, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, userInputTokenAccount, lpTokenMint, inputCustodyConfig, lpTokenAccount, inputToken, flpStakeAccount, poolStakedLpVault, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, custodyAccountMetas, custodyOracleAccountMetas, markets, _c, _d, custody, _e, _f, market, instruction;
|
3732
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
3733
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3734
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3735
|
+
return __generator(this, function (_g) {
|
3736
|
+
switch (_g.label) {
|
3666
3737
|
case 0:
|
3667
3738
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
3668
3739
|
preInstructions = [];
|
@@ -3683,14 +3754,14 @@ var PerpetualsClient = (function () {
|
|
3683
3754
|
_a = anchor_1.BN.bind;
|
3684
3755
|
return [4, this.provider.connection.getBalance(publicKey)];
|
3685
3756
|
case 1:
|
3686
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
3757
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
3687
3758
|
if (unWrappedSolBalance.lt(lamports)) {
|
3688
3759
|
throw "Insufficient SOL Funds";
|
3689
3760
|
}
|
3690
|
-
|
3761
|
+
_g.label = 2;
|
3691
3762
|
case 2: return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
3692
3763
|
case 3:
|
3693
|
-
if (!(
|
3764
|
+
if (!(_g.sent())) {
|
3694
3765
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
3695
3766
|
}
|
3696
3767
|
if (!ephemeralSignerPubkey) {
|
@@ -3716,23 +3787,23 @@ var PerpetualsClient = (function () {
|
|
3716
3787
|
if (!!skipBalanceChecks) return [3, 7];
|
3717
3788
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
3718
3789
|
case 5:
|
3719
|
-
if (!(
|
3790
|
+
if (!(_g.sent())) {
|
3720
3791
|
throw "Insufficient Funds , token Account doesn't exist";
|
3721
3792
|
}
|
3722
3793
|
_b = anchor_1.BN.bind;
|
3723
3794
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
3724
3795
|
case 6:
|
3725
|
-
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (
|
3796
|
+
tokenAccountBalance = new (_b.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
3726
3797
|
if (tokenAccountBalance.lt(amountIn)) {
|
3727
3798
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
3728
3799
|
}
|
3729
|
-
|
3800
|
+
_g.label = 7;
|
3730
3801
|
case 7:
|
3731
3802
|
custodyAccountMetas = [];
|
3732
3803
|
custodyOracleAccountMetas = [];
|
3733
3804
|
markets = [];
|
3734
|
-
for (
|
3735
|
-
custody = _c
|
3805
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
3806
|
+
custody = _d[_c];
|
3736
3807
|
custodyAccountMetas.push({
|
3737
3808
|
pubkey: custody.custodyAccount,
|
3738
3809
|
isSigner: false,
|
@@ -3744,8 +3815,8 @@ var PerpetualsClient = (function () {
|
|
3744
3815
|
isWritable: false,
|
3745
3816
|
});
|
3746
3817
|
}
|
3747
|
-
for (
|
3748
|
-
market = _e
|
3818
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
3819
|
+
market = _f[_e];
|
3749
3820
|
markets.push({
|
3750
3821
|
pubkey: market.marketAccount,
|
3751
3822
|
isSigner: false,
|
@@ -3779,7 +3850,7 @@ var PerpetualsClient = (function () {
|
|
3779
3850
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3780
3851
|
.instruction()];
|
3781
3852
|
case 8:
|
3782
|
-
instruction =
|
3853
|
+
instruction = _g.sent();
|
3783
3854
|
instructions.push(instruction);
|
3784
3855
|
return [2, {
|
3785
3856
|
instructions: __spreadArray(__spreadArray(__spreadArray([], preInstructions, true), instructions, true), postInstructions, true),
|
@@ -3789,16 +3860,20 @@ var PerpetualsClient = (function () {
|
|
3789
3860
|
});
|
3790
3861
|
});
|
3791
3862
|
};
|
3792
|
-
this.removeLiquidity = function (
|
3793
|
-
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
3797
|
-
|
3798
|
-
|
3799
|
-
|
3800
|
-
|
3801
|
-
|
3863
|
+
this.removeLiquidity = function (recieveTokenSymbol_1, liquidityAmountIn_1, minTokenAmountOut_1, poolConfig_1) {
|
3864
|
+
var args_1 = [];
|
3865
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
3866
|
+
args_1[_i - 4] = arguments[_i];
|
3867
|
+
}
|
3868
|
+
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) {
|
3869
|
+
var recieveTokenCustodyConfig, publicKey, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, recieveToken, stakedLpTokenAccount, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, lamports, _e, removeLiquidityTx, closeInx, closeWsolATAIns, err_6;
|
3870
|
+
if (closeLpATA === void 0) { closeLpATA = false; }
|
3871
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
3872
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
3873
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
3874
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
3875
|
+
return __generator(this, function (_f) {
|
3876
|
+
switch (_f.label) {
|
3802
3877
|
case 0:
|
3803
3878
|
recieveTokenCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(recieveTokenSymbol).mintKey); });
|
3804
3879
|
if (!recieveTokenCustodyConfig) {
|
@@ -3810,15 +3885,15 @@ var PerpetualsClient = (function () {
|
|
3810
3885
|
postInstructions = [];
|
3811
3886
|
additionalSigners = [];
|
3812
3887
|
recieveToken = poolConfig.getTokenFromSymbol(recieveTokenSymbol);
|
3813
|
-
|
3888
|
+
_f.label = 1;
|
3814
3889
|
case 1:
|
3815
|
-
|
3890
|
+
_f.trys.push([1, 7, , 8]);
|
3816
3891
|
stakedLpTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.stakedLpTokenMint, publicKey, true);
|
3817
3892
|
custodyAccountMetas = [];
|
3818
3893
|
custodyOracleAccountMetas = [];
|
3819
3894
|
markets = [];
|
3820
|
-
for (
|
3821
|
-
custody = _a
|
3895
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
3896
|
+
custody = _b[_a];
|
3822
3897
|
custodyAccountMetas.push({
|
3823
3898
|
pubkey: custody.custodyAccount,
|
3824
3899
|
isSigner: false,
|
@@ -3830,8 +3905,8 @@ var PerpetualsClient = (function () {
|
|
3830
3905
|
isWritable: false,
|
3831
3906
|
});
|
3832
3907
|
}
|
3833
|
-
for (
|
3834
|
-
market = _c
|
3908
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
3909
|
+
market = _d[_c];
|
3835
3910
|
markets.push({
|
3836
3911
|
pubkey: market.marketAccount,
|
3837
3912
|
isSigner: false,
|
@@ -3860,17 +3935,17 @@ var PerpetualsClient = (function () {
|
|
3860
3935
|
return [3, 5];
|
3861
3936
|
case 2:
|
3862
3937
|
userReceivingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(recieveToken.mintKey, publicKey, true, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID);
|
3863
|
-
|
3864
|
-
if (!
|
3938
|
+
_e = createUserATA;
|
3939
|
+
if (!_e) return [3, 4];
|
3865
3940
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
3866
3941
|
case 3:
|
3867
|
-
|
3868
|
-
|
3942
|
+
_e = !(_f.sent());
|
3943
|
+
_f.label = 4;
|
3869
3944
|
case 4:
|
3870
|
-
if (
|
3945
|
+
if (_e) {
|
3871
3946
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, recieveToken.mintKey, recieveToken.isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID));
|
3872
3947
|
}
|
3873
|
-
|
3948
|
+
_f.label = 5;
|
3874
3949
|
case 5: return [4, this.program.methods
|
3875
3950
|
.removeLiquidity({
|
3876
3951
|
lpAmountIn: liquidityAmountIn,
|
@@ -3897,7 +3972,7 @@ var PerpetualsClient = (function () {
|
|
3897
3972
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
3898
3973
|
.instruction()];
|
3899
3974
|
case 6:
|
3900
|
-
removeLiquidityTx =
|
3975
|
+
removeLiquidityTx = _f.sent();
|
3901
3976
|
instructions.push(removeLiquidityTx);
|
3902
3977
|
if (closeLpATA) {
|
3903
3978
|
closeInx = (0, spl_token_1.createCloseAccountInstruction)(stakedLpTokenAccount, publicKey, publicKey);
|
@@ -3909,7 +3984,7 @@ var PerpetualsClient = (function () {
|
|
3909
3984
|
}
|
3910
3985
|
return [3, 8];
|
3911
3986
|
case 7:
|
3912
|
-
err_6 =
|
3987
|
+
err_6 = _f.sent();
|
3913
3988
|
console.log("perpClient removeLiquidity error:: ", err_6);
|
3914
3989
|
throw err_6;
|
3915
3990
|
case 8: return [2, {
|
@@ -4177,22 +4252,26 @@ var PerpetualsClient = (function () {
|
|
4177
4252
|
}
|
4178
4253
|
});
|
4179
4254
|
}); };
|
4180
|
-
this.refreshStakeWithTokenStake = function (
|
4181
|
-
|
4182
|
-
|
4183
|
-
|
4184
|
-
|
4185
|
-
|
4255
|
+
this.refreshStakeWithTokenStake = function (rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1) {
|
4256
|
+
var args_1 = [];
|
4257
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4258
|
+
args_1[_i - 3] = arguments[_i];
|
4259
|
+
}
|
4260
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, flpStakeAccountPk_1], args_1, true), void 0, function (rewardSymbol, poolConfig, flpStakeAccountPk, userPublicKey) {
|
4261
|
+
var publicKey, rewardCustodyMint, rewardCustodyConfig, pool, feeDistributionTokenAccount, custodyAccountMetas, _a, _b, custody, stakeAccountMetas, tokenStakeAccount, refreshStakeInstruction, err_12;
|
4262
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4263
|
+
return __generator(this, function (_c) {
|
4264
|
+
switch (_c.label) {
|
4186
4265
|
case 0:
|
4187
|
-
|
4266
|
+
_c.trys.push([0, 2, , 3]);
|
4188
4267
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4189
4268
|
rewardCustodyMint = poolConfig.getTokenFromSymbol(rewardSymbol).mintKey;
|
4190
4269
|
rewardCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(rewardSymbol).mintKey); });
|
4191
4270
|
pool = poolConfig.poolAddress;
|
4192
4271
|
feeDistributionTokenAccount = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("custody_token_account"), pool.toBuffer(), rewardCustodyMint.toBuffer()], this.programId)[0];
|
4193
4272
|
custodyAccountMetas = [];
|
4194
|
-
for (
|
4195
|
-
custody = _a
|
4273
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4274
|
+
custody = _b[_a];
|
4196
4275
|
custodyAccountMetas.push({
|
4197
4276
|
pubkey: custody.custodyAccount,
|
4198
4277
|
isSigner: false,
|
@@ -4224,10 +4303,10 @@ var PerpetualsClient = (function () {
|
|
4224
4303
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), stakeAccountMetas, true))
|
4225
4304
|
.instruction()];
|
4226
4305
|
case 1:
|
4227
|
-
refreshStakeInstruction =
|
4306
|
+
refreshStakeInstruction = _c.sent();
|
4228
4307
|
return [2, refreshStakeInstruction];
|
4229
4308
|
case 2:
|
4230
|
-
err_12 =
|
4309
|
+
err_12 = _c.sent();
|
4231
4310
|
console.log("perpClient refreshStaking error:: ", err_12);
|
4232
4311
|
throw err_12;
|
4233
4312
|
case 3: return [2];
|
@@ -4235,10 +4314,14 @@ var PerpetualsClient = (function () {
|
|
4235
4314
|
});
|
4236
4315
|
});
|
4237
4316
|
};
|
4238
|
-
this.unstakeInstant = function (
|
4239
|
-
|
4240
|
-
|
4317
|
+
this.unstakeInstant = function (rewardSymbol_1, unstakeAmount_1, poolConfig_1) {
|
4318
|
+
var args_1 = [];
|
4319
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4320
|
+
args_1[_i - 3] = arguments[_i];
|
4321
|
+
}
|
4322
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, unstakeAmount_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, unstakeAmount, poolConfig, userPublicKey) {
|
4241
4323
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyConfig, pool, flpStakeAccount, tokenStakeAccount, tokenStakeAccounts, _a, unstakeInstantInstruction, err_13;
|
4324
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4242
4325
|
return __generator(this, function (_b) {
|
4243
4326
|
switch (_b.label) {
|
4244
4327
|
case 0:
|
@@ -4397,13 +4480,17 @@ var PerpetualsClient = (function () {
|
|
4397
4480
|
}
|
4398
4481
|
});
|
4399
4482
|
}); };
|
4400
|
-
this.withdrawStake = function (
|
4401
|
-
|
4402
|
-
|
4403
|
-
|
4404
|
-
|
4405
|
-
return __awaiter(_this,
|
4483
|
+
this.withdrawStake = function (poolConfig_1) {
|
4484
|
+
var args_1 = [];
|
4485
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
4486
|
+
args_1[_i - 1] = arguments[_i];
|
4487
|
+
}
|
4488
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, pendingActivation, deactivated, createUserLPTA, userPublicKey) {
|
4406
4489
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, lpTokenMint, pool, poolStakedLpVault, flpStakeAccount, userLpTokenAccount, _a, withdrawStakeInstruction, err_16;
|
4490
|
+
if (pendingActivation === void 0) { pendingActivation = true; }
|
4491
|
+
if (deactivated === void 0) { deactivated = true; }
|
4492
|
+
if (createUserLPTA === void 0) { createUserLPTA = true; }
|
4493
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4407
4494
|
return __generator(this, function (_b) {
|
4408
4495
|
switch (_b.label) {
|
4409
4496
|
case 0:
|
@@ -4465,10 +4552,14 @@ var PerpetualsClient = (function () {
|
|
4465
4552
|
});
|
4466
4553
|
});
|
4467
4554
|
};
|
4468
|
-
this.collectStakeFees = function (
|
4469
|
-
|
4470
|
-
|
4555
|
+
this.collectStakeFees = function (rewardSymbol_1, poolConfig_1, tokenStakeAccount_1) {
|
4556
|
+
var args_1 = [];
|
4557
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4558
|
+
args_1[_i - 3] = arguments[_i];
|
4559
|
+
}
|
4560
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, tokenStakeAccount_1], args_1, true), void 0, function (rewardSymbol, poolConfig, tokenStakeAccount, createUserATA) {
|
4471
4561
|
var publicKey, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tokenStakeAccounts, withdrawStakeInstruction, err_17;
|
4562
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4472
4563
|
return __generator(this, function (_b) {
|
4473
4564
|
switch (_b.label) {
|
4474
4565
|
case 0:
|
@@ -4538,14 +4629,18 @@ var PerpetualsClient = (function () {
|
|
4538
4629
|
});
|
4539
4630
|
});
|
4540
4631
|
};
|
4541
|
-
this.addCompoundingLiquidity = function (
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4546
|
-
|
4547
|
-
|
4548
|
-
|
4632
|
+
this.addCompoundingLiquidity = function (amountIn_1, minCompoundingAmountOut_1, inTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
4633
|
+
var args_1 = [];
|
4634
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
4635
|
+
args_1[_i - 5] = arguments[_i];
|
4636
|
+
}
|
4637
|
+
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) {
|
4638
|
+
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_18;
|
4639
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
4640
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4641
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4642
|
+
return __generator(this, function (_f) {
|
4643
|
+
switch (_f.label) {
|
4549
4644
|
case 0:
|
4550
4645
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4551
4646
|
preInstructions = [];
|
@@ -4562,8 +4657,8 @@ var PerpetualsClient = (function () {
|
|
4562
4657
|
custodyAccountMetas = [];
|
4563
4658
|
custodyOracleAccountMetas = [];
|
4564
4659
|
markets = [];
|
4565
|
-
for (
|
4566
|
-
custody = _a
|
4660
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
4661
|
+
custody = _b[_a];
|
4567
4662
|
custodyAccountMetas.push({
|
4568
4663
|
pubkey: custody.custodyAccount,
|
4569
4664
|
isSigner: false,
|
@@ -4575,8 +4670,8 @@ var PerpetualsClient = (function () {
|
|
4575
4670
|
isWritable: false,
|
4576
4671
|
});
|
4577
4672
|
}
|
4578
|
-
for (
|
4579
|
-
market = _c
|
4673
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
4674
|
+
market = _d[_c];
|
4580
4675
|
markets.push({
|
4581
4676
|
pubkey: market.marketAccount,
|
4582
4677
|
isSigner: false,
|
@@ -4585,26 +4680,26 @@ var PerpetualsClient = (function () {
|
|
4585
4680
|
}
|
4586
4681
|
return [4, (0, utils_1.checkIfAccountExists)(lpTokenAccount, this.provider.connection)];
|
4587
4682
|
case 1:
|
4588
|
-
if (!(
|
4683
|
+
if (!(_f.sent())) {
|
4589
4684
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, lpTokenAccount, publicKey, poolConfig.stakedLpTokenMint));
|
4590
4685
|
}
|
4591
4686
|
return [4, (0, utils_1.checkIfAccountExists)(compoundingTokenAccount, this.provider.connection)];
|
4592
4687
|
case 2:
|
4593
|
-
if (!(
|
4688
|
+
if (!(_f.sent())) {
|
4594
4689
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoundingTokenAccount, publicKey, poolConfig.compoundingTokenMint));
|
4595
4690
|
}
|
4596
4691
|
if (!(inTokenSymbol == 'SOL')) return [3, 5];
|
4597
4692
|
console.log("inTokenSymbol === SOL", inTokenSymbol);
|
4598
4693
|
lamports = amountIn.add(new anchor_1.BN(this.minimumBalanceForRentExemptAccountLamports));
|
4599
4694
|
if (!!skipBalanceChecks) return [3, 4];
|
4600
|
-
|
4695
|
+
_e = anchor_1.BN.bind;
|
4601
4696
|
return [4, this.provider.connection.getBalance(publicKey)];
|
4602
4697
|
case 3:
|
4603
|
-
unWrappedSolBalance = new (
|
4698
|
+
unWrappedSolBalance = new (_e.apply(anchor_1.BN, [void 0, _f.sent()]))();
|
4604
4699
|
if (unWrappedSolBalance.lt(lamports)) {
|
4605
4700
|
throw "Insufficient SOL Funds";
|
4606
4701
|
}
|
4607
|
-
|
4702
|
+
_f.label = 4;
|
4608
4703
|
case 4:
|
4609
4704
|
if (!ephemeralSignerPubkey) {
|
4610
4705
|
wrappedSolAccount = new web3_js_1.Keypair();
|
@@ -4628,12 +4723,12 @@ var PerpetualsClient = (function () {
|
|
4628
4723
|
if (!!skipBalanceChecks) return [3, 7];
|
4629
4724
|
return [4, (0, utils_1.checkIfAccountExists)(fundingAccount, this.provider.connection)];
|
4630
4725
|
case 6:
|
4631
|
-
if (!(
|
4726
|
+
if (!(_f.sent())) {
|
4632
4727
|
throw "Insufficient Funds , token Account doesn't exist";
|
4633
4728
|
}
|
4634
|
-
|
4729
|
+
_f.label = 7;
|
4635
4730
|
case 7:
|
4636
|
-
|
4731
|
+
_f.trys.push([7, 9, , 10]);
|
4637
4732
|
return [4, this.program.methods
|
4638
4733
|
.addCompoundingLiquidity({
|
4639
4734
|
amountIn: amountIn,
|
@@ -4657,16 +4752,18 @@ var PerpetualsClient = (function () {
|
|
4657
4752
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
4658
4753
|
eventAuthority: this.eventAuthority.publicKey,
|
4659
4754
|
program: this.program.programId,
|
4660
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
4755
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
4756
|
+
fundingMint: inCustodyConfig.mintKey,
|
4757
|
+
fundingTokenProgram: poolConfig.getTokenFromSymbol(inTokenSymbol).isToken2022 ? spl_token_1.TOKEN_2022_PROGRAM_ID : spl_token_1.TOKEN_PROGRAM_ID,
|
4661
4758
|
})
|
4662
4759
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4663
4760
|
.instruction()];
|
4664
4761
|
case 8:
|
4665
|
-
addCompoundingLiquidity =
|
4762
|
+
addCompoundingLiquidity = _f.sent();
|
4666
4763
|
instructions.push(addCompoundingLiquidity);
|
4667
4764
|
return [3, 10];
|
4668
4765
|
case 9:
|
4669
|
-
err_18 =
|
4766
|
+
err_18 = _f.sent();
|
4670
4767
|
console.log("perpClient addCompoundingLiquidity error:: ", err_18);
|
4671
4768
|
return [3, 10];
|
4672
4769
|
case 10: return [2, {
|
@@ -4677,14 +4774,18 @@ var PerpetualsClient = (function () {
|
|
4677
4774
|
});
|
4678
4775
|
});
|
4679
4776
|
};
|
4680
|
-
this.removeCompoundingLiquidity = function (
|
4681
|
-
|
4682
|
-
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4777
|
+
this.removeCompoundingLiquidity = function (compoundingAmountIn_1, minAmountOut_1, outTokenSymbol_1, rewardTokenMint_1, poolConfig_1) {
|
4778
|
+
var args_1 = [];
|
4779
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
4780
|
+
args_1[_i - 5] = arguments[_i];
|
4781
|
+
}
|
4782
|
+
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) {
|
4783
|
+
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_19;
|
4784
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4785
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
4786
|
+
if (userPublicKey === void 0) { userPublicKey = undefined; }
|
4787
|
+
return __generator(this, function (_f) {
|
4788
|
+
switch (_f.label) {
|
4688
4789
|
case 0:
|
4689
4790
|
publicKey = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : this.provider.wallet.publicKey;
|
4690
4791
|
preInstructions = [];
|
@@ -4721,19 +4822,19 @@ var PerpetualsClient = (function () {
|
|
4721
4822
|
if (!_a) return [3, 3];
|
4722
4823
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
4723
4824
|
case 2:
|
4724
|
-
_a = !(
|
4725
|
-
|
4825
|
+
_a = !(_f.sent());
|
4826
|
+
_f.label = 3;
|
4726
4827
|
case 3:
|
4727
4828
|
if (_a) {
|
4728
4829
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userReceivingTokenAccount, publicKey, outCustodyConfig.mintKey));
|
4729
4830
|
}
|
4730
|
-
|
4831
|
+
_f.label = 4;
|
4731
4832
|
case 4:
|
4732
4833
|
custodyAccountMetas = [];
|
4733
4834
|
custodyOracleAccountMetas = [];
|
4734
4835
|
markets = [];
|
4735
|
-
for (
|
4736
|
-
custody = _b
|
4836
|
+
for (_b = 0, _c = poolConfig.custodies; _b < _c.length; _b++) {
|
4837
|
+
custody = _c[_b];
|
4737
4838
|
custodyAccountMetas.push({
|
4738
4839
|
pubkey: custody.custodyAccount,
|
4739
4840
|
isSigner: false,
|
@@ -4745,8 +4846,8 @@ var PerpetualsClient = (function () {
|
|
4745
4846
|
isWritable: false,
|
4746
4847
|
});
|
4747
4848
|
}
|
4748
|
-
for (
|
4749
|
-
market = _d
|
4849
|
+
for (_d = 0, _e = poolConfig.markets; _d < _e.length; _d++) {
|
4850
|
+
market = _e[_d];
|
4750
4851
|
markets.push({
|
4751
4852
|
pubkey: market.marketAccount,
|
4752
4853
|
isSigner: false,
|
@@ -4754,9 +4855,9 @@ var PerpetualsClient = (function () {
|
|
4754
4855
|
});
|
4755
4856
|
}
|
4756
4857
|
compoundingTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(compoundingTokenMint, publicKey, true);
|
4757
|
-
|
4858
|
+
_f.label = 5;
|
4758
4859
|
case 5:
|
4759
|
-
|
4860
|
+
_f.trys.push([5, 7, , 8]);
|
4760
4861
|
return [4, this.program.methods
|
4761
4862
|
.removeCompoundingLiquidity({
|
4762
4863
|
compoundingAmountIn: compoundingAmountIn,
|
@@ -4785,11 +4886,11 @@ var PerpetualsClient = (function () {
|
|
4785
4886
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
4786
4887
|
.instruction()];
|
4787
4888
|
case 6:
|
4788
|
-
removeCompoundingLiquidity =
|
4889
|
+
removeCompoundingLiquidity = _f.sent();
|
4789
4890
|
instructions.push(removeCompoundingLiquidity);
|
4790
4891
|
return [3, 8];
|
4791
4892
|
case 7:
|
4792
|
-
err_19 =
|
4893
|
+
err_19 = _f.sent();
|
4793
4894
|
console.log("perpClient removeCompoundingLiquidity error:: ", err_19);
|
4794
4895
|
return [3, 8];
|
4795
4896
|
case 8: return [2, {
|
@@ -4800,12 +4901,16 @@ var PerpetualsClient = (function () {
|
|
4800
4901
|
});
|
4801
4902
|
});
|
4802
4903
|
};
|
4803
|
-
this.migrateStake = function (
|
4804
|
-
|
4805
|
-
|
4806
|
-
|
4807
|
-
|
4808
|
-
|
4904
|
+
this.migrateStake = function (amount_1, rewardTokenMint_1, poolConfig_1) {
|
4905
|
+
var args_1 = [];
|
4906
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
4907
|
+
args_1[_i - 3] = arguments[_i];
|
4908
|
+
}
|
4909
|
+
return __awaiter(_this, __spreadArray([amount_1, rewardTokenMint_1, poolConfig_1], args_1, true), void 0, function (amount, rewardTokenMint, poolConfig, createUserATA) {
|
4910
|
+
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_20;
|
4911
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
4912
|
+
return __generator(this, function (_g) {
|
4913
|
+
switch (_g.label) {
|
4809
4914
|
case 0:
|
4810
4915
|
publicKey = this.provider.wallet.publicKey;
|
4811
4916
|
preInstructions = [];
|
@@ -4820,8 +4925,8 @@ var PerpetualsClient = (function () {
|
|
4820
4925
|
if (!_a) return [3, 2];
|
4821
4926
|
return [4, (0, utils_1.checkIfAccountExists)(compoudingTokenAccount, this.provider.connection)];
|
4822
4927
|
case 1:
|
4823
|
-
_a = !(
|
4824
|
-
|
4928
|
+
_a = !(_g.sent());
|
4929
|
+
_g.label = 2;
|
4825
4930
|
case 2:
|
4826
4931
|
if (_a) {
|
4827
4932
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, compoudingTokenAccount, publicKey, compoundingTokenMint));
|
@@ -4833,8 +4938,8 @@ var PerpetualsClient = (function () {
|
|
4833
4938
|
if (!_b) return [3, 4];
|
4834
4939
|
return [4, (0, utils_1.checkIfAccountExists)(tokenStakeAccount, this.provider.connection)];
|
4835
4940
|
case 3:
|
4836
|
-
_b = (
|
4837
|
-
|
4941
|
+
_b = (_g.sent());
|
4942
|
+
_g.label = 4;
|
4838
4943
|
case 4:
|
4839
4944
|
if (_b) {
|
4840
4945
|
tokenStakeAccounts.push({
|
@@ -4847,8 +4952,8 @@ var PerpetualsClient = (function () {
|
|
4847
4952
|
custodyAccountMetas = [];
|
4848
4953
|
custodyOracleAccountMetas = [];
|
4849
4954
|
markets = [];
|
4850
|
-
for (
|
4851
|
-
custody = _c
|
4955
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
4956
|
+
custody = _d[_c];
|
4852
4957
|
custodyAccountMetas.push({
|
4853
4958
|
pubkey: custody.custodyAccount,
|
4854
4959
|
isSigner: false,
|
@@ -4860,17 +4965,17 @@ var PerpetualsClient = (function () {
|
|
4860
4965
|
isWritable: false,
|
4861
4966
|
});
|
4862
4967
|
}
|
4863
|
-
for (
|
4864
|
-
market = _e
|
4968
|
+
for (_e = 0, _f = poolConfig.markets; _e < _f.length; _e++) {
|
4969
|
+
market = _f[_e];
|
4865
4970
|
markets.push({
|
4866
4971
|
pubkey: market.marketAccount,
|
4867
4972
|
isSigner: false,
|
4868
4973
|
isWritable: false,
|
4869
4974
|
});
|
4870
4975
|
}
|
4871
|
-
|
4976
|
+
_g.label = 5;
|
4872
4977
|
case 5:
|
4873
|
-
|
4978
|
+
_g.trys.push([5, 7, , 8]);
|
4874
4979
|
return [4, this.program.methods
|
4875
4980
|
.migrateStake({
|
4876
4981
|
amount: amount
|
@@ -4896,11 +5001,11 @@ var PerpetualsClient = (function () {
|
|
4896
5001
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true), tokenStakeAccounts, true))
|
4897
5002
|
.instruction()];
|
4898
5003
|
case 6:
|
4899
|
-
migrateStake =
|
5004
|
+
migrateStake = _g.sent();
|
4900
5005
|
instructions.push(migrateStake);
|
4901
5006
|
return [3, 8];
|
4902
5007
|
case 7:
|
4903
|
-
err_20 =
|
5008
|
+
err_20 = _g.sent();
|
4904
5009
|
console.log("perpClient migrateStake error:: ", err_20);
|
4905
5010
|
return [3, 8];
|
4906
5011
|
case 8: return [2, {
|
@@ -4994,12 +5099,16 @@ var PerpetualsClient = (function () {
|
|
4994
5099
|
}
|
4995
5100
|
});
|
4996
5101
|
}); };
|
4997
|
-
this.compoundingFee = function (
|
4998
|
-
|
4999
|
-
|
5000
|
-
|
5001
|
-
|
5002
|
-
|
5102
|
+
this.compoundingFee = function (poolConfig_1) {
|
5103
|
+
var args_1 = [];
|
5104
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
5105
|
+
args_1[_i - 1] = arguments[_i];
|
5106
|
+
}
|
5107
|
+
return __awaiter(_this, __spreadArray([poolConfig_1], args_1, true), void 0, function (poolConfig, rewardTokenSymbol) {
|
5108
|
+
var instructions, additionalSigners, rewardCustody, lpTokenMint, custodyAccountMetas, custodyOracleAccountMetas, markets, _a, _b, custody, _c, _d, market, compoundingFee, err_22;
|
5109
|
+
if (rewardTokenSymbol === void 0) { rewardTokenSymbol = 'USDC'; }
|
5110
|
+
return __generator(this, function (_e) {
|
5111
|
+
switch (_e.label) {
|
5003
5112
|
case 0:
|
5004
5113
|
instructions = [];
|
5005
5114
|
additionalSigners = [];
|
@@ -5008,8 +5117,8 @@ var PerpetualsClient = (function () {
|
|
5008
5117
|
custodyAccountMetas = [];
|
5009
5118
|
custodyOracleAccountMetas = [];
|
5010
5119
|
markets = [];
|
5011
|
-
for (
|
5012
|
-
custody = _a
|
5120
|
+
for (_a = 0, _b = poolConfig.custodies; _a < _b.length; _a++) {
|
5121
|
+
custody = _b[_a];
|
5013
5122
|
custodyAccountMetas.push({
|
5014
5123
|
pubkey: custody.custodyAccount,
|
5015
5124
|
isSigner: false,
|
@@ -5021,17 +5130,17 @@ var PerpetualsClient = (function () {
|
|
5021
5130
|
isWritable: false,
|
5022
5131
|
});
|
5023
5132
|
}
|
5024
|
-
for (
|
5025
|
-
market = _c
|
5133
|
+
for (_c = 0, _d = poolConfig.markets; _c < _d.length; _c++) {
|
5134
|
+
market = _d[_c];
|
5026
5135
|
markets.push({
|
5027
5136
|
pubkey: market.marketAccount,
|
5028
5137
|
isSigner: false,
|
5029
5138
|
isWritable: false,
|
5030
5139
|
});
|
5031
5140
|
}
|
5032
|
-
|
5141
|
+
_e.label = 1;
|
5033
5142
|
case 1:
|
5034
|
-
|
5143
|
+
_e.trys.push([1, 3, , 4]);
|
5035
5144
|
return [4, this.program.methods
|
5036
5145
|
.compoundFees({})
|
5037
5146
|
.accounts({
|
@@ -5050,11 +5159,11 @@ var PerpetualsClient = (function () {
|
|
5050
5159
|
.remainingAccounts(__spreadArray(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true), markets, true))
|
5051
5160
|
.instruction()];
|
5052
5161
|
case 2:
|
5053
|
-
compoundingFee =
|
5162
|
+
compoundingFee = _e.sent();
|
5054
5163
|
instructions.push(compoundingFee);
|
5055
5164
|
return [3, 4];
|
5056
5165
|
case 3:
|
5057
|
-
err_22 =
|
5166
|
+
err_22 = _e.sent();
|
5058
5167
|
console.log("perpClient compoundingFee error:: ", err_22);
|
5059
5168
|
return [3, 4];
|
5060
5169
|
case 4: return [2, {
|
@@ -5122,7 +5231,8 @@ var PerpetualsClient = (function () {
|
|
5122
5231
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5123
5232
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
5124
5233
|
eventAuthority: this.eventAuthority.publicKey,
|
5125
|
-
program: this.programId
|
5234
|
+
program: this.programId,
|
5235
|
+
receivingTokenMint: poolConfig.tokenMint,
|
5126
5236
|
})
|
5127
5237
|
.instruction()];
|
5128
5238
|
case 6:
|
@@ -5236,7 +5346,8 @@ var PerpetualsClient = (function () {
|
|
5236
5346
|
systemProgram: web3_js_1.SystemProgram.programId,
|
5237
5347
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5238
5348
|
eventAuthority: this.eventAuthority.publicKey,
|
5239
|
-
program: this.programId
|
5349
|
+
program: this.programId,
|
5350
|
+
tokenMint: poolConfig.tokenMint,
|
5240
5351
|
})
|
5241
5352
|
.instruction()];
|
5242
5353
|
case 3:
|
@@ -5436,10 +5547,14 @@ var PerpetualsClient = (function () {
|
|
5436
5547
|
}
|
5437
5548
|
});
|
5438
5549
|
}); };
|
5439
|
-
this.collectTokenReward = function (
|
5440
|
-
|
5441
|
-
|
5550
|
+
this.collectTokenReward = function (owner_1, poolConfig_1) {
|
5551
|
+
var args_1 = [];
|
5552
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5553
|
+
args_1[_i - 2] = arguments[_i];
|
5554
|
+
}
|
5555
|
+
return __awaiter(_this, __spreadArray([owner_1, poolConfig_1], args_1, true), void 0, function (owner, poolConfig, createUserATA) {
|
5442
5556
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, tokenStakeAccount, userTokenAccount, _a, collectTokenRewardInstruction, err_30;
|
5557
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5443
5558
|
return __generator(this, function (_b) {
|
5444
5559
|
switch (_b.label) {
|
5445
5560
|
case 0:
|
@@ -5475,7 +5590,8 @@ var PerpetualsClient = (function () {
|
|
5475
5590
|
tokenStakeAccount: tokenStakeAccount,
|
5476
5591
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5477
5592
|
eventAuthority: this.eventAuthority.publicKey,
|
5478
|
-
program: this.programId
|
5593
|
+
program: this.programId,
|
5594
|
+
tokenMint: poolConfig.tokenMint,
|
5479
5595
|
})
|
5480
5596
|
.instruction()];
|
5481
5597
|
case 4:
|
@@ -5494,10 +5610,14 @@ var PerpetualsClient = (function () {
|
|
5494
5610
|
});
|
5495
5611
|
});
|
5496
5612
|
};
|
5497
|
-
this.collectRevenue = function (
|
5498
|
-
|
5499
|
-
|
5613
|
+
this.collectRevenue = function (owner_1, rewardSymbol_1, poolConfig_1) {
|
5614
|
+
var args_1 = [];
|
5615
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5616
|
+
args_1[_i - 3] = arguments[_i];
|
5617
|
+
}
|
5618
|
+
return __awaiter(_this, __spreadArray([owner_1, rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (owner, rewardSymbol, poolConfig, createUserATA) {
|
5500
5619
|
var publicKey, preInstructions, instructions, postInstructions, additionalSigners, rewardCustodyMint, tokenStakeAccount, userTokenAccount, _a, collectRevenueInstruction, err_31;
|
5620
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5501
5621
|
return __generator(this, function (_b) {
|
5502
5622
|
switch (_b.label) {
|
5503
5623
|
case 0:
|
@@ -5534,7 +5654,8 @@ var PerpetualsClient = (function () {
|
|
5534
5654
|
tokenStakeAccount: tokenStakeAccount,
|
5535
5655
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
5536
5656
|
eventAuthority: this.eventAuthority.publicKey,
|
5537
|
-
program: this.programId
|
5657
|
+
program: this.programId,
|
5658
|
+
receivingTokenMint: rewardCustodyMint,
|
5538
5659
|
})
|
5539
5660
|
.instruction()];
|
5540
5661
|
case 4:
|
@@ -5643,10 +5764,14 @@ var PerpetualsClient = (function () {
|
|
5643
5764
|
}
|
5644
5765
|
});
|
5645
5766
|
}); };
|
5646
|
-
this.collectNftReward = function (
|
5647
|
-
|
5648
|
-
|
5767
|
+
this.collectNftReward = function (rewardSymbol_1, poolConfig_1, nftMint_1) {
|
5768
|
+
var args_1 = [];
|
5769
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
5770
|
+
args_1[_i - 3] = arguments[_i];
|
5771
|
+
}
|
5772
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1, nftMint_1], args_1, true), void 0, function (rewardSymbol, poolConfig, nftMint, createUserATA) {
|
5649
5773
|
var publicKey, rewardToken, rewardCustodyMint, instructions, additionalSigners, nftTokenAccount, metadataAccount, receivingTokenAccount, _a, rewardRecord, rewardVault, rewardTokenAccount, nftTransferAuthority, collectNftReward, err_34;
|
5774
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5650
5775
|
return __generator(this, function (_b) {
|
5651
5776
|
switch (_b.label) {
|
5652
5777
|
case 0:
|
@@ -5707,10 +5832,14 @@ var PerpetualsClient = (function () {
|
|
5707
5832
|
});
|
5708
5833
|
});
|
5709
5834
|
};
|
5710
|
-
this.collectAndDistributeFee = function (
|
5711
|
-
|
5712
|
-
|
5835
|
+
this.collectAndDistributeFee = function (rewardSymbol_1, poolConfig_1) {
|
5836
|
+
var args_1 = [];
|
5837
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
5838
|
+
args_1[_i - 2] = arguments[_i];
|
5839
|
+
}
|
5840
|
+
return __awaiter(_this, __spreadArray([rewardSymbol_1, poolConfig_1], args_1, true), void 0, function (rewardSymbol, poolConfig, createUserATA, nftTradingAccount) {
|
5713
5841
|
var publicKey, rewardToken, rewardCustodyMint, rewardCustodyConfig, preInstructions, instructions, postInstructions, additionalSigners, pool, flpStakeAccount, receivingTokenAccount, _a, tradingAccount, rewardVault, rewardTokenAccount, withdrawStakeInstruction, err_35;
|
5842
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5714
5843
|
return __generator(this, function (_b) {
|
5715
5844
|
switch (_b.label) {
|
5716
5845
|
case 0:
|
@@ -5836,12 +5965,16 @@ var PerpetualsClient = (function () {
|
|
5836
5965
|
}
|
5837
5966
|
});
|
5838
5967
|
}); };
|
5839
|
-
this.forceClosePosition = function (
|
5840
|
-
|
5841
|
-
|
5842
|
-
|
5843
|
-
|
5968
|
+
this.forceClosePosition = function (positionAccount_2, targetSymbol_1, collateralSymbol_1, side_1, isStopLoss_1, poolConfig_1) {
|
5969
|
+
var args_1 = [];
|
5970
|
+
for (var _i = 6; _i < arguments.length; _i++) {
|
5971
|
+
args_1[_i - 6] = arguments[_i];
|
5972
|
+
}
|
5973
|
+
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) {
|
5844
5974
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, forceClosePosition, closeWsolATAIns, err_37;
|
5975
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
5976
|
+
if (closeUsersWSOLATA === void 0) { closeUsersWSOLATA = false; }
|
5977
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5845
5978
|
return __generator(this, function (_b) {
|
5846
5979
|
switch (_b.label) {
|
5847
5980
|
case 0:
|
@@ -5912,11 +6045,15 @@ var PerpetualsClient = (function () {
|
|
5912
6045
|
});
|
5913
6046
|
});
|
5914
6047
|
};
|
5915
|
-
this.placeLimitOrder = function (
|
5916
|
-
|
5917
|
-
|
5918
|
-
|
6048
|
+
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) {
|
6049
|
+
var args_1 = [];
|
6050
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6051
|
+
args_1[_i - 11] = arguments[_i];
|
6052
|
+
}
|
6053
|
+
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) {
|
5919
6054
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, userReserveTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, accCreationLamports, lamports, unWrappedSolBalance, _a, tokenAccountBalance, _b, positionAccount, orderAccount, placeLimitOrder, err_38;
|
6055
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6056
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
5920
6057
|
return __generator(this, function (_c) {
|
5921
6058
|
switch (_c.label) {
|
5922
6059
|
case 0:
|
@@ -6031,11 +6168,15 @@ var PerpetualsClient = (function () {
|
|
6031
6168
|
});
|
6032
6169
|
});
|
6033
6170
|
};
|
6034
|
-
this.editLimitOrder = function (
|
6035
|
-
|
6036
|
-
|
6037
|
-
|
6171
|
+
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) {
|
6172
|
+
var args_1 = [];
|
6173
|
+
for (var _i = 11; _i < arguments.length; _i++) {
|
6174
|
+
args_1[_i - 11] = arguments[_i];
|
6175
|
+
}
|
6176
|
+
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) {
|
6038
6177
|
var publicKey, targetCustodyConfig, reserveCustodyConfig, collateralCustodyConfig, receiveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, wrappedSolAccount, userReceivingTokenAccount, lamports, _a, positionAccount, orderAccount, editLimitOrder, err_39;
|
6178
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6179
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6039
6180
|
return __generator(this, function (_b) {
|
6040
6181
|
switch (_b.label) {
|
6041
6182
|
case 0:
|
@@ -6116,6 +6257,7 @@ var PerpetualsClient = (function () {
|
|
6116
6257
|
eventAuthority: this.eventAuthority.publicKey,
|
6117
6258
|
program: this.programId,
|
6118
6259
|
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6260
|
+
receivingMint: poolConfig.getTokenFromSymbol(reserveSymbol).mintKey
|
6119
6261
|
})
|
6120
6262
|
.instruction()];
|
6121
6263
|
case 6:
|
@@ -6134,12 +6276,16 @@ var PerpetualsClient = (function () {
|
|
6134
6276
|
});
|
6135
6277
|
});
|
6136
6278
|
};
|
6137
|
-
this.executeLimitOrder = function (
|
6138
|
-
|
6139
|
-
|
6140
|
-
|
6141
|
-
|
6279
|
+
this.executeLimitOrder = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6280
|
+
var args_1 = [];
|
6281
|
+
for (var _i = 7; _i < arguments.length; _i++) {
|
6282
|
+
args_1[_i - 7] = arguments[_i];
|
6283
|
+
}
|
6284
|
+
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) {
|
6142
6285
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitOrder, err_40;
|
6286
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6287
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6288
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6143
6289
|
return __generator(this, function (_a) {
|
6144
6290
|
switch (_a.label) {
|
6145
6291
|
case 0:
|
@@ -6199,12 +6345,16 @@ var PerpetualsClient = (function () {
|
|
6199
6345
|
});
|
6200
6346
|
});
|
6201
6347
|
};
|
6202
|
-
this.executeLimitWithSwap = function (
|
6203
|
-
|
6204
|
-
|
6205
|
-
|
6206
|
-
|
6348
|
+
this.executeLimitWithSwap = function (userPubkey_1, targetSymbol_1, collateralSymbol_1, reserveSymbol_1, side_1, orderId_1, poolConfig_1, privilege_1) {
|
6349
|
+
var args_1 = [];
|
6350
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6351
|
+
args_1[_i - 8] = arguments[_i];
|
6352
|
+
}
|
6353
|
+
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) {
|
6207
6354
|
var publicKey, targetCustodyConfig, collateralCustodyConfig, reserveCustodyConfig, marketAccount, preInstructions, instructions, postInstructions, additionalSigners, positionAccount, orderAccount, executeLimitWithSwap, err_41;
|
6355
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6356
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6357
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6208
6358
|
return __generator(this, function (_a) {
|
6209
6359
|
switch (_a.label) {
|
6210
6360
|
case 0:
|
@@ -6247,7 +6397,8 @@ var PerpetualsClient = (function () {
|
|
6247
6397
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
6248
6398
|
eventAuthority: this.eventAuthority.publicKey,
|
6249
6399
|
program: this.programId,
|
6250
|
-
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY
|
6400
|
+
ixSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
6401
|
+
collateralMint: collateralCustodyConfig.mintKey,
|
6251
6402
|
})
|
6252
6403
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6253
6404
|
.instruction()];
|
@@ -6470,16 +6621,20 @@ var PerpetualsClient = (function () {
|
|
6470
6621
|
}
|
6471
6622
|
});
|
6472
6623
|
}); };
|
6473
|
-
this.executeTriggerWithSwap = function (
|
6474
|
-
|
6475
|
-
|
6476
|
-
|
6477
|
-
|
6478
|
-
|
6479
|
-
|
6480
|
-
|
6481
|
-
|
6482
|
-
|
6624
|
+
this.executeTriggerWithSwap = function (owner_1, targetSymbol_1, collateralSymbol_1, receivingSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6625
|
+
var args_1 = [];
|
6626
|
+
for (var _i = 9; _i < arguments.length; _i++) {
|
6627
|
+
args_1[_i - 9] = arguments[_i];
|
6628
|
+
}
|
6629
|
+
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) {
|
6630
|
+
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, receivingCustodyConfig, marketAccount, userReceivingTokenAccount, userReceivingTokenAccountCollateral, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, collateralToken, receivingToken, _a, _b, positionAccount, orderAccount, custodyAccountMetas, custodyOracleAccountMetas, _c, _d, custody, executeTriggerWithSwap, err_46;
|
6631
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6632
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6633
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6634
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6635
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6636
|
+
return __generator(this, function (_e) {
|
6637
|
+
switch (_e.label) {
|
6483
6638
|
case 0:
|
6484
6639
|
payerPubkey = this.provider.wallet.publicKey;
|
6485
6640
|
targetCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(targetSymbol).mintKey); });
|
@@ -6492,9 +6647,9 @@ var PerpetualsClient = (function () {
|
|
6492
6647
|
additionalSigners = [];
|
6493
6648
|
collateralToken = poolConfig.getTokenFromSymbol(collateralSymbol);
|
6494
6649
|
receivingToken = poolConfig.getTokenFromSymbol(receivingSymbol);
|
6495
|
-
|
6650
|
+
_e.label = 1;
|
6496
6651
|
case 1:
|
6497
|
-
|
6652
|
+
_e.trys.push([1, 9, , 10]);
|
6498
6653
|
if (!false) return [3, 2];
|
6499
6654
|
return [3, 7];
|
6500
6655
|
case 2:
|
@@ -6503,8 +6658,8 @@ var PerpetualsClient = (function () {
|
|
6503
6658
|
if (!_a) return [3, 4];
|
6504
6659
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccount, this.provider.connection)];
|
6505
6660
|
case 3:
|
6506
|
-
_a = !(
|
6507
|
-
|
6661
|
+
_a = !(_e.sent());
|
6662
|
+
_e.label = 4;
|
6508
6663
|
case 4:
|
6509
6664
|
if (_a) {
|
6510
6665
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccount, owner, poolConfig.getTokenFromSymbol(receivingSymbol).mintKey));
|
@@ -6514,20 +6669,20 @@ var PerpetualsClient = (function () {
|
|
6514
6669
|
if (!_b) return [3, 6];
|
6515
6670
|
return [4, (0, utils_1.checkIfAccountExists)(userReceivingTokenAccountCollateral, this.provider.connection)];
|
6516
6671
|
case 5:
|
6517
|
-
_b = !(
|
6518
|
-
|
6672
|
+
_b = !(_e.sent());
|
6673
|
+
_e.label = 6;
|
6519
6674
|
case 6:
|
6520
6675
|
if (_b) {
|
6521
6676
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(payerPubkey, userReceivingTokenAccountCollateral, owner, poolConfig.getTokenFromSymbol(collateralSymbol).mintKey));
|
6522
6677
|
}
|
6523
|
-
|
6678
|
+
_e.label = 7;
|
6524
6679
|
case 7:
|
6525
6680
|
positionAccount = poolConfig.getPositionFromMarketPk(owner, marketAccount);
|
6526
6681
|
orderAccount = poolConfig.getOrderFromMarketPk(owner, marketAccount);
|
6527
6682
|
custodyAccountMetas = [];
|
6528
6683
|
custodyOracleAccountMetas = [];
|
6529
|
-
for (
|
6530
|
-
custody = _c
|
6684
|
+
for (_c = 0, _d = poolConfig.custodies; _c < _d.length; _c++) {
|
6685
|
+
custody = _d[_c];
|
6531
6686
|
custodyAccountMetas.push({
|
6532
6687
|
pubkey: custody.custodyAccount,
|
6533
6688
|
isSigner: false,
|
@@ -6575,11 +6730,11 @@ var PerpetualsClient = (function () {
|
|
6575
6730
|
.remainingAccounts(__spreadArray([], (0, getReferralAccounts_1.getReferralAccounts)(tokenStakeAccount, userReferralAccount, rebateTokenAccount, privilege), true))
|
6576
6731
|
.instruction()];
|
6577
6732
|
case 8:
|
6578
|
-
executeTriggerWithSwap =
|
6733
|
+
executeTriggerWithSwap = _e.sent();
|
6579
6734
|
instructions.push(executeTriggerWithSwap);
|
6580
6735
|
return [3, 10];
|
6581
6736
|
case 9:
|
6582
|
-
err_46 =
|
6737
|
+
err_46 = _e.sent();
|
6583
6738
|
console.log("perpClient executeTriggerWithSwap error:: ", err_46);
|
6584
6739
|
throw err_46;
|
6585
6740
|
case 10: return [2, {
|
@@ -6590,14 +6745,18 @@ var PerpetualsClient = (function () {
|
|
6590
6745
|
});
|
6591
6746
|
});
|
6592
6747
|
};
|
6593
|
-
this.executeTriggerOrder = function (
|
6594
|
-
|
6595
|
-
|
6596
|
-
|
6597
|
-
|
6598
|
-
|
6599
|
-
return __awaiter(_this, void 0, void 0, function () {
|
6748
|
+
this.executeTriggerOrder = function (owner_1, targetSymbol_1, collateralSymbol_1, side_1, orderId_1, isStopLoss_1, privilege_1, poolConfig_1) {
|
6749
|
+
var args_1 = [];
|
6750
|
+
for (var _i = 8; _i < arguments.length; _i++) {
|
6751
|
+
args_1[_i - 8] = arguments[_i];
|
6752
|
+
}
|
6753
|
+
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) {
|
6600
6754
|
var payerPubkey, targetCustodyConfig, collateralCustodyConfig, marketAccount, userReceivingTokenAccount, wrappedSolAccount, preInstructions, instructions, postInstructions, additionalSigners, _a, positionAccount, orderAccount, executeTriggerOrder, err_47;
|
6755
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6756
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6757
|
+
if (tokenStakeAccount === void 0) { tokenStakeAccount = web3_js_1.PublicKey.default; }
|
6758
|
+
if (userReferralAccount === void 0) { userReferralAccount = web3_js_1.PublicKey.default; }
|
6759
|
+
if (rebateTokenAccount === void 0) { rebateTokenAccount = web3_js_1.PublicKey.default; }
|
6601
6760
|
return __generator(this, function (_b) {
|
6602
6761
|
switch (_b.label) {
|
6603
6762
|
case 0:
|
@@ -6716,16 +6875,20 @@ var PerpetualsClient = (function () {
|
|
6716
6875
|
}
|
6717
6876
|
});
|
6718
6877
|
}); };
|
6719
|
-
this.swap = function (
|
6720
|
-
|
6721
|
-
|
6722
|
-
|
6723
|
-
|
6724
|
-
|
6725
|
-
|
6726
|
-
|
6727
|
-
|
6728
|
-
|
6878
|
+
this.swap = function (userInputTokenSymbol_1, userOutputTokenSymbol_1, amountIn_1, minAmountOut_1, poolConfig_1) {
|
6879
|
+
var args_1 = [];
|
6880
|
+
for (var _i = 5; _i < arguments.length; _i++) {
|
6881
|
+
args_1[_i - 5] = arguments[_i];
|
6882
|
+
}
|
6883
|
+
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) {
|
6884
|
+
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_49;
|
6885
|
+
if (useFeesPool === void 0) { useFeesPool = false; }
|
6886
|
+
if (createUserATA === void 0) { createUserATA = true; }
|
6887
|
+
if (unWrapSol === void 0) { unWrapSol = false; }
|
6888
|
+
if (skipBalanceChecks === void 0) { skipBalanceChecks = false; }
|
6889
|
+
if (ephemeralSignerPubkey === void 0) { ephemeralSignerPubkey = undefined; }
|
6890
|
+
return __generator(this, function (_g) {
|
6891
|
+
switch (_g.label) {
|
6729
6892
|
case 0:
|
6730
6893
|
userInputCustodyConfig = poolConfig.custodies.find(function (i) { return i.mintKey.equals(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey); });
|
6731
6894
|
if (!userInputCustodyConfig) {
|
@@ -6743,10 +6906,10 @@ var PerpetualsClient = (function () {
|
|
6743
6906
|
if (!(userInputTokenSymbol == 'SOL' && userOutputTokenSymbol == 'WSOL')) return [3, 5];
|
6744
6907
|
return [4, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, publicKey, true)];
|
6745
6908
|
case 1:
|
6746
|
-
wsolAssociatedTokenAccount =
|
6909
|
+
wsolAssociatedTokenAccount = _g.sent();
|
6747
6910
|
return [4, (0, utils_1.checkIfAccountExists)(wsolAssociatedTokenAccount, this.provider.connection)];
|
6748
6911
|
case 2:
|
6749
|
-
wsolATAExist =
|
6912
|
+
wsolATAExist = _g.sent();
|
6750
6913
|
if (!wsolATAExist) {
|
6751
6914
|
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, wsolAssociatedTokenAccount, publicKey, spl_token_1.NATIVE_MINT));
|
6752
6915
|
}
|
@@ -6754,11 +6917,11 @@ var PerpetualsClient = (function () {
|
|
6754
6917
|
_a = anchor_1.BN.bind;
|
6755
6918
|
return [4, this.provider.connection.getBalance(publicKey)];
|
6756
6919
|
case 3:
|
6757
|
-
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0,
|
6920
|
+
unWrappedSolBalance = new (_a.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6758
6921
|
if (unWrappedSolBalance.lt(amountIn)) {
|
6759
6922
|
throw "Insufficient SOL Funds";
|
6760
6923
|
}
|
6761
|
-
|
6924
|
+
_g.label = 4;
|
6762
6925
|
case 4:
|
6763
6926
|
instructions.push(web3_js_1.SystemProgram.transfer({
|
6764
6927
|
fromPubkey: publicKey,
|
@@ -6780,20 +6943,20 @@ var PerpetualsClient = (function () {
|
|
6780
6943
|
additionalSigners: additionalSigners
|
6781
6944
|
}];
|
6782
6945
|
}
|
6783
|
-
|
6946
|
+
_g.label = 6;
|
6784
6947
|
case 6:
|
6785
|
-
|
6948
|
+
_g.trys.push([6, 19, , 20]);
|
6786
6949
|
if (!(userInputTokenSymbol == 'SOL')) return [3, 9];
|
6787
6950
|
console.log("userInputTokenSymbol === sol", userInputTokenSymbol);
|
6788
6951
|
return [4, (0, spl_token_1.getMinimumBalanceForRentExemptAccount)(this.provider.connection)];
|
6789
6952
|
case 7:
|
6790
|
-
accCreationLamports = (
|
6953
|
+
accCreationLamports = (_g.sent());
|
6791
6954
|
console.log("accCreationLamports:", accCreationLamports);
|
6792
6955
|
lamports = amountIn.add(new anchor_1.BN(accCreationLamports));
|
6793
6956
|
_b = anchor_1.BN.bind;
|
6794
6957
|
return [4, this.provider.connection.getBalance(publicKey)];
|
6795
6958
|
case 8:
|
6796
|
-
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0,
|
6959
|
+
unWrappedSolBalance = new (_b.apply(anchor_1.BN, [void 0, _g.sent()]))();
|
6797
6960
|
if (unWrappedSolBalance.lt(amountIn)) {
|
6798
6961
|
throw "Insufficient SOL Funds";
|
6799
6962
|
}
|
@@ -6820,18 +6983,18 @@ var PerpetualsClient = (function () {
|
|
6820
6983
|
userInputTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(poolConfig.getTokenFromSymbol(userInputTokenSymbol).mintKey, publicKey, true);
|
6821
6984
|
return [4, (0, utils_1.checkIfAccountExists)(userInputTokenAccount, this.provider.connection)];
|
6822
6985
|
case 10:
|
6823
|
-
if (!(
|
6986
|
+
if (!(_g.sent())) {
|
6824
6987
|
throw "Insufficient Funds , Token Account doesn't exist";
|
6825
6988
|
}
|
6826
6989
|
if (!!skipBalanceChecks) return [3, 12];
|
6827
6990
|
_c = anchor_1.BN.bind;
|
6828
6991
|
return [4, this.provider.connection.getTokenAccountBalance(userInputTokenAccount)];
|
6829
6992
|
case 11:
|
6830
|
-
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (
|
6993
|
+
tokenAccountBalance = new (_c.apply(anchor_1.BN, [void 0, (_g.sent()).value.amount]))();
|
6831
6994
|
if (tokenAccountBalance.lt(amountIn)) {
|
6832
6995
|
throw "Insufficient Funds need more ".concat(amountIn.sub(tokenAccountBalance), " tokens");
|
6833
6996
|
}
|
6834
|
-
|
6997
|
+
_g.label = 12;
|
6835
6998
|
case 12:
|
6836
6999
|
if (!(userOutputTokenSymbol == 'SOL')) return [3, 13];
|
6837
7000
|
lamports = (this.minimumBalanceForRentExemptAccountLamports);
|
@@ -6856,23 +7019,23 @@ var PerpetualsClient = (function () {
|
|
6856
7019
|
return [3, 17];
|
6857
7020
|
case 13: return [4, (0, spl_token_1.getAssociatedTokenAddress)(poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey, publicKey, true)];
|
6858
7021
|
case 14:
|
6859
|
-
userOutputTokenAccount =
|
7022
|
+
userOutputTokenAccount = _g.sent();
|
6860
7023
|
_d = createUserATA;
|
6861
7024
|
if (!_d) return [3, 16];
|
6862
7025
|
return [4, (0, utils_1.checkIfAccountExists)(userOutputTokenAccount, this.provider.connection)];
|
6863
7026
|
case 15:
|
6864
|
-
_d = !(
|
6865
|
-
|
7027
|
+
_d = !(_g.sent());
|
7028
|
+
_g.label = 16;
|
6866
7029
|
case 16:
|
6867
7030
|
if (_d) {
|
6868
7031
|
preInstructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(publicKey, userOutputTokenAccount, publicKey, poolConfig.getTokenFromSymbol(userOutputTokenSymbol).mintKey));
|
6869
7032
|
}
|
6870
|
-
|
7033
|
+
_g.label = 17;
|
6871
7034
|
case 17:
|
6872
7035
|
custodyAccountMetas = [];
|
6873
7036
|
custodyOracleAccountMetas = [];
|
6874
|
-
for (
|
6875
|
-
custody = _e
|
7037
|
+
for (_e = 0, _f = poolConfig.custodies; _e < _f.length; _e++) {
|
7038
|
+
custody = _f[_e];
|
6876
7039
|
custodyAccountMetas.push({
|
6877
7040
|
pubkey: custody.custodyAccount,
|
6878
7041
|
isSigner: false,
|
@@ -6915,7 +7078,7 @@ var PerpetualsClient = (function () {
|
|
6915
7078
|
.remainingAccounts(__spreadArray(__spreadArray([], custodyAccountMetas, true), custodyOracleAccountMetas, true))
|
6916
7079
|
.instruction()];
|
6917
7080
|
case 18:
|
6918
|
-
inx =
|
7081
|
+
inx = _g.sent();
|
6919
7082
|
instructions.push(inx);
|
6920
7083
|
if (userOutputTokenSymbol == 'SOL' && unWrapSol) {
|
6921
7084
|
closeWsolATAIns = (0, spl_token_1.createCloseAccountInstruction)(userOutputTokenAccount, publicKey, publicKey);
|
@@ -6923,7 +7086,7 @@ var PerpetualsClient = (function () {
|
|
6923
7086
|
}
|
6924
7087
|
return [3, 20];
|
6925
7088
|
case 19:
|
6926
|
-
err_49 =
|
7089
|
+
err_49 = _g.sent();
|
6927
7090
|
console.error("perpClient Swap error:: ", err_49);
|
6928
7091
|
throw err_49;
|
6929
7092
|
case 20: return [2, {
|
@@ -8032,7 +8195,8 @@ var PerpetualsClient = (function () {
|
|
8032
8195
|
tokenVaultTokenAccount: poolConfig.tokenVaultTokenAccount,
|
8033
8196
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
8034
8197
|
eventAuthority: this.eventAuthority.publicKey,
|
8035
|
-
program: this.programId
|
8198
|
+
program: this.programId,
|
8199
|
+
tokenMint: poolConfig.tokenMint,
|
8036
8200
|
})
|
8037
8201
|
.instruction()];
|
8038
8202
|
case 2:
|
@@ -8233,9 +8397,9 @@ var PerpetualsClient = (function () {
|
|
8233
8397
|
}
|
8234
8398
|
}
|
8235
8399
|
};
|
8236
|
-
PerpetualsClient.prototype.sendTransaction = function (
|
8237
|
-
|
8238
|
-
|
8400
|
+
PerpetualsClient.prototype.sendTransaction = function (ixs_1) {
|
8401
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8402
|
+
if (opts === void 0) { opts = {}; }
|
8239
8403
|
return __generator(this, function (_a) {
|
8240
8404
|
switch (_a.label) {
|
8241
8405
|
case 0: return [4, (0, rpc_1.sendTransaction)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|
@@ -8244,9 +8408,9 @@ var PerpetualsClient = (function () {
|
|
8244
8408
|
});
|
8245
8409
|
});
|
8246
8410
|
};
|
8247
|
-
PerpetualsClient.prototype.sendTransactionV3 = function (
|
8248
|
-
|
8249
|
-
|
8411
|
+
PerpetualsClient.prototype.sendTransactionV3 = function (ixs_1) {
|
8412
|
+
return __awaiter(this, arguments, void 0, function (ixs, opts) {
|
8413
|
+
if (opts === void 0) { opts = {}; }
|
8250
8414
|
return __generator(this, function (_a) {
|
8251
8415
|
switch (_a.label) {
|
8252
8416
|
case 0: return [4, (0, rpc_1.sendTransactionV3)(this.program.provider, ixs, __assign({ postSendTxCallback: this.postSendTxCallback, prioritizationFee: this.prioritizationFee }, opts))];
|