@reyaxyz/common 0.362.1 → 0.363.0

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 (104) 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/services/getNativeToken.js +1 -0
  6. package/dist/services/getNativeToken.js.map +1 -1
  7. package/dist/services/getSocketAddresses.js +1 -0
  8. package/dist/services/getSocketAddresses.js.map +1 -1
  9. package/dist/trading-api-types.js.map +1 -1
  10. package/dist/transactions/abis/Errors.json +1638 -34
  11. package/dist/transactions/abis/OrdersGateway.json +729 -123
  12. package/dist/transactions/abis/PassivePerpProxy.json +542 -0
  13. package/dist/transactions/buildMulticallTx.js.map +1 -1
  14. package/dist/transactions/consts.js +1 -2
  15. package/dist/transactions/consts.js.map +1 -1
  16. package/dist/transactions/contractAddresses.js +45 -5
  17. package/dist/transactions/contractAddresses.js.map +1 -1
  18. package/dist/transactions/sign.js +237 -111
  19. package/dist/transactions/sign.js.map +1 -1
  20. package/dist/types/commands/exposure/command.d.ts +8 -7
  21. package/dist/types/commands/exposure/command.d.ts.map +1 -1
  22. package/dist/types/incentives-api-types.d.ts +61 -5
  23. package/dist/types/incentives-api-types.d.ts.map +1 -1
  24. package/dist/types/services/getNativeToken.d.ts.map +1 -1
  25. package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
  26. package/dist/types/trading-api-types.d.ts +200 -32
  27. package/dist/types/trading-api-types.d.ts.map +1 -1
  28. package/dist/types/transactions/buildMulticallTx.d.ts +1 -0
  29. package/dist/types/transactions/buildMulticallTx.d.ts.map +1 -1
  30. package/dist/types/transactions/consts.d.ts +0 -1
  31. package/dist/types/transactions/consts.d.ts.map +1 -1
  32. package/dist/types/transactions/contractAddresses.d.ts +0 -1
  33. package/dist/types/transactions/contractAddresses.d.ts.map +1 -1
  34. package/dist/types/transactions/sign.d.ts +113 -9
  35. package/dist/types/transactions/sign.d.ts.map +1 -1
  36. package/dist/types/types.d.ts +61 -65
  37. package/dist/types/types.d.ts.map +1 -1
  38. package/dist/types/utils/calculate.d.ts.map +1 -1
  39. package/dist/types/utils/consts.d.ts +2 -2
  40. package/dist/types/utils/consts.d.ts.map +1 -1
  41. package/dist/types/utils/error-sanitizer.d.ts +15 -0
  42. package/dist/types/utils/error-sanitizer.d.ts.map +1 -0
  43. package/dist/types/utils/index.d.ts +3 -0
  44. package/dist/types/utils/index.d.ts.map +1 -1
  45. package/dist/types/utils/network.d.ts.map +1 -1
  46. package/dist/types/utils/number.d.ts +5 -0
  47. package/dist/types/utils/number.d.ts.map +1 -1
  48. package/dist/types/utils/realized-balance.d.ts +54 -0
  49. package/dist/types/utils/realized-balance.d.ts.map +1 -0
  50. package/dist/types/utils/throttled-error.d.ts +42 -0
  51. package/dist/types/utils/throttled-error.d.ts.map +1 -0
  52. package/dist/types/utils/token/normalize.d.ts +2 -1
  53. package/dist/types/utils/token/normalize.d.ts.map +1 -1
  54. package/dist/types/utils/token/token-info-getters.d.ts.map +1 -1
  55. package/dist/types/utils/token/token-info.d.ts.map +1 -1
  56. package/dist/types.js +25 -11
  57. package/dist/types.js.map +1 -1
  58. package/dist/utils/calculate.js +18 -9
  59. package/dist/utils/calculate.js.map +1 -1
  60. package/dist/utils/consts.js +2 -7
  61. package/dist/utils/consts.js.map +1 -1
  62. package/dist/utils/error-sanitizer.js +135 -0
  63. package/dist/utils/error-sanitizer.js.map +1 -0
  64. package/dist/utils/index.js +3 -0
  65. package/dist/utils/index.js.map +1 -1
  66. package/dist/utils/network.js +4 -0
  67. package/dist/utils/network.js.map +1 -1
  68. package/dist/utils/number.js +96 -1
  69. package/dist/utils/number.js.map +1 -1
  70. package/dist/utils/realized-balance.js +126 -0
  71. package/dist/utils/realized-balance.js.map +1 -0
  72. package/dist/utils/throttled-error.js +60 -0
  73. package/dist/utils/throttled-error.js.map +1 -0
  74. package/dist/utils/token/normalize.js +2 -2
  75. package/dist/utils/token/normalize.js.map +1 -1
  76. package/dist/utils/token/token-info-getters.js +80 -5
  77. package/dist/utils/token/token-info-getters.js.map +1 -1
  78. package/dist/utils/token/token-info.js +7 -0
  79. package/dist/utils/token/token-info.js.map +1 -1
  80. package/package.json +3 -3
  81. package/src/commands/exposure/command.ts +8 -38
  82. package/src/incentives-api-types.ts +60 -5
  83. package/src/services/getNativeToken.ts +1 -0
  84. package/src/services/getSocketAddresses.ts +1 -0
  85. package/src/trading-api-types.ts +258 -39
  86. package/src/transactions/abis/Errors.json +5478 -3874
  87. package/src/transactions/abis/OrdersGateway.json +730 -124
  88. package/src/transactions/abis/PassivePerpProxy.json +542 -0
  89. package/src/transactions/buildMulticallTx.ts +4 -0
  90. package/src/transactions/consts.ts +0 -1
  91. package/src/transactions/contractAddresses.ts +42 -7
  92. package/src/transactions/sign.ts +306 -150
  93. package/src/types.ts +98 -83
  94. package/src/utils/calculate.ts +21 -8
  95. package/src/utils/consts.ts +4 -16
  96. package/src/utils/error-sanitizer.ts +137 -0
  97. package/src/utils/index.ts +3 -0
  98. package/src/utils/network.ts +4 -0
  99. package/src/utils/number.ts +110 -0
  100. package/src/utils/realized-balance.ts +163 -0
  101. package/src/utils/throttled-error.ts +85 -0
  102. package/src/utils/token/normalize.ts +6 -1
  103. package/src/utils/token/token-info-getters.ts +104 -6
  104. package/src/utils/token/token-info.ts +42 -0
