@reyaxyz/common 0.344.0 → 0.344.1-perpob.135

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 (85) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/exposure/command.js +8 -22
  3. package/dist/commands/exposure/command.js.map +1 -1
  4. package/dist/incentives-api-types.js.map +1 -1
  5. package/dist/rest/helpers/constants.js +12 -0
  6. package/dist/rest/helpers/constants.js.map +1 -1
  7. package/dist/trading-api-types.js.map +1 -1
  8. package/dist/transactions/abis/Errors.json +276 -1
  9. package/dist/transactions/abis/OrdersGateway.json +691 -119
  10. package/dist/transactions/abis/PassivePerpProxy.json +537 -0
  11. package/dist/transactions/buildMulticallTx.js.map +1 -1
  12. package/dist/transactions/contractAddresses.js +33 -4
  13. package/dist/transactions/contractAddresses.js.map +1 -1
  14. package/dist/transactions/executeTransaction.js +8 -123
  15. package/dist/transactions/executeTransaction.js.map +1 -1
  16. package/dist/transactions/sign.js +234 -1
  17. package/dist/transactions/sign.js.map +1 -1
  18. package/dist/types/commands/exposure/command.d.ts +8 -7
  19. package/dist/types/commands/exposure/command.d.ts.map +1 -1
  20. package/dist/types/incentives-api-types.d.ts +6 -2
  21. package/dist/types/incentives-api-types.d.ts.map +1 -1
  22. package/dist/types/rest/helpers/constants.d.ts +1 -1
  23. package/dist/types/rest/helpers/constants.d.ts.map +1 -1
  24. package/dist/types/trading-api-types.d.ts +123 -31
  25. package/dist/types/trading-api-types.d.ts.map +1 -1
  26. package/dist/types/transactions/buildMulticallTx.d.ts +1 -0
  27. package/dist/types/transactions/buildMulticallTx.d.ts.map +1 -1
  28. package/dist/types/transactions/contractAddresses.d.ts +1 -1
  29. package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
  30. package/dist/types/transactions/executeTransaction.d.ts +2 -15
  31. package/dist/types/transactions/executeTransaction.d.ts.map +1 -1
  32. package/dist/types/transactions/sign.d.ts +38 -1
  33. package/dist/types/transactions/sign.d.ts.map +1 -1
  34. package/dist/types/types.d.ts +44 -18
  35. package/dist/types/types.d.ts.map +1 -1
  36. package/dist/types/utils/calculate.d.ts +14 -2
  37. package/dist/types/utils/calculate.d.ts.map +1 -1
  38. package/dist/types/utils/layerzero.d.ts +22 -0
  39. package/dist/types/utils/layerzero.d.ts.map +1 -0
  40. package/dist/types/utils/token/batch-token-getters.d.ts +0 -5
  41. package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -1
  42. package/dist/types/utils/token/token-getters.d.ts +0 -2
  43. package/dist/types/utils/token/token-getters.d.ts.map +1 -1
  44. package/dist/types.js +51 -7
  45. package/dist/types.js.map +1 -1
  46. package/dist/utils/calculate.js +137 -16
  47. package/dist/utils/calculate.js.map +1 -1
  48. package/dist/utils/layerzero.js +31 -0
  49. package/dist/utils/layerzero.js.map +1 -0
  50. package/dist/utils/token/batch-token-getters.js +13 -64
  51. package/dist/utils/token/batch-token-getters.js.map +1 -1
  52. package/dist/utils/token/token-getters.js +1 -42
  53. package/dist/utils/token/token-getters.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/commands/exposure/command.ts +8 -38
  56. package/src/incentives-api-types.ts +11 -5
  57. package/src/rest/helpers/constants.ts +22 -0
  58. package/src/trading-api-types.ts +128 -47
  59. package/src/transactions/abis/Errors.json +4148 -3873
  60. package/src/transactions/abis/OrdersGateway.json +692 -120
  61. package/src/transactions/abis/PassivePerpProxy.json +537 -0
  62. package/src/transactions/buildMulticallTx.ts +4 -0
  63. package/src/transactions/contractAddresses.ts +34 -4
  64. package/src/transactions/executeTransaction.ts +2 -130
  65. package/src/transactions/sign.ts +302 -0
  66. package/src/types.ts +70 -19
  67. package/src/utils/calculate.ts +181 -21
  68. package/src/utils/layerzero.ts +66 -0
  69. package/src/utils/token/batch-token-getters.ts +0 -28
  70. package/src/utils/token/token-getters.ts +0 -29
  71. package/dist/types/utils/layerzero/index.d.ts +0 -3
  72. package/dist/types/utils/layerzero/index.d.ts.map +0 -1
  73. package/dist/types/utils/layerzero/oft-config.d.ts +0 -4
  74. package/dist/types/utils/layerzero/oft-config.d.ts.map +0 -1
  75. package/dist/types/utils/layerzero/types.d.ts +0 -23
  76. package/dist/types/utils/layerzero/types.d.ts.map +0 -1
  77. package/dist/utils/layerzero/index.js +0 -19
  78. package/dist/utils/layerzero/index.js.map +0 -1
  79. package/dist/utils/layerzero/oft-config.js +0 -29
  80. package/dist/utils/layerzero/oft-config.js.map +0 -1
  81. package/dist/utils/layerzero/types.js +0 -3
  82. package/dist/utils/layerzero/types.js.map +0 -1
  83. package/src/utils/layerzero/index.ts +0 -2
  84. package/src/utils/layerzero/oft-config.ts +0 -32
  85. package/src/utils/layerzero/types.ts +0 -25
