@gmx-io/sdk 1.2.0 → 1.2.1

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.
Files changed (88) hide show
  1. package/build/cjs/src/abis/ClaimHandler.json +439 -0
  2. package/build/cjs/src/abis/index.js +4 -0
  3. package/build/cjs/src/configs/__tests__/markets.spec.js +1 -1
  4. package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -1
  5. package/build/cjs/src/configs/batch.js +12 -0
  6. package/build/cjs/src/configs/contracts.js +2 -0
  7. package/build/cjs/src/configs/dataStore.js +13 -3
  8. package/build/cjs/src/configs/express.js +2 -1
  9. package/build/cjs/src/configs/markets.js +35 -0
  10. package/build/cjs/src/configs/oracleKeeper.js +19 -35
  11. package/build/cjs/src/configs/tokens.js +55 -0
  12. package/build/cjs/src/index.js +3 -3
  13. package/build/cjs/src/modules/orders/helpers.js +9 -0
  14. package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
  15. package/build/cjs/src/modules/orders/orders.js +3 -3
  16. package/build/cjs/src/modules/utils/utils.js +3 -3
  17. package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +40 -0
  18. package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +255 -0
  19. package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +75 -0
  20. package/build/cjs/src/types/subsquid.js +91 -1
  21. package/build/cjs/src/types/swapStrategy.js +2 -0
  22. package/build/cjs/src/types/trade.js +1 -0
  23. package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +2 -0
  24. package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  25. package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +10 -0
  26. package/build/cjs/src/utils/errors/transactionsErrors.js +7 -1
  27. package/build/cjs/src/utils/orderTransactions.js +0 -1
  28. package/build/cjs/src/utils/swap/botanixStaking.js +90 -0
  29. package/build/cjs/src/utils/swap/buildSwapStrategy.js +224 -0
  30. package/build/cjs/src/utils/swap/externalSwapPath.js +41 -0
  31. package/build/cjs/src/utils/swap/externalSwapQuoteByPath.js +27 -0
  32. package/build/cjs/src/utils/swap/swapValues.js +250 -11
  33. package/build/cjs/src/utils/trade/amounts.js +89 -41
  34. package/build/cjs/src/utils/trade/trade.js +2 -2
  35. package/build/cjs/src/utils/twap/uiFeeReceiver.js +9 -9
  36. package/build/esm/src/abis/ClaimHandler.json +439 -0
  37. package/build/esm/src/abis/index.js +4 -0
  38. package/build/esm/src/configs/__tests__/markets.spec.js +1 -1
  39. package/build/esm/src/configs/__tests__/tokens.spec.js +1 -1
  40. package/build/esm/src/configs/batch.js +13 -1
  41. package/build/esm/src/configs/contracts.js +2 -0
  42. package/build/esm/src/configs/dataStore.js +8 -0
  43. package/build/esm/src/configs/express.js +1 -0
  44. package/build/esm/src/configs/markets.js +35 -0
  45. package/build/esm/src/configs/oracleKeeper.js +17 -29
  46. package/build/esm/src/configs/tokens.js +55 -0
  47. package/build/esm/src/index.js +3 -3
  48. package/build/esm/src/modules/orders/helpers.js +9 -0
  49. package/build/esm/src/modules/orders/helpers.spec.js +1 -1
  50. package/build/esm/src/modules/orders/orders.js +3 -3
  51. package/build/esm/src/modules/utils/utils.js +3 -3
  52. package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +40 -0
  53. package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +255 -0
  54. package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +75 -0
  55. package/build/esm/src/types/subsquid.js +90 -0
  56. package/build/esm/src/types/swapStrategy.js +1 -0
  57. package/build/esm/src/types/trade.js +1 -0
  58. package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +2 -0
  59. package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
  60. package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +11 -1
  61. package/build/esm/src/utils/errors/transactionsErrors.js +7 -1
  62. package/build/esm/src/utils/orderTransactions.js +0 -1
  63. package/build/esm/src/utils/swap/botanixStaking.js +83 -0
  64. package/build/esm/src/utils/swap/buildSwapStrategy.js +219 -0
  65. package/build/esm/src/utils/swap/externalSwapPath.js +37 -0
  66. package/build/esm/src/utils/swap/externalSwapQuoteByPath.js +23 -0
  67. package/build/esm/src/utils/swap/swapValues.js +248 -9
  68. package/build/esm/src/utils/trade/amounts.js +89 -41
  69. package/build/esm/src/utils/trade/trade.js +2 -2
  70. package/build/esm/src/utils/twap/uiFeeReceiver.js +9 -9
  71. package/build/types/src/abis/index.d.ts +1 -1
  72. package/build/types/src/configs/batch.d.ts +2 -1
  73. package/build/types/src/configs/contracts.d.ts +2 -0
  74. package/build/types/src/configs/dataStore.d.ts +4 -0
  75. package/build/types/src/configs/express.d.ts +1 -0
  76. package/build/types/src/configs/oracleKeeper.d.ts +2 -3
  77. package/build/types/src/types/subsquid.d.ts +303 -0
  78. package/build/types/src/types/swapStrategy.d.ts +33 -0
  79. package/build/types/src/types/tokens.d.ts +5 -0
  80. package/build/types/src/types/trade.d.ts +18 -4
  81. package/build/types/src/utils/swap/botanixStaking.d.ts +11 -0
  82. package/build/types/src/utils/swap/buildSwapStrategy.d.ts +22 -0
  83. package/build/types/src/utils/swap/externalSwapPath.d.ts +13 -0
  84. package/build/types/src/utils/swap/externalSwapQuoteByPath.d.ts +6 -0
  85. package/build/types/src/utils/swap/swapValues.d.ts +10 -3
  86. package/build/types/src/utils/trade/amounts.d.ts +5 -2
  87. package/build/types/src/utils/twap/uiFeeReceiver.d.ts +7 -7
  88. package/package.json +1 -1
@@ -1352,6 +1352,36 @@
1352
1352
  "shortInterestInTokensUsingLongToken": "0xf8b11af0ad2d1ab5f63791944792e3d3c96e5973b7f003dd86bd4314a25dcda9",
1353
1353
  "shortInterestInTokensUsingShortToken": "0x4ed2301ae42565af0bc559a51c13c60223d0159f349ccc0efc2f080d3a467298"
1354
1354
  },
