@heliofi/withdraw-core 0.0.7-alpha.1781007397 → 0.0.8-alpha.1781276921

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Core JS/TS SDK for MoonPay Commerce withdrawals — routes, quotes, balance checks, and transaction submission.
4
4
 
5
- ## Install
5
+ ## Install guide
6
6
 
7
7
  ```bash
8
8
  npm install @heliofi/withdraw-core
package/dist/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export type { WithdrawalJwtPayload } from './jwt';
3
3
  export { decodeJwt, isQuoteExpired } from './jwt';
4
4
  export type { ApiClientConfig } from './sdk';
5
5
  export { WithdrawalSDK } from './sdk';
6
- export type { BalanceResponse, BaseBlockchain, PolymarketWalletPreparedTransaction, PreparedTransaction, PrepareWithdrawalParams, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateQuoteParams, UserOpPreparedTransaction, WithdrawalConfig, WithdrawalCustomerSwapRoute, WithdrawalDetail, } from './types';
7
- export { SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, } from './types';
6
+ export type { BalanceResponse, BaseBlockchain, PolymarketWalletPreparedTransaction, PreparedTransaction, PrepareWithdrawalParams, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateQuoteParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCustomerSwapRoute, } from './types';
7
+ export { BroadcastAck, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, } from './types';
@@ -1,13 +1,13 @@
1
1
  import type { QuoteResponse } from '../types/prepared';
2
2
  import type { PrepareWithdrawalParams, SubmitWithdrawalParams, UpdateQuoteParams } from '../types/requests';
3
- import type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawalConfig, WithdrawalDetail } from '../types/responses';
3
+ import type { BalanceResponse, RoutesResponse, StatusResponse, SubmitResponse, WithdrawalConfig } from '../types/responses';
4
4
  import { type ApiClientConfig } from './ApiClient';
5
5
  export declare class WithdrawalSDK {
6
6
  private readonly api;
7
7
  constructor(config: ApiClientConfig);
8
8
  getWithdrawalConfig(withdrawalConfigId: string, signal?: AbortSignal): Promise<WithdrawalConfig>;
9
9
  getRoutes(withdrawalConfigId: string, signal?: AbortSignal): Promise<RoutesResponse>;
10
- getBalance(withdrawalConfigId: string, fromWallet: string, signal?: AbortSignal): Promise<BalanceResponse>;
10
+ getBalance(withdrawalConfigId: string, walletAddress: string, signal?: AbortSignal): Promise<BalanceResponse>;
11
11
  /**
12
12
  * Calls `POST /withdraw/:withdrawalConfigId/prepare`.
13
13
  * `withdrawalConfigId` goes in the path; the remaining fields are the
@@ -27,6 +27,5 @@ export declare class WithdrawalSDK {
27
27
  * `{ token, signedTx: { kind, signature } }`.
28
28
  */
29
29
  submitWithdrawal(params: SubmitWithdrawalParams, signal?: AbortSignal): Promise<SubmitResponse>;
30
- getStatus(withdrawalDetailId: string, signal?: AbortSignal): Promise<StatusResponse>;
31
- getWithdrawalDetail(withdrawalDetailId: string, signal?: AbortSignal): Promise<WithdrawalDetail>;
30
+ getWithdrawalDetail(withdrawalDetailId: string, signal?: AbortSignal): Promise<StatusResponse>;
32
31
  }
@@ -1,5 +1,6 @@
1
1
  export declare enum WithdrawalState {
2
2
  QUOTED = "QUOTED",
3
+ SUBMITTING = "SUBMITTING",
3
4
  SUBMITTED = "SUBMITTED",
4
5
  BRIDGING = "BRIDGING",
5
6
  COMPLETED = "COMPLETED",
@@ -28,6 +29,11 @@ export declare enum WithdrawalErrorCode {
28
29
  BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED",
29
30
  UNKNOWN = "UNKNOWN"
30
31
  }
32
+ export declare enum BroadcastAck {
33
+ ACKNOWLEDGED = "acknowledged",
34
+ UNACKNOWLEDGED = "unacknowledged",
35
+ REJECTED = "rejected"
36
+ }
31
37
  export declare enum SignedTransactionKind {
32
38
  RAW = "raw",
33
39
  USER_OP = "userop",
@@ -1,4 +1,4 @@
1
- export { SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, } from './enums';
1
+ export { BroadcastAck, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalState, } from './enums';
2
2
  export type { PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
3
3
  export type { PrepareWithdrawalParams, SubmitWithdrawalParams, UpdateQuoteParams, } from './requests';
4
- export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WithdrawalConfig, WithdrawalCustomerSwapRoute, WithdrawalDetail, } from './responses';
4
+ export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCustomerSwapRoute, } from './responses';
@@ -1,4 +1,4 @@
1
- import type { WithdrawalState } from './enums';
1
+ import type { BroadcastAck, WithdrawalState } from './enums';
2
2
  export type WithdrawalConfig = unknown;
3
3
  export interface BaseBlockchain {
4
4
  id: string;
@@ -22,12 +22,22 @@ export interface WithdrawalCustomerSwapRoute {
22
22
  export interface RoutesResponse {
23
23
  routes: WithdrawalCustomerSwapRoute[];
24
24
  }
25
- export type BalanceResponse = unknown;
25
+ export interface WalletCurrencyBalance {
26
+ currencyId: string;
27
+ symbol: string;
28
+ mintAddress: string;
29
+ /** Minimal units. */
30
+ balance: string | null;
31
+ uiBalance: string | null;
32
+ }
33
+ export interface BalanceResponse {
34
+ balances: WalletCurrencyBalance[];
35
+ }
26
36
  export type SubmitResponse = unknown;
27
37
  export interface StatusResponse {
38
+ withdrawalDetailId: string;
28
39
  state: WithdrawalState;
29
- txHash?: string;
30
- errorReason?: string;
31
- updatedAt: string;
40
+ txHash: string | null;
41
+ broadcastAck: BroadcastAck | null;
42
+ errorReason: string | null;
32
43
  }
33
- export type WithdrawalDetail = unknown;
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var W=(t,e,s)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var T=(t,e,s)=>W(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var A=(t=>(t.QUOTED="QUOTED",t.SUBMITTED="SUBMITTED",t.BRIDGING="BRIDGING",t.COMPLETED="COMPLETED",t.FAILED="FAILED",t.FAILED_EXPIRED="FAILED_EXPIRED",t.EXPIRED="EXPIRED",t.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",t))(A||{});const N=new Set(["COMPLETED","FAILED","FAILED_EXPIRED","EXPIRED","REFUNDED_BY_PROVIDER"]);var _=(t=>(t.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",t.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",t.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",t.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",t.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",t.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",t.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",t.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",t.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",t.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",t.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",t.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",t.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",t.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",t.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",t.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",t.UNKNOWN="UNKNOWN",t))(_||{}),I=(t=>(t.RAW="raw",t.USER_OP="userop",t.POLYMARKET_WALLET="polymarket_wallet",t))(I||{});const c=new Set(Object.values(_));class i extends Error{constructor(s,E,D){super(D??E);T(this,"name","WithdrawalApiError");this.status=s,this.code=E,this.detail=D}}const a=t=>t&&c.has(t)?t:_.UNKNOWN,R=t=>{const e=t.split(".");if(e.length!==3)throw new Error("Invalid JWT: expected 3 parts");const s=atob(e[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)},O=(t,e=5e3)=>{const{exp:s}=R(t);return s===void 0?!1:Date.now()>=s*1e3-e};class p{constructor(e){T(this,"baseUrl");T(this,"headers");T(this,"fetch");if(!e.publicApiKey)throw new Error("publicApiKey is required");this.baseUrl=e.baseUrl.endsWith("/")?e.baseUrl.slice(0,-1):e.baseUrl,this.headers={"Content-Type":"application/json",Authorization:`Bearer ${e.publicApiKey}`,...e.headers},this.fetch=e.fetch??globalThis.fetch.bind(globalThis)}async get(e,s){return this.request("GET",e,void 0,s)}async post(e,s,E){return this.request("POST",e,s,E)}async patch(e,s,E){return this.request("PATCH",e,s,E)}async request(e,s,E,D){const n=`${this.baseUrl}${s}`,r=await this.fetch(n,{method:e,headers:this.headers,body:E!==void 0?JSON.stringify(E):void 0,signal:D});if(!r.ok)throw await this.buildError(r);return await r.json()}async buildError(e){let s,E;try{const D=await e.json();s=D.message??void 0,E=D.errorCode??D.errorType??void 0}catch{s=e.statusText||void 0}return new i(e.status,a(E),s)}}class o{constructor(e){T(this,"api");this.api=new p(e)}async getWithdrawalConfig(e,s){return this.api.get(`/withdrawal-configs/${e}/public`,s)}async getRoutes(e,s){return this.api.get(`/withdraw/${e}/routes`,s)}async getBalance(e,s,E){return this.api.get(`/withdraw/${e}/balance/${s}`,E)}async prepare(e,s){const{withdrawalConfigId:E,...D}=e;return this.api.post(`/withdraw/${E}/prepare`,D,s)}async updateQuote(e,s,E){throw new Error("updateQuote is not yet supported by the backend. Create a new quote via prepare() instead.")}async submitWithdrawal(e,s){const{withdrawalDetailId:E,...D}=e;return this.api.post(`/withdraw/${E}/submit`,D,s)}async getStatus(e,s){return this.api.get(`/withdraw/${e}/status`,s)}async getWithdrawalDetail(e,s){return this.api.get(`/withdraw/${e}`,s)}}exports.SignedTransactionKind=I;exports.TERMINAL_STATES=N;exports.WithdrawalApiError=i;exports.WithdrawalErrorCode=_;exports.WithdrawalSDK=o;exports.WithdrawalState=A;exports.decodeJwt=R;exports.isQuoteExpired=O;exports.toWithdrawalErrorCode=a;
1
+ "use strict";var W=Object.defineProperty;var u=(e,t,s)=>t in e?W(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var T=(e,t,s)=>u(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var r=(e=>(e.QUOTED="QUOTED",e.SUBMITTING="SUBMITTING",e.SUBMITTED="SUBMITTED",e.BRIDGING="BRIDGING",e.COMPLETED="COMPLETED",e.FAILED="FAILED",e.FAILED_EXPIRED="FAILED_EXPIRED",e.EXPIRED="EXPIRED",e.REFUNDED_BY_PROVIDER="REFUNDED_BY_PROVIDER",e))(r||{});const c=new Set(["COMPLETED","FAILED","FAILED_EXPIRED","EXPIRED","REFUNDED_BY_PROVIDER"]);var _=(e=>(e.WITHDRAW_TX_INVALID_SIGNATURE="WITHDRAW_TX_INVALID_SIGNATURE",e.WITHDRAW_TX_BLOCKHASH_EXPIRED="WITHDRAW_TX_BLOCKHASH_EXPIRED",e.WITHDRAW_TX_NONCE_TOO_LOW="WITHDRAW_TX_NONCE_TOO_LOW",e.WITHDRAW_TX_USEROP_EXPIRED="WITHDRAW_TX_USEROP_EXPIRED",e.WITHDRAW_TX_UNDERPRICED="WITHDRAW_TX_UNDERPRICED",e.WITHDRAW_BUNDLER_REJECTED="WITHDRAW_BUNDLER_REJECTED",e.WITHDRAW_TX_BROADCAST_TIMEOUT="WITHDRAW_TX_BROADCAST_TIMEOUT",e.WITHDRAW_TX_ALREADY_KNOWN="WITHDRAW_TX_ALREADY_KNOWN",e.WITHDRAW_QUOTE_EXPIRED="WITHDRAW_QUOTE_EXPIRED",e.WITHDRAW_SANCTIONS_BLOCKED="WITHDRAW_SANCTIONS_BLOCKED",e.WITHDRAW_NO_ROUTE="WITHDRAW_NO_ROUTE",e.WITHDRAW_NOT_FOUND="WITHDRAW_NOT_FOUND",e.WITHDRAW_INSUFFICIENT_BALANCE="WITHDRAW_INSUFFICIENT_BALANCE",e.WITHDRAW_DETAILS_NOT_UPDATABLE="WITHDRAW_DETAILS_NOT_UPDATABLE",e.INVALID_WALLET_ADDRESS="INVALID_WALLET_ADDRESS",e.BALANCE_FETCH_FAILED="BALANCE_FETCH_FAILED",e.UNKNOWN="UNKNOWN",e))(_||{}),A=(e=>(e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e))(A||{}),i=(e=>(e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e))(i||{});const O=new Set(Object.values(_));class R extends Error{constructor(s,E,D){super(D??E);T(this,"name","WithdrawalApiError");this.status=s,this.code=E,this.detail=D}}const n=e=>e&&O.has(e)?e:_.UNKNOWN,a=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)},o=(e,t=5e3)=>{const{exp:s}=a(e);return s===void 0?!1:Date.now()>=s*1e3-t};class p{constructor(t){T(this,"baseUrl");T(this,"headers");T(this,"fetch");if(!t.publicApiKey)throw new Error("publicApiKey is required");this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json",Authorization:`Bearer ${t.publicApiKey}`,...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,s){return this.request("GET",t,void 0,s)}async post(t,s,E){return this.request("POST",t,s,E)}async patch(t,s,E){return this.request("PATCH",t,s,E)}async request(t,s,E,D){const N=`${this.baseUrl}${s}`,I=await this.fetch(N,{method:t,headers:this.headers,body:E!==void 0?JSON.stringify(E):void 0,signal:D});if(!I.ok)throw await this.buildError(I);return await I.json()}async buildError(t){let s,E;try{const D=await t.json();s=D.message??void 0,E=D.errorCode??D.errorType??void 0}catch{s=t.statusText||void 0}return new R(t.status,n(E),s)}}class L{constructor(t){T(this,"api");this.api=new p(t)}async getWithdrawalConfig(t,s){return this.api.get(`/withdrawal-configs/${t}/public`,s)}async getRoutes(t,s){return this.api.get(`/withdraw/${t}/routes`,s)}async getBalance(t,s,E){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(s)}`,E)}async prepare(t,s){const{withdrawalConfigId:E,...D}=t;return this.api.post(`/withdraw/${E}/prepare`,D,s)}async updateQuote(t,s,E){throw new Error("updateQuote is not yet supported by the backend. Create a new quote via prepare() instead.")}async submitWithdrawal(t,s){const{withdrawalDetailId:E,...D}=t;return this.api.post(`/withdraw/${E}/submit`,D,s)}async getWithdrawalDetail(t,s){return this.api.get(`/withdraw-details/${t}`,s)}}exports.BroadcastAck=A;exports.SignedTransactionKind=i;exports.TERMINAL_STATES=c;exports.WithdrawalApiError=R;exports.WithdrawalErrorCode=_;exports.WithdrawalSDK=L;exports.WithdrawalState=r;exports.decodeJwt=a;exports.isQuoteExpired=o;exports.toWithdrawalErrorCode=n;
@@ -1,8 +1,8 @@
1
1
  var R = Object.defineProperty;