@@ -919,44 +919,6 @@ export class ExposureCommand {
919
919
  );
920
920
  }
921
921
 
922
- /**
923
- * @audit This function uses a linear approximation that is not aligned with the on-chain
924
- * exponential logPriceMultiplier pricing logic (PriceMultiplier.sol). The intention is to
925
- * deprecate this function completely once downstream consumers (PoolLiquidityCommand,
926
- * updateLiquidity.task, marketDataLiquidity.task) are migrated.
927
- */
928
- getSlippage(
929
- deltaBase: number,
930
- marketConfiguration: MarketConfiguration,
931
- marketStorage: MarketStorage,
932
- ): number {
933
- const deltaExposure = BigNumber(
934
- this.oraclePricePerMarket[marketConfiguration.market_id],
935
- )
936
- .times(deltaBase)
937
- .toNumber();
938
-
939
- const riskMatrixIndex = BigNumber(
940
- String(marketConfiguration.risk_matrix_index),
941
- ).toNumber();
942
-
943
- // isPool is true as we only get slippage for the pool
944
- const { maxExposureShort, maxExposureLong, exposures } =
945
- this.getMaxExposure(marketConfiguration, marketStorage, true);
946
-
947
- const netExposure = exposures[riskMatrixIndex].plus(deltaExposure);
948
- const maxExposure = netExposure.lt(0) ? maxExposureShort : maxExposureLong;
949
-
950
- return BigNumber(netExposure)
951
- .negated()
952
- .div(
953
- BigNumber(maxExposure)
954
- .times(amountNormalizer(marketConfiguration.depth_factor))
955
- .plus(netExposure),
956
- )
957
- .toNumber();
958
- }
959
-
960
922
  getMaxExposure(
961
923
  marketConfiguration: MarketConfiguration,
962
924
  marketStorage: MarketStorage,
@@ -1228,6 +1190,10 @@ export class ExposureCommand {
1228
1190
  return clampFundingRate(lastFundingRate.plus(fundingRateDelta));
1229
1191
  }
1230
1192
 
1193
+ /**
1194
+ * @deprecated OB model reads funding rate directly from FundingRateProvider.
1195
+ * Remains for legacy AMM model consumers. To be removed in a future cleanup PR.
1196
+ */
1231
1197
  static getCurrentHourlyFundingRate(
1232
1198
  last_funding_timestamp: BigNumber,
1233
1199
  lastFundingVelocity: BigNumber,
@@ -1276,6 +1242,10 @@ export class ExposureCommand {
1276
1242
  return areaDelta.times(price).times(baseMultiplier);
1277
1243
  }
1278
1244
 
1245
+ /**
1246
+ * @deprecated OB model reads funding value directly from market trackers.
1247
+ * Remains for legacy AMM model consumers. To be removed in a future cleanup PR.
1248
+ */
1279
1249
  static getCurrentFundingValue(
1280
1250
  spotPrice: BigNumber,
1281
1251
  lastFundingValue: BigNumber,
@@ -102,11 +102,17 @@ export type LeaderBoardParams = { type: 'weekly' | 'total' };
102
102
 
103
103
  export type TradingCompetitionRoundParams = { round: number };
104
104
 
105
- export type TradingCompetitionUserSummaryData = {
106
- realizedPnl: number;
107
- eligible: boolean;
108
- position: number | null;
109
- };
105
+ export type TradingCompetitionUserSummaryData =
106
+ | {
107
+ status: 'out';
108
+ }
109
+ | {
110
+ status: 'in';
111
+ realizedPnl: number;
112
+ position: number;
113
+ volume: number;
114
+ volumePosition: number;
115
+ };
110
116
 
111
117
  export type TradingCompetitionLeaderboardEntry = {
112
118
  walletAddress: string;
@@ -5,6 +5,7 @@ export type ServiceEnvironment =
5
5
  | 'production'
6
6
  | 'staging'
7
7
  | 'test'
8
+ | 'devnet'
8
9
  | 'localmainnet'
9
10
  | 'localtestnet';
10
11
 
@@ -92,6 +93,27 @@ const API_CLIENT_CONFIGS: Record<ServiceEnvironment, ServiceConfig> = {
92
93
  timeout: API_TIMEOUT,
93
94
  logging: true,
94
95
  },
96
+ // Devnet1 shares the cronos chain (89346162) but has its own
97
+ // sub-deploy at `reya-cronos.network` (distinct from `reya.xyz`).
98
+ // Added so UIs can offer "devnet" as a first-class environment
99
+ // selection rather than overriding `test`'s default endpoint.
100
+ devnet: {
101
+ chain: ReyaChainId.reyaCronos,
102
+ apiEndpoint: getEnvVar(
103
+ 'NEXT_PUBLIC_REYA_API_ENDPOINT',
104
+ 'https://api-devnet.reya-cronos.network',
105
+ ),
106
+ webSocketEndpoint: getEnvVar(
107
+ 'NEXT_PUBLIC_REYA_WEBSOCKET_ENDPOINT',
108
+ 'wss://websocket-devnet.reya-cronos.network',
109
+ ),
110
+ environment: getEnvVar(
111
+ 'NEXT_PUBLIC_REYA_ENVIRONMENT',
112
+ 'devnet',
113
+ ) as ServiceEnvironment,
114
+ timeout: API_TIMEOUT,
115
+ logging: true,
116
+ },
95
117
  };
96
118
 
97
119
  export const getApiClientConfig = (env: ServiceEnvironment): ServiceConfig => {
@@ -1,5 +1,5 @@
1
1
  import { ParamsDictionary, Query } from 'express-serve-static-core';
2
- import { AssetPair, CollateralPrice, MarketPrice } from './types';
2
+ import { Address, AssetPair, CollateralPrice, MarketPrice } from './types';
3
3
  import {
4
4
  AddressParam,
5
5
  ApiEndpoint,
@@ -30,6 +30,7 @@ type Candle = {
30
30
  resolution: CandleResolution;
31
31
  };
32
32
 
33
+ // Used only for PerpExecutionReplicationData (replication:orders messages)
33
34
  type Order = {
34
35
  id: string;
35
36
  market_id: Decimal | null;
@@ -54,6 +55,11 @@ type Order = {
54
55
  counterparty_funding_value: Decimal | null;
55
56
  counterparty_last_price: Decimal | null;
56
57
  counterparty_last_price_timestamp: Decimal | null;
58
+ counterparty_previous_average_entry_funding_value: Decimal | null;
59
+ counterparty_previous_base_multiplier: Decimal | null;
60
+ counterparty_previous_funding_value: Decimal | null;
61
+ counterparty_previous_last_price: Decimal | null;
62
+ counterparty_previous_realized_pnl: Decimal | null;
57
63
  counterparty_realized_pnl: Decimal | null;
58
64
  counterparty_session: Decimal | null;
59
65
  position_adl_unwind_price: Decimal | null;
@@ -73,6 +79,13 @@ type Order = {
73
79
  position_session: Decimal | null;
74
80
  referrer_account_id: Decimal | null;
75
81
  referrer_fee_credit: Decimal | null;
82
+ // V3 fields
83
+ protocol_fee_credit: Decimal | null;
84
+ exchange_fee_credit: Decimal | null;
85
+ maker_fee_credit: Decimal | null;
86
+ maker_fee_debit: Decimal | null;
87
+ account_order_id: bigint | null;
88
+ counterparty_order_id: bigint | null;
76
89
  };
77
90
 
78
91
  type Position = {
@@ -124,20 +137,6 @@ type ConditionalOrderSensitive = ConditionalOrder & {
124
137
  signature: string;
125
138
  };
126
139
 
127
- type Market = {
128
- id: Decimal;
129
- assetPairId: AssetPair;
130
- ticker: string;
131
- isActive: boolean;
132
- maxLeverage: number;
133
- description: string;
134
- name: string;
135
- tickSizeDecimals: number;
136
- priority: number;
137
- underlyingAssetId: string;
138
- quoteTokenId: string;
139
- };
140
-
141
140
  type Account = {
142
141
  account_id: Decimal;
143
142
  name: string;
@@ -277,6 +276,10 @@ type MarketTrackers = {
277
276
  price_spread: Decimal | null;
278
277
  depth_factor: Decimal | null;
279
278
  log_price_multiplier: Decimal | null;
279
+ mark_price: Decimal | null;
280
+ mark_price_timestamp: Decimal | null;
281
+ funding_rate: Decimal | null;
282
+ funding_rate_timestamp: Decimal | null;
280
283
  };
281
284
 
282
285
  export type TradingApiReplication<
@@ -335,7 +338,6 @@ export type TradingApiSource = {
335
338
  { address: string },
336
339
  'accountLeveragePerMarket'
337
340
  >;
338
- markets: TradingApiListEndpoint<Market>;
339
341
  'markets/data': TradingApiListEndpoint<MarketData, never, 'marketData'>;
340
342
  'spotMarkets/data': TradingApiListEndpoint<
341
343
  SpotMarketData,
@@ -388,12 +390,6 @@ export type TradingApiSource = {
388
390
  },
389
391
  'marketTrackers'
390
392
  >;
391
- 'market/:marketId': TradingApiEndpoint<
392
- Market,
393
- {
394
- marketId: string;
395
- }
396
- >;
397
393
  'market/:marketId/data': TradingApiEndpoint<
398
394
  MarketData,
399
395
  {
@@ -401,13 +397,6 @@ export type TradingApiSource = {
401
397
  },
402
398
  'marketData'
403
399
  >;
404
- 'market/:marketId/trades': TradingApiInfiniteListEndpoint<
405
- Order,
406
- {
407
- marketId: string;
408
- },
409
- 'orders'
410
- >;
411
400
  'wallet/:address/positions': TradingApiListEndpoint<
412
401
  Position,
413
402
  AddressParam,
@@ -473,21 +462,6 @@ export type TradingApiSource = {
473
462
  timestamp: string;
474
463
  }
475
464
  >;
476
- 'wallet/:address/trades': TradingApiInfiniteListEndpoint<
477
- Order,
478
- {
479
- address: string;
480
- },
481
- 'order_history'
482
- >;
483
- 'wallet/:address/trades/:type': TradingApiInfiniteListEndpoint<
484
- Order,
485
- {
486
- address: string;
487
- type?: 'matchOrder' | 'liquidation';
488
- },
489
- 'order_history'
490
- >;
491
465
  riskMatrices: TradingApiListEndpoint<
492
466
  {
493
467
  blockId: Decimal;
@@ -623,6 +597,12 @@ export type TradingApiSource = {
623
597
  address: string;
624
598
  }
625
599
  >;
600
+ 'collaterals/definitions': TradingApiEndpoint<
601
+ {
602
+ collaterals: CollateralDefinition[];
603
+ },
604
+ never
605
+ >;
626
606
  };
627
607
 
628
608
  export type Req<P = ParamsDictionary, ReqQuery = Query> = {
@@ -676,6 +656,7 @@ type account_owner_updated_snapshot = {
676
656
  block_timestamp: Decimal | null;
677
657
  block_number: Decimal;
678
658
  unique_id: bigint | null;
659
+ event_sequence_number: bigint | null;
679
660
  };
680
661
 
681
662
  type positions_migration = {
@@ -700,9 +681,10 @@ type positions_migration = {
700
681
  referrer_fee_credit: Decimal | null;
701
682
  };
702
683
 
703
- type spot_execution_bust = {
684
+ type execution_bust = {
704
685
  event_sequence_number: bigint;
705
- spot_market_id: Decimal;
686
+ market_id: Decimal;
687
+ market_type: string;
706
688
  account_id: Decimal;
707
689
  counterparty_account_id: Decimal;
708
690
  account_order_id: bigint;
@@ -741,7 +723,106 @@ type ReplicationMessage =
741
723
  'positions_migration'
742
724
  >
743
725
  | GenericReplicationMessage<spot_execution, 'spot_executions'>
744
- | GenericReplicationMessage<spot_execution_bust, 'spot_execution_busts'>;
726
+ | GenericReplicationMessage<Order, 'orders'>
727
+ | GenericReplicationMessage<execution_bust, 'execution_busts'>;
728
+
729
+ export type SocketDepositChainDetails = {
730
+ chainId: number;
731
+ chainName: string;
732
+ collateralAddress: Address;
733
+ collateralName: string;
734
+ collateralAddressInReyaPeriphery: Address;
735
+ vaultAddress: Address;
736
+ connectorAddress: Address;
737
+ msgGasLimit: string;
738
+ bridgeTime: number;
739
+ };
740
+
741
+ export type SocketWithdrawChainDetails = {
742
+ chainId: number;
743
+ chainName: string;
744
+ collateralAddress: Address;
745
+ collateralName: string;
746
+ collateralAddressInReyaCore: Address;
747
+ msgGasLimit: string;
748
+ bridgeFee: string;
749
+ bridgeTime: number;
750
+ };
751
+
752
+ export type LayerzeroDepositChainDetails = {
753
+ chainId: number;
754
+ chainName: string;
755
+ collateralAddress: Address;
756
+ collateralName: string;
757
+ collateralAddressInReyaPeriphery: Address;
758
+ dstEid: number;
759
+ extraOptions: string;
760
+ bridgeTime: number;
761
+ };
762
+
763
+ export type LayerzeroWithdrawChainDetails = {
764
+ chainId: number;
765
+ chainName: string;
766
+ collateralAddress: Address;
767
+ collateralName: string;
768
+ collateralAddressInReyaCore: Address;
769
+ dstEid: number;
770
+ bridgeFee: string;
771
+ bridgeTime: number;
772
+ };
773
+
774
+ export type SocketDepositInfo =
775
+ | { enabled: false }
776
+ | { enabled: true; chains: SocketDepositChainDetails[]; minAmount: number };
777
+
778
+ export type SocketWithdrawInfo =
779
+ | { enabled: false }
780
+ | { enabled: true; chains: SocketWithdrawChainDetails[]; minAmount: number };
781
+
782
+ export type LayerzeroDepositInfo =
783
+ | { enabled: false }
784
+ | {
785
+ enabled: true;
786
+ minAmount: number;
787
+ chains: LayerzeroDepositChainDetails[];
788
+ };
789
+
790
+ export type LayerzeroWithdrawInfo =
791
+ | { enabled: false }
792
+ | {
793
+ enabled: true;
794
+ minAmount: number;
795
+ chains: LayerzeroWithdrawChainDetails[];
796
+ };
797
+
798
+ export type TransferInfo = { enabled: boolean };
799
+
800
+ export type SpotInfo =
801
+ | { enabled: false }
802
+ | { enabled: true; spotMarketSymbol: string };
803
+
804
+ export type DisplayInfo = {
805
+ advertisedInSpot: boolean;
806
+ advertisedInPerp: boolean;
807
+ displayName: string;
808
+ displayDecimals: number;
809
+ };
810
+
811
+ export type CollateralDefinition = {
812
+ id: Uppercase<string>;
813
+ address: Address;
814
+ assetPairId: string;
815
+ priceHaircut: string;
816
+ liquidationDiscount: string;
817
+ decimals: number;
818
+ socketDepositInfo: SocketDepositInfo;
819
+ socketWithdrawInfo: SocketWithdrawInfo;
820
+ layerzeroDepositInfo: LayerzeroDepositInfo;
821
+ layerzeroWithdrawInfo: LayerzeroWithdrawInfo;
822
+ transferInfo: TransferInfo;
823
+ spotInfo: SpotInfo;
824
+ displayInfo: DisplayInfo;
825
+ };
745
826
 
746
827
  export type Replication = {
747
828
  [K in ReplicationMessage as `replication:${K['model']}`]: Extract<