@polyester/sdk 0.36.0-devnet-20261114152753 → 0.36.0-devnet-20261115165158
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 +25 -1
- package/dist/catalogs/readers.d.ts.map +1 -1
- package/dist/catalogs/readers.js +1 -1
- package/dist/catalogs/readers.js.map +1 -1
- package/dist/catalogs/snapshot-validation.js +8 -6
- package/dist/catalogs/snapshot-validation.js.map +1 -1
- package/dist/catalogs/unknown-asset.d.ts.map +1 -1
- package/dist/catalogs/unknown-asset.js +4 -4
- package/dist/catalogs/unknown-asset.js.map +1 -1
- package/dist/core-client.d.ts.map +1 -1
- package/dist/core-client.js +2 -1
- package/dist/core-client.js.map +1 -1
- package/dist/realtime/private-orders.d.ts +8 -0
- package/dist/realtime/private-orders.d.ts.map +1 -1
- package/dist/realtime/private-orders.js +38 -5
- package/dist/realtime/private-orders.js.map +1 -1
- package/dist/services/address-book/address-book.schemas.d.ts.map +1 -1
- package/dist/services/address-book/address-book.schemas.js +4 -4
- package/dist/services/address-book/address-book.schemas.js.map +1 -1
- package/dist/services/assistant/assistant-events.schemas.d.ts +5 -5
- package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +19 -19
- package/dist/services/balances/balances.schemas.d.ts +6 -24
- package/dist/services/balances/balances.schemas.d.ts.map +1 -1
- package/dist/services/balances/balances.schemas.js +2 -2
- package/dist/services/balances/balances.schemas.js.map +1 -1
- 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/internal-transfers/internal-transfers.schemas.d.ts +3 -3
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +13 -13
- package/dist/services/orders/order-errors.schemas.d.ts +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts.map +1 -1
- package/dist/services/orders/order-errors.schemas.js +7 -4
- package/dist/services/orders/order-errors.schemas.js.map +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +13 -13
- package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-batch.schemas.js +3 -2
- package/dist/services/orders/orders-batch.schemas.js.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +3 -3
- package/dist/services/orders/orders-input.schemas.js +1 -1
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-modify.schemas.js +2 -1
- package/dist/services/orders/orders-modify.schemas.js.map +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-output.schemas.js +2 -10
- package/dist/services/orders/orders-output.schemas.js.map +1 -1
- package/dist/services/orders/orders.d.ts +6 -0
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +4 -0
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/price-alerts/price-alerts.schemas.d.ts +10 -10
- package/dist/services/rewards/rewards.schemas.d.ts +4 -4
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +4 -4
- 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/service.js +1 -1
- package/dist/services/trading-withdraws/service.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.d.ts +10 -12
- package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.js +28 -20
- package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts +0 -5
- package/dist/services/trading-withdraws/trading-withdraws.schemas.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js +0 -4
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js.map +1 -1
- package/dist/services/trading-withdraws/wallet-message.js +1 -1
- package/dist/services/trading-withdraws/wallet-message.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +4 -3
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +2 -3
- package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.js +1 -1
- package/dist/services/vip/vip.schemas.d.ts +3 -3
- package/dist/shared/transports.d.ts +2 -1
- package/dist/shared/transports.d.ts.map +1 -1
- package/dist/shared/transports.js +52 -9
- package/dist/shared/transports.js.map +1 -1
- package/dist/utils/base58-id.js +1 -1
- package/dist/utils/base58-id.js.map +1 -1
- package/dist/utils/numbers.js +3 -2
- package/dist/utils/numbers.js.map +1 -1
- package/package.json +1 -1
|
@@ -242,7 +242,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
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
244
|
readonly role: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer">]>;
|
|
245
|
-
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
245
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "accepted" | "canceled" | "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>;
|
|
@@ -269,7 +269,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
269
269
|
granteeAccountId: string;
|
|
270
270
|
inviterAccountId: string;
|
|
271
271
|
role: "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer";
|
|
272
|
-
status: "unspecified" | "
|
|
272
|
+
status: "unspecified" | "accepted" | "canceled" | "pending" | "declined";
|
|
273
273
|
createdAt?: number | undefined;
|
|
274
274
|
respondedAt?: number | undefined;
|
|
275
275
|
granteeUsername: string;
|
|
@@ -287,7 +287,7 @@ declare const SubaccountInviteSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<
|
|
|
287
287
|
granteeAccountId: string;
|
|
288
288
|
inviterAccountId: string;
|
|
289
289
|
role: "unspecified" | "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer";
|
|
290
|
-
status: "unspecified" | "
|
|
290
|
+
status: "unspecified" | "accepted" | "canceled" | "pending" | "declined";
|
|
291
291
|
createdAt?: number | undefined;
|
|
292
292
|
respondedAt?: number | undefined;
|
|
293
293
|
granteeUsername: string;
|
|
@@ -309,7 +309,7 @@ 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" | "
|
|
312
|
+
readonly entityKind: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "subaccount" | "api_key" | "account" | "destination" | "security" | "policy" | "session" | "member" | "invite">]>;
|
|
313
313
|
readonly eventAction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "disabled" | "revoked" | "removed" | "failed" | "applied" | "enabled" | "created" | "updated" | "deleted" | "role_set" | "received" | "replied" | "blocked" | "hold_placed" | "hold_released" | "requested">]>;
|
|
314
314
|
readonly source: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "api" | "web" | "mobile">]>;
|
|
315
315
|
readonly ip: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -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" | "completed" | "scheduled" | "in_progress")[] | 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" | "completed" | "scheduled" | "in_progress">]>;
|
|
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" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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" | "completed" | "scheduled" | "in_progress";
|
|
81
81
|
title: string;
|
|
82
82
|
message: string;
|
|
83
83
|
startTime?: number | undefined;
|
|
84
84
|
endTime?: number | undefined;
|
|
85
|
-
services: ("unspecified" | "
|
|
85
|
+
services: ("unspecified" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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" | "completed" | "scheduled" | "in_progress";
|
|
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" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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" | "completed" | "scheduled" | "in_progress">]>;
|
|
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" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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" | "completed" | "scheduled" | "in_progress";
|
|
183
183
|
title: string;
|
|
184
184
|
message: string;
|
|
185
185
|
startTime?: number | undefined;
|
|
186
186
|
endTime?: number | undefined;
|
|
187
|
-
services: ("unspecified" | "
|
|
187
|
+
services: ("unspecified" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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" | "completed" | "scheduled" | "in_progress";
|
|
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" | "deposits" | "withdrawals" | "transfers" | "trading" | "market_data" | "accounts" | "api" | "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.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.
|
|
172
|
+
}, undefined>], undefined>], ({ input }: v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | v.CheckIssue<bigint> | v.MaxValueIssue<number, 1000> | v.NeverIssue | v.UnionIssue<v.NumberIssue | v.BooleanIssue | v.IntegerIssue<number> | v.MinValueIssue<number, 1> | v.MaxValueIssue<number, 4294967295> | v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1> | v.UnionIssue<v.StringIssue | v.StrictObjectIssue | v.PicklistIssue | v.MinLengthIssue<string, 1>> | v.GtValueIssue<number, 0> | 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;
|
|
@@ -5,7 +5,7 @@ import { TradingWithdrawsService } from "./trading-withdraws.js";
|
|
|
5
5
|
const tradingWithdrawsService = defineService((context) => new TradingWithdrawsService(context.transports, context.resolver, {
|
|
6
6
|
chainId: context.environment.chain.id,
|
|
7
7
|
tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress
|
|
8
|
-
}, context.scales, context.catalog));
|
|
8
|
+
}, context.scales, context.catalog, context.auth));
|
|
9
9
|
//#endregion
|
|
10
10
|
export { tradingWithdrawsService };
|
|
11
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","names":[],"sources":["../../../src/services/trading-withdraws/service.ts"],"sourcesContent":["import { defineService } from \"../../core-client.js\";\nimport { TradingWithdrawsService } from \"./trading-withdraws.js\";\n\n/** Returns the client's TradingWithdrawsService, creating it on first use. */\nexport const tradingWithdrawsService = defineService(\n (context) =>\n new TradingWithdrawsService(\n context.transports,\n context.resolver,\n {\n chainId: context.environment.chain.id,\n tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress,\n },\n context.scales,\n context.catalog,\n ),\n);\n"],"mappings":";;;;AAIA,MAAa,0BAA0B,eAClC,YACG,IAAI,wBACA,QAAQ,YACR,QAAQ,UACR;CACI,SAAS,QAAQ,YAAY,MAAM;CACnC,uBAAuB,QAAQ,YAAY,UAAU;AACzD,GACA,QAAQ,QACR,QAAQ,
|
|
1
|
+
{"version":3,"file":"service.js","names":[],"sources":["../../../src/services/trading-withdraws/service.ts"],"sourcesContent":["import { defineService } from \"../../core-client.js\";\nimport { TradingWithdrawsService } from \"./trading-withdraws.js\";\n\n/** Returns the client's TradingWithdrawsService, creating it on first use. */\nexport const tradingWithdrawsService = defineService(\n (context) =>\n new TradingWithdrawsService(\n context.transports,\n context.resolver,\n {\n chainId: context.environment.chain.id,\n tradingGatewayAddress: context.environment.contracts.tradingGatewayAddress,\n },\n context.scales,\n context.catalog,\n context.auth,\n ),\n);\n"],"mappings":";;;;AAIA,MAAa,0BAA0B,eAClC,YACG,IAAI,wBACA,QAAQ,YACR,QAAQ,UACR;CACI,SAAS,QAAQ,YAAY,MAAM;CACnC,uBAAuB,QAAQ,YAAY,UAAU;AACzD,GACA,QAAQ,QACR,QAAQ,SACR,QAAQ,IACZ,CACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientCatalog } from "../../catalogs/types.js";
|
|
2
|
-
import { AuthApiTransports } from "../../shared/transports.js";
|
|
2
|
+
import { ApiKeyEd25519AuthProvider, AuthApiTransports, JwtAuthProvider } from "../../shared/transports.js";
|
|
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";
|
|
@@ -29,26 +29,24 @@ type PreparedTradingWithdraw = Readonly<{
|
|
|
29
29
|
/** When the backend stops accepting the currently signed request. */
|
|
30
30
|
deadline: Date;
|
|
31
31
|
/**
|
|
32
|
-
* True once the deadline is less than a minute away.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* cannot be signed again: prepare again (same input, same idempotency key) instead.
|
|
32
|
+
* True once the deadline is less than a minute away. The withdraw signs again on
|
|
33
|
+
* `submit` from then on, so callers can keep resubmitting the same prepared withdraw,
|
|
34
|
+
* e.g. after a slow MFA step-up.
|
|
36
35
|
*/
|
|
37
36
|
isExpired: () => boolean;
|
|
38
37
|
/**
|
|
39
38
|
* Submits the payload and signature produced during preparation. Repeated calls only
|
|
40
|
-
* change transport options such as the step-up token, unless the deadline is near:
|
|
41
|
-
*
|
|
42
|
-
* key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.
|
|
39
|
+
* change transport options such as the step-up token, unless the deadline is near: the
|
|
40
|
+
* withdraw then signs a fresh deadline and nonce with the same idempotency key.
|
|
43
41
|
*/
|
|
44
42
|
submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;
|
|
45
43
|
}>;
|
|
46
44
|
/**
|
|
47
|
-
* Creates durable Trading withdrawal intents
|
|
45
|
+
* Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).
|
|
48
46
|
*/
|
|
49
47
|
declare class TradingWithdrawsService {
|
|
50
48
|
#private;
|
|
51
|
-
constructor(transports: AuthApiTransports, resolver: SubaccountResolver | undefined, signingConfig: TradingWithdrawSigningConfig, scales: SdkScales, catalog?: ClientCatalog);
|
|
49
|
+
constructor(transports: AuthApiTransports, resolver: SubaccountResolver | undefined, signingConfig: TradingWithdrawSigningConfig, scales: SdkScales, catalog?: ClientCatalog, auth?: JwtAuthProvider | ApiKeyEd25519AuthProvider);
|
|
52
50
|
/**
|
|
53
51
|
* Reads the zTokens the account's smart account wallet holds on Polyester Chain, such as a
|
|
54
52
|
* rejected withdrawal's refund (see the lifecycle step's `refundAddress`), which stays there
|
|
@@ -60,7 +58,7 @@ declare class TradingWithdrawsService {
|
|
|
60
58
|
*/
|
|
61
59
|
validateDestination(input: ValidateWithdrawDestinationInput, options?: PolyesterRequestOptions): Promise<ValidateWithdrawDestinationResult>;
|
|
62
60
|
/**
|
|
63
|
-
* 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
|
|
61
|
+
* 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.
|
|
64
62
|
*/
|
|
65
63
|
createToFunding(input: CreateTradingWithdrawToFundingServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
|
|
66
64
|
/**
|
|
@@ -69,7 +67,7 @@ declare class TradingWithdrawsService {
|
|
|
69
67
|
*/
|
|
70
68
|
prepareToFunding(input: CreateTradingWithdrawToFundingServiceInput): Promise<PreparedTradingWithdraw>;
|
|
71
69
|
/**
|
|
72
|
-
* 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
|
|
70
|
+
* 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.
|
|
73
71
|
*/
|
|
74
72
|
createToExternalChain(input: CreateTradingWithdrawToExternalChainServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
|
|
75
73
|
/**
|
|
@@ -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":";;;;;;;;KA8CY;EACR;EACA;;;;;EAKA,cAAc,oBAAoB,QAAQ;;KAGlC;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0BAA0B;;EAElC,UAAU;;;;;;EAMV;;;;;;EAMA,SAAS,UAAU,6BAA6B,QAAQ;;;;;cAoG/C;;EAaL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU,eACV,OAAO,kBAAkB;;;;;;EAkBvB,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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
2
|
-
import {
|
|
1
|
+
import { TradingWithdrawIntentPayloadSchema, WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
2
|
+
import { ConfigurationError, ValidationError } from "../../shared/errors.js";
|
|
3
|
+
import { signApiKeyEd25519Payload } from "../../shared/transports.js";
|
|
3
4
|
import { checksumEvmAddress, evmHexToBytes } from "../../utils/evm.js";
|
|
4
5
|
import { parse } from "../../shared/validation.js";
|
|
5
6
|
import { removeUndefined } from "../../utils/remove-undefined.js";
|
|
@@ -8,6 +9,7 @@ import { idToBigInt } from "../../utils/base58-id.js";
|
|
|
8
9
|
import { resolveAccountScopedInput } from "../subaccount-resolver.js";
|
|
9
10
|
import { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, GetWalletBalancesInputSchema, GetWalletBalancesResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema, renewTradingWithdrawPayload } from "./trading-withdraws.schemas.js";
|
|
10
11
|
import { buildTradingWithdrawWalletMessage } from "./wallet-message.js";
|
|
12
|
+
import { create, toBinary } from "@bufbuild/protobuf";
|
|
11
13
|
import { createClient } from "@connectrpc/connect";
|
|
12
14
|
//#region src/services/trading-withdraws/trading-withdraws.ts
|
|
13
15
|
const PREPARED_WITHDRAW_EXPIRY_MARGIN_MS = 6e4;
|
|
@@ -23,8 +25,7 @@ function preparedWithdraw(signed, resign) {
|
|
|
23
25
|
},
|
|
24
26
|
isExpired,
|
|
25
27
|
submit: async (options) => {
|
|
26
|
-
if (
|
|
27
|
-
else if (Date.now() >= deadlineMs(current.payload)) throw new WithdrawDeadlineExpiredError("Withdraw signature deadline has passed. Prepare the withdraw again.");
|
|
28
|
+
if (isExpired()) current = await resign(renewTradingWithdrawPayload(current.payload));
|
|
28
29
|
return current.send(options);
|
|
29
30
|
}
|
|
30
31
|
};
|
|
@@ -64,7 +65,7 @@ async function resolveWalletSignature(params) {
|
|
|
64
65
|
};
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* Creates durable Trading withdrawal intents
|
|
68
|
+
* Creates durable Trading withdrawal intents, signed by the client's API key or a wallet (EIP-191).
|
|
68
69
|
*/
|
|
69
70
|
var TradingWithdrawsService = class {
|
|
70
71
|
#client;
|
|
@@ -72,10 +73,12 @@ var TradingWithdrawsService = class {
|
|
|
72
73
|
#signingConfig;
|
|
73
74
|
#catalog;
|
|
74
75
|
#scales;
|
|
76
|
+
#auth;
|
|
75
77
|
#toFundingInputSchema;
|
|
76
78
|
#toExternalChainInputSchema;
|
|
77
|
-
constructor(transports, resolver, signingConfig, scales, catalog) {
|
|
79
|
+
constructor(transports, resolver, signingConfig, scales, catalog, auth) {
|
|
78
80
|
this.#client = createClient(WithdrawService, transports.authApi);
|
|
81
|
+
this.#auth = auth;
|
|
79
82
|
this.#resolver = resolver;
|
|
80
83
|
this.#signingConfig = signingConfig;
|
|
81
84
|
this.#catalog = catalog;
|
|
@@ -102,7 +105,7 @@ var TradingWithdrawsService = class {
|
|
|
102
105
|
return parse(ValidateWithdrawDestinationResultSchema, response);
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
|
-
* 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
|
|
108
|
+
* 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.
|
|
106
109
|
*/
|
|
107
110
|
async createToFunding(input, options) {
|
|
108
111
|
return (await this.prepareToFunding(input)).submit(options);
|
|
@@ -119,7 +122,7 @@ var TradingWithdrawsService = class {
|
|
|
119
122
|
return this.#prepareWithdraw(validated, walletSigner);
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
122
|
-
* 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
|
|
125
|
+
* 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.
|
|
123
126
|
*/
|
|
124
127
|
async createToExternalChain(input, options) {
|
|
125
128
|
return (await this.prepareToExternalChain(input)).submit(options);
|
|
@@ -168,18 +171,23 @@ var TradingWithdrawsService = class {
|
|
|
168
171
|
};
|
|
169
172
|
return preparedWithdraw(await sign(validated.payload), sign);
|
|
170
173
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
174
|
+
const auth = this.#auth;
|
|
175
|
+
if (auth?.kind !== "api-key-ed25519") throw new ConfigurationError("Trading withdraw requires a wallet signer or API-key auth.");
|
|
176
|
+
if (validated.subaccountId !== void 0) throw new ValidationError("API-key trading withdraws cannot target a subaccount. Use `account: \"main\"` or a wallet signer.");
|
|
177
|
+
const sign = async (payload) => {
|
|
178
|
+
const payloadSignature = await signApiKeyEd25519Payload(auth, toBinary(TradingWithdrawIntentPayloadSchema, create(TradingWithdrawIntentPayloadSchema, payload)));
|
|
179
|
+
return {
|
|
180
|
+
payload,
|
|
181
|
+
send: async (options) => {
|
|
182
|
+
const response = await this.#client.createTradingWithdraw({
|
|
183
|
+
payload,
|
|
184
|
+
payloadSignature
|
|
185
|
+
}, toConnectCallOptions(options));
|
|
186
|
+
return parse(CreateTradingWithdrawResultSchema, response);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
return preparedWithdraw(await sign(validated.payload), sign);
|
|
183
191
|
}
|
|
184
192
|
};
|
|
185
193
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.js","names":["#client","Proto.WithdrawService","#resolver","#signingConfig","#catalog","#scales","#toFundingInputSchema","#toExternalChainInputSchema","#prepareWithdraw"],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"sourcesContent":["import { ValidationError, WithdrawDeadlineExpiredError } from \"../../shared/errors.js\";\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 type { AuthApiTransports } 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. Wallet-signed\n * withdraws sign again on `submit` from then on, so callers can keep resubmitting the\n * same prepared withdraw, e.g. after a slow MFA step-up. Payload-signed withdraws\n * cannot be signed again: prepare again (same input, same idempotency key) instead.\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:\n * wallet-signed withdraws then sign a fresh deadline and nonce with the same idempotency\n * key, and payload-signed withdraws throw `WithdrawDeadlineExpiredError` once it passes.\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 (resign && isExpired()) {\n current = await resign(renewTradingWithdrawPayload(current.payload));\n } else if (Date.now() >= deadlineMs(current.payload)) {\n throw new WithdrawDeadlineExpiredError(\n \"Withdraw signature deadline has passed. Prepare the withdraw again.\",\n );\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 to Funding using API signatures or wallet EIP-191 signatures.\n */\nexport class TradingWithdrawsService {\n #client: Client<typeof Proto.WithdrawService>;\n #resolver?: SubaccountResolver;\n #signingConfig: TradingWithdrawSigningConfig;\n #catalog?: ClientCatalog;\n #scales: SdkScales;\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 ) {\n this.#client = createClient(Proto.WithdrawService, transports.authApi);\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. 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 a payload signature is required for the backend-authorized 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 a payload signature is required for the backend-authorized 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 if (!validated.payloadSignature) {\n throw new ValidationError(\n \"Trading withdraw requires a wallet signer or payload signature.\",\n );\n }\n\n const request = removeUndefined({\n payload: validated.payload,\n payloadSignature: validated.payloadSignature,\n });\n return preparedWithdraw({\n payload: validated.payload,\n send: async (options) => {\n const response = await this.#client.createTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateTradingWithdrawResultSchema, response);\n },\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyFA,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,UAAU,GACpB,UAAU,MAAM,OAAO,4BAA4B,QAAQ,OAAO,CAAC;QAChE,IAAI,KAAK,IAAI,KAAK,WAAW,QAAQ,OAAO,GAC/C,MAAM,IAAI,6BACN,qEACJ;GAEJ,OAAO,QAAQ,KAAK,O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AsC;IAC1D,cAAc,UAAU;IACxB,eAAe,aAAa;GAChC,CAAC;GACD,MAAM,OAAO,OACT,YACiC;IACjC,MAAM,kBAAkB,MAAM,uBAAuB;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,KAAKJ,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,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,iBAAiB;GACpB,SAAS,UAAU;GACnB,MAAM,OAAO,YAAY;IACrB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;IACA,OAAO,MAAM,mCAAmC,QAAQ;GAC5D;EACJ,CAAC;CACL;AACJ"}
|
|
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. 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,KAA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AO,GAAG,IAAI;CAC/D;AACJ"}
|
|
@@ -16,7 +16,6 @@ type TradingWithdrawIntentPayloadRequest = {
|
|
|
16
16
|
type CreateTradingWithdrawRequestBase = {
|
|
17
17
|
subaccountId: bigint | undefined;
|
|
18
18
|
payload: TradingWithdrawIntentPayloadRequest;
|
|
19
|
-
payloadSignature?: Uint8Array;
|
|
20
19
|
};
|
|
21
20
|
declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
22
21
|
readonly assetId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
@@ -24,7 +23,6 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
|
|
|
24
23
|
readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
25
24
|
readonly destinationAddress: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
26
25
|
readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
27
|
-
readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
|
|
28
26
|
/**
|
|
29
27
|
* When the signed authorization lapses. Defaults to five minutes from now
|
|
30
28
|
* on the device clock.
|
|
@@ -39,7 +37,6 @@ declare function createCreateTradingWithdrawToFundingInputSchema(scales: SdkScal
|
|
|
39
37
|
idempotencyKey: string;
|
|
40
38
|
destinationAddress: string;
|
|
41
39
|
signerWallet: string;
|
|
42
|
-
payloadSignature?: Uint8Array<ArrayBuffer> | undefined;
|
|
43
40
|
deadline?: Date | undefined;
|
|
44
41
|
account?: "active" | "main" | {
|
|
45
42
|
subaccountId: string;
|
|
@@ -52,7 +49,6 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
|
|
|
52
49
|
readonly destinationAddress: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
53
50
|
readonly idempotencyKey: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
54
51
|
readonly signerWallet: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
55
|
-
readonly payloadSignature: v.OptionalSchema<v.InstanceSchema<Uint8ArrayConstructor, undefined>, undefined>;
|
|
56
52
|
/**
|
|
57
53
|
* When the signed authorization lapses. Defaults to five minutes from now
|
|
58
54
|
* on the device clock.
|
|
@@ -68,7 +64,6 @@ declare function createCreateTradingWithdrawToExternalChainInputSchema(scales: S
|
|
|
68
64
|
destinationAddress: string;
|
|
69
65
|
idempotencyKey: string;
|
|
70
66
|
signerWallet: string;
|
|
71
|
-
payloadSignature?: Uint8Array<ArrayBuffer> | undefined;
|
|
72
67
|
deadline?: Date | undefined;
|
|
73
68
|
account?: "active" | "main" | {
|
|
74
69
|
subaccountId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAwBY;EACR,QAAQ;EACR;EACA;EACA,WAAW;EACX;EACA,OAAO;EACP;EACA;;KAGC;EACD;EACA,SAAS
|
|
1
|
+
{"version":3,"file":"trading-withdraws.schemas.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.schemas.ts"],"mappings":";;;;;KAwBY;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;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCtF;KAEW,sCAAsC,EAAE,WAChD,kBAAkB;KAOV,4CAA4C,EAAE,WACtD,kBAAkB;cAOT,mCAAiC,EAAA;;;KAIlC,8BAA8B,EAAE,mBAAmB;cAOlD,wCAAsC,EAAA,yBAAA,EAAA;;;;;;;;;;KAgBvC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAyB9B,0BAA0B,EAAE,mBAAmB"}
|
|
@@ -45,7 +45,6 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
|
|
|
45
45
|
idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
46
46
|
destinationAddress: v.optional(v.pipe(v.string(), v.trim()), ""),
|
|
47
47
|
signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
|
|
48
|
-
payloadSignature: v.optional(v.instance(Uint8Array)),
|
|
49
48
|
/**
|
|
50
49
|
* When the signed authorization lapses. Defaults to five minutes from now
|
|
51
50
|
* on the device clock.
|
|
@@ -59,7 +58,6 @@ function createCreateTradingWithdrawToFundingInputSchema(scales) {
|
|
|
59
58
|
});
|
|
60
59
|
return {
|
|
61
60
|
subaccountId: accountScopeToSubaccountId(input.account),
|
|
62
|
-
payloadSignature: input.payloadSignature,
|
|
63
61
|
payload: createTradingWithdrawPayload({
|
|
64
62
|
action: TradingWithdrawActionCodec.inputToProto.to_funding,
|
|
65
63
|
assetId: input.assetId,
|
|
@@ -81,7 +79,6 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
|
|
|
81
79
|
destinationAddress: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
82
80
|
idempotencyKey: v.pipe(v.string(), v.trim(), v.minLength(1)),
|
|
83
81
|
signerWallet: v.optional(v.pipe(v.string(), v.trim()), ""),
|
|
84
|
-
payloadSignature: v.optional(v.instance(Uint8Array)),
|
|
85
82
|
/**
|
|
86
83
|
* When the signed authorization lapses. Defaults to five minutes from now
|
|
87
84
|
* on the device clock.
|
|
@@ -95,7 +92,6 @@ function createCreateTradingWithdrawToExternalChainInputSchema(scales) {
|
|
|
95
92
|
});
|
|
96
93
|
return {
|
|
97
94
|
subaccountId: accountScopeToSubaccountId(input.account),
|
|
98
|
-
payloadSignature: input.payloadSignature,
|
|
99
95
|
payload: createTradingWithdrawPayload({
|
|
100
96
|
action: TradingWithdrawActionCodec.inputToProto.to_external_chain,
|
|
101
97
|
assetId: input.assetId,
|