@heliofi/withdraw-core 0.3.3-alpha.1782827814 → 0.4.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/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/types/enums.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/responses.d.ts +1 -1
- package/dist/withdraw-core.cjs +1 -1
- package/dist/withdraw-core.js +115 -214
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { decodeJwt, isQuoteExpired } from './jwt';
|
|
|
4
4
|
export type { ApiClientConfig } from './sdk';
|
|
5
5
|
export { WithdrawalSDK } from './sdk';
|
|
6
6
|
export type { BalanceResponse, BaseBlockchain, PolymarketWalletPreparedTransaction, PreparedTransaction, PrepareWithdrawalParams, QuoteResponse, QuoteSummary, RawPreparedTransaction, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, SubmitWithdrawalParams, UpdateQuoteParams, UserOpPreparedTransaction, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './types';
|
|
7
|
-
export {
|
|
7
|
+
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, WithdrawalState, } from './types';
|
package/dist/types/enums.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, WithdrawalFeature, WithdrawalState } from '@heliofi/common-fe';
|
|
2
|
+
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, WithdrawalFeature, WithdrawalState, };
|
|
3
3
|
export declare const TERMINAL_STATES: ReadonlySet<WithdrawalState>;
|
|
4
4
|
export declare enum WithdrawalErrorCode {
|
|
5
5
|
WITHDRAW_TX_INVALID_SIGNATURE = "WITHDRAW_TX_INVALID_SIGNATURE",
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BlockchainEngineType, BlockchainSymbol, BroadcastAck, Platform, SignedTransactionKind, TERMINAL_STATES, WithdrawalErrorCode, WithdrawalFeature, 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
4
|
export type { BalanceResponse, BaseBlockchain, RoutesResponse, SlimCurrencyWithBlockchain, StatusResponse, SubmitResponse, WalletCurrencyBalance, WithdrawalConfig, WithdrawalCurrenciesExchangeRate, WithdrawalCustomerSwapRoute, } from './responses';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BlockchainSymbol, BroadcastAck, Platform, WithdrawalFeature, WithdrawalState } from './enums';
|
|
2
2
|
export interface WithdrawalCurrenciesExchangeRate {
|
|
3
3
|
minimalUnitRate: string;
|
|
4
4
|
decimalRate: string;
|
package/dist/withdraw-core.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var a=(e,t,E)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:E}):e[t]=E;var r=(e,t,E)=>a(e,typeof t!="symbol"?t+"":t,E);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let i=(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})({}),p=(function(e){return e.RAW="raw",e.USER_OP="userop",e.POLYMARKET_WALLET="polymarket_wallet",e.HYPERCORE="hypercore",e})({});const U=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 H=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&&H.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)},C=(e,t=5e3)=>{const{exp:E}=O(e);return E===void 0?!1:Date.now()>=E*1e3-t},P="0.4.0";class S{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 N=`${this.baseUrl}${E}`,_=await this.fetch(N,{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 S(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 prepare(t,E){const{withdrawalConfigId:s,...D}=t;return this.api.post(`/withdraw/${s}/prepare`,D,E)}async updateQuote(t,E,s){throw new Error("updateQuote is not yet supported by the backend. Create a new quote via prepare() 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=i;exports.BroadcastAck=c;exports.Platform=o;exports.SignedTransactionKind=p;exports.TERMINAL_STATES=U;exports.WithdrawalApiError=A;exports.WithdrawalErrorCode=I;exports.WithdrawalFeature=L;exports.WithdrawalSDK=R;exports.WithdrawalState=T;exports.decodeJwt=O;exports.isQuoteExpired=C;exports.toWithdrawalErrorCode=n;
|
package/dist/withdraw-core.js
CHANGED
|
@@ -1,219 +1,121 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
var o = {}, h;
|
|
27
|
-
function H() {
|
|
28
|
-
if (h) return o;
|
|
29
|
-
h = 1, Object.defineProperty(o, "__esModule", { value: !0 }), o.PLATFORM_HEADER_NAME = o.toPlatform = o.Platform = void 0;
|
|
30
|
-
var t;
|
|
31
|
-
(function(r) {
|
|
32
|
-
r.HELIO = "HELIO", r.MAGIC_EDEN = "MAGIC_EDEN";
|
|
33
|
-
})(t || (o.Platform = t = {}));
|
|
34
|
-
const e = (r) => {
|
|
35
|
-
switch (r) {
|
|
36
|
-
case t.HELIO:
|
|
37
|
-
return t.HELIO;
|
|
38
|
-
case t.MAGIC_EDEN:
|
|
39
|
-
return t.MAGIC_EDEN;
|
|
40
|
-
default:
|
|
41
|
-
throw new Error("Platform not supported");
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return o.toPlatform = e, o.PLATFORM_HEADER_NAME = "x-platform", o;
|
|
45
|
-
}
|
|
46
|
-
var T = {}, W;
|
|
47
|
-
function m() {
|
|
48
|
-
if (W) return T;
|
|
49
|
-
W = 1, Object.defineProperty(T, "__esModule", { value: !0 }), T.WithdrawalFeature = void 0;
|
|
50
|
-
var t;
|
|
51
|
-
return (function(e) {
|
|
52
|
-
e.IRON = "iron", e.MP_SELL = "mp_sell";
|
|
53
|
-
})(t || (T.WithdrawalFeature = t = {})), T;
|
|
54
|
-
}
|
|
55
|
-
var d = {}, N;
|
|
56
|
-
function b() {
|
|
57
|
-
if (N) return d;
|
|
58
|
-
N = 1, Object.defineProperty(d, "__esModule", { value: !0 }), d.WithdrawalState = void 0;
|
|
59
|
-
var t;
|
|
60
|
-
return (function(e) {
|
|
61
|
-
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";
|
|
62
|
-
})(t || (d.WithdrawalState = t = {})), d;
|
|
63
|
-
}
|
|
64
|
-
var _ = {}, S;
|
|
65
|
-
function U() {
|
|
66
|
-
if (S) return _;
|
|
67
|
-
S = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.BroadcastAck = void 0;
|
|
68
|
-
var t;
|
|
69
|
-
return (function(e) {
|
|
70
|
-
e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected";
|
|
71
|
-
})(t || (_.BroadcastAck = t = {})), _;
|
|
72
|
-
}
|
|
73
|
-
var l = {}, P;
|
|
74
|
-
function C() {
|
|
75
|
-
if (P) return l;
|
|
76
|
-
P = 1, Object.defineProperty(l, "__esModule", { value: !0 }), l.SignedTransactionKind = void 0;
|
|
77
|
-
var t;
|
|
78
|
-
return (function(e) {
|
|
79
|
-
e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet";
|
|
80
|
-
})(t || (l.SignedTransactionKind = t = {})), l;
|
|
81
|
-
}
|
|
82
|
-
var f;
|
|
83
|
-
function g() {
|
|
84
|
-
return f || (f = 1, (function(t) {
|
|
85
|
-
Object.defineProperty(t, "__esModule", { value: !0 }), t.SignedTransactionKind = t.BroadcastAck = t.WithdrawalState = t.WithdrawalFeature = t.Platform = t.BlockchainEngineType = t.BlockchainSymbol = void 0;
|
|
86
|
-
var e = B();
|
|
87
|
-
Object.defineProperty(t, "BlockchainSymbol", { enumerable: !0, get: function() {
|
|
88
|
-
return e.BlockchainSymbol;
|
|
89
|
-
} });
|
|
90
|
-
var r = y();
|
|
91
|
-
Object.defineProperty(t, "BlockchainEngineType", { enumerable: !0, get: function() {
|
|
92
|
-
return r.BlockchainEngineType;
|
|
93
|
-
} });
|
|
94
|
-
var a = H();
|
|
95
|
-
Object.defineProperty(t, "Platform", { enumerable: !0, get: function() {
|
|
96
|
-
return a.Platform;
|
|
97
|
-
} });
|
|
98
|
-
var n = m();
|
|
99
|
-
Object.defineProperty(t, "WithdrawalFeature", { enumerable: !0, get: function() {
|
|
100
|
-
return n.WithdrawalFeature;
|
|
101
|
-
} });
|
|
102
|
-
var A = b();
|
|
103
|
-
Object.defineProperty(t, "WithdrawalState", { enumerable: !0, get: function() {
|
|
104
|
-
return A.WithdrawalState;
|
|
105
|
-
} });
|
|
106
|
-
var c = U();
|
|
107
|
-
Object.defineProperty(t, "BroadcastAck", { enumerable: !0, get: function() {
|
|
108
|
-
return c.BroadcastAck;
|
|
109
|
-
} });
|
|
110
|
-
var L = C();
|
|
111
|
-
Object.defineProperty(t, "SignedTransactionKind", { enumerable: !0, get: function() {
|
|
112
|
-
return L.SignedTransactionKind;
|
|
113
|
-
} });
|
|
114
|
-
})(D)), D;
|
|
115
|
-
}
|
|
116
|
-
var i = g();
|
|
117
|
-
const $ = /* @__PURE__ */ new Set([
|
|
118
|
-
i.WithdrawalState.COMPLETED,
|
|
119
|
-
i.WithdrawalState.FAILED,
|
|
120
|
-
i.WithdrawalState.FAILED_EXPIRED,
|
|
121
|
-
i.WithdrawalState.EXPIRED,
|
|
122
|
-
i.WithdrawalState.REFUNDED_BY_PROVIDER
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var n = (e, t, E) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: E }) : e[t] = E;
|
|
3
|
+
var T = (e, t, E) => n(e, typeof t != "symbol" ? t + "" : t, E);
|
|
4
|
+
let o = /* @__PURE__ */ (function(e) {
|
|
5
|
+
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;
|
|
6
|
+
})({}), a = /* @__PURE__ */ (function(e) {
|
|
7
|
+
return e.EVM = "EVM", e.SOL = "SOL", e.BTC = "BTC", e.TRON = "TRON", e.HYPERCORE = "HYPERCORE", e.DOGE = "DOGE", e;
|
|
8
|
+
})({}), p = /* @__PURE__ */ (function(e) {
|
|
9
|
+
return e.HELIO = "HELIO", e.MAGIC_EDEN = "MAGIC_EDEN", e;
|
|
10
|
+
})({}), C = /* @__PURE__ */ (function(e) {
|
|
11
|
+
return e.IRON = "iron", e.MP_SELL = "mp_sell", e;
|
|
12
|
+
})({}), I = /* @__PURE__ */ (function(e) {
|
|
13
|
+
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;
|
|
14
|
+
})({}), c = /* @__PURE__ */ (function(e) {
|
|
15
|
+
return e.ACKNOWLEDGED = "acknowledged", e.UNACKNOWLEDGED = "unacknowledged", e.REJECTED = "rejected", e;
|
|
16
|
+
})({}), P = /* @__PURE__ */ (function(e) {
|
|
17
|
+
return e.RAW = "raw", e.USER_OP = "userop", e.POLYMARKET_WALLET = "polymarket_wallet", e.HYPERCORE = "hypercore", e;
|
|
18
|
+
})({});
|
|
19
|
+
const X = /* @__PURE__ */ new Set([
|
|
20
|
+
I.COMPLETED,
|
|
21
|
+
I.FAILED,
|
|
22
|
+
I.FAILED_EXPIRED,
|
|
23
|
+
I.EXPIRED,
|
|
24
|
+
I.REFUNDED_BY_PROVIDER
|
|
123
25
|
]);
|
|
124
|
-
var R = /* @__PURE__ */ ((
|
|
125
|
-
const
|
|
126
|
-
class
|
|
127
|
-
constructor(
|
|
128
|
-
super(
|
|
129
|
-
|
|
130
|
-
this.status =
|
|
26
|
+
var R = /* @__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))(R || {});
|
|
27
|
+
const N = new Set(Object.values(R));
|
|
28
|
+
class u extends Error {
|
|
29
|
+
constructor(E, s, D) {
|
|
30
|
+
super(D ?? s);
|
|
31
|
+
T(this, "name", "WithdrawalApiError");
|
|
32
|
+
this.status = E, this.code = s, this.detail = D;
|
|
131
33
|
}
|
|
132
34
|
}
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
35
|
+
const L = (e) => e && N.has(e) ? e : R.UNKNOWN, W = (e) => {
|
|
36
|
+
const t = e.split(".");
|
|
37
|
+
if (t.length !== 3)
|
|
136
38
|
throw new Error("Invalid JWT: expected 3 parts");
|
|
137
|
-
const
|
|
138
|
-
return JSON.parse(
|
|
139
|
-
},
|
|
140
|
-
const { exp:
|
|
141
|
-
return
|
|
142
|
-
},
|
|
143
|
-
class
|
|
144
|
-
constructor(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var
|
|
149
|
-
this.baseUrl =
|
|
39
|
+
const E = atob(t[1].replace(/-/g, "+").replace(/_/g, "/"));
|
|
40
|
+
return JSON.parse(E);
|
|
41
|
+
}, S = (e, t = 5e3) => {
|
|
42
|
+
const { exp: E } = W(e);
|
|
43
|
+
return E === void 0 ? !1 : Date.now() >= E * 1e3 - t;
|
|
44
|
+
}, i = "0.4.0";
|
|
45
|
+
class U {
|
|
46
|
+
constructor(t) {
|
|
47
|
+
T(this, "baseUrl");
|
|
48
|
+
T(this, "headers");
|
|
49
|
+
T(this, "fetch");
|
|
50
|
+
var E, s;
|
|
51
|
+
this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.headers = {
|
|
150
52
|
"Content-Type": "application/json",
|
|
151
53
|
// Every request self-identifies with the client version (always sent).
|
|
152
|
-
"X-MoonPay-Commerce-SDK-Version":
|
|
153
|
-
...(
|
|
154
|
-
...(
|
|
155
|
-
...
|
|
156
|
-
}, this.fetch =
|
|
54
|
+
"X-MoonPay-Commerce-SDK-Version": i,
|
|
55
|
+
...(E = t.consumer) != null && E.name ? { "X-MoonPay-Commerce-Consumer": t.consumer.name } : {},
|
|
56
|
+
...(s = t.consumer) != null && s.version ? { "X-MoonPay-Commerce-Consumer-Version": t.consumer.version } : {},
|
|
57
|
+
...t.headers
|
|
58
|
+
}, this.fetch = t.fetch ?? globalThis.fetch.bind(globalThis);
|
|
157
59
|
}
|
|
158
|
-
async get(
|
|
159
|
-
return this.request("GET",
|
|
60
|
+
async get(t, E) {
|
|
61
|
+
return this.request("GET", t, void 0, E);
|
|
160
62
|
}
|
|
161
|
-
async post(
|
|
162
|
-
return this.request("POST",
|
|
63
|
+
async post(t, E, s) {
|
|
64
|
+
return this.request("POST", t, E, s);
|
|
163
65
|
}
|
|
164
|
-
async patch(
|
|
165
|
-
return this.request("PATCH",
|
|
66
|
+
async patch(t, E, s) {
|
|
67
|
+
return this.request("PATCH", t, E, s);
|
|
166
68
|
}
|
|
167
|
-
async request(
|
|
168
|
-
const
|
|
169
|
-
method:
|
|
69
|
+
async request(t, E, s, D) {
|
|
70
|
+
const r = `${this.baseUrl}${E}`, _ = await this.fetch(r, {
|
|
71
|
+
method: t,
|
|
170
72
|
headers: this.headers,
|
|
171
|
-
body:
|
|
172
|
-
signal:
|
|
73
|
+
body: s !== void 0 ? JSON.stringify(s) : void 0,
|
|
74
|
+
signal: D
|
|
173
75
|
});
|
|
174
|
-
if (!
|
|
175
|
-
throw await this.buildError(
|
|
176
|
-
return await
|
|
76
|
+
if (!_.ok)
|
|
77
|
+
throw await this.buildError(_);
|
|
78
|
+
return await _.json();
|
|
177
79
|
}
|
|
178
|
-
async buildError(
|
|
179
|
-
let
|
|
80
|
+
async buildError(t) {
|
|
81
|
+
let E, s;
|
|
180
82
|
try {
|
|
181
|
-
const
|
|
182
|
-
|
|
83
|
+
const D = await t.json();
|
|
84
|
+
E = D.message ?? void 0, s = D.errorCode ?? D.errorType ?? void 0;
|
|
183
85
|
} catch {
|
|
184
|
-
|
|
86
|
+
E = t.statusText || void 0;
|
|
185
87
|
}
|
|
186
|
-
return new
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
88
|
+
return new u(
|
|
89
|
+
t.status,
|
|
90
|
+
L(s),
|
|
91
|
+
E
|
|
190
92
|
);
|
|
191
93
|
}
|
|
192
94
|
}
|
|
193
|
-
class
|
|
95
|
+
class A {
|
|
194
96
|
// Takes a prebuilt ApiClient (DI). Use `WithdrawalSDK.create()` for the
|
|
195
97
|
// common case where you just have config.
|
|
196
|
-
constructor(
|
|
197
|
-
this.api =
|
|
98
|
+
constructor(t) {
|
|
99
|
+
this.api = t;
|
|
198
100
|
}
|
|
199
|
-
static create(
|
|
200
|
-
return new
|
|
101
|
+
static create(t) {
|
|
102
|
+
return new A(new U(t));
|
|
201
103
|
}
|
|
202
|
-
async getWithdrawalConfig(
|
|
104
|
+
async getWithdrawalConfig(t, E) {
|
|
203
105
|
return this.api.get(
|
|
204
|
-
`/withdrawal-configs/${
|
|
205
|
-
|
|
106
|
+
`/withdrawal-configs/${t}/public`,
|
|
107
|
+
E
|
|
206
108
|
);
|
|
207
109
|
}
|
|
208
|
-
async getRoutes(
|
|
209
|
-
return this.api.get(`/withdraw/${
|
|
110
|
+
async getRoutes(t, E) {
|
|
111
|
+
return this.api.get(`/withdraw/${t}/routes`, E);
|
|
210
112
|
}
|
|
211
|
-
async getBalance(
|
|
113
|
+
async getBalance(t, E, s) {
|
|
212
114
|
return this.api.get(
|
|
213
|
-
`/withdraw/${
|
|
214
|
-
|
|
115
|
+
`/withdraw/${t}/balances?walletAddress=${encodeURIComponent(
|
|
116
|
+
E
|
|
215
117
|
)}`,
|
|
216
|
-
|
|
118
|
+
s
|
|
217
119
|
);
|
|
218
120
|
}
|
|
219
121
|
/**
|
|
@@ -221,12 +123,12 @@ class v {
|
|
|
221
123
|
* `withdrawalConfigId` goes in the path; the remaining fields are the
|
|
222
124
|
* request body matching the backend `PreparedWithdrawalDto`.
|
|
223
125
|
*/
|
|
224
|
-
async prepare(
|
|
225
|
-
const { withdrawalConfigId:
|
|
126
|
+
async prepare(t, E) {
|
|
127
|
+
const { withdrawalConfigId: s, ...D } = t;
|
|
226
128
|
return this.api.post(
|
|
227
|
-
`/withdraw/${
|
|
228
|
-
|
|
229
|
-
|
|
129
|
+
`/withdraw/${s}/prepare`,
|
|
130
|
+
D,
|
|
131
|
+
E
|
|
230
132
|
);
|
|
231
133
|
}
|
|
232
134
|
/**
|
|
@@ -236,7 +138,7 @@ class v {
|
|
|
236
138
|
* This stub is kept for forward compatibility. It will throw until
|
|
237
139
|
* the backend ships the handler.
|
|
238
140
|
*/
|
|
239
|
-
async updateQuote(
|
|
141
|
+
async updateQuote(t, E, s) {
|
|
240
142
|
throw new Error(
|
|
241
143
|
"updateQuote is not yet supported by the backend. Create a new quote via prepare() instead."
|
|
242
144
|
);
|
|
@@ -245,32 +147,31 @@ class v {
|
|
|
245
147
|
* Body matches the backend `SubmitWithdrawalDto`:
|
|
246
148
|
* `{ token, signedTx }`, where `signedTx` is the bare signed payload string.
|
|
247
149
|
*/
|
|
248
|
-
async submitWithdrawal(
|
|
249
|
-
const { withdrawalDetailId:
|
|
150
|
+
async submitWithdrawal(t, E) {
|
|
151
|
+
const { withdrawalDetailId: s, ...D } = t;
|
|
250
152
|
return this.api.post(
|
|
251
|
-
`/withdraw/${
|
|
252
|
-
|
|
253
|
-
|
|
153
|
+
`/withdraw/${s}/submit`,
|
|
154
|
+
D,
|
|
155
|
+
E
|
|
254
156
|
);
|
|
255
157
|
}
|
|
256
|
-
async getWithdrawalDetail(
|
|
257
|
-
return this.api.get(`/withdraw-details/${
|
|
158
|
+
async getWithdrawalDetail(t, E) {
|
|
159
|
+
return this.api.get(`/withdraw-details/${t}`, E);
|
|
258
160
|
}
|
|
259
161
|
}
|
|
260
|
-
const Y = i.BlockchainEngineType, V = i.BlockchainSymbol, Q = i.BroadcastAck, J = i.Platform, z = i.SignedTransactionKind, Z = i.WithdrawalFeature, x = i.WithdrawalState;
|
|
261
162
|
export {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
163
|
+
a as BlockchainEngineType,
|
|
164
|
+
o as BlockchainSymbol,
|
|
165
|
+
c as BroadcastAck,
|
|
166
|
+
p as Platform,
|
|
167
|
+
P as SignedTransactionKind,
|
|
168
|
+
X as TERMINAL_STATES,
|
|
169
|
+
u as WithdrawalApiError,
|
|
269
170
|
R as WithdrawalErrorCode,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
171
|
+
C as WithdrawalFeature,
|
|
172
|
+
A as WithdrawalSDK,
|
|
173
|
+
I as WithdrawalState,
|
|
174
|
+
W as decodeJwt,
|
|
175
|
+
S as isQuoteExpired,
|
|
176
|
+
L as toWithdrawalErrorCode
|
|
276
177
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliofi/withdraw-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"vitest": "3.2.4"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@heliofi/common": "0.2.
|
|
44
|
+
"@heliofi/common-fe": "0.2.278-alpha.1782920922"
|
|
45
45
|
}
|
|
46
46
|
}
|