@heliofi/withdraw-core 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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, CreateWithdrawalDetailParams, HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './types';
6
+ export type { BalanceResponse, BaseBlockchain, BlockchainEngine, CreateWithdrawalDetailParams, HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PopulatedBlockchain, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, SlimCurrencyWithPopulatedBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './types';
7
7
  export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './types';
@@ -1,4 +1,4 @@
1
1
  export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './enums';
2
2
  export type { HypercorePreparedTransaction, PolymarketWalletPreparedTransaction, PreparedTransaction, QuoteResponse, QuoteSummary, RawPreparedTransaction, UserOpPreparedTransaction, } from './prepared';
3
3
  export type { CreateWithdrawalDetailParams, SubmitWithdrawalParams, UpdateWithdrawalDetailParams, } from './requests';
4
- export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './responses';
4
+ export type { BalanceResponse, BaseBlockchain, BlockchainEngine, PopulatedBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, SlimCurrencyWithPopulatedBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './responses';
@@ -15,7 +15,8 @@ export interface CreateWithdrawalDetailParams {
15
15
  amount: string;
16
16
  /** Destination currency ID (MongoDB ObjectId). */
17
17
  toCurrencyId: string;
18
- sourceCurrencyId?: string;
18
+ /** Source currency ID (MongoDB ObjectId). */
19
+ sourceCurrencyId: string;
19
20
  }
20
21
  /**
21
22
  * Parameters for `PATCH /withdraw/:withdrawalDetailId/prepare`.
@@ -1,4 +1,4 @@
1
- import type { BlockchainSymbol, BroadcastAck, Platform, WithdrawalFeature, WithdrawalState } from './enums';
1
+ import type { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, WithdrawalFeature, WithdrawalState } from './enums';
2
2
  export interface WithdrawalCurrenciesExchangeRate {
3
3
  minimalUnitRate: string;
4
4
  decimalRate: string;
@@ -19,7 +19,7 @@ export interface WithdrawalConfig {
19
19
  createdAt: string;
20
20
  /** ISO 8601 timestamp. */
21
21
  updatedAt: string;
22
- fromCurrencies: SlimCurrencyWithBlockchain[];
22
+ fromCurrencies: SlimCurrencyWithPopulatedBlockchain[];
23
23
  exchangeRates: WithdrawalCurrenciesExchangeRate[];
24
24
  }
25
25
  export interface BaseBlockchain {
@@ -27,6 +27,29 @@ export interface BaseBlockchain {
27
27
  symbol: string;
28
28
  displayName: string;
29
29
  }
30
+ /**
31
+ * The blockchain engine (EVM / SOL / BTC / …) that owns the
32
+ * address-validation regex. Mirrors the backend `BlockchainEngine` entity.
33
+ */
34
+ export interface BlockchainEngine {
35
+ id: string;
36
+ type: BlockchainEngineType;
37
+ /**
38
+ * Network-aware (testnet vs mainnet) source string for an address-validation
39
+ * regex, e.g. `^[1-9A-HJ-NP-Za-km-z]{32,44}$` for SOL. Present on the
40
+ * withdrawal `/routes` and `/public` responses; may be absent for engines
41
+ * without a configured regex.
42
+ */
43
+ addressRegex?: string;
44
+ }
45
+ /**
46
+ * A blockchain guaranteed to have its `engine` populated (with the engine's
47
+ * address-validation regex). Mirrors the backend `Blockchain` entity. Used by
48
+ * the withdrawal `/routes` and `/public` responses.
49
+ */
50
+ export interface PopulatedBlockchain extends BaseBlockchain {
51
+ engine: BlockchainEngine;
52
+ }
30
53
  export interface SlimCurrencyWithBlockchain {
31
54
  id: string;
32
55
  symbol: string;
@@ -35,17 +58,26 @@ export interface SlimCurrencyWithBlockchain {
35
58
  decimals: number;
36
59
  blockchain: BaseBlockchain;
37
60
  }
61
+ /**
62
+ * `SlimCurrencyWithBlockchain` whose blockchain is guaranteed populated with its
63
+ * engine (and the engine's address regex). Mirrors the backend
64
+ * `SlimCurrencyWithPopulatedBlockchain` entity — the type of `fromCurrencies`
65
+ * on the withdrawal `/routes` and `/public` responses.
66
+ */
67
+ export type SlimCurrencyWithPopulatedBlockchain = Omit<SlimCurrencyWithBlockchain, 'blockchain'> & {
68
+ blockchain: PopulatedBlockchain;
69
+ };
38
70
  export interface WithdrawalCustomerSwapRoute {
39
71
  id: string;
40
72
  fromCurrencyId: string;
41
- toCurrency: SlimCurrencyWithBlockchain;
73
+ toCurrency: SlimCurrencyWithPopulatedBlockchain;
42
74
  available: boolean;
43
75
  minimumAmountMinimalUnit: string | null;
44
76
  minimumAmountUsd: string;
45
77
  }
46
78
  export interface RoutesResponse {
47
79
  /** Source currencies available under the merchant's config. */
48
- fromCurrencies: SlimCurrencyWithBlockchain[];
80
+ fromCurrencies: SlimCurrencyWithPopulatedBlockchain[];
49
81
  routes: WithdrawalCustomerSwapRoute[];
50
82
  }
51
83
  export interface WalletCurrencyBalance {
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var i=(e,t,E)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):e[t]=E;var r=(e,t,E)=>i(e,typeof t!="symbol"?t+"":t,E);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let u=(function(e){return e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e})({}),W=(function(e){return e.EVM="EVM",e.SOL="SOL",e.BTC="BTC",e.TRON="TRON",e.HYPERCORE="HYPERCORE",e.DOGE="DOGE",e})({}),o=(function(e){return e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e})({}),L=(function(e){return e.IRON="iron",e.MP_SELL="mp_sell",e})({}),T=(function(e){return 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})({}),c=(function(e){return e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e})({}),U=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const H=new Set([T.COMPLETED,T.FAILED,T.FAILED_EXPIRED,T.EXPIRED,T.REFUNDED_BY_PROVIDER]);var I=(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||{});const C=new Set(Object.values(I));class A extends Error{constructor(E,s,D){super(D??s);r(this,"name","WithdrawalApiError");this.status=E,this.code=s,this.detail=D}}const n=e=>e&&C.has(e)?e:I.UNKNOWN,O=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const E=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(E)},l=(e,t=5e3)=>{const{exp:E}=O(e);return E===void 0?!1:Date.now()>=E*1e3-t},p="0.5.0";class P{constructor(t){r(this,"baseUrl");r(this,"headers");r(this,"fetch");var E,s;this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json","X-MoonPay-Commerce-SDK-Version":p,...(E=t.consumer)!=null&&E.name?{"X-MoonPay-Commerce-Consumer":t.consumer.name}:{},...(s=t.consumer)!=null&&s.version?{"X-MoonPay-Commerce-Consumer-Version":t.consumer.version}:{},...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,E){return this.request("GET",t,void 0,E)}async post(t,E,s){return this.request("POST",t,E,s)}async patch(t,E,s){return this.request("PATCH",t,E,s)}async request(t,E,s,D){const a=`${this.baseUrl}${E}`,_=await this.fetch(a,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:D});if(!_.ok)throw await this.buildError(_);return await _.json()}async buildError(t){let E,s;try{const D=await t.json();E=D.message??void 0,s=D.errorCode??D.errorType??void 0}catch{E=t.statusText||void 0}return new A(t.status,n(s),E)}}class R{constructor(t){this.api=t}static create(t){return new R(new P(t))}async getWithdrawalConfig(t,E){return this.api.get(`/withdrawal-configs/${t}/public`,E)}async getRoutes(t,E){return this.api.get(`/withdraw/${t}/routes`,E)}async getBalance(t,E,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(E)}`,s)}async createWithdrawalDetail(t,E){const{withdrawalConfigId:s,...D}=t;return this.api.post(`/withdraw/${s}/prepare`,D,E)}async updateWithdrawalDetail(t,E,s){throw new Error("updateWithdrawalDetail is not yet supported by the backend. Create a new withdrawal detail via createWithdrawalDetail() instead.")}async submitWithdrawal(t,E){const{withdrawalDetailId:s,...D}=t;return this.api.post(`/withdraw/${s}/submit`,D,E)}async getWithdrawalDetail(t,E){return this.api.get(`/withdraw-details/${t}`,E)}}exports.BlockchainEngineType=W;exports.BlockchainSymbol=u;exports.BroadcastAck=c;exports.Platform=o;exports.SignedTransactionKind=U;exports.TERMINAL_STATES=H;exports.WithdrawalApiError=A;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=L;exports.WithdrawalSDK=R;exports.WithdrawalState=T;exports.decodeJwt=O;exports.isQuoteExpired=l;exports.toWithdrawalErrorCode=n;
1
+ "use strict";var N=Object.defineProperty;var i=(e,t,E)=>t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):e[t]=E;var r=(e,t,E)=>i(e,typeof t!="symbol"?t+"":t,E);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let u=(function(e){return e.SOL="SOL",e.ETH="ETH",e.POLYGON="POLYGON",e.BASE="BASE",e.BITCOIN="BITCOIN",e.ARBITRUM="ARBITRUM",e.BSC="BSC",e.TRON="TRON",e.DOGE="DOGE",e})({}),W=(function(e){return e.EVM="EVM",e.SOL="SOL",e.BTC="BTC",e.TRON="TRON",e.HYPERCORE="HYPERCORE",e.DOGE="DOGE",e})({}),o=(function(e){return e.HELIO="HELIO",e.MAGIC_EDEN="MAGIC_EDEN",e})({}),L=(function(e){return e.IRON="iron",e.MP_SELL="mp_sell",e})({}),T=(function(e){return 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})({}),c=(function(e){return e.ACKNOWLEDGED="acknowledged",e.UNACKNOWLEDGED="unacknowledged",e.REJECTED="rejected",e})({}),U=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const H=new Set([T.COMPLETED,T.FAILED,T.FAILED_EXPIRED,T.EXPIRED,T.REFUNDED_BY_PROVIDER]);var I=(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||{});const C=new Set(Object.values(I));class A extends Error{constructor(E,s,D){super(D??s);r(this,"name","WithdrawalApiError");this.status=E,this.code=s,this.detail=D}}const n=e=>e&&C.has(e)?e:I.UNKNOWN,O=e=>{const t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected 3 parts");const E=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(E)},l=(e,t=5e3)=>{const{exp:E}=O(e);return E===void 0?!1:Date.now()>=E*1e3-t},p="0.7.0";class P{constructor(t){r(this,"baseUrl");r(this,"headers");r(this,"fetch");var E,s;this.baseUrl=t.baseUrl.endsWith("/")?t.baseUrl.slice(0,-1):t.baseUrl,this.headers={"Content-Type":"application/json","X-MoonPay-Commerce-SDK-Version":p,...(E=t.consumer)!=null&&E.name?{"X-MoonPay-Commerce-Consumer":t.consumer.name}:{},...(s=t.consumer)!=null&&s.version?{"X-MoonPay-Commerce-Consumer-Version":t.consumer.version}:{},...t.headers},this.fetch=t.fetch??globalThis.fetch.bind(globalThis)}async get(t,E){return this.request("GET",t,void 0,E)}async post(t,E,s){return this.request("POST",t,E,s)}async patch(t,E,s){return this.request("PATCH",t,E,s)}async request(t,E,s,D){const a=`${this.baseUrl}${E}`,_=await this.fetch(a,{method:t,headers:this.headers,body:s!==void 0?JSON.stringify(s):void 0,signal:D});if(!_.ok)throw await this.buildError(_);return await _.json()}async buildError(t){let E,s;try{const D=await t.json();E=D.message??void 0,s=D.errorCode??D.errorType??void 0}catch{E=t.statusText||void 0}return new A(t.status,n(s),E)}}class R{constructor(t){this.api=t}static create(t){return new R(new P(t))}async getWithdrawalConfig(t,E){return this.api.get(`/withdrawal-configs/${t}/public`,E)}async getRoutes(t,E){return this.api.get(`/withdraw/${t}/routes`,E)}async getBalance(t,E,s){return this.api.get(`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(E)}`,s)}async createWithdrawalDetail(t,E){const{withdrawalConfigId:s,...D}=t;return this.api.post(`/withdraw/${s}/prepare`,D,E)}async updateWithdrawalDetail(t,E,s){throw new Error("updateWithdrawalDetail is not yet supported by the backend. Create a new withdrawal detail via createWithdrawalDetail() instead.")}async submitWithdrawal(t,E){const{withdrawalDetailId:s,...D}=t;return this.api.post(`/withdraw/${s}/submit`,D,E)}async getWithdrawalDetail(t,E){return this.api.get(`/withdraw-details/${t}`,E)}}exports.BlockchainEngineType=W;exports.BlockchainSymbol=u;exports.BroadcastAck=c;exports.Platform=o;exports.SignedTransactionKind=U;exports.TERMINAL_STATES=H;exports.WithdrawalApiError=A;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=L;exports.WithdrawalSDK=R;exports.WithdrawalState=T;exports.decodeJwt=O;exports.isQuoteExpired=l;exports.toWithdrawalErrorCode=n;
@@ -41,7 +41,7 @@ const W = (e) => e && N.has(e) ? e : R.UNKNOWN, a = (e) => {
41
41
  }, l = (e, t = 5e3) => {
42
42
  const { exp: E } = a(e);
43
43
  return E === void 0 ? !1 : Date.now() >= E * 1e3 - t;
44
- }, i = "0.5.0";
44
+ }, i = "0.7.0";
45
45
  class L {
46
46
  constructor(t) {
47
47
  T(this, "baseUrl");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@heliofi/withdraw-core",
3
3
  "private": false,
4
- "version": "0.5.0",
4
+ "version": "0.7.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",