@swapkit/helpers 1.0.0-rc.9 → 1.0.0-rc.91
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.js +2099 -0
- package/dist/index.js.map +29 -0
- package/package.json +24 -37
- package/src/helpers/__tests__/asset.test.ts +126 -108
- package/src/helpers/__tests__/memo.test.ts +52 -40
- package/src/helpers/__tests__/others.test.ts +42 -37
- package/src/helpers/__tests__/validators.test.ts +24 -0
- package/src/helpers/asset.ts +118 -93
- package/src/helpers/derivationPath.ts +52 -0
- package/src/helpers/liquidity.ts +50 -43
- package/src/helpers/memo.ts +31 -28
- package/src/helpers/others.ts +30 -13
- package/src/helpers/validators.ts +15 -6
- package/src/helpers/web3wallets.ts +178 -0
- package/src/index.ts +14 -9
- package/src/modules/__tests__/assetValue.test.ts +325 -116
- package/src/modules/__tests__/bigIntArithmetics.test.ts +30 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +306 -183
- package/src/modules/assetValue.ts +216 -152
- package/src/modules/bigIntArithmetics.ts +214 -147
- package/src/modules/requestClient.ts +29 -0
- package/src/modules/swapKitError.ts +32 -5
- package/src/modules/swapKitNumber.ts +8 -1
- package/src/types/abis/erc20.ts +99 -0
- package/src/types/abis/tcEthVault.ts +496 -0
- package/src/types/chains.ts +220 -0
- package/src/types/commonTypes.ts +119 -0
- package/src/types/derivationPath.ts +56 -0
- package/src/types/index.ts +9 -0
- package/src/types/network.ts +43 -0
- package/src/types/sdk.ts +44 -0
- package/src/types/tokens.ts +30 -0
- package/src/types/wallet.ts +47 -0
- package/LICENSE +0 -201
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -354
- package/dist/index.es.js +0 -1054
- package/src/helpers/request.ts +0 -16
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2023 THORSwap
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var Ae=Object.create;var N=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Ie=(s,e,t)=>e in s?N(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Be=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Se(e))!ve.call(s,n)&&n!==t&&N(s,n,{get:()=>e[n],enumerable:!(r=Te(e,n))||r.enumerable});return s};var $e=(s,e,t)=>(t=s!=null?Ae(Re(s)):{},Be(e||!s||!s.__esModule?N(t,"default",{value:s,enumerable:!0}):t,s));var p=(s,e,t)=>(Ie(s,typeof e!="symbol"?e+"":e,t),t),Ee=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var _=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var m=(s,e,t)=>(Ee(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@swapkit/types"),Oe="0x313ce567",re=async({chain:s,to:e})=>{try{const{result:t}=await pe.post(i.ChainToRPC[s],{headers:{accept:"*/*","cache-control":"no-cache"},body:JSON.stringify({id:44,jsonrpc:"2.0",method:"eth_call",params:[{to:e.toLowerCase(),data:Oe},"latest"]})});return parseInt(BigInt(t).toString())}catch(t){return console.error(t),i.BaseDecimal[s]}},Me=async s=>{if(s===i.Chain.Ethereum)return i.BaseDecimal.ETH;const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?re({chain:i.Chain.Ethereum,to:e}):i.BaseDecimal.ETH},ke=async s=>{const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?re({chain:i.Chain.Avalanche,to:e.toLowerCase()}):i.BaseDecimal.AVAX},qe=async s=>(s===i.Chain.BinanceSmartChain,i.BaseDecimal.BSC),K=async({chain:s,symbol:e})=>{switch(s){case i.Chain.Ethereum:return Me(e);case i.Chain.Avalanche:return ke(e);case i.Chain.BinanceSmartChain:return qe(e);default:return i.BaseDecimal[s]}},Ve={[i.FeeOption.Average]:1.2,[i.FeeOption.Fast]:1.5,[i.FeeOption.Fastest]:2},se=({chain:s,symbol:e})=>{switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Ethereum:case i.Chain.Avalanche:return e===s;case i.Chain.Arbitrum:case i.Chain.Optimism:return e==="ETH";case i.Chain.Maya:return e==="CACAO";case i.Chain.Kujira:return e==="KUJI";case i.Chain.Cosmos:return e==="ATOM";case i.Chain.Polygon:return e==="MATIC";case i.Chain.BinanceSmartChain:return e==="BNB";case i.Chain.THORChain:return e==="RUNE"}},ne=s=>{switch(s){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case i.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:i.BaseDecimal[s]};case i.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:i.BaseDecimal[s]};case i.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:i.BaseDecimal[s]};case i.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:i.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case i.Chain.Kujira:case i.Chain.Arbitrum:case i.Chain.Optimism:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Avalanche:case i.Chain.Polygon:case i.Chain.Bitcoin:case i.Chain.Ethereum:return{identifier:`${s}.${s}`,decimal:i.BaseDecimal[s]}}},ie=({chain:s,symbol:e})=>{if(e.includes("/"))return"Synth";switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Dogecoin:case i.Chain.Litecoin:case i.Chain.Maya:case i.Chain.THORChain:return"Native";case i.Chain.Cosmos:return e==="ATOM"?"Native":i.Chain.Cosmos;case i.Chain.Kujira:return e===i.Chain.Kujira?"Native":i.Chain.Kujira;case i.Chain.Binance:return e===i.Chain.Binance?"Native":"BEP2";case i.Chain.BinanceSmartChain:return e===i.Chain.Binance?"Native":"BEP20";case i.Chain.Ethereum:return e===i.Chain.Ethereum?"Native":"ERC20";case i.Chain.Avalanche:return e===i.Chain.Avalanche?"Native":i.Chain.Avalanche;case i.Chain.Polygon:return e===i.Chain.Polygon?"Native":"POLYGON";case i.Chain.Arbitrum:return[i.Chain.Ethereum,i.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case i.Chain.Optimism:return[i.Chain.Ethereum,i.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},Pe=s=>{var o;const[e,...t]=s.split("."),r=s.includes("/"),n=t.join("."),a=(o=n==null?void 0:n.split("-"))==null?void 0:o[0];return{chain:e,symbol:n,ticker:a,synth:r}},Ne=new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,"gmi"),xe=s=>s.filter(e=>!Ne.test(e.toString())&&!e.toString().includes("undefined")),ae=({liquidityUnits:s,poolUnits:e,runeDepth:t})=>{const r=d(s),n=d(e),a=d(t),o=r.mul(a),c=n.mul(n).mul(2),u=n.mul(r).mul(2),l=r.mul(r),h=n.mul(n).mul(n);return o.mul(c.sub(u).add(l)).div(h)},oe=({liquidityUnits:s,poolUnits:e,assetDepth:t})=>{const r=d(s),n=d(e),a=d(t),o=r.mul(a),c=n.mul(n).mul(2),u=n.mul(r).mul(2),l=r.mul(r),h=o.mul(c.sub(u).add(l)),g=n.mul(n).mul(n);return h.div(g)},De=({percent:s,runeDepth:e,liquidityUnits:t,poolUnits:r})=>ae({runeDepth:e,liquidityUnits:t,poolUnits:r}).mul(s),He=({percent:s,assetDepth:e,liquidityUnits:t,poolUnits:r})=>oe({assetDepth:e,liquidityUnits:t,poolUnits:r}).mul(s),d=s=>new _e({value:s,decimal:i.BaseDecimal.THOR}),ce=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r})=>({assetAmount:d(r).mul(s).div(e),runeAmount:d(t).mul(s).div(e)}),je=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r,percent:n})=>Object.fromEntries(Object.entries(ce({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r})).map(([a,o])=>[a,o.mul(n)])),Le=({runeDepth:s,poolUnits:e,assetDepth:t,liquidityUnits:r,runeAmount:n,assetAmount:a})=>{const o=d(s),c=d(t),u=d(e),l=d(n),h=d(a),g=l.mul(c),C=h.mul(o),V=l.mul(h),ye=o.mul(c),be=u.mul(g.add(C.add(V.mul(2)))),Ce=g.add(C.add(ye.mul(2))),J=be.div(Ce),P=d(r).add(J);if(J.baseValueNumber===0)return P.div(u).baseValueNumber;const we=u.add(P);return P.div(we).baseValueNumber},Ue=({runeAmount:s,assetAmount:e,runeDepth:t,assetDepth:r})=>{const n=d(t),a=d(r),o=d(e),c=d(s),u=o.mul(n).sub(a.mul(c)),l=a.mul(c).add(n.mul(a));return Math.abs(u.div(l).baseValueNumber)},Fe=({symbol:s,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${s.slice(-3)}`:s,We=(s,e)=>{switch(s){case i.MemoType.LEAVE:case i.MemoType.BOND:{const{address:t}=e;return`${s}:${t}`}case i.MemoType.UNBOND:{const{address:t,unbondAmount:r}=e;return`${s}:${t}:${r*10**8}`}case i.MemoType.THORNAME_REGISTER:{const{name:t,chain:r,address:n,owner:a}=e;return`${s}:${t}:${r}:${n}${a?`:${a}`:""}`}case i.MemoType.DEPOSIT:{const{chain:t,symbol:r,address:n,singleSide:a}=e;return a?`${s}:${t}/${r}::t:0`:`${s}:${t}.${r}:${n||""}:t:0`}case i.MemoType.WITHDRAW:{const{chain:t,ticker:r,symbol:n,basisPoints:a,targetAssetString:o,singleSide:c}=e,u=!c&&o?`:${o}`:"",l=Fe({chain:t,symbol:n,ticker:r});return`${s}:${t}${c?"/":"."}${l}:${a}${u}`}case i.MemoType.OPEN_LOAN:case i.MemoType.CLOSE_LOAN:{const{asset:t,address:r}=e;return`${s}:${t}:${r}`}default:return""}},Ge=s=>{if(s<0)throw new Error("Invalid number of year");return 10+s},Ke=s=>{if(s.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!s.match(e)},Ye=([s,e,t,r,n])=>`${s}'/${e}'/${t}'/${r}${typeof n!="number"?"":`/${n}`}`;class Q extends Error{constructor(e,t,r){const n=e.status||e.status===0?e.status:"",a=e.statusText||"",o=`${n} ${a}`.trim(),c=o?`status code ${o}`:"an unknown error";super(`Request failed with ${c}`),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=e,this.request=t,this.options=r}}class ue extends Error{constructor(e){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=e}}const O=s=>s!==null&&typeof s=="object",E=(...s)=>{for(const e of s)if((!O(e)||Array.isArray(e))&&e!==void 0)throw new TypeError("The `options` argument must be an object");return Y({},...s)},le=(s={},e={})=>{const t=new globalThis.Headers(s),r=e instanceof globalThis.Headers,n=new globalThis.Headers(e);for(const[a,o]of n.entries())r&&o==="undefined"||o===void 0?t.delete(a):t.set(a,o);return t},Y=(...s)=>{let e={},t={};for(const r of s)if(Array.isArray(r))Array.isArray(e)||(e=[]),e=[...e,...r];else if(O(r)){for(let[n,a]of Object.entries(r))O(a)&&n in e&&(a=Y(e[n],a)),e={...e,[n]:a};O(r.headers)&&(t=le(t,r.headers),e.headers=t)}return e},ze=(()=>{let s=!1,e=!1;const t=typeof globalThis.ReadableStream=="function",r=typeof globalThis.Request=="function";return t&&r&&(e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return s=!0,"half"}}).headers.has("Content-Type")),s&&!e})(),Je=typeof globalThis.AbortController=="function",Qe=typeof globalThis.ReadableStream=="function",Xe=typeof globalThis.FormData=="function",he=["get","post","put","patch","head","delete"],Ze={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},x=2147483647,de=Symbol("stop"),et={json:!0,parseJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,fetch:!0},tt={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,dispatcher:!0,duplex:!0},rt=s=>he.includes(s)?s.toUpperCase():s,st=["get","put","head","delete","options","trace"],nt=[408,413,429,500,502,503,504],me=[413,429,503],X={limit:2,methods:st,statusCodes:nt,afterStatusCodes:me,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:s=>.3*2**(s-1)*1e3},it=(s={})=>{if(typeof s=="number")return{...X,limit:s};if(s.methods&&!Array.isArray(s.methods))throw new Error("retry.methods must be an array");if(s.statusCodes&&!Array.isArray(s.statusCodes))throw new Error("retry.statusCodes must be an array");return{...X,...s,afterStatusCodes:me}};async function at(s,e,t,r){return new Promise((n,a)=>{const o=setTimeout(()=>{t&&t.abort(),a(new ue(s))},r.timeout);r.fetch(s,e).then(n).catch(a).then(()=>{clearTimeout(o)})})}async function ot(s,{signal:e}){return new Promise((t,r)=>{e&&(e.throwIfAborted(),e.addEventListener("abort",n,{once:!0}));function n(){clearTimeout(a),r(e.reason)}const a=setTimeout(()=>{e==null||e.removeEventListener("abort",n),t()},s)})}const ct=(s,e)=>{const t={};for(const r in e)!(r in tt)&&!(r in et)&&!(r in s)&&(t[r]=e[r]);return t};class M{static create(e,t){const r=new M(e,t),n=async()=>{if(typeof r._options.timeout=="number"&&r._options.timeout>x)throw new RangeError(`The \`timeout\` option cannot be greater than ${x}`);await Promise.resolve();let c=await r._fetch();for(const u of r._options.hooks.afterResponse){const l=await u(r.request,r._options,r._decorateResponse(c.clone()));l instanceof globalThis.Response&&(c=l)}if(r._decorateResponse(c),!c.ok&&r._options.throwHttpErrors){let u=new Q(c,r.request,r._options);for(const l of r._options.hooks.beforeError)u=await l(u);throw u}if(r._options.onDownloadProgress){if(typeof r._options.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Qe)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return r._stream(c.clone(),r._options.onDownloadProgress)}return c},o=r._options.retry.methods.includes(r.request.method.toLowerCase())?r._retry(n):n();for(const[c,u]of Object.entries(Ze))o[c]=async()=>{r.request.headers.set("accept",r.request.headers.get("accept")||u);const h=(await o).clone();if(c==="json"){if(h.status===204||(await h.clone().arrayBuffer()).byteLength===0)return"";if(t.parseJson)return t.parseJson(await h.text())}return h[c]()};return o}constructor(e,t={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=e,this._options={credentials:this._input.credentials||"same-origin",...t,headers:le(this._input.headers,t.headers),hooks:Y({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},t.hooks),method:rt(t.method??this._input.method),prefixUrl:String(t.prefixUrl||""),retry:it(t.retry),throwHttpErrors:t.throwHttpErrors!==!1,timeout:t.timeout??1e4,fetch:t.fetch??globalThis.fetch.bind(globalThis)},typeof this._input!="string"&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&typeof this._input=="string"){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(Je){if(this.abortController=new globalThis.AbortController,this._options.signal){const r=this._options.signal;this._options.signal.addEventListener("abort",()=>{this.abortController.abort(r.reason)})}this._options.signal=this.abortController.signal}if(ze&&(this._options.duplex="half"),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const n="?"+(typeof this._options.searchParams=="string"?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),a=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,n);(Xe&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)&&!(this._options.headers&&this._options.headers["content-type"])&&this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(a,{...this.request}),this._options)}this._options.json!==void 0&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_calculateRetryDelay(e){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(e instanceof ue)){if(e instanceof Q){if(!this._options.retry.statusCodes.includes(e.response.status))return 0;const r=e.response.headers.get("Retry-After");if(r&&this._options.retry.afterStatusCodes.includes(e.response.status)){let n=Number(r);return Number.isNaN(n)?n=Date.parse(r)-Date.now():n*=1e3,this._options.retry.maxRetryAfter!==void 0&&n>this._options.retry.maxRetryAfter?0:n}if(e.response.status===413)return 0}const t=this._options.retry.delay(this._retryCount);return Math.min(this._options.retry.backoffLimit,t)}return 0}_decorateResponse(e){return this._options.parseJson&&(e.json=async()=>this._options.parseJson(await e.text())),e}async _retry(e){try{return await e()}catch(t){const r=Math.min(this._calculateRetryDelay(t),x);if(r!==0&&this._retryCount>0){await ot(r,{signal:this._options.signal});for(const n of this._options.hooks.beforeRetry)if(await n({request:this.request,options:this._options,error:t,retryCount:this._retryCount})===de)return;return this._retry(e)}throw t}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const r=await t(this.request,this._options);if(r instanceof Request){this.request=r;break}if(r instanceof Response)return r}const e=ct(this.request,this._options);return this._options.timeout===!1?this._options.fetch(this.request.clone(),e):at(this.request.clone(),e,this.abortController,this._options)}_stream(e,t){const r=Number(e.headers.get("content-length"))||0;let n=0;return e.status===204?(t&&t({percent:1,totalBytes:r,transferredBytes:n},new Uint8Array),new globalThis.Response(null,{status:e.status,statusText:e.statusText,headers:e.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(a){const o=e.body.getReader();t&&t({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array);async function c(){const{done:u,value:l}=await o.read();if(u){a.close();return}if(t){n+=l.byteLength;const h=r===0?0:n/r;t({percent:h,transferredBytes:n,totalBytes:r},l)}a.enqueue(l),await c()}await c()}}),{status:e.status,statusText:e.statusText,headers:e.headers})}}/*! MIT License © Sindre Sorhus */const j=s=>{const e=(t,r)=>M.create(t,E(s,r));for(const t of he)e[t]=(r,n)=>M.create(r,E(s,n,{method:t}));return e.create=t=>j(E(t)),e.extend=t=>j(E(s,t)),e.stop=de,e},ut=j(),lt=ut,Z=lt.create({headers:{referrer:"https://sk.thorswap.net",referer:"https://sk.thorswap.net","Content-Type":"application/json"}}),pe={get:(s,e)=>Z.get(s,e).json(),post:(s,e)=>Z.post(s,e).json()},ee=Object.values(i.Chain),ht=(s="")=>{const e=s.toUpperCase(),[t]=e.split(".");if(ee.includes(t))return!0;const[r]=e.split("/");if(ee.includes(r))return!0;throw new Error(`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},v=8,w=s=>10n**BigInt(s),T=s=>Math.log10(parseFloat(s.toString()));function L({value:s,bigIntDecimal:e=v,decimal:t=v}){const r=s<0n;let n=s.toString().substring(r?1:0);const a=t-(n.length-1);a>0&&(n="0".repeat(a)+n);const o=n.length-t;let c=n.slice(-t);return parseInt(c[e])>=5?c=`${c.substring(0,e-1)}${(parseInt(c[e-1])+1).toString()}`:c=c.substring(0,e),`${r?"-":""}${n.slice(0,o)}.${c}`.replace(/\.?0*$/,"")}var y,S,k,fe,q,ge,B,U,b,R,$,F;const I=class I{constructor(e){_(this,y);_(this,k);_(this,q);_(this,B);_(this,b);_(this,$);p(this,"decimalMultiplier",10n**8n);p(this,"bigIntValue",0n);p(this,"decimal");const t=D(e);this.decimal=typeof e=="object"?e.decimal:void 0,this.decimalMultiplier=w(Math.max(m(this,$,F).call(this,m(this,b,R).call(this,t)),this.decimal||0)),m(this,k,fe).call(this,t)}static fromBigInt(e,t){return new I({decimal:t,value:L({value:e,bigIntDecimal:t,decimal:t})})}static shiftDecimals({value:e,from:t,to:r}){return I.fromBigInt(new I(e).bigIntValue*w(r)/w(t),r)}get baseValue(){return this.getBaseValue("string")}get baseValueNumber(){return this.getBaseValue("number")}get baseValueBigInt(){return this.getBaseValue("bigint")}set(e){return new this.constructor({decimal:this.decimal,value:e,identifier:this.toString()})}add(...e){return m(this,y,S).call(this,"add",...e)}sub(...e){return m(this,y,S).call(this,"sub",...e)}mul(...e){return m(this,y,S).call(this,"mul",...e)}div(...e){return m(this,y,S).call(this,"div",...e)}gt(e){return this.bigIntValue>this.getBigIntValue(e)}gte(e){return this.bigIntValue>=this.getBigIntValue(e)}lt(e){return this.bigIntValue<this.getBigIntValue(e)}lte(e){return this.bigIntValue<=this.getBigIntValue(e)}eqValue(e){return this.bigIntValue===this.getBigIntValue(e)}getValue(e){const t=this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||T(this.decimalMultiplier));switch(e){case"number":return Number(t);case"string":return t;default:return this.bigIntValue*BigInt(this.decimal||8n)/this.decimalMultiplier}}getBaseValue(e){const t=this.decimalMultiplier/w(this.decimal||i.BaseDecimal.THOR),r=this.bigIntValue/t;switch(e){case"number":return Number(r);case"string":return r.toString();default:return r}}getBigIntValue(e,t){if(!t&&typeof e=="object")return e.bigIntValue;const r=D(e),n=m(this,b,R).call(this,r);return n==="0"||n==="undefined"?0n:m(this,B,U).call(this,n,t)}formatBigIntToSafeValue(e,t){const r=t||this.decimal||v,n=Math.max(r,T(this.decimalMultiplier)),a=e<0n,o=e.toString().substring(a?1:0),c=n-(o.length-1),u=c>0?"0".repeat(c)+o:o,l=u.length-n;let h=u.slice(-n);return parseInt(h[r])>=5?h=`${h.substring(0,r-1)}${(parseInt(h[r-1])+1).toString()}`:h=h.substring(0,r),`${a?"-":""}${u.slice(0,l)}.${h}`.replace(/\.?0*$/,"")}toSignificant(e=6){const[t,r]=this.getValue("string").split("."),n=t||"",a=r||"",o=parseInt(n)?n.length+a.length:a.length;if(o<=e)return this.getValue("string");if(n.length>=e)return n.slice(0,e).padEnd(n.length,"0");if(parseInt(n))return`${n}.${a.slice(0,e-n.length)}`.padEnd(o-e,"0");const c=parseInt(a),u=`${c}`.slice(0,e);return`0.${u.padStart(a.length-`${c}`.length+u.length,"0")}`}};y=new WeakSet,S=function(e,...t){const r=m(this,q,ge).call(this,this,...t),n=w(r),a=t.reduce((c,u)=>{const l=this.getBigIntValue(u,r);switch(e){case"add":return c+l;case"sub":return c-l;case"mul":return c*l/n;case"div":{if(l===0n)throw new RangeError("Division by zero");return c*n/l}default:return c}},this.bigIntValue*n/this.decimalMultiplier),o=L({bigIntDecimal:r,decimal:Math.max(r,T(this.decimalMultiplier)),value:a});return new this.constructor({decimal:this.decimal,value:o,identifier:this.toString()})},k=new WeakSet,fe=function(e){const t=m(this,b,R).call(this,e)||"0";this.bigIntValue=m(this,B,U).call(this,t)},q=new WeakSet,ge=function(...e){const t=e.map(r=>typeof r=="object"?r.decimal||T(r.decimalMultiplier):m(this,$,F).call(this,m(this,b,R).call(this,r))).filter(Boolean);return Math.max(...t,v)},B=new WeakSet,U=function(e,t){const r=t?w(t):this.decimalMultiplier,n=T(r),[a="",o=""]=e.split(".");return BigInt(`${a}${o.padEnd(n,"0")}`)},b=new WeakSet,R=function(e){const r=`${typeof e=="number"?Number(e).toLocaleString("fullwide",{useGrouping:!1,maximumFractionDigits:20}):D(e)}`.replaceAll(",",".").split(".");return r.length>1?`${r.slice(0,-1).join("")}.${r.at(-1)}`:r[0]},$=new WeakSet,F=function(e){var r;const t=((r=e.split(".")[1])==null?void 0:r.length)||0;return Math.max(t,v)};let A=I;function D(s){return typeof s=="object"?"getValue"in s?s.getValue("string"):s.value:s}let W;const H=s=>{if(!W)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return W.get(s.toUpperCase())||{decimal:i.BaseDecimal.THOR,identifier:""}},te=async(s,e=0)=>{ht(s);const t=await K(G(s));return new f({decimal:t,value:e,identifier:s})};class f extends A{constructor(t){super(t.value instanceof A?t.value:{decimal:t.decimal,value:t.value});p(this,"address");p(this,"chain");p(this,"isSynthetic",!1);p(this,"isGasAsset",!1);p(this,"symbol");p(this,"ticker");p(this,"type");const r="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`,n=G(r);this.type=ie(n),this.chain=n.chain,this.ticker=n.ticker,this.symbol=n.symbol,this.address=n.address,this.isSynthetic=n.isSynthetic,this.isGasAsset=n.isGasAsset}get assetValue(){return`${this.getValue("string")} ${this.ticker}`}toString(t=!1){const r=this.isSynthetic?this.ticker:`${this.chain}.${this.ticker}`;return t?r:`${this.chain}.${this.symbol}`}eq({chain:t,symbol:r}){return this.chain===t&&this.symbol===r}static async fromString(t,r=0){return te(t,r)}static fromStringSync(t,r=0){const{decimal:n,identifier:a}=H(t);return a?new f({decimal:n,identifier:a,value:r}):void 0}static async fromIdentifier(t,r=0){return te(t,r)}static fromIdentifierSync(t,r=0){const{decimal:n,identifier:a}=H(t);return new f({decimal:n,identifier:a,value:r})}static fromChainOrSignature(t,r=0){const{decimal:n,identifier:a}=ne(t);return new f({value:r,decimal:n,identifier:a})}static async fromTCQuote(t,r=0){const n=await K(G(t)),a=this.shiftDecimals({value:r,from:i.BaseDecimal.THOR,to:n});return new f({value:a,identifier:t,decimal:n})}static fromTCQuoteStatic(t,r=0){const n=H(t),a=this.shiftDecimals({value:r,from:i.BaseDecimal.THOR,to:n.decimal});return new f({...n,value:a})}static async loadStaticAssets(){return new Promise(async(t,r)=>{try{const{ThorchainList:n,NativeList:a,...o}=await import("@swapkit/tokens");W=[a,...Object.values(o)].reduce((u,{tokens:l})=>(l.forEach(({identifier:h,chain:g,...C})=>{const V="decimals"in C?C.decimals:i.BaseDecimal[g];u.set(h,{identifier:h,decimal:V})}),u),new Map),t({ok:!0})}catch(n){console.error(n),r({ok:!1,error:n,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}}const dt=s=>{const e=f.fromChainOrSignature(s);switch(s){case i.Chain.Bitcoin:case i.Chain.Litecoin:case i.Chain.BitcoinCash:return e.add(10001);case i.Chain.Dogecoin:return e.add(100000001);case i.Chain.Avalanche:case i.Chain.Ethereum:return e.add(10*10**9);case i.Chain.THORChain:case i.Chain.Maya:return e.add(0);default:return e.add(1)}},G=s=>{const e=s.slice(0,14).includes("/"),t=s.includes(".")?s:`${i.Chain.THORChain}.${s}`,[r,n]=t.split("."),[a,o]=n.split("-");return{address:o==null?void 0:o.toLowerCase(),chain:r,isGasAsset:se({chain:r,symbol:n}),isSynthetic:e,symbol:o?`${a}-${(o==null?void 0:o.toLowerCase())??""}`:n,ticker:e?n:a}},mt={core_wallet_connection_not_found:10001,core_estimated_max_spendable_chain_not_supported:10002,core_extend_error:10003,core_inbound_data_not_found:10004,core_approve_asset_address_or_from_not_found:10005,core_chain_halted:10099,core_wallet_xdefi_not_installed:10101,core_wallet_evmwallet_not_installed:10102,core_wallet_walletconnect_not_installed:10103,core_wallet_keystore_not_installed:10104,core_wallet_ledger_not_installed:10105,core_wallet_trezor_not_installed:10106,core_wallet_keplr_not_installed:10107,core_wallet_okx_not_installed:10108,core_swap_invalid_params:10200,core_swap_route_not_complete:10201,core_swap_asset_not_recognized:10202,core_swap_contract_not_found:10203,core_swap_route_transaction_not_found:10204,core_swap_contract_not_supported:10205,core_swap_transaction_error:10206,core_swap_quote_mode_not_supported:10207,core_transaction_deposit_error:10301,core_transaction_create_liquidity_rune_error:10302,core_transaction_create_liquidity_asset_error:10303,core_transaction_create_liquidity_invalid_params:10304,core_transaction_add_liquidity_invalid_params:10305,core_transaction_add_liquidity_no_rune_address:10306,core_transaction_add_liquidity_rune_error:10307,core_transaction_add_liquidity_asset_error:10308,core_transaction_withdraw_error:10309,core_transaction_deposit_to_pool_error:10310,core_transaction_deposit_insufficient_funds_error:10311,core_transaction_deposit_gas_error:10312,core_transaction_deposit_server_error:10313,wallet_ledger_connection_error:20001,helpers_number_different_decimals:99101};class z extends Error{constructor(e,t){console.error(t),super(e,{cause:{code:mt[e],message:e}}),Object.setPrototypeOf(this,z.prototype)}}class _e extends A{eq(e){return this.eqValue(e)}}exports.AssetValue=f;exports.BigIntArithmetics=A;exports.RequestClient=pe;exports.SwapKitError=z;exports.SwapKitNumber=_e;exports.assetFromString=Pe;exports.derivationPathToString=Ye;exports.filterAssets=xe;exports.formatBigIntToSafeValue=L;exports.gasFeeMultiplier=Ve;exports.getAssetType=ie;exports.getAsymmetricAssetShare=oe;exports.getAsymmetricAssetWithdrawAmount=He;exports.getAsymmetricRuneShare=ae;exports.getAsymmetricRuneWithdrawAmount=De;exports.getCommonAssetInfo=ne;exports.getDecimal=K;exports.getEstimatedPoolShare=Le;exports.getLiquiditySlippage=Ue;exports.getMemoFor=We;exports.getMinAmountByChain=dt;exports.getSymmetricPoolShare=ce;exports.getSymmetricWithdraw=je;exports.getTHORNameCost=Ge;exports.isGasAsset=se;exports.validateTHORName=Ke;
|
package/dist/index.d.ts
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { Chain } from '@swapkit/types';
|
|
2
|
-
import type { CoinGeckoList } from '@swapkit/tokens';
|
|
3
|
-
import { FeeOption } from '@swapkit/types';
|
|
4
|
-
import type { MayaList } from '@swapkit/tokens';
|
|
5
|
-
import { MemoType } from '@swapkit/types';
|
|
6
|
-
import type { Options } from 'ky';
|
|
7
|
-
import type { PancakeswapETHList } from '@swapkit/tokens';
|
|
8
|
-
import type { PancakeswapList } from '@swapkit/tokens';
|
|
9
|
-
import type { PangolinList } from '@swapkit/tokens';
|
|
10
|
-
import type { StargateARBList } from '@swapkit/tokens';
|
|
11
|
-
import type { SushiswapList } from '@swapkit/tokens';
|
|
12
|
-
import type { ThorchainList } from '@swapkit/tokens';
|
|
13
|
-
import type { TraderjoeList } from '@swapkit/tokens';
|
|
14
|
-
import type { UniswapList } from '@swapkit/tokens';
|
|
15
|
-
import type { WoofiList } from '@swapkit/tokens';
|
|
16
|
-
|
|
17
|
-
export declare const assetFromString: (assetString: string) => {
|
|
18
|
-
chain: Chain;
|
|
19
|
-
symbol: string;
|
|
20
|
-
ticker: string;
|
|
21
|
-
synth: boolean;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export declare class AssetValue extends BigIntArithmetics {
|
|
25
|
-
address?: string;
|
|
26
|
-
chain: Chain;
|
|
27
|
-
isSynthetic: boolean;
|
|
28
|
-
isGasAsset: boolean;
|
|
29
|
-
symbol: string;
|
|
30
|
-
ticker: string;
|
|
31
|
-
type: ReturnType<typeof getAssetType>;
|
|
32
|
-
constructor(params: AssetValueParams);
|
|
33
|
-
get assetValue(): string;
|
|
34
|
-
toString(short?: boolean): string;
|
|
35
|
-
eq({ chain, symbol }: {
|
|
36
|
-
chain: Chain;
|
|
37
|
-
symbol: string;
|
|
38
|
-
}): boolean;
|
|
39
|
-
static fromString(assetString: string, value?: number | string): Promise<AssetValue>;
|
|
40
|
-
static fromStringSync(assetString: string, value?: number | string): AssetValue | undefined;
|
|
41
|
-
static fromIdentifier(assetString: `${Chain}.${string}` | `${Chain}/${string}` | `${Chain}.${string}-${string}`, value?: number | string): Promise<AssetValue>;
|
|
42
|
-
static fromIdentifierSync(identifier: TokenNames, value?: number | string): AssetValue;
|
|
43
|
-
static fromChainOrSignature(assetString: CommonAssetString, value?: number | string): AssetValue;
|
|
44
|
-
static fromTCQuote(identifier: TCTokenNames, value?: number | string): Promise<AssetValue>;
|
|
45
|
-
static fromTCQuoteStatic(identifier: TCTokenNames, value?: number | string): AssetValue;
|
|
46
|
-
static loadStaticAssets(): Promise<{
|
|
47
|
-
ok: true;
|
|
48
|
-
} | {
|
|
49
|
-
ok: false;
|
|
50
|
-
message: string;
|
|
51
|
-
error: any;
|
|
52
|
-
}>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
declare type AssetValueParams = {
|
|
56
|
-
decimal: number;
|
|
57
|
-
value: SwapKitValueType;
|
|
58
|
-
} & ({
|
|
59
|
-
chain: Chain;
|
|
60
|
-
symbol: string;
|
|
61
|
-
} | {
|
|
62
|
-
identifier: string;
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
export declare class BigIntArithmetics {
|
|
66
|
-
|
|
67
|
-
decimalMultiplier: bigint;
|
|
68
|
-
bigIntValue: bigint;
|
|
69
|
-
decimal?: number;
|
|
70
|
-
static fromBigInt(value: bigint, decimal?: number): BigIntArithmetics;
|
|
71
|
-
static shiftDecimals({ value, from, to, }: {
|
|
72
|
-
value: InitialisationValueType;
|
|
73
|
-
from: number;
|
|
74
|
-
to: number;
|
|
75
|
-
}): BigIntArithmetics;
|
|
76
|
-
constructor(params: SKBigIntParams);
|
|
77
|
-
/**
|
|
78
|
-
* @deprecated Use `getBaseValue('string')` instead
|
|
79
|
-
*/
|
|
80
|
-
get baseValue(): string;
|
|
81
|
-
/**
|
|
82
|
-
* @deprecated Use `getBaseValue('number')` instead
|
|
83
|
-
*/
|
|
84
|
-
get baseValueNumber(): number;
|
|
85
|
-
/**
|
|
86
|
-
* @deprecated Use `getBaseValue('bigint')` instead
|
|
87
|
-
*/
|
|
88
|
-
get baseValueBigInt(): bigint;
|
|
89
|
-
set(value: SKBigIntParams): any;
|
|
90
|
-
add(...args: InitialisationValueType[]): this;
|
|
91
|
-
sub(...args: InitialisationValueType[]): this;
|
|
92
|
-
mul(...args: InitialisationValueType[]): this;
|
|
93
|
-
div(...args: InitialisationValueType[]): this;
|
|
94
|
-
gt(value: InitialisationValueType): boolean;
|
|
95
|
-
gte(value: InitialisationValueType): boolean;
|
|
96
|
-
lt(value: InitialisationValueType): boolean;
|
|
97
|
-
lte(value: InitialisationValueType): boolean;
|
|
98
|
-
eqValue(value: InitialisationValueType): boolean;
|
|
99
|
-
getValue<T extends 'number' | 'string'>(type: T): NumberPrimitivesType[T];
|
|
100
|
-
getBaseValue<T extends 'number' | 'string' | 'bigint'>(type: T): NumberPrimitivesType[T];
|
|
101
|
-
getBigIntValue(value: InitialisationValueType, decimal?: number): bigint;
|
|
102
|
-
formatBigIntToSafeValue(value: bigint, decimal?: number): string;
|
|
103
|
-
toSignificant(significantDigits?: number): string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export declare type CommonAssetString = 'MAYA.MAYA' | 'ETH.THOR' | 'ETH.vTHOR' | Chain;
|
|
107
|
-
|
|
108
|
-
export declare const derivationPathToString: ([network, chainId, account, change, index]: number[]) => string;
|
|
109
|
-
|
|
110
|
-
declare const errorMessages: {
|
|
111
|
-
/**
|
|
112
|
-
* Core
|
|
113
|
-
*/
|
|
114
|
-
readonly core_wallet_connection_not_found: 10001;
|
|
115
|
-
readonly core_estimated_max_spendable_chain_not_supported: 10002;
|
|
116
|
-
readonly core_extend_error: 10003;
|
|
117
|
-
readonly core_inbound_data_not_found: 10004;
|
|
118
|
-
readonly core_approve_asset_address_or_from_not_found: 10005;
|
|
119
|
-
readonly core_chain_halted: 10099;
|
|
120
|
-
/**
|
|
121
|
-
* Core - Wallet Connection
|
|
122
|
-
*/
|
|
123
|
-
readonly core_wallet_xdefi_not_installed: 10101;
|
|
124
|
-
readonly core_wallet_evmwallet_not_installed: 10102;
|
|
125
|
-
readonly core_wallet_walletconnect_not_installed: 10103;
|
|
126
|
-
readonly core_wallet_keystore_not_installed: 10104;
|
|
127
|
-
readonly core_wallet_ledger_not_installed: 10105;
|
|
128
|
-
readonly core_wallet_trezor_not_installed: 10106;
|
|
129
|
-
readonly core_wallet_keplr_not_installed: 10107;
|
|
130
|
-
readonly core_wallet_okx_not_installed: 10108;
|
|
131
|
-
/**
|
|
132
|
-
* Core - Swap
|
|
133
|
-
*/
|
|
134
|
-
readonly core_swap_invalid_params: 10200;
|
|
135
|
-
readonly core_swap_route_not_complete: 10201;
|
|
136
|
-
readonly core_swap_asset_not_recognized: 10202;
|
|
137
|
-
readonly core_swap_contract_not_found: 10203;
|
|
138
|
-
readonly core_swap_route_transaction_not_found: 10204;
|
|
139
|
-
readonly core_swap_contract_not_supported: 10205;
|
|
140
|
-
readonly core_swap_transaction_error: 10206;
|
|
141
|
-
readonly core_swap_quote_mode_not_supported: 10207;
|
|
142
|
-
/**
|
|
143
|
-
* Core - Transaction
|
|
144
|
-
*/
|
|
145
|
-
readonly core_transaction_deposit_error: 10301;
|
|
146
|
-
readonly core_transaction_create_liquidity_rune_error: 10302;
|
|
147
|
-
readonly core_transaction_create_liquidity_asset_error: 10303;
|
|
148
|
-
readonly core_transaction_create_liquidity_invalid_params: 10304;
|
|
149
|
-
readonly core_transaction_add_liquidity_invalid_params: 10305;
|
|
150
|
-
readonly core_transaction_add_liquidity_no_rune_address: 10306;
|
|
151
|
-
readonly core_transaction_add_liquidity_rune_error: 10307;
|
|
152
|
-
readonly core_transaction_add_liquidity_asset_error: 10308;
|
|
153
|
-
readonly core_transaction_withdraw_error: 10309;
|
|
154
|
-
readonly core_transaction_deposit_to_pool_error: 10310;
|
|
155
|
-
readonly core_transaction_deposit_insufficient_funds_error: 10311;
|
|
156
|
-
readonly core_transaction_deposit_gas_error: 10312;
|
|
157
|
-
readonly core_transaction_deposit_server_error: 10313;
|
|
158
|
-
/**
|
|
159
|
-
* Wallets
|
|
160
|
-
*/
|
|
161
|
-
readonly wallet_ledger_connection_error: 20001;
|
|
162
|
-
/**
|
|
163
|
-
* Helpers
|
|
164
|
-
*/
|
|
165
|
-
readonly helpers_number_different_decimals: 99101;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export declare const filterAssets: (assets: AssetValue[]) => AssetValue[];
|
|
169
|
-
|
|
170
|
-
export declare function formatBigIntToSafeValue({ value, bigIntDecimal, decimal, }: {
|
|
171
|
-
value: bigint;
|
|
172
|
-
bigIntDecimal?: number;
|
|
173
|
-
decimal?: number;
|
|
174
|
-
}): string;
|
|
175
|
-
|
|
176
|
-
export declare const gasFeeMultiplier: Record<FeeOption, number>;
|
|
177
|
-
|
|
178
|
-
export declare const getAssetType: ({ chain, symbol }: {
|
|
179
|
-
chain: Chain;
|
|
180
|
-
symbol: string;
|
|
181
|
-
}) => Chain.Avalanche | Chain.Cosmos | Chain.Kujira | "Synth" | "Native" | "BEP2" | "BEP20" | "ERC20" | "POLYGON" | "ARBITRUM" | "OPTIMISM";
|
|
182
|
-
|
|
183
|
-
export declare const getAsymmetricAssetShare: ({ liquidityUnits, poolUnits, assetDepth, }: ShareParams<{
|
|
184
|
-
assetDepth: string;
|
|
185
|
-
}>) => SwapKitNumber;
|
|
186
|
-
|
|
187
|
-
export declare const getAsymmetricAssetWithdrawAmount: ({ percent, assetDepth, liquidityUnits, poolUnits, }: ShareParams<{
|
|
188
|
-
percent: number;
|
|
189
|
-
assetDepth: string;
|
|
190
|
-
}>) => SwapKitNumber;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Ref: https://gitlab.com/thorchain/thornode/-/issues/657
|
|
194
|
-
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
195
|
-
* s = stakeUnits for member (after factoring in withdrawBasisPoints)
|
|
196
|
-
* T = totalPoolUnits for pool
|
|
197
|
-
* A = assetDepth to be withdrawn
|
|
198
|
-
*
|
|
199
|
-
* Formula:
|
|
200
|
-
* share = (s * A * (2 * T^2 - 2 * T * s + s^2))/T^3
|
|
201
|
-
* (part1 * (part2 - part3 + part4)) / part5
|
|
202
|
-
*/
|
|
203
|
-
export declare const getAsymmetricRuneShare: ({ liquidityUnits, poolUnits, runeDepth, }: ShareParams<{
|
|
204
|
-
runeDepth: string;
|
|
205
|
-
}>) => SwapKitNumber;
|
|
206
|
-
|
|
207
|
-
export declare const getAsymmetricRuneWithdrawAmount: ({ percent, runeDepth, liquidityUnits, poolUnits, }: ShareParams<{
|
|
208
|
-
percent: number;
|
|
209
|
-
runeDepth: string;
|
|
210
|
-
}>) => SwapKitNumber;
|
|
211
|
-
|
|
212
|
-
export declare const getCommonAssetInfo: (assetString: CommonAssetString) => {
|
|
213
|
-
identifier: string;
|
|
214
|
-
decimal: number;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export declare const getDecimal: ({ chain, symbol }: {
|
|
218
|
-
chain: Chain;
|
|
219
|
-
symbol: string;
|
|
220
|
-
}) => Promise<number>;
|
|
221
|
-
|
|
222
|
-
export declare const getEstimatedPoolShare: ({ runeDepth, poolUnits, assetDepth, liquidityUnits, runeAmount, assetAmount, }: ShareParams<{
|
|
223
|
-
runeAmount: string;
|
|
224
|
-
assetAmount: string;
|
|
225
|
-
runeDepth: string;
|
|
226
|
-
assetDepth: string;
|
|
227
|
-
}>) => number;
|
|
228
|
-
|
|
229
|
-
export declare const getLiquiditySlippage: ({ runeAmount, assetAmount, runeDepth, assetDepth, }: PoolParams) => number;
|
|
230
|
-
|
|
231
|
-
export declare const getMemoFor: <T extends MemoType>(memoType: T, options: MemoOptions<T>) => string;
|
|
232
|
-
|
|
233
|
-
export declare const getMinAmountByChain: (chain: Chain) => AssetValue;
|
|
234
|
-
|
|
235
|
-
export declare const getSymmetricPoolShare: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, }: ShareParams<{
|
|
236
|
-
runeDepth: string;
|
|
237
|
-
assetDepth: string;
|
|
238
|
-
}>) => {
|
|
239
|
-
assetAmount: SwapKitNumber;
|
|
240
|
-
runeAmount: SwapKitNumber;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export declare const getSymmetricWithdraw: ({ liquidityUnits, poolUnits, runeDepth, assetDepth, percent, }: ShareParams<{
|
|
244
|
-
runeDepth: string;
|
|
245
|
-
assetDepth: string;
|
|
246
|
-
percent: number;
|
|
247
|
-
}>) => {
|
|
248
|
-
[k: string]: SwapKitNumber;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
export declare const getTHORNameCost: (year: number) => number;
|
|
252
|
-
|
|
253
|
-
declare type InitialisationValueType = NumberPrimitives | BigIntArithmetics | SwapKitNumber;
|
|
254
|
-
|
|
255
|
-
export declare const isGasAsset: ({ chain, symbol }: {
|
|
256
|
-
chain: Chain;
|
|
257
|
-
symbol: string;
|
|
258
|
-
}) => boolean;
|
|
259
|
-
|
|
260
|
-
export declare type Keys = keyof typeof errorMessages;
|
|
261
|
-
|
|
262
|
-
export declare type MemoOptions<T extends MemoType> = {
|
|
263
|
-
[MemoType.BOND]: WithAddress;
|
|
264
|
-
[MemoType.LEAVE]: WithAddress;
|
|
265
|
-
[MemoType.CLOSE_LOAN]: WithAddress<{
|
|
266
|
-
asset: string;
|
|
267
|
-
minAmount?: string;
|
|
268
|
-
}>;
|
|
269
|
-
[MemoType.OPEN_LOAN]: WithAddress<{
|
|
270
|
-
asset: string;
|
|
271
|
-
minAmount?: string;
|
|
272
|
-
}>;
|
|
273
|
-
[MemoType.UNBOND]: WithAddress<{
|
|
274
|
-
unbondAmount: number;
|
|
275
|
-
}>;
|
|
276
|
-
[MemoType.DEPOSIT]: WithChain<{
|
|
277
|
-
symbol: string;
|
|
278
|
-
address?: string;
|
|
279
|
-
singleSide?: boolean;
|
|
280
|
-
}>;
|
|
281
|
-
[MemoType.WITHDRAW]: WithChain<{
|
|
282
|
-
ticker: string;
|
|
283
|
-
symbol: string;
|
|
284
|
-
basisPoints: number;
|
|
285
|
-
targetAssetString?: string;
|
|
286
|
-
singleSide?: boolean;
|
|
287
|
-
}>;
|
|
288
|
-
[MemoType.THORNAME_REGISTER]: Omit<ThornameRegisterParam, 'preferredAsset' | 'expiryBlock'>;
|
|
289
|
-
}[T];
|
|
290
|
-
|
|
291
|
-
declare type NumberPrimitives = bigint | number | string;
|
|
292
|
-
|
|
293
|
-
declare type NumberPrimitivesType = {
|
|
294
|
-
bigint: bigint;
|
|
295
|
-
number: number;
|
|
296
|
-
string: string;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
declare type PoolParams<T = {}> = T & {
|
|
300
|
-
runeAmount: string;
|
|
301
|
-
assetAmount: string;
|
|
302
|
-
runeDepth: string;
|
|
303
|
-
assetDepth: string;
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
export declare const RequestClient: {
|
|
307
|
-
get: <T>(url: string | URL | Request, options?: Options) => Promise<T>;
|
|
308
|
-
post: <T_1>(url: string | URL | Request, options?: Options) => Promise<T_1>;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
declare type ShareParams<T = {}> = T & {
|
|
312
|
-
liquidityUnits: string;
|
|
313
|
-
poolUnits: string;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
declare type SKBigIntParams = InitialisationValueType | {
|
|
317
|
-
decimal?: number;
|
|
318
|
-
value: number | string;
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
export declare class SwapKitError extends Error {
|
|
322
|
-
constructor(errorKey: Keys, sourceError?: any);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export declare class SwapKitNumber extends BigIntArithmetics {
|
|
326
|
-
eq(value: SwapKitValueType): boolean;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export declare type SwapKitValueType = BigIntArithmetics | string | number;
|
|
330
|
-
|
|
331
|
-
declare type TCTokenNames = (typeof ThorchainList)['tokens'][number]['identifier'];
|
|
332
|
-
|
|
333
|
-
export declare type ThornameRegisterParam = {
|
|
334
|
-
name: string;
|
|
335
|
-
chain: string;
|
|
336
|
-
address: string;
|
|
337
|
-
owner?: string;
|
|
338
|
-
preferredAsset?: string;
|
|
339
|
-
expiryBlock?: string;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
declare type TokenNames = TCTokenNames | (typeof CoinGeckoList)['tokens'][number]['identifier'] | (typeof MayaList)['tokens'][number]['identifier'] | (typeof PancakeswapETHList)['tokens'][number]['identifier'] | (typeof PancakeswapList)['tokens'][number]['identifier'] | (typeof PangolinList)['tokens'][number]['identifier'] | (typeof StargateARBList)['tokens'][number]['identifier'] | (typeof SushiswapList)['tokens'][number]['identifier'] | (typeof TraderjoeList)['tokens'][number]['identifier'] | (typeof WoofiList)['tokens'][number]['identifier'] | (typeof UniswapList)['tokens'][number]['identifier'];
|
|
343
|
-
|
|
344
|
-
export declare const validateTHORName: (name: string) => boolean;
|
|
345
|
-
|
|
346
|
-
declare type WithAddress<T = {}> = T & {
|
|
347
|
-
address: string;
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
declare type WithChain<T = {}> = T & {
|
|
351
|
-
chain: Chain;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
export { }
|