@polyester/sdk 0.36.0-devnet-20261119195411 → 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 +16 -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/address-book/address-book.schemas.d.ts +2 -2
- package/dist/services/api-keys/api-keys.js +1 -1
- package/dist/services/api-keys/api-keys.schemas.d.ts +6 -6
- package/dist/services/assistant/assistant-events.schemas.d.ts +138 -40
- 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 +9 -9
- package/dist/services/balances/balances.js +1 -1
- package/dist/services/balances/balances.schemas.d.ts +3 -3
- 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 +6 -6
- package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
- package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +79 -79
- 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/orders/order-errors.schemas.d.ts +6 -6
- package/dist/services/orders/orders-batch.schemas.d.ts +67 -67
- 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 +20 -20
- 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 +39 -39
- 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
|
@@ -9,11 +9,11 @@ declare const SubaccountPermissionDefinitionSchema: v.ObjectSchema<{
|
|
|
9
9
|
readonly permission: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "internal_transfer" | "swap" | "convert_dust" | "read_subaccount" | "update_subaccount" | "read_balances" | "read_spot" | "trade_spot" | "read_internal_transfers" | "external_withdraw" | "read_address_book" | "manage_address_book" | "read_members" | "manage_members" | "read_invites" | "manage_invites" | "read_api_keys" | "manage_api_keys" | "read_subaccount_policy" | "manage_subaccount_policy" | "read_activity" | "read_activity_security_details" | "manage_member_mfa_requirement" | "create_deposit_address" | "read_deposit_addresses" | "read_guard_signer_status" | "manage_guard_signer" | "read_auto_withdraw" | "manage_auto_withdraw" | "read_statements" | "read_funding_flows">]>;
|
|
10
10
|
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
11
11
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
12
|
-
readonly policyAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "swap" | "trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book" | "read-auto-withdraw" | "manage-auto-withdraw" | "read-statements" | "convert-dust" | "read-funding-flows" | "read-api-keys" | "read-api-policies" | "read-subaccount-policies" | "read-subaccount-permissions" | "read-vip-status" | "read-social-verification" | "read-profile" | "read-account-directory" | "read-withdraw-validation" | "read-daily-claims" | "claim-daily-reward" | "read-checkpoints" | "read-rewards" | "create-deposit-address" | "read-deposit-addresses" | "read-subaccounts" | "read-subaccount-activity" | "read-subaccount-members" | "read-subaccount-invites" | "read-guard-signer-status" | "read-price-alerts" | "manage-price-alerts" | "read-notifications" | "read-account-activity" | "manage-api-keys" | "manage-api-key-policies" | "manage-subaccount-policies">]>;
|
|
12
|
+
readonly policyAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "swap" | "trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book" | "read-auto-withdraw" | "manage-auto-withdraw" | "read-statements" | "convert-dust" | "read-funding-flows" | "read-api-keys" | "read-api-policies" | "read-subaccount-policies" | "read-subaccount-permissions" | "read-vip-status" | "read-social-verification" | "read-profile" | "read-account-directory" | "read-withdraw-validation" | "read-daily-claims" | "claim-daily-reward" | "read-checkpoints" | "read-rewards" | "create-deposit-address" | "read-deposit-addresses" | "read-subaccounts" | "read-subaccount-activity" | "read-subaccount-members" | "read-subaccount-invites" | "read-guard-signer-status" | "read-price-alerts" | "manage-price-alerts" | "read-notifications" | "read-account-activity" | "read-strategies" | "draft-strategies" | "propose-strategy-deploy" | "manage-api-keys" | "manage-api-key-policies" | "manage-subaccount-policies">]>;
|
|
13
13
|
}, undefined>;
|
|
14
14
|
type SubaccountPermissionDefinition = v.InferOutput<typeof SubaccountPermissionDefinitionSchema>;
|
|
15
15
|
declare const SubaccountRoleDefinitionSchema: v.ObjectSchema<{
|
|
16
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
16
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
17
17
|
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
18
18
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
19
19
|
readonly assignable: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
@@ -25,10 +25,10 @@ declare const SubaccountRoleCatalogSchema: v.ObjectSchema<{
|
|
|
25
25
|
readonly permission: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "internal_transfer" | "swap" | "convert_dust" | "read_subaccount" | "update_subaccount" | "read_balances" | "read_spot" | "trade_spot" | "read_internal_transfers" | "external_withdraw" | "read_address_book" | "manage_address_book" | "read_members" | "manage_members" | "read_invites" | "manage_invites" | "read_api_keys" | "manage_api_keys" | "read_subaccount_policy" | "manage_subaccount_policy" | "read_activity" | "read_activity_security_details" | "manage_member_mfa_requirement" | "create_deposit_address" | "read_deposit_addresses" | "read_guard_signer_status" | "manage_guard_signer" | "read_auto_withdraw" | "manage_auto_withdraw" | "read_statements" | "read_funding_flows">]>;
|
|
26
26
|
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
27
27
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
28
|
-
readonly policyAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "swap" | "trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book" | "read-auto-withdraw" | "manage-auto-withdraw" | "read-statements" | "convert-dust" | "read-funding-flows" | "read-api-keys" | "read-api-policies" | "read-subaccount-policies" | "read-subaccount-permissions" | "read-vip-status" | "read-social-verification" | "read-profile" | "read-account-directory" | "read-withdraw-validation" | "read-daily-claims" | "claim-daily-reward" | "read-checkpoints" | "read-rewards" | "create-deposit-address" | "read-deposit-addresses" | "read-subaccounts" | "read-subaccount-activity" | "read-subaccount-members" | "read-subaccount-invites" | "read-guard-signer-status" | "read-price-alerts" | "manage-price-alerts" | "read-notifications" | "read-account-activity" | "manage-api-keys" | "manage-api-key-policies" | "manage-subaccount-policies">]>;
|
|
28
|
+
readonly policyAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "swap" | "trade-spot" | "internal-transfer" | "external-withdraw" | "read-balances" | "read-spot" | "read-internal-transfers" | "read-address-book" | "manage-address-book" | "read-auto-withdraw" | "manage-auto-withdraw" | "read-statements" | "convert-dust" | "read-funding-flows" | "read-api-keys" | "read-api-policies" | "read-subaccount-policies" | "read-subaccount-permissions" | "read-vip-status" | "read-social-verification" | "read-profile" | "read-account-directory" | "read-withdraw-validation" | "read-daily-claims" | "claim-daily-reward" | "read-checkpoints" | "read-rewards" | "create-deposit-address" | "read-deposit-addresses" | "read-subaccounts" | "read-subaccount-activity" | "read-subaccount-members" | "read-subaccount-invites" | "read-guard-signer-status" | "read-price-alerts" | "manage-price-alerts" | "read-notifications" | "read-account-activity" | "read-strategies" | "draft-strategies" | "propose-strategy-deploy" | "manage-api-keys" | "manage-api-key-policies" | "manage-subaccount-policies">]>;
|
|
29
29
|
}, undefined>, undefined>, readonly []>;
|
|
30
30
|
readonly roles: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
31
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
31
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
32
32
|
readonly displayName: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
33
33
|
readonly description: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
34
34
|
readonly assignable: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
@@ -37,7 +37,7 @@ declare const SubaccountRoleCatalogSchema: v.ObjectSchema<{
|
|
|
37
37
|
}, undefined>;
|
|
38
38
|
type SubaccountRoleCatalog = v.InferOutput<typeof SubaccountRoleCatalogSchema>;
|
|
39
39
|
declare const EffectiveSubaccountPermissionsSchema: v.ObjectSchema<{
|
|
40
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
40
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
41
41
|
readonly permissions: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "internal_transfer" | "swap" | "convert_dust" | "read_subaccount" | "update_subaccount" | "read_balances" | "read_spot" | "trade_spot" | "read_internal_transfers" | "external_withdraw" | "read_address_book" | "manage_address_book" | "read_members" | "manage_members" | "read_invites" | "manage_invites" | "read_api_keys" | "manage_api_keys" | "read_subaccount_policy" | "manage_subaccount_policy" | "read_activity" | "read_activity_security_details" | "manage_member_mfa_requirement" | "create_deposit_address" | "read_deposit_addresses" | "read_guard_signer_status" | "manage_guard_signer" | "read_auto_withdraw" | "manage_auto_withdraw" | "read_statements" | "read_funding_flows">]>, undefined>, readonly []>;
|
|
42
42
|
readonly subaccountPolicyId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
43
43
|
}, undefined>;
|
|
@@ -129,7 +129,7 @@ type UpdateSubaccountInput = v.InferInput<typeof UpdateSubaccountInputSchema>;
|
|
|
129
129
|
declare const InviteSubaccountMemberInputSchema: v.StrictObjectSchema<{
|
|
130
130
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
131
131
|
readonly granteeAccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
132
|
-
readonly role: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["owner", "admin", "treasury", "leveraged_trader", "trader", "viewer"], undefined>, v.TransformAction<"
|
|
132
|
+
readonly role: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["owner", "admin", "treasury", "leveraged_trader", "trader", "viewer"], undefined>, v.TransformAction<"owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer", SubaccountRole$1.VIEWER | SubaccountRole$1.TRADER | SubaccountRole$1.LEVERAGED_TRADER | SubaccountRole$1.TREASURY | SubaccountRole$1.ADMIN | SubaccountRole$1.OWNER>]>;
|
|
133
133
|
}, undefined>;
|
|
134
134
|
type InviteSubaccountMemberInput = v.InferInput<typeof InviteSubaccountMemberInputSchema>;
|
|
135
135
|
declare const RemoveSubaccountMemberInputSchema: v.StrictObjectSchema<{
|
|
@@ -140,7 +140,7 @@ type RemoveSubaccountMemberInput = v.InferInput<typeof RemoveSubaccountMemberInp
|
|
|
140
140
|
declare const UpdateSubaccountMemberRoleInputSchema: v.StrictObjectSchema<{
|
|
141
141
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
142
142
|
readonly granteeAccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
143
|
-
readonly role: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["owner", "admin", "treasury", "leveraged_trader", "trader", "viewer"], undefined>, v.TransformAction<"
|
|
143
|
+
readonly role: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["owner", "admin", "treasury", "leveraged_trader", "trader", "viewer"], undefined>, v.TransformAction<"owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer", SubaccountRole$1.VIEWER | SubaccountRole$1.TRADER | SubaccountRole$1.LEVERAGED_TRADER | SubaccountRole$1.TREASURY | SubaccountRole$1.ADMIN | SubaccountRole$1.OWNER>]>;
|
|
144
144
|
}, undefined>;
|
|
145
145
|
type UpdateSubaccountMemberRoleInput = v.InferInput<typeof UpdateSubaccountMemberRoleInputSchema>;
|
|
146
146
|
declare const SetSubaccountMemberMfaRequirementInputSchema: v.StrictObjectSchema<{
|
|
@@ -163,7 +163,7 @@ declare const ProtoSubaccountStatusSchema: v.SchemaWithPipe<readonly [v.NumberSc
|
|
|
163
163
|
type SubaccountStatus = v.InferOutput<typeof ProtoSubaccountStatusSchema>;
|
|
164
164
|
declare const SubaccountSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
165
165
|
readonly id: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
166
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
166
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
167
167
|
readonly label: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
168
168
|
readonly icon: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
169
169
|
readonly color: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
@@ -189,7 +189,7 @@ declare const SubaccountSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
189
189
|
readonly removed: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
190
190
|
}, undefined>, v.TransformAction<{
|
|
191
191
|
id: string;
|
|
192
|
-
role: "
|
|
192
|
+
role: "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified";
|
|
193
193
|
label: string;
|
|
194
194
|
icon: string;
|
|
195
195
|
color: string;
|
|
@@ -211,7 +211,7 @@ declare const SubaccountSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
211
211
|
updatedAt: number | undefined;
|
|
212
212
|
updatedAtNs: string | undefined;
|
|
213
213
|
id: string;
|
|
214
|
-
role: "
|
|
214
|
+
role: "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified";
|
|
215
215
|
label: string;
|
|
216
216
|
icon: string;
|
|
217
217
|
color: string;
|
|
@@ -229,7 +229,7 @@ declare const SubaccountSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
229
229
|
type Subaccount = v.InferOutput<typeof SubaccountSchema>;
|
|
230
230
|
declare const SubaccountMemberSchema: v.ObjectSchema<{
|
|
231
231
|
readonly accountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
232
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
232
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
233
233
|
readonly username: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
234
234
|
readonly smartAccountAddress: v.StringSchema<undefined>;
|
|
235
235
|
readonly avatarUrl: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
@@ -241,8 +241,8 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
241
241
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
242
242
|
readonly granteeAccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
243
243
|
readonly inviterAccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
244
|
-
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
245
|
-
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "
|
|
244
|
+
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
245
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "accepted" | "pending" | "declined">]>;
|
|
246
246
|
readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
247
247
|
readonly seconds: v.BigintSchema<undefined>;
|
|
248
248
|
readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
|
|
@@ -268,8 +268,8 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
268
268
|
subaccountId: string;
|
|
269
269
|
granteeAccountId: string;
|
|
270
270
|
inviterAccountId: string;
|
|
271
|
-
role: "
|
|
272
|
-
status: "unspecified" | "canceled" | "
|
|
271
|
+
role: "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified";
|
|
272
|
+
status: "unspecified" | "canceled" | "accepted" | "pending" | "declined";
|
|
273
273
|
createdAt?: number | undefined;
|
|
274
274
|
respondedAt?: number | undefined;
|
|
275
275
|
granteeUsername: string;
|
|
@@ -286,8 +286,8 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
286
286
|
id: string;
|
|
287
287
|
granteeAccountId: string;
|
|
288
288
|
inviterAccountId: string;
|
|
289
|
-
role: "
|
|
290
|
-
status: "unspecified" | "canceled" | "
|
|
289
|
+
role: "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified";
|
|
290
|
+
status: "unspecified" | "canceled" | "accepted" | "pending" | "declined";
|
|
291
291
|
createdAt?: number | undefined;
|
|
292
292
|
respondedAt?: number | undefined;
|
|
293
293
|
granteeUsername: string;
|
|
@@ -309,9 +309,9 @@ declare const SubaccountActivityEventSchema: v.ObjectSchema<{
|
|
|
309
309
|
seconds: bigint;
|
|
310
310
|
nanos: number;
|
|
311
311
|
} | undefined, number | undefined>]>;
|
|
312
|
-
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "subaccount" | "api_key" | "account" | "
|
|
313
|
-
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "disabled" | "
|
|
314
|
-
readonly source: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
312
|
+
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "subaccount" | "api_key" | "account" | "session" | "member" | "policy" | "invite" | "security" | "destination">]>;
|
|
313
|
+
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "disabled" | "removed" | "revoked" | "created" | "updated" | "deleted" | "enabled" | "role_set" | "received" | "replied" | "failed" | "blocked" | "hold_placed" | "hold_released" | "requested" | "applied">]>;
|
|
314
|
+
readonly source: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "web" | "mobile" | "api">]>;
|
|
315
315
|
readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
316
316
|
readonly userAgent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
317
317
|
readonly actorAccountId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
@@ -11,7 +11,7 @@ declare const ListStatusEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictOb
|
|
|
11
11
|
/** Previous `nextPageToken`; resend the same `states` and `kinds` with it. */
|
|
12
12
|
readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>;
|
|
13
13
|
}, undefined>, v.TransformAction<{
|
|
14
|
-
states?: ("canceled" | "
|
|
14
|
+
states?: ("canceled" | "scheduled" | "in_progress" | "completed")[] | undefined;
|
|
15
15
|
kinds?: ("maintenance" | "incident")[] | undefined;
|
|
16
16
|
limit?: number | undefined;
|
|
17
17
|
pageToken?: string | undefined;
|
|
@@ -26,7 +26,7 @@ type ListStatusEventsInput = v.InferInput<typeof ListStatusEventsInputSchema>;
|
|
|
26
26
|
declare const StatusEventSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
27
27
|
readonly id: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
28
28
|
readonly kind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "maintenance" | "incident">]>;
|
|
29
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "
|
|
29
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed">]>;
|
|
30
30
|
readonly title: v.StringSchema<undefined>;
|
|
31
31
|
readonly message: v.StringSchema<undefined>;
|
|
32
32
|
readonly startTime: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
@@ -43,7 +43,7 @@ declare const StatusEventSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
43
43
|
seconds: bigint;
|
|
44
44
|
nanos: number;
|
|
45
45
|
} | undefined, number | undefined>]>;
|
|
46
|
-
readonly services: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
46
|
+
readonly services: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app">]>, undefined>;
|
|
47
47
|
readonly markets: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
48
48
|
readonly updatedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
49
49
|
readonly seconds: v.BigintSchema<undefined>;
|
|
@@ -77,12 +77,12 @@ declare const StatusEventSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
77
77
|
}, undefined>, v.TransformAction<{
|
|
78
78
|
id: string;
|
|
79
79
|
kind: "unspecified" | "maintenance" | "incident";
|
|
80
|
-
state: "unspecified" | "canceled" | "
|
|
80
|
+
state: "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed";
|
|
81
81
|
title: string;
|
|
82
82
|
message: string;
|
|
83
83
|
startTime?: number | undefined;
|
|
84
84
|
endTime?: number | undefined;
|
|
85
|
-
services: ("unspecified" | "
|
|
85
|
+
services: ("unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app")[];
|
|
86
86
|
markets: string[];
|
|
87
87
|
updatedAt?: number | undefined;
|
|
88
88
|
impact: "unspecified" | "degraded" | "partial_outage" | "major_outage";
|
|
@@ -98,13 +98,13 @@ declare const StatusEventSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
98
98
|
/** Stable across updates; match events across pages by it. */
|
|
99
99
|
id: string;
|
|
100
100
|
kind: "unspecified" | "maintenance" | "incident";
|
|
101
|
-
state: "unspecified" | "canceled" | "
|
|
101
|
+
state: "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed";
|
|
102
102
|
title: string;
|
|
103
103
|
message: string;
|
|
104
104
|
startTime: number | null;
|
|
105
105
|
/** Always set for maintenance; null for an incident with no expected end yet. */
|
|
106
106
|
endTime: number | null;
|
|
107
|
-
services: ("unspecified" | "
|
|
107
|
+
services: ("unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app")[];
|
|
108
108
|
/** Affected market symbols such as `"BTC-USDT"`; empty when not limited to markets. */
|
|
109
109
|
markets: string[];
|
|
110
110
|
/** Affected asset codes such as `"SOL"`; empty when not limited to assets. */
|
|
@@ -128,7 +128,7 @@ declare const ListStatusEventsResultSchema: v.ObjectSchema<{
|
|
|
128
128
|
readonly events: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
129
129
|
readonly id: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
130
130
|
readonly kind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "maintenance" | "incident">]>;
|
|
131
|
-
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "
|
|
131
|
+
readonly state: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed">]>;
|
|
132
132
|
readonly title: v.StringSchema<undefined>;
|
|
133
133
|
readonly message: v.StringSchema<undefined>;
|
|
134
134
|
readonly startTime: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
@@ -145,7 +145,7 @@ declare const ListStatusEventsResultSchema: v.ObjectSchema<{
|
|
|
145
145
|
seconds: bigint;
|
|
146
146
|
nanos: number;
|
|
147
147
|
} | undefined, number | undefined>]>;
|
|
148
|
-
readonly services: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
148
|
+
readonly services: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app">]>, undefined>;
|
|
149
149
|
readonly markets: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
150
150
|
readonly updatedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
151
151
|
readonly seconds: v.BigintSchema<undefined>;
|
|
@@ -179,12 +179,12 @@ declare const ListStatusEventsResultSchema: v.ObjectSchema<{
|
|
|
179
179
|
}, undefined>, v.TransformAction<{
|
|
180
180
|
id: string;
|
|
181
181
|
kind: "unspecified" | "maintenance" | "incident";
|
|
182
|
-
state: "unspecified" | "canceled" | "
|
|
182
|
+
state: "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed";
|
|
183
183
|
title: string;
|
|
184
184
|
message: string;
|
|
185
185
|
startTime?: number | undefined;
|
|
186
186
|
endTime?: number | undefined;
|
|
187
|
-
services: ("unspecified" | "
|
|
187
|
+
services: ("unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app")[];
|
|
188
188
|
markets: string[];
|
|
189
189
|
updatedAt?: number | undefined;
|
|
190
190
|
impact: "unspecified" | "degraded" | "partial_outage" | "major_outage";
|
|
@@ -200,13 +200,13 @@ declare const ListStatusEventsResultSchema: v.ObjectSchema<{
|
|
|
200
200
|
/** Stable across updates; match events across pages by it. */
|
|
201
201
|
id: string;
|
|
202
202
|
kind: "unspecified" | "maintenance" | "incident";
|
|
203
|
-
state: "unspecified" | "canceled" | "
|
|
203
|
+
state: "unspecified" | "canceled" | "scheduled" | "in_progress" | "completed";
|
|
204
204
|
title: string;
|
|
205
205
|
message: string;
|
|
206
206
|
startTime: number | null;
|
|
207
207
|
/** Always set for maintenance; null for an incident with no expected end yet. */
|
|
208
208
|
endTime: number | null;
|
|
209
|
-
services: ("unspecified" | "
|
|
209
|
+
services: ("unspecified" | "api" | "deposits" | "withdrawals" | "transfers" | "trading" | "accounts" | "market_data" | "quickswap" | "app")[];
|
|
210
210
|
/** Affected market symbols such as `"BTC-USDT"`; empty when not limited to markets. */
|
|
211
211
|
markets: string[];
|
|
212
212
|
/** Affected asset codes such as `"SOL"`; empty when not limited to assets. */
|
|
@@ -169,7 +169,7 @@ declare const GetUserTradesInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema
|
|
|
169
169
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
170
170
|
readonly lineageId: 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`>]>;
|
|
171
171
|
readonly throughGeneration: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
172
|
-
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.
|
|
172
|
+
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.StringIssue | v.BooleanIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.PicklistIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.PicklistIssue> | v.GtValueIssue<number, 0> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue | v.UnionIssue<v.NumberIssue | v.StringIssue | v.BooleanIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.PicklistIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.MinLengthIssue<string, 1> | v.PicklistIssue> | v.GtValueIssue<number, 0> | v.MaxValueIssue<number, 4294967295> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue>>) => "Provide at most one of orderId or lineageId" | "throughGeneration requires lineageId" | "symbolId is required when afterMatchId is set" | "Invalid trade filters">, v.TransformAction<{
|
|
173
173
|
symbolId?: number | undefined;
|
|
174
174
|
afterMatchId?: undefined;
|
|
175
175
|
side?: Side.BUY | Side.SELL | undefined;
|
|
@@ -3,7 +3,7 @@ import { ApiKeyEd25519AuthProvider, AuthApiTransports, JwtAuthProvider } from ".
|
|
|
3
3
|
import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../shared/request-options.js";
|
|
4
4
|
import { SubaccountResolver } from "../subaccount-resolver.js";
|
|
5
5
|
import { SdkScales } from "../../shared/decimal-surface.js";
|
|
6
|
-
import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
|
|
6
|
+
import { CreateTradingToFundingBatchInput, CreateTradingToFundingBatchResult, CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
|
|
7
7
|
import { Address, Hex } from "viem";
|
|
8
8
|
//#region src/services/trading-withdraws/trading-withdraws.d.ts
|
|
9
9
|
type TradingWithdrawWalletSigner = {
|
|
@@ -25,6 +25,20 @@ type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFunding
|
|
|
25
25
|
type CreateTradingWithdrawToExternalChainServiceInput = CreateTradingWithdrawToExternalChainInput & {
|
|
26
26
|
walletSigner?: TradingWithdrawWalletSigner;
|
|
27
27
|
};
|
|
28
|
+
type CreateTradingToFundingBatchServiceInput = CreateTradingToFundingBatchInput & {
|
|
29
|
+
walletSigner: TradingWithdrawWalletSigner;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A signed batch. `submit` always sends the same signed request, so it can be repeated after
|
|
33
|
+
* an MFA step-up, or after an `aborted` or `unavailable` answer: the server then answers the
|
|
34
|
+
* first outcome for the key. It never signs again; a refused batch is final for its key, so
|
|
35
|
+
* moving the funds needs a new batch with a new `idempotencyKey`.
|
|
36
|
+
*/
|
|
37
|
+
type PreparedTradingToFundingBatch = Readonly<{
|
|
38
|
+
/** When the backend stops accepting a new submission of this batch. */
|
|
39
|
+
deadline: Date;
|
|
40
|
+
submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingToFundingBatchResult>;
|
|
41
|
+
}>;
|
|
28
42
|
type PreparedTradingWithdraw = Readonly<{
|
|
29
43
|
/** When the backend stops accepting the currently signed request. */
|
|
30
44
|
deadline: Date;
|
|
@@ -76,7 +90,20 @@ declare class TradingWithdrawsService {
|
|
|
76
90
|
* be resubmitted after backend-directed authorization such as MFA step-up.
|
|
77
91
|
*/
|
|
78
92
|
prepareToExternalChain(input: CreateTradingWithdrawToExternalChainServiceInput): Promise<PreparedTradingWithdraw>;
|
|
93
|
+
/**
|
|
94
|
+
* Moves up to 10 amounts from one Trading account to Funding accounts with one wallet
|
|
95
|
+
* signature and one MFA check. All legs are accepted or none, and an accepted batch is paid
|
|
96
|
+
* as one or refunded in full. When every leg goes to the caller's own accounts, an
|
|
97
|
+
* MFA-elevated session is enough; any other leg needs a fresh `stepUpToken`. Wallet signers
|
|
98
|
+
* only.
|
|
99
|
+
*/
|
|
100
|
+
createToFundingBatch(input: CreateTradingToFundingBatchServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingToFundingBatchResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Builds and signs a Trading-to-Funding batch once, so the exact request can be resubmitted
|
|
103
|
+
* after an MFA step-up or a transient failure.
|
|
104
|
+
*/
|
|
105
|
+
prepareToFundingBatch(input: CreateTradingToFundingBatchServiceInput): Promise<PreparedTradingToFundingBatch>;
|
|
79
106
|
}
|
|
80
107
|
//#endregion
|
|
81
|
-
export { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawsService };
|
|
108
|
+
export { CreateTradingToFundingBatchServiceInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingToFundingBatch, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawsService };
|
|
82
109
|
//# sourceMappingURL=trading-withdraws.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;KAsDY;EACR;EACA;;;;;EAKA,cAAc,oBAAoB,QAAQ;;KAGlC;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0CAA0C;EAClD,cAAc;;;;;;;;KASN,gCAAgC;;EAExC,UAAU;EACV,SAAS,UAAU,6BAA6B,QAAQ;;KAGhD,0BAA0B;;EAElC,UAAU;;;;;;EAMV;;;;;;EAMA,SAAS,UAAU,6BAA6B,QAAQ;;;;;cAqG/C;;EAcL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU,eACV,OAAO,kBAAkB;;;;;;;EAoBvB,kBACF,QAAO,wBACP,UAAU,0BACX,QAAQ;;;;EAeL,oBACF,OAAO,kCACP,UAAU,0BACX,QAAQ;;;;EAYL,gBACF,OAAO,4CACP,UAAU,2BACX,QAAQ;;;;;EASL,iBACF,OAAO,6CACR,QAAQ;;;;EAWL,sBACF,OAAO,kDACP,UAAU,2BACX,QAAQ;;;;;EASL,uBACF,OAAO,mDACR,QAAQ;;;;;;;;EAeL,qBACF,OAAO,yCACP,UAAU,2BACX,QAAQ;;;;;EASL,sBACF,OAAO,0CACR,QAAQ"}
|
|
@@ -5,10 +5,11 @@ import { parse } from "../../shared/validation.js";
|
|
|
5
5
|
import { removeUndefined } from "../../utils/remove-undefined.js";
|
|
6
6
|
import { toConnectCallOptions } from "../../shared/request-options.js";
|
|
7
7
|
import { idToBigInt } from "../../utils/base58-id.js";
|
|
8
|
+
import { toU128 } from "../../utils/u128.js";
|
|
8
9
|
import { resolveAccountScopedInput } from "../subaccount-resolver.js";
|
|
9
10
|
import { TradingWithdrawIntentPayloadSchema, WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
10
|
-
import { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload } from "./trading-withdraws.schemas.js";
|
|
11
|
-
import { buildTradingWithdrawWalletMessage } from "./wallet-message.js";
|
|
11
|
+
import { CreateTradingToFundingBatchResultSchema, CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingToFundingBatchInputSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload } from "./trading-withdraws.schemas.js";
|
|
12
|
+
import { buildTradingToFundingBatchWalletMessage, buildTradingWithdrawWalletMessage } from "./wallet-message.js";
|
|
12
13
|
import { create, toBinary } from "@bufbuild/protobuf";
|
|
13
14
|
import { createClient } from "@connectrpc/connect";
|
|
14
15
|
//#region src/services/trading-withdraws/trading-withdraws.ts
|
|
@@ -30,6 +31,10 @@ function preparedWithdraw(signed, resign) {
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
function walletSignatureBytes(signature) {
|
|
35
|
+
if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) throw new ValidationError("Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.");
|
|
36
|
+
return evmHexToBytes(signature);
|
|
37
|
+
}
|
|
33
38
|
function resolveTradingWithdrawTargetAccountId(params) {
|
|
34
39
|
if (params.subaccountId !== void 0) return params.subaccountId;
|
|
35
40
|
return idToBigInt(params.rootAccountId, "targetAccountId");
|
|
@@ -51,17 +56,15 @@ async function resolveTradingWithdrawSigningConfig(params) {
|
|
|
51
56
|
async function resolveWalletSignature(params) {
|
|
52
57
|
const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();
|
|
53
58
|
const accountId = idToBigInt(params.walletSigner.accountId, "accountId");
|
|
54
|
-
const signature = await params.walletSigner.signMessage(buildTradingWithdrawWalletMessage({
|
|
55
|
-
signingConfig: params.signingConfig,
|
|
56
|
-
payload: params.payload,
|
|
57
|
-
signerWallet,
|
|
58
|
-
accountId,
|
|
59
|
-
targetAccountId: params.targetAccountId
|
|
60
|
-
}));
|
|
61
|
-
if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) throw new ValidationError("Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.");
|
|
62
59
|
return {
|
|
63
60
|
signerWallet,
|
|
64
|
-
payloadSignature:
|
|
61
|
+
payloadSignature: walletSignatureBytes(await params.walletSigner.signMessage(buildTradingWithdrawWalletMessage({
|
|
62
|
+
signingConfig: params.signingConfig,
|
|
63
|
+
payload: params.payload,
|
|
64
|
+
signerWallet,
|
|
65
|
+
accountId,
|
|
66
|
+
targetAccountId: params.targetAccountId
|
|
67
|
+
})))
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
@@ -76,6 +79,7 @@ var TradingWithdrawsService = class {
|
|
|
76
79
|
#auth;
|
|
77
80
|
#toFundingInputSchema;
|
|
78
81
|
#toExternalChainInputSchema;
|
|
82
|
+
#toFundingBatchInputSchema;
|
|
79
83
|
constructor(transports, resolver, signingConfig, scales, catalog, auth) {
|
|
80
84
|
this.#client = createClient(WithdrawService, transports.authApi);
|
|
81
85
|
this.#auth = auth;
|
|
@@ -85,6 +89,7 @@ var TradingWithdrawsService = class {
|
|
|
85
89
|
this.#scales = scales;
|
|
86
90
|
this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);
|
|
87
91
|
this.#toExternalChainInputSchema = createCreateTradingWithdrawToExternalChainInputSchema(scales);
|
|
92
|
+
this.#toFundingBatchInputSchema = createCreateTradingToFundingBatchInputSchema(scales);
|
|
88
93
|
}
|
|
89
94
|
/**
|
|
90
95
|
* Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a
|
|
@@ -139,6 +144,64 @@ var TradingWithdrawsService = class {
|
|
|
139
144
|
const validated = parse(this.#toExternalChainInputSchema, resolvedInput);
|
|
140
145
|
return this.#prepareWithdraw(validated, walletSigner);
|
|
141
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Moves up to 10 amounts from one Trading account to Funding accounts with one wallet
|
|
149
|
+
* signature and one MFA check. All legs are accepted or none, and an accepted batch is paid
|
|
150
|
+
* as one or refunded in full. When every leg goes to the caller's own accounts, an
|
|
151
|
+
* MFA-elevated session is enough; any other leg needs a fresh `stepUpToken`. Wallet signers
|
|
152
|
+
* only.
|
|
153
|
+
*/
|
|
154
|
+
async createToFundingBatch(input, options) {
|
|
155
|
+
return (await this.prepareToFundingBatch(input)).submit(options);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Builds and signs a Trading-to-Funding batch once, so the exact request can be resubmitted
|
|
159
|
+
* after an MFA step-up or a transient failure.
|
|
160
|
+
*/
|
|
161
|
+
async prepareToFundingBatch(input) {
|
|
162
|
+
await this.#scales.ready();
|
|
163
|
+
const { walletSigner, ...inputForValidation } = input;
|
|
164
|
+
const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);
|
|
165
|
+
const validated = parse(this.#toFundingBatchInputSchema, resolvedInput);
|
|
166
|
+
const signingConfig = await resolveTradingWithdrawSigningConfig({
|
|
167
|
+
fallback: this.#signingConfig,
|
|
168
|
+
catalog: this.#catalog
|
|
169
|
+
});
|
|
170
|
+
const signerWallet = walletSigner.signerWallet.trim().toLowerCase();
|
|
171
|
+
const signature = await walletSigner.signMessage(buildTradingToFundingBatchWalletMessage({
|
|
172
|
+
signingConfig,
|
|
173
|
+
signerWallet,
|
|
174
|
+
accountId: idToBigInt(walletSigner.accountId, "accountId"),
|
|
175
|
+
targetAccountId: resolveTradingWithdrawTargetAccountId({
|
|
176
|
+
subaccountId: validated.subaccountId,
|
|
177
|
+
rootAccountId: walletSigner.accountId
|
|
178
|
+
}),
|
|
179
|
+
deadlineTsSec: validated.deadlineTsSec,
|
|
180
|
+
nonce: validated.nonce,
|
|
181
|
+
idempotencyKey: validated.idempotencyKey,
|
|
182
|
+
legs: validated.legs
|
|
183
|
+
}));
|
|
184
|
+
const request = removeUndefined({
|
|
185
|
+
legs: validated.legs.map((leg) => ({
|
|
186
|
+
assetId: leg.assetId,
|
|
187
|
+
amountE18: toU128(leg.amountE18),
|
|
188
|
+
destinationAddress: leg.destinationAddress
|
|
189
|
+
})),
|
|
190
|
+
subaccountId: validated.subaccountId,
|
|
191
|
+
deadlineTsSec: validated.deadlineTsSec,
|
|
192
|
+
nonce: toU128(validated.nonce),
|
|
193
|
+
idempotencyKey: validated.idempotencyKey,
|
|
194
|
+
signerWallet,
|
|
195
|
+
payloadSignature: walletSignatureBytes(signature)
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
deadline: /* @__PURE__ */ new Date(Number(validated.deadlineTsSec) * 1e3),
|
|
199
|
+
submit: async (options) => {
|
|
200
|
+
const response = await this.#client.createWalletTradingToFundingBatch(request, toConnectCallOptions(options));
|
|
201
|
+
return parse(CreateTradingToFundingBatchResultSchema, response);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
142
205
|
async #prepareWithdraw(validated, walletSigner) {
|
|
143
206
|
if (walletSigner) {
|
|
144
207
|
const signingConfig = await resolveTradingWithdrawSigningConfig({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#auth","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw","Proto.TradingWithdrawIntentPayloadSchema"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ConfigurationError, ValidationError } from \"../../shared/errors.js\";\nimport { create, toBinary } from \"@bufbuild/protobuf\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n signApiKeyEd25519Payload,\n type ApiKeyEd25519AuthProvider,\n type AuthApiTransports,\n type JwtAuthProvider,\n} from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n GetWalletBalancesInputSchema,\n GetWalletBalancesResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type GetWalletBalancesInput,\n type GetWalletBalancesResult,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { buildTradingWithdrawWalletMessage } from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. The withdraw signs again on\n * `submit` from then on, so callers can keep resubmitting the same prepared withdraw,\n * e.g. after a slow MFA step-up.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near: the\n * withdraw then signs a fresh deadline and nonce with the same idempotency key.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return {\n signerWallet,\n payloadSignature: evmHexToBytes(signature),\n };\n}\n\n/**\n * Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#auth = auth;\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n }\n\n /**\n * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a\n * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there\n * until moved. Balances that could not be read are listed in `unavailableAssets`, not\n * reported as zero. API keys need `read-balances`.\n */\n async getWalletBalances(\n input: GetWalletBalancesInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<GetWalletBalancesResult> {\n const request = parse(\n GetWalletBalancesInputSchema,\n resolveAccountScopedInput(input, this.#resolver),\n );\n const response = await this.#client.getWalletBalances(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetWalletBalancesResultSchema, response);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one. API keys need `read-withdraw-validation`.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n const auth = this.#auth;\n if (auth?.kind !== \"api-key-ed25519\") {\n throw new ConfigurationError(\n \"Trading withdraw requires a wallet signer or API-key auth.\",\n );\n }\n // CreateTradingWithdrawRequest has no subaccount field: the API key decides the account.\n if (validated.subaccountId !== undefined) {\n throw new ValidationError(\n 'API-key trading withdraws cannot target a subaccount. Use `account: \"main\"` or a wallet signer.',\n );\n }\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n // The backend verifies the signature over the payload's protobuf encoding.\n const payloadSignature = await signApiKeyEd25519Payload(\n auth,\n toBinary(\n Proto.TradingWithdrawIntentPayloadSchema,\n create(Proto.TradingWithdrawIntentPayloadSchema, payload),\n ),\n );\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n { payload, payloadSignature },\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6FA,MAAM,qCAAqC;AAE3C,SAAS,WAAW,SAAsD;CACtE,OAAO,OAAO,QAAQ,aAAa,IAAI;AAC3C;AAEA,SAAS,iBACL,QACA,QACuB;CACvB,IAAI,UAAU;CACd,MAAM,kBACF,KAAK,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K,UAAU,OAAO,GAAG,IAAI;CAC/D;AACJ"}
|
|
1
|
+
{"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#auth","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#toFundingBatchInputSchema","#prepareWithdraw","Proto.TradingWithdrawIntentPayloadSchema"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ConfigurationError, ValidationError } from \"../../shared/errors.js\";\nimport { create, toBinary } from \"@bufbuild/protobuf\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport { checksumEvmAddress, evmHexToBytes } from \"../../utils/evm.js\";\nimport type { ClientCatalog } from \"../../catalogs/types.js\";\nimport * as Proto from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { idToBigInt } from \"../../utils/base58-id.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n toConnectCallOptions,\n type PolyesterMutationOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { type SubaccountResolver, resolveAccountScopedInput } from \"../subaccount-resolver.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n signApiKeyEd25519Payload,\n type ApiKeyEd25519AuthProvider,\n type AuthApiTransports,\n type JwtAuthProvider,\n} from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport {\n createCreateTradingToFundingBatchInputSchema,\n CreateTradingToFundingBatchResultSchema,\n type CreateTradingToFundingBatchInput,\n type CreateTradingToFundingBatchResult,\n createCreateTradingWithdrawToExternalChainInputSchema,\n createCreateTradingWithdrawToFundingInputSchema,\n CreateTradingWithdrawResultSchema,\n CreateWalletTradingWithdrawResultSchema,\n GetWalletBalancesInputSchema,\n GetWalletBalancesResultSchema,\n ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n renewTradingWithdrawPayload,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type GetWalletBalancesInput,\n type GetWalletBalancesResult,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\nimport { toU128 } from \"../../utils/u128.js\";\nimport {\n buildTradingToFundingBatchWalletMessage,\n buildTradingWithdrawWalletMessage,\n} from \"./wallet-message.js\";\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n /**\n * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.\n * For a viem account, use `(message) => account.signMessage({ message })`.\n */\n signMessage: (message: string) => Promise<Hex>;\n};\n\nexport type TradingWithdrawSigningConfig = {\n chainId: number;\n tradingGatewayAddress: Address;\n};\n\nexport type CreateTradingWithdrawToFundingServiceInput = CreateTradingWithdrawToFundingInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n};\n\nexport type CreateTradingWithdrawToExternalChainServiceInput =\n CreateTradingWithdrawToExternalChainInput & {\n walletSigner?: TradingWithdrawWalletSigner;\n };\n\nexport type CreateTradingToFundingBatchServiceInput = CreateTradingToFundingBatchInput & {\n walletSigner: TradingWithdrawWalletSigner;\n};\n\n/**\n * A signed batch. `submit` always sends the same signed request, so it can be repeated after\n * an MFA step-up, or after an `aborted` or `unavailable` answer: the server then answers the\n * first outcome for the key. It never signs again; a refused batch is final for its key, so\n * moving the funds needs a new batch with a new `idempotencyKey`.\n */\nexport type PreparedTradingToFundingBatch = Readonly<{\n /** When the backend stops accepting a new submission of this batch. */\n deadline: Date;\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingToFundingBatchResult>;\n}>;\n\nexport type PreparedTradingWithdraw = Readonly<{\n /** When the backend stops accepting the currently signed request. */\n deadline: Date;\n /**\n * True once the deadline is less than a minute away. The withdraw signs again on\n * `submit` from then on, so callers can keep resubmitting the same prepared withdraw,\n * e.g. after a slow MFA step-up.\n */\n isExpired: () => boolean;\n /**\n * Submits the payload and signature produced during preparation. Repeated calls only\n * change transport options such as the step-up token, unless the deadline is near: the\n * withdraw then signs a fresh deadline and nonce with the same idempotency key.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype SignedTradingWithdraw = {\n payload: TradingWithdrawIntentPayloadRequest;\n send: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n};\n\n// Leaves room for the request to reach the backend and for modest clock skew.\nconst PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 60_000;\n\nfunction deadlineMs(payload: TradingWithdrawIntentPayloadRequest): number {\n return Number(payload.deadlineTsSec) * 1000;\n}\n\nfunction preparedWithdraw(\n signed: SignedTradingWithdraw,\n resign: (payload: TradingWithdrawIntentPayloadRequest) => Promise<SignedTradingWithdraw>,\n): PreparedTradingWithdraw {\n let current = signed;\n const isExpired = () =>\n Date.now() >= deadlineMs(current.payload) - PREPARED_WITHDRAW_EXPIRY_MARGIN_MS;\n return {\n get deadline() {\n return new Date(deadlineMs(current.payload));\n },\n isExpired,\n submit: async (options) => {\n if (isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n }\n return current.send(options);\n },\n };\n}\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction walletSignatureBytes(signature: Hex): Uint8Array {\n if (!/^0x[0-9a-fA-F]{128}(?:00|01|1[bBcC])$/.test(signature)) {\n throw new ValidationError(\n \"Trading withdraw wallet signature must be 65 bytes with recovery byte 0, 1, 27, or 28.\",\n );\n }\n return evmHexToBytes(signature);\n}\n\nfunction resolveTradingWithdrawTargetAccountId(params: {\n subaccountId: bigint | undefined;\n rootAccountId: string;\n}): bigint {\n if (params.subaccountId !== undefined) return params.subaccountId;\n return idToBigInt(params.rootAccountId, \"targetAccountId\");\n}\n\nasync function resolveTradingWithdrawSigningConfig(params: {\n fallback: TradingWithdrawSigningConfig;\n catalog?: ClientCatalog;\n}): Promise<TradingWithdrawSigningConfig> {\n if (!params.catalog) return params.fallback;\n\n try {\n await params.catalog.ensureReady();\n const gateway = params.catalog.zipper.getContractByName(\"tradingGateway\");\n const address = gateway?.address?.trim();\n if (!address?.startsWith(\"0x\")) return params.fallback;\n\n return {\n chainId: params.fallback.chainId,\n tradingGatewayAddress: checksumEvmAddress(address),\n };\n } catch {\n return params.fallback;\n }\n}\n\nasync function resolveWalletSignature(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n walletSigner: TradingWithdrawWalletSigner;\n targetAccountId: bigint;\n}): Promise<{ signerWallet: string; payloadSignature: Uint8Array }> {\n const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signMessage(\n buildTradingWithdrawWalletMessage({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet,\n accountId,\n targetAccountId: params.targetAccountId,\n }),\n );\n return { signerWallet, payloadSignature: walletSignatureBytes(signature) };\n}\n\n/**\n * Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\n #auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider;\n #toFundingInputSchema: ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>;\n #toExternalChainInputSchema: ReturnType<\n typeof createCreateTradingWithdrawToExternalChainInputSchema\n >;\n #toFundingBatchInputSchema: ReturnType<typeof createCreateTradingToFundingBatchInputSchema>;\n\n constructor(\n transports: AuthApiTransports,\n resolver: SubaccountResolver | undefined,\n signingConfig: TradingWithdrawSigningConfig,\n scales: SdkScales,\n catalog?: ClientCatalog,\n auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider,\n ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\n this.#auth = auth;\n this.#resolver = resolver;\n this.#signingConfig = signingConfig;\n this.#catalog = catalog;\n this.#scales = scales;\n this.#toFundingInputSchema = createCreateTradingWithdrawToFundingInputSchema(scales);\n this.#toExternalChainInputSchema =\n createCreateTradingWithdrawToExternalChainInputSchema(scales);\n this.#toFundingBatchInputSchema = createCreateTradingToFundingBatchInputSchema(scales);\n }\n\n /**\n * Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a\n * rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there\n * until moved. Balances that could not be read are listed in `unavailableAssets`, not\n * reported as zero. API keys need `read-balances`.\n */\n async getWalletBalances(\n input: GetWalletBalancesInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<GetWalletBalancesResult> {\n const request = parse(\n GetWalletBalancesInputSchema,\n resolveAccountScopedInput(input, this.#resolver),\n );\n const response = await this.#client.getWalletBalances(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(GetWalletBalancesResultSchema, response);\n }\n\n /**\n * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one. API keys need `read-withdraw-validation`.\n */\n async validateDestination(\n input: ValidateWithdrawDestinationInput,\n options?: PolyesterRequestOptions,\n ): Promise<ValidateWithdrawDestinationResult> {\n const request = parse(ValidateWithdrawDestinationInputSchema, input);\n const response = await this.#client.validateWithdrawDestination(\n request,\n toConnectCallOptions(options),\n );\n return parse(ValidateWithdrawDestinationResultSchema, response);\n }\n\n /**\n * Builds a Trading-to-Funding withdraw intent payload with asset id, decimal amount, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToFunding(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding withdrawal once so the exact request can be\n * resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToFunding(\n input: CreateTradingWithdrawToFundingServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Builds a Trading-to-external-chain withdraw intent payload with asset id, decimal gross amount, destination network, destination address, five-minute deadline, nonce, and idempotency key. If a wallet signer is provided, it signs the canonical EIP-191 message and calls the wallet endpoint; otherwise the client's API key signs the payload for the API-key endpoint.\n */\n async createToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingWithdrawResult> {\n const prepared = await this.prepareToExternalChain(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-external-chain withdrawal once so the exact request can\n * be resubmitted after backend-directed authorization such as MFA step-up.\n */\n async prepareToExternalChain(\n input: CreateTradingWithdrawToExternalChainServiceInput,\n ): Promise<PreparedTradingWithdraw> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toExternalChainInputSchema, resolvedInput);\n return this.#prepareWithdraw(validated, walletSigner);\n }\n\n /**\n * Moves up to 10 amounts from one Trading account to Funding accounts with one wallet\n * signature and one MFA check. All legs are accepted or none, and an accepted batch is paid\n * as one or refunded in full. When every leg goes to the caller's own accounts, an\n * MFA-elevated session is enough; any other leg needs a fresh `stepUpToken`. Wallet signers\n * only.\n */\n async createToFundingBatch(\n input: CreateTradingToFundingBatchServiceInput,\n options?: PolyesterMutationOptions,\n ): Promise<CreateTradingToFundingBatchResult> {\n const prepared = await this.prepareToFundingBatch(input);\n return prepared.submit(options);\n }\n\n /**\n * Builds and signs a Trading-to-Funding batch once, so the exact request can be resubmitted\n * after an MFA step-up or a transient failure.\n */\n async prepareToFundingBatch(\n input: CreateTradingToFundingBatchServiceInput,\n ): Promise<PreparedTradingToFundingBatch> {\n await this.#scales.ready();\n const { walletSigner, ...inputForValidation } = input;\n const resolvedInput = resolveAccountScopedInput(inputForValidation, this.#resolver);\n const validated = parse(this.#toFundingBatchInputSchema, resolvedInput);\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const signerWallet = walletSigner.signerWallet.trim().toLowerCase();\n const signature = await walletSigner.signMessage(\n buildTradingToFundingBatchWalletMessage({\n signingConfig,\n signerWallet,\n accountId: idToBigInt(walletSigner.accountId, \"accountId\"),\n targetAccountId: resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n }),\n deadlineTsSec: validated.deadlineTsSec,\n nonce: validated.nonce,\n idempotencyKey: validated.idempotencyKey,\n legs: validated.legs,\n }),\n );\n const request = removeUndefined({\n legs: validated.legs.map((leg) => ({\n assetId: leg.assetId,\n amountE18: toU128(leg.amountE18),\n destinationAddress: leg.destinationAddress,\n })),\n subaccountId: validated.subaccountId,\n deadlineTsSec: validated.deadlineTsSec,\n nonce: toU128(validated.nonce),\n idempotencyKey: validated.idempotencyKey,\n signerWallet,\n payloadSignature: walletSignatureBytes(signature),\n });\n return {\n deadline: new Date(Number(validated.deadlineTsSec) * 1000),\n submit: async (options) => {\n const response = await this.#client.createWalletTradingToFundingBatch(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateTradingToFundingBatchResultSchema, response);\n },\n };\n }\n\n async #prepareWithdraw(\n validated: TradingWithdrawRequest,\n walletSigner: TradingWithdrawWalletSigner | undefined,\n ): Promise<PreparedTradingWithdraw> {\n if (walletSigner) {\n const signingConfig = await resolveTradingWithdrawSigningConfig({\n fallback: this.#signingConfig,\n catalog: this.#catalog,\n });\n const targetAccountId = resolveTradingWithdrawTargetAccountId({\n subaccountId: validated.subaccountId,\n rootAccountId: walletSigner.accountId,\n });\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n\n const auth = this.#auth;\n if (auth?.kind !== \"api-key-ed25519\") {\n throw new ConfigurationError(\n \"Trading withdraw requires a wallet signer or API-key auth.\",\n );\n }\n // CreateTradingWithdrawRequest has no subaccount field: the API key decides the account.\n if (validated.subaccountId !== undefined) {\n throw new ValidationError(\n 'API-key trading withdraws cannot target a subaccount. Use `account: \"main\"` or a wallet signer.',\n );\n }\n const sign = async (\n payload: TradingWithdrawIntentPayloadRequest,\n ): Promise<SignedTradingWithdraw> => {\n // The backend verifies the signature over the payload's protobuf encoding.\n const payloadSignature = await signApiKeyEd25519Payload(\n auth,\n toBinary(\n Proto.TradingWithdrawIntentPayloadSchema,\n create(Proto.TradingWithdrawIntentPayloadSchema, payload),\n ),\n );\n return {\n payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n { payload, payloadSignature },\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n };\n };\n return preparedWithdraw(await sign(validated.payload), sign);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqHA,MAAM,qCAAqC;AAE3C,SAAS,WAAW,SAAsD;CACtE,OAAO,OAAO,QAAQ,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