@@ -1 +1 @@
1
- {"version":3,"file":"trading-api-types.js","sourceRoot":"/","sources":["trading-api-types.ts"],"names":[],"mappings":";;;AAYa,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;CACjB,CAAC","sourcesContent":["import { ParamsDictionary, Query } from 'express-serve-static-core';\nimport { Address, AssetPair } from './types';\nimport {\n AddressParam,\n ApiEndpoint,\n ApiInfiniteListEndpoint,\n ApiListEndpoint,\n Decimal,\n PaginatedQueryParams,\n Stringified,\n} from './api-types';\n\nexport const AccountStatusValues = {\n OPEN: 'OPEN',\n CLOSED: 'CLOSED',\n};\n\nexport type AccountStatus =\n (typeof AccountStatusValues)[keyof typeof AccountStatusValues];\n\ntype CandleResolution = '1' | '5' | '15' | '30' | '60' | '240' | '1D';\n\ntype Candle = {\n time: number;\n open: number;\n high: number;\n low: number;\n close: number;\n assetPairId: AssetPair;\n resolution: CandleResolution;\n};\n\n// Used only for PerpExecutionReplicationData (replication:orders messages)\ntype Order = {\n id: string;\n market_id: Decimal | null;\n account_id: Decimal | null;\n executed_base: Decimal | null;\n fee: Decimal | null;\n price: Decimal | null;\n is_match_order: boolean | null;\n liquidation_type: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n event_sequence_number: bigint | null;\n exchange_id: Decimal | null;\n created_at: Date;\n counterparty_account_id: Decimal | null;\n counterparty_adl_unwind_price: Decimal | null;\n counterparty_average_entry_funding_value: Decimal | null;\n counterparty_base: Decimal | null;\n counterparty_base_multiplier: Decimal | null;\n counterparty_funding_value: Decimal | null;\n counterparty_last_price: Decimal | null;\n counterparty_last_price_timestamp: Decimal | null;\n counterparty_realized_pnl: Decimal | null;\n counterparty_session: Decimal | null;\n position_adl_unwind_price: Decimal | null;\n position_average_entry_funding_value: Decimal | null;\n position_base: Decimal | null;\n position_base_multiplier: Decimal | null;\n position_funding_value: Decimal | null;\n position_last_price: Decimal | null;\n position_last_price_timestamp: Decimal | null;\n position_previous_adl_unwind_price: Decimal | null;\n position_previous_average_entry_funding_value: Decimal | null;\n position_previous_base_multiplier: Decimal | null;\n position_previous_funding_value: Decimal | null;\n position_previous_last_price: Decimal | null;\n position_previous_realized_pnl: Decimal | null;\n position_realized_pnl: Decimal | null;\n position_session: Decimal | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n};\n\ntype Position = {\n market_id: Decimal;\n account_id: Decimal;\n base: Decimal | null;\n realized_pnl: Decimal | null;\n last_price: Decimal | null;\n last_price_timestamp: Decimal | null;\n funding_value: Decimal | null;\n base_multiplier: Decimal | null;\n adl_unwind_price: Decimal | null;\n average_entry_funding_value: Decimal | null;\n session: Decimal | null;\n exchange_id: Decimal | null;\n event_sequence_number: bigint | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n adjusted_base: Decimal | null;\n adl_realized_pnl: Decimal | null;\n};\n\ntype ConditionalOrder = {\n id: string;\n account_id: Decimal;\n market_id: Decimal;\n order_type: string;\n is_long: boolean;\n trigger_price: number;\n order_base: Decimal;\n status: string;\n creation_timestamp_ms: bigint;\n last_update_timestamp_ms: bigint;\n transaction_hash: string | null;\n};\n\ntype ConditionalOrderSensitive = ConditionalOrder & {\n exchange_id: bigint;\n inputs: string;\n counterparty_account_id: bigint;\n reya_chain_id: bigint;\n deadline: bigint;\n signer_address: string;\n nonce: Decimal;\n signature: string;\n};\n\ntype Account = {\n account_id: Decimal;\n name: string;\n status: AccountStatus;\n updated_timestamp_ms: Decimal;\n source: string | null;\n};\n\ntype AccountBalance = {\n account_id: Decimal | null;\n collateral: string | null;\n balance?: Decimal | null;\n delta?: Decimal | null;\n};\n\ntype spot_execution = {\n account_id: Decimal;\n counterparty_account_id: Decimal;\n exchange_id: Decimal;\n executed_base: Decimal;\n price: Decimal;\n account_order_id: bigint;\n counterparty_order_id: bigint;\n spot_market_id: Decimal;\n is_auto_exchange: boolean;\n is_long: boolean;\n event_sequence_number: bigint;\n parent_event_sequence_number: bigint | null;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n created_at: string;\n};\n\ntype account_real_balance = {\n account_id: Decimal;\n collateral: string;\n balance: Decimal;\n rpnl: Decimal;\n event_sequence_number: bigint | null;\n transfer_event_sequence_number: bigint | null;\n parent_event_sequence_number: bigint | null;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n};\n\ntype WalletStats = {\n volume_14d: Decimal;\n lookback_volume: Decimal;\n lookback_window_seconds: number;\n};\n\ntype MarketData = {\n marketId: string;\n updatedAt: number;\n longOI: number;\n shortOI: number;\n longSkewPercentage: number;\n shortSkewPercentage: number;\n openInterest?: number;\n fundingRate?: number;\n fundingRateVelocity?: number;\n longFundingValue?: number;\n shortFundingValue?: number;\n last24hVolume: number;\n priceChange24H?: number;\n priceChange24HPercentage?: number;\n maxAmountBaseLong?: number;\n maxAmountSizeLong?: number;\n maxAmountBaseShort?: number;\n maxAmountSizeShort?: number;\n oraclePrice?: number;\n poolPrice?: number;\n pricesUpdatedAt?: number;\n longBaseMultiplier?: number;\n shortBaseMultiplier?: number;\n longAdlUnwindPrice?: number;\n shortAdlUnwindPrice?: number;\n depthFactor?: number;\n priceSpread?: number;\n logPriceMultiplier?: number;\n};\n\ntype SpotMarketData = {\n spotMarketId: string;\n symbol: string;\n updatedAt: number;\n volume24h: number;\n pxChange24h?: number;\n oraclePrice?: number;\n};\n\ntype MarketTrackers = {\n market_data_id: Decimal;\n passive_pool_id: Decimal | null;\n pool_account_id: Decimal | null;\n quote_token: string | null;\n quote_token_decimals: Decimal | null;\n last_funding_velocity: Decimal | null;\n last_funding_timestamp: Decimal | null;\n last_mtm_price: Decimal | null;\n last_mtm_timestamp: Decimal | null;\n long_trackers_funding_value: Decimal | null;\n last_funding_rate: Decimal | null;\n long_trackers_base_multiplier: Decimal | null;\n long_trackers_adl_unwind_price: Decimal | null;\n short_trackers_funding_value: Decimal | null;\n short_trackers_base_multiplier: Decimal | null;\n short_trackers_adl_unwind_price: Decimal | null;\n open_interest: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n price_spread: Decimal | null;\n depth_factor: Decimal | null;\n log_price_multiplier: Decimal | null;\n};\n\nexport type TradingApiReplication<\n ReplicationTable extends ReplicationModel = never,\n Replication = never,\n> = {\n replication: ReplicationTable extends never\n ? never\n : GenericReplicationMessage<Replication, ReplicationTable>;\n};\n\nexport type TradingApiEndpoint<\n Response,\n Params,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = never,\n> = ApiEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiListEndpoint<\n Response,\n Params = never,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = never,\n> = ApiListEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiInfiniteListEndpoint<\n Response,\n Params = never,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = PaginatedQueryParams,\n> = ApiInfiniteListEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiSource = {\n 'poolBalance/:poolId': TradingApiEndpoint<\n {\n id: number;\n timestamp: bigint;\n pool_id: number;\n value: Decimal;\n apy: Decimal;\n share_price: Decimal;\n share_price_index: Decimal;\n } | null,\n {\n poolId?: string;\n }\n >;\n 'poolBalance/:poolId/apy-history': TradingApiEndpoint<\n { timestampInMs: number; apy: number }[],\n { poolId?: string },\n never,\n { timestampInMs: number; apy: number }[],\n { timeframeMs: string; granularity: string }\n >;\n 'markets/data': TradingApiListEndpoint<MarketData, never, 'marketData'>;\n 'spotMarkets/data': TradingApiListEndpoint<\n SpotMarketData,\n never,\n 'spotMarketData'\n >;\n 'markets/configuration': TradingApiListEndpoint<{\n market_id: Decimal;\n risk_matrix_index: Decimal | null;\n max_open_base: Decimal | null;\n velocity_multiplier: Decimal | null;\n minimum_order_base: Decimal | null;\n base_spacing: Decimal | null;\n price_spacing: Decimal | null;\n oracle_node_id: string | null;\n mtm_window: Decimal | null;\n dutch_config_lambda: Decimal | null;\n dutch_config_min_base: Decimal | null;\n slippage_params_phi: Decimal | null;\n slippage_params_beta: Decimal | null;\n depth_factor: Decimal | null;\n max_exposure_factor: Decimal | null;\n max_p_slippage: Decimal | null;\n price_spread: Decimal | null;\n volatility_index_multiplier: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n }>;\n 'markets/storage': TradingApiListEndpoint<{\n market_id: Decimal;\n quote_collateral: string | null;\n instrument_address: string | null;\n name: string | null;\n risk_block_id: Decimal | null;\n collateral_pool_id: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n }>;\n 'markets/trackers': TradingApiListEndpoint<\n MarketTrackers,\n never,\n 'marketTrackers'\n >;\n 'market/:marketId/trackers': TradingApiEndpoint<\n MarketTrackers,\n {\n marketId: string;\n },\n 'marketTrackers'\n >;\n 'market/:marketId/data': TradingApiEndpoint<\n MarketData,\n {\n marketId: string;\n },\n 'marketData'\n >;\n 'wallet/:address/positions': TradingApiListEndpoint<\n Position,\n AddressParam,\n 'position',\n Omit<Position, 'adjusted_base' | 'adl_realized_pnl'>\n >;\n 'wallet/:address/openOrders': TradingApiListEndpoint<\n ConditionalOrder,\n AddressParam,\n 'ConditionalOrders'\n >;\n // Bridge deposits and withdrawals for a wallet. Rows are registered by the\n // Reya app when it broadcasts the source-chain transaction, and reconciled\n // by the pending-transaction cron -- nothing else writes them, which is why\n // this is a v1 app endpoint rather than part of the general v2 API.\n 'wallet/:address/bridgeTransactions': TradingApiListEndpoint<\n bridge_transactions_margin_account,\n AddressParam,\n 'BridgeTransactionsMarginAccount'\n >;\n 'wallet/:address/accounts': TradingApiListEndpoint<\n Account,\n AddressParam,\n 'AccountProfile'\n >;\n 'wallet/:address/accounts/balances': TradingApiListEndpoint<\n AccountBalance,\n AddressParam,\n 'account_balances'\n >;\n 'wallet/:address/balanceHistory/:timestamp': TradingApiListEndpoint<\n {\n timestamp: number;\n balance: number;\n },\n {\n address: string;\n timestamp: string;\n }\n >;\n riskMatrices: TradingApiListEndpoint<\n {\n blockId: Decimal;\n matrix: string[][];\n },\n {\n poolId: string;\n }\n >;\n 'candle/:assetPairId/:resolution': TradingApiEndpoint<\n Candle | null,\n {\n resolution: CandleResolution;\n assetPairId: AssetPair;\n },\n 'storkPriceCandle',\n Candle\n >;\n feeTierParameters: TradingApiListEndpoint<{\n tier_id: Decimal;\n taker_fee: Decimal;\n maker_fee: Decimal;\n volume: Decimal;\n }>;\n globalFeeParameters: TradingApiEndpoint<\n {\n og_discount: Decimal;\n vltz_discount: Decimal;\n spread_discount: Decimal;\n referee_discount: Decimal;\n referrer_rebate: Decimal;\n affiliate_referrer_rebate: Decimal;\n },\n never\n >;\n dynamicDepthConfig: TradingApiEndpoint<\n {\n markets: {\n marketId: number;\n baseDepth: number;\n thresholds: number[];\n ratios: number[];\n }[];\n },\n never\n >;\n 'wallet/:address/configuration': TradingApiEndpoint<\n {\n tier_id: Decimal;\n og_status: boolean;\n vltz_status: boolean;\n affiliate_status: boolean;\n referee_status: boolean;\n spread_discount_status: boolean;\n main_account_id: Decimal;\n },\n {\n address: string;\n }\n >;\n 'wallet/:address/stats': TradingApiEndpoint<\n WalletStats,\n {\n address: string;\n }\n >;\n 'wallet/:address/apiWalletStatus': TradingApiEndpoint<\n {\n enabledApiWallets: string[];\n },\n {\n address: string;\n }\n >;\n rlp: TradingApiEndpoint<\n {\n tvlInUsdc: number;\n tvlInRlp: number;\n rlpUsdcPrice: number;\n apy: {\n '1d': number;\n '7d': number;\n '30d': number;\n '365d': number;\n };\n numberOfDepositors: number;\n ageSeconds: number;\n },\n never\n >;\n 'wallet/:address/rlp': TradingApiEndpoint<\n {\n balanceInUsdc: number;\n balanceInRlp: number;\n },\n {\n address: string;\n }\n >;\n 'collaterals/definitions': TradingApiEndpoint<\n {\n collaterals: CollateralDefinition[];\n },\n never\n >;\n 'collaterals/balances/wallet/:address': TradingApiEndpoint<\n {\n collaterals: CollateralWalletBalance[];\n },\n {\n address: string;\n }\n >;\n};\n\nexport type Req<P = ParamsDictionary, ReqQuery = Query> = {\n params: P;\n query: ReqQuery;\n};\n\nexport type TradingApi = {\n [K in keyof TradingApiSource as K]: {\n params: TradingApiSource[K]['params'];\n query: TradingApiSource[K]['query'];\n response: Stringified<TradingApiSource[K]['response']>;\n replication: Stringified<TradingApiSource[K]['replication']>;\n };\n};\n\ntype ReplicationModel = string | never;\n\nexport type GenericReplicationMessage<T, model extends ReplicationModel> =\n | {\n model: model;\n result: T;\n operation: 'create' | 'update' | 'upsert' | 'delete';\n }\n | {\n model: model;\n result: T[];\n operation: 'updateMany';\n }\n | {\n model: model;\n result: T[];\n operation: 'createMany';\n };\n\ntype account_collateral_balance_entries = {\n id: string;\n account_id: Decimal | null;\n collateral: string | null;\n amount: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n};\n\ntype account_owner_updated_snapshot = {\n account_id: Decimal;\n transaction_hash: string;\n new_owner: string | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n};\n\ntype positions_migration = {\n market_id: Decimal;\n account_id: Decimal;\n base: Decimal | null;\n realized_pnl: Decimal | null;\n last_price: Decimal | null;\n last_price_timestamp: Decimal | null;\n funding_value: Decimal | null;\n base_multiplier: Decimal | null;\n adl_unwind_price: Decimal | null;\n average_entry_funding_value: Decimal | null;\n session: Decimal | null;\n exchange_id: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n event_sequence_number: bigint | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n};\n\ntype spot_execution_bust = {\n event_sequence_number: bigint;\n spot_market_id: Decimal;\n account_id: Decimal;\n counterparty_account_id: Decimal;\n account_order_id: bigint;\n counterparty_order_id: bigint;\n exchange_id: Decimal;\n failed_base: Decimal;\n price: Decimal;\n is_long: boolean;\n reason: string;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n created_at: string;\n};\n\n// Bridge-carried money-in/out transactions, recorded as soon as the source\n// chain tx is broadcast and reconciled once the bridge delivers. Declared with\n// the database's own types; `Stringified<>` maps Date and Decimal to strings\n// for the replication payload.\ntype bridge_transactions_margin_account = {\n source_tx_hash: string;\n destination_tx_hash: string | null;\n source_chain_id: number;\n destination_chain_id: number;\n account_id: Decimal;\n status: string;\n amount: Decimal;\n type: string;\n asset_id: string;\n createdAt: Date;\n updatedAt: Date;\n};\n\ntype ReplicationMessage =\n // Extract the union of all `replication` values from TradingApiSource\n | Exclude<TradingApiSource[keyof TradingApiSource]['replication'], never>\n // add messages that do not exists in TradingApiSource\n | GenericReplicationMessage<\n account_owner_updated_snapshot,\n 'account_owner_updated_snapshot'\n >\n | GenericReplicationMessage<\n account_collateral_balance_entries,\n 'account_collateral_balance_entries'\n >\n | GenericReplicationMessage<account_real_balance, 'account_real_balances'>\n | GenericReplicationMessage<\n ConditionalOrderSensitive,\n 'ConditionalOrdersSensitive'\n >\n | GenericReplicationMessage<\n // Todo: remove after migration\n positions_migration,\n 'positions_migration'\n >\n | GenericReplicationMessage<spot_execution, 'spot_executions'>\n | GenericReplicationMessage<spot_execution_bust, 'spot_execution_busts'>\n | GenericReplicationMessage<Order, 'orders'>\n | GenericReplicationMessage<\n bridge_transactions_margin_account,\n 'BridgeTransactionsMarginAccount'\n >;\n\nexport type SocketDepositChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaPeriphery: Address;\n vaultAddress: Address;\n connectorAddress: Address;\n msgGasLimit: string;\n bridgeTime: number;\n};\n\nexport type SocketWithdrawChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaCore: Address;\n msgGasLimit: string;\n bridgeFee: string;\n bridgeTime: number;\n};\n\nexport type LayerzeroDepositChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaPeriphery: Address;\n dstEid: number;\n extraOptions: string;\n bridgeTime: number;\n};\n\nexport type LayerzeroWithdrawChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaCore: Address;\n dstEid: number;\n bridgeFee: string;\n bridgeTime: number;\n};\n\nexport type SocketDepositInfo =\n | { enabled: false }\n | { enabled: true; chains: SocketDepositChainDetails[]; minAmount: number };\n\nexport type SocketWithdrawInfo =\n | { enabled: false }\n | { enabled: true; chains: SocketWithdrawChainDetails[]; minAmount: number };\n\nexport type LayerzeroDepositInfo =\n | { enabled: false }\n | {\n enabled: true;\n minAmount: number;\n chains: LayerzeroDepositChainDetails[];\n };\n\nexport type LayerzeroWithdrawInfo =\n | { enabled: false }\n | {\n enabled: true;\n minAmount: number;\n chains: LayerzeroWithdrawChainDetails[];\n };\n\nexport type TransferInfo = { enabled: boolean };\n\nexport type SpotInfo =\n | { enabled: false }\n | { enabled: true; spotMarketSymbol: string };\n\nexport type DisplayInfo = {\n advertisedInSpot: boolean;\n advertisedInPerp: boolean;\n displayName: string;\n displayDecimals: number;\n};\n\nexport type CollateralDefinition = {\n id: Uppercase<string>;\n address: Address;\n assetPairId: string;\n priceHaircut: string;\n liquidationDiscount: string;\n decimals: number;\n socketDepositInfo: SocketDepositInfo;\n socketWithdrawInfo: SocketWithdrawInfo;\n layerzeroDepositInfo: LayerzeroDepositInfo;\n layerzeroWithdrawInfo: LayerzeroWithdrawInfo;\n transferInfo: TransferInfo;\n spotInfo: SpotInfo;\n displayInfo: DisplayInfo;\n};\n\n// Per-collateral, per-source-chain wallet balance available to deposit. This is\n// the user's ERC20 balance of the collateral's source-chain token (what a\n// deposit spends), read via `balanceOf`. `balance` is a human-readable decimal\n// string; it is `null` when every RPC for that chain failed.\nexport type CollateralChainBalance = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n balance: string | null;\n};\n\nexport type CollateralWalletBalance = {\n id: Uppercase<string>;\n chains: CollateralChainBalance[];\n};\n\nexport type Replication = {\n [K in ReplicationMessage as `replication:${K['model']}`]: Extract<\n ReplicationMessage,\n { model: K['model'] }\n >;\n};\n"]}
1
+ {"version":3,"file":"trading-api-types.js","sourceRoot":"/","sources":["trading-api-types.ts"],"names":[],"mappings":";;;AAYa,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;CACjB,CAAC","sourcesContent":["import { ParamsDictionary, Query } from 'express-serve-static-core';\nimport { Address, AssetPair, CollateralPrice, MarketPrice } from './types';\nimport {\n AddressParam,\n ApiEndpoint,\n ApiInfiniteListEndpoint,\n ApiListEndpoint,\n Decimal,\n PaginatedQueryParams,\n Stringified,\n} from './api-types';\n\nexport const AccountStatusValues = {\n OPEN: 'OPEN',\n CLOSED: 'CLOSED',\n};\n\nexport type AccountStatus =\n (typeof AccountStatusValues)[keyof typeof AccountStatusValues];\n\ntype CandleResolution = '1' | '5' | '15' | '30' | '60' | '240' | '1D';\n\ntype Candle = {\n time: number;\n open: number;\n high: number;\n low: number;\n close: number;\n assetPairId: AssetPair;\n resolution: CandleResolution;\n};\n\n// Database-shaped perp execution row exposed by provider and API types.\ntype Order = {\n id: string;\n market_id: Decimal | null;\n account_id: Decimal | null;\n executed_base: Decimal | null;\n fee: Decimal | null;\n price: Decimal | null;\n is_match_order: boolean | null;\n liquidation_type: Decimal | null;\n execution_type: number | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n event_sequence_number: bigint | null;\n exchange_id: Decimal | null;\n created_at: Date;\n counterparty_account_id: Decimal | null;\n counterparty_adl_unwind_price: Decimal | null;\n counterparty_average_entry_funding_value: Decimal | null;\n counterparty_base: Decimal | null;\n counterparty_base_multiplier: Decimal | null;\n counterparty_funding_value: Decimal | null;\n counterparty_last_price: Decimal | null;\n counterparty_last_price_timestamp: Decimal | null;\n counterparty_previous_adl_unwind_price: Decimal | null;\n counterparty_previous_average_entry_funding_value: Decimal | null;\n counterparty_previous_base_multiplier: Decimal | null;\n counterparty_previous_funding_value: Decimal | null;\n counterparty_previous_last_price: Decimal | null;\n counterparty_previous_realized_pnl: Decimal | null;\n counterparty_realized_pnl: Decimal | null;\n counterparty_session: Decimal | null;\n position_adl_unwind_price: Decimal | null;\n position_average_entry_funding_value: Decimal | null;\n position_base: Decimal | null;\n position_base_multiplier: Decimal | null;\n position_funding_value: Decimal | null;\n position_last_price: Decimal | null;\n position_last_price_timestamp: Decimal | null;\n position_previous_adl_unwind_price: Decimal | null;\n position_previous_average_entry_funding_value: Decimal | null;\n position_previous_base_multiplier: Decimal | null;\n position_previous_funding_value: Decimal | null;\n position_previous_last_price: Decimal | null;\n position_previous_realized_pnl: Decimal | null;\n position_realized_pnl: Decimal | null;\n position_session: Decimal | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n // V3 fields\n protocol_fee_credit: Decimal | null;\n taker_rebate_credit: Decimal | null;\n pool_fee_credit: Decimal | null;\n exchange_fee_credit: Decimal | null;\n maker_fee_credit: Decimal | null;\n maker_fee_debit: Decimal | null;\n account_order_id: bigint | null;\n counterparty_order_id: bigint | null;\n me_nonce: Decimal | null;\n};\n\ntype Position = {\n market_id: Decimal;\n account_id: Decimal;\n base: Decimal | null;\n realized_pnl: Decimal | null;\n last_price: Decimal | null;\n last_price_timestamp: Decimal | null;\n funding_value: Decimal | null;\n base_multiplier: Decimal | null;\n adl_unwind_price: Decimal | null;\n average_entry_funding_value: Decimal | null;\n session: Decimal | null;\n exchange_id: Decimal | null;\n event_sequence_number: bigint | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n adjusted_base: Decimal | null;\n adl_realized_pnl: Decimal | null;\n};\n\n// PRO-126 Bug 7: `ConditionalOrder` + `ConditionalOrderSensitive`\n// trading-api-types retired with the rest of the legacy\n// `ConditionalOrders` DB pipeline. They modeled the legacy row shape\n// for the dead V1 `/wallet/:address/openOrders` endpoint + the dead\n// `replication:ConditionalOrdersSensitive` broadcast channel; both\n// callers have been removed.\n\ntype Account = {\n account_id: Decimal;\n name: string;\n status: AccountStatus;\n updated_timestamp_ms: Decimal;\n source: string | null;\n};\n\ntype AccountBalance = {\n account_id: Decimal | null;\n collateral: string | null;\n balance?: Decimal | null;\n delta?: Decimal | null;\n};\n\ntype spot_execution = {\n account_id: Decimal;\n counterparty_account_id: Decimal;\n // Order attribution is absent for auto-exchange executions: there is no\n // matched order, so the chain emits no exchange/order ids and the DB\n // columns are NULL. Matches the `spot_executions` Prisma model.\n exchange_id: Decimal | null;\n executed_base: Decimal;\n price: Decimal;\n account_order_id: bigint | null;\n counterparty_order_id: bigint | null;\n me_nonce: Decimal | null;\n spot_market_id: Decimal;\n is_auto_exchange: boolean;\n is_long: boolean;\n event_sequence_number: bigint;\n parent_event_sequence_number: bigint | null;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n created_at: string;\n};\n\ntype account_real_balance = {\n account_id: Decimal;\n collateral: string;\n balance: Decimal;\n rpnl: Decimal;\n event_sequence_number: bigint | null;\n transfer_event_sequence_number: bigint | null;\n parent_event_sequence_number: bigint | null;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n};\n\n// `Leverage` is still referenced by the `wallet/:address/leverages`\n// endpoint below, so it is kept; `AutoExchange` (a dead legacy type with\n// no remaining references) was removed in #2713/#2710.\ntype Leverage = {\n accountId: Decimal;\n marketId: Decimal;\n leverage: number;\n createdAt: Date;\n updatedAt: Date;\n};\n\ntype WalletStats = {\n volume_14d: Decimal;\n lookback_volume: Decimal;\n lookback_window_seconds: number;\n};\n\ntype MarketData = {\n marketId: string;\n updatedAt: number;\n longOI: number;\n shortOI: number;\n longSkewPercentage: number;\n shortSkewPercentage: number;\n openInterest?: number;\n fundingRate?: number;\n fundingRateVelocity?: number;\n longFundingValue?: number;\n shortFundingValue?: number;\n last24hVolume: number;\n priceChange24H?: number;\n priceChange24HPercentage?: number;\n maxAmountBaseLong?: number;\n maxAmountSizeLong?: number;\n maxAmountBaseShort?: number;\n maxAmountSizeShort?: number;\n /** ME mark price, despite the name. Surfaced as v2 `MarketSummary.markPrice`. */\n oraclePrice?: number;\n /**\n * Orderbook mid. Absent on an empty or one-sided book\n */\n poolPrice?: number;\n /**\n * Stork index price, rUSD-quoted (divided by USDCUSD, like the collateral\n * feeds). Surfaced as v2 `MarketSummary.oraclePrice` — the name differs\n * because the v1 `oraclePrice` above is already taken by the mark price.\n * Absent when the index feed has no fresh tick.\n */\n indexPrice?: number;\n pricesUpdatedAt?: number;\n longBaseMultiplier?: number;\n shortBaseMultiplier?: number;\n longAdlUnwindPrice?: number;\n shortAdlUnwindPrice?: number;\n depthFactor?: number;\n priceSpread?: number;\n logPriceMultiplier?: number;\n};\n\ntype SpotMarketData = {\n spotMarketId: string;\n symbol: string;\n updatedAt: number;\n volume24h: number;\n pxChange24h?: number;\n /** Stork price for the base token, rUSD-quoted (divided by USDCUSD). */\n oraclePrice?: number;\n /**\n * Spot orderbook mid, read from the ME `{depth}:bbo:<id>` key. Absent on an\n * empty or one-sided book — spot has no mark price to fall back to, unlike\n * the perp `poolPrice` above.\n */\n throttledMidPrice?: number;\n};\n\ntype MarketTrackers = {\n market_data_id: Decimal;\n passive_pool_id: Decimal | null;\n pool_account_id: Decimal | null;\n quote_token: string | null;\n quote_token_decimals: Decimal | null;\n last_funding_velocity: Decimal | null;\n last_funding_timestamp: Decimal | null;\n last_mtm_price: Decimal | null;\n last_mtm_timestamp: Decimal | null;\n long_trackers_funding_value: Decimal | null;\n last_funding_rate: Decimal | null;\n long_trackers_base_multiplier: Decimal | null;\n long_trackers_adl_unwind_price: Decimal | null;\n short_trackers_funding_value: Decimal | null;\n short_trackers_base_multiplier: Decimal | null;\n short_trackers_adl_unwind_price: Decimal | null;\n open_interest: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n price_spread: Decimal | null;\n depth_factor: Decimal | null;\n log_price_multiplier: Decimal | null;\n mark_price: Decimal | null;\n mark_price_timestamp: Decimal | null;\n funding_rate: Decimal | null;\n funding_rate_timestamp: Decimal | null;\n};\n\nexport type TradingApiReplication<\n ReplicationTable extends ReplicationModel = never,\n Replication = never,\n> = {\n replication: ReplicationTable extends never\n ? never\n : GenericReplicationMessage<Replication, ReplicationTable>;\n};\n\nexport type TradingApiEndpoint<\n Response,\n Params,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = never,\n> = ApiEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiListEndpoint<\n Response,\n Params = never,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = never,\n> = ApiListEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiInfiniteListEndpoint<\n Response,\n Params = never,\n ReplicationTable extends ReplicationModel = never,\n Replication = Response,\n Query = PaginatedQueryParams,\n> = ApiInfiniteListEndpoint<Response, Params, Query> &\n TradingApiReplication<ReplicationTable, Replication>;\n\nexport type TradingApiSource = {\n 'poolBalance/:poolId': TradingApiEndpoint<\n {\n id: number;\n timestamp: bigint;\n pool_id: number;\n value: Decimal;\n apy: Decimal;\n share_price: Decimal;\n share_price_index: Decimal;\n } | null,\n {\n poolId?: string;\n }\n >;\n 'poolBalance/:poolId/apy-history': TradingApiEndpoint<\n { timestampInMs: number; apy: number }[],\n { poolId?: string },\n never,\n { timestampInMs: number; apy: number }[],\n { timeframeMs: string; granularity: string }\n >;\n 'wallet/:address/leverages': TradingApiListEndpoint<\n Leverage,\n { address: string },\n 'accountLeveragePerMarket'\n >;\n 'markets/data': TradingApiListEndpoint<MarketData, never, 'marketData'>;\n 'spotMarkets/data': TradingApiListEndpoint<\n SpotMarketData,\n never,\n 'spotMarketData'\n >;\n 'markets/configuration': TradingApiListEndpoint<{\n market_id: Decimal;\n risk_matrix_index: Decimal | null;\n max_open_base: Decimal | null;\n velocity_multiplier: Decimal | null;\n minimum_order_base: Decimal | null;\n base_spacing: Decimal | null;\n price_spacing: Decimal | null;\n oracle_node_id: string | null;\n mtm_window: Decimal | null;\n dutch_config_lambda: Decimal | null;\n dutch_config_min_base: Decimal | null;\n slippage_params_phi: Decimal | null;\n slippage_params_beta: Decimal | null;\n depth_factor: Decimal | null;\n max_exposure_factor: Decimal | null;\n max_p_slippage: Decimal | null;\n price_spread: Decimal | null;\n volatility_index_multiplier: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n }>;\n 'markets/storage': TradingApiListEndpoint<{\n market_id: Decimal;\n quote_collateral: string | null;\n instrument_address: string | null;\n name: string | null;\n risk_block_id: Decimal | null;\n collateral_pool_id: Decimal | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n }>;\n 'markets/trackers': TradingApiListEndpoint<\n MarketTrackers,\n never,\n 'marketTrackers'\n >;\n 'market/:marketId/trackers': TradingApiEndpoint<\n MarketTrackers,\n {\n marketId: string;\n },\n 'marketTrackers'\n >;\n 'market/:marketId/data': TradingApiEndpoint<\n MarketData,\n {\n marketId: string;\n },\n 'marketData'\n >;\n 'wallet/:address/positions': TradingApiListEndpoint<\n Position,\n AddressParam,\n 'position',\n Omit<Position, 'adjusted_base' | 'adl_realized_pnl'>\n >;\n // PRO-126 Bug 7: V1 `/wallet/:address/openOrders` endpoint type\n // retired. The route+controller were removed in trading.router.ts +\n // trading.controller.ts. V2 callers should use\n // `/v2/wallet/:address/openOrders` which serves both spot and perp\n // orders from the unified ME stream via AccountOrdersMap.\n assets: TradingApiListEndpoint<{\n address: string;\n name: string;\n short: string;\n createdAt: Date;\n updatedAt: Date;\n asset_price_contract_id: string | null;\n asset_price_usdc_contract_id: string | null;\n decimals: number;\n }>;\n prices: TradingApiEndpoint<\n Partial<Record<AssetPair, MarketPrice | CollateralPrice>>,\n never\n >;\n 'prices/:assetPairId': TradingApiEndpoint<\n MarketPrice | CollateralPrice | undefined,\n {\n assetPairId: string;\n },\n 'price'\n >;\n // Bridge deposits and withdrawals for a wallet. Rows are registered by the\n // Reya app when it broadcasts the source-chain transaction, and reconciled\n // by the pending-transaction cron -- nothing else writes them, which is why\n // this is a v1 app endpoint rather than part of the general v2 API.\n 'wallet/:address/bridgeTransactions': TradingApiListEndpoint<\n bridge_transactions_margin_account,\n AddressParam,\n 'BridgeTransactionsMarginAccount'\n >;\n 'wallet/:address/accounts': TradingApiListEndpoint<\n Account,\n AddressParam,\n 'AccountProfile'\n >;\n 'wallet/:address/accounts/balances': TradingApiListEndpoint<\n AccountBalance,\n AddressParam,\n 'account_balances'\n >;\n 'wallet/:address/balanceHistory/:timestamp': TradingApiListEndpoint<\n {\n timestamp: number;\n balance: number;\n },\n {\n address: string;\n timestamp: string;\n }\n >;\n riskMatrices: TradingApiListEndpoint<\n {\n blockId: Decimal;\n matrix: string[][];\n },\n {\n poolId: string;\n }\n >;\n 'candle/:assetPairId/:resolution': TradingApiEndpoint<\n Candle | null,\n {\n resolution: CandleResolution;\n assetPairId: AssetPair;\n },\n 'storkPriceCandle',\n Candle\n >;\n 'candles/:assetPairId/:resolution': TradingApiEndpoint<\n {\n t: number[];\n o: number[];\n h: number[];\n l: number[];\n c: number[];\n },\n {\n resolution: CandleResolution;\n assetPairId: AssetPair;\n },\n never,\n never,\n {\n to: string;\n from: string;\n countBack?: string;\n }\n >;\n feeTierParameters: TradingApiListEndpoint<{\n tier_id: Decimal;\n taker_fee: Decimal;\n maker_fee: Decimal;\n volume: Decimal;\n }>;\n globalFeeParameters: TradingApiEndpoint<\n {\n og_discount: Decimal;\n vltz_discount: Decimal;\n referee_discount: Decimal;\n referrer_rebate: Decimal;\n affiliate_referrer_rebate: Decimal;\n },\n never\n >;\n dynamicDepthConfig: TradingApiEndpoint<\n {\n markets: {\n marketId: number;\n baseDepth: number;\n thresholds: number[];\n ratios: number[];\n }[];\n },\n never\n >;\n 'wallet/:address/configuration': TradingApiEndpoint<\n {\n tier_id: Decimal;\n og_status: boolean;\n vltz_status: boolean;\n affiliate_status: boolean;\n referee_status: boolean;\n spread_discount_status: boolean;\n main_account_id: Decimal;\n },\n {\n address: string;\n }\n >;\n 'wallet/:address/stats': TradingApiEndpoint<\n WalletStats,\n {\n address: string;\n }\n >;\n 'wallet/:address/apiWalletStatus': TradingApiEndpoint<\n {\n enabledApiWallets: string[];\n },\n {\n address: string;\n }\n >;\n rlp: TradingApiEndpoint<\n {\n tvlInUsdc: number;\n tvlInRlp: number;\n rlpUsdcPrice: number;\n apy: {\n '1d': number;\n '7d': number;\n '30d': number;\n '365d': number;\n };\n numberOfDepositors: number;\n ageSeconds: number;\n },\n never\n >;\n 'wallet/:address/rlp': TradingApiEndpoint<\n {\n balanceInUsdc: number;\n balanceInRlp: number;\n },\n {\n address: string;\n }\n >;\n 'collaterals/definitions': TradingApiEndpoint<\n {\n collaterals: CollateralDefinition[];\n },\n never\n >;\n 'collaterals/balances/wallet/:address': TradingApiEndpoint<\n {\n collaterals: CollateralWalletBalance[];\n },\n {\n address: string;\n }\n >;\n};\n\nexport type Req<P = ParamsDictionary, ReqQuery = Query> = {\n params: P;\n query: ReqQuery;\n};\n\nexport type TradingApi = {\n [K in keyof TradingApiSource as K]: {\n params: TradingApiSource[K]['params'];\n query: TradingApiSource[K]['query'];\n response: Stringified<TradingApiSource[K]['response']>;\n replication: Stringified<TradingApiSource[K]['replication']>;\n };\n};\n\ntype ReplicationModel = string | never;\n\nexport type GenericReplicationMessage<T, model extends ReplicationModel> =\n | {\n model: model;\n result: T;\n operation: 'create' | 'update' | 'upsert' | 'delete';\n }\n | {\n model: model;\n result: T[];\n operation: 'updateMany';\n }\n | {\n model: model;\n result: T[];\n operation: 'createMany';\n };\n\ntype account_collateral_balance_entries = {\n id: string;\n account_id: Decimal | null;\n collateral: string | null;\n amount: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n};\n\ntype account_owner_updated_snapshot = {\n account_id: Decimal;\n transaction_hash: string;\n new_owner: string | null;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n event_sequence_number: bigint | null;\n};\n\nexport interface OrdersGatewayPermissionUpdatedStreamResult {\n owner: string;\n delegate: string;\n permission_state: boolean;\n event_sequence_number: string;\n block_number: string;\n block_timestamp: string;\n transaction_hash: string | null;\n}\n\nexport interface PerpTradeStreamPosition {\n account_id: Decimal;\n base: Decimal;\n base_multiplier: Decimal;\n funding_value: Decimal;\n adl_unwind_price: Decimal;\n last_price: Decimal;\n last_price_timestamp: Decimal;\n realized_pnl: Decimal;\n average_entry_funding_value: Decimal;\n session: Decimal;\n}\n\nexport interface PerpTradeStreamResult {\n id: string;\n event_sequence_number: Decimal;\n me_nonce: Decimal;\n market_id: Decimal;\n account_id: Decimal;\n counterparty_account_id: Decimal;\n executed_base: Decimal;\n fee: Decimal;\n price: Decimal;\n is_match_order: boolean;\n liquidation_type: Decimal;\n execution_type: number;\n protocol_fee_credit: Decimal;\n taker_rebate_credit: Decimal;\n pool_fee_credit: Decimal;\n exchange_fee_credit: null;\n maker_fee_credit: null;\n maker_fee_debit: null;\n account_order_id: Decimal;\n counterparty_order_id: Decimal;\n position_previous_average_entry_funding_value: Decimal;\n position_previous_adl_unwind_price: Decimal;\n position_previous_base_multiplier: Decimal;\n position_previous_funding_value: Decimal;\n position_previous_last_price: Decimal;\n position_previous_realized_pnl: Decimal;\n counterparty_previous_average_entry_funding_value: Decimal;\n counterparty_previous_adl_unwind_price: Decimal;\n counterparty_previous_base_multiplier: Decimal;\n counterparty_previous_funding_value: Decimal;\n counterparty_previous_last_price: Decimal;\n counterparty_previous_realized_pnl: Decimal;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n unique_id: bigint;\n exchange_id: Decimal;\n referrer_account_id: Decimal;\n referrer_fee_credit: Decimal;\n account: PerpTradeStreamPosition;\n counterparty: PerpTradeStreamPosition;\n}\n\nexport type PerpTradeStreamMessage = GenericReplicationMessage<\n PerpTradeStreamResult,\n 'trade'\n>;\n\nexport interface BalanceStreamSide {\n account_id: Decimal;\n balance: Decimal;\n /** Lowercased owner address (address(0) for account 0); part of the ledger enrichment. */\n owner?: string;\n}\n\n/**\n * One built leg of a Transfers event. The account ledger fields (PRO-852,\n * design §3.2) label and link the leg the same way its account_transfers row\n * is: `type` from command type and leg position, `fill_id` (ME nonce) and\n * `market_id` for perp fills settled after reya-network#752,\n * `spot_execution_sequence_number` / `spot_market_id` for spot trades and\n * auto-exchanges. Consumers that only track balances ignore them.\n */\nexport interface BalanceStreamTransfer {\n transfer_event_sequence_number: Decimal;\n collateral: string;\n from: BalanceStreamSide;\n to: BalanceStreamSide;\n // The ledger enrichment (PRO-852), included on all newly published legs;\n // a leg without it feeds the balances rail and nothing else.\n /** Position of the leg in the event's array. */\n leg_index?: number;\n /** Amount moved (`netDepositsDelta`), raw token units, always positive. */\n amount?: Decimal;\n /** TransferType label; OTHER when the leg is not recognised. */\n type?: string;\n fill_id?: Decimal | null;\n market_id?: Decimal | null;\n spot_execution_sequence_number?: Decimal | null;\n spot_market_id?: Decimal | null;\n}\n\n/** A leg as published while the ledger is on: every enrichment field present. */\nexport type EnrichedBalanceStreamTransfer = Required<\n Omit<BalanceStreamTransfer, 'from' | 'to'>\n> & {\n from: Required<BalanceStreamSide>;\n to: Required<BalanceStreamSide>;\n};\n\nexport interface BalanceStreamResult {\n event_sequence_number: Decimal;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n command_type: Decimal;\n me_nonce: Decimal | null;\n spot_market_id: Decimal | null;\n account_id: Decimal | null;\n counterparty_account_id: Decimal | null;\n transfers: BalanceStreamTransfer[];\n}\n\nexport type BalanceStreamMessage = GenericReplicationMessage<\n BalanceStreamResult,\n 'transfers'\n>;\n\ntype positions_migration = {\n market_id: Decimal;\n account_id: Decimal;\n base: Decimal | null;\n realized_pnl: Decimal | null;\n last_price: Decimal | null;\n last_price_timestamp: Decimal | null;\n funding_value: Decimal | null;\n base_multiplier: Decimal | null;\n adl_unwind_price: Decimal | null;\n average_entry_funding_value: Decimal | null;\n session: Decimal | null;\n exchange_id: Decimal | null;\n transaction_hash: string;\n block_timestamp: Decimal | null;\n block_number: Decimal;\n unique_id: bigint | null;\n event_sequence_number: bigint | null;\n referrer_account_id: Decimal | null;\n referrer_fee_credit: Decimal | null;\n};\n\ntype execution_bust = {\n event_sequence_number: bigint;\n market_id: Decimal;\n market_type: string;\n account_id: Decimal;\n counterparty_account_id: Decimal;\n account_order_id: bigint;\n counterparty_order_id: bigint;\n me_nonce: Decimal | null;\n exchange_id: Decimal;\n failed_base: Decimal;\n price: Decimal;\n is_long: boolean;\n reason: string;\n block_timestamp: Decimal;\n block_number: Decimal;\n transaction_hash: string;\n created_at: string;\n};\n\n// Bridge-carried money-in/out transactions, recorded as soon as the source\n// chain tx is broadcast and reconciled once the bridge delivers. Declared with\n// the database's own types; `Stringified<>` maps Date and Decimal to strings\n// for the replication payload.\ntype bridge_transactions_margin_account = {\n source_tx_hash: string;\n destination_tx_hash: string | null;\n source_chain_id: number;\n destination_chain_id: number;\n account_id: Decimal;\n status: string;\n amount: Decimal;\n type: string;\n asset_id: string;\n createdAt: Date;\n updatedAt: Date;\n};\n\ntype ReplicationMessage =\n // Extract the union of all `replication` values from TradingApiSource\n | Exclude<TradingApiSource[keyof TradingApiSource]['replication'], never>\n // add messages that do not exists in TradingApiSource\n | GenericReplicationMessage<\n account_owner_updated_snapshot,\n 'account_owner_updated_snapshot'\n >\n | GenericReplicationMessage<\n account_collateral_balance_entries,\n 'account_collateral_balance_entries'\n >\n | GenericReplicationMessage<account_real_balance, 'account_real_balances'>\n | GenericReplicationMessage<\n OrdersGatewayPermissionUpdatedStreamResult,\n 'orders_gateway_permission'\n >\n // PRO-126 Bug 7: `ConditionalOrdersSensitive` replication channel\n // retired with the rest of the `ConditionalOrders` DB pipeline.\n // Order data flows through the ME's `{orders}:changes` stream.\n | GenericReplicationMessage<\n // Todo: remove after migration\n positions_migration,\n 'positions_migration'\n >\n | GenericReplicationMessage<spot_execution, 'spot_executions'>\n | GenericReplicationMessage<Order, 'orders'>\n | GenericReplicationMessage<execution_bust, 'execution_busts'>\n | GenericReplicationMessage<\n bridge_transactions_margin_account,\n 'BridgeTransactionsMarginAccount'\n >;\n\nexport type SocketDepositChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaPeriphery: Address;\n vaultAddress: Address;\n connectorAddress: Address;\n msgGasLimit: string;\n bridgeTime: number;\n};\n\nexport type SocketWithdrawChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaCore: Address;\n msgGasLimit: string;\n bridgeFee: string;\n bridgeTime: number;\n};\n\nexport type LayerzeroDepositChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaPeriphery: Address;\n dstEid: number;\n extraOptions: string;\n bridgeTime: number;\n};\n\nexport type LayerzeroWithdrawChainDetails = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n collateralName: string;\n collateralAddressInReyaCore: Address;\n dstEid: number;\n bridgeFee: string;\n bridgeTime: number;\n};\n\nexport type SocketDepositInfo =\n | { enabled: false }\n | { enabled: true; chains: SocketDepositChainDetails[]; minAmount: number };\n\nexport type SocketWithdrawInfo =\n | { enabled: false }\n | { enabled: true; chains: SocketWithdrawChainDetails[]; minAmount: number };\n\nexport type LayerzeroDepositInfo =\n | { enabled: false }\n | {\n enabled: true;\n minAmount: number;\n chains: LayerzeroDepositChainDetails[];\n };\n\nexport type LayerzeroWithdrawInfo =\n | { enabled: false }\n | {\n enabled: true;\n minAmount: number;\n chains: LayerzeroWithdrawChainDetails[];\n };\n\nexport type TransferInfo = { enabled: boolean };\n\nexport type SpotInfo =\n | { enabled: false }\n | { enabled: true; spotMarketSymbol: string };\n\nexport type DisplayInfo = {\n advertisedInSpot: boolean;\n advertisedInPerp: boolean;\n displayName: string;\n displayDecimals: number;\n};\n\nexport type CollateralDefinition = {\n id: Uppercase<string>;\n address: Address;\n assetPairId: string;\n priceHaircut: string;\n liquidationDiscount: string;\n decimals: number;\n socketDepositInfo: SocketDepositInfo;\n socketWithdrawInfo: SocketWithdrawInfo;\n layerzeroDepositInfo: LayerzeroDepositInfo;\n layerzeroWithdrawInfo: LayerzeroWithdrawInfo;\n transferInfo: TransferInfo;\n spotInfo: SpotInfo;\n displayInfo: DisplayInfo;\n};\n\n// Per-collateral, per-source-chain wallet balance available to deposit. This is\n// the user's ERC20 balance of the collateral's source-chain token (what a\n// deposit spends), read via `balanceOf`. `balance` is a human-readable decimal\n// string; it is `null` when every RPC for that chain failed.\nexport type CollateralChainBalance = {\n chainId: number;\n chainName: string;\n collateralAddress: Address;\n balance: string | null;\n};\n\nexport type CollateralWalletBalance = {\n id: Uppercase<string>;\n chains: CollateralChainBalance[];\n};\n\nexport type Replication = {\n [K in ReplicationMessage as `replication:${K['model']}`]: Extract<\n ReplicationMessage,\n { model: K['model'] }\n >;\n};\n"]}