@polyester/sdk 0.22.2 → 0.23.0
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 +14 -0
- package/dist/account-signer/types.d.ts +1 -1
- package/dist/account-signer/types.js.map +1 -1
- package/dist/environment.js +1 -1
- package/dist/environment.js.map +1 -1
- package/dist/gen/auth/v1/auth_pb.d.ts +88 -46
- package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/auth_pb.js +43 -11
- package/dist/gen/auth/v1/auth_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +5 -17
- package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +2 -2
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +2 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/services/auth/account-signer-auth.d.ts +7 -3
- package/dist/services/auth/account-signer-auth.d.ts.map +1 -1
- package/dist/services/auth/account-signer-auth.js +28 -13
- package/dist/services/auth/account-signer-auth.js.map +1 -1
- package/dist/services/auth/auth.d.ts +19 -14
- package/dist/services/auth/auth.d.ts.map +1 -1
- package/dist/services/auth/auth.js +24 -14
- package/dist/services/auth/auth.js.map +1 -1
- package/dist/services/auth/auth.types.d.ts +2 -2
- package/dist/services/auth/wallet-challenge.schemas.js +20 -0
- package/dist/services/auth/wallet-challenge.schemas.js.map +1 -0
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/heatmap/heatmap.schemas.d.ts +9 -9
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +42 -42
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/orders/orders-batch.schemas.d.ts +14 -14
- package/dist/services/orders/orders-input.schemas.d.ts +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +12 -12
- package/dist/services/subaccounts/subaccounts.d.ts +1 -1
- package/dist/services/subaccounts/subaccounts.js +1 -1
- package/dist/services/subaccounts/subaccounts.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +7 -9
- package/dist/services/subaccounts/subaccounts.schemas.d.ts.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.js +4 -5
- package/dist/services/subaccounts/subaccounts.schemas.js.map +1 -1
- package/dist/services/trading-withdraws/index.d.ts +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.d.ts +10 -72
- package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.js +8 -84
- package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.types.d.ts +2 -2
- package/dist/services/trading-withdraws/wallet-message.js +43 -0
- package/dist/services/trading-withdraws/wallet-message.js.map +1 -0
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/triggers-output.schemas.d.ts +18 -18
- package/package.json +2 -1
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { ValidationError } from "../../shared/errors.js";
|
|
2
2
|
import { WithdrawService } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
3
3
|
import { idToBigInt } from "../../utils/base58-id.js";
|
|
4
|
-
import { checksumEvmAddress, evmHexToBytes
|
|
4
|
+
import { checksumEvmAddress, evmHexToBytes } from "../../utils/evm.js";
|
|
5
5
|
import { parse } from "../../shared/validation.js";
|
|
6
6
|
import { toConnectCallOptions } from "../../shared/request-options.js";
|
|
7
7
|
import { removeUndefined } from "../../utils/remove-undefined.js";
|
|
8
8
|
import { resolveAccountScopedInput } from "../subaccount-resolver.js";
|
|
9
9
|
import { CreateTradingWithdrawResultSchema, CreateWalletTradingWithdrawResultSchema, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema } from "./trading-withdraws.schemas.js";
|
|
10
|
+
import { buildTradingWithdrawWalletMessage } from "./wallet-message.js";
|
|
10
11
|
import { createClient } from "@connectrpc/connect";
|
|
11
12
|
//#region src/services/trading-withdraws/trading-withdraws.ts
|
|
12
|
-
function fromU128(value) {
|
|
13
|
-
if (!value) return 0n;
|
|
14
|
-
return (value.hi << 64n) + value.lo;
|
|
15
|
-
}
|
|
16
13
|
function resolveTradingWithdrawTargetAccountId(params) {
|
|
17
14
|
if (params.subaccountId !== void 0) return params.subaccountId;
|
|
18
15
|
return idToBigInt(params.rootAccountId, "targetAccountId");
|
|
@@ -31,97 +28,24 @@ async function resolveTradingWithdrawSigningConfig(params) {
|
|
|
31
28
|
return params.fallback;
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
function buildTradingWithdrawWalletTypedData(params) {
|
|
35
|
-
const payload = params.payload;
|
|
36
|
-
const destinationAddress = (payload.destinationAddress ?? "").trim();
|
|
37
|
-
const idempotencyKey = payload.idempotencyKey.trim();
|
|
38
|
-
return {
|
|
39
|
-
domain: {
|
|
40
|
-
name: "Polyester Trading Withdraw",
|
|
41
|
-
version: "1",
|
|
42
|
-
chainId: params.signingConfig.chainId,
|
|
43
|
-
verifyingContract: params.signingConfig.tradingGatewayAddress
|
|
44
|
-
},
|
|
45
|
-
types: { WalletTradingWithdraw: [
|
|
46
|
-
{
|
|
47
|
-
name: "signerWallet",
|
|
48
|
-
type: "address"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "actionType",
|
|
52
|
-
type: "uint8"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "accountId",
|
|
56
|
-
type: "uint64"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "targetAccountId",
|
|
60
|
-
type: "uint64"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: "assetId",
|
|
64
|
-
type: "uint32"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "destinationChainId",
|
|
68
|
-
type: "uint64"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: "amountQ",
|
|
72
|
-
type: "uint128"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "destinationHash",
|
|
76
|
-
type: "bytes32"
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: "deadlineTsSec",
|
|
80
|
-
type: "uint256"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "nonce",
|
|
84
|
-
type: "uint128"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "idempotencyKeyHash",
|
|
88
|
-
type: "bytes32"
|
|
89
|
-
}
|
|
90
|
-
] },
|
|
91
|
-
primaryType: "WalletTradingWithdraw",
|
|
92
|
-
message: {
|
|
93
|
-
signerWallet: params.signerWallet,
|
|
94
|
-
actionType: payload.action,
|
|
95
|
-
accountId: params.accountId,
|
|
96
|
-
targetAccountId: params.targetAccountId,
|
|
97
|
-
assetId: payload.assetId,
|
|
98
|
-
destinationChainId: payload.destinationChainId ?? 0n,
|
|
99
|
-
amountQ: fromU128(payload.amountE18),
|
|
100
|
-
destinationHash: keccak256Hex(evmUtf8ToBytes(destinationAddress)),
|
|
101
|
-
deadlineTsSec: payload.deadlineTsSec,
|
|
102
|
-
nonce: fromU128(payload.nonce),
|
|
103
|
-
idempotencyKeyHash: keccak256Hex(evmUtf8ToBytes(idempotencyKey))
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
31
|
async function resolveWalletSignature(params) {
|
|
108
|
-
const signerWallet = params.walletSigner.signerWallet.trim();
|
|
109
|
-
if (!signerWallet.startsWith("0x")) throw new ValidationError("Trading withdraw signer wallet is required.");
|
|
32
|
+
const signerWallet = params.walletSigner.signerWallet.trim().toLowerCase();
|
|
110
33
|
const accountId = idToBigInt(params.walletSigner.accountId, "accountId");
|
|
111
|
-
const signature = await params.walletSigner.
|
|
34
|
+
const signature = await params.walletSigner.signMessage(buildTradingWithdrawWalletMessage({
|
|
112
35
|
signingConfig: params.signingConfig,
|
|
113
36
|
payload: params.payload,
|
|
114
37
|
signerWallet,
|
|
115
38
|
accountId,
|
|
116
39
|
targetAccountId: params.targetAccountId
|
|
117
40
|
}));
|
|
41
|
+
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.");
|
|
118
42
|
return {
|
|
119
43
|
signerWallet,
|
|
120
44
|
payloadSignature: evmHexToBytes(signature)
|
|
121
45
|
};
|
|
122
46
|
}
|
|
123
47
|
/**
|
|
124
|
-
* Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-
|
|
48
|
+
* Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.
|
|
125
49
|
*/
|
|
126
50
|
var TradingWithdrawsService = class {
|
|
127
51
|
#client;
|
|
@@ -149,7 +73,7 @@ var TradingWithdrawsService = class {
|
|
|
149
73
|
return parse(ValidateWithdrawDestinationResultSchema, response);
|
|
150
74
|
}
|
|
151
75
|
/**
|
|
152
|
-
* 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 EIP-
|
|
76
|
+
* 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.
|
|
153
77
|
*/
|
|
154
78
|
async createToFunding(input, options) {
|
|
155
79
|
return (await this.prepareToFunding(input)).submit(options);
|
|
@@ -166,7 +90,7 @@ var TradingWithdrawsService = class {
|
|
|
166
90
|
return this.#prepareWithdraw(validated, walletSigner);
|
|
167
91
|
}
|
|
168
92
|
/**
|
|
169
|
-
* 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 EIP-
|
|
93
|
+
* 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.
|
|
170
94
|
*/
|
|
171
95
|
async createToExternalChain(input, options) {
|
|
172
96
|
return (await this.prepareToExternalChain(input)).submit(options);
|
|
@@ -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 } from \"../../shared/errors.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport type { Address, Hex } from \"viem\";\nimport {\n checksumEvmAddress,\n evmHexToBytes,\n evmUtf8ToBytes,\n keccak256Hex,\n} 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 ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\n type TradingWithdrawIntentPayloadRequest,\n type ValidateWithdrawDestinationInput,\n type ValidateWithdrawDestinationResult,\n} from \"./trading-withdraws.schemas.js\";\n\nexport type TradingWithdrawWalletTypedData = ReturnType<typeof buildTradingWithdrawWalletTypedData>;\n\nexport type TradingWithdrawWalletSigner = {\n signerWallet: string;\n accountId: string;\n signTypedData: (typedData: TradingWithdrawWalletTypedData) => 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 /**\n * Submits the exact payload and signature produced during preparation.\n * Repeated calls only change transport options such as the step-up token.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\n}>;\n\ntype TradingWithdrawRequest =\n | CreateTradingWithdrawToFundingRequest\n | CreateTradingWithdrawToExternalChainRequest;\n\nfunction fromU128(value: TradingWithdrawIntentPayloadRequest[\"amountE18\"] | undefined): bigint {\n if (!value) return 0n;\n return (value.hi << 64n) + value.lo;\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\nfunction buildTradingWithdrawWalletTypedData(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: Address;\n accountId: bigint;\n targetAccountId: bigint;\n}) {\n const payload = params.payload;\n const destinationAddress = (payload.destinationAddress ?? \"\").trim();\n const idempotencyKey = payload.idempotencyKey.trim();\n\n return {\n domain: {\n name: \"Polyester Trading Withdraw\",\n version: \"1\",\n chainId: params.signingConfig.chainId,\n verifyingContract: params.signingConfig.tradingGatewayAddress,\n },\n types: {\n WalletTradingWithdraw: [\n { name: \"signerWallet\", type: \"address\" },\n { name: \"actionType\", type: \"uint8\" },\n { name: \"accountId\", type: \"uint64\" },\n { name: \"targetAccountId\", type: \"uint64\" },\n { name: \"assetId\", type: \"uint32\" },\n { name: \"destinationChainId\", type: \"uint64\" },\n { name: \"amountQ\", type: \"uint128\" },\n { name: \"destinationHash\", type: \"bytes32\" },\n { name: \"deadlineTsSec\", type: \"uint256\" },\n { name: \"nonce\", type: \"uint128\" },\n { name: \"idempotencyKeyHash\", type: \"bytes32\" },\n ],\n },\n primaryType: \"WalletTradingWithdraw\",\n message: {\n signerWallet: params.signerWallet,\n actionType: payload.action,\n accountId: params.accountId,\n targetAccountId: params.targetAccountId,\n assetId: payload.assetId,\n destinationChainId: payload.destinationChainId ?? 0n,\n amountQ: fromU128(payload.amountE18),\n destinationHash: keccak256Hex(evmUtf8ToBytes(destinationAddress)),\n deadlineTsSec: payload.deadlineTsSec,\n nonce: fromU128(payload.nonce),\n idempotencyKeyHash: keccak256Hex(evmUtf8ToBytes(idempotencyKey)),\n },\n } as const;\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();\n if (!signerWallet.startsWith(\"0x\")) {\n throw new ValidationError(\"Trading withdraw signer wallet is required.\");\n }\n const accountId = idToBigInt(params.walletSigner.accountId, \"accountId\");\n const signature = await params.walletSigner.signTypedData(\n buildTradingWithdrawWalletTypedData({\n signingConfig: params.signingConfig,\n payload: params.payload,\n signerWallet: signerWallet as Address,\n accountId,\n targetAccountId: params.targetAccountId,\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-712 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 * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one.\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 EIP-712 typed data 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 EIP-712 typed data 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\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload: validated.payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload: validated.payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n submit: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\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 {\n submit: 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":";;;;;;;;;;;AAyEA,SAAS,SAAS,OAA6E;CAC3F,IAAI,CAAC,OAAO,OAAO;CACnB,QAAQ,MAAM,MAAM,OAAO,MAAM;AACrC;AAEA,SAAS,sCAAsC,QAGpC;CACP,IAAI,OAAO,iBAAiB,KAAA,GAAW,OAAO,OAAO;CACrD,OAA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AAY;GACvB,MAAM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;GACA,OAAO,MAAM,mCAAmC,QAAQ;EAC5D,EACJ;CACJ;AACJ"}
|
|
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 } 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 ValidateWithdrawDestinationInputSchema,\n ValidateWithdrawDestinationResultSchema,\n type CreateTradingWithdrawResult,\n type CreateTradingWithdrawToExternalChainInput,\n type CreateTradingWithdrawToExternalChainRequest,\n type CreateTradingWithdrawToFundingInput,\n type CreateTradingWithdrawToFundingRequest,\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 /**\n * Submits the exact payload and signature produced during preparation.\n * Repeated calls only change transport options such as the step-up token.\n */\n submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;\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 * Checks whether an external-chain destination can receive a withdrawal without creating, signing, or reserving one.\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\n const walletSignature = await resolveWalletSignature({\n signingConfig,\n payload: validated.payload,\n walletSigner,\n targetAccountId,\n });\n const request = removeUndefined({\n payload: validated.payload,\n subaccountId: validated.subaccountId,\n signerWallet: walletSignature.signerWallet,\n payloadSignature: walletSignature.payloadSignature,\n });\n return {\n submit: async (options) => {\n const response = await this.#client.createWalletTradingWithdraw(\n request,\n toConnectCallOptions(options),\n );\n return parse(CreateWalletTradingWithdrawResultSchema, response);\n },\n };\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 {\n submit: 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":";;;;;;;;;;;;AAuEA,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,OAAO,QAAQ,OAAO,kBAAkB,gBAClC,CAAC,EAAE,SAAS,KAAK;EACvC,IAAI,CAA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AM,WAAW,MAAM,KAAKA,QAAQ,sBAChC,SACA,qBAAqB,OAAO,CAChC;GACA,OAAO,MAAM,mCAAmC,QAAQ;EAC5D,EACJ;CACJ;AACJ"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
|
|
2
|
-
import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner
|
|
3
|
-
export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner,
|
|
2
|
+
import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner } from "./trading-withdraws.js";
|
|
3
|
+
export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ValidationError } from "../../shared/errors.js";
|
|
2
|
+
import "../../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
3
|
+
import { isEvmAddress } from "../../utils/evm.js";
|
|
4
|
+
//#region src/services/trading-withdraws/wallet-message.ts
|
|
5
|
+
function messageAddress(value, field) {
|
|
6
|
+
const address = value.trim();
|
|
7
|
+
if (!isEvmAddress(address)) throw new ValidationError(`Trading withdraw ${field} must be a valid EVM address.`);
|
|
8
|
+
return address.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
function messageText(value, field) {
|
|
11
|
+
const text = value.trim();
|
|
12
|
+
if (/[\p{Cc}\p{Cs}]/u.test(text)) throw new ValidationError(`Trading withdraw ${field} must be valid UTF-8 without control characters.`);
|
|
13
|
+
return text;
|
|
14
|
+
}
|
|
15
|
+
function buildTradingWithdrawWalletMessage(params) {
|
|
16
|
+
const { payload, signingConfig } = params;
|
|
17
|
+
if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) throw new ValidationError("Trading withdraw chain ID must be a positive safe integer.");
|
|
18
|
+
const action = payload.action === 1 ? "TO_FUNDING" : payload.action === 2 ? "TO_EXTERNAL_CHAIN" : void 0;
|
|
19
|
+
if (!action) throw new ValidationError("Invalid trading withdraw action.");
|
|
20
|
+
return [
|
|
21
|
+
"Polyester Trading Withdrawal",
|
|
22
|
+
"",
|
|
23
|
+
"Version: 1",
|
|
24
|
+
"Environment: polyester",
|
|
25
|
+
`Action: ${action}`,
|
|
26
|
+
`Signer Wallet: ${messageAddress(params.signerWallet, "signer wallet")}`,
|
|
27
|
+
`Account ID: ${params.accountId}`,
|
|
28
|
+
`Target Account ID: ${params.targetAccountId}`,
|
|
29
|
+
`Asset ID: ${payload.assetId}`,
|
|
30
|
+
`Polyester Chain ID: ${signingConfig.chainId}`,
|
|
31
|
+
`Destination Chain ID: ${payload.destinationChainId}`,
|
|
32
|
+
`Amount E18: ${(payload.amountE18.hi << 64n) + payload.amountE18.lo}`,
|
|
33
|
+
`Destination: ${messageText(payload.destinationAddress, "destination")}`,
|
|
34
|
+
`Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, "verifying contract")}`,
|
|
35
|
+
`Deadline: ${payload.deadlineTsSec}`,
|
|
36
|
+
`Nonce: ${(payload.nonce.hi << 64n) + payload.nonce.lo}`,
|
|
37
|
+
`Idempotency Key: ${messageText(payload.idempotencyKey, "idempotency key")}`
|
|
38
|
+
].join("\n");
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { buildTradingWithdrawWalletMessage };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=wallet-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-message.js","names":[],"sources":["../../../src/services/trading-withdraws/wallet-message.ts"],"sourcesContent":["import { TradingWithdrawAction } from \"../../gen/chain/withdraw/v1/withdraw_pb.js\";\nimport { ValidationError } from \"../../shared/errors.js\";\nimport { isEvmAddress } from \"../../utils/evm.js\";\nimport type { TradingWithdrawIntentPayloadRequest } from \"./trading-withdraws.schemas.js\";\nimport type { TradingWithdrawSigningConfig } from \"./trading-withdraws.js\";\n\nfunction messageAddress(value: string, field: string): string {\n const address = value.trim();\n if (!isEvmAddress(address)) {\n throw new ValidationError(`Trading withdraw ${field} must be a valid EVM address.`);\n }\n return address.toLowerCase();\n}\n\nfunction messageText(value: string, field: string): string {\n const text = value.trim();\n if (/[\\p{Cc}\\p{Cs}]/u.test(text)) {\n throw new ValidationError(\n `Trading withdraw ${field} must be valid UTF-8 without control characters.`,\n );\n }\n return text;\n}\n\nexport function buildTradingWithdrawWalletMessage(params: {\n signingConfig: TradingWithdrawSigningConfig;\n payload: TradingWithdrawIntentPayloadRequest;\n signerWallet: string;\n accountId: bigint;\n targetAccountId: bigint;\n}): string {\n const { payload, signingConfig } = params;\n if (!Number.isSafeInteger(signingConfig.chainId) || signingConfig.chainId <= 0) {\n throw new ValidationError(\"Trading withdraw chain ID must be a positive safe integer.\");\n }\n const action =\n payload.action === TradingWithdrawAction.TO_FUNDING\n ? \"TO_FUNDING\"\n : payload.action === TradingWithdrawAction.TO_EXTERNAL_CHAIN\n ? \"TO_EXTERNAL_CHAIN\"\n : undefined;\n if (!action) throw new ValidationError(\"Invalid trading withdraw action.\");\n\n return [\n \"Polyester Trading Withdrawal\",\n \"\",\n \"Version: 1\",\n \"Environment: polyester\",\n `Action: ${action}`,\n `Signer Wallet: ${messageAddress(params.signerWallet, \"signer wallet\")}`,\n `Account ID: ${params.accountId}`,\n `Target Account ID: ${params.targetAccountId}`,\n `Asset ID: ${payload.assetId}`,\n `Polyester Chain ID: ${signingConfig.chainId}`,\n `Destination Chain ID: ${payload.destinationChainId}`,\n `Amount E18: ${(payload.amountE18.hi << 64n) + payload.amountE18.lo}`,\n `Destination: ${messageText(payload.destinationAddress, \"destination\")}`,\n `Verifying Contract: ${messageAddress(signingConfig.tradingGatewayAddress, \"verifying contract\")}`,\n `Deadline: ${payload.deadlineTsSec}`,\n `Nonce: ${(payload.nonce.hi << 64n) + payload.nonce.lo}`,\n `Idempotency Key: ${messageText(payload.idempotencyKey, \"idempotency key\")}`,\n ].join(\"\\n\");\n}\n"],"mappings":";;;;AAMA,SAAS,eAAe,OAAe,OAAuB;CAC1D,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,CAAC,aAAa,OAAO,GACrB,MAAM,IAAI,gBAAgB,oBAAoB,MAAM,8BAA8B;CAEtF,OAAO,QAAQ,YAAY;AAC/B;AAEA,SAAS,YAAY,OAAe,OAAuB;CACvD,MAAM,OAAO,MAAM,KAAK;CACxB,IAAI,kBAAkB,KAAK,IAAI,GAC3B,MAAM,IAAI,gBACN,oBAAoB,MAAM,iDAC9B;CAEJ,OAAO;AACX;AAEA,SAAgB,kCAAkC,QAMvC;CACP,MAAM,EAAE,SAAS,kBAAkB;CACnC,IAAI,CAAC,OAAO,cAAc,cAAc,OAAO,KAAK,cAAc,WAAW,GACzE,MAAM,IAAI,gBAAgB,4DAA4D;CAE1F,MAAM,SACF,QAAQ,WAAA,IACF,eACA,QAAQ,WAAA,IACN,sBACA,KAAA;CACZ,IAAI,CAAC,QAAQ,MAAM,IAAI,gBAAgB,kCAAkC;CAEzE,OAAO;EACH;EACA;EACA;EACA;EACA,WAAW;EACX,kBAAkB,eAAe,OAAO,cAAc,eAAe;EACrE,eAAe,OAAO;EACtB,sBAAsB,OAAO;EAC7B,aAAa,QAAQ;EACrB,uBAAuB,cAAc;EACrC,yBAAyB,QAAQ;EACjC,gBAAgB,QAAQ,UAAU,MAAM,OAAO,QAAQ,UAAU;EACjE,gBAAgB,YAAY,QAAQ,oBAAoB,aAAa;EACrE,uBAAuB,eAAe,cAAc,uBAAuB,oBAAoB;EAC/F,aAAa,QAAQ;EACrB,WAAW,QAAQ,MAAM,MAAM,OAAO,QAAQ,MAAM;EACpD,oBAAoB,YAAY,QAAQ,gBAAgB,iBAAiB;CAC7E,CAAC,CAAC,KAAK,IAAI;AACf"}
|
|
@@ -845,7 +845,7 @@ type CreateTriggerInput = v.InferInput<ReturnType<typeof createCreateTriggerInpu
|
|
|
845
845
|
declare const ListTriggersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
846
846
|
readonly parentOrderId: v.SchemaWithPipe<readonly [v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>, v.TransformAction<string | undefined, bigint | undefined>]>;
|
|
847
847
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
848
|
-
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("
|
|
848
|
+
readonly status: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["created", "armed", "running", "completed", "cancelled", "failed", "paused"], undefined>, undefined>, undefined>, v.TransformAction<("completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused")[] | undefined, (TriggerStatus.STATUS_CREATED | TriggerStatus.STATUS_ARMED | TriggerStatus.STATUS_RUNNING | TriggerStatus.STATUS_COMPLETED | TriggerStatus.STATUS_CANCELED | TriggerStatus.STATUS_FAILED | TriggerStatus.STATUS_PAUSED)[]>]>;
|
|
849
849
|
readonly triggerType: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["stop_loss", "take_profit", "trailing_stop", "twap", "ladder"], undefined>, undefined>, v.TransformAction<"twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop" | undefined, TriggerType>]>;
|
|
850
850
|
readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>, 50>;
|
|
851
851
|
readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, "">;
|
|
@@ -1066,7 +1066,7 @@ declare const ListTriggerEventsInputSchema: v.SchemaWithPipe<readonly [v.StrictO
|
|
|
1066
1066
|
readonly triggerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
|
|
1067
1067
|
}, undefined>, v.TransformAction<{
|
|
1068
1068
|
limit?: number | undefined;
|
|
1069
|
-
eventType?: "
|
|
1069
|
+
eventType?: "failed" | "updated" | "fired" | "canceled" | undefined;
|
|
1070
1070
|
pageToken: string;
|
|
1071
1071
|
account?: "active" | "main" | {
|
|
1072
1072
|
subaccountId: string;
|
|
@@ -31,62 +31,62 @@ declare const CreateTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSche
|
|
|
31
31
|
type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;
|
|
32
32
|
declare const CancelTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
33
33
|
readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
34
|
-
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "
|
|
34
|
+
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
|
|
35
35
|
readonly tsNs: v.BigintSchema<undefined>;
|
|
36
36
|
}, undefined>, v.TransformAction<{
|
|
37
37
|
triggerId: string;
|
|
38
|
-
status: "unspecified" | "
|
|
38
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
39
39
|
tsNs: bigint;
|
|
40
40
|
}, {
|
|
41
41
|
ts: number;
|
|
42
42
|
tsNs: string;
|
|
43
43
|
triggerId: string;
|
|
44
|
-
status: "unspecified" | "
|
|
44
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
45
45
|
}>]>;
|
|
46
46
|
type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;
|
|
47
47
|
declare const ModifyTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
48
48
|
readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
49
|
-
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "
|
|
49
|
+
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
|
|
50
50
|
readonly tsNs: v.BigintSchema<undefined>;
|
|
51
51
|
}, undefined>, v.TransformAction<{
|
|
52
52
|
triggerId: string;
|
|
53
|
-
status: "unspecified" | "
|
|
53
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
54
54
|
tsNs: bigint;
|
|
55
55
|
}, {
|
|
56
56
|
ts: number;
|
|
57
57
|
tsNs: string;
|
|
58
58
|
triggerId: string;
|
|
59
|
-
status: "unspecified" | "
|
|
59
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
60
60
|
}>]>;
|
|
61
61
|
type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;
|
|
62
62
|
declare const PauseTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
63
63
|
readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
64
|
-
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "
|
|
64
|
+
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
|
|
65
65
|
readonly tsNs: v.BigintSchema<undefined>;
|
|
66
66
|
}, undefined>, v.TransformAction<{
|
|
67
67
|
triggerId: string;
|
|
68
|
-
status: "unspecified" | "
|
|
68
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
69
69
|
tsNs: bigint;
|
|
70
70
|
}, {
|
|
71
71
|
ts: number;
|
|
72
72
|
tsNs: string;
|
|
73
73
|
triggerId: string;
|
|
74
|
-
status: "unspecified" | "
|
|
74
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
75
75
|
}>]>;
|
|
76
76
|
type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;
|
|
77
77
|
declare const ResumeTriggerResultSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
78
78
|
readonly triggerId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
79
|
-
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "
|
|
79
|
+
readonly status: v.SchemaWithPipe<readonly [v.EnumSchema<typeof TriggerStatus, undefined>, v.TransformAction<TriggerStatus, "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused">]>;
|
|
80
80
|
readonly tsNs: v.BigintSchema<undefined>;
|
|
81
81
|
}, undefined>, v.TransformAction<{
|
|
82
82
|
triggerId: string;
|
|
83
|
-
status: "unspecified" | "
|
|
83
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
84
84
|
tsNs: bigint;
|
|
85
85
|
}, {
|
|
86
86
|
ts: number;
|
|
87
87
|
tsNs: string;
|
|
88
88
|
triggerId: string;
|
|
89
|
-
status: "unspecified" | "
|
|
89
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
90
90
|
}>]>;
|
|
91
91
|
type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;
|
|
92
92
|
type StopDetailsOutput = {
|
|
@@ -558,7 +558,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
|
|
|
558
558
|
triggerId: string;
|
|
559
559
|
subaccountId: string;
|
|
560
560
|
symbolId: number;
|
|
561
|
-
status: "unspecified" | "
|
|
561
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
562
562
|
parentOrderId: string | undefined;
|
|
563
563
|
qty: string;
|
|
564
564
|
feeAsset: "unspecified" | "quote" | "base";
|
|
@@ -714,7 +714,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
|
|
|
714
714
|
triggerId: string;
|
|
715
715
|
subaccountId: string;
|
|
716
716
|
symbolId: number;
|
|
717
|
-
status: "unspecified" | "
|
|
717
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
718
718
|
parentOrderId: string | undefined;
|
|
719
719
|
qty: string;
|
|
720
720
|
feeAsset: "unspecified" | "quote" | "base";
|
|
@@ -870,7 +870,7 @@ declare function createTriggerSchema(scales: SdkScales): v.SchemaWithPipe<readon
|
|
|
870
870
|
triggerId: string;
|
|
871
871
|
subaccountId: string;
|
|
872
872
|
symbolId: number;
|
|
873
|
-
status: "unspecified" | "
|
|
873
|
+
status: "unspecified" | "completed" | "failed" | "cancelled" | "created" | "armed" | "running" | "paused";
|
|
874
874
|
parentOrderId: string | undefined;
|
|
875
875
|
qty: string;
|
|
876
876
|
feeAsset: "unspecified" | "quote" | "base";
|
|
@@ -1069,7 +1069,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1069
1069
|
subaccountId: string;
|
|
1070
1070
|
symbolId: number;
|
|
1071
1071
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1072
|
-
eventType: "unspecified" | "
|
|
1072
|
+
eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
|
|
1073
1073
|
ts: number;
|
|
1074
1074
|
childSeq: number;
|
|
1075
1075
|
childOrderId: string | undefined;
|
|
@@ -1081,7 +1081,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1081
1081
|
subaccountId: string;
|
|
1082
1082
|
symbolId: number;
|
|
1083
1083
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1084
|
-
eventType: "unspecified" | "
|
|
1084
|
+
eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
|
|
1085
1085
|
ts: number;
|
|
1086
1086
|
childSeq: number;
|
|
1087
1087
|
childOrderId: string | undefined;
|
|
@@ -1093,7 +1093,7 @@ declare function createTriggerEventSchema(scales: SdkScales): v.SchemaWithPipe<r
|
|
|
1093
1093
|
subaccountId: string;
|
|
1094
1094
|
symbolId: number;
|
|
1095
1095
|
triggerType: "unspecified" | "twap" | "ladder" | "stop_loss" | "take_profit" | "trailing_stop";
|
|
1096
|
-
eventType: "unspecified" | "
|
|
1096
|
+
eventType: "unspecified" | "failed" | "updated" | "fired" | "canceled";
|
|
1097
1097
|
ts: number;
|
|
1098
1098
|
childSeq: number;
|
|
1099
1099
|
childOrderId: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polyester/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "TypeScript SDK providing access to APIs on Polyester Exchange.",
|
|
6
6
|
"homepage": "https://github.com/Fabric-Labs/polyester-sdk-typescript#readme",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"@types/bun": "1.3.14",
|
|
110
110
|
"oxfmt": "0.61.0",
|
|
111
111
|
"oxlint": "1.76.0",
|
|
112
|
+
"pkg-pr-new": "0.0.88",
|
|
112
113
|
"tsdown": "0.22.14",
|
|
113
114
|
"typescript": "6.0.3",
|
|
114
115
|
"vitest": "4.1.11"
|