@polyester/sdk 0.22.3 → 0.23.1

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/account-signer/types.d.ts +1 -1
  3. package/dist/account-signer/types.js.map +1 -1
  4. package/dist/environment.js +4 -4
  5. package/dist/environment.js.map +1 -1
  6. package/dist/gen/auth/v1/auth_pb.d.ts +88 -46
  7. package/dist/gen/auth/v1/auth_pb.d.ts.map +1 -1
  8. package/dist/gen/auth/v1/auth_pb.js +43 -11
  9. package/dist/gen/auth/v1/auth_pb.js.map +1 -1
  10. package/dist/gen/auth/v1/subaccounts_pb.d.ts +5 -17
  11. package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
  12. package/dist/gen/auth/v1/subaccounts_pb.js +1 -1
  13. package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
  14. package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +2 -2
  15. package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
  16. package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +2 -1
  17. package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts.map +1 -1
  18. package/dist/gen/marketoverview/v1/marketoverview_pb.js.map +1 -1
  19. package/dist/index.d.ts +3 -3
  20. package/dist/services/auth/account-signer-auth.d.ts +7 -3
  21. package/dist/services/auth/account-signer-auth.d.ts.map +1 -1
  22. package/dist/services/auth/account-signer-auth.js +28 -13
  23. package/dist/services/auth/account-signer-auth.js.map +1 -1
  24. package/dist/services/auth/auth.d.ts +19 -14
  25. package/dist/services/auth/auth.d.ts.map +1 -1
  26. package/dist/services/auth/auth.js +24 -14
  27. package/dist/services/auth/auth.js.map +1 -1
  28. package/dist/services/auth/auth.types.d.ts +2 -2
  29. package/dist/services/auth/wallet-challenge.schemas.js +20 -0
  30. package/dist/services/auth/wallet-challenge.schemas.js.map +1 -0
  31. package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
  32. package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
  33. package/dist/services/orders/orders-batch.schemas.d.ts +14 -14
  34. package/dist/services/orders/orders-input.schemas.d.ts +1 -1
  35. package/dist/services/orders/orders-output.schemas.d.ts +6 -6
  36. package/dist/services/subaccounts/subaccounts.d.ts +1 -1
  37. package/dist/services/subaccounts/subaccounts.js +1 -1
  38. package/dist/services/subaccounts/subaccounts.js.map +1 -1
  39. package/dist/services/subaccounts/subaccounts.schemas.d.ts +5 -7
  40. package/dist/services/subaccounts/subaccounts.schemas.d.ts.map +1 -1
  41. package/dist/services/subaccounts/subaccounts.schemas.js +4 -5
  42. package/dist/services/subaccounts/subaccounts.schemas.js.map +1 -1
  43. package/dist/services/trading-withdraws/index.d.ts +1 -1
  44. package/dist/services/trading-withdraws/trading-withdraws.d.ts +10 -72
  45. package/dist/services/trading-withdraws/trading-withdraws.d.ts.map +1 -1
  46. package/dist/services/trading-withdraws/trading-withdraws.js +8 -84
  47. package/dist/services/trading-withdraws/trading-withdraws.js.map +1 -1
  48. package/dist/services/trading-withdraws/trading-withdraws.types.d.ts +2 -2
  49. package/dist/services/trading-withdraws/wallet-message.js +43 -0
  50. package/dist/services/trading-withdraws/wallet-message.js.map +1 -0
  51. package/package.json +2 -1
