@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
|
@@ -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.NumberIssue | v.StringIssue | v.BooleanIssue | 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,IAAI,KAAK,WAAW,QAAQ,OAAO,IAAI;CAChD,OAAO;EACH,IAAI,WAAW;GACX,OAAO,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC;EAC/C;EACA;EACA,QAAQ,OAAO,YAAY;GACvB,IAAI,UAAU,GACV,UAAU,MAAM,OAAO,4BAA4B,QAAQ,OAAO,CAAC;GAEvE,OAAO,QAAQ,KAAK,OAAO;EAC/B;CACJ;AACJ;AAMA,SAAS,sCAAsC,QAGpC;CACP,IAAI,OAAO,iBAAiB,KAAA,GAAW,OAAO,OAAO;CACrD,OAAO,WAAW,OAAO,eAAe,iBAAiB;AAC7D;AAEA,eAAe,oCAAoC,QAGT;CACtC,IAAI,CAAC,OAAO,SAAS,OAAO,OAAO;CAEnC,IAAI;EACA,MAAM,OAAO,QAAQ,YAAY;EAEjC,MAAM,UADU,OAA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AAC;IACD,OAAO;KACH;KACA,MAAM,OAAO,YAAY;MACrB,MAAM,WAAW,MAAM,KAAKL,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;MACA,OAAO,MAAM,yCAAyC,QAAQ;KAClE;IACJ;GACJ;GACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;EAC/D;EAEA,MAAM,OAAO,KAAKE;EAClB,IAAI,MAAM,SAAS,mBACf,MAAM,IAAI,mBACN,4DACJ;EAGJ,IAAI,UAAU,iBAAiB,KAAA,GAC3B,MAAM,IAAI,gBACN,mGACJ;EAEJ,MAAM,OAAO,OACT,YACiC;GAEjC,MAAM,mBAAmB,MAAM,yBAC3B,MACA,SACIQ,oCACA,OAAOA,oCAA0C,OAAO,CAC5D,CACJ;GACA,OAAO;IACH;IACA,MAAM,OAAO,YAAY;KACrB,MAAM,WAAW,MAAM,KAAKV,QAAQ,sBAChC;MAAE;MAAS;KAAiB,GAC5B,qBAAqB,OAAO,CAChC;KACA,OAAO,MAAM,mCAAmC,QAAQ;IAC5D;GACJ;EACJ;EACA,OAAO,iBAAiB,MAAM,KAAK,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,aAAa,IAAI;AAC3C;AAEA,SAAS,iBACL,QACA,QACuB;CACvB,IAAI,UAAU;CACd,MAAM,kBACF,KAAK,IAAI,KAAK,WAAW,QAAQ,OAAO,IAAI;CAChD,OAAO;EACH,IAAI,WAAW;GACX,OAAO,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC;EAC/C;EACA;EACA,QAAQ,OAAO,YAAY;GACvB,IAAI,UAAU,GACV,UAAU,MAAM,OAAO,4BAA4B,QAAQ,OAAO,CAAC;GAEvE,OAAO,QAAQ,KAAK,OAAO;EAC/B;CACJ;AACJ;AAMA,SAAS,qBAAqB,WAA4B;CACtD,IAAI,CAAC,wCAAwC,KAAK,SAAS,GACvD,MAAM,IAAI,gBACN,wFACJ;CAEJ,OAAO,cAAc,SAAS;AAClC;AAEA,SAAS,sCAAsC,QAGpC;CACP,IAAI,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KACjD;KACA;KACA;KACA;IACJ,CAAC;IACD,MAAM,UAAU,gBAAgB;KAC5B;KACA,cAAc,UAAU;KACxB,cAAc,gBAAgB;KAC9B,kBAAkB,gBAAgB;IACtC,CAAC;IACD,OAAO;KACH;KACA,MAAM,OAAO,YAAY;MACrB,MAAM,WAAW,MAAM,KAAKL,QAAQ,4BAChC,SACA,qBAAqB,OAAO,CAChC;MACA,OAAO,MAAM,yCAAyC,QAAQ;KAClE;IACJ;GACJ;GACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;EAC/D;EAEA,MAAM,OAAO,KAAKE;EAClB,IAAI,MAAM,SAAS,mBACf,MAAM,IAAI,mBACN,4DACJ;EAGJ,IAAI,UAAU,iBAAiB,KAAA,GAC3B,MAAM,IAAI,gBACN,mGACJ;EAEJ,MAAM,OAAO,OACT,YACiC;GAEjC,MAAM,mBAAmB,MAAM,yBAC3B,MACA,SACIS,oCACA,OAAOA,oCAA0C,OAAO,CAC5D,CACJ;GACA,OAAO;IACH;IACA,MAAM,OAAO,YAAY;KACrB,MAAM,WAAW,MAAM,KAAKX,QAAQ,sBAChC;MAAE;MAAS;KAAiB,GAC5B,qBAAqB,OAAO,CAChC;KACA,OAAO,MAAM,mCAAmC,QAAQ;IAC5D;GACJ;EACJ;EACA,OAAO,iBAAiB,MAAM,KAAK,UAAU,OAAO,GAAG,IAAI;CAC/D;AACJ"}
|
|
@@ -70,6 +70,90 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
|
|
|
70
70
|
subaccountId: string;
|
|
71
71
|
} | undefined;
|
|
72
72
|
}, CreateTradingWithdrawRequestBase>]>;
|
|
73
|
+
declare function createCreateTradingToFundingBatchInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
74
|
+
/** Moves to make, in order: 1 to 10. Legs may repeat an asset or a destination. */
|
|
75
|
+
readonly legs: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
|
|
76
|
+
readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
77
|
+
readonly quantity: v.StringSchema<undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* A Polyester Funding address, signed in the letter case given. Omit it
|
|
80
|
+
* to credit the source account's own Funding account; another account's
|
|
81
|
+
* address must be on the internal whitelist.
|
|
82
|
+
*/
|
|
83
|
+
readonly destinationAddress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
84
|
+
}, undefined>, undefined>, v.MinLengthAction<{
|
|
85
|
+
assetId: number;
|
|
86
|
+
quantity: string;
|
|
87
|
+
destinationAddress: string;
|
|
88
|
+
}[], 1, undefined>, v.MaxLengthAction<{
|
|
89
|
+
assetId: number;
|
|
90
|
+
quantity: string;
|
|
91
|
+
destinationAddress: string;
|
|
92
|
+
}[], 10, undefined>]>;
|
|
93
|
+
/** Scoped to the source account; 1 to 128 characters. */
|
|
94
|
+
readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 128, undefined>]>;
|
|
95
|
+
/**
|
|
96
|
+
* When the signed batch lapses, at most 15 minutes ahead. Defaults to five minutes
|
|
97
|
+
* from now on the device clock.
|
|
98
|
+
*/
|
|
99
|
+
readonly deadline: v.OptionalSchema<v.DateSchema<undefined>, undefined>;
|
|
100
|
+
readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
|
|
101
|
+
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
102
|
+
}, undefined>], undefined>, undefined>;
|
|
103
|
+
}, undefined>, v.TransformAction<{
|
|
104
|
+
legs: {
|
|
105
|
+
assetId: number;
|
|
106
|
+
quantity: string;
|
|
107
|
+
destinationAddress: string;
|
|
108
|
+
}[];
|
|
109
|
+
idempotencyKey: string;
|
|
110
|
+
deadline?: Date | undefined;
|
|
111
|
+
account?: "active" | "main" | {
|
|
112
|
+
subaccountId: string;
|
|
113
|
+
} | undefined;
|
|
114
|
+
}, {
|
|
115
|
+
subaccountId: bigint | undefined;
|
|
116
|
+
legs: {
|
|
117
|
+
assetId: number;
|
|
118
|
+
amountE18: bigint;
|
|
119
|
+
destinationAddress: string;
|
|
120
|
+
}[];
|
|
121
|
+
idempotencyKey: string;
|
|
122
|
+
deadlineTsSec: bigint;
|
|
123
|
+
nonce: bigint;
|
|
124
|
+
}>]>;
|
|
125
|
+
type CreateTradingToFundingBatchInput = v.InferInput<ReturnType<typeof createCreateTradingToFundingBatchInputSchema>>;
|
|
126
|
+
declare const CreateTradingToFundingBatchResultSchema: v.ObjectSchema<{
|
|
127
|
+
readonly batchId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
128
|
+
/** Every leg, in request order; follow each `intentId` like a single withdraw's. */
|
|
129
|
+
readonly legs: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
130
|
+
readonly legIndex: v.NumberSchema<undefined>;
|
|
131
|
+
readonly intentId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
132
|
+
readonly assetId: v.NumberSchema<undefined>;
|
|
133
|
+
readonly amountE18: v.OptionalSchema<v.ObjectSchema<{
|
|
134
|
+
readonly hi: v.BigintSchema<undefined>;
|
|
135
|
+
readonly lo: v.BigintSchema<undefined>;
|
|
136
|
+
}, undefined>, undefined>;
|
|
137
|
+
readonly destinationAddress: v.StringSchema<undefined>;
|
|
138
|
+
}, undefined>, v.TransformAction<{
|
|
139
|
+
legIndex: number;
|
|
140
|
+
intentId: string;
|
|
141
|
+
assetId: number;
|
|
142
|
+
amountE18?: {
|
|
143
|
+
hi: bigint;
|
|
144
|
+
lo: bigint;
|
|
145
|
+
} | undefined;
|
|
146
|
+
destinationAddress: string;
|
|
147
|
+
}, {
|
|
148
|
+
legIndex: number;
|
|
149
|
+
intentId: string;
|
|
150
|
+
assetId: number;
|
|
151
|
+
amount: string;
|
|
152
|
+
/** Empty when the leg credits the source account's own Funding account. */
|
|
153
|
+
destinationAddress: string;
|
|
154
|
+
}>]>, undefined>;
|
|
155
|
+
}, undefined>;
|
|
156
|
+
type CreateTradingToFundingBatchResult = v.InferOutput<typeof CreateTradingToFundingBatchResultSchema>;
|
|
73
157
|
type CreateTradingWithdrawToFundingInput = v.InferInput<ReturnType<typeof createCreateTradingWithdrawToFundingInputSchema>>;
|
|
74
158
|
type CreateTradingWithdrawToExternalChainInput = v.InferInput<ReturnType<typeof createCreateTradingWithdrawToExternalChainInputSchema>>;
|
|
75
159
|
declare const CreateTradingWithdrawResultSchema: v.ObjectSchema<{
|
|
@@ -175,5 +259,5 @@ declare const GetWalletBalancesResultSchema: v.ObjectSchema<{
|
|
|
175
259
|
*/
|
|
176
260
|
type GetWalletBalancesResult = v.InferOutput<typeof GetWalletBalancesResultSchema>;
|
|
177
261
|
//#endregion
|
|
178
|
-
export { CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, GetWalletBalancesResultSchema, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
|
|
262
|
+
export { CreateTradingToFundingBatchInput, CreateTradingToFundingBatchResult, CreateTradingToFundingBatchResultSchema, CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, GetWalletBalancesInput, GetWalletBalancesResult, GetWalletBalancesResultSchema, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingToFundingBatchInputSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema };
|
|
179
263
|
//# sourceMappingURL=trading-withdraws.schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KA0BY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;;iBAmDG,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAmChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CtF;
|
|
1
|
+
{"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KA0BY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS;;iBAmDG,gDAAgD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;GAmChF;iBAEe,sDAAsD,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CtF;iBAEe,6CAA6C,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmDlE,mCAAmC,EAAE,WAC7C,kBAAkB;cAGT,yCAAuC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwBxC,oCAAoC,EAAE,mBACvC;KAGC,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;;KAiBvC,mCAAmC,EAAE,kBACtC;cA4CE,yCAAuC,EAAA,aAAA,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAKxC,oCAAoC,EAAE,mBACvC;cAGL,iCAA+B,EAAA;;;;;KAOzB,yBAAyB,EAAE,kBAAkB;cAE5C,+BAA6B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwC9B,0BAA0B,EAAE,mBAAmB"}
|
|
@@ -106,6 +106,61 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
|
|
|
106
106
|
};
|
|
107
107
|
}));
|
|
108
108
|
}
|
|
109
|
+
function createCreateTradingToFundingBatchInputSchema(scales) {
|
|
110
|
+
return v.pipe(v.strictObject({
|
|
111
|
+
...AccountScopeInputEntries,
|
|
112
|
+
/** Moves to make, in order: 1 to 10. Legs may repeat an asset or a destination. */
|
|
113
|
+
legs: v.pipe(v.array(v.strictObject({
|
|
114
|
+
assetId: PositiveUint32InputSchema,
|
|
115
|
+
quantity: v.string(),
|
|
116
|
+
/**
|
|
117
|
+
* A Polyester Funding address, signed in the letter case given. Omit it
|
|
118
|
+
* to credit the source account's own Funding account; another account's
|
|
119
|
+
* address must be on the internal whitelist.
|
|
120
|
+
*/
|
|
121
|
+
destinationAddress: v.optional(v.pipe(v.string(), v.trim()), "")
|
|
122
|
+
})), v.minLength(1), v.maxLength(10)),
|
|
123
|
+
/** Scoped to the source account; 1 to 128 characters. */
|
|
124
|
+
idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(128)),
|
|
125
|
+
/**
|
|
126
|
+
* When the signed batch lapses, at most 15 minutes ahead. Defaults to five minutes
|
|
127
|
+
* from now on the device clock.
|
|
128
|
+
*/
|
|
129
|
+
deadline: v.optional(v.date())
|
|
130
|
+
}), v.transform((input) => ({
|
|
131
|
+
subaccountId: accountScopeToSubaccountId(input.account),
|
|
132
|
+
legs: input.legs.map((leg) => ({
|
|
133
|
+
assetId: leg.assetId,
|
|
134
|
+
amountE18: quantityInputToE18({
|
|
135
|
+
scales,
|
|
136
|
+
assetId: leg.assetId,
|
|
137
|
+
quantity: leg.quantity
|
|
138
|
+
}),
|
|
139
|
+
destinationAddress: leg.destinationAddress
|
|
140
|
+
})),
|
|
141
|
+
idempotencyKey: input.idempotencyKey,
|
|
142
|
+
deadlineTsSec: BigInt(input.deadline ? Math.floor(input.deadline.getTime() / 1e3) : Math.floor(Date.now() / 1e3) + DEFAULT_DEADLINE_SECONDS),
|
|
143
|
+
nonce: createNonce()
|
|
144
|
+
})));
|
|
145
|
+
}
|
|
146
|
+
const CreateTradingToFundingBatchResultSchema = v.object({
|
|
147
|
+
batchId: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
148
|
+
/** Every leg, in request order; follow each `intentId` like a single withdraw's. */
|
|
149
|
+
legs: v.array(v.pipe(v.object({
|
|
150
|
+
legIndex: v.number(),
|
|
151
|
+
intentId: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
152
|
+
assetId: v.number(),
|
|
153
|
+
amountE18: v.optional(U128Schema),
|
|
154
|
+
destinationAddress: v.string()
|
|
155
|
+
}), v.transform(({ amountE18, ...leg }) => ({
|
|
156
|
+
legIndex: leg.legIndex,
|
|
157
|
+
intentId: leg.intentId,
|
|
158
|
+
assetId: leg.assetId,
|
|
159
|
+
amount: scaledToDecimalOutput(fromU128(amountE18), 18),
|
|
160
|
+
/** Empty when the leg credits the source account's own Funding account. */
|
|
161
|
+
destinationAddress: leg.destinationAddress
|
|
162
|
+
}))))
|
|
163
|
+
});
|
|
109
164
|
const CreateTradingWithdrawResultSchema = v.object({ intentId: v.pipe(v.string(), v.trim(), v.minLength(1)) });
|
|
110
165
|
const CreateWalletTradingWithdrawResultSchema = CreateTradingWithdrawResultSchema;
|
|
111
166
|
const ValidateWithdrawDestinationInputSchema = v.pipe(v.strictObject({
|
|
@@ -170,6 +225,6 @@ const GetWalletBalancesResultSchema = v.object({
|
|
|
170
225
|
}))
|
|
171
226
|
});
|
|
172
227
|
//#endregion
|
|
173
|
-
export { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload };
|
|
228
|
+
export { CreateTradingToFundingBatchResultSchema, CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingToFundingBatchInputSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload };
|
|
174
229
|
|
|
175
230
|
//# sourceMappingURL=trading-withdraws.schemas.js.map
|