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