1355
+ "0x8263bC3766a09f6dD4Bab04b4bf8D45F2B0973FF": {
1356
+ "longPoolAmount": "0x376d10c7c9e12d555cc72da9c11f290bb948dee849e7ac53c9919cb7ea326356",
1357
+ "shortPoolAmount": "0x0328aa07dddd94e5b175e0c18e2a038a87ef77dbe0f01598abfd5334e14f8e5e",
1358
+ "positionImpactPoolAmount": "0xec2057fa3283a4b58a58071d0fc709fbabe164669de94f39a32c0f9e6d8ad857",
1359
+ "swapImpactPoolAmountLong": "0xcad777762cbf8191fdc7a83fed0b6dc7267c3ec95deafbc3f278c78640f5def2",
1360
+ "swapImpactPoolAmountShort": "0x4ea39496d661599d66dd7c36f636e2beb1d9f22d494251079661ef97b260796b",
1361
+ "longInterestUsingLongToken": "0x60b2619176219b8e25afc32c0822b3ff9866f234f23171cd5c443e1307aadb83",
1362
+ "longInterestUsingShortToken": "0x2d9f098282c2b594ffa540647b1ac0c6209b17e64061586c5c89f70b7f1e561c",
1363
+ "shortInterestUsingLongToken": "0x46574cd73b54eb902ef9f6257cf28096088a744437a313e50ac6a3dcdde873ad",
1364
+ "shortInterestUsingShortToken": "0xa8bbf0769960efdfe8fcd0fb1dd38f6713bf76f3980f613aee0fb1c8fbcb5fa6",
1365
+ "longInterestInTokensUsingLongToken": "0x64f6ab661c3fb1f4782cee482f58fa61e4a8e8f100f407793406835061104b48",
1366
+ "longInterestInTokensUsingShortToken": "0x2aa02635cddc8d2c7be1cb924b3bb933eeb0fea6fa8a5a480180c0d0cb7d3aca",
1367
+ "shortInterestInTokensUsingLongToken": "0x82047a97d39c5c336f198c2c03598016c99e5e7c055d3507be800f23e516aef6",
1368
+ "shortInterestInTokensUsingShortToken": "0xe2de08baa4086bcdaa890f544b6144c2a3e1f7687a0724b6d9211851eb8851cb"
1369
+ },
1370
+ "0x40dAEAc02dCf6b3c51F9151f532C21DCEF2F7E63": {
1371
+ "longPoolAmount": "0x3ada05b4ab6a01c1e9d5d14a6623330ac706b167ef0a071c44caae0f2e86fdc5",
1372
+ "shortPoolAmount": "0x4549e636396f94e60a42c4e6cf6de9cc4641b422616da34afad3bb545252d55b",
1373
+ "positionImpactPoolAmount": "0x7ac4153f38da7f40234e4278155360da68d5d7ba448b8406a58a32e3984e1c84",
1374
+ "swapImpactPoolAmountLong": "0x23d98dcb90fa99c0c0afaf8da74219739891cb8110408cf62f0ff7ee9791b841",
1375
+ "swapImpactPoolAmountShort": "0x67689a5fe771bcce0255ea6af7497ebdf969b44a2925b0a7d57ab813a7d92528",
1376
+ "longInterestUsingLongToken": "0xb54834f5f22fd80d4bff9e5fad82cdc0812f9c92145c9213d61ec65e023f4a49",
1377
+ "longInterestUsingShortToken": "0x6b03ae70dddc4ea9ffac583d90730c4deb7aa91f2e05b0ef4496373135f501db",
1378
+ "shortInterestUsingLongToken": "0xb7825b979161efdf744c59e3a2f1ce9a946401f1fff467cdda4c79b4eeef1dee",
1379
+ "shortInterestUsingShortToken": "0x20d46f0c26c10020a4caa0b8508e679b5c0366ffa1957348f4af12e02e8ae627",
1380
+ "longInterestInTokensUsingLongToken": "0xb05b543fd027e0faeac576b85e5eb8dd16dbe9b0a287951e880462f74428dbe7",
1381
+ "longInterestInTokensUsingShortToken": "0x548e4ec925976c9573b2513f3e04ccb85992e7b2f9fcadef9d390972901249d2",
1382
+ "shortInterestInTokensUsingLongToken": "0x43eeca3a191fb5f9d6e028d433477afb80d8bc8be6d4736ca40f72100ed01760",
1383
+ "shortInterestInTokensUsingShortToken": "0x08fb093e1d5256360f715652095ebef083a166cb62c222f96d377cc7aee3e961"
1384
+ },
1355
1385
  "0x672fEA44f4583DdaD620d60C1Ac31021F47558Cb": {
1356
1386
  "longPoolAmount": "0xd88d77f52c0605af9087b8ac011f7ce71651f30489699ab476eaaf49fe3169be",
1357
1387
  "shortPoolAmount": "0xd88d77f52c0605af9087b8ac011f7ce71651f30489699ab476eaaf49fe3169be",
@@ -1366,6 +1396,51 @@
1366
1396
  "longInterestInTokensUsingShortToken": "0x8ff57a652cd892eade9757b138549656bc9f8dc00d9eeeb3fc4f9bd6f2cc2bd4",
1367
1397
  "shortInterestInTokensUsingLongToken": "0x81b4fc3022e9cb293b10549fa7ff90ca91abec03ca725ded69a4b35c09858ddf",
1368
1398
  "shortInterestInTokensUsingShortToken": "0x81b4fc3022e9cb293b10549fa7ff90ca91abec03ca725ded69a4b35c09858ddf"
1399
+ },
1400
+ "0x3B7f4e4Cf2fa43df013d2B32673e6A01d29ab2Ac": {
1401
+ "longPoolAmount": "0x950f55352377af24d3a96bc2a3a38d1e5dfbf04c07d8364475feb8092ec75c64",
1402
+ "shortPoolAmount": "0x0704221c55eb30a2efec7b9d42ad18b41c308c26c638e85ce53d08cc694bb340",
1403
+ "positionImpactPoolAmount": "0x757e7478893be5bf67fc10551f9ed34f1403a3628a8ff3f99bafa17b3ea66b79",
1404
+ "swapImpactPoolAmountLong": "0x7d1c81974ef4c7afb3592f7ebd245358952ca21333678e9ed0685d30b02e8a0a",
1405
+ "swapImpactPoolAmountShort": "0x71ba227bbc9232cd200c2a208ce26cb2991da321664a31bbd5d410174d07eefa",
1406
+ "longInterestUsingLongToken": "0xffbd879ff459c888617ba08141ca99969c83ac9de54990cab294ce2edd9fc9bd",
1407
+ "longInterestUsingShortToken": "0xb86c0a56965a83b03c7f93e6612efc66d78eaffc027d8877b4edf23ad75fa4cc",
1408
+ "shortInterestUsingLongToken": "0x769be22d39b7606b33a7734d76e3b9416cba72fff936b26a9ddb7875b4497dc3",
1409
+ "shortInterestUsingShortToken": "0x1746986fd30dbb8fb1939fe11604f11eeb57acbc85b1a76b5c78551798afdea7",
1410
+ "longInterestInTokensUsingLongToken": "0x19507cd2da36e6ca0e96b043c6b0e853e477cd1aab3ee7f74db45f918910549d",
1411
+ "longInterestInTokensUsingShortToken": "0x8d9c0ab0775b9405e5f54458dcbe28bfa2a49a07e39253b6d9735a77ba8a6c16",
1412
+ "shortInterestInTokensUsingLongToken": "0x10863b6d78d3d1746d0bb8de8b7e3df021ddcdc1008d6c1ede3c3bfb30f08199",
1413
+ "shortInterestInTokensUsingShortToken": "0x98724366736175a92826c63d94d611bc2ea3a63f24714d71c2c106a24a7548ea"
1414
+ },
1415
+ "0xa29FfE4152B65A0347512Ae5c6A4Bbc7a3d6d51B": {
1416
+ "longPoolAmount": "0x6693ae65f8c7bbbdb4dafdc6e2d2a4824b589b7c7454b411517e795feae42bc8",
1417
+ "shortPoolAmount": "0x29057b0a5f9faf83d5b250aa95a44056aafe0c87f6ebbed9ff5bede52e4b2d7e",
1418
+ "positionImpactPoolAmount": "0x2882e4b9bb2ad8ea954630b4ecb75982cf32cba38bac0acaf3db59d61735bee3",
1419
+ "swapImpactPoolAmountLong": "0xd496578938511700e33179b3c23bd8fed3ce421ad8800f4dfd11e3363ba2dddb",
1420
+ "swapImpactPoolAmountShort": "0x3308ca648709f2b017c80f87483d2f87e1f55bc67d0a7de075d50ef01af25a13",
1421
+ "longInterestUsingLongToken": "0xd5f0aacccbc59df807fe217610dff270e934ce85b5629a8bd93f723389fd628c",
1422
+ "longInterestUsingShortToken": "0x250a4ce3cc83fa6179cdff4c755cd1434fa1d2ca4fbc8dd0db896098ce0fd94a",
1423
+ "shortInterestUsingLongToken": "0x977c23ba871ab8a9572a25e627de71e8665f2ff6f3bcd6fb8aa1c033382ec0a1",
1424
+ "shortInterestUsingShortToken": "0xce032220c9bf7365cd2b408a5f6bb2df31f6220585ceaaffbecb714a182cba81",
1425
+ "longInterestInTokensUsingLongToken": "0xbb9538095139b99b8d1a471e5298108f9879203fdc9f88e302b98edbc810f377",
1426
+ "longInterestInTokensUsingShortToken": "0xaf453df5666a65e4ccc0f2a16fe04f10e5c7c44b0c24d8ebfdd1da10e0b57e1e",
1427
+ "shortInterestInTokensUsingLongToken": "0x168d1abf6abf13f235b7fbc88ac6a316e280110fb243fa96ba0d1d39184a8863",
1428
+ "shortInterestInTokensUsingShortToken": "0xfd8853a8fc94ff0f74ae1b99c4dd162d6a5673bf3a2b1d7cea2217cfecd8ad2a"
1429
+ },
1430
+ "0x9f0849FB830679829d1FB759b11236D375D15C78": {
1431
+ "longPoolAmount": "0x21b6ff319e87d9484b5155577154f1e7eb2a02719b2c78877e1b878bd628aab6",
1432
+ "shortPoolAmount": "0xcbcc6f24046ab5a5cb181328fc5279797aa888128db0943ca97d5e29cd07589c",
1433
+ "positionImpactPoolAmount": "0x7bc771e3bd2c1e339894d8cc0e339f3bd29571b1f81dc4aaab752d9d5c4565d8",
1434
+ "swapImpactPoolAmountLong": "0x9b8e8803dce19ab635bdcbd739151269bdcfe50181bdded95378e3fd86b32060",
1435
+ "swapImpactPoolAmountShort": "0x55f2af971ae258c2ac5ae48e016329ea7e3d41558f1171bc082f9de3c822dff3",
1436
+ "longInterestUsingLongToken": "0xe7339c70b7e5f38ed83fde6e7db586b5472612110751aa45da936bdbac49d176",
1437
+ "longInterestUsingShortToken": "0x8be7905da5f947c317e5183fdcb4ccfa7dc100dd7b612f5c7ba9ecba45220914",
1438
+ "shortInterestUsingLongToken": "0x35cff8db41f43cd082d5ec9e12c8e41e96e62da8ad6e9f62c24ab649ae2de828",
1439
+ "shortInterestUsingShortToken": "0xd933217c4dd384699dac11292fa70a208607ffbf9a63beb7bae9d66b1b7080b8",
1440
+ "longInterestInTokensUsingLongToken": "0x3953a9515c3bf950fa114c7de0c76524b7dce1188855ed5e1858ff72a757b4f3",
1441
+ "longInterestInTokensUsingShortToken": "0x0b102716f7adc9208283d13cf4d33943256dda36d1ee07862e50753261911492",
1442
+ "shortInterestInTokensUsingLongToken": "0x6a9fe892379ef84c1da651fb1b30387a0d01a1569c5351d4a18984b34bfd1f62",
1443
+ "shortInterestInTokensUsingShortToken": "0x84181252090dc10bfd3e2e1e50d08518e7699461a3fa413f0231e14bdacb16fd"
1369
1444
  }
