@polyester/sdk 0.36.0-devnet-20261119184734 → 0.36.0-devnet-20261120015159
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 +18 -2
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -1
- package/dist/gen/ai/v1/assistant_pb.d.ts +55 -3
- package/dist/gen/ai/v1/assistant_pb.d.ts.map +1 -1
- package/dist/gen/ai/v1/assistant_pb.js +8 -1
- package/dist/gen/ai/v1/assistant_pb.js.map +1 -1
- package/dist/gen/auth/v1/account_scope_pb.d.ts +40 -0
- package/dist/gen/auth/v1/account_scope_pb.d.ts.map +1 -0
- package/dist/gen/auth/v1/account_scope_pb.js +46 -0
- package/dist/gen/auth/v1/account_scope_pb.js.map +1 -0
- package/dist/gen/auth/v1/address_book_pb.d.ts +3 -31
- package/dist/gen/auth/v1/address_book_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/address_book_pb.js +8 -38
- package/dist/gen/auth/v1/address_book_pb.js.map +1 -1
- package/dist/gen/auth/v1/auth_pb.d.ts +15 -14
- package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/auth_pb.js +16 -15
- package/dist/gen/auth/v1/auth_pb.js.map +1 -1
- package/dist/gen/auth/v1/connected_apps_pb.d.ts +59 -58
- package/dist/gen/auth/v1/connected_apps_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/connected_apps_pb.js +38 -37
- package/dist/gen/auth/v1/connected_apps_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +27 -1
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +27 -1
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +228 -2
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js +32 -8
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
- package/dist/gen/changelog/v1/changelog_pb.d.ts +16 -4
- package/dist/gen/changelog/v1/changelog_pb.d.ts.map +1 -1
- package/dist/gen/changelog/v1/changelog_pb.js.map +1 -1
- package/dist/gen/index.d.ts +7 -5
- package/dist/gen/index.js +7 -5
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts +288 -2
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts.map +1 -1
- package/dist/gen/marketdata/v1/marketdata_pb.js +115 -2
- package/dist/gen/marketdata/v1/marketdata_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +78 -25
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +36 -7
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +35 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js.map +1 -1
- package/dist/gen/strategies/v1/strategies_pb.d.ts +2928 -0
- package/dist/gen/strategies/v1/strategies_pb.d.ts.map +1 -0
- package/dist/gen/strategies/v1/strategies_pb.js +818 -0
- package/dist/gen/strategies/v1/strategies_pb.js.map +1 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +38 -17
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +4 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_explorer_pb.d.ts +312 -132
- package/dist/gen/swap/quickswap/v1/quickswap_explorer_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_explorer_pb.js +31 -26
- package/dist/gen/swap/quickswap/v1/quickswap_explorer_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +28 -13
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js +2 -2
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts +109 -2
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js +23 -3
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js.map +1 -1
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts +3 -2
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts.map +1 -1
- package/dist/gen/transfer/v1/internal_transfer_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +61 -11
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +4 -2
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/services/account-activity/account-activity.schemas.d.ts +6 -6
- package/dist/services/address-book/address-book.codecs.js +1 -0
- package/dist/services/address-book/address-book.codecs.js.map +1 -1
- package/dist/services/address-book/address-book.js +1 -1
- package/dist/services/api-keys/api-keys.js +1 -1
- package/dist/services/assistant/assistant-events.schemas.d.ts +141 -43
- package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -1
- package/dist/services/assistant/assistant-events.schemas.js +15 -5
- package/dist/services/assistant/assistant-events.schemas.js.map +1 -1
- package/dist/services/assistant/assistant.codecs.d.ts +5 -2
- package/dist/services/assistant/assistant.codecs.d.ts.map +1 -1
- package/dist/services/assistant/assistant.codecs.js +10 -2
- package/dist/services/assistant/assistant.codecs.js.map +1 -1
- package/dist/services/assistant/assistant.schemas.d.ts +2 -2
- package/dist/services/auth/auth.js +1 -1
- package/dist/services/auth/auth.js.map +1 -1
- package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +16 -16
- package/dist/services/balances/balances.js +1 -1
- package/dist/services/balances/balances.schemas.d.ts +3 -3
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/changelog/changelog.schemas.d.ts +38 -38
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +1 -1
- package/dist/services/claims/claims.schemas.d.ts +2 -2
- package/dist/services/connected-apps/connected-apps.d.ts +4 -4
- package/dist/services/connected-apps/connected-apps.d.ts.map +1 -1
- package/dist/services/connected-apps/connected-apps.js +13 -13
- package/dist/services/connected-apps/connected-apps.js.map +1 -1
- package/dist/services/connected-apps/connected-apps.schemas.d.ts +7 -7
- package/dist/services/connected-apps/connected-apps.schemas.d.ts.map +1 -1
- package/dist/services/connected-apps/connected-apps.schemas.js +10 -10
- package/dist/services/connected-apps/connected-apps.schemas.js.map +1 -1
- package/dist/services/connected-apps/connected-apps.types.d.ts +2 -2
- package/dist/services/dust-conversion/dust-conversion.schemas.d.ts +8 -8
- package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
- package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +6 -6
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +94 -94
- package/dist/services/market-data/market-data.codecs.d.ts +9 -1
- package/dist/services/market-data/market-data.codecs.d.ts.map +1 -1
- package/dist/services/market-data/market-data.codecs.js +14 -1
- package/dist/services/market-data/market-data.codecs.js.map +1 -1
- package/dist/services/market-data/market-data.d.ts +9 -1
- package/dist/services/market-data/market-data.d.ts.map +1 -1
- package/dist/services/market-data/market-data.js +14 -1
- package/dist/services/market-data/market-data.js.map +1 -1
- package/dist/services/market-data/market-data.schemas.d.ts +40 -2
- package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
- package/dist/services/market-data/market-data.schemas.js +43 -8
- package/dist/services/market-data/market-data.schemas.js.map +1 -1
- package/dist/services/market-data/market-data.types.d.ts +3 -3
- package/dist/services/notifications/notifications.schemas.d.ts +4 -4
- package/dist/services/orderbook/orderbook.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.js +5 -19
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +6 -6
- package/dist/services/orders/orders-batch.schemas.d.ts +72 -72
- package/dist/services/orders/orders-input.schemas.d.ts +10 -10
- package/dist/services/orders/orders-output.schemas.d.ts +16 -16
- package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-output.schemas.js +1 -1
- package/dist/services/orders/orders-output.schemas.js.map +1 -1
- package/dist/services/orders/orders.d.ts +5 -0
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +5 -0
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.js +1 -1
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
- package/dist/services/policies/shared.codecs.js +13 -4
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.js +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +3 -3
- package/dist/services/rewards/rewards.schemas.d.ts +4 -4
- package/dist/services/statement-exports/statement-exports.schemas.d.ts +6 -6
- package/dist/services/strategies/service.d.ts +8 -0
- package/dist/services/strategies/service.d.ts.map +1 -0
- package/dist/services/strategies/service.js +9 -0
- package/dist/services/strategies/service.js.map +1 -0
- package/dist/services/strategies/strategies.codecs.d.ts +15 -0
- package/dist/services/strategies/strategies.codecs.d.ts.map +1 -0
- package/dist/services/strategies/strategies.codecs.js +50 -0
- package/dist/services/strategies/strategies.codecs.js.map +1 -0
- package/dist/services/strategies/strategies.d.ts +75 -0
- package/dist/services/strategies/strategies.d.ts.map +1 -0
- package/dist/services/strategies/strategies.js +135 -0
- package/dist/services/strategies/strategies.js.map +1 -0
- package/dist/services/strategies/strategies.schemas.d.ts +568 -0
- package/dist/services/strategies/strategies.schemas.d.ts.map +1 -0
- package/dist/services/strategies/strategies.schemas.js +408 -0
- package/dist/services/strategies/strategies.schemas.js.map +1 -0
- package/dist/services/strategies/strategies.types.d.ts +3 -0
- package/dist/services/subaccounts/subaccounts.js +2 -2
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +8 -8
- package/dist/services/system/system.schemas.d.ts +13 -13
- package/dist/services/trades/trades.schemas.d.ts +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.d.ts +29 -2
- package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.js +74 -11
- package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +85 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js +56 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.types.d.ts +3 -3
- package/dist/services/trading-withdraws/wallet-message.js +29 -1
- package/dist/services/trading-withdraws/wallet-message.js.map +1 -1
- package/dist/services/transfers/transfers.js +1 -1
- package/dist/services/transfers/transfers.schemas.d.ts +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/triggers-output.schemas.d.ts +44 -44
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +5 -0
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/error-detail.d.ts +25 -2
- package/dist/shared/error-detail.d.ts.map +1 -1
- package/dist/shared/error-detail.js +1 -0
- package/dist/shared/error-detail.js.map +1 -1
- package/dist/shared/error-details/strategies.js +36 -0
- package/dist/shared/error-details/strategies.js.map +1 -0
- package/dist/wired-services.d.ts.map +1 -1
- package/dist/wired-services.js +6 -4
- package/dist/wired-services.js.map +1 -1
- package/package.json +1 -1
|
@@ -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 {\n E18_SCALE,\n quantityInputToE18,\n scaledToDecimalOutput,\n type SdkScales,\n} 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 { fromU128, toU128, type U128Value } from \"../../utils/u128.js\";\nimport { U128Schema } from \"../../shared/schemas.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport { enumLabelSchema } from \"../../shared/proto-enum-codec.js\";\nimport {\n TradingWithdrawActionCodec,\n WalletAssetUnavailableReasonCodec,\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};\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 /**\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 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 /** Polyester chain ID of the network: a Zipper chain's `chainId`, not its `nativeChainId`. */\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 /**\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 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 /** Polyester chain ID of the network: a Zipper chain's `chainId`, not its `nativeChainId`. */\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\nconst WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });\n\nexport const GetWalletBalancesInputSchema = v.pipe(\n WalletBalancesInputObjectSchema,\n v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })),\n);\n\nexport type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;\n\nexport const GetWalletBalancesResultSchema = v.object({\n smartAccountAddress: v.string(),\n balances: v.array(\n v.pipe(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n amountE18: v.optional(U128Schema),\n }),\n v.transform(({ amountE18, ...balance }) => ({\n ...balance,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n })),\n ),\n ),\n /**\n * zTokens whose balance could not be read: unknown, not zero. Read again later; the read is\n * complete only when this is empty.\n */\n unavailableAssets: v.array(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n reason: v.optional(enumLabelSchema(WalletAssetUnavailableReasonCodec.protoToOutput), 0),\n }),\n ),\n});\n\n/**\n * zTokens the account's smart account wallet holds on Polyester Chain, read live from the\n * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`\n * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`\n * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.\n * An asset whose balance could not be read is in `unavailableAssets` instead, never in `balances`\n * as zero.\n */\nexport type GetWalletBalancesResult = v.InferOutput<typeof Get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AAa,EAAE,GAAG,yBAAyB,CAAC;AAEtF,MAAa,+BAA+B,EAAE,KAC1C,iCACA,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,2BAA2B,OAAO,EAAE,EAAE,CACxF;AAIA,MAAa,gCAAgC,EAAE,OAAO;CAClD,qBAAqB,EAAE,OAAO;CAC9B,UAAU,EAAE,MACR,EAAE,KACE,EAAE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,WAAW,EAAE,SAAS,UAAU;CACpC,CAAC,GACD,EAAE,WAAW,EAAE,WAAW,GAAG,eAAe;EACxC,GAAG;EACH,QAAQ,sBAAsB,SAAS,SAAS,GAAA,EAAY;CAChE,EAAE,CACN,CACJ;;;;;CAKA,mBAAmB,EAAE,MACjB,EAAE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,QAAQ,EAAE,SAAS,gBAAgB,kCAAkC,aAAa,GAAG,CAAC;CAC1F,CAAC,CACL;AACJ,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 {\n E18_SCALE,\n quantityInputToE18,\n scaledToDecimalOutput,\n type SdkScales,\n} 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 { fromU128, toU128, type U128Value } from \"../../utils/u128.js\";\nimport { U128Schema } from \"../../shared/schemas.js\";\nimport { ConfigurationError } from \"../../shared/errors.js\";\nimport { enumLabelSchema } from \"../../shared/proto-enum-codec.js\";\nimport {\n TradingWithdrawActionCodec,\n WalletAssetUnavailableReasonCodec,\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};\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 /**\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 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 /** Polyester chain ID of the network: a Zipper chain's `chainId`, not its `nativeChainId`. */\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 /**\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 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 function createCreateTradingToFundingBatchInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n /** Moves to make, in order: 1 to 10. Legs may repeat an asset or a destination. */\n legs: v.pipe(\n v.array(\n v.strictObject({\n assetId: PositiveUint32InputSchema,\n quantity: v.string(),\n /**\n * A Polyester Funding address, signed in the letter case given. Omit it\n * to credit the source account's own Funding account; another account's\n * address must be on the internal whitelist.\n */\n destinationAddress: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n }),\n ),\n v.minLength(1),\n v.maxLength(10),\n ),\n /** Scoped to the source account; 1 to 128 characters. */\n idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(128)),\n /**\n * When the signed batch lapses, at most 15 minutes ahead. Defaults to five minutes\n * from now on the device clock.\n */\n deadline: v.optional(v.date()),\n }),\n v.transform((input) => ({\n subaccountId: accountScopeToSubaccountId(input.account),\n legs: input.legs.map((leg) => ({\n assetId: leg.assetId,\n amountE18: quantityInputToE18({\n scales,\n assetId: leg.assetId,\n quantity: leg.quantity,\n }),\n destinationAddress: leg.destinationAddress,\n })),\n idempotencyKey: input.idempotencyKey,\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: createNonce(),\n })),\n );\n}\n\nexport type CreateTradingToFundingBatchInput = v.InferInput<\n ReturnType<typeof createCreateTradingToFundingBatchInputSchema>\n>;\n\nexport const CreateTradingToFundingBatchResultSchema = v.object({\n batchId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n /** Every leg, in request order; follow each `intentId` like a single withdraw's. */\n legs: v.array(\n v.pipe(\n v.object({\n legIndex: v.number(),\n intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),\n assetId: v.number(),\n amountE18: v.optional(U128Schema),\n destinationAddress: v.string(),\n }),\n v.transform(({ amountE18, ...leg }) => ({\n legIndex: leg.legIndex,\n intentId: leg.intentId,\n assetId: leg.assetId,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n /** Empty when the leg credits the source account's own Funding account. */\n destinationAddress: leg.destinationAddress,\n })),\n ),\n ),\n});\n\nexport type CreateTradingToFundingBatchResult = v.InferOutput<\n typeof CreateTradingToFundingBatchResultSchema\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 /** Polyester chain ID of the network: a Zipper chain's `chainId`, not its `nativeChainId`. */\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\nconst WalletBalancesInputObjectSchema = v.strictObject({ ...AccountScopeInputEntries });\n\nexport const GetWalletBalancesInputSchema = v.pipe(\n WalletBalancesInputObjectSchema,\n v.transform(({ account }) => ({ subaccountId: accountScopeToSubaccountId(account) })),\n);\n\nexport type GetWalletBalancesInput = v.InferInput<typeof WalletBalancesInputObjectSchema>;\n\nexport const GetWalletBalancesResultSchema = v.object({\n smartAccountAddress: v.string(),\n balances: v.array(\n v.pipe(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n amountE18: v.optional(U128Schema),\n }),\n v.transform(({ amountE18, ...balance }) => ({\n ...balance,\n amount: scaledToDecimalOutput(fromU128(amountE18), E18_SCALE),\n })),\n ),\n ),\n /**\n * zTokens whose balance could not be read: unknown, not zero. Read again later; the read is\n * complete only when this is empty.\n */\n unavailableAssets: v.array(\n v.object({\n zippedAssetId: v.number(),\n unifiedAssetId: v.number(),\n chainId: v.number(),\n ztokenAddress: v.string(),\n reason: v.optional(enumLabelSchema(WalletAssetUnavailableReasonCodec.protoToOutput), 0),\n }),\n ),\n});\n\n/**\n * zTokens the account's smart account wallet holds on Polyester Chain, read live from the\n * chain: for example a rejected withdrawal's refund, which stays there until moved. `amount`\n * is a decimal string (zTokens have 18 decimals); `chainId` is a `GetDepositWithdrawConfig`\n * chain. `balances` lists nonzero balances by `zippedAssetId` and is empty when there are none.\n * An asset whose balance could not be read is in `unavailableAssets` instead, never in `balances`\n * as zero.\n */\nexport type GetWalletBalancesResult = v.InferOutput<typeof GetWalletBalancesResultSchema>;\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,2BAA2B;AAkBjC,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/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AE,eAAe,EAAE,cAAc,2BAA2B,OAAO,EAAE,EAAE,CACxF;AAIA,MAAa,gCAAgC,EAAE,OAAO;CAClD,qBAAqB,EAAE,OAAO;CAC9B,UAAU,EAAE,MACR,EAAE,KACE,EAAE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,WAAW,EAAE,SAAS,UAAU;CACpC,CAAC,GACD,EAAE,WAAW,EAAE,WAAW,GAAG,eAAe;EACxC,GAAG;EACH,QAAQ,sBAAsB,SAAS,SAAS,GAAA,EAAY;CAChE,EAAE,CACN,CACJ;;;;;CAKA,mBAAmB,EAAE,MACjB,EAAE,OAAO;EACL,eAAe,EAAE,OAAO;EACxB,gBAAgB,EAAE,OAAO;EACzB,SAAS,EAAE,OAAO;EAClB,eAAe,EAAE,OAAO;EACxB,QAAQ,EAAE,SAAS,gBAAgB,kCAAkC,aAAa,GAAG,CAAC;CAC1F,CAAC,CACL;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
|
|
2
|
-
import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner } from "./trading-withdraws.js";
|
|
1
|
+
import { CreateTradingToFundingBatchInput, CreateTradingToFundingBatchResult, CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
|
|
2
|
+
import { CreateTradingToFundingBatchServiceInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingToFundingBatch, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner } from "./trading-withdraws.js";
|
|
3
3
|
import { WalletAssetUnavailableReasonValue } from "./trading-withdraws.codecs.js";
|
|
4
|
-
export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, GetWalletBalancesInput, GetWalletBalancesResult, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult, WalletAssetUnavailableReasonValue };
|
|
4
|
+
export type { CreateTradingToFundingBatchInput, CreateTradingToFundingBatchResult, CreateTradingToFundingBatchServiceInput, CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, GetWalletBalancesInput, GetWalletBalancesResult, PreparedTradingToFundingBatch, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult, WalletAssetUnavailableReasonValue };
|
|
@@ -37,7 +37,35 @@ function buildTradingWithdrawWalletMessage(params) {
|
|
|
37
37
|
`Idempotency Key: ${messageText(payload.idempotencyKey, "idempotency key")}`
|
|
38
38
|
].join("\n");
|
|
39
39
|
}
|
|
40
|
+
/** The text a wallet signs (EIP-191) for `CreateWalletTradingToFundingBatch`. */
|
|
41
|
+
function buildTradingToFundingBatchWalletMessage(params) {
|
|
42
|
+
const { signingConfig, legs } = params;
|
|
43
|
+
if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) throw new ValidationError("Trading withdraw chain ID must be a positive safe integer.");
|
|
44
|
+
return [
|
|
45
|
+
"Polyester Trading Withdrawal Batch",
|
|
46
|
+
"",
|
|
47
|
+
"Version: 1",
|
|
48
|
+
"Environment: polyester",
|
|
49
|
+
"Action: TO_FUNDING",
|
|
50
|
+
`Signer Wallet: ${messageAddress(params.signerWallet, "signer wallet")}`,
|
|
51
|
+
`Account ID: ${params.accountId}`,
|
|
52
|
+
`Target Account ID: ${params.targetAccountId}`,
|
|
53
|
+
`Polyester Chain ID: ${signingConfig.chainId}`,
|
|
54
|
+
`Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, "verifying contract")}`,
|
|
55
|
+
`Deadline: ${params.deadlineTsSec}`,
|
|
56
|
+
`Nonce: ${params.nonce}`,
|
|
57
|
+
`Idempotency Key: ${messageText(params.idempotencyKey, "idempotency key")}`,
|
|
58
|
+
`Legs: ${legs.length}`,
|
|
59
|
+
...legs.flatMap((leg, i) => [
|
|
60
|
+
"",
|
|
61
|
+
`Leg ${i + 1} of ${legs.length}`,
|
|
62
|
+
`Asset ID: ${leg.assetId}`,
|
|
63
|
+
`Amount E18: ${leg.amountE18}`,
|
|
64
|
+
`Destination: ${messageText(leg.destinationAddress, "destination")}`
|
|
65
|
+
])
|
|
66
|
+
].join("\n");
|
|
67
|
+
}
|
|
40
68
|
//#endregion
|
|
41
|
-
export { buildTradingWithdrawWalletMessage };
|
|
69
|
+
export { buildTradingToFundingBatchWalletMessage, buildTradingWithdrawWalletMessage };
|
|
42
70
|
|
|
43
71
|
//# sourceMappingURL=wallet-message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-message.js","names":[],"sources":["../../../src/services/trading-withdraws/wallet-message.ts"],"sourcesContent":["import { TradingWithdrawAction } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { ValidationError } from \"../../shared/errors.js\";\nimport { isEvmAddress } from \"../../utils/evm.js\";\nimport type { TradingWithdrawIntentPayloadRequest } from \"./trading-withdraws.schemas.js\";\nimport type { TradingWithdrawSigningConfig } from \"./trading-withdraws.js\";\n\nfunction messageAddress(value: string, field: string): string {\n const address = value.trim();\n if (!isEvmAddress(address)) {\n throw new ValidationError(`Trading withdraw ${field} must be a valid EVM address.`);\n }\n return address.toLowerCase();\n}\n\nfunction messageText(value: string, field: string): string {\n const text = value.trim();\n // Separators and format characters (RTL override, zero-width) can make the wallet\n // prompt read differently from the signed bytes.\n if (/[\\p{Cc}\\p{Cs}\\p{Cf}\\p{Zl}\\p{Zp}]/u.test(text)) {\n throw new ValidationError(\n `Trading withdraw ${field} must be valid UTF-8 without control characters.`,\n );\n }\n return text;\n}\n\nexport function buildTradingWithdrawWalletMessage(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: string;\n accountId: bigint;\n targetAccountId: bigint;\n}): string {\n const { payload, signingConfig } = params;\n if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) {\n throw new ValidationError(\"Trading withdraw chain ID must be a positive safe integer.\");\n }\n const action =\n payload.action === TradingWithdrawAction.TO_FUNDING\n ? \"TO_FUNDING\"\n : payload.action === TradingWithdrawAction.TO_EXTERNAL_CHAIN\n ? \"TO_EXTERNAL_CHAIN\"\n : undefined;\n if (!action) throw new ValidationError(\"Invalid trading withdraw action.\");\n\n return [\n \"Polyester Trading Withdrawal\",\n \"\",\n \"Version: 1\",\n \"Environment: polyester\",\n `Action: ${action}`,\n `Signer Wallet: ${messageAddress(params.signerWallet, \"signer wallet\")}`,\n `Account ID: ${params.accountId}`,\n `Target Account ID: ${params.targetAccountId}`,\n `Asset ID: ${payload.assetId}`,\n `Polyester Chain ID: ${signingConfig.chainId}`,\n `Destination Chain ID: ${payload.destinationChainId}`,\n `Amount E18: ${(payload.amountE18.hi << 64n) + payload.amountE18.lo}`,\n `Destination: ${messageText(payload.destinationAddress, \"destination\")}`,\n `Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, \"verifying contract\")}`,\n `Deadline: ${payload.deadlineTsSec}`,\n `Nonce: ${(payload.nonce.hi << 64n) + payload.nonce.lo}`,\n `Idempotency Key: ${messageText(payload.idempotencyKey, \"idempotency key\")}`,\n ].join(\"\\n\");\n}\n"],"mappings":";;;;AAMA,SAAS,eAAe,OAAe,OAAuB;CAC1D,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,CAAC,aAAa,OAAO,GACrB,MAAM,IAAI,gBAAgB,oBAAoB,MAAM,8BAA8B;CAEtF,OAAO,QAAQ,YAAY;AAC/B;AAEA,SAAS,YAAY,OAAe,OAAuB;CACvD,MAAM,OAAO,MAAM,KAAK;CAGxB,IAAI,oCAAoC,KAAK,IAAI,GAC7C,MAAM,IAAI,gBACN,oBAAoB,MAAM,iDAC9B;CAEJ,OAAO;AACX;AAEA,SAAgB,kCAAkC,QAMvC;CACP,MAAM,EAAE,SAAS,kBAAkB;CACnC,IAAI,CAAC,OAAO,cAAc,cAAc,OAAO,KAAK,cAAc,WAAW,GACzE,MAAM,IAAI,gBAAgB,4DAA4D;CAE1F,MAAM,SACF,QAAQ,WAAA,IACF,eACA,QAAQ,WAAA,IACN,sBACA,KAAA;CACZ,IAAI,CAAC,QAAQ,MAAM,IAAI,gBAAgB,kCAAkC;CAEzE,OAAO;EACH;EACA;EACA;EACA;EACA,WAAW;EACX,kBAAkB,eAAe,OAAO,cAAc,eAAe;EACrE,eAAe,OAAO;EACtB,sBAAsB,OAAO;EAC7B,aAAa,QAAQ;EACrB,uBAAuB,cAAc;EACrC,yBAAyB,QAAQ;EACjC,gBAAgB,QAAQ,UAAU,MAAM,OAAO,QAAQ,UAAU;EACjE,gBAAgB,YAAY,QAAQ,oBAAoB,aAAa;EACrE,uBAAuB,eAAe,cAAc,uBAAuB,oBAAoB;EAC/F,aAAa,QAAQ;EACrB,WAAW,QAAQ,MAAM,MAAM,OAAO,QAAQ,MAAM;EACpD,oBAAoB,YAAY,QAAQ,gBAAgB,iBAAiB;CAC7E,CAAC,CAAC,KAAK,IAAI;AACf"}
|
|
1
|
+
{"version":3,"file":"wallet-message.js","names":[],"sources":["../../../src/services/trading-withdraws/wallet-message.ts"],"sourcesContent":["import { TradingWithdrawAction } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { ValidationError } from \"../../shared/errors.js\";\nimport { isEvmAddress } from \"../../utils/evm.js\";\nimport type { TradingWithdrawIntentPayloadRequest } from \"./trading-withdraws.schemas.js\";\nimport type { TradingWithdrawSigningConfig } from \"./trading-withdraws.js\";\n\nfunction messageAddress(value: string, field: string): string {\n const address = value.trim();\n if (!isEvmAddress(address)) {\n throw new ValidationError(`Trading withdraw ${field} must be a valid EVM address.`);\n }\n return address.toLowerCase();\n}\n\nfunction messageText(value: string, field: string): string {\n const text = value.trim();\n // Separators and format characters (RTL override, zero-width) can make the wallet\n // prompt read differently from the signed bytes.\n if (/[\\p{Cc}\\p{Cs}\\p{Cf}\\p{Zl}\\p{Zp}]/u.test(text)) {\n throw new ValidationError(\n `Trading withdraw ${field} must be valid UTF-8 without control characters.`,\n );\n }\n return text;\n}\n\nexport function buildTradingWithdrawWalletMessage(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: string;\n accountId: bigint;\n targetAccountId: bigint;\n}): string {\n const { payload, signingConfig } = params;\n if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) {\n throw new ValidationError(\"Trading withdraw chain ID must be a positive safe integer.\");\n }\n const action =\n payload.action === TradingWithdrawAction.TO_FUNDING\n ? \"TO_FUNDING\"\n : payload.action === TradingWithdrawAction.TO_EXTERNAL_CHAIN\n ? \"TO_EXTERNAL_CHAIN\"\n : undefined;\n if (!action) throw new ValidationError(\"Invalid trading withdraw action.\");\n\n return [\n \"Polyester Trading Withdrawal\",\n \"\",\n \"Version: 1\",\n \"Environment: polyester\",\n `Action: ${action}`,\n `Signer Wallet: ${messageAddress(params.signerWallet, \"signer wallet\")}`,\n `Account ID: ${params.accountId}`,\n `Target Account ID: ${params.targetAccountId}`,\n `Asset ID: ${payload.assetId}`,\n `Polyester Chain ID: ${signingConfig.chainId}`,\n `Destination Chain ID: ${payload.destinationChainId}`,\n `Amount E18: ${(payload.amountE18.hi << 64n) + payload.amountE18.lo}`,\n `Destination: ${messageText(payload.destinationAddress, \"destination\")}`,\n `Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, \"verifying contract\")}`,\n `Deadline: ${payload.deadlineTsSec}`,\n `Nonce: ${(payload.nonce.hi << 64n) + payload.nonce.lo}`,\n `Idempotency Key: ${messageText(payload.idempotencyKey, \"idempotency key\")}`,\n ].join(\"\\n\");\n}\n\nexport type TradingToFundingBatchMessageLeg = {\n assetId: number;\n amountE18: bigint;\n destinationAddress: string;\n};\n\n/** The text a wallet signs (EIP-191) for `CreateWalletTradingToFundingBatch`. */\nexport function buildTradingToFundingBatchWalletMessage(params: {\n signingConfig: TradingWithdrawSigningConfig;\n signerWallet: string;\n accountId: bigint;\n targetAccountId: bigint;\n deadlineTsSec: bigint;\n nonce: bigint;\n idempotencyKey: string;\n legs: readonly TradingToFundingBatchMessageLeg[];\n}): string {\n const { signingConfig, legs } = params;\n if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) {\n throw new ValidationError(\"Trading withdraw chain ID must be a positive safe integer.\");\n }\n return [\n \"Polyester Trading Withdrawal Batch\",\n \"\",\n \"Version: 1\",\n \"Environment: polyester\",\n \"Action: TO_FUNDING\",\n `Signer Wallet: ${messageAddress(params.signerWallet, \"signer wallet\")}`,\n `Account ID: ${params.accountId}`,\n `Target Account ID: ${params.targetAccountId}`,\n `Polyester Chain ID: ${signingConfig.chainId}`,\n `Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, \"verifying contract\")}`,\n `Deadline: ${params.deadlineTsSec}`,\n `Nonce: ${params.nonce}`,\n `Idempotency Key: ${messageText(params.idempotencyKey, \"idempotency key\")}`,\n `Legs: ${legs.length}`,\n ...legs.flatMap((leg, i) => [\n \"\",\n `Leg ${i + 1} of ${legs.length}`,\n `Asset ID: ${leg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CACP,MAAM,EAAE,eAAe,SAAS;CAChC,IAAI,CAAC,OAAO,cAAc,cAAc,OAAO,KAAK,cAAc,WAAW,GACzE,MAAM,IAAI,gBAAgB,4DAA4D;CAE1F,OAAO;EACH;EACA;EACA;EACA;EACA;EACA,kBAAkB,eAAe,OAAO,cAAc,eAAe;EACrE,eAAe,OAAO;EACtB,sBAAsB,OAAO;EAC7B,uBAAuB,cAAc;EACrC,uBAAuB,eAAe,cAAc,uBAAuB,oBAAoB;EAC/F,aAAa,OAAO;EACpB,UAAU,OAAO;EACjB,oBAAoB,YAAY,OAAO,gBAAgB,iBAAiB;EACxE,SAAS,KAAK;EACd,GAAG,KAAK,SAAS,KAAK,MAAM;GACxB;GACA,OAAO,IAAI,EAAE,MAAM,KAAK;GACxB,aAAa,IAAI;GACjB,eAAe,IAAI;GACnB,gBAAgB,YAAY,IAAI,oBAAoB,aAAa;EACrE,CAAC;CACL,CAAC,CAAC,KAAK,IAAI;AACf"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LedgerReadService, TransferRowBatchSchema } from "../../gen/ledger/read/v1/ledger_read_pb.js";
|
|
2
1
|
import { parse } from "../../shared/validation.js";
|
|
3
2
|
import { toConnectCallOptions } from "../../shared/request-options.js";
|
|
4
3
|
import { deliverBatch } from "../../shared/subscription-errors.js";
|
|
4
|
+
import { LedgerReadService, TransferRowBatchSchema } from "../../gen/ledger/read/v1/ledger_read_pb.js";
|
|
5
5
|
import { resolveAccountScopedInput } from "../subaccount-resolver.js";
|
|
6
6
|
import { LedgerTransferSchema, ListTransfersInputSchema } from "./transfers.schemas.js";
|
|
7
7
|
import { createClient } from "@connectrpc/connect";
|
|
@@ -85,7 +85,7 @@ declare const LedgerTransferSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
85
85
|
amount: string;
|
|
86
86
|
balanceAfter: string | undefined;
|
|
87
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" | "trading_withdraw_fee_leg" | "quickswap_polyester_fee" | "quickswap_broker_fee" | "quickswap_affiliate_fee" | "fee_sweep" | "fee_refill" | "system_adjustment" | "withdraw_failed" | "internal_batch";
|
|
88
|
-
accountCode: "unspecified" | "
|
|
88
|
+
accountCode: "unspecified" | "funding" | "trading";
|
|
89
89
|
timestamp: number;
|
|
90
90
|
isDebit: boolean;
|
|
91
91
|
linkId: string | undefined;
|
|
@@ -1118,7 +1118,7 @@ declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObject
|
|
|
1118
1118
|
/** Both legs of the OCO created with this client list ID. */
|
|
1119
1119
|
readonly clientListId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientListId has an invalid format">]>, undefined>;
|
|
1120
1120
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
1121
|
-
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("
|
|
1121
|
+
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "canceled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("created" | "failed" | "canceled" | "running" | "paused" | "armed" | "completed")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
|
|
1122
1122
|
readonly triggerType: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["stop_loss", "take_profit", "trailing_stop", "twap", "ladder"], undefined>, undefined>, v.TransformAction<"twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop" | undefined, TriggerType>]>;
|
|
1123
1123
|
readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>, 50>;
|
|
1124
1124
|
readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
@@ -1565,7 +1565,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
|
|
|
1565
1565
|
readonly triggerId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
1566
1566
|
}, undefined>, v.TransformAction<{
|
|
1567
1567
|
limit?: number | undefined;
|
|
1568
|
-
eventType?: "
|
|
1568
|
+
eventType?: "updated" | "failed" | "canceled" | "armed" | "fired" | "activated" | "fire_refused" | undefined;
|
|
1569
1569
|
pageToken: string;
|
|
1570
1570
|
account?: "active" | "main" | {
|
|
1571
1571
|
subaccountId: string;
|