@@ -4,6 +4,7 @@ import { BigIntStringSchema, OptionalTimestampMsSchema, PublicIdSchema, Timestam
4
4
  import { PolicyAction } from "../../gen/auth/v1/policies_pb.js";
5
5
  import { PolicyActionCodec } from "../policies/shared.codecs.js";
6
6
  import { buildProtoPatch, defineProtoPatchFields } from "../../utils/proto-patch.js";
7
+ import { WalletAddressSchema, WalletChallengeMessageSchema, WalletSignatureSchema } from "../auth/wallet-challenge.schemas.js";
7
8
  import { ActivityEntityKind, ActivityEventAction, ActivityEventSource, SubaccountInviteStatus, SubaccountPermission, SubaccountRole, SubaccountStatus } from "../../gen/auth/v1/subaccounts_pb.js";
8
9
  import { ActivityEntityKindCodec, ActivityEventActionCodec, ActivityEventSourceCodec, InviteActionCodec, InviteStatusCodec, SUBACCOUNT_INVITE_DIRECTION_VALUES, SUBACCOUNT_STATUS_VALUES, SubaccountInviteDirectionCodec, SubaccountPermissionCodec, SubaccountRoleCodec, SubaccountStatusCodec } from "./subaccounts.codecs.js";
9
10
  import * as v from "valibot";
@@ -43,11 +44,9 @@ const CreateSubaccountInputSchema = v.strictObject({
43
44
  label: v.optional(v.string(), ""),
44
45
  icon: v.optional(v.string(), ""),
45
46
  color: v.optional(v.string(), ""),
46
- smartAccountAddress: v.string(),
47
- nonce: v.string(),
48
- signature: v.string(),
49
- primaryWalletAddress: v.optional(v.string(), ""),
50
- walletProvider: v.optional(v.string(), "")
47
+ smartAccountAddress: WalletAddressSchema,
48
+ message: WalletChallengeMessageSchema,
49
+ signature: WalletSignatureSchema
51
50
  });
52
51
  const SubaccountIdInputSchema = v.strictObject({ subaccountId: idInputSchema("subaccountId") });
53
52
  const CreateSubaccountResultSchema = v.object({
@@ -1 +1 @@
1
- {"version":3,"file":"subaccounts.schemas.js","names":["Proto.SubaccountRole","Proto.SubaccountPermission","ProtoPolicies.PolicyAction","Proto.SubaccountInviteStatus","Proto.SubaccountStatus","Proto.ActivityEntityKind","Proto.ActivityEventAction","Proto.ActivityEventSource"],"sources":["../../../src/services/subaccounts/subaccounts.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/auth/v1/subaccounts_pb.js\";\nimport * as ProtoPolicies from \"../../gen/auth/v1/policies_pb.js\";\nimport * as v from \"valibot\";\nimport {\n BigIntStringSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampSchema,\n idInputSchema,\n positiveBigintStringInputSchema,\n} from \"../../shared/schemas.js\";\nimport { tsObjToMs, tsObjToNsString } from \"../../utils/time.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport {\n SubaccountRoleCodec,\n SubaccountPermissionCodec,\n InviteActionCodec,\n InviteStatusCodec,\n SubaccountInviteDirectionCodec,\n SUBACCOUNT_INVITE_DIRECTION_VALUES,\n SubaccountStatusCodec,\n SUBACCOUNT_STATUS_VALUES,\n ActivityEntityKindCodec,\n ActivityEventActionCodec,\n ActivityEventSourceCodec,\n} from \"./subaccounts.codecs.js\";\nimport { PolicyActionCodec } from \"../policies/shared.codecs.js\";\nimport { buildProtoPatch, defineProtoPatchFields } from \"../../utils/proto-patch.js\";\n\nconst SUBACCOUNT_ROLE_VALUES = [\n \"owner\",\n \"admin\",\n \"treasury\",\n \"leveraged_trader\",\n \"trader\",\n \"viewer\",\n] as const;\n\nexport const SubaccountRoleSchema = v.picklist(SUBACCOUNT_ROLE_VALUES);\n\nexport type SubaccountRole = v.InferOutput<typeof SubaccountRoleSchema>;\n\nconst ProtoSubaccountRoleSchema = v.pipe(\n v.enum(Proto.SubaccountRole),\n v.transform((role) =>\n requiredEnumLabel(SubaccountRoleCodec.protoToOutput, role, \"SubaccountRoleSchema\", \"role\"),\n ),\n);\n\nconst ProtoSubaccountPermissionSchema = v.pipe(\n v.enum(Proto.SubaccountPermission),\n v.transform((permission) =>\n requiredEnumLabel(\n SubaccountPermissionCodec.protoToOutput,\n permission,\n \"SubaccountPermissionSchema\",\n \"permission\",\n ),\n ),\n);\n\nexport type SubaccountPermission = v.InferOutput<typeof ProtoSubaccountPermissionSchema>;\n\nexport const SubaccountPermissionDefinitionSchema = v.object({\n permission: ProtoSubaccountPermissionSchema,\n displayName: v.optional(v.string(), \"\"),\n description: v.optional(v.string(), \"\"),\n policyAction: v.pipe(\n v.enum(ProtoPolicies.PolicyAction),\n v.transform((action) =>\n requiredEnumLabel(\n PolicyActionCodec.protoToOutput,\n action,\n \"SubaccountPermissionDefinitionSchema\",\n \"policy action\",\n ),\n ),\n ),\n});\n\nexport type SubaccountPermissionDefinition = v.InferOutput<\n typeof SubaccountPermissionDefinitionSchema\n>;\n\nexport const SubaccountRoleDefinitionSchema = v.object({\n role: ProtoSubaccountRoleSchema,\n displayName: v.optional(v.string(), \"\"),\n description: v.optional(v.string(), \"\"),\n assignable: v.optional(v.boolean(), false),\n permissions: v.optional(v.array(ProtoSubaccountPermissionSchema), []),\n});\n\nexport type SubaccountRoleDefinition = v.InferOutput<typeof SubaccountRoleDefinitionSchema>;\n\nexport const SubaccountRoleCatalogSchema = v.object({\n permissions: v.optional(v.array(SubaccountPermissionDefinitionSchema), []),\n roles: v.optional(v.array(SubaccountRoleDefinitionSchema), []),\n});\n\nexport type SubaccountRoleCatalog = v.InferOutput<typeof SubaccountRoleCatalogSchema>;\n\nexport const EffectiveSubaccountPermissionsSchema = v.object({\n role: ProtoSubaccountRoleSchema,\n permissions: v.optional(v.array(ProtoSubaccountPermissionSchema), []),\n subaccountPolicyId: PublicIdSchema,\n});\n\nexport type EffectiveSubaccountPermissions = v.InferOutput<\n typeof EffectiveSubaccountPermissionsSchema\n>;\n\nexport const CreateSubaccountInputSchema = v.strictObject({\n label: v.optional(v.string(), \"\"),\n icon: v.optional(v.string(), \"\"),\n color: v.optional(v.string(), \"\"),\n smartAccountAddress: v.string(),\n nonce: v.string(),\n signature: v.string(),\n primaryWalletAddress: v.optional(v.string(), \"\"),\n walletProvider: v.optional(v.string(), \"\"),\n});\n\nexport type CreateSubaccountInput = v.InferInput<typeof CreateSubaccountInputSchema>;\n\nexport const SubaccountIdInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n});\n\nexport type SubaccountIdInput = v.InferInput<typeof SubaccountIdInputSchema>;\n\nexport const CreateSubaccountResultSchema = v.object({\n subaccountId: PublicIdSchema,\n totalCreated: v.number(),\n smartAccountSaltNonce: v.number(),\n revision: BigIntStringSchema,\n});\n\nexport type CreateSubaccountResult = v.InferOutput<typeof CreateSubaccountResultSchema>;\n\nexport const SubaccountMutationResultSchema = v.object({});\n\nexport type SubaccountMutationResult = v.InferOutput<typeof SubaccountMutationResultSchema>;\n\ntype SubaccountPatch = {\n label?: string;\n icon?: string;\n color?: string;\n status?: (typeof SUBACCOUNT_STATUS_VALUES)[number];\n};\n\nconst SUBACCOUNT_PATCH_FIELDS = defineProtoPatchFields<SubaccountPatch>()({\n label: { path: \"label\", encode: (label) => ({ label }) },\n icon: { path: \"icon\", encode: (icon) => ({ icon }) },\n color: { path: \"color\", encode: (color) => ({ color }) },\n status: {\n path: \"status\",\n encode: (status) => ({ status: SubaccountStatusCodec.inputToProto[status] }),\n },\n});\n\nexport const UpdateSubaccountInputSchema = v.pipe(\n v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n expectedRevision: positiveBigintStringInputSchema(\"expectedRevision\"),\n label: v.optional(v.string()),\n icon: v.optional(v.string()),\n color: v.optional(v.string()),\n status: v.optional(v.picklist(SUBACCOUNT_STATUS_VALUES)),\n }),\n v.check(\n ({ label, icon, color, status }) =>\n label !== undefined ||\n icon !== undefined ||\n color !== undefined ||\n status !== undefined,\n \"At least one subaccount field must be provided\",\n ),\n v.transform(({ subaccountId, expectedRevision, ...input }) => {\n const { patch: subaccount, updateMask } = buildProtoPatch(input, SUBACCOUNT_PATCH_FIELDS);\n return {\n subaccountId,\n subaccount,\n updateMask,\n expectedRevision,\n };\n }),\n);\n\nexport type UpdateSubaccountInput = v.InferInput<typeof UpdateSubaccountInputSchema>;\n\nexport const InviteSubaccountMemberInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n granteeAccountId: idInputSchema(\"granteeAccountId\"),\n role: v.pipe(\n SubaccountRoleSchema,\n v.transform((role) => SubaccountRoleCodec.inputToProto[role]),\n ),\n});\n\nexport type InviteSubaccountMemberInput = v.InferInput<typeof InviteSubaccountMemberInputSchema>;\n\nexport const RemoveSubaccountMemberInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n granteeAccountId: idInputSchema(\"granteeAccountId\"),\n});\n\nexport type RemoveSubaccountMemberInput = v.InferInput<typeof RemoveSubaccountMemberInputSchema>;\n\nexport const UpdateSubaccountMemberRoleInputSchema = InviteSubaccountMemberInputSchema;\n\nexport type UpdateSubaccountMemberRoleInput = v.InferInput<\n typeof UpdateSubaccountMemberRoleInputSchema\n>;\n\nexport const SetSubaccountMemberMfaRequirementInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n requireMemberMfa: v.boolean(),\n});\n\nexport type SetSubaccountMemberMfaRequirementInput = v.InferInput<\n typeof SetSubaccountMemberMfaRequirementInputSchema\n>;\n\nexport const ListSubaccountInvitesInputSchema = v.strictObject({\n direction: v.pipe(\n v.optional(v.picklist(SUBACCOUNT_INVITE_DIRECTION_VALUES), \"\"),\n v.transform((direction) => SubaccountInviteDirectionCodec.inputToProto[direction]),\n ),\n});\n\nexport type ListSubaccountInvitesInput = v.InferInput<typeof ListSubaccountInvitesInputSchema>;\n\nconst InviteActionSchema = v.picklist([\"accept\", \"decline\", \"cancel\"]);\n\nconst InviteStatusSchema = v.picklist([\"pending\", \"accepted\", \"declined\", \"cancelled\"]);\n\nexport type SubaccountInviteStatus = v.InferOutput<typeof InviteStatusSchema>;\n\nconst ProtoInviteStatusSchema = v.enum(Proto.SubaccountInviteStatus);\n\nexport const RespondSubaccountInviteInputSchema = v.strictObject({\n inviteId: idInputSchema(\"inviteId\"),\n action: v.pipe(\n InviteActionSchema,\n v.transform((v) => InviteActionCodec.inputToProto[v]),\n ),\n});\n\nexport type RespondSubaccountInviteInput = v.InferInput<typeof RespondSubaccountInviteInputSchema>;\n\nconst ProtoSubaccountStatusSchema = v.pipe(\n v.enum(Proto.SubaccountStatus),\n v.transform((status) =>\n requiredEnumLabel(\n SubaccountStatusCodec.protoToOutput,\n status,\n \"SubaccountSchema\",\n \"status\",\n ),\n ),\n);\n\nexport type SubaccountStatus = v.InferOutput<typeof ProtoSubaccountStatusSchema>;\n\nexport const SubaccountSchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n label: v.optional(v.string(), \"\"),\n icon: v.optional(v.string(), \"\"),\n color: v.optional(v.string(), \"\"),\n status: ProtoSubaccountStatusSchema,\n smartAccountAddress: v.string(),\n smartAccountSaltNonce: v.optional(v.number()),\n ownerUsername: v.optional(v.string(), \"\"),\n ownerAvatarUrl: v.optional(v.string(), \"\"),\n ownerRootSmartAccountAddress: v.string(),\n subaccountPolicyId: PublicIdSchema,\n requireMemberMfa: v.optional(v.boolean(), false),\n updatedAt: v.optional(TimestampSchema),\n revision: BigIntStringSchema,\n }),\n v.transform(({ updatedAt, ...subaccount }) => ({\n ...subaccount,\n updatedAt: tsObjToMs(updatedAt),\n updatedAtNs: tsObjToNsString(updatedAt),\n })),\n);\n\nexport type Subaccount = v.InferOutput<typeof SubaccountSchema>;\n\nexport const SubaccountMemberSchema = v.object({\n accountId: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n username: v.optional(v.string(), \"\"),\n smartAccountAddress: v.string(),\n avatarUrl: v.optional(v.string(), \"\"),\n mfaEnrolled: v.optional(v.boolean(), false),\n});\n\nexport type SubaccountMember = v.InferOutput<typeof SubaccountMemberSchema>;\n\nexport const SubaccountInviteSchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n subaccountId: PublicIdSchema,\n granteeAccountId: PublicIdSchema,\n inviterAccountId: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n status: v.pipe(\n ProtoInviteStatusSchema,\n v.transform((v) =>\n requiredEnumLabel(\n InviteStatusCodec.protoToOutput,\n v,\n \"SubaccountInviteSchema\",\n \"status\",\n ),\n ),\n ),\n createdAt: OptionalTimestampMsSchema,\n respondedAt: OptionalTimestampMsSchema,\n granteeUsername: v.optional(v.string(), \"\"),\n inviterUsername: v.optional(v.string(), \"\"),\n subaccountLabel: v.optional(v.string(), \"\"),\n inviterRootSmartAccountAddress: v.string(),\n granteeRootSmartAccountAddress: v.string(),\n requireMemberMfa: v.boolean(),\n }),\n v.transform(\n ({\n subaccountLabel,\n subaccountId,\n inviterRootSmartAccountAddress,\n granteeRootSmartAccountAddress,\n ...rest\n }) => ({\n ...rest,\n subaccountId,\n subaccountLabel,\n inviterSmartAccountAddress: inviterRootSmartAccountAddress,\n granteeSmartAccountAddress: granteeRootSmartAccountAddress,\n }),\n ),\n);\n\nexport type SubaccountInvite = v.InferOutput<typeof SubaccountInviteSchema>;\n\nexport const SubaccountActivityInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(200)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n});\n\nexport type SubaccountActivityInput = v.InferInput<typeof SubaccountActivityInputSchema>;\n\nexport const SubaccountActivityEventSchema = v.object({\n createdAt: OptionalTimestampMsSchema,\n entityKind: v.pipe(\n v.enum(Proto.ActivityEntityKind),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEntityKindCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"entity kind\",\n ),\n ),\n ),\n eventAction: v.pipe(\n v.enum(Proto.ActivityEventAction),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEventActionCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"event action\",\n ),\n ),\n ),\n source: v.pipe(\n v.enum(Proto.ActivityEventSource),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEventSourceCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"source\",\n ),\n ),\n ),\n ip: v.optional(v.string()),\n userAgent: v.optional(v.string()),\n actorAccountId: PublicIdSchema,\n payloadJson: v.pipe(\n v.string(),\n v.transform((v) => JSON.parse(v)),\n ),\n});\n\nexport type SubaccountEvent = v.InferOutput<typeof SubaccountActivityEventSchema>;\n"],"mappings":";;;;;;;;;AAsCA,MAAa,uBAAuB,EAAE,SAAS;CAR3C;CACA;CACA;CACA;CACA;CACA;AAG2C,CAAsB;AAIrE,MAAM,4BAA4B,EAAE,KAChC,EAAE,KAAKA,cAAoB,GAC3B,EAAE,WAAW,SACT,kBAAkB,oBAAoB,eAAe,MAAM,wBAAwB,MAAM,CAC7F,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4B;AAChC,EACJ,CACJ;AAIA,MAAa,gCAAgC,EAAE,aAAa;CACxD,cAAc,cAAc,cAAc;CAC1C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE;CACrF,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE;AAC1D,CAAC;AAID,MAAa,gCAAgC,EAAE,OAAO;CAClD,WAAW;CACX,YAAY,EAAE,KACV,EAAE,KAAKC,kBAAwB,GAC/B,EAAE,WAAW,UACT,kBACI,wBAAwB,eACxB,OACA,iCACA,aACJ,CACJ,CACJ;CACA,aAAa,EAAE,KACX,EAAE,KAAKC,mBAAyB,GAChC,EAAE,WAAW,UACT,kBACI,yBAAyB,eACzB,OACA,iCACA,cACJ,CACJ,CACJ;CACA,QAAQ,EAAE,KACN,EAAE,KAAKC,mBAAyB,GAChC,EAAE,WAAW,UACT,kBACI,yBAAyB,eACzB,OACA,iCACA,QACJ,CACJ,CACJ;CACA,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC;CAChC,gBAAgB;CAChB,aAAa,EAAE,KACX,EAAE,OAAO,GACT,EAAE,WAAW,MAAM,KAAK,MAAM,CAAC,CAAC,CACpC;AACJ,CAAC"}
1
+ {"version":3,"file":"subaccounts.schemas.js","names":["Proto.SubaccountRole","Proto.SubaccountPermission","ProtoPolicies.PolicyAction","Proto.SubaccountInviteStatus","Proto.SubaccountStatus","Proto.ActivityEntityKind","Proto.ActivityEventAction","Proto.ActivityEventSource"],"sources":["../../../src/services/subaccounts/subaccounts.schemas.ts"],"sourcesContent":["import {\n WalletAddressSchema,\n WalletChallengeMessageSchema,\n WalletSignatureSchema,\n} from \"../auth/wallet-challenge.schemas.js\";\nimport * as Proto from \"../../gen/auth/v1/subaccounts_pb.js\";\nimport * as ProtoPolicies from \"../../gen/auth/v1/policies_pb.js\";\nimport * as v from \"valibot\";\nimport {\n BigIntStringSchema,\n OptionalTimestampMsSchema,\n PublicIdSchema,\n TimestampSchema,\n idInputSchema,\n positiveBigintStringInputSchema,\n} from \"../../shared/schemas.js\";\nimport { tsObjToMs, tsObjToNsString } from \"../../utils/time.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport {\n SubaccountRoleCodec,\n SubaccountPermissionCodec,\n InviteActionCodec,\n InviteStatusCodec,\n SubaccountInviteDirectionCodec,\n SUBACCOUNT_INVITE_DIRECTION_VALUES,\n SubaccountStatusCodec,\n SUBACCOUNT_STATUS_VALUES,\n ActivityEntityKindCodec,\n ActivityEventActionCodec,\n ActivityEventSourceCodec,\n} from \"./subaccounts.codecs.js\";\nimport { PolicyActionCodec } from \"../policies/shared.codecs.js\";\nimport { buildProtoPatch, defineProtoPatchFields } from \"../../utils/proto-patch.js\";\n\nconst SUBACCOUNT_ROLE_VALUES = [\n \"owner\",\n \"admin\",\n \"treasury\",\n \"leveraged_trader\",\n \"trader\",\n \"viewer\",\n] as const;\n\nexport const SubaccountRoleSchema = v.picklist(SUBACCOUNT_ROLE_VALUES);\n\nexport type SubaccountRole = v.InferOutput<typeof SubaccountRoleSchema>;\n\nconst ProtoSubaccountRoleSchema = v.pipe(\n v.enum(Proto.SubaccountRole),\n v.transform((role) =>\n requiredEnumLabel(SubaccountRoleCodec.protoToOutput, role, \"SubaccountRoleSchema\", \"role\"),\n ),\n);\n\nconst ProtoSubaccountPermissionSchema = v.pipe(\n v.enum(Proto.SubaccountPermission),\n v.transform((permission) =>\n requiredEnumLabel(\n SubaccountPermissionCodec.protoToOutput,\n permission,\n \"SubaccountPermissionSchema\",\n \"permission\",\n ),\n ),\n);\n\nexport type SubaccountPermission = v.InferOutput<typeof ProtoSubaccountPermissionSchema>;\n\nexport const SubaccountPermissionDefinitionSchema = v.object({\n permission: ProtoSubaccountPermissionSchema,\n displayName: v.optional(v.string(), \"\"),\n description: v.optional(v.string(), \"\"),\n policyAction: v.pipe(\n v.enum(ProtoPolicies.PolicyAction),\n v.transform((action) =>\n requiredEnumLabel(\n PolicyActionCodec.protoToOutput,\n action,\n \"SubaccountPermissionDefinitionSchema\",\n \"policy action\",\n ),\n ),\n ),\n});\n\nexport type SubaccountPermissionDefinition = v.InferOutput<\n typeof SubaccountPermissionDefinitionSchema\n>;\n\nexport const SubaccountRoleDefinitionSchema = v.object({\n role: ProtoSubaccountRoleSchema,\n displayName: v.optional(v.string(), \"\"),\n description: v.optional(v.string(), \"\"),\n assignable: v.optional(v.boolean(), false),\n permissions: v.optional(v.array(ProtoSubaccountPermissionSchema), []),\n});\n\nexport type SubaccountRoleDefinition = v.InferOutput<typeof SubaccountRoleDefinitionSchema>;\n\nexport const SubaccountRoleCatalogSchema = v.object({\n permissions: v.optional(v.array(SubaccountPermissionDefinitionSchema), []),\n roles: v.optional(v.array(SubaccountRoleDefinitionSchema), []),\n});\n\nexport type SubaccountRoleCatalog = v.InferOutput<typeof SubaccountRoleCatalogSchema>;\n\nexport const EffectiveSubaccountPermissionsSchema = v.object({\n role: ProtoSubaccountRoleSchema,\n permissions: v.optional(v.array(ProtoSubaccountPermissionSchema), []),\n subaccountPolicyId: PublicIdSchema,\n});\n\nexport type EffectiveSubaccountPermissions = v.InferOutput<\n typeof EffectiveSubaccountPermissionsSchema\n>;\n\nexport const CreateSubaccountInputSchema = v.strictObject({\n label: v.optional(v.string(), \"\"),\n icon: v.optional(v.string(), \"\"),\n color: v.optional(v.string(), \"\"),\n smartAccountAddress: WalletAddressSchema,\n message: WalletChallengeMessageSchema,\n signature: WalletSignatureSchema,\n});\n\nexport type CreateSubaccountInput = v.InferInput<typeof CreateSubaccountInputSchema>;\n\nexport const SubaccountIdInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n});\n\nexport type SubaccountIdInput = v.InferInput<typeof SubaccountIdInputSchema>;\n\nexport const CreateSubaccountResultSchema = v.object({\n subaccountId: PublicIdSchema,\n totalCreated: v.number(),\n smartAccountSaltNonce: v.number(),\n revision: BigIntStringSchema,\n});\n\nexport type CreateSubaccountResult = v.InferOutput<typeof CreateSubaccountResultSchema>;\n\nexport const SubaccountMutationResultSchema = v.object({});\n\nexport type SubaccountMutationResult = v.InferOutput<typeof SubaccountMutationResultSchema>;\n\ntype SubaccountPatch = {\n label?: string;\n icon?: string;\n color?: string;\n status?: (typeof SUBACCOUNT_STATUS_VALUES)[number];\n};\n\nconst SUBACCOUNT_PATCH_FIELDS = defineProtoPatchFields<SubaccountPatch>()({\n label: { path: \"label\", encode: (label) => ({ label }) },\n icon: { path: \"icon\", encode: (icon) => ({ icon }) },\n color: { path: \"color\", encode: (color) => ({ color }) },\n status: {\n path: \"status\",\n encode: (status) => ({ status: SubaccountStatusCodec.inputToProto[status] }),\n },\n});\n\nexport const UpdateSubaccountInputSchema = v.pipe(\n v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n expectedRevision: positiveBigintStringInputSchema(\"expectedRevision\"),\n label: v.optional(v.string()),\n icon: v.optional(v.string()),\n color: v.optional(v.string()),\n status: v.optional(v.picklist(SUBACCOUNT_STATUS_VALUES)),\n }),\n v.check(\n ({ label, icon, color, status }) =>\n label !== undefined ||\n icon !== undefined ||\n color !== undefined ||\n status !== undefined,\n \"At least one subaccount field must be provided\",\n ),\n v.transform(({ subaccountId, expectedRevision, ...input }) => {\n const { patch: subaccount, updateMask } = buildProtoPatch(input, SUBACCOUNT_PATCH_FIELDS);\n return {\n subaccountId,\n subaccount,\n updateMask,\n expectedRevision,\n };\n }),\n);\n\nexport type UpdateSubaccountInput = v.InferInput<typeof UpdateSubaccountInputSchema>;\n\nexport const InviteSubaccountMemberInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n granteeAccountId: idInputSchema(\"granteeAccountId\"),\n role: v.pipe(\n SubaccountRoleSchema,\n v.transform((role) => SubaccountRoleCodec.inputToProto[role]),\n ),\n});\n\nexport type InviteSubaccountMemberInput = v.InferInput<typeof InviteSubaccountMemberInputSchema>;\n\nexport const RemoveSubaccountMemberInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n granteeAccountId: idInputSchema(\"granteeAccountId\"),\n});\n\nexport type RemoveSubaccountMemberInput = v.InferInput<typeof RemoveSubaccountMemberInputSchema>;\n\nexport const UpdateSubaccountMemberRoleInputSchema = InviteSubaccountMemberInputSchema;\n\nexport type UpdateSubaccountMemberRoleInput = v.InferInput<\n typeof UpdateSubaccountMemberRoleInputSchema\n>;\n\nexport const SetSubaccountMemberMfaRequirementInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n requireMemberMfa: v.boolean(),\n});\n\nexport type SetSubaccountMemberMfaRequirementInput = v.InferInput<\n typeof SetSubaccountMemberMfaRequirementInputSchema\n>;\n\nexport const ListSubaccountInvitesInputSchema = v.strictObject({\n direction: v.pipe(\n v.optional(v.picklist(SUBACCOUNT_INVITE_DIRECTION_VALUES), \"\"),\n v.transform((direction) => SubaccountInviteDirectionCodec.inputToProto[direction]),\n ),\n});\n\nexport type ListSubaccountInvitesInput = v.InferInput<typeof ListSubaccountInvitesInputSchema>;\n\nconst InviteActionSchema = v.picklist([\"accept\", \"decline\", \"cancel\"]);\n\nconst InviteStatusSchema = v.picklist([\"pending\", \"accepted\", \"declined\", \"cancelled\"]);\n\nexport type SubaccountInviteStatus = v.InferOutput<typeof InviteStatusSchema>;\n\nconst ProtoInviteStatusSchema = v.enum(Proto.SubaccountInviteStatus);\n\nexport const RespondSubaccountInviteInputSchema = v.strictObject({\n inviteId: idInputSchema(\"inviteId\"),\n action: v.pipe(\n InviteActionSchema,\n v.transform((v) => InviteActionCodec.inputToProto[v]),\n ),\n});\n\nexport type RespondSubaccountInviteInput = v.InferInput<typeof RespondSubaccountInviteInputSchema>;\n\nconst ProtoSubaccountStatusSchema = v.pipe(\n v.enum(Proto.SubaccountStatus),\n v.transform((status) =>\n requiredEnumLabel(\n SubaccountStatusCodec.protoToOutput,\n status,\n \"SubaccountSchema\",\n \"status\",\n ),\n ),\n);\n\nexport type SubaccountStatus = v.InferOutput<typeof ProtoSubaccountStatusSchema>;\n\nexport const SubaccountSchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n label: v.optional(v.string(), \"\"),\n icon: v.optional(v.string(), \"\"),\n color: v.optional(v.string(), \"\"),\n status: ProtoSubaccountStatusSchema,\n smartAccountAddress: v.string(),\n smartAccountSaltNonce: v.optional(v.number()),\n ownerUsername: v.optional(v.string(), \"\"),\n ownerAvatarUrl: v.optional(v.string(), \"\"),\n ownerRootSmartAccountAddress: v.string(),\n subaccountPolicyId: PublicIdSchema,\n requireMemberMfa: v.optional(v.boolean(), false),\n updatedAt: v.optional(TimestampSchema),\n revision: BigIntStringSchema,\n }),\n v.transform(({ updatedAt, ...subaccount }) => ({\n ...subaccount,\n updatedAt: tsObjToMs(updatedAt),\n updatedAtNs: tsObjToNsString(updatedAt),\n })),\n);\n\nexport type Subaccount = v.InferOutput<typeof SubaccountSchema>;\n\nexport const SubaccountMemberSchema = v.object({\n accountId: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n username: v.optional(v.string(), \"\"),\n smartAccountAddress: v.string(),\n avatarUrl: v.optional(v.string(), \"\"),\n mfaEnrolled: v.optional(v.boolean(), false),\n});\n\nexport type SubaccountMember = v.InferOutput<typeof SubaccountMemberSchema>;\n\nexport const SubaccountInviteSchema = v.pipe(\n v.object({\n id: PublicIdSchema,\n subaccountId: PublicIdSchema,\n granteeAccountId: PublicIdSchema,\n inviterAccountId: PublicIdSchema,\n role: ProtoSubaccountRoleSchema,\n status: v.pipe(\n ProtoInviteStatusSchema,\n v.transform((v) =>\n requiredEnumLabel(\n InviteStatusCodec.protoToOutput,\n v,\n \"SubaccountInviteSchema\",\n \"status\",\n ),\n ),\n ),\n createdAt: OptionalTimestampMsSchema,\n respondedAt: OptionalTimestampMsSchema,\n granteeUsername: v.optional(v.string(), \"\"),\n inviterUsername: v.optional(v.string(), \"\"),\n subaccountLabel: v.optional(v.string(), \"\"),\n inviterRootSmartAccountAddress: v.string(),\n granteeRootSmartAccountAddress: v.string(),\n requireMemberMfa: v.boolean(),\n }),\n v.transform(\n ({\n subaccountLabel,\n subaccountId,\n inviterRootSmartAccountAddress,\n granteeRootSmartAccountAddress,\n ...rest\n }) => ({\n ...rest,\n subaccountId,\n subaccountLabel,\n inviterSmartAccountAddress: inviterRootSmartAccountAddress,\n granteeSmartAccountAddress: granteeRootSmartAccountAddress,\n }),\n ),\n);\n\nexport type SubaccountInvite = v.InferOutput<typeof SubaccountInviteSchema>;\n\nexport const SubaccountActivityInputSchema = v.strictObject({\n subaccountId: idInputSchema(\"subaccountId\"),\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(200)), 50),\n pageToken: v.optional(v.pipe(v.string(), v.trim()), \"\"),\n});\n\nexport type SubaccountActivityInput = v.InferInput<typeof SubaccountActivityInputSchema>;\n\nexport const SubaccountActivityEventSchema = v.object({\n createdAt: OptionalTimestampMsSchema,\n entityKind: v.pipe(\n v.enum(Proto.ActivityEntityKind),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEntityKindCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"entity kind\",\n ),\n ),\n ),\n eventAction: v.pipe(\n v.enum(Proto.ActivityEventAction),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEventActionCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"event action\",\n ),\n ),\n ),\n source: v.pipe(\n v.enum(Proto.ActivityEventSource),\n v.transform((value) =>\n requiredEnumLabel(\n ActivityEventSourceCodec.protoToOutput,\n value,\n \"SubaccountActivityEventSchema\",\n \"source\",\n ),\n ),\n ),\n ip: v.optional(v.string()),\n userAgent: v.optional(v.string()),\n actorAccountId: PublicIdSchema,\n payloadJson: v.pipe(\n v.string(),\n v.transform((v) => JSON.parse(v)),\n ),\n});\n\nexport type SubaccountEvent = v.InferOutput<typeof SubaccountActivityEventSchema>;\n"],"mappings":";;;;;;;;;;AA2CA,MAAa,uBAAuB,EAAE,SAAS;CAR3C;CACA;CACA;CACA;CACA;CACA;AAG2C,CAAsB;AAIrE,MAAM,4BAA4B,EAAE,KAChC,EAAE,KAAKA,cAAoB,GAC3B,EAAE,WAAW,SACT,kBAAkB,oBAAoB,eAAe,MAAM,wBAAwB,MAAM,CAC7F,CACJ;AAEA,MAAM,kCAAkC,EAAE,KACtC,EAAE,KAAKC,oBAA0B,GACjC,EAAE,WAAW,eACT,kBACI,0BAA0B,eAC1B,YACA,8BACA,YACJ,CACJ,CACJ;AAIA,MAAa,uCAAuC,EAAE,OAAO;CACzD,YAAY;CACZ,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACtC,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACtC,cAAc,EAAE,KACZ,EAAE,KAAKC,YAA0B,GACjC,EAAE,WAAW,WACT,kBACI,kBAAkB,eAClB,QACA,wCACA,eACJ,CACJ,CACJ;AACJ,CAAC;AAMD,MAAa,iCAAiC,EAAE,OAAO;CACnD,MAAM;CACN,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACtC,aAAa,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACtC,YAAY,EAAE,SAAS,EAAE,QAAQ,GAAG,KAAK;CACzC,aAAa,EAAE,SAAS,EAAE,MAAM,+BAA+B,GAAG,CAAC,CAAC;AACxE,CAAC;AAID,MAAa,8BAA8B,EAAE,OAAO;CAChD,aAAa,EAAE,SAAS,EAAE,MAAM,oCAAoC,GAAG,CAAC,CAAC;CACzE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACjE,CAAC;AAID,MAAa,uCAAuC,EAAE,OAAO;CACzD,MAAM;CACN,aAAa,EAAE,SAAS,EAAE,MAAM,+BAA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AAO;CACzC,gCAAgC,EAAE,OAAO;CACzC,kBAAkB,EAAE,QAAQ;AAChC,CAAC,GACD,EAAE,WACG,EACG,iBACA,cACA,gCACA,gCACA,GAAG,YACA;CACH,GAAG;CACH;CACA;CACA,4BAA4B;CAC5B,4BAA4B;AAChC,EACJ,CACJ;AAIA,MAAa,gCAAgC,EAAE,aAAa;CACxD,cAAc,cAAc,cAAc;CAC1C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE;CACrF,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE;AAC1D,CAAC;AAID,MAAa,gCAAgC,EAAE,OAAO;CAClD,WAAW;CACX,YAAY,EAAE,KACV,EAAE,KAAKC,kBAAwB,GAC/B,EAAE,WAAW,UACT,kBACI,wBAAwB,eACxB,OACA,iCACA,aACJ,CACJ,CACJ;CACA,aAAa,EAAE,KACX,EAAE,KAAKC,mBAAyB,GAChC,EAAE,WAAW,UACT,kBACI,yBAAyB,eACzB,OACA,iCACA,cACJ,CACJ,CACJ;CACA,QAAQ,EAAE,KACN,EAAE,KAAKC,mBAAyB,GAChC,EAAE,WAAW,UACT,kBACI,yBAAyB,eACzB,OACA,iCACA,QACJ,CACJ,CACJ;CACA,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC;CAChC,gBAAgB;CAChB,aAAa,EAAE,KACX,EAAE,OAAO,GACT,EAAE,WAAW,MAAM,KAAK,MAAM,CAAC,CAAC,CACpC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import { CreateTradingWithdrawResult, CreateTradingWithdrawResultSchema, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationInputSchema, ValidateWithdrawDestinationResult, ValidateWithdrawDestinationResultSchema, createCreateTradingWithdrawToExternalChainInputSchema, createCreateTradingWithdrawToFundingInputSchema } from "./trading-withdraws.schemas.js";
2
- import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawWalletTypedData, TradingWithdrawsService } from "./trading-withdraws.js";
2
+ import { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawsService } from "./trading-withdraws.js";
3
3
  import "./trading-withdraws.codecs.js";
4
4
  export { TradingWithdrawsService };
@@ -1,17 +1,19 @@
1
- import { TradingWithdrawAction } from "../../gen/chain/withdraw/v1/withdraw_pb.js";
2
1
  import { ClientCatalog } from "../../catalogs/types.js";
3
2
  import { AuthApiTransports } from "../../shared/transports.js";
4
3
  import { PolyesterMutationOptions, PolyesterRequestOptions } from "../../shared/request-options.js";
5
4
  import { SubaccountResolver } from "../subaccount-resolver.js";
6
5
  import { SdkScales } from "../../shared/decimal-surface.js";
7
- import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, TradingWithdrawIntentPayloadRequest, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
6
+ import { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToFundingInput, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult } from "./trading-withdraws.schemas.js";
8
7
  import { Address, Hex } from "viem";
9
8
  //#region src/services/trading-withdraws/trading-withdraws.d.ts
10
- type TradingWithdrawWalletTypedData = ReturnType<typeof buildTradingWithdrawWalletTypedData>;
11
9
  type TradingWithdrawWalletSigner = {
12
10
  signerWallet: string;
13
11
  accountId: string;
14
- signTypedData: (typedData: TradingWithdrawWalletTypedData) => Promise<Hex>;
12
+ /**
13
+ * Signs the UTF-8 message directly using EIP-191 personal_sign, without pre-hashing or switching chains.
14
+ * For a viem account, use `(message) => account.signMessage({ message })`.
15
+ */
16
+ signMessage: (message: string) => Promise<Hex>;
15
17
  };
16
18
  type TradingWithdrawSigningConfig = {
17
19
  chainId: number;
@@ -30,72 +32,8 @@ type PreparedTradingWithdraw = Readonly<{
30
32
  */
31
33
  submit: (options?: PolyesterMutationOptions) => Promise<CreateTradingWithdrawResult>;
32
34
  }>;
33
- declare function buildTradingWithdrawWalletTypedData(params: {
34
- signingConfig: TradingWithdrawSigningConfig;
35
- payload: TradingWithdrawIntentPayloadRequest;
36
- signerWallet: Address;
37
- accountId: bigint;
38
- targetAccountId: bigint;
39
- }): {
40
- readonly domain: {
41
- readonly name: "Polyester Trading Withdraw";
42
- readonly version: "1";
43
- readonly chainId: number;
44
- readonly verifyingContract: `0x${string}`;
45
- };
46
- readonly types: {
47
- readonly WalletTradingWithdraw: readonly [{
48
- readonly name: "signerWallet";
49
- readonly type: "address";
50
- }, {
51
- readonly name: "actionType";
52
- readonly type: "uint8";
53
- }, {
54
- readonly name: "accountId";
55
- readonly type: "uint64";
56
- }, {
57
- readonly name: "targetAccountId";
58
- readonly type: "uint64";
59
- }, {
60
- readonly name: "assetId";
61
- readonly type: "uint32";
62
- }, {
63
- readonly name: "destinationChainId";
64
- readonly type: "uint64";
65
- }, {
66
- readonly name: "amountQ";
67
- readonly type: "uint128";
68
- }, {
69
- readonly name: "destinationHash";
70
- readonly type: "bytes32";
71
- }, {
72
- readonly name: "deadlineTsSec";
73
- readonly type: "uint256";
74
- }, {
75
- readonly name: "nonce";
76
- readonly type: "uint128";
77
- }, {
78
- readonly name: "idempotencyKeyHash";
79
- readonly type: "bytes32";
80
- }];
81
- };
82
- readonly primaryType: "WalletTradingWithdraw";
83
- readonly message: {
84
- readonly signerWallet: `0x${string}`;
85
- readonly actionType: TradingWithdrawAction;
86
- readonly accountId: bigint;
87
- readonly targetAccountId: bigint;
88
- readonly assetId: number;
89
- readonly destinationChainId: bigint;
90
- readonly amountQ: bigint;
91
- readonly destinationHash: `0x${string}`;
92
- readonly deadlineTsSec: bigint;
93
- readonly nonce: bigint;
94
- readonly idempotencyKeyHash: `0x${string}`;
95
- };
96
- };
97
35
  /**
98
- * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-712 signatures.
36
+ * Creates durable Trading withdrawal intents to Funding using API signatures or wallet EIP-191 signatures.
99
37
  */
100
38
  declare class TradingWithdrawsService {
101
39
  #private;
@@ -105,7 +43,7 @@ declare class TradingWithdrawsService {
105
43
  */
106
44
  validateDestination(input: ValidateWithdrawDestinationInput, options?: PolyesterRequestOptions): Promise<ValidateWithdrawDestinationResult>;
107
45
  /**
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 EIP-712 typed data and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
46
+ * 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.
109
47
  */
110
48
  createToFunding(input: CreateTradingWithdrawToFundingServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
111
49
  /**
@@ -114,7 +52,7 @@ declare class TradingWithdrawsService {
114
52
  */
115
53
  prepareToFunding(input: CreateTradingWithdrawToFundingServiceInput): Promise<PreparedTradingWithdraw>;
116
54
  /**
117
- * 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.
55
+ * 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.
118
56
  */
119
57
  createToExternalChain(input: CreateTradingWithdrawToExternalChainServiceInput, options?: PolyesterMutationOptions): Promise<CreateTradingWithdrawResult>;
120
58
  /**
@@ -124,5 +62,5 @@ declare class TradingWithdrawsService {
124
62
  prepareToExternalChain(input: CreateTradingWithdrawToExternalChainServiceInput): Promise<PreparedTradingWithdraw>;
125
63
  }
126
64
  //#endregion
127
- export { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawWalletTypedData, TradingWithdrawsService };
65
+ export { CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawsService };
128
66
  //# sourceMappingURL=trading-withdraws.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;;KAuCY,iCAAiC,kBAAkB;KAEnD;EACR;EACA;EACA,gBAAgB,WAAW,mCAAmC,QAAQ;;KAG9D;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0BAA0B;;;;;EAKlC,SAAS,UAAU,6BAA6B,QAAQ;;iBAyCnD,oCAAoC;EACzC,eAAe;EACf,SAAS;EACT,cAAc;EACd;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA0ES;;EAYL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU;;;;EAeR,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
+ {"version":3,"file":"trading-withdraws.d.ts","names":[],"sources":["../../../src/services/trading-withdraws/trading-withdraws.ts"],"mappings":";;;;;;;;KAmCY;EACR;EACA;;;;;EAKA,cAAc,oBAAoB,QAAQ;;KAGlC;EACR;EACA,uBAAuB;;KAGf,6CAA6C;EACrD,eAAe;;KAGP,mDACR;EACI,eAAe;;KAGX,0BAA0B;;;;;EAKlC,SAAS,UAAU,6BAA6B,QAAQ;;;;;cAmE/C;;EAYL,YAAA,YAAY,mBACZ,UAAU,gCACV,eAAe,8BACf,QAAQ,WACR,UAAU;;;;EAeR,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,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, evmUtf8ToBytes, keccak256Hex } from "../../utils/evm.js";
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.signTypedData(buildTradingWithdrawWalletTypedData({
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-712 signatures.
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-712 typed data and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
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-712 typed data and calls the wallet endpoint; otherwise a payload signature is required for the backend-authorized endpoint.
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,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J;EACJ;EAEA,IAAI,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,EACH,QAAQ,OAAO,YAAY;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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,CAAC,UAAU,kBACX,MAAM,IAAI,gBACN,iEACJ;EAGJ,MAAM,UAAU,gBAAgB;GAC5B,SAAS,UAAU;GACnB,kBAAkB,UAAU;EAChC,CAAC;EACD,OAAO,EACH,QAAQ,OAAO,YAAY;GACvB,MAAM,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, TradingWithdrawWalletTypedData } from "./trading-withdraws.js";
3
- export type { CreateTradingWithdrawResult, CreateTradingWithdrawToExternalChainInput, CreateTradingWithdrawToExternalChainServiceInput, CreateTradingWithdrawToFundingInput, CreateTradingWithdrawToFundingServiceInput, PreparedTradingWithdraw, TradingWithdrawSigningConfig, TradingWithdrawWalletSigner, TradingWithdrawWalletTypedData, ValidateWithdrawDestinationInput, ValidateWithdrawDestinationResult };
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyester/sdk",
3
- "version": "0.22.3",
3
+ "version": "0.23.1",
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"