flash-sdk 2.0.51 → 2.0.52

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.
@@ -1171,7 +1171,8 @@ exports.IDL = {
1171
1171
  "defined": "AddLiquidityParams"
1172
1172
  }
1173
1173
  }
1174
- ]
1174
+ ],
1175
+ "returns": "u64"
1175
1176
  },
1176
1177
  {
1177
1178
  "name": "removeLiquidity",
@@ -1821,6 +1822,79 @@ exports.IDL = {
1821
1822
  }
1822
1823
  ]
1823
1824
  },
1825
+ {
1826
+ "name": "setTriggerPrice",
1827
+ "accounts": [
1828
+ {
1829
+ "name": "owner",
1830
+ "isMut": false,
1831
+ "isSigner": true
1832
+ },
1833
+ {
1834
+ "name": "perpetuals",
1835
+ "isMut": false,
1836
+ "isSigner": false
1837
+ },
1838
+ {
1839
+ "name": "pool",
1840
+ "isMut": false,
1841
+ "isSigner": false
1842
+ },
1843
+ {
1844
+ "name": "position",
1845
+ "isMut": true,
1846
+ "isSigner": false
1847
+ },
1848
+ {
1849
+ "name": "market",
1850
+ "isMut": false,
1851
+ "isSigner": false
1852
+ },
1853
+ {
1854
+ "name": "targetCustody",
1855
+ "isMut": false,
1856
+ "isSigner": false
1857
+ },
1858
+ {
1859
+ "name": "targetOracleAccount",
1860
+ "isMut": false,
1861
+ "isSigner": false
1862
+ },
1863
+ {
1864
+ "name": "collateralCustody",
1865
+ "isMut": false,
1866
+ "isSigner": false
1867
+ },
1868
+ {
1869
+ "name": "collateralOracleAccount",
1870
+ "isMut": false,
1871
+ "isSigner": false
1872
+ },
1873
+ {
1874
+ "name": "eventAuthority",
1875
+ "isMut": false,
1876
+ "isSigner": false
1877
+ },
1878
+ {
1879
+ "name": "program",
1880
+ "isMut": false,
1881
+ "isSigner": false
1882
+ },
1883
+ {
1884
+ "name": "ixSysvar",
1885
+ "isMut": false,
1886
+ "isSigner": false
1887
+ }
1888
+ ],
1889
+ "args": [
1890
+ {
1891
+ "name": "params",
1892
+ "type": {
1893
+ "defined": "SetTriggerPriceParams"
1894
+ }
1895
+ }
1896
+ ]
1897
+ },
1824
1898
  {
1825
1899
  "name": "addCollateral",
1826
1900
  "accounts": [
@@ -2278,6 +2352,100 @@ exports.IDL = {
2278
2352
  ],
2279
2353
  "returns": "u64"
2280
2354
  },
2355
+ {
2356
+ "name": "forceClosePosition",
2357
+ "accounts": [
2358
+ {
2359
+ "name": "owner",
2360
+ "isMut": true,
2361
+ "isSigner": false
2362
+ },
2363
+ {
2364
+ "name": "receivingAccount",
2365
+ "isMut": true,
2366
+ "isSigner": false
2367
+ },
2368
+ {
2369
+ "name": "transferAuthority",
2370
+ "isMut": false,
2371
+ "isSigner": false
2372
+ },
2373
+ {
2374
+ "name": "perpetuals",
2375
+ "isMut": false,
2376
+ "isSigner": false
2377
+ },
2378
+ {
2379
+ "name": "pool",
2380
+ "isMut": false,
2381
+ "isSigner": false
2382
+ },
2383
+ {
2384
+ "name": "position",
2385
+ "isMut": true,
2386
+ "isSigner": false
2387
+ },
2388
+ {
2389
+ "name": "market",
2390
+ "isMut": true,
2391
+ "isSigner": false
2392
+ },
2393
+ {
2394
+ "name": "targetCustody",
2395
+ "isMut": false,
2396
+ "isSigner": false
2397
+ },
2398
+ {
2399
+ "name": "targetOracleAccount",
2400
+ "isMut": false,
2401
+ "isSigner": false
2402
+ },
2403
+ {
2404
+ "name": "collateralCustody",
2405
+ "isMut": true,
2406
+ "isSigner": false
2407
+ },
2408
+ {
2409
+ "name": "collateralOracleAccount",
2410
+ "isMut": false,
2411
+ "isSigner": false
2412
+ },
2413
+ {
2414
+ "name": "collateralCustodyTokenAccount",
2415
+ "isMut": true,
2416
+ "isSigner": false
2417
+ },
2418
+ {
2419
+ "name": "tokenProgram",
2420
+ "isMut": false,
2421
+ "isSigner": false
2422
+ },
2423
+ {
2424
+ "name": "eventAuthority",
2425
+ "isMut": false,
2426
+ "isSigner": false
2427
+ },
2428
+ {
2429
+ "name": "program",
2430
+ "isMut": false,
2431
+ "isSigner": false
2432
+ },
2433
+ {
2434
+ "name": "ixSysvar",
2435
+ "isMut": false,
2436
+ "isSigner": false
2437
+ }
2438
+ ],
2439
+ "args": [
2440
+ {
2441
+ "name": "params",
2442
+ "type": {
2443
+ "defined": "ForceClosePositionParams"
2444
+ }
2445
+ }
2446
+ ],
2447
+ "returns": "u64"
2448
+ },
2281
2449
  {
2282
2450
  "name": "levelUp",
2283
2451
  "accounts": [
@@ -2753,6 +2921,62 @@ exports.IDL = {
2753
2921
  ],
2754
2922
  "returns": "u8"
2755
2923
  },
2924
+ {
2925
+ "name": "getLiquidationPrice",
2926
+ "accounts": [
2927
+ {
2928
+ "name": "perpetuals",
2929
+ "isMut": false,
2930
+ "isSigner": false
2931
+ },
2932
+ {
2933
+ "name": "pool",
2934
+ "isMut": false,
2935
+ "isSigner": false
2936
+ },
2937
+ {
2938
+ "name": "position",
2939
+ "isMut": false,
2940
+ "isSigner": false
2941
+ },
2942
+ {
2943
+ "name": "market",
2944
+ "isMut": false,
2945
+ "isSigner": false
2946
+ },
2947
+ {
2948
+ "name": "targetCustody",
2949
+ "isMut": false,
2950
+ "isSigner": false
2951
+ },
2952
+ {
2953
+ "name": "collateralCustody",
2954
+ "isMut": false,
2955
+ "isSigner": false
2956
+ },
2957
+ {
2958
+ "name": "collateralOracleAccount",
2959
+ "isMut": false,
2960
+ "isSigner": false
2961
+ },
2962
+ {
2963
+ "name": "ixSysvar",
2964
+ "isMut": false,
2965
+ "isSigner": false
2966
+ }
2967
+ ],
2968
+ "args": [
2969
+ {
2970
+ "name": "params",
2971
+ "type": {
2972
+ "defined": "GetLiquidationPriceParams"
2973
+ }
2974
+ }
2975
+ ],
2976
+ "returns": {
2977
+ "defined": "OraclePrice"
2978
+ }
2979
+ },
2756
2980
  {
2757
2981
  "name": "getOraclePrice",
2758
2982
  "accounts": [
@@ -3775,6 +3999,24 @@ exports.IDL = {
3775
3999
  ]
3776
4000
  }
3777
4001
  },
4002
+ {
4003
+ "name": "ForceClosePositionParams",
4004
+ "type": {
4005
+ "kind": "struct",
4006
+ "fields": [
4007
+ {
4008
+ "name": "privilege",
4009
+ "type": {
4010
+ "defined": "Privilege"
4011
+ }
4012
+ },
4013
+ {
4014
+ "name": "isStopLoss",
4015
+ "type": "bool"
4016
+ }
4017
+ ]
4018
+ }
4019
+ },
3778
4020
  {
3779
4021
  "name": "GetAddLiquidityAmountAndFeeParams",
3780
4022
  "type": {
@@ -3823,6 +4065,13 @@ exports.IDL = {
3823
4065
  "fields": []
3824
4066
  }
3825
4067
  },
4068
+ {
4069
+ "name": "GetLiquidationPriceParams",
4070
+ "type": {
4071
+ "kind": "struct",
4072
+ "fields": []
4073
+ }
4074
+ },
3826
4075
  {
3827
4076
  "name": "GetLiquidationStateParams",
3828
4077
  "type": {
@@ -4261,6 +4510,24 @@ exports.IDL = {
4261
4510
  ]
4262
4511
  }
4263
4512
  },
4513
+ {
4514
+ "name": "SetTriggerPriceParams",
4515
+ "type": {
4516
+ "kind": "struct",
4517
+ "fields": [
4518
+ {
4519
+ "name": "triggerPrice",
4520
+ "type": {
4521
+ "defined": "OraclePrice"
4522
+ }
4523
+ },
4524
+ {
4525
+ "name": "isStopLoss",
4526
+ "type": "bool"
4527
+ }
4528
+ ]
4529
+ }
4530
+ },
4264
4531
  {
4265
4532
  "name": "SwapParams",
4266
4533
  "type": {
@@ -5418,6 +5685,56 @@ exports.IDL = {
5418
5685
  }
5419
5686
  ]
5420
5687
  },
5688
+ {
5689
+ "name": "ForceClosePositionLog",
5690
+ "fields": [
5691
+ {
5692
+ "name": "owner",
5693
+ "type": "publicKey",
5694
+ "index": false
5695
+ },
5696
+ {
5697
+ "name": "market",
5698
+ "type": "publicKey",
5699
+ "index": false
5700
+ },
5701
+ {
5702
+ "name": "priceUsd",
5703
+ "type": "u64",
5704
+ "index": false
5705
+ },
5706
+ {
5707
+ "name": "sizeAmount",
5708
+ "type": "u64",
5709
+ "index": false
5710
+ },
5711
+ {
5712
+ "name": "sizeUsd",
5713
+ "type": "u64",
5714
+ "index": false
5715
+ },
5716
+ {
5717
+ "name": "profitUsd",
5718
+ "type": "u64",
5719
+ "index": false
5720
+ },
5721
+ {
5722
+ "name": "lossUsd",
5723
+ "type": "u64",
5724
+ "index": false
5725
+ },
5726
+ {
5727
+ "name": "feeAmount",
5728
+ "type": "u64",
5729
+ "index": false
5730
+ },
5731
+ {
5732
+ "name": "isStopLoss",
5733
+ "type": "bool",
5734
+ "index": false
5735
+ }
5736
+ ]
5737
+ },
5421
5738
  {
5422
5739
  "name": "IncreaseSizeLog",
5423
5740
  "fields": [
@@ -5593,6 +5910,31 @@ exports.IDL = {
5593
5910
  }
5594
5911
  ]
5595
5912
  },
5913
+ {
5914
+ "name": "SetTriggerPriceLog",
5915
+ "fields": [
5916
+ {
5917
+ "name": "owner",
5918
+ "type": "publicKey",
5919
+ "index": false
5920
+ },
5921
+ {
5922
+ "name": "market",
5923
+ "type": "publicKey",
5924
+ "index": false
5925
+ },
5926
+ {
5927
+ "name": "priceUsd",
5928
+ "type": "u64",
5929
+ "index": false
5930
+ },
5931
+ {
5932
+ "name": "isStopLoss",
5933
+ "type": "bool",
5934
+ "index": false
5935
+ }
5936
+ ]
5937
+ },
5596
5938
  {
5597
5939
  "name": "SwapLog",
5598
5940
  "fields": [
@@ -5909,6 +6251,21 @@ exports.IDL = {
5909
6251
  "code": 6047,
5910
6252
  "name": "TradingAccountMismatch",
5911
6253
  "msg": "Trading account doesnot match referral account"
6254
+ },
6255
+ {
6256
+ "code": 6048,
6257
+ "name": "MaxDepostsReached",
6258
+ "msg": "Max deposits reached"
6259
+ },
6260
+ {
6261
+ "code": 6049,
6262
+ "name": "InvalidStopLossPrice",
6263
+ "msg": "Invalid Stop Loss price"
6264
+ },
6265
+ {
6266
+ "code": 6050,
6267
+ "name": "InvalidTakeProfitPrice",
6268
+ "msg": "Invalid Take Profit price"
5912
6269
  }
5913
6270
  ]
5914
6271
  };
package/dist/test2.js CHANGED
@@ -39,15 +39,11 @@ var _a;
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  require("dotenv/config");
41
41
  var bn_js_1 = require("bn.js");
42
- var utils_1 = require("./utils");
43
42
  var PerpetualsClient_1 = require("./PerpetualsClient");
44
43
  var anchor_1 = require("@coral-xyz/anchor");
45
- var web3_js_1 = require("@solana/web3.js");
46
- var types_1 = require("./types");
47
44
  var OraclePrice_1 = require("./OraclePrice");
48
45
  var CustodyAccount_1 = require("./CustodyAccount");
49
46
  var client_1 = require("@pythnetwork/client");
50
- var PositionAccount_1 = require("./PositionAccount");
51
47
  var PoolAccount_1 = require("./PoolAccount");
52
48
  var PoolDataClient_1 = require("./PoolDataClient");
53
49
  var spl_token_1 = require("@solana/spl-token");
@@ -67,21 +63,20 @@ function initClient(clusterUrl, adminKeyPath, programId, composabilityProgramId,
67
63
  var prettyPrint = function (object) {
68
64
  console.log(JSON.stringify(object, null, 2));
69
65
  };
70
- var url = 'https://flashtr-flash-885f.mainnet.rpcpool.com/11a75a74-fd8e-44cc-87f4-d84bb82d0983';
66
+ var url = 'https://flashtr-flash-885f.devnet.rpcpool.com/e0f3d11e-6673-4e02-b3f8-361d596ee7fe';
71
67
  console.log("url:", url);
72
68
  var adminKey = (_a = process.env["KEYPAIR_PATH"]) !== null && _a !== void 0 ? _a : "/Users/aw/.config/solana/Beta-Hcik.json";
73
69
  console.log("adminKey path:", adminKey);
74
70
  var main2 = function () { return __awaiter(void 0, void 0, void 0, function () {
75
- var POOL_CONFIG, marketConfig, programId, composabilityProgramId, poolName, poolKey, poolData, poolAccount, custodyAccounts, i, custodyAccountKey, custodyAccountInfo, ca, lpTokenInfo, pythClient, pythHttpClientResult, priceDataSOL, priceOracleSOL, emaPriceOracleSOL, priceDataUSDC, priceOracleUSDC, emaPriceOracleUSDC, priceDataBTC, priceOracleBTC, emaPriceOracleBTC, priceDataETH, priceOracleETH, emaPriceOracleETH, nprices, custodyData, lpStats, position, newPosition, currtime, x;
71
+ var POOL_CONFIG, programId, composabilityProgramId, poolName, poolKey, poolData, poolAccount, custodyAccounts, i, custodyAccountKey, custodyAccountInfo, ca, lpTokenInfo, pythClient, pythHttpClientResult, priceDataSOL, priceOracleSOL, emaPriceOracleSOL, priceDataUSDC, priceOracleUSDC, emaPriceOracleUSDC, priceDataBTC, priceOracleBTC, emaPriceOracleBTC, priceDataETH, priceOracleETH, emaPriceOracleETH, nprices, custodyData, lpStats, apy;
76
72
  return __generator(this, function (_a) {
77
73
  switch (_a.label) {
78
74
  case 0:
79
- POOL_CONFIG = PoolConfig_1.PoolConfig.fromIdsByName('Crypto.1', 'mainnet-beta');
80
- marketConfig = POOL_CONFIG.markets.find(function (i) { return i.marketId == 0; });
75
+ POOL_CONFIG = PoolConfig_1.PoolConfig.fromIdsByName('devnet.1', 'devnet');
81
76
  programId = POOL_CONFIG.programId;
82
77
  composabilityProgramId = POOL_CONFIG.perpComposibilityProgramId;
83
78
  initClient(url, adminKey, programId, composabilityProgramId, POOL_CONFIG.fbNftRewardProgramId);
84
- poolName = "Crypto.1";
79
+ poolName = "devnet.1";
85
80
  poolKey = POOL_CONFIG.poolAddress;
86
81
  return [4, client.getPool(poolName)];
87
82
  case 1:
@@ -106,7 +101,7 @@ var main2 = function () { return __awaiter(void 0, void 0, void 0, function () {
106
101
  case 6:
107
102
  lpTokenInfo = _a.sent();
108
103
  poolClient = new PoolDataClient_1.PoolDataClient(POOL_CONFIG, poolAccount, lpTokenInfo, custodyAccounts);
109
- pythClient = new client_1.PythHttpClient(client.provider.connection, (0, client_1.getPythProgramKeyForCluster)('mainnet-beta'));
104
+ pythClient = new client_1.PythHttpClient(client.provider.connection, (0, client_1.getPythProgramKeyForCluster)('devnet'));
110
105
  return [4, pythClient.getData()];
111
106
  case 7:
112
107
  pythHttpClientResult = _a.sent();
@@ -171,14 +166,9 @@ var main2 = function () { return __awaiter(void 0, void 0, void 0, function () {
171
166
  console.log("custodyData[0].availableToAddUsdUi:", custodyData[0].availableToAddUsdUi);
172
167
  lpStats = poolClient.getLpStats(nprices);
173
168
  console.log("lpStats:", lpStats.priceUi);
174
- return [4, client.getPosition(new web3_js_1.PublicKey('J1LEe1ASZJrEpomSRH3TADmDd4ecowts48c2mDofHdjS'))];
175
- case 8:
176
- position = _a.sent();
177
- newPosition = PositionAccount_1.PositionAccount.from(new web3_js_1.PublicKey('J1LEe1ASZJrEpomSRH3TADmDd4ecowts48c2mDofHdjS'), position);
178
- console.log('position :>> ', newPosition);
179
- currtime = new bn_js_1.BN((0, utils_1.getUnixTs)());
180
- x = client.getDecreaseSizeCollateralAndFeeSync(newPosition, true, new bn_js_1.BN(1000000), true, priceOracleSOL, emaPriceOracleSOL, marketConfig, custodyAccounts[1], priceOracleSOL, emaPriceOracleSOL, custodyAccounts[1], currtime, types_1.Side.Long, POOL_CONFIG);
181
- console.log(x.liquidationPrice.toString());
169
+ console.log("custodyAccounts[0].feesStats.rewardPerLpStaked:", custodyAccounts[0].feesStats.rewardPerLpStaked.toString());
170
+ apy = client.getApyPercentageUi(custodyAccounts[0], custodyAccounts[0].feesStats.rewardPerLpStaked.subn(3000), new bn_js_1.BN(1 * Math.pow(10, 6)));
171
+ console.log("apy:", apy.toString());
182
172
  return [2];
183
173
  }
184
174
  });