@polyester/sdk 0.31.0 → 0.32.0-devnet-20261102134326
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +116 -0
- package/README.md +7 -0
- package/dist/browser-core.d.ts.map +1 -1
- package/dist/browser-core.js.map +1 -1
- package/dist/catalogs/market-data-catalog.d.ts +2 -0
- package/dist/catalogs/market-data-catalog.d.ts.map +1 -1
- package/dist/catalogs/market-data-catalog.js +1 -0
- package/dist/catalogs/market-data-catalog.js.map +1 -1
- package/dist/catalogs/snapshot-validation.js +6 -0
- package/dist/catalogs/snapshot-validation.js.map +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/core-client.d.ts.map +1 -1
- package/dist/core-client.js +1 -0
- package/dist/core-client.js.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts +6 -3
- package/dist/gen/auth/v1/api_keys_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/auth_pb.d.ts +16 -2
- package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/auth_pb.js +16 -2
- package/dist/gen/auth/v1/auth_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +26 -2
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +26 -2
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +41 -17
- package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js +20 -3
- package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
- package/dist/gen/chain/analytics/v1/analytics_read_pb.d.ts.map +1 -1
- package/dist/gen/chain/analytics/v1/analytics_read_pb.js +2 -1
- package/dist/gen/chain/analytics/v1/analytics_read_pb.js.map +1 -1
- package/dist/gen/chain/deposit/v1/deposit_pb.d.ts +10 -6
- package/dist/gen/chain/deposit/v1/deposit_pb.d.ts.map +1 -1
- package/dist/gen/chain/deposit/v1/deposit_pb.js +2 -1
- package/dist/gen/chain/deposit/v1/deposit_pb.js.map +1 -1
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts +32 -2
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts.map +1 -1
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.js +2 -2
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.js.map +1 -1
- package/dist/gen/chain/lifecycle/v1/types_pb.d.ts +19 -3
- package/dist/gen/chain/lifecycle/v1/types_pb.d.ts.map +1 -1
- package/dist/gen/chain/lifecycle/v1/types_pb.js +18 -2
- package/dist/gen/chain/lifecycle/v1/types_pb.js.map +1 -1
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts +840 -0
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts.map +1 -0
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.js +351 -0
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.js.map +1 -0
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +22 -2
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js +17 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
- package/dist/gen/chain/zipper/v1/reason_pb.d.ts +14 -0
- package/dist/gen/chain/zipper/v1/reason_pb.d.ts.map +1 -1
- package/dist/gen/chain/zipper/v1/reason_pb.js +15 -1
- package/dist/gen/chain/zipper/v1/reason_pb.js.map +1 -1
- package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts +1134 -0
- package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts.map +1 -0
- package/dist/gen/checkpoints/v1/checkpoints_pb.js +327 -0
- package/dist/gen/checkpoints/v1/checkpoints_pb.js.map +1 -0
- package/dist/gen/claims/v1/claims_pb.d.ts +61 -4
- package/dist/gen/claims/v1/claims_pb.d.ts.map +1 -1
- package/dist/gen/claims/v1/claims_pb.js +26 -1
- package/dist/gen/claims/v1/claims_pb.js.map +1 -1
- package/dist/gen/fees/v1/fees_pb.d.ts.map +1 -1
- package/dist/gen/fees/v1/fees_pb.js +2 -1
- package/dist/gen/fees/v1/fees_pb.js.map +1 -1
- package/dist/gen/index.d.ts +7 -5
- package/dist/gen/index.js +12 -10
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +45 -3
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts.map +1 -1
- package/dist/gen/ledger/read/v1/ledger_read_pb.js +19 -7
- package/dist/gen/ledger/read/v1/ledger_read_pb.js.map +1 -1
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts +248 -27
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts.map +1 -1
- package/dist/gen/marketdata/v1/marketdata_pb.js +73 -20
- package/dist/gen/marketdata/v1/marketdata_pb.js.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +2 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.js.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts +16 -4
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.js +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +1222 -63
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +971 -44
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +214 -25
- package/dist/gen/orders/v1/orders_read_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js +159 -20
- package/dist/gen/orders/v1/orders_read_pb.js.map +1 -1
- package/dist/gen/polyester/api/options_pb.d.ts +8 -1
- package/dist/gen/polyester/api/options_pb.d.ts.map +1 -1
- package/dist/gen/polyester/api/options_pb.js +8 -1
- package/dist/gen/polyester/api/options_pb.js.map +1 -1
- package/dist/gen/privatews/v1/private_ws_pb.d.ts +1419 -0
- package/dist/gen/privatews/v1/private_ws_pb.d.ts.map +1 -0
- package/dist/gen/privatews/v1/private_ws_pb.js +551 -0
- package/dist/gen/privatews/v1/private_ws_pb.js.map +1 -0
- package/dist/gen/ratelimit/v1/ratelimit_pb.d.ts +1 -0
- package/dist/gen/ratelimit/v1/ratelimit_pb.d.ts.map +1 -1
- package/dist/gen/ratelimit/v1/ratelimit_pb.js +1 -1
- package/dist/gen/ratelimit/v1/ratelimit_pb.js.map +1 -1
- package/dist/gen/rewards/v1/rewards_pb.d.ts +6 -0
- package/dist/gen/rewards/v1/rewards_pb.d.ts.map +1 -1
- package/dist/gen/rewards/v1/rewards_pb.js +1 -1
- package/dist/gen/rewards/v1/rewards_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +2108 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +522 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -0
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +2296 -0
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -0
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js +1014 -0
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -0
- package/dist/gen/swap/v1/swap_pb.d.ts +958 -0
- package/dist/gen/swap/v1/swap_pb.d.ts.map +1 -0
- package/dist/gen/swap/v1/swap_pb.js +434 -0
- package/dist/gen/swap/v1/swap_pb.js.map +1 -0
- package/dist/gen/tradews/v1/trade_ws_pb.d.ts +68 -3
- package/dist/gen/tradews/v1/trade_ws_pb.d.ts.map +1 -1
- package/dist/gen/tradews/v1/trade_ws_pb.js +1 -1
- package/dist/gen/tradews/v1/trade_ws_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +612 -33
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +437 -20
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/gen/vip/v1/vip_pb.d.ts +95 -7
- package/dist/gen/vip/v1/vip_pb.d.ts.map +1 -1
- package/dist/gen/vip/v1/vip_pb.js +53 -5
- package/dist/gen/vip/v1/vip_pb.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.js +2 -2
- package/dist/realtime/client.d.ts +3 -0
- package/dist/realtime/client.d.ts.map +1 -1
- package/dist/realtime/client.js +76 -24
- package/dist/realtime/client.js.map +1 -1
- package/dist/realtime/index.d.ts +2 -1
- package/dist/realtime/private-orders.d.ts +38 -0
- package/dist/realtime/private-orders.d.ts.map +1 -0
- package/dist/realtime/private-orders.js +594 -0
- package/dist/realtime/private-orders.js.map +1 -0
- package/dist/realtime/ready-gated-subscription.js +10 -4
- package/dist/realtime/ready-gated-subscription.js.map +1 -1
- package/dist/realtime/types.d.ts +3 -0
- package/dist/realtime/types.d.ts.map +1 -1
- package/dist/services/auth/account-signer-auth.d.ts +5 -3
- package/dist/services/auth/account-signer-auth.d.ts.map +1 -1
- package/dist/services/auth/account-signer-auth.js +21 -3
- package/dist/services/auth/account-signer-auth.js.map +1 -1
- package/dist/services/auth/profile/profile.schemas.js +1 -1
- package/dist/services/balances/balances.js +1 -1
- package/dist/services/balances/balances.schemas.d.ts +3 -3
- package/dist/services/candles/candles.codecs.js +15 -0
- package/dist/services/candles/candles.codecs.js.map +1 -1
- package/dist/services/candles/candles.schemas.d.ts +13 -13
- package/dist/services/checkpoints/checkpoints.codecs.d.ts +8 -0
- package/dist/services/checkpoints/checkpoints.codecs.d.ts.map +1 -0
- package/dist/services/checkpoints/checkpoints.codecs.js +36 -0
- package/dist/services/checkpoints/checkpoints.codecs.js.map +1 -0
- package/dist/services/checkpoints/checkpoints.d.ts +22 -0
- package/dist/services/checkpoints/checkpoints.d.ts.map +1 -0
- package/dist/services/checkpoints/checkpoints.js +31 -0
- package/dist/services/checkpoints/checkpoints.js.map +1 -0
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +437 -0
- package/dist/services/checkpoints/checkpoints.schemas.d.ts.map +1 -0
- package/dist/services/checkpoints/checkpoints.schemas.js +176 -0
- package/dist/services/checkpoints/checkpoints.schemas.js.map +1 -0
- package/dist/services/checkpoints/checkpoints.types.d.ts +3 -0
- package/dist/services/checkpoints/service.d.ts +8 -0
- package/dist/services/checkpoints/service.d.ts.map +1 -0
- package/dist/services/checkpoints/service.js +9 -0
- package/dist/services/checkpoints/service.js.map +1 -0
- package/dist/services/claims/claims.codecs.d.ts +1 -1
- package/dist/services/claims/claims.codecs.d.ts.map +1 -1
- package/dist/services/claims/claims.codecs.js +2 -1
- package/dist/services/claims/claims.codecs.js.map +1 -1
- package/dist/services/claims/claims.d.ts +13 -5
- package/dist/services/claims/claims.d.ts.map +1 -1
- package/dist/services/claims/claims.js +15 -6
- package/dist/services/claims/claims.js.map +1 -1
- package/dist/services/claims/claims.schemas.d.ts +13 -3
- package/dist/services/claims/claims.schemas.d.ts.map +1 -1
- package/dist/services/claims/claims.schemas.js +10 -4
- package/dist/services/claims/claims.schemas.js.map +1 -1
- package/dist/services/claims/claims.types.d.ts +2 -2
- package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
- package/dist/services/lifecycle/lifecycle.codecs.d.ts +1 -1
- package/dist/services/lifecycle/lifecycle.codecs.d.ts.map +1 -1
- package/dist/services/lifecycle/lifecycle.codecs.js +4 -2
- package/dist/services/lifecycle/lifecycle.codecs.js.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +185 -135
- package/dist/services/lifecycle/lifecycle.schemas.d.ts.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.js +7 -1
- package/dist/services/lifecycle/lifecycle.schemas.js.map +1 -1
- package/dist/services/market-data/market-data.codecs.js +2 -1
- package/dist/services/market-data/market-data.codecs.js.map +1 -1
- package/dist/services/market-data/market-data.d.ts +10 -1
- package/dist/services/market-data/market-data.d.ts.map +1 -1
- package/dist/services/market-data/market-data.js +21 -9
- package/dist/services/market-data/market-data.js.map +1 -1
- package/dist/services/market-data/market-data.schemas.d.ts +29 -2
- package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
- package/dist/services/market-data/market-data.schemas.js +53 -4
- package/dist/services/market-data/market-data.schemas.js.map +1 -1
- package/dist/services/market-data/market-data.types.d.ts +2 -2
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/orderbook/orderbook.d.ts +2 -1
- package/dist/services/orderbook/orderbook.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.js +17 -2
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orderbook/orderbook.schemas.d.ts +5 -1
- package/dist/services/orderbook/orderbook.schemas.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.schemas.js +2 -0
- package/dist/services/orderbook/orderbook.schemas.js.map +1 -1
- package/dist/services/orders/order-enums.codecs.js +7 -1
- package/dist/services/orders/order-enums.codecs.js.map +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +4 -2
- package/dist/services/orders/order-errors.schemas.d.ts.map +1 -1
- package/dist/services/orders/order-errors.schemas.js +4 -1
- package/dist/services/orders/order-errors.schemas.js.map +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +375 -54
- package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-batch.schemas.js +12 -2
- package/dist/services/orders/orders-batch.schemas.js.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +551 -9
- package/dist/services/orders/orders-input.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-input.schemas.js +23 -5
- package/dist/services/orders/orders-input.schemas.js.map +1 -1
- package/dist/services/orders/orders-modify.schemas.d.ts +106 -1
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-modify.schemas.js +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +80 -61
- package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-output.schemas.js +15 -22
- package/dist/services/orders/orders-output.schemas.js.map +1 -1
- package/dist/services/orders/orders-risk.schemas.d.ts +69 -1
- package/dist/services/orders/orders-risk.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-risk.schemas.js +21 -11
- package/dist/services/orders/orders-risk.schemas.js.map +1 -1
- package/dist/services/orders/orders.codecs.js +26 -2
- package/dist/services/orders/orders.codecs.js.map +1 -1
- package/dist/services/orders/orders.d.ts +31 -5
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +53 -15
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
- package/dist/services/policies/shared.codecs.js +8 -2
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/shared.d.ts.map +1 -1
- package/dist/services/policies/shared.js +4 -1
- package/dist/services/policies/shared.js.map +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +9 -9
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.js +1 -1
- package/dist/services/subaccounts/subaccounts.codecs.js +4 -1
- package/dist/services/subaccounts/subaccounts.codecs.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.d.ts +1 -1
- package/dist/services/subaccounts/subaccounts.d.ts.map +1 -1
- package/dist/services/subaccounts/subaccounts.js +1 -2
- package/dist/services/subaccounts/subaccounts.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +10 -10
- package/dist/services/trades/trades.d.ts +2 -0
- package/dist/services/trades/trades.d.ts.map +1 -1
- package/dist/services/trades/trades.js +6 -6
- package/dist/services/trades/trades.js.map +1 -1
- package/dist/services/trades/trades.schemas.d.ts +2 -2
- package/dist/services/trades/trades.schemas.js +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.d.ts +9 -5
- package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.js +45 -26
- package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +12 -0
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js +26 -6
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
- package/dist/services/trailing-oneof-inputs.js +6 -1
- package/dist/services/trailing-oneof-inputs.js.map +1 -1
- package/dist/services/transfers/transfers.d.ts +2 -0
- package/dist/services/transfers/transfers.d.ts.map +1 -1
- package/dist/services/transfers/transfers.js +6 -11
- package/dist/services/transfers/transfers.js.map +1 -1
- package/dist/services/transfers/transfers.schemas.d.ts +4 -1
- package/dist/services/transfers/transfers.schemas.d.ts.map +1 -1
- package/dist/services/transfers/transfers.schemas.js +3 -1
- package/dist/services/transfers/transfers.schemas.js.map +1 -1
- package/dist/services/triggers/trigger-child-order.schemas.js +23 -18
- package/dist/services/triggers/trigger-child-order.schemas.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +291 -28
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +38 -22
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +183 -59
- package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.js +28 -20
- package/dist/services/triggers/triggers-output.schemas.js.map +1 -1
- package/dist/services/triggers/triggers.codecs.js +66 -3
- package/dist/services/triggers/triggers.codecs.js.map +1 -1
- package/dist/services/triggers/triggers.d.ts +6 -2
- package/dist/services/triggers/triggers.d.ts.map +1 -1
- package/dist/services/triggers/triggers.js +10 -8
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/services/vip/vip.js +1 -1
- package/dist/services/vip/vip.schemas.d.ts +23 -1
- package/dist/services/vip/vip.schemas.d.ts.map +1 -1
- package/dist/services/vip/vip.schemas.js +20 -2
- package/dist/services/vip/vip.schemas.js.map +1 -1
- package/dist/services/vip/vip.types.d.ts +2 -2
- package/dist/shared/catalog-config.d.ts +14 -2
- package/dist/shared/catalog-config.d.ts.map +1 -1
- package/dist/shared/catalog-config.js +2 -1
- package/dist/shared/catalog-config.js.map +1 -1
- package/dist/shared/connect-error-mapping.d.ts +3 -0
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +45 -6
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/errors.d.ts +79 -6
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +92 -4
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/rate-limit.schemas.d.ts +1 -1
- package/dist/shared/request-options.d.ts +7 -0
- package/dist/shared/request-options.d.ts.map +1 -1
- package/dist/shared/request-options.js +6 -1
- package/dist/shared/request-options.js.map +1 -1
- package/dist/shared/schemas.js +1 -1
- package/dist/shared/subscription-errors.js +12 -1
- package/dist/shared/subscription-errors.js.map +1 -1
- package/dist/shared/transports.d.ts.map +1 -1
- package/dist/shared/transports.js +9 -2
- package/dist/shared/transports.js.map +1 -1
- package/dist/shared/wire-bounds.js +3 -1
- package/dist/shared/wire-bounds.js.map +1 -1
- package/dist/smart-account/index.d.ts +2 -1
- package/dist/smart-account/index.js +2 -1
- package/dist/smart-account/smart-account.d.ts +5 -4
- package/dist/smart-account/smart-account.d.ts.map +1 -1
- package/dist/smart-account/smart-account.js +37 -8
- package/dist/smart-account/smart-account.js.map +1 -1
- package/dist/utils/numbers.js +4 -1
- package/dist/utils/numbers.js.map +1 -1
- package/dist/wired-services.js +5 -5
- package/dist/wired-services.js.map +1 -1
- package/package.json +9 -4
- package/dist/gen/collab/v1/whiteboard_pb.d.ts +0 -829
- package/dist/gen/collab/v1/whiteboard_pb.d.ts.map +0 -1
- package/dist/gen/collab/v1/whiteboard_pb.js +0 -250
- package/dist/gen/collab/v1/whiteboard_pb.js.map +0 -1
- package/dist/gen/layout/v1/layout_pb.d.ts +0 -1289
- package/dist/gen/layout/v1/layout_pb.d.ts.map +0 -1
- package/dist/gen/layout/v1/layout_pb.js +0 -313
- package/dist/gen/layout/v1/layout_pb.js.map +0 -1
- package/dist/gen/polychart/events/v1/polychart_events_pb.d.ts +0 -192
- package/dist/gen/polychart/events/v1/polychart_events_pb.d.ts.map +0 -1
- package/dist/gen/polychart/events/v1/polychart_events_pb.js +0 -57
- package/dist/gen/polychart/events/v1/polychart_events_pb.js.map +0 -1
- package/dist/gen/polychart/v1/polychart_pb.d.ts +0 -1208
- package/dist/gen/polychart/v1/polychart_pb.d.ts.map +0 -1
- package/dist/gen/polychart/v1/polychart_pb.js +0 -244
- package/dist/gen/polychart/v1/polychart_pb.js.map +0 -1
- package/dist/services/whiteboard/service.d.ts +0 -8
- package/dist/services/whiteboard/service.d.ts.map +0 -1
- package/dist/services/whiteboard/service.js +0 -9
- package/dist/services/whiteboard/service.js.map +0 -1
- package/dist/services/whiteboard/whiteboard.codecs.js +0 -55
- package/dist/services/whiteboard/whiteboard.codecs.js.map +0 -1
- package/dist/services/whiteboard/whiteboard.d.ts +0 -42
- package/dist/services/whiteboard/whiteboard.d.ts.map +0 -1
- package/dist/services/whiteboard/whiteboard.js +0 -76
- package/dist/services/whiteboard/whiteboard.js.map +0 -1
- package/dist/services/whiteboard/whiteboard.schemas.d.ts +0 -771
- package/dist/services/whiteboard/whiteboard.schemas.d.ts.map +0 -1
- package/dist/services/whiteboard/whiteboard.schemas.js +0 -132
- package/dist/services/whiteboard/whiteboard.schemas.js.map +0 -1
- package/dist/services/whiteboard/whiteboard.types.d.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;;;AAgBA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CACzE,IAAI,CAAC,QACD,MAAM,IAAI,mBAAmB,0DAA0D;CAG3F,MAAM,wBAAQ,IAAI,eAAe,CAAC;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pB,oBAAoB,OAAO,MAAM,kBAAkB;CACnD,oBAAoB,MAAM;AAC9B,EAAE,CACN;AASA,MAAM,uCAAuC,EAAE,KAC3C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,IAAI;CACrB,MAAM,EAAE,QAAA,CAA+C;CACvD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,uCAAuC,cAAc,OAAO;AACtE,EAAE,CACN;AAEA,MAAM,GAAA,IACyC,+BAC3C,GAAG,wCACH,uCAAuC;AAE3C,MAAM,yCAAyC,EAAE,KAC7C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,KAAK;CACtB,MAAM,EAAE,SAAS;;;;;;;CAOjB,CAAC;CACD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,OAAO;AAC1C,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,oCAAoC,OAAO;AACrD,EAAE,CACN;AAEA,MAAa,0CAA0C,EAAE,MAAM,CAC3D,sCACA,sCACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"trading-withdraws.schemas.js","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PositiveUint32InputSchema } from \"../shared.js\";\nimport { quantityInputToE18, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport type * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { WithdrawDestinationValidationCode } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { toU128, type U128Value } from \"../../utils/u128.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport {\n TradingWithdrawActionCodec,\n WithdrawDestinationValidationCodeCodec,\n} from \"./trading-withdraws.codecs.js\";\n\nconst DEFAULT_DEADLINE_SECONDS = 5 * 60;\n\nexport type TradingWithdrawIntentPayloadRequest = {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n amountE18: U128Value;\n deadlineTsSec: bigint;\n nonce: U128Value;\n destinationAddress: string;\n idempotencyKey: string;\n};\n\ntype CreateTradingWithdrawRequestBase = {\n subaccountId: bigint | undefined;\n payload: TradingWithdrawIntentPayloadRequest;\n payloadSignature?: Uint8Array;\n};\n\nfunction createNonce(): bigint {\n const random = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto);\n if (!random) {\n throw new ConfigurationError(\"Secure nonce generation requires crypto.getRandomValues.\");\n }\n\n const bytes = new BigUint64Array(1);\n random(bytes);\n const nonce = bytes[0]!;\n return nonce === 0n ? 1n : nonce;\n}\n\nfunction createTradingWithdrawPayload(input: {\n action: Proto.TradingWithdrawAction;\n assetId: number;\n destinationChainId: bigint;\n quantityScaled: bigint;\n destinationAddress: string;\n idempotencyKey: string;\n deadline: Date | undefined;\n}): TradingWithdrawIntentPayloadRequest {\n return {\n action: input.action,\n assetId: input.assetId,\n destinationChainId: input.destinationChainId,\n amountE18: toU128(input.quantityScaled),\n deadlineTsSec: BigInt(\n input.deadline\n ? Math.floor(input.deadline.getTime() / 1000)\n : Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS,\n ),\n nonce: toU128(createNonce()),\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n };\n}\n\n/** The same withdraw with a fresh default deadline and nonce, for signing again. */\nexport function renewTradingWithdrawPayload(\n payload: TradingWithdrawIntentPayloadRequest,\n): TradingWithdrawIntentPayloadRequest {\n return {\n ...payload,\n deadlineTsSec: BigInt(Math.floor(Date.now() / 1000) + DEFAULT_DEADLINE_SECONDS),\n nonce: toU128(createNonce()),\n };\n}\n\nexport function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_funding,\n assetId: input.assetId,\n destinationChainId: 0n,\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport function createCreateTradingWithdrawToExternalChainInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),\n signerWallet: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n payloadSignature: v.optional(v.instance(Uint8Array)),\n /**\n * When the signed authorization lapses. Defaults to five minutes from now\n * on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input): CreateTradingWithdrawRequestBase => {\n const quantityScaled = quantityInputToE18({\n scales,\n assetId: input.assetId,\n quantity: input.quantity,\n });\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n payloadSignature: input.payloadSignature,\n payload: createTradingWithdrawPayload({\n action: TradingWithdrawActionCodec.inputToProto.to_external_chain,\n assetId: input.assetId,\n destinationChainId: BigInt(input.destinationChainId),\n quantityScaled,\n destinationAddress: input.destinationAddress,\n idempotencyKey: input.idempotencyKey,\n deadline: input.deadline,\n }),\n };\n }),\n );\n}\n\nexport type CreateTradingWithdrawToFundingInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToFundingRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainInput = v.InferInput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport type CreateTradingWithdrawToExternalChainRequest = v.InferOutput<\n ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>\n>;\n\nexport const CreateTradingWithdrawResultSchema = v.object({\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n});\n\nexport type CreateTradingWithdrawResult = v.InferOutput<typeof CreateTradingWithdrawResultSchema>;\n\nexport const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;\nexport type CreateWalletTradingWithdrawResult = v.InferOutput<\n typeof CreateWalletTradingWithdrawResultSchema\n>;\n\nexport const ValidateWithdrawDestinationInputSchema = v.pipe(\n v.strictObject({\n destinationChainId: v.pipe(\n v.number(),\n v.integer(),\n v.gtValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n ),\n destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((input) => ({\n destinationChainId: BigInt(input.destinationChainId),\n destinationAddress: input.destinationAddress,\n })),\n);\n\nexport type ValidateWithdrawDestinationInput = v.InferInput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\nexport type ValidateWithdrawDestinationRequest = v.InferOutput<\n typeof ValidateWithdrawDestinationInputSchema\n>;\n\nconst ValidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(true),\n code: v.literal(WithdrawDestinationValidationCode.VALID),\n message: v.string(),\n canonicalDestinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),\n }),\n v.transform((result) => ({\n ...result,\n code: WithdrawDestinationValidationCodeCodec.protoToOutput[result.code],\n })),\n);\n\nconst {\n [WithdrawDestinationValidationCode.VALID]: _validWithdrawDestinationCode,\n ...InvalidWithdrawDestinationCodeCodec\n} = WithdrawDestinationValidationCodeCodec.protoToOutput;\n\nconst InvalidWithdrawDestinationResultSchema = v.pipe(\n v.object({\n valid: v.literal(false),\n code: v.picklist([\n WithdrawDestinationValidationCode.RESULT_UNSPECIFIED,\n WithdrawDestinationValidationCode.INVALID_ADDRESS,\n WithdrawDestinationValidationCode.UNSUPPORTED_CHAIN,\n WithdrawDestinationValidationCode.POLYESTER_SMART_ACCOUNT,\n WithdrawDestinationValidationCode.TOKEN_CONTRACT,\n WithdrawDestinationValidationCode.DENYLISTED_ADDRESS,\n ]),\n message: v.string(),\n canonicalDestinationAddress: v.string(),\n }),\n v.transform((result) => ({\n ...result,\n code: InvalidWithdrawDestinationCodeCodec[result.code],\n })),\n);\n\nexport const ValidateWithdrawDestinationResultSchema = v.union([\n ValidWithdrawDestinationResultSchema,\n InvalidWithdrawDestinationResultSchema,\n]);\n\nexport type ValidateWithdrawDestinationResult = v.InferOutput<\n typeof ValidateWithdrawDestinationResultSchema\n>;\n"],"mappings":";;;;;;;;;AAgBA,MAAM,2BAA2B;AAmBjC,SAAS,cAAsB;CAC3B,MAAM,SAAS,WAAW,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CACzE,IAAI,CAAC,QACD,MAAM,IAAI,mBAAmB,0DAA0D;CAG3F,MAAM,wBAAQ,IAAI,eAAe,CAAC;CAClC,OAAO,KAAK;CACZ,MAAM,QAAQ,MAAM;CACpB,OAAO,UAAU,KAAK,KAAK;AAC/B;AAEA,SAAS,6BAA6B,OAQE;CACpC,OAAO;EACH,QAAQ,MAAM;EACd,SAAS,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GACT,EAAE,QAAQ,GACV,EAAE,QAAQ,CAAC,GACX,EAAE,SAAS,OAAO,gBAAgB,CACtC;CACA,oBAAoB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AACnE,CAAC,GACD,EAAE,WAAW,WAAW;CACpB,oBAAoB,OAAO,MAAM,kBAAkB;CACnD,oBAAoB,MAAM;AAC9B,EAAE,CACN;AASA,MAAM,uCAAuC,EAAE,KAC3C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,IAAI;CACrB,MAAM,EAAE,QAAA,CAA+C;CACvD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;AAC5E,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,uCAAuC,cAAc,OAAO;AACtE,EAAE,CACN;AAEA,MAAM,GAAA,IACyC,+BAC3C,GAAG,wCACH,uCAAuC;AAE3C,MAAM,yCAAyC,EAAE,KAC7C,EAAE,OAAO;CACL,OAAO,EAAE,QAAQ,KAAK;CACtB,MAAM,EAAE,SAAS;;;;;;;CAOjB,CAAC;CACD,SAAS,EAAE,OAAO;CAClB,6BAA6B,EAAE,OAAO;AAC1C,CAAC,GACD,EAAE,WAAW,YAAY;CACrB,GAAG;CACH,MAAM,oCAAoC,OAAO;AACrD,EAAE,CACN;AAEA,MAAa,0CAA0C,EAAE,MAAM,CAC3D,sCACA,sCACJ,CAAC"}
|
|
@@ -4,6 +4,11 @@ import { positiveDecimalInputToScaled } from "../shared/decimal-surface.js";
|
|
|
4
4
|
//#region src/services/trailing-oneof-inputs.ts
|
|
5
5
|
/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */
|
|
6
6
|
const MAX_SLIPPAGE_BPS = 1e4;
|
|
7
|
+
/**
|
|
8
|
+
* Cap for a market order or market child that sells, where 100% would leave no
|
|
9
|
+
* positive price, and for every trailing stop, whichever side it trades.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_SELLING_SLIPPAGE_BPS = 9999;
|
|
7
12
|
const MAX_TRAILING_DISTANCE_BPS = 1e4;
|
|
8
13
|
function parseTrailingDistanceInput(scales, distance, fieldName) {
|
|
9
14
|
if (distance.kind === "none") return {
|
|
@@ -41,6 +46,6 @@ function exceedsMax(value, max) {
|
|
|
41
46
|
return max !== void 0 && value > max;
|
|
42
47
|
}
|
|
43
48
|
//#endregion
|
|
44
|
-
export { MAX_SLIPPAGE_BPS, parseSlippageInput, parseTrailingDistanceInput };
|
|
49
|
+
export { MAX_SELLING_SLIPPAGE_BPS, MAX_SLIPPAGE_BPS, parseSlippageInput, parseTrailingDistanceInput };
|
|
45
50
|
|
|
46
51
|
//# sourceMappingURL=trailing-oneof-inputs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */\nexport const MAX_SLIPPAGE_BPS = 10_000;\n\nconst MAX_TRAILING_DISTANCE_BPS = 10_000;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: bigint }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps > MAX_TRAILING_DISTANCE_BPS) {\n throw new CatalogConversionError(\n `${fieldName}.bps`,\n `${fieldName}Bps must be between 1 and ${MAX_TRAILING_DISTANCE_BPS}`,\n );\n }\n return { case: \"trailingDistanceBps\", value: bps };\n}\n\nexport function parseSlippageInput<const TicksCase extends string, const BpsCase extends string>(\n scales: SdkScales,\n slippage: SlippageInput | undefined,\n options: SlippageOptions<TicksCase, BpsCase>,\n): SlippageOneof<TicksCase, BpsCase> {\n if (!slippage || slippage.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (slippage.kind === \"slippage\") {\n return {\n case: options.ticksCase,\n value: positiveDecimalInputToScaled(\n `${options.fieldName}.slippage`,\n slippage.slippage,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(slippage.bps);\n if (bps === undefined || bps <= 0 || exceedsMax(bps, options.maxBps)) {\n throw new CatalogConversionError(\n `${options.fieldName}.bps`,\n `${options.fieldName}Bps must be ${\n options.maxBps === undefined\n ? \"a positive integer\"\n : `between 1 and ${options.maxBps}`\n }`,\n );\n }\n return { case: options.bpsCase, value: bps };\n}\n\nfunction exceedsMax(value: number, max: number | undefined): boolean {\n return max !== undefined && value > max;\n}\n"],"mappings":";;;;;AAOA,MAAa,mBAAmB;
|
|
1
|
+
{"version":3,"file":"trailing-oneof-inputs.js","names":[],"sources":["../../src/services/trailing-oneof-inputs.ts"],"sourcesContent":["import { positiveDecimalInputToScaled, type SdkScales } from \"../shared/decimal-surface.js\";\nimport { CatalogConversionError } from \"../catalogs/types.js\";\nimport { parseOptionalPositiveIntLike } from \"../utils/numbers.js\";\n\ntype PositiveIntLikeInput = string | number;\n\n/** Product-wide cap for bps slippage inputs (market IOC, attached and standalone trailing stops). */\nexport const MAX_SLIPPAGE_BPS = 10_000;\n\n/**\n * Cap for a market order or market child that sells, where 100% would leave no\n * positive price, and for every trailing stop, whichever side it trades.\n */\nexport const MAX_SELLING_SLIPPAGE_BPS = MAX_SLIPPAGE_BPS - 1;\n\nconst MAX_TRAILING_DISTANCE_BPS = 10_000;\n\n/**\n * Trailing distance and slippage inputs: absolute price distances and\n * slippages are decimal price strings (e.g. \"0.50\"), converted to wire ticks\n * via the price scale; basis points are integers.\n */\nexport type TrailingDistanceInput =\n | { kind: \"distance\"; distance: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\nexport type SlippageInput =\n | { kind: \"slippage\"; slippage: string }\n | { kind: \"bps\"; bps: PositiveIntLikeInput }\n | { kind: \"none\" };\n\ntype UnsetOneof = { case: undefined; value: undefined };\n\ntype TrailingDistanceOneof =\n | { case: \"trailingDistanceTicks\"; value: bigint }\n | { case: \"trailingDistanceBps\"; value: number }\n | UnsetOneof;\n\ntype SlippageOneof<TicksCase extends string, BpsCase extends string> =\n | { case: TicksCase; value: bigint }\n | { case: BpsCase; value: number }\n | UnsetOneof;\n\ntype SlippageOptions<TicksCase extends string, BpsCase extends string> = {\n fieldName: string;\n ticksCase: TicksCase;\n bpsCase: BpsCase;\n maxBps?: number;\n};\n\nexport function parseTrailingDistanceInput(\n scales: SdkScales,\n distance: TrailingDistanceInput,\n fieldName: string,\n): TrailingDistanceOneof {\n if (distance.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (distance.kind === \"distance\") {\n return {\n case: \"trailingDistanceTicks\",\n value: positiveDecimalInputToScaled(\n `${fieldName}.distance`,\n distance.distance,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(distance.bps);\n if (bps === undefined || bps > MAX_TRAILING_DISTANCE_BPS) {\n throw new CatalogConversionError(\n `${fieldName}.bps`,\n `${fieldName}Bps must be between 1 and ${MAX_TRAILING_DISTANCE_BPS}`,\n );\n }\n return { case: \"trailingDistanceBps\", value: bps };\n}\n\nexport function parseSlippageInput<const TicksCase extends string, const BpsCase extends string>(\n scales: SdkScales,\n slippage: SlippageInput | undefined,\n options: SlippageOptions<TicksCase, BpsCase>,\n): SlippageOneof<TicksCase, BpsCase> {\n if (!slippage || slippage.kind === \"none\") {\n return { case: undefined, value: undefined };\n }\n if (slippage.kind === \"slippage\") {\n return {\n case: options.ticksCase,\n value: positiveDecimalInputToScaled(\n `${options.fieldName}.slippage`,\n slippage.slippage,\n scales.price(),\n ),\n };\n }\n\n const bps = parseOptionalPositiveIntLike(slippage.bps);\n if (bps === undefined || bps <= 0 || exceedsMax(bps, options.maxBps)) {\n throw new CatalogConversionError(\n `${options.fieldName}.bps`,\n `${options.fieldName}Bps must be ${\n options.maxBps === undefined\n ? \"a positive integer\"\n : `between 1 and ${options.maxBps}`\n }`,\n );\n }\n return { case: options.bpsCase, value: bps };\n}\n\nfunction exceedsMax(value: number, max: number | undefined): boolean {\n return max !== undefined && value > max;\n}\n"],"mappings":";;;;;AAOA,MAAa,mBAAmB;;;;;AAMhC,MAAa,2BAA2B;AAExC,MAAM,4BAA4B;AAoClC,SAAgB,2BACZ,QACA,UACA,WACqB;CACrB,IAAI,SAAS,SAAS,QAClB,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAClB,OAAO;EACH,MAAM;EACN,OAAO,6BACH,GAAG,UAAU,YACb,SAAS,UACT,OAAO,MAAM,CACjB;CACJ;CAGJ,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,MAAM,2BAC3B,MAAM,IAAI,uBACN,GAAG,UAAU,OACb,GAAG,UAAU,4BAA4B,2BAC7C;CAEJ,OAAO;EAAE,MAAM;EAAuB,OAAO;CAAI;AACrD;AAEA,SAAgB,mBACZ,QACA,UACA,SACiC;CACjC,IAAI,CAAC,YAAY,SAAS,SAAS,QAC/B,OAAO;EAAE,MAAM,KAAA;EAAW,OAAO,KAAA;CAAU;CAE/C,IAAI,SAAS,SAAS,YAClB,OAAO;EACH,MAAM,QAAQ;EACd,OAAO,6BACH,GAAG,QAAQ,UAAU,YACrB,SAAS,UACT,OAAO,MAAM,CACjB;CACJ;CAGJ,MAAM,MAAM,6BAA6B,SAAS,GAAG;CACrD,IAAI,QAAQ,KAAA,KAAa,OAAO,KAAK,WAAW,KAAK,QAAQ,MAAM,GAC/D,MAAM,IAAI,uBACN,GAAG,QAAQ,UAAU,OACrB,GAAG,QAAQ,UAAU,cACjB,QAAQ,WAAW,KAAA,IACb,uBACA,iBAAiB,QAAQ,UAEvC;CAEJ,OAAO;EAAE,MAAM,QAAQ;EAAS,OAAO;CAAI;AAC/C;AAEA,SAAS,WAAW,OAAe,KAAkC;CACjE,OAAO,QAAQ,KAAA,KAAa,QAAQ;AACxC"}
|
|
@@ -24,6 +24,8 @@ declare class TransfersService {
|
|
|
24
24
|
}>;
|
|
25
25
|
/**
|
|
26
26
|
* Subscribes to private ledger transfer updates on private:ledger:transfers:{accountId}:proto and emits parsed transfer rows.
|
|
27
|
+
* Each publication batches transfer legs, emitted one at a time; `(transferId, accountCode,
|
|
28
|
+
* isDebit)` identifies a leg, and a repeated identity replaces the earlier copy.
|
|
27
29
|
*/
|
|
28
30
|
subscribe(input: SubscribeTransfersInput): () => void;
|
|
29
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.d.ts","names":[],"sources":["../../../src/services/transfers/transfers.ts"],"mappings":";;;;;;;;UAoBU,gCAAgC,mBAAmB;EACzD;;;;;cAMS;;EAML,YAAA,YAAY,mBACZ,UAAU,mBACV,UAAU;;;;EAUR,KACF,QAAO,oBACP,UAAU,0BACX;IAAU,WAAW;IAAkB
|
|
1
|
+
{"version":3,"file":"transfers.d.ts","names":[],"sources":["../../../src/services/transfers/transfers.ts"],"mappings":";;;;;;;;UAoBU,gCAAgC,mBAAmB;EACzD;;;;;cAMS;;EAML,YAAA,YAAY,mBACZ,UAAU,mBACV,UAAU;;;;EAUR,KACF,QAAO,oBACP,UAAU,0BACX;IAAU,WAAW;IAAkB;;;;;;;EAa1C,UAAU,OAAO"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { parse } from "../../shared/validation.js";
|
|
2
2
|
import { toConnectCallOptions } from "../../shared/request-options.js";
|
|
3
|
-
import {
|
|
4
|
-
import { LedgerReadService, TransferRowSchema } from "../../gen/ledger/read/v1/ledger_read_pb.js";
|
|
3
|
+
import { deliverBatch } from "../../shared/subscription-errors.js";
|
|
5
4
|
import { resolveAccountScopedInput } from "../subaccount-resolver.js";
|
|
5
|
+
import { LedgerReadService, TransferRowBatchSchema } from "../../gen/ledger/read/v1/ledger_read_pb.js";
|
|
6
6
|
import { LedgerTransferSchema, ListTransfersInputSchema } from "./transfers.schemas.js";
|
|
7
7
|
import { createClient } from "@connectrpc/connect";
|
|
8
8
|
import * as v from "valibot";
|
|
@@ -33,20 +33,15 @@ var TransfersService = class {
|
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Subscribes to private ledger transfer updates on private:ledger:transfers:{accountId}:proto and emits parsed transfer rows.
|
|
36
|
+
* Each publication batches transfer legs, emitted one at a time; `(transferId, accountCode,
|
|
37
|
+
* isDebit)` identifies a leg, and a repeated identity replaces the earlier copy.
|
|
36
38
|
*/
|
|
37
39
|
subscribe(input) {
|
|
38
40
|
const channel = `private:ledger:transfers:${input.accountId}:proto`;
|
|
39
41
|
return this.#realtime.connectProtoChannel({
|
|
40
42
|
channel,
|
|
41
|
-
schema:
|
|
42
|
-
onPublication: (
|
|
43
|
-
try {
|
|
44
|
-
const tr = parse(LedgerTransferSchema, m);
|
|
45
|
-
input.onEvent(tr);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
input.onError?.(publicationHandlerErrorContext(channel, error));
|
|
48
|
-
}
|
|
49
|
-
},
|
|
43
|
+
schema: TransferRowBatchSchema,
|
|
44
|
+
onPublication: (batch) => deliverBatch(channel, batch.events, (row) => input.onEvent(parse(LedgerTransferSchema, row)), input.onError),
|
|
50
45
|
onConnected: input.onOpen,
|
|
51
46
|
onDisconnected: input.onClose,
|
|
52
47
|
onError: input.onError
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","Proto.
|
|
1
|
+
{"version":3,"file":"transfers.js","names":["#client","Proto.LedgerReadService","#realtime","#resolver","Proto.TransferRowBatchSchema"],"sources":["../../../src/services/transfers/transfers.ts"],"sourcesContent":["import * as Proto from \"../../gen/ledger/read/v1/ledger_read_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport { deliverBatch } from \"../../shared/subscription-errors.js\";\nimport * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PolyesterRealtime } from \"../../realtime/index.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport {\n LedgerTransferSchema,\n ListTransfersInputSchema,\n type LedgerTransfer,\n type ListTransfersInput,\n} from \"./transfers.schemas.js\";\n\ninterface SubscribeTransfersInput extends BaseSubscribeInput<LedgerTransfer> {\n accountId: string;\n}\n\n/**\n * Reads and streams ledger transfer activity for the authenticated account scope.\n */\nexport class TransfersService {\n #client: Client<typeof Proto.LedgerReadService>;\n #realtime: PolyesterRealtime;\n #resolver?: SubaccountResolver;\n\n constructor(\n transports: AuthApiTransports,\n realtime: PolyesterRealtime,\n resolver: SubaccountResolver | undefined,\n ) {\n this.#client = createClient(Proto.LedgerReadService, transports.authApi);\n this.#realtime = realtime;\n this.#resolver = resolver;\n }\n\n /**\n * Returns ledger transfers for the resolved account scope with limit, direction, timestamp, code, ledger, and page-token filters.\n */\n async list(\n input: ListTransfersInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ transfers: LedgerTransfer[]; nextPageToken: string }> {\n const resolved = resolveAccountScopedInput(input, this.#resolver);\n const validatedInput = parse(ListTransfersInputSchema, resolved);\n const res = await this.#client.listTransfers(validatedInput, toConnectCallOptions(options));\n const transfers = parse(v.array(LedgerTransferSchema), res.transfers);\n return { transfers, nextPageToken: res.nextPageToken };\n }\n\n /**\n * Subscribes to private ledger transfer updates on private:ledger:transfers:{accountId}:proto and emits parsed transfer rows.\n * Each publication batches transfer legs, emitted one at a time; `(transferId, accountCode,\n * isDebit)` identifies a leg, and a repeated identity replaces the earlier copy.\n */\n subscribe(input: SubscribeTransfersInput): () => void {\n const channel = `private:ledger:transfers:${input.accountId}:proto`;\n return this.#realtime.connectProtoChannel({\n channel,\n schema: Proto.TransferRowBatchSchema,\n onPublication: (batch) =>\n deliverBatch(\n channel,\n batch.events,\n (row) => input.onEvent(parse(LedgerTransferSchema, row)),\n input.onError,\n ),\n onConnected: input.onOpen,\n onDisconnected: input.onClose,\n onError: input.onError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CAEA,YACI,YACA,UACA,UACF;EACE,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;EACvE,KAAKC,YAAY;EACjB,KAAKC,YAAY;CACrB;;;;CAKA,MAAM,KACF,QAA4B,CAAC,GAC7B,SAC+D;EAC/D,MAAM,WAAW,0BAA0B,OAAO,KAAKA,SAAS;EAChE,MAAM,iBAAiB,MAAM,0BAA0B,QAAQ;EAC/D,MAAM,MAAM,MAAM,KAAKH,QAAQ,cAAc,gBAAgB,qBAAqB,OAAO,CAAC;EAE1F,OAAO;GAAE,WADS,MAAM,EAAE,MAAM,oBAAoB,GAAG,IAAI,SAC1C;GAAG,eAAe,IAAI;EAAc;CACzD;;;;;;CAOA,UAAU,OAA4C;EAClD,MAAM,UAAU,4BAA4B,MAAM,UAAU;EAC5D,OAAO,KAAKE,UAAU,oBAAoB;GACtC;GACA,QAAQE;GACR,gBAAgB,UACZ,aACI,SACA,MAAM,SACL,QAAQ,MAAM,QAAQ,MAAM,sBAAsB,GAAG,CAAC,GACvD,MAAM,OACV;GACJ,aAAa,MAAM;GACnB,gBAAgB,MAAM;GACtB,SAAS,MAAM;EACnB,CAAC;CACL;AACJ"}
|
|
@@ -37,6 +37,7 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
37
37
|
readonly address: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
38
38
|
readonly chainId: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
|
|
39
39
|
}, undefined>, undefined>;
|
|
40
|
+
readonly transferId: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
40
41
|
}, undefined>, v.TransformAction<{
|
|
41
42
|
assetId: number;
|
|
42
43
|
amountE18?: {
|
|
@@ -65,6 +66,7 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
65
66
|
address: string;
|
|
66
67
|
chainId?: number | undefined;
|
|
67
68
|
} | undefined;
|
|
69
|
+
transferId: string;
|
|
68
70
|
}, {
|
|
69
71
|
destination?: {
|
|
70
72
|
kind: "unspecified" | "funding_account" | "trading_account" | "external_address" | "private_counterparty" | "fee_account" | "system_account";
|
|
@@ -78,11 +80,12 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
78
80
|
address: string;
|
|
79
81
|
chainId?: number | undefined;
|
|
80
82
|
} | undefined;
|
|
83
|
+
transferId: string;
|
|
81
84
|
assetId: number;
|
|
82
85
|
amount: string;
|
|
83
86
|
balanceAfter: string | undefined;
|
|
84
87
|
type: "unspecified" | "internal_transfer" | "deposit" | "withdraw" | "maker_fee" | "taker_fee" | "trade_base" | "trade_quote" | "rebate" | "funding_to_trading" | "trading_to_funding" | "trading_withdraw_reserve" | "funding_user_transfer" | "trading_withdraw_request_fee";
|
|
85
|
-
accountCode: "unspecified" | "
|
|
88
|
+
accountCode: "unspecified" | "trading" | "funding";
|
|
86
89
|
timestamp: number;
|
|
87
90
|
isDebit: boolean;
|
|
88
91
|
linkId: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.schemas.d.ts","names":[],"sources":["../../../src/services/transfers/transfers.schemas.ts"],"mappings":";;;cAiCa,0BAAwB,EAAA;;;;;;KAOzB,qBAAqB,EAAE,mBAAmB;;cAGzC,sBAAoB,EAAA,yBAAA,EAAA
|
|
1
|
+
{"version":3,"file":"transfers.schemas.d.ts","names":[],"sources":["../../../src/services/transfers/transfers.schemas.ts"],"mappings":";;;cAiCa,0BAAwB,EAAA;;;;;;KAOzB,qBAAqB,EAAE,mBAAmB;;cAGzC,sBAAoB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2CrB,iBAAiB,EAAE,mBAAmB;cAErC,0BAAwB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwBzB,qBAAqB,EAAE,kBAAkB"}
|
|
@@ -32,11 +32,13 @@ const LedgerTransferSchema = v.pipe(v.object({
|
|
|
32
32
|
linkId: v.optional(v.bigint()),
|
|
33
33
|
flowId: v.optional(v.string()),
|
|
34
34
|
source: v.optional(LedgerTransferSideSchema),
|
|
35
|
-
destination: v.optional(LedgerTransferSideSchema)
|
|
35
|
+
destination: v.optional(LedgerTransferSideSchema),
|
|
36
|
+
transferId: v.optional(v.string(), "")
|
|
36
37
|
}), v.transform((tr) => {
|
|
37
38
|
const amount = fromU128(tr.amountE18);
|
|
38
39
|
const linkId = tr.linkId && tr.linkId > 0n ? tr.linkId.toString() : void 0;
|
|
39
40
|
return {
|
|
41
|
+
transferId: tr.transferId,
|
|
40
42
|
assetId: tr.assetId,
|
|
41
43
|
amount: scaledToDecimalOutput(amount, 18),
|
|
42
44
|
balanceAfter: tr.balanceAfterE18 !== void 0 ? scaledToDecimalOutput(fromU128(tr.balanceAfterE18), 18) : void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfers.schemas.js","names":[],"sources":["../../../src/services/transfers/transfers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport {\n AccountCodeCodec,\n TRANSFER_CODE_VALUES,\n TransferCodeCodec,\n} from \"../../shared/ledger-codes.js\";\nimport { enumLabel, enumLabelSchema } from \"../../shared/proto-enum-codec.js\";\nimport { wireTimestampToMs } from \"../../utils/time.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsToUsInputSchema,\n U128Schema,\n} from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { E18_SCALE, scaledToDecimalOutput } from \"../../shared/decimal-surface.js\";\nimport { TransferSideKindCodec } from \"./transfers.codecs.js\";\n\nconst WireTimestampInputSchema = v.union([\n v.bigint(),\n v.number(),\n v.pipe(\n v.string(),\n v.regex(/^\\d+$/),\n v.transform((value) => BigInt(value)),\n ),\n]);\n\nconst TransferSideKindSchema = enumLabelSchema(TransferSideKindCodec.protoToOutput);\n\nexport const LedgerTransferSideSchema = v.object({\n kind: TransferSideKindSchema,\n accountId: OptionalPublicIdSchema,\n address: v.optional(v.string(), \"\"),\n chainId: v.optional(v.number()),\n});\n\nexport type LedgerTransferSide = v.InferOutput<typeof LedgerTransferSideSchema>;\n\n/** Parses ledger transfer rows whose monetary fields use the protocol's fixed E18 scale. */\nexport const LedgerTransferSchema = v.pipe(\n v.object({\n assetId: v.number(),\n amountE18: v.optional(U128Schema),\n balanceAfterE18: v.optional(U128Schema),\n isDebit: v.boolean(),\n transferCode: v.number(),\n accountCode: v.number(),\n tsUs: WireTimestampInputSchema,\n linkId: v.optional(v.bigint()),\n flowId: v.optional(v.string()),\n source: v.optional(LedgerTransferSideSchema),\n destination: v.optional(LedgerTransferSideSchema),\n }),\n v.transform((tr) => {\n const amount = fromU128(tr.amountE18);\n const linkId = tr.linkId && tr.linkId > 0n ? tr.linkId.toString() : undefined;\n\n const output = {\n assetId: tr.assetId,\n amount: scaledToDecimalOutput(amount, E18_SCALE),\n balanceAfter:\n tr.balanceAfterE18 !== undefined\n ? scaledToDecimalOutput(fromU128(tr.balanceAfterE18), E18_SCALE)\n : undefined,\n type: enumLabel(TransferCodeCodec.protoToOutput, tr.transferCode),\n accountCode: enumLabel(AccountCodeCodec.protoToOutput, tr.accountCode),\n timestamp: wireTimestampToMs(tr.tsUs),\n isDebit: tr.isDebit,\n linkId,\n flowId: tr.flowId?.trim() ?? \"\",\n };\n\n return {\n ...output,\n ...(tr.source ? { source: tr.source } : {}),\n ...(tr.destination ? { destination: tr.destination } : {}),\n };\n }),\n);\n\nexport type LedgerTransfer = v.InferOutput<typeof LedgerTransferSchema>;\n\nexport const ListTransfersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n ledger: v.optional(v.number(), 0),\n limit: v.optional(v.number()),\n reversed: v.optional(v.boolean(), false),\n timestampMin: OptionalTimestampMsToUsInputSchema,\n timestampMax: OptionalTimestampMsToUsInputSchema,\n transferCode: v.optional(\n v.pipe(\n v.picklist(TRANSFER_CODE_VALUES),\n v.transform((value) => TransferCodeCodec.inputToProto[value]),\n ),\n ),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, timestampMin, timestampMax, ...input }) => ({\n ...input,\n tsMinUs: timestampMin,\n tsMaxUs: timestampMax,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type ListTransfersInput = v.InferInput<typeof ListTransfersInputSchema>;\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,2BAA2B,EAAE,MAAM;CACrC,EAAE,OAAO;CACT,EAAE,OAAO;CACT,EAAE,KACE,EAAE,OAAO,GACT,EAAE,MAAM,OAAO,GACf,EAAE,WAAW,UAAU,OAAO,KAAK,CAAC,CACxC;AACJ,CAAC;AAED,MAAM,yBAAyB,gBAAgB,sBAAsB,aAAa;AAElF,MAAa,2BAA2B,EAAE,OAAO;CAC7C,MAAM;CACN,WAAW;CACX,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAClC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC;AAClC,CAAC;;AAKD,MAAa,uBAAuB,EAAE,KAClC,EAAE,OAAO;CACL,SAAS,EAAE,OAAO;CAClB,WAAW,EAAE,SAAS,UAAU;CAChC,iBAAiB,EAAE,SAAS,UAAU;CACtC,SAAS,EAAE,QAAQ;CACnB,cAAc,EAAE,OAAO;CACvB,aAAa,EAAE,OAAO;CACtB,MAAM;CACN,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;CAC7B,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;CAC7B,QAAQ,EAAE,SAAS,wBAAwB;CAC3C,aAAa,EAAE,SAAS,wBAAwB;
|
|
1
|
+
{"version":3,"file":"transfers.schemas.js","names":[],"sources":["../../../src/services/transfers/transfers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { fromU128 } from \"../../utils/u128.js\";\nimport {\n AccountCodeCodec,\n TRANSFER_CODE_VALUES,\n TransferCodeCodec,\n} from \"../../shared/ledger-codes.js\";\nimport { enumLabel, enumLabelSchema } from \"../../shared/proto-enum-codec.js\";\nimport { wireTimestampToMs } from \"../../utils/time.js\";\nimport {\n OptionalPublicIdSchema,\n OptionalTimestampMsToUsInputSchema,\n U128Schema,\n} from \"../../shared/schemas.js\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { E18_SCALE, scaledToDecimalOutput } from \"../../shared/decimal-surface.js\";\nimport { TransferSideKindCodec } from \"./transfers.codecs.js\";\n\nconst WireTimestampInputSchema = v.union([\n v.bigint(),\n v.number(),\n v.pipe(\n v.string(),\n v.regex(/^\\d+$/),\n v.transform((value) => BigInt(value)),\n ),\n]);\n\nconst TransferSideKindSchema = enumLabelSchema(TransferSideKindCodec.protoToOutput);\n\nexport const LedgerTransferSideSchema = v.object({\n kind: TransferSideKindSchema,\n accountId: OptionalPublicIdSchema,\n address: v.optional(v.string(), \"\"),\n chainId: v.optional(v.number()),\n});\n\nexport type LedgerTransferSide = v.InferOutput<typeof LedgerTransferSideSchema>;\n\n/** Parses ledger transfer rows whose monetary fields use the protocol's fixed E18 scale. */\nexport const LedgerTransferSchema = v.pipe(\n v.object({\n assetId: v.number(),\n amountE18: v.optional(U128Schema),\n balanceAfterE18: v.optional(U128Schema),\n isDebit: v.boolean(),\n transferCode: v.number(),\n accountCode: v.number(),\n tsUs: WireTimestampInputSchema,\n linkId: v.optional(v.bigint()),\n flowId: v.optional(v.string()),\n source: v.optional(LedgerTransferSideSchema),\n destination: v.optional(LedgerTransferSideSchema),\n transferId: v.optional(v.string(), \"\"),\n }),\n v.transform((tr) => {\n const amount = fromU128(tr.amountE18);\n const linkId = tr.linkId && tr.linkId > 0n ? tr.linkId.toString() : undefined;\n\n const output = {\n transferId: tr.transferId,\n assetId: tr.assetId,\n amount: scaledToDecimalOutput(amount, E18_SCALE),\n balanceAfter:\n tr.balanceAfterE18 !== undefined\n ? scaledToDecimalOutput(fromU128(tr.balanceAfterE18), E18_SCALE)\n : undefined,\n type: enumLabel(TransferCodeCodec.protoToOutput, tr.transferCode),\n accountCode: enumLabel(AccountCodeCodec.protoToOutput, tr.accountCode),\n timestamp: wireTimestampToMs(tr.tsUs),\n isDebit: tr.isDebit,\n linkId,\n flowId: tr.flowId?.trim() ?? \"\",\n };\n\n return {\n ...output,\n ...(tr.source ? { source: tr.source } : {}),\n ...(tr.destination ? { destination: tr.destination } : {}),\n };\n }),\n);\n\nexport type LedgerTransfer = v.InferOutput<typeof LedgerTransferSchema>;\n\nexport const ListTransfersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n ledger: v.optional(v.number(), 0),\n limit: v.optional(v.number()),\n reversed: v.optional(v.boolean(), false),\n timestampMin: OptionalTimestampMsToUsInputSchema,\n timestampMax: OptionalTimestampMsToUsInputSchema,\n transferCode: v.optional(\n v.pipe(\n v.picklist(TRANSFER_CODE_VALUES),\n v.transform((value) => TransferCodeCodec.inputToProto[value]),\n ),\n ),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n v.transform(({ account, timestampMin, timestampMax, ...input }) => ({\n ...input,\n tsMinUs: timestampMin,\n tsMaxUs: timestampMax,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type ListTransfersInput = v.InferInput<typeof ListTransfersInputSchema>;\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,2BAA2B,EAAE,MAAM;CACrC,EAAE,OAAO;CACT,EAAE,OAAO;CACT,EAAE,KACE,EAAE,OAAO,GACT,EAAE,MAAM,OAAO,GACf,EAAE,WAAW,UAAU,OAAO,KAAK,CAAC,CACxC;AACJ,CAAC;AAED,MAAM,yBAAyB,gBAAgB,sBAAsB,aAAa;AAElF,MAAa,2BAA2B,EAAE,OAAO;CAC7C,MAAM;CACN,WAAW;CACX,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAClC,SAAS,E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E,SAAS,EAAE,OAAO,CAAC;CAC5B,UAAU,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK;CACvC,cAAc;CACd,cAAc;CACd,cAAc,EAAE,SACZ,EAAE,KACE,EAAE,SAAS,oBAAoB,GAC/B,EAAE,WAAW,UAAU,kBAAkB,aAAa,MAAM,CAChE,CACJ;CACA,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE;AAC1D,CAAC,GACD,EAAE,WAAW,EAAE,SAAS,cAAc,cAAc,GAAG,aAAa;CAChE,GAAG;CACH,SAAS;CACT,SAAS;CACT,cAAc,2BAA2B,OAAO;AACpD,EAAE,CACN"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { positiveDecimalInputToScaled } from "../../shared/decimal-surface.js";
|
|
2
2
|
import { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from "../shared.js";
|
|
3
3
|
import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
|
|
4
|
+
import "../../gen/orders/v1/orders_pb.js";
|
|
4
5
|
import { FEE_ASSET_VALUES, FeeAssetCodec, ORDER_SIDE_VALUES, OrderSideCodec, SELF_TRADE_PREVENTION_MODE_VALUES, SelfTradePreventionModeCodec } from "../orders/order-enums.codecs.js";
|
|
5
|
-
import { MAX_SLIPPAGE_BPS, parseSlippageInput } from "../trailing-oneof-inputs.js";
|
|
6
|
+
import { MAX_SELLING_SLIPPAGE_BPS, MAX_SLIPPAGE_BPS, parseSlippageInput } from "../trailing-oneof-inputs.js";
|
|
6
7
|
import { TriggerLimitFokSchema, TriggerLimitGtcSchema, TriggerLimitIocSchema, TriggerMarketIocSchema, TwapLimitGtcSchema, TwapMarketIocSchema } from "../../gen/triggers/v1/triggers_pb.js";
|
|
7
8
|
import { create } from "@bufbuild/protobuf";
|
|
8
9
|
import * as v from "valibot";
|
|
@@ -21,8 +22,22 @@ const BaseTriggerFieldsSchema = v.object({
|
|
|
21
22
|
selfTradePreventionMode: v.pipe(v.optional(SelfTradePreventionModeSchema, "expire_maker"), v.transform((value) => SelfTradePreventionModeCodec.inputToProto[value]))
|
|
22
23
|
});
|
|
23
24
|
const TriggerSideInputSchema = v.pipe(SideInputSchema, v.transform((value) => OrderSideCodec.inputToProto[value]));
|
|
24
|
-
const
|
|
25
|
-
|
|
25
|
+
const PriceSlippageInputSchema = v.strictObject({
|
|
26
|
+
kind: v.literal("slippage"),
|
|
27
|
+
slippage: DecimalInputStringSchema
|
|
28
|
+
});
|
|
29
|
+
const MaxSlippageInputSchema = v.union([
|
|
30
|
+
PriceSlippageInputSchema,
|
|
31
|
+
BpsStringOrNumberInputSchema,
|
|
32
|
+
NoneInputSchema
|
|
33
|
+
]);
|
|
34
|
+
/** Omit `maxSlippage` to use the pair's default market slippage for the child's side. */
|
|
35
|
+
const MarketIocConditionalExecutionInputSchema = v.strictObject({
|
|
36
|
+
type: v.literal("market_ioc"),
|
|
37
|
+
maxSlippage: v.optional(MaxSlippageInputSchema)
|
|
38
|
+
});
|
|
39
|
+
const ConditionalExecutionInputSchema = v.variant("type", [
|
|
40
|
+
MarketIocConditionalExecutionInputSchema,
|
|
26
41
|
v.strictObject({
|
|
27
42
|
type: v.literal("limit_gtc"),
|
|
28
43
|
price: DecimalInputStringSchema,
|
|
@@ -37,16 +52,6 @@ const LimitConditionalExecutionInputSchema = v.variant("type", [
|
|
|
37
52
|
price: DecimalInputStringSchema
|
|
38
53
|
})
|
|
39
54
|
]);
|
|
40
|
-
const ConditionalExecutionInputSchema = v.variant("type", [MarketIocConditionalExecutionInputSchema, ...LimitConditionalExecutionInputSchema.options]);
|
|
41
|
-
const PriceSlippageInputSchema = v.strictObject({
|
|
42
|
-
kind: v.literal("slippage"),
|
|
43
|
-
slippage: DecimalInputStringSchema
|
|
44
|
-
});
|
|
45
|
-
const MaxSlippageInputSchema = v.union([
|
|
46
|
-
PriceSlippageInputSchema,
|
|
47
|
-
BpsStringOrNumberInputSchema,
|
|
48
|
-
NoneInputSchema
|
|
49
|
-
]);
|
|
50
55
|
const TwapExecutionInputSchema = v.variant("type", [v.strictObject({
|
|
51
56
|
type: v.literal("market_ioc"),
|
|
52
57
|
maxSlippage: v.optional(MaxSlippageInputSchema)
|
|
@@ -54,12 +59,12 @@ const TwapExecutionInputSchema = v.variant("type", [v.strictObject({
|
|
|
54
59
|
type: v.literal("limit_gtc"),
|
|
55
60
|
price: DecimalInputStringSchema
|
|
56
61
|
})]);
|
|
57
|
-
function parseMaxSlippage(scales, slippage) {
|
|
62
|
+
function parseMaxSlippage(scales, slippage, maxBps = MAX_SLIPPAGE_BPS) {
|
|
58
63
|
return parseSlippageInput(scales, slippage, {
|
|
59
64
|
fieldName: "maxSlippage",
|
|
60
65
|
ticksCase: "maxSlippageTicks",
|
|
61
66
|
bpsCase: "maxSlippageBps",
|
|
62
|
-
maxBps
|
|
67
|
+
maxBps
|
|
63
68
|
});
|
|
64
69
|
}
|
|
65
70
|
function buildTriggerIntentBase(input, scales) {
|
|
@@ -74,11 +79,11 @@ function buildTriggerIntentBase(input, scales) {
|
|
|
74
79
|
}
|
|
75
80
|
};
|
|
76
81
|
}
|
|
77
|
-
function buildConditionalExecution(input, scales) {
|
|
82
|
+
function buildConditionalExecution(input, scales, side) {
|
|
78
83
|
switch (input.type) {
|
|
79
84
|
case "market_ioc": return { execution: {
|
|
80
85
|
case: "marketIoc",
|
|
81
|
-
value: create(TriggerMarketIocSchema)
|
|
86
|
+
value: create(TriggerMarketIocSchema, { maxSlippage: parseMaxSlippage(scales, input.maxSlippage, side === 2 ? MAX_SELLING_SLIPPAGE_BPS : MAX_SLIPPAGE_BPS) })
|
|
82
87
|
} };
|
|
83
88
|
case "limit_gtc": return { execution: {
|
|
84
89
|
case: "limitGtc",
|
|
@@ -107,6 +112,6 @@ function buildTwapExecution(input, scales) {
|
|
|
107
112
|
};
|
|
108
113
|
}
|
|
109
114
|
//#endregion
|
|
110
|
-
export { BaseTriggerFieldsSchema, ConditionalExecutionInputSchema, DecimalInputStringSchema,
|
|
115
|
+
export { BaseTriggerFieldsSchema, ConditionalExecutionInputSchema, DecimalInputStringSchema, MarketIocConditionalExecutionInputSchema, MaxSlippageInputSchema, TriggerSideInputSchema, TwapExecutionInputSchema, buildConditionalExecution, buildTriggerIntentBase, buildTwapExecution, parseMaxSlippage };
|
|
111
116
|
|
|
112
117
|
//# sourceMappingURL=trigger-child-order.schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger-child-order.schemas.js","names":["TRIGGER_SIDE_VALUES","TriggerSideCodec","Proto.TriggerMarketIocSchema","Proto.TriggerLimitGtcSchema","Proto.TriggerLimitIocSchema","Proto.TriggerLimitFokSchema","Proto.TwapMarketIocSchema","Proto.TwapLimitGtcSchema"],"sources":["../../../src/services/triggers/trigger-child-order.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as v from \"valibot\";\nimport { create } from \"@bufbuild/protobuf\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport { MAX_SLIPPAGE_BPS, parseSlippageInput } from \"../trailing-oneof-inputs.js\";\nimport {\n FEE_ASSET_VALUES,\n FeeAssetCodec,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n SelfTradePreventionModeCodec,\n TRIGGER_SIDE_VALUES,\n TriggerSideCodec,\n} from \"./triggers.codecs.js\";\n\nconst FeeAssetSchema = v.picklist(FEE_ASSET_VALUES);\nconst SelfTradePreventionModeSchema = v.picklist(SELF_TRADE_PREVENTION_MODE_VALUES);\nconst SideInputSchema = v.picklist(TRIGGER_SIDE_VALUES);\nexport const DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nexport type TrailingDistanceOneof = Proto.ModifyTriggerRequest[\"trailingDistance\"];\nexport type MaxSlippageOneof = Proto.ModifyTriggerRequest[\"maxSlippage\"];\n\n/** Shared public fields for creating a trigger intent. */\nexport const BaseTriggerFieldsSchema = v.object({\n ...AccountScopeInputEntries,\n symbolId: SymbolIdInputSchema,\n clientTriggerId: v.optional(v.pipe(v.string(), v.trim()), () => crypto.randomUUID()),\n qty: DecimalInputStringSchema,\n feeAsset: v.pipe(\n v.optional(FeeAssetSchema, \"quote\"),\n v.transform((value) => FeeAssetCodec.inputToProto[value]),\n ),\n selfTradePreventionMode: v.pipe(\n v.optional(SelfTradePreventionModeSchema, \"expire_maker\"),\n v.transform((value) => SelfTradePreventionModeCodec.inputToProto[value]),\n ),\n});\n\nexport const TriggerSideInputSchema = v.pipe(\n SideInputSchema,\n v.transform((value) => TriggerSideCodec.inputToProto[value]),\n);\n\nexport const MarketIocConditionalExecutionInputSchema = v.strictObject({\n type: v.literal(\"market_ioc\"),\n});\n\nexport const LimitConditionalExecutionInputSchema = v.variant(\"type\", [\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n postOnly: v.optional(v.boolean(), false),\n }),\n v.strictObject({\n type: v.literal(\"limit_ioc\"),\n price: DecimalInputStringSchema,\n }),\n v.strictObject({\n type: v.literal(\"limit_fok\"),\n price: DecimalInputStringSchema,\n }),\n]);\n\nexport const ConditionalExecutionInputSchema = v.variant(\"type\", [\n MarketIocConditionalExecutionInputSchema,\n ...LimitConditionalExecutionInputSchema.options,\n]);\n\nconst PriceSlippageInputSchema = v.strictObject({\n kind: v.literal(\"slippage\"),\n slippage: DecimalInputStringSchema,\n});\n\nexport const MaxSlippageInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\nexport const TwapExecutionInputSchema = v.variant(\"type\", [\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n }),\n]);\n\ntype BaseTriggerInput = v.InferOutput<typeof BaseTriggerFieldsSchema>;\ntype ConditionalExecutionInput = v.InferOutput<typeof ConditionalExecutionInputSchema>;\ntype TwapExecutionInput = v.InferOutput<typeof TwapExecutionInputSchema>;\n\nexport function parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema> | undefined,\n): MaxSlippageOneof {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps: MAX_SLIPPAGE_BPS,\n });\n}\n\nexport function buildTriggerIntentBase(input: BaseTriggerInput, scales: SdkScales) {\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n intent: {\n symbolId: input.symbolId,\n qtyScaled: positiveDecimalInputToScaled(\n \"qty\",\n input.qty,\n scales.baseQty(input.symbolId),\n ),\n feeAsset: input.feeAsset,\n selfTradePreventionMode: input.selfTradePreventionMode,\n clientTriggerId: input.clientTriggerId ?? crypto.randomUUID(),\n },\n };\n}\n\nexport function buildConditionalExecution(input: ConditionalExecutionInput, scales: SdkScales) {\n switch (input.type) {\n case \"market_ioc\":\n return {\n execution: {\n case: \"marketIoc\",\n value: create(Proto.TriggerMarketIocSchema),\n },\n } as const;\n case \"limit_gtc\":\n return {\n execution: {\n case: \"limitGtc\",\n value: create(Proto.TriggerLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n postOnly: input.postOnly,\n }),\n },\n } as const;\n case \"limit_ioc\":\n return {\n execution: {\n case: \"limitIoc\",\n value: create(Proto.TriggerLimitIocSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n },\n } as const;\n case \"limit_fok\":\n return {\n execution: {\n case: \"limitFok\",\n value: create(Proto.TriggerLimitFokSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n },\n } as const;\n }\n}\n\nexport function buildTwapExecution(input: TwapExecutionInput, scales: SdkScales) {\n return input.type === \"market_ioc\"\n ? ({\n case: \"marketIoc\",\n value: create(Proto.TwapMarketIocSchema, {\n maxSlippage: parseMaxSlippage(scales, input.maxSlippage),\n }),\n } as const)\n : ({\n case: \"limitGtc\",\n value: create(Proto.TwapLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n } as const);\n}\n"],"mappings":";;;;;;;;;AAmBA,MAAM,iBAAiB,EAAE,SAAS,gBAAgB;AAClD,MAAM,gCAAgC,EAAE,SAAS,iCAAiC;AAClF,MAAM,kBAAkB,EAAE,SAASA,iBAAmB;AACtD,MAAa,2BAA2B,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,CAAC,CAAC;;AAMnF,MAAa,0BAA0B,EAAE,OAAO;CAC5C,GAAG;CACH,UAAU;CACV,iBAAiB,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,SAAS,OAAO,WAAW,CAAC;CACnF,KAAK;CACL,UAAU,EAAE,KACR,EAAE,SAAS,gBAAgB,OAAO,GAClC,EAAE,WAAW,UAAU,cAAc,aAAa,MAAM,CAC5D;CACA,yBAAyB,EAAE,KACvB,EAAE,SAAS,+BAA+B,cAAc,GACxD,EAAE,WAAW,UAAU,6BAA6B,aAAa,MAAM,CAC3E;AACJ,CAAC;AAED,MAAa,yBAAyB,EAAE,KACpC,iBACA,EAAE,WAAW,UAAUC,eAAiB,aAAa,MAAM,CAC/D;AAEA,MAAa,2CAA2C,EAAE,aAAa,EACnE,MAAM,EAAE,QAAQ,YAAY,EAChC,CAAC;AAED,MAAa,uCAAuC,EAAE,QAAQ,QAAQ;CAClE,EAAE,aAAa;EACX,MAA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9C,EACJ;EACJ,KAAK,aACD,OAAO,EACH,WAAW;GACP,MAAM;GACN,OAAO,OAAOC,uBAA6B;IACvC,YAAY,6BACR,mBACA,MAAM,OACN,OAAO,MAAM,CACjB;IACA,UAAU,MAAM;GACpB,CAAC;EACL,EACJ;EACJ,KAAK,aACD,OAAO,EACH,WAAW;GACP,MAAM;GACN,OAAO,OAAOC,uBAA6B,EACvC,YAAY,6BACR,mBACA,MAAM,OACN,OAAO,MAAM,CACjB,EACJ,CAAC;EACL,EACJ;EACJ,KAAK,aACD,OAAO,EACH,WAAW;GACP,MAAM;GACN,OAAO,OAAOC,uBAA6B,EACvC,YAAY,6BACR,mBACA,MAAM,OACN,OAAO,MAAM,CACjB,EACJ,CAAC;EACL,EACJ;CACR;AACJ;AAEA,SAAgB,mBAAmB,OAA2B,QAAmB;CAC7E,OAAO,MAAM,SAAS,eACf;EACG,MAAM;EACN,OAAO,OAAOC,qBAA2B,EACrC,aAAa,iBAAiB,QAAQ,MAAM,WAAW,EAC3D,CAAC;CACL,IACC;EACG,MAAM;EACN,OAAO,OAAOC,oBAA0B,EACpC,YAAY,6BACR,mBACA,MAAM,OACN,OAAO,MAAM,CACjB,EACJ,CAAC;CACL;AACV"}
|
|
1
|
+
{"version":3,"file":"trigger-child-order.schemas.js","names":["TRIGGER_SIDE_VALUES","TriggerSideCodec","Proto.TriggerMarketIocSchema","Proto.TriggerLimitGtcSchema","Proto.TriggerLimitIocSchema","Proto.TriggerLimitFokSchema","Proto.TwapMarketIocSchema","Proto.TwapLimitGtcSchema"],"sources":["../../../src/services/triggers/trigger-child-order.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport { create } from \"@bufbuild/protobuf\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { positiveDecimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { BpsStringOrNumberInputSchema, NoneInputSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport {\n MAX_SELLING_SLIPPAGE_BPS,\n MAX_SLIPPAGE_BPS,\n parseSlippageInput,\n} from \"../trailing-oneof-inputs.js\";\nimport {\n FEE_ASSET_VALUES,\n FeeAssetCodec,\n SELF_TRADE_PREVENTION_MODE_VALUES,\n SelfTradePreventionModeCodec,\n TRIGGER_SIDE_VALUES,\n TriggerSideCodec,\n} from \"./triggers.codecs.js\";\n\nconst FeeAssetSchema = v.picklist(FEE_ASSET_VALUES);\nconst SelfTradePreventionModeSchema = v.picklist(SELF_TRADE_PREVENTION_MODE_VALUES);\nconst SideInputSchema = v.picklist(TRIGGER_SIDE_VALUES);\nexport const DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\n\nexport type TrailingDistanceOneof = Proto.ModifyTriggerRequest[\"trailingDistance\"];\nexport type MaxSlippageOneof = Proto.ModifyTriggerRequest[\"maxSlippage\"];\n\n/** Shared public fields for creating a trigger intent. */\nexport const BaseTriggerFieldsSchema = v.object({\n ...AccountScopeInputEntries,\n symbolId: SymbolIdInputSchema,\n clientTriggerId: v.optional(v.pipe(v.string(), v.trim()), () => crypto.randomUUID()),\n qty: DecimalInputStringSchema,\n feeAsset: v.pipe(\n v.optional(FeeAssetSchema, \"quote\"),\n v.transform((value) => FeeAssetCodec.inputToProto[value]),\n ),\n selfTradePreventionMode: v.pipe(\n v.optional(SelfTradePreventionModeSchema, \"expire_maker\"),\n v.transform((value) => SelfTradePreventionModeCodec.inputToProto[value]),\n ),\n});\n\nexport const TriggerSideInputSchema = v.pipe(\n SideInputSchema,\n v.transform((value) => TriggerSideCodec.inputToProto[value]),\n);\n\nconst PriceSlippageInputSchema = v.strictObject({\n kind: v.literal(\"slippage\"),\n slippage: DecimalInputStringSchema,\n});\n\nexport const MaxSlippageInputSchema = v.union([\n PriceSlippageInputSchema,\n BpsStringOrNumberInputSchema,\n NoneInputSchema,\n]);\n\n/** Omit `maxSlippage` to use the pair's default market slippage for the child's side. */\nexport const MarketIocConditionalExecutionInputSchema = v.strictObject({\n type: v.literal(\"market_ioc\"),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n});\n\nexport const ConditionalExecutionInputSchema = v.variant(\"type\", [\n MarketIocConditionalExecutionInputSchema,\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n postOnly: v.optional(v.boolean(), false),\n }),\n v.strictObject({\n type: v.literal(\"limit_ioc\"),\n price: DecimalInputStringSchema,\n }),\n v.strictObject({\n type: v.literal(\"limit_fok\"),\n price: DecimalInputStringSchema,\n }),\n]);\n\nexport const TwapExecutionInputSchema = v.variant(\"type\", [\n v.strictObject({\n type: v.literal(\"market_ioc\"),\n maxSlippage: v.optional(MaxSlippageInputSchema),\n }),\n v.strictObject({\n type: v.literal(\"limit_gtc\"),\n price: DecimalInputStringSchema,\n }),\n]);\n\ntype BaseTriggerInput = v.InferOutput<typeof BaseTriggerFieldsSchema>;\ntype ConditionalExecutionInput = v.InferOutput<typeof ConditionalExecutionInputSchema>;\ntype TwapExecutionInput = v.InferOutput<typeof TwapExecutionInputSchema>;\n\nexport function parseMaxSlippage(\n scales: SdkScales,\n slippage: v.InferOutput<typeof MaxSlippageInputSchema> | undefined,\n maxBps = MAX_SLIPPAGE_BPS,\n): MaxSlippageOneof {\n return parseSlippageInput(scales, slippage, {\n fieldName: \"maxSlippage\",\n ticksCase: \"maxSlippageTicks\",\n bpsCase: \"maxSlippageBps\",\n maxBps,\n });\n}\n\nexport function buildTriggerIntentBase(input: BaseTriggerInput, scales: SdkScales) {\n return {\n subaccountId: accountScopeToSubaccountId(input.account),\n intent: {\n symbolId: input.symbolId,\n qtyScaled: positiveDecimalInputToScaled(\n \"qty\",\n input.qty,\n scales.baseQty(input.symbolId),\n ),\n feeAsset: input.feeAsset,\n selfTradePreventionMode: input.selfTradePreventionMode,\n clientTriggerId: input.clientTriggerId ?? crypto.randomUUID(),\n },\n };\n}\n\nexport function buildConditionalExecution(\n input: ConditionalExecutionInput,\n scales: SdkScales,\n side: ProtoOrders.Side,\n) {\n switch (input.type) {\n case \"market_ioc\":\n return {\n execution: {\n case: \"marketIoc\",\n value: create(Proto.TriggerMarketIocSchema, {\n maxSlippage: parseMaxSlippage(\n scales,\n input.maxSlippage,\n side === ProtoOrders.Side.SELL\n ? MAX_SELLING_SLIPPAGE_BPS\n : MAX_SLIPPAGE_BPS,\n ),\n }),\n },\n } as const;\n case \"limit_gtc\":\n return {\n execution: {\n case: \"limitGtc\",\n value: create(Proto.TriggerLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n postOnly: input.postOnly,\n }),\n },\n } as const;\n case \"limit_ioc\":\n return {\n execution: {\n case: \"limitIoc\",\n value: create(Proto.TriggerLimitIocSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n },\n } as const;\n case \"limit_fok\":\n return {\n execution: {\n case: \"limitFok\",\n value: create(Proto.TriggerLimitFokSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n },\n } as const;\n }\n}\n\nexport function buildTwapExecution(input: TwapExecutionInput, scales: SdkScales) {\n return input.type === \"market_ioc\"\n ? ({\n case: \"marketIoc\",\n value: create(Proto.TwapMarketIocSchema, {\n maxSlippage: parseMaxSlippage(scales, input.maxSlippage),\n }),\n } as const)\n : ({\n case: \"limitGtc\",\n value: create(Proto.TwapLimitGtcSchema, {\n priceTicks: positiveDecimalInputToScaled(\n \"execution.price\",\n input.price,\n scales.price(),\n ),\n }),\n } as const);\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,iBAAiB,EAAE,SAAS,gBAAgB;AAClD,MAAM,gCAAgC,EAAE,SAAS,iCAAiC;AAClF,MAAM,kBAAkB,EAAE,SAASA,iBAAmB;AAC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