2
- var r = (t, e, s) => e in t ? R(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var E = (t, e, s) => r(t, typeof e != "symbol" ? e + "" : e, s);
4
- var i = /* @__PURE__ */ ((t) => (t.QUOTED = "QUOTED", t.SUBMITTED = "SUBMITTED", t.BRIDGING = "BRIDGING", t.COMPLETED = "COMPLETED", t.FAILED = "FAILED", t.FAILED_EXPIRED = "FAILED_EXPIRED", t.EXPIRED = "EXPIRED", t.REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER", t))(i || {});
5
- const p = /* @__PURE__ */ new Set([
2
+ var n = (e, t, s) => t in e ? R(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var T = (e, t, s) => n(e, typeof t != "symbol" ? t + "" : t, s);
4
+ var r = /* @__PURE__ */ ((e) => (e.QUOTED = "QUOTED", e.SUBMITTING = "SUBMITTING", e.SUBMITTED = "SUBMITTED", e.BRIDGING = "BRIDGING", e.COMPLETED = "COMPLETED", e.FAILED = "FAILED", e.FAILED_EXPIRED = "FAILED_EXPIRED", e.EXPIRED = "EXPIRED", e.REFUNDED_BY_PROVIDER = "REFUNDED_BY_PROVIDER", e))(r || {});
5
+ const L = /* @__PURE__ */ new Set([
6
6
  "COMPLETED",
7
7
  "FAILED",
8
8
  "FAILED_EXPIRED",
@@ -10,90 +10,92 @@ const p = /* @__PURE__ */ new Set([
10
10
  "REFUNDED_BY_PROVIDER"
11
11
  /* REFUNDED_BY_PROVIDER */
12
12
  ]);
13
- var I = /* @__PURE__ */ ((t) => (t.WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE", t.WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED", t.WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW", t.WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED", t.WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED", t.WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED", t.WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT", t.WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN", t.WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED", t.WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED", t.WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE", t.WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND", t.WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE", t.WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE", t.INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS", t.BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED", t.UNKNOWN = "UNKNOWN", t))(I || {}), a = /* @__PURE__ */ ((t) => (t.RAW = "raw", t.USER_OP = "userop", t.POLYMARKET_WALLET = "polymarket_wallet", t))(a || {});
14
- const n = new Set(Object.values(I));
15
- class N extends Error {
16
- constructor(s, D, _) {
17
- super(_ ?? D);
18
- E(this, "name", "WithdrawalApiError");
19
- this.status = s, this.code = D, this.detail = _;
13
+ var I = /* @__PURE__ */ ((e) => (e.WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE", e.WITHDRAW_TX_BLOCKHASH_EXPIRED = "WITHDRAW_TX_BLOCKHASH_EXPIRED", e.WITHDRAW_TX_NONCE_TOO_LOW = "WITHDRAW_TX_NONCE_TOO_LOW", e.WITHDRAW_TX_USEROP_EXPIRED = "WITHDRAW_TX_USEROP_EXPIRED", e.WITHDRAW_TX_UNDERPRICED = "WITHDRAW_TX_UNDERPRICED", e.WITHDRAW_BUNDLER_REJECTED = "WITHDRAW_BUNDLER_REJECTED", e.WITHDRAW_TX_BROADCAST_TIMEOUT = "WITHDRAW_TX_BROADCAST_TIMEOUT", e.WITHDRAW_TX_ALREADY_KNOWN = "WITHDRAW_TX_ALREADY_KNOWN", e.WITHDRAW_QUOTE_EXPIRED = "WITHDRAW_QUOTE_EXPIRED", e.WITHDRAW_SANCTIONS_BLOCKED = "WITHDRAW_SANCTIONS_BLOCKED", e.WITHDRAW_NO_ROUTE = "WITHDRAW_NO_ROUTE", e.WITHDRAW_NOT_FOUND = "WITHDRAW_NOT_FOUND", e.WITHDRAW_INSUFFICIENT_BALANCE = "WITHDRAW_INSUFFICIENT_BALANCE", e.WITHDRAW_DETAILS_NOT_UPDATABLE = "WITHDRAW_DETAILS_NOT_UPDATABLE", e.INVALID_WALLET_ADDRESS = "INVALID_WALLET_ADDRESS", e.BALANCE_FETCH_FAILED = "BALANCE_FETCH_FAILED", e.UNKNOWN = "UNKNOWN", e))(I || {}), i = /* @__PURE__ */ ((e) => (e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e))(i || {}), N = /* @__PURE__ */ ((e) => (e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e))(N || {});
14
+ const a = new Set(Object.values(I));
15
+ class O extends Error {
16
+ constructor(s, D, E) {
17
+ super(E ?? D);
18
+ T(this, "name", "WithdrawalApiError");
19
+ this.status = s, this.code = D, this.detail = E;
20
20
  }
21
21
  }
22
- const u = (t) => t && n.has(t) ? t : I.UNKNOWN, W = (t) => {
23
- const e = t.split(".");
24
- if (e.length !== 3)
22
+ const W = (e) => e && a.has(e) ? e : I.UNKNOWN, u = (e) => {
23
+ const t = e.split(".");
24
+ if (t.length !== 3)
25
25
  throw new Error("Invalid JWT: expected 3 parts");
26
- const s = atob(e[1].replace(/-/g, "+").replace(/_/g, "/"));
26
+ const s = atob(t[1].replace(/-/g, "+").replace(/_/g, "/"));
27
27
  return JSON.parse(s);
28
- }, L = (t, e = 5e3) => {
29
- const { exp: s } = W(t);
30
- return s === void 0 ? !1 : Date.now() >= s * 1e3 - e;
28
+ }, o = (e, t = 5e3) => {
29
+ const { exp: s } = u(e);
30
+ return s === void 0 ? !1 : Date.now() >= s * 1e3 - t;
31
31
  };
32
- class O {
33
- constructor(e) {
34
- E(this, "baseUrl");
35
- E(this, "headers");
36
- E(this, "fetch");
37
- if (!e.publicApiKey)
32
+ class c {
33
+ constructor(t) {
34
+ T(this, "baseUrl");
35
+ T(this, "headers");
36
+ T(this, "fetch");
37
+ if (!t.publicApiKey)
38
38
  throw new Error("publicApiKey is required");
39
- this.baseUrl = e.baseUrl.endsWith("/") ? e.baseUrl.slice(0, -1) : e.baseUrl, this.headers = {
39
+ this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.headers = {
40
40
  "Content-Type": "application/json",
41
- Authorization: `Bearer ${e.publicApiKey}`,
42
- ...e.headers
43
- }, this.fetch = e.fetch ?? globalThis.fetch.bind(globalThis);
41
+ Authorization: `Bearer ${t.publicApiKey}`,
42
+ ...t.headers
43
+ }, this.fetch = t.fetch ?? globalThis.fetch.bind(globalThis);
44
44
  }
45
- async get(e, s) {
46
- return this.request("GET", e, void 0, s);
45
+ async get(t, s) {
46
+ return this.request("GET", t, void 0, s);
47
47
  }
48
- async post(e, s, D) {
49
- return this.request("POST", e, s, D);
48
+ async post(t, s, D) {
49
+ return this.request("POST", t, s, D);
50
50
  }
51
- async patch(e, s, D) {
52
- return this.request("PATCH", e, s, D);
51
+ async patch(t, s, D) {
52
+ return this.request("PATCH", t, s, D);
53
53
  }
54
- async request(e, s, D, _) {
55
- const A = `${this.baseUrl}${s}`, T = await this.fetch(A, {
56
- method: e,
54
+ async request(t, s, D, E) {
55
+ const A = `${this.baseUrl}${s}`, _ = await this.fetch(A, {
56
+ method: t,
57
57
  headers: this.headers,
58
58
  body: D !== void 0 ? JSON.stringify(D) : void 0,
59
- signal: _
59
+ signal: E
60
60
  });
61
- if (!T.ok)
62
- throw await this.buildError(T);
63
- return await T.json();
61
+ if (!_.ok)
62
+ throw await this.buildError(_);
63
+ return await _.json();
64
64
  }
65
- async buildError(e) {
65
+ async buildError(t) {
66
66
  let s, D;
67
67
  try {
68
- const _ = await e.json();
69
- s = _.message ?? void 0, D = _.errorCode ?? _.errorType ?? void 0;
68
+ const E = await t.json();
69
+ s = E.message ?? void 0, D = E.errorCode ?? E.errorType ?? void 0;
70
70
  } catch {
71
- s = e.statusText || void 0;
71
+ s = t.statusText || void 0;
72
72
  }
73
- return new N(
74
- e.status,
75
- u(D),
73
+ return new O(
74
+ t.status,
75
+ W(D),
76
76
  s
77
77
  );
78
78
  }
79
79
  }
80
- class h {
81
- constructor(e) {
82
- E(this, "api");
83
- this.api = new O(e);
80
+ class U {
81
+ constructor(t) {
82
+ T(this, "api");
83
+ this.api = new c(t);
84
84
  }
85
- async getWithdrawalConfig(e, s) {
85
+ async getWithdrawalConfig(t, s) {
86
86
  return this.api.get(
87
- `/withdrawal-configs/${e}/public`,
87
+ `/withdrawal-configs/${t}/public`,
88
88
  s
89
89
  );
90
90
  }
91
- async getRoutes(e, s) {
92
- return this.api.get(`/withdraw/${e}/routes`, s);
91
+ async getRoutes(t, s) {
92
+ return this.api.get(`/withdraw/${t}/routes`, s);
93
93
  }
94
- async getBalance(e, s, D) {
94
+ async getBalance(t, s, D) {
95
95
  return this.api.get(
96
- `/withdraw/${e}/balance/${s}`,
96
+ `/withdraw/${t}/balances?walletAddress=${encodeURIComponent(
97
+ s
98
+ )}`,
97
99
  D
98
100
  );
99
101
  }
@@ -102,11 +104,11 @@ class h {
102
104
  * `withdrawalConfigId` goes in the path; the remaining fields are the
103
105
  * request body matching the backend `PreparedWithdrawalDto`.
104
106
  */
105
- async prepare(e, s) {
106
- const { withdrawalConfigId: D, ..._ } = e;
107
+ async prepare(t, s) {
108
+ const { withdrawalConfigId: D, ...E } = t;
107
109
  return this.api.post(
108
110
  `/withdraw/${D}/prepare`,
109
- _,
111
+ E,
110
112
  s
111
113
  );
112
114
  }
@@ -117,7 +119,7 @@ class h {
117
119
  * This stub is kept for forward compatibility. It will throw until
118
120
  * the backend ships the handler.
119
121
  */
120
- async updateQuote(e, s, D) {
122
+ async updateQuote(t, s, D) {
121
123
  throw new Error(
122
124
  "updateQuote is not yet supported by the backend. Create a new quote via prepare() instead."
123
125
  );
@@ -126,29 +128,27 @@ class h {
126
128
  * Body matches the backend `SubmitWithdrawalDto`:
127
129
  * `{ token, signedTx: { kind, signature } }`.
128
130
  */
129
- async submitWithdrawal(e, s) {
130
- const { withdrawalDetailId: D, ..._ } = e;
131
+ async submitWithdrawal(t, s) {
132
+ const { withdrawalDetailId: D, ...E } = t;
131
133
  return this.api.post(
132
134
  `/withdraw/${D}/submit`,
133
- _,
135
+ E,
134
136
  s
135
137
  );
136
138
  }
137
- async getStatus(e, s) {
138
- return this.api.get(`/withdraw/${e}/status`, s);
139
- }
140
- async getWithdrawalDetail(e, s) {
141
- return this.api.get(`/withdraw/${e}`, s);
139
+ async getWithdrawalDetail(t, s) {
140
+ return this.api.get(`/withdraw-details/${t}`, s);
142
141
  }
143
142
  }
144
143
  export {
145
- a as SignedTransactionKind,
146
- p as TERMINAL_STATES,
147
- N as WithdrawalApiError,
144
+ i as BroadcastAck,
145
+ N as SignedTransactionKind,
146
+ L as TERMINAL_STATES,
147
+ O as WithdrawalApiError,
148
148
  I as WithdrawalErrorCode,
149
- h as WithdrawalSDK,
150
- i as WithdrawalState,
151
- W as decodeJwt,
152
- L as isQuoteExpired,
153
- u as toWithdrawalErrorCode
149
+ U as WithdrawalSDK,
150
+ r as WithdrawalState,
151
+ u as decodeJwt,
152
+ o as isQuoteExpired,
153
+ W as toWithdrawalErrorCode
154
154
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@heliofi/withdraw-core",
3
3
  "private": false,
4
- "version": "0.0.7-alpha.1781007397",
4
+ "version": "0.0.8-alpha.1781276921",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",