1370
1445
  },
1371
1446
  "43113": {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransactionOrderByInput = exports.TradeActionOrderByInput = exports.SwapInfoOrderByInput = exports.PriceType = exports.PriceOrderByInput = exports.PositionOrderByInput = exports.PositionFeesEntityType = exports.PositionFeesEntityOrderByInput = exports.PositionChangeType = exports.PositionChangeOrderByInput = exports.PnlAprSnapshotOrderByInput = exports.OrderStatus = exports.OrderOrderByInput = exports.OnChainSettingType = exports.OnChainSettingOrderByInput = exports.MarketOrderByInput = exports.MarketInfoOrderByInput = exports.GlvOrderByInput = exports.EntityType = exports.CumulativePoolValueOrderByInput = exports.CumulativePnlOrderByInput = exports.CollectedFeesInfoOrderByInput = exports.ClaimableFundingFeeInfoOrderByInput = exports.ClaimRefOrderByInput = exports.ClaimActionType = exports.ClaimActionOrderByInput = exports.BorrowingRateSnapshotOrderByInput = exports.AprSnapshotOrderByInput = exports.AccountStatOrderByInput = void 0;
3
+ exports.TransactionOrderByInput = exports.TradeActionOrderByInput = exports.SwapInfoOrderByInput = exports.ProcessorStatusOrderByInput = exports.PriceType = exports.PriceOrderByInput = exports.PositionOrderByInput = exports.PositionFeesEntityType = exports.PositionFeesEntityOrderByInput = exports.PositionChangeType = exports.PositionChangeOrderByInput = exports.PnlAprSnapshotOrderByInput = exports.OrderStatus = exports.OrderOrderByInput = exports.OnChainSettingType = exports.OnChainSettingOrderByInput = exports.MarketOrderByInput = exports.MarketInfoOrderByInput = exports.GlvOrderByInput = exports.EntityType = exports.DistributionOrderByInput = exports.CumulativePoolValueOrderByInput = exports.CumulativePnlOrderByInput = exports.CollectedFeesInfoOrderByInput = exports.ClaimableFundingFeeInfoOrderByInput = exports.ClaimRefOrderByInput = exports.ClaimActionType = exports.ClaimActionOrderByInput = exports.BorrowingRateSnapshotOrderByInput = exports.AprSnapshotOrderByInput = exports.AccountStatOrderByInput = void 0;
4
4
  var AccountStatOrderByInput;
5
5
  (function (AccountStatOrderByInput) {
6
6
  AccountStatOrderByInput["closedCount_ASC"] = "closedCount_ASC";
@@ -468,6 +468,69 @@ var CumulativePoolValueOrderByInput;
468
468
  CumulativePoolValueOrderByInput["snapshotTimestamp_DESC_NULLS_FIRST"] = "snapshotTimestamp_DESC_NULLS_FIRST";
469
469
  CumulativePoolValueOrderByInput["snapshotTimestamp_DESC_NULLS_LAST"] = "snapshotTimestamp_DESC_NULLS_LAST";
470
470
  })(CumulativePoolValueOrderByInput || (exports.CumulativePoolValueOrderByInput = CumulativePoolValueOrderByInput = {}));
471
+ var DistributionOrderByInput;
472
+ (function (DistributionOrderByInput) {
473
+ DistributionOrderByInput["id_ASC"] = "id_ASC";
474
+ DistributionOrderByInput["id_ASC_NULLS_FIRST"] = "id_ASC_NULLS_FIRST";
475
+ DistributionOrderByInput["id_ASC_NULLS_LAST"] = "id_ASC_NULLS_LAST";
476
+ DistributionOrderByInput["id_DESC"] = "id_DESC";
477
+ DistributionOrderByInput["id_DESC_NULLS_FIRST"] = "id_DESC_NULLS_FIRST";
478
+ DistributionOrderByInput["id_DESC_NULLS_LAST"] = "id_DESC_NULLS_LAST";
479
+ DistributionOrderByInput["receiver_ASC"] = "receiver_ASC";
480
+ DistributionOrderByInput["receiver_ASC_NULLS_FIRST"] = "receiver_ASC_NULLS_FIRST";
481
+ DistributionOrderByInput["receiver_ASC_NULLS_LAST"] = "receiver_ASC_NULLS_LAST";
482
+ DistributionOrderByInput["receiver_DESC"] = "receiver_DESC";
483
+ DistributionOrderByInput["receiver_DESC_NULLS_FIRST"] = "receiver_DESC_NULLS_FIRST";
484
+ DistributionOrderByInput["receiver_DESC_NULLS_LAST"] = "receiver_DESC_NULLS_LAST";
485
+ DistributionOrderByInput["transaction_blockNumber_ASC"] = "transaction_blockNumber_ASC";
486
+ DistributionOrderByInput["transaction_blockNumber_ASC_NULLS_FIRST"] = "transaction_blockNumber_ASC_NULLS_FIRST";
487
+ DistributionOrderByInput["transaction_blockNumber_ASC_NULLS_LAST"] = "transaction_blockNumber_ASC_NULLS_LAST";
488
+ DistributionOrderByInput["transaction_blockNumber_DESC"] = "transaction_blockNumber_DESC";
489
+ DistributionOrderByInput["transaction_blockNumber_DESC_NULLS_FIRST"] = "transaction_blockNumber_DESC_NULLS_FIRST";
490
+ DistributionOrderByInput["transaction_blockNumber_DESC_NULLS_LAST"] = "transaction_blockNumber_DESC_NULLS_LAST";
491
+ DistributionOrderByInput["transaction_from_ASC"] = "transaction_from_ASC";
492
+ DistributionOrderByInput["transaction_from_ASC_NULLS_FIRST"] = "transaction_from_ASC_NULLS_FIRST";
493
+ DistributionOrderByInput["transaction_from_ASC_NULLS_LAST"] = "transaction_from_ASC_NULLS_LAST";
494
+ DistributionOrderByInput["transaction_from_DESC"] = "transaction_from_DESC";
495
+ DistributionOrderByInput["transaction_from_DESC_NULLS_FIRST"] = "transaction_from_DESC_NULLS_FIRST";
496
+ DistributionOrderByInput["transaction_from_DESC_NULLS_LAST"] = "transaction_from_DESC_NULLS_LAST";
497
+ DistributionOrderByInput["transaction_hash_ASC"] = "transaction_hash_ASC";
498
+ DistributionOrderByInput["transaction_hash_ASC_NULLS_FIRST"] = "transaction_hash_ASC_NULLS_FIRST";
499
+ DistributionOrderByInput["transaction_hash_ASC_NULLS_LAST"] = "transaction_hash_ASC_NULLS_LAST";
500
+ DistributionOrderByInput["transaction_hash_DESC"] = "transaction_hash_DESC";
501
+ DistributionOrderByInput["transaction_hash_DESC_NULLS_FIRST"] = "transaction_hash_DESC_NULLS_FIRST";
502
+ DistributionOrderByInput["transaction_hash_DESC_NULLS_LAST"] = "transaction_hash_DESC_NULLS_LAST";
503
+ DistributionOrderByInput["transaction_id_ASC"] = "transaction_id_ASC";
504
+ DistributionOrderByInput["transaction_id_ASC_NULLS_FIRST"] = "transaction_id_ASC_NULLS_FIRST";
505
+ DistributionOrderByInput["transaction_id_ASC_NULLS_LAST"] = "transaction_id_ASC_NULLS_LAST";
506
+ DistributionOrderByInput["transaction_id_DESC"] = "transaction_id_DESC";
507
+ DistributionOrderByInput["transaction_id_DESC_NULLS_FIRST"] = "transaction_id_DESC_NULLS_FIRST";
508
+ DistributionOrderByInput["transaction_id_DESC_NULLS_LAST"] = "transaction_id_DESC_NULLS_LAST";
509
+ DistributionOrderByInput["transaction_timestamp_ASC"] = "transaction_timestamp_ASC";
510
+ DistributionOrderByInput["transaction_timestamp_ASC_NULLS_FIRST"] = "transaction_timestamp_ASC_NULLS_FIRST";
511
+ DistributionOrderByInput["transaction_timestamp_ASC_NULLS_LAST"] = "transaction_timestamp_ASC_NULLS_LAST";
512
+ DistributionOrderByInput["transaction_timestamp_DESC"] = "transaction_timestamp_DESC";
513
+ DistributionOrderByInput["transaction_timestamp_DESC_NULLS_FIRST"] = "transaction_timestamp_DESC_NULLS_FIRST";
514
+ DistributionOrderByInput["transaction_timestamp_DESC_NULLS_LAST"] = "transaction_timestamp_DESC_NULLS_LAST";
515
+ DistributionOrderByInput["transaction_to_ASC"] = "transaction_to_ASC";
516
+ DistributionOrderByInput["transaction_to_ASC_NULLS_FIRST"] = "transaction_to_ASC_NULLS_FIRST";
517
+ DistributionOrderByInput["transaction_to_ASC_NULLS_LAST"] = "transaction_to_ASC_NULLS_LAST";
518
+ DistributionOrderByInput["transaction_to_DESC"] = "transaction_to_DESC";
519
+ DistributionOrderByInput["transaction_to_DESC_NULLS_FIRST"] = "transaction_to_DESC_NULLS_FIRST";
520
+ DistributionOrderByInput["transaction_to_DESC_NULLS_LAST"] = "transaction_to_DESC_NULLS_LAST";
521
+ DistributionOrderByInput["transaction_transactionIndex_ASC"] = "transaction_transactionIndex_ASC";
522
+ DistributionOrderByInput["transaction_transactionIndex_ASC_NULLS_FIRST"] = "transaction_transactionIndex_ASC_NULLS_FIRST";
523
+ DistributionOrderByInput["transaction_transactionIndex_ASC_NULLS_LAST"] = "transaction_transactionIndex_ASC_NULLS_LAST";
524
+ DistributionOrderByInput["transaction_transactionIndex_DESC"] = "transaction_transactionIndex_DESC";
525
+ DistributionOrderByInput["transaction_transactionIndex_DESC_NULLS_FIRST"] = "transaction_transactionIndex_DESC_NULLS_FIRST";
526
+ DistributionOrderByInput["transaction_transactionIndex_DESC_NULLS_LAST"] = "transaction_transactionIndex_DESC_NULLS_LAST";
527
+ DistributionOrderByInput["typeId_ASC"] = "typeId_ASC";
528
+ DistributionOrderByInput["typeId_ASC_NULLS_FIRST"] = "typeId_ASC_NULLS_FIRST";
529
+ DistributionOrderByInput["typeId_ASC_NULLS_LAST"] = "typeId_ASC_NULLS_LAST";
530
+ DistributionOrderByInput["typeId_DESC"] = "typeId_DESC";
531
+ DistributionOrderByInput["typeId_DESC_NULLS_FIRST"] = "typeId_DESC_NULLS_FIRST";
532
+ DistributionOrderByInput["typeId_DESC_NULLS_LAST"] = "typeId_DESC_NULLS_LAST";
533
+ })(DistributionOrderByInput || (exports.DistributionOrderByInput = DistributionOrderByInput = {}));
471
534
  var EntityType;
472
535
  (function (EntityType) {
473
536
  EntityType["Glv"] = "Glv";
@@ -1980,6 +2043,33 @@ var PriceType;
1980
2043
  PriceType["onchainFeed"] = "onchainFeed";
1981
2044
  PriceType["v2"] = "v2";
1982
2045
  })(PriceType || (exports.PriceType = PriceType = {}));
2046
+ var ProcessorStatusOrderByInput;
2047
+ (function (ProcessorStatusOrderByInput) {
2048
+ ProcessorStatusOrderByInput["id_ASC"] = "id_ASC";
2049
+ ProcessorStatusOrderByInput["id_ASC_NULLS_FIRST"] = "id_ASC_NULLS_FIRST";
2050
+ ProcessorStatusOrderByInput["id_ASC_NULLS_LAST"] = "id_ASC_NULLS_LAST";
2051
+ ProcessorStatusOrderByInput["id_DESC"] = "id_DESC";
2052
+ ProcessorStatusOrderByInput["id_DESC_NULLS_FIRST"] = "id_DESC_NULLS_FIRST";
2053
+ ProcessorStatusOrderByInput["id_DESC_NULLS_LAST"] = "id_DESC_NULLS_LAST";
2054
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_ASC"] = "lastParsedBlockNumber_ASC";
2055
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_ASC_NULLS_FIRST"] = "lastParsedBlockNumber_ASC_NULLS_FIRST";
2056
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_ASC_NULLS_LAST"] = "lastParsedBlockNumber_ASC_NULLS_LAST";
2057
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_DESC"] = "lastParsedBlockNumber_DESC";
2058
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_DESC_NULLS_FIRST"] = "lastParsedBlockNumber_DESC_NULLS_FIRST";
2059
+ ProcessorStatusOrderByInput["lastParsedBlockNumber_DESC_NULLS_LAST"] = "lastParsedBlockNumber_DESC_NULLS_LAST";
2060
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_ASC"] = "lastParsedBlockTimestamp_ASC";
2061
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_ASC_NULLS_FIRST"] = "lastParsedBlockTimestamp_ASC_NULLS_FIRST";
2062
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_ASC_NULLS_LAST"] = "lastParsedBlockTimestamp_ASC_NULLS_LAST";
2063
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_DESC"] = "lastParsedBlockTimestamp_DESC";
2064
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_DESC_NULLS_FIRST"] = "lastParsedBlockTimestamp_DESC_NULLS_FIRST";
2065
+ ProcessorStatusOrderByInput["lastParsedBlockTimestamp_DESC_NULLS_LAST"] = "lastParsedBlockTimestamp_DESC_NULLS_LAST";
2066
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_ASC"] = "lastProcessorCallTimestamp_ASC";
2067
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_ASC_NULLS_FIRST"] = "lastProcessorCallTimestamp_ASC_NULLS_FIRST";
2068
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_ASC_NULLS_LAST"] = "lastProcessorCallTimestamp_ASC_NULLS_LAST";
2069
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_DESC"] = "lastProcessorCallTimestamp_DESC";
2070
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_DESC_NULLS_FIRST"] = "lastProcessorCallTimestamp_DESC_NULLS_FIRST";
2071
+ ProcessorStatusOrderByInput["lastProcessorCallTimestamp_DESC_NULLS_LAST"] = "lastProcessorCallTimestamp_DESC_NULLS_LAST";
2072
+ })(ProcessorStatusOrderByInput || (exports.ProcessorStatusOrderByInput = ProcessorStatusOrderByInput = {}));
1983
2073
  var SwapInfoOrderByInput;
1984
2074
  (function (SwapInfoOrderByInput) {
1985
2075
  SwapInfoOrderByInput["amountInAfterFees_ASC"] = "amountInAfterFees_ASC";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -23,4 +23,5 @@ var TriggerThresholdType;
23
23
  var ExternalSwapAggregator;
24
24
  (function (ExternalSwapAggregator) {
25
25
  ExternalSwapAggregator["OpenOcean"] = "openOcean";
26
+ ExternalSwapAggregator["BotanixStaking"] = "botanixStaking";
26
27
  })(ExternalSwapAggregator || (exports.ExternalSwapAggregator = ExternalSwapAggregator = {}));
@@ -164,6 +164,7 @@ const mock_1 = require("../../../test/mock");
164
164
  (0, vitest_1.it)("Token transfers with multiple orders, external swaps, update and cancel", () => {
165
165
  const params1 = {
166
166
  ...commonParams,
167
+ swapPath: [],
167
168
  payTokenAddress: tokens_1.NATIVE_TOKEN_ADDRESS,
168
169
  payTokenAmount: (0, numbers_1.parseValue)("1", WETH.decimals), // 1 ETH
169
170
  externalSwapQuote: (0, mock_1.mockExternalSwap)({
@@ -177,6 +178,7 @@ const mock_1 = require("../../../test/mock");
177
178
  };
178
179
  const params2 = {
179
180
  ...commonParams,
181
+ swapPath: [],
180
182
  payTokenAddress: USDC.address,
181
183
  payTokenAmount: (0, numbers_1.parseValue)("1000", USDC.decimals), // 1000 USDC
182
184
  externalSwapQuote: (0, mock_1.mockExternalSwap)({
@@ -296,6 +296,7 @@ const mock_1 = require("../../../test/mock");
296
296
  (0, vitest_1.it)("Market Increase with External Swap, Pay With Native Token", () => {
297
297
  const params = {
298
298
  ...commonParams,
299
+ swapPath: [],
299
300
  payTokenAddress: tokens_1.NATIVE_TOKEN_ADDRESS,
300
301
  payTokenAmount: (0, numbers_1.parseValue)("1", WETH.decimals), // 1 ETH
301
302
  collateralTokenAddress: USDC.address,
@@ -375,6 +376,7 @@ const mock_1 = require("../../../test/mock");
375
376
  (0, vitest_1.it)("Market Increase with External Swap, Pay With ERC20", () => {
376
377
  const params = {
377
378
  ...commonParams,
379
+ swapPath: [],
378
380
  payTokenAddress: USDC.address,
379
381
  payTokenAmount: (0, numbers_1.parseValue)("1000", USDC.decimals), // 1000 USDC
380
382
  collateralTokenAddress: WETH.address,
@@ -52,3 +52,13 @@ const uiFeeReceiver_1 = require("../twap/uiFeeReceiver");
52
52
  });
53
53
  });
54
54
  });
55
+ (0, vitest_1.describe)("setUiFeeReceiverIsExpress", () => {
56
+ (0, vitest_1.it)("should correctly set isExpress for simple uiFeeReceiver", () => {
57
+ (0, vitest_1.expect)((0, uiFeeReceiver_1.setUiFeeReceiverIsExpress)("0xff00000000000000000000000000000000000001", true)).toEqual("0xff00000000000000000000000000000100000001");
58
+ (0, vitest_1.expect)((0, uiFeeReceiver_1.setUiFeeReceiverIsExpress)("0xff00000000000000000000000000000000000001", false)).toEqual("0xff00000000000000000000000000000000000001");
59
+ });
60
+ (0, vitest_1.it)("should correctly set isExpress for twap uiFeeReceiver", () => {
61
+ (0, vitest_1.expect)((0, uiFeeReceiver_1.setUiFeeReceiverIsExpress)("0xff0000000000000000000000000000000a123401", true)).toEqual("0xff0000000000000000000000000000010a123401");
62
+ (0, vitest_1.expect)((0, uiFeeReceiver_1.setUiFeeReceiverIsExpress)("0xff0000000000000000000000000000000a123401", false)).toEqual("0xff0000000000000000000000000000000a123401");
63
+ });
64
+ });
@@ -20,6 +20,8 @@ const TX_ERROR_PATTERNS = {
20
20
  { msg: "User denied transaction signature" },
21
21
  { msg: "User rejected" },
22
22
  { msg: "User cancelled" },
23
+ { msg: "Cancelled" },
24
+ { msg: "Cancelled by user" },
23
25
  { msg: "user rejected action" },
24
26
  { msg: "ethers-user-denied" },
25
27
  { msg: "Action cancelled by user" },
@@ -29,7 +31,11 @@ const TX_ERROR_PATTERNS = {
29
31
  { msg: "Router: mark price lower than limit" },
30
32
  { msg: "Router: mark price higher than limit" },
31
33
  ],
32
- [TxErrorType.NetworkChanged]: [{ msg: "network changed" }, { msg: "Invalid network" }],
34
+ [TxErrorType.NetworkChanged]: [
35
+ { msg: "network changed" },
36
+ { msg: "Invalid network" },
37
+ { msg: "chainId should be same" },
38
+ ],
33
39
  [TxErrorType.Expired]: [{ msg: "Request expired" }],
34
40
  [TxErrorType.RpcError]: [
35
41
  // @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
@@ -380,7 +380,6 @@ function buildTokenTransfersParamsForIncreaseOrSwap({ chainId, receiver, payToke
380
380
  * */
381
381
  initialCollateralTokenAddress = (0, tokens_1.convertTokenAddress)(chainId, externalSwapQuote.outTokenAddress, "wrapped");
382
382
  initialCollateralDeltaAmount = 0n;
383
- swapPath = [];
384
383
  externalCalls = getExternalCallsPayload({
385
384
  chainId,
386
385
  account: receiver,
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBotanixStakingExternalSwapQuote = void 0;
7
+ const viem_1 = require("viem");
8
+ const StBTC_json_1 = __importDefault(require("../../abis/StBTC.json"));
9
+ const chains_1 = require("../../configs/chains");
10
+ const contracts_1 = require("../../configs/contracts");
11
+ const trade_1 = require("../../types/trade");
12
+ const bigmath_1 = require("../bigmath");
13
+ const numbers_1 = require("../numbers");
14
+ const externalSwapPath_1 = require("./externalSwapPath");
15
+ const tokens_1 = require("../tokens");
16
+ const COEF_REDUCER = (0, numbers_1.getBasisPoints)(1n, 10000n);
17
+ const getBotanixStakingExternalSwapQuote = ({ tokenInAddress, tokenOutAddress, amountIn, gasPrice, receiverAddress, tokensData, assetsPerShare, }) => {
18
+ const inTokenData = (0, tokens_1.getTokenData)(tokensData, tokenInAddress);
19
+ const outTokenData = (0, tokens_1.getTokenData)(tokensData, tokenOutAddress);
20
+ const assetsPerShareRate = (0, numbers_1.getBasisPoints)(assetsPerShare, 10n ** 18n) - COEF_REDUCER;
21
+ const sharesPerAssetRate = (0, numbers_1.getBasisPoints)(10n ** 18n, assetsPerShare) - COEF_REDUCER;
22
+ if (!inTokenData || !outTokenData) {
23
+ return undefined;
24
+ }
25
+ if (externalSwapPath_1.AVAILABLE_BOTANIX_DEPOSIT_PAIRS.some((pair) => pair.from === tokenInAddress && pair.to === tokenOutAddress)) {
26
+ const priceIn = (0, tokens_1.getMidPrice)(inTokenData.prices);
27
+ const priceOut = bigmath_1.bigMath.mulDiv(priceIn, sharesPerAssetRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT);
28
+ const usdIn = (0, tokens_1.convertToUsd)(amountIn, inTokenData.decimals, priceIn);
29
+ const amountOut = amountIn > 0n ? bigmath_1.bigMath.mulDiv(amountIn, sharesPerAssetRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT) - gasPrice : 0n;
30
+ const usdOut = amountOut > 0n ? (0, tokens_1.convertToUsd)(amountOut, outTokenData.decimals, priceOut) : 0n;
31
+ return {
32
+ aggregator: trade_1.ExternalSwapAggregator.BotanixStaking,
33
+ inTokenAddress: tokenInAddress,
34
+ outTokenAddress: tokenOutAddress,
35
+ receiver: receiverAddress,
36
+ amountIn,
37
+ amountOut,
38
+ usdIn: usdIn,
39
+ usdOut: usdOut,
40
+ priceIn,
41
+ priceOut,
42
+ feesUsd: gasPrice,
43
+ needSpenderApproval: true,
44
+ txnData: {
45
+ to: (0, contracts_1.getContract)(chains_1.BOTANIX, "StBTC"),
46
+ data: (0, viem_1.encodeFunctionData)({
47
+ abi: StBTC_json_1.default.abi,
48
+ functionName: "deposit",
49
+ args: [amountIn, receiverAddress],
50
+ }),
51
+ value: 0n,
52
+ estimatedGas: gasPrice,
53
+ estimatedExecutionFee: gasPrice,
54
+ },
55
+ };
56
+ }
57
+ if (externalSwapPath_1.AVAILABLE_BOTANIX_WITHDRAW_PAIRS.some((pair) => pair.from === tokenInAddress && pair.to === tokenOutAddress)) {
58
+ const priceIn = (0, tokens_1.getMidPrice)(inTokenData.prices);
59
+ const priceOut = bigmath_1.bigMath.mulDiv(priceIn, assetsPerShareRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT);
60
+ const usdIn = (0, tokens_1.convertToUsd)(amountIn, inTokenData.decimals, priceIn);
61
+ const amountOut = amountIn > 0n ? bigmath_1.bigMath.mulDiv(amountIn, assetsPerShareRate, numbers_1.BASIS_POINTS_DIVISOR_BIGINT) - gasPrice : 0n;
62
+ const usdOut = amountOut > 0n ? (0, tokens_1.convertToUsd)(amountOut, outTokenData.decimals, priceOut) : 0n;
63
+ return {
64
+ aggregator: trade_1.ExternalSwapAggregator.BotanixStaking,
65
+ inTokenAddress: tokenInAddress,
66
+ outTokenAddress: tokenOutAddress,
67
+ receiver: receiverAddress,
68
+ amountIn,
69
+ amountOut,
70
+ usdIn: usdIn,
71
+ usdOut: usdOut,
72
+ priceIn,
73
+ priceOut,
74
+ feesUsd: gasPrice,
75
+ needSpenderApproval: true,
76
+ txnData: {
77
+ to: (0, contracts_1.getContract)(chains_1.BOTANIX, "StBTC"),
78
+ data: (0, viem_1.encodeFunctionData)({
79
+ abi: StBTC_json_1.default.abi,
80
+ functionName: "withdraw",
81
+ args: [amountIn, receiverAddress, (0, contracts_1.getContract)(chains_1.BOTANIX, "ExternalHandler")],
82
+ }),
83
+ value: 0n,
84
+ estimatedGas: gasPrice,
85
+ estimatedExecutionFee: gasPrice,
86
+ },
87
+ };
88
+ }
89
+ };
90
+ exports.getBotanixStakingExternalSwapQuote = getBotanixStakingExternalSwapQuote;
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildReverseSwapStrategy = exports.buildSwapStrategy = void 0;
4
+ const bigmath_1 = require("../bigmath");
5
+ const tokens_1 = require("../tokens");
6
+ const externalSwapPath_1 = require("./externalSwapPath");
7
+ const externalSwapQuoteByPath_1 = require("./externalSwapQuoteByPath");
8
+ const swapPath_1 = require("./swapPath");
9
+ /*
10
+ Order/Priority of getting swap strategy:
11
+ 1. Check if it needs a swap and return noSwap if tokens are equivalent, stake or unstake [noSwap]
12
+ 2. Check if there is a swap path stats for the internal swap quote and return internalSwap if there is [internalSwap]
13
+ 3. Check if there is a combined swap strategy and return combinedSwap if there is [combinedSwap]
14
+ 4. Return defaultSwapStrategy (noSwap) if there is no other swap strategy [noSwap]
15
+ */
16
+ function buildSwapStrategy({ amountIn, tokenIn, tokenOut, marketsInfoData, chainId, swapOptimizationOrder, externalSwapQuoteParams, }) {
17
+ const priceIn = tokenIn.prices.minPrice;
18
+ const usdIn = (0, tokens_1.convertToUsd)(amountIn, tokenIn.decimals, priceIn);
19
+ if (amountIn < 0n) {
20
+ amountIn = 0n;
21
+ }
22
+ const defaultSwapStrategy = {
23
+ type: "noSwap",
24
+ externalSwapQuote: undefined,
25
+ swapPathStats: undefined,
26
+ amountIn,
27
+ amountOut: (0, tokens_1.convertToTokenAmount)(usdIn, tokenOut.decimals, tokenOut.prices.maxPrice),
28
+ usdIn,
29
+ usdOut: usdIn,
30
+ priceIn,
31
+ priceOut: tokenOut.prices.maxPrice,
32
+ feesUsd: 0n,
33
+ };
34
+ if ((0, tokens_1.getIsEquivalentTokens)(tokenIn, tokenOut) || (0, tokens_1.getIsStake)(tokenIn, tokenOut) || (0, tokens_1.getIsUnstake)(tokenIn, tokenOut)) {
35
+ return defaultSwapStrategy;
36
+ }
37
+ const findSwapPath = (0, swapPath_1.createFindSwapPath)({
38
+ chainId,
39
+ fromTokenAddress: tokenIn.address,
40
+ toTokenAddress: tokenOut.address,
41
+ marketsInfoData,
42
+ isExpressFeeSwap: false,
43
+ });
44
+ const swapPathStats = findSwapPath(usdIn, { order: swapOptimizationOrder });
45
+ if (swapPathStats) {
46
+ return {
47
+ type: "internalSwap",
48
+ swapPathStats,
49
+ externalSwapQuote: undefined,
50
+ amountIn,
51
+ amountOut: swapPathStats.amountOut,
52
+ usdIn: usdIn,
53
+ usdOut: swapPathStats.usdOut,
54
+ priceIn: priceIn,
55
+ priceOut: tokenOut.prices.maxPrice,
56
+ feesUsd: usdIn - swapPathStats.usdOut,
57
+ };
58
+ }
59
+ const availableExternalSwapPaths = (0, externalSwapPath_1.getAvailableExternalSwapPaths)({ chainId, fromTokenAddress: tokenIn.address });
60
+ const suitableSwapPath = availableExternalSwapPaths.find((path) => {
61
+ const findSwapPath = (0, swapPath_1.createFindSwapPath)({
62
+ chainId,
63
+ fromTokenAddress: path.outTokenAddress,
64
+ toTokenAddress: tokenOut.address,
65
+ marketsInfoData,
66
+ isExpressFeeSwap: false,
67
+ });
68
+ const swapPathStats = findSwapPath(usdIn);
69
+ return Boolean(swapPathStats);
70
+ });
71
+ if (suitableSwapPath && suitableSwapPath.outTokenAddress !== tokenOut.address) {
72
+ const externalSwapQuoteForCombinedSwap = (0, externalSwapQuoteByPath_1.getExternalSwapQuoteByPath)({
73
+ amountIn,
74
+ externalSwapPath: suitableSwapPath,
75
+ externalSwapQuoteParams,
76
+ });
77
+ const findSwapPathForSuitableSwapPath = (0, swapPath_1.createFindSwapPath)({
78
+ chainId,
79
+ fromTokenAddress: suitableSwapPath.outTokenAddress,
80
+ toTokenAddress: tokenOut.address,
81
+ marketsInfoData,
82
+ isExpressFeeSwap: false,
83
+ });
84
+ const swapPathStatsForCombinedSwap = externalSwapQuoteForCombinedSwap
85
+ ? findSwapPathForSuitableSwapPath(externalSwapQuoteForCombinedSwap.usdOut)
86
+ : undefined;
87
+ return externalSwapQuoteForCombinedSwap && swapPathStatsForCombinedSwap
88
+ ? {
89
+ type: "combinedSwap",
90
+ externalSwapQuote: externalSwapQuoteForCombinedSwap,
91
+ swapPathStats: swapPathStatsForCombinedSwap,
92
+ amountIn,
93
+ amountOut: swapPathStatsForCombinedSwap.amountOut,
94
+ usdIn: externalSwapQuoteForCombinedSwap.usdIn,
95
+ usdOut: swapPathStatsForCombinedSwap.usdOut,
96
+ priceIn: externalSwapQuoteForCombinedSwap.priceIn,
97
+ priceOut: tokenOut.prices.maxPrice,
98
+ feesUsd: externalSwapQuoteForCombinedSwap.usdIn - swapPathStatsForCombinedSwap.usdOut,
99
+ }
100
+ : defaultSwapStrategy;
101
+ }
102
+ return defaultSwapStrategy;
103
+ }
104
+ exports.buildSwapStrategy = buildSwapStrategy;
105
+ // Used for getting swap amounts by to value
106
+ function buildReverseSwapStrategy({ amountOut, tokenIn, tokenOut, marketsInfoData, chainId, externalSwapQuoteParams, swapOptimizationOrder, }) {
107
+ const priceIn = (0, tokens_1.getMidPrice)(tokenIn.prices);
108
+ const priceOut = (0, tokens_1.getMidPrice)(tokenOut.prices);
109
+ const preferredUsdOut = (0, tokens_1.convertToUsd)(amountOut, tokenOut.decimals, (0, tokens_1.getMidPrice)(tokenOut.prices));
110
+ const approximateAmountIn = (0, tokens_1.convertToTokenAmount)(preferredUsdOut, tokenIn.decimals, (0, tokens_1.getMidPrice)(tokenIn.prices));
111
+ const approximateUsdIn = preferredUsdOut;
112
+ const defaultSwapStrategy = {
113
+ type: "noSwap",
114
+ externalSwapQuote: undefined,
115
+ swapPathStats: undefined,
116
+ amountIn: approximateAmountIn,
117
+ amountOut: amountOut,
118
+ usdIn: approximateUsdIn,
119
+ usdOut: preferredUsdOut,
120
+ priceIn,
121
+ priceOut,
122
+ feesUsd: 0n,
123
+ };
124
+ if ((0, tokens_1.getIsEquivalentTokens)(tokenIn, tokenOut) || (0, tokens_1.getIsStake)(tokenIn, tokenOut) || (0, tokens_1.getIsUnstake)(tokenIn, tokenOut)) {
125
+ return defaultSwapStrategy;
126
+ }
127
+ const findSwapPath = (0, swapPath_1.createFindSwapPath)({
128
+ chainId,
129
+ fromTokenAddress: tokenIn.address,
130
+ toTokenAddress: tokenOut.address,
131
+ marketsInfoData,
132
+ isExpressFeeSwap: false,
133
+ });
134
+ const approximateSwapPathStats = findSwapPath(approximateUsdIn, { order: swapOptimizationOrder });
135
+ if (approximateSwapPathStats) {
136
+ // Increase or decrease usdIn the same way preferred usdOut is different from swapStrategy.usdOut
137
+ // preferred_in / approximate_in = preferred_out / approximate_out
138
+ // preferred_in = approximate_in * preferred_out / approximate_out
139
+ const adjustedUsdIn = approximateSwapPathStats.usdOut > 0
140
+ ? bigmath_1.bigMath.mulDiv(approximateUsdIn, preferredUsdOut, approximateSwapPathStats.usdOut)
141
+ : 0n;
142
+ const adjustedAmountIn = (0, tokens_1.convertToTokenAmount)(adjustedUsdIn, tokenIn.decimals, (0, tokens_1.getMidPrice)(tokenIn.prices));
143
+ const adjustedSwapPathStats = findSwapPath(adjustedUsdIn, { order: swapOptimizationOrder });
144
+ if (adjustedSwapPathStats) {
145
+ return {
146
+ type: "internalSwap",
147
+ swapPathStats: adjustedSwapPathStats,
148
+ externalSwapQuote: undefined,
149
+ amountIn: adjustedAmountIn,
150
+ amountOut: adjustedSwapPathStats.amountOut,
151
+ usdIn: adjustedUsdIn,
152
+ usdOut: adjustedSwapPathStats.usdOut,
153
+ priceIn: priceIn,
154
+ priceOut: priceOut,
155
+ feesUsd: adjustedUsdIn - adjustedSwapPathStats.usdOut,
156
+ };
157
+ }
158
+ }
159
+ const availableExternalSwapPaths = (0, externalSwapPath_1.getAvailableExternalSwapPaths)({ chainId, fromTokenAddress: tokenIn.address });
160
+ const suitableSwapPath = availableExternalSwapPaths.find((path) => {
161
+ if (path.outTokenAddress !== tokenOut.address)
162
+ return false;
163
+ const findSwapPath = (0, swapPath_1.createFindSwapPath)({
164
+ chainId,
165
+ fromTokenAddress: tokenIn.address,
166
+ toTokenAddress: path.inTokenAddress,
167
+ marketsInfoData,
168
+ isExpressFeeSwap: false,
169
+ });
170
+ const swapPathStats = findSwapPath(approximateUsdIn);
171
+ return Boolean(swapPathStats);
172
+ });
173
+ if (suitableSwapPath) {
174
+ const approximateExternalSwapQuoteForCombinedSwap = (0, externalSwapQuoteByPath_1.getExternalSwapQuoteByPath)({
175
+ amountIn: approximateAmountIn,
176
+ externalSwapPath: suitableSwapPath,
177
+ externalSwapQuoteParams,
178
+ });
179
+ if (!approximateExternalSwapQuoteForCombinedSwap) {
180
+ return defaultSwapStrategy;
181
+ }
182
+ const findSwapPathForSuitableSwapPath = (0, swapPath_1.createFindSwapPath)({
183
+ chainId,
184
+ fromTokenAddress: tokenIn.address,
185
+ toTokenAddress: suitableSwapPath.inTokenAddress,
186
+ marketsInfoData,
187
+ isExpressFeeSwap: false,
188
+ });
189
+ const approximateSwapPathStatsForCombinedSwap = findSwapPathForSuitableSwapPath(approximateExternalSwapQuoteForCombinedSwap.usdOut);
190
+ if (!approximateSwapPathStatsForCombinedSwap) {
191
+ return defaultSwapStrategy;
192
+ }
193
+ const adjustedUsdIn = approximateSwapPathStatsForCombinedSwap.usdOut > 0
194
+ ? bigmath_1.bigMath.mulDiv(approximateUsdIn, preferredUsdOut, approximateSwapPathStatsForCombinedSwap.usdOut)
195
+ : 0n;
196
+ const adjustedAmountIn = (0, tokens_1.convertToTokenAmount)(adjustedUsdIn, tokenIn.decimals, (0, tokens_1.getMidPrice)(tokenIn.prices));
197
+ const adjustedExternalSwapQuoteForCombinedSwap = (0, externalSwapQuoteByPath_1.getExternalSwapQuoteByPath)({
198
+ amountIn: adjustedAmountIn,
199
+ externalSwapPath: suitableSwapPath,
200
+ externalSwapQuoteParams,
201
+ });
202
+ if (!adjustedExternalSwapQuoteForCombinedSwap) {
203
+ return defaultSwapStrategy;
204
+ }
205
+ const adjustedSwapPathStatsForCombinedSwap = findSwapPathForSuitableSwapPath(adjustedExternalSwapQuoteForCombinedSwap.usdOut);
206
+ if (!adjustedSwapPathStatsForCombinedSwap) {
207
+ return defaultSwapStrategy;
208
+ }
209
+ return {
210
+ type: "combinedSwap",
211
+ externalSwapQuote: adjustedExternalSwapQuoteForCombinedSwap,
212
+ swapPathStats: adjustedSwapPathStatsForCombinedSwap,
213
+ amountIn: adjustedAmountIn,
214
+ amountOut: adjustedSwapPathStatsForCombinedSwap.amountOut,
215
+ usdIn: adjustedExternalSwapQuoteForCombinedSwap.usdIn,
216
+ usdOut: adjustedSwapPathStatsForCombinedSwap.usdOut,
217
+ priceIn: adjustedExternalSwapQuoteForCombinedSwap.priceIn,
218
+ priceOut: priceOut,
219
+ feesUsd: adjustedExternalSwapQuoteForCombinedSwap.usdIn - adjustedSwapPathStatsForCombinedSwap.usdOut,
220
+ };
221
+ }
222
+ return defaultSwapStrategy;
223
+ }
224
+ exports.buildReverseSwapStrategy = buildReverseSwapStrategy;