@swapkit/core 1.0.0-rc.5 → 1.0.0-rc.51
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.cjs +2 -2
- package/dist/index.d.ts +9 -4
- package/dist/index.es.js +1263 -817
- package/package.json +18 -18
- package/src/client/__tests__/helpers.test.ts +35 -11
- package/src/client/explorerUrls.ts +1 -1
- package/src/client/index.ts +92 -69
- package/src/client/thornode.ts +3 -3
- package/dist/index-9e36735e.cjs +0 -1
- package/dist/index-cf1865cd.js +0 -649
package/dist/index.es.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var T = (e, t, n) => (
|
|
1
|
+
var qe = Object.defineProperty;
|
|
2
|
+
var We = (e, t, n) => t in e ? qe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var T = (e, t, n) => (We(e, typeof t != "symbol" ? t + "" : t, n), n), je = (e, t, n) => {
|
|
4
4
|
if (!t.has(e))
|
|
5
5
|
throw TypeError("Cannot " + n);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var f = (e, t, n) => (je(e, t, "read from private field"), n ? n.call(e) : t.get(e)), P = (e, t, n) => {
|
|
8
8
|
if (t.has(e))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
const
|
|
12
|
+
var Ke = Object.defineProperty, Ye = (e, t, n) => t in e ? Ke(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, C = (e, t, n) => (Ye(e, typeof t != "symbol" ? t + "" : t, n), n);
|
|
13
|
+
const fn = [
|
|
14
14
|
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
|
|
15
15
|
{
|
|
16
16
|
anonymous: !1,
|
|
@@ -108,7 +108,7 @@ const Lt = [
|
|
|
108
108
|
stateMutability: "nonpayable",
|
|
109
109
|
type: "function"
|
|
110
110
|
}
|
|
111
|
-
],
|
|
111
|
+
], Xe = [
|
|
112
112
|
{
|
|
113
113
|
inputs: [{ internalType: "address", name: "rune", type: "address" }],
|
|
114
114
|
stateMutability: "nonpayable",
|
|
@@ -283,7 +283,7 @@ const Lt = [
|
|
|
283
283
|
stateMutability: "view",
|
|
284
284
|
type: "function"
|
|
285
285
|
}
|
|
286
|
-
],
|
|
286
|
+
], Je = [
|
|
287
287
|
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
|
|
288
288
|
{
|
|
289
289
|
anonymous: !1,
|
|
@@ -447,7 +447,7 @@ const Lt = [
|
|
|
447
447
|
stateMutability: "view",
|
|
448
448
|
type: "function"
|
|
449
449
|
}
|
|
450
|
-
],
|
|
450
|
+
], Qe = [
|
|
451
451
|
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
|
|
452
452
|
{
|
|
453
453
|
anonymous: !1,
|
|
@@ -600,13 +600,13 @@ const Lt = [
|
|
|
600
600
|
type: "function"
|
|
601
601
|
}
|
|
602
602
|
];
|
|
603
|
-
var
|
|
604
|
-
const
|
|
603
|
+
var ze = /* @__PURE__ */ ((e) => (e.TC_SUPPORTED_TO_TC_SUPPORTED = "TC-TC", e.TC_SUPPORTED_TO_ETH = "TC-ERC20", e.TC_SUPPORTED_TO_AVAX = "TC-ARC20", e.TC_SUPPORTED_TO_BSC = "TC-BEP20", e.ETH_TO_TC_SUPPORTED = "ERC20-TC", e.ETH_TO_ETH = "ERC20-ERC20", e.ETH_TO_AVAX = "ERC20-ARC20", e.ETH_TO_BSC = "ERC20-BEP20", e.AVAX_TO_TC_SUPPORTED = "ARC20-TC", e.AVAX_TO_ETH = "ARC20-ERC20", e.AVAX_TO_AVAX = "ARC20-ARC20", e.AVAX_TO_BSC = "ARC20-BEP20", e.BSC_TO_TC_SUPPORTED = "BEP20-TC", e.BSC_TO_ETH = "BEP20-ERC20", e.BSC_TO_AVAX = "BEP20-ARC20", e.BSC_TO_BSC = "BEP20-BEP20", e))(ze || {});
|
|
604
|
+
const Ze = [
|
|
605
605
|
"ERC20-ERC20",
|
|
606
606
|
"ARC20-ARC20",
|
|
607
607
|
"BEP20-BEP20"
|
|
608
608
|
/* BSC_TO_BSC */
|
|
609
|
-
],
|
|
609
|
+
], et = [
|
|
610
610
|
"ERC20-TC",
|
|
611
611
|
"ERC20-ARC20",
|
|
612
612
|
"ERC20-BEP20",
|
|
@@ -617,95 +617,95 @@ const He = [
|
|
|
617
617
|
"BEP20-ERC20",
|
|
618
618
|
"BEP20-ARC20"
|
|
619
619
|
/* BSC_TO_AVAX */
|
|
620
|
-
],
|
|
620
|
+
], tt = [
|
|
621
621
|
"TC-TC",
|
|
622
622
|
"TC-ERC20",
|
|
623
623
|
"TC-ARC20",
|
|
624
624
|
"TC-BEP20"
|
|
625
625
|
/* TC_SUPPORTED_TO_BSC */
|
|
626
626
|
];
|
|
627
|
-
var
|
|
628
|
-
const
|
|
629
|
-
[
|
|
630
|
-
[
|
|
631
|
-
[
|
|
632
|
-
[
|
|
633
|
-
[
|
|
634
|
-
[
|
|
635
|
-
[
|
|
636
|
-
[
|
|
637
|
-
[
|
|
638
|
-
[
|
|
639
|
-
[
|
|
640
|
-
[
|
|
641
|
-
[
|
|
642
|
-
[
|
|
643
|
-
[
|
|
644
|
-
[
|
|
645
|
-
[
|
|
646
|
-
[
|
|
647
|
-
[
|
|
648
|
-
[
|
|
649
|
-
[
|
|
650
|
-
[
|
|
651
|
-
[
|
|
652
|
-
[
|
|
653
|
-
[
|
|
654
|
-
[
|
|
655
|
-
[
|
|
656
|
-
[
|
|
657
|
-
[
|
|
658
|
-
[
|
|
659
|
-
[
|
|
660
|
-
[
|
|
661
|
-
[
|
|
662
|
-
[
|
|
663
|
-
[
|
|
664
|
-
[
|
|
665
|
-
[
|
|
666
|
-
[
|
|
667
|
-
[
|
|
668
|
-
[
|
|
669
|
-
[
|
|
670
|
-
[
|
|
671
|
-
[
|
|
672
|
-
[
|
|
673
|
-
[
|
|
674
|
-
[
|
|
675
|
-
[
|
|
676
|
-
[
|
|
677
|
-
[
|
|
678
|
-
[
|
|
679
|
-
},
|
|
680
|
-
let n =
|
|
627
|
+
var ve = /* @__PURE__ */ ((e) => (e.VALIDATION_ERROR = "VALIDATION_ERROR", e.REQUEST_PARAMETER_ERROR = "REQUEST_PARAMETER_ERROR", e.RESPONSE_PARSING_ERROR = "RESPONSE_PARSING_ERROR", e.UNSUPPORTED = "UNSUPPORTED", e.NOT_IMPLEMENTED = "NOT_IMPLEMENTED", e.INCOMPATIBLE_ASSETS_OPERATIONS = "INCOMPATIBLE_ASSETS_OPERATIONS", e.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", e.DOWN_FOR_MAINTENANCE = "DOWN_FOR_MAINTENANCE", e.MISSING_INBOUND_INFO = "MISSING_INBOUND_INFO", e.QUOTE_FETCHING_ERROR = "QUOTE_FETCHING_ERROR", e.AIRDROP_ERROR = "AIRDROP_ERROR", e.UNHANDLED_ERROR = "UNHANDLED_ERROR", e))(ve || {}), nt = /* @__PURE__ */ ((e) => (e.HEALTH_CONTROLLER = "1000", e.LIQUIDITY_CONTROLLER = "1001", e.PROVIDER_CONTROLLER = "1002", e.QUOTE_CONTROLLER = "1003", e.SWAP_CONTROLLER = "1004", e.UTIL_CONTROLLER = "1005", e.AIRDROP_CONTROLLER = "1006", e.PROVIDER = "2000", e.ASSET = "2001", e.TOKEN_LIST = "2002", e.QUOTE = "2100", e.QUOTE_TXN_DETAILS = "2101", e.THORCHAIN_PROVIDER = "3000", e.UNISWAPV2_ETH_PROVIDER = "3001", e.UNISWAPV3_ETH_PROVIDER = "3002", e.SUSHISWAP_ETH_PROVIDER = "3003", e.PANCAKESWAP_BSC_PROVIDER = "3004", e.PANCAKESWAP_ETH_PROVIDER = "3005", e.ONEINCH_ETH_PROVIDER = "3006", e.ONEINCH_BSC_PROVIDER = "3007", e.ONEINCH_AVAX_PROVIDER = "3008", e.ZEROX_ETH_PROVIDER = "3009", e.WOOFI_AVAX_PROVIDER = "3010", e.PANGOLIN_AVAX_PROVIDER = "3011", e.TRADERJOE_AVAX_PROVIDER = "3012", e.KYBER_ETH_PROVIDER = "3013", e.KYBER_AVAX_PROVIDER = "3014", e.WOOFI_BSC_PROVIDER = "3015", e.STARGATE_PROVIDER = "3016", e.PROVIDER_UTIL = "4000", e.TXN_DETAILS = "5000", e.AIRDROP_UTIL = "6000", e))(nt || {}), y = /* @__PURE__ */ ((e) => (e.INVALID_INPUT_PARAMETERS = "1000", e.UNKNOWN_PROVIDERS = "1001", e.CANNOT_FIND_INBOUND_ADDRESS = "1002", e.NO_INBOUND_ADDRESSES = "1003", e.CHAIN_HALTED_OR_UNSUPPORTED = "1004", e.MISSING_INPUT_PARAMETER = "1005", e.INVALID_TYPE_GENERIC = "1100", e.INVALID_NUMBER_STRING = "1101", e.INVALID_NUMBER = "1102", e.INVALID_BOOLEAN = "1103", e.INVALID_OBJECT = "1104", e.INVALID_ARRAY = "1105", e.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2000", e.SELL_BUY_ASSETS_ARE_THE_SAME = "2001", e.MISSING_SOURCE_ADDRESS_FOR_SYNTH = "2002", e.AFF_ADDRESS_AND_BPS_OR_NEITHER = "2003", e.AFF_ADDRESS_TOO_LONG = "2004", e.AFF_BPS_INTEGER_0_100 = "2005", e.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = "2006", e.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = "2007", e.PREFERRED_PROFVIDER_NOT_SUPPORTED = "2008", e.DESTINATION_ADDRESS_SMART_CONTRACT = "2009", e.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = "2010", e.SOURCE_ADDRESS_SMART_CONTRACT = "2011", e.INVALID_PROVIDER = "2100", e.MISSING_CROSS_CHAIN_PROVIDER = "2101", e.MISSING_AVAX_PROVIDER = "2102", e.MISSING_BSC_PROVIDER = "2103", e.MISSING_ETH_PROVIDER = "2104", e.INVALID_PROVIDER_FOR_SWAP_OUT = "2105", e.MISSING_ARB_PROVIDER = "2106", e.INVALID_CHAIN = "2200", e.INVALID_ASSET = "2201", e.INVALID_ASSET_IDENTIFIER = "2202", e.UNSUPPORTED_CHAIN = "2204", e.UNSUPPORTED_ASSET = "2203", e.UNSUPPORTED_ASSET_FOR_SWAPOUT = "2205", e.INVALID_SOURCE_ADDRESS = "2300", e.INVALID_DESTINATION_ADDRESS = "2301", e.THORNODE_QUOTE_GENERIC_ERROR = "3000", e.NOT_ENOUGH_SYNTH_BALANCE = "3001", e.SYNTH_MINTING_CAP_REACHED = "3002", e.INVALID_QUOTE_MODE = "4000", e.NO_QUOTES = "4001", e.SERVICE_UNAVAILABLE_GENERIC = "5000", e.MISSING_GAS_DATA_GENERIC = "5100", e.MISSING_TOKEN_INFO_GENERIC = "5200", e.CANT_FIND_TOKEN_LIST = "5201", e.NO_PRICE = "5202", e.PRICE_IS_STALE = "5203", e.ADDRESS_NOT_WHITELISTED = "6000", e.ADDRESS_ALREADY_CLAIMED = "6001", e.TEMPORARY_ERROR = "9999", e))(y || {});
|
|
628
|
+
const at = {
|
|
629
|
+
[y.INVALID_INPUT_PARAMETERS]: "Invalid input parameters: {0}.",
|
|
630
|
+
[y.UNKNOWN_PROVIDERS]: "Unknown providers: {0}.",
|
|
631
|
+
[y.CANNOT_FIND_INBOUND_ADDRESS]: "Cannot find inbound address.",
|
|
632
|
+
[y.NO_INBOUND_ADDRESSES]: "No inbound addresses.",
|
|
633
|
+
[y.CHAIN_HALTED_OR_UNSUPPORTED]: "Chain {0} halted or unsupported.",
|
|
634
|
+
[y.MISSING_INPUT_PARAMETER]: "Missing input parameter: {0}.",
|
|
635
|
+
[y.INVALID_TYPE_GENERIC]: "Invalid type",
|
|
636
|
+
[y.INVALID_NUMBER_STRING]: "Invalid number string.",
|
|
637
|
+
[y.INVALID_NUMBER]: "Invalid number.",
|
|
638
|
+
[y.INVALID_BOOLEAN]: "Invalid boolean.",
|
|
639
|
+
[y.INVALID_OBJECT]: "Invalid object.",
|
|
640
|
+
[y.INVALID_ARRAY]: "Invalid array.",
|
|
641
|
+
[y.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER]: "Sell amount must be a positive integer.",
|
|
642
|
+
[y.SELL_BUY_ASSETS_ARE_THE_SAME]: "Sell and buy assets are the same.",
|
|
643
|
+
[y.MISSING_SOURCE_ADDRESS_FOR_SYNTH]: "Source address is required for synth quote.",
|
|
644
|
+
[y.AFF_ADDRESS_AND_BPS_OR_NEITHER]: "Must provide affiliateAddress and affiliateBasisPoints params, or neither.",
|
|
645
|
+
[y.AFF_ADDRESS_TOO_LONG]: "affiliateAddress too long: 3 characters max.",
|
|
646
|
+
[y.AFF_BPS_INTEGER_0_100]: "affiliateBasisPoints must be an integer between 0 and 100.",
|
|
647
|
+
[y.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN]: "Source address {0} invalid for sell chain.",
|
|
648
|
+
[y.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN]: "Destination address {0} invalid for buy chain.",
|
|
649
|
+
[y.PREFERRED_PROFVIDER_NOT_SUPPORTED]: "Preferred provider not supported.",
|
|
650
|
+
[y.DESTINATION_ADDRESS_SMART_CONTRACT]: "Destination address is a smart contract.",
|
|
651
|
+
[y.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER]: "Buy amount must be a positive integer.",
|
|
652
|
+
[y.INVALID_PROVIDER]: "Invalid provider {0}.",
|
|
653
|
+
[y.MISSING_CROSS_CHAIN_PROVIDER]: "Missing cross-chain provider.",
|
|
654
|
+
[y.MISSING_AVAX_PROVIDER]: "Missing AVAX provider.",
|
|
655
|
+
[y.MISSING_BSC_PROVIDER]: "Missing BSC provider.",
|
|
656
|
+
[y.MISSING_ETH_PROVIDER]: "Missing ETH provider.",
|
|
657
|
+
[y.MISSING_ARB_PROVIDER]: "Missing ARB provider.",
|
|
658
|
+
[y.INVALID_PROVIDER_FOR_SWAP_OUT]: "Invalid provider for swap out.",
|
|
659
|
+
[y.INVALID_CHAIN]: "Invalid chain {0}.",
|
|
660
|
+
[y.INVALID_ASSET]: "Invalid asset {0}.",
|
|
661
|
+
[y.UNSUPPORTED_CHAIN]: "Unsupported chain {0}.",
|
|
662
|
+
[y.UNSUPPORTED_ASSET]: "Unsupported asset {0}.",
|
|
663
|
+
[y.UNSUPPORTED_ASSET_FOR_SWAPOUT]: "Unsupported asset {0} for swap out.",
|
|
664
|
+
[y.THORNODE_QUOTE_GENERIC_ERROR]: "ThorNode quote generic error.",
|
|
665
|
+
[y.INVALID_SOURCE_ADDRESS]: "Invalid source address {0}",
|
|
666
|
+
[y.INVALID_DESTINATION_ADDRESS]: "Invalid destination address {0}",
|
|
667
|
+
[y.NOT_ENOUGH_SYNTH_BALANCE]: "Source address doesn't have enough synth balance for this quote.",
|
|
668
|
+
[y.SYNTH_MINTING_CAP_REACHED]: "Synth minting cap reached.",
|
|
669
|
+
[y.INVALID_QUOTE_MODE]: "Invalid quote mode.",
|
|
670
|
+
[y.NO_QUOTES]: "No quotes to service this request.",
|
|
671
|
+
[y.SERVICE_UNAVAILABLE_GENERIC]: "Service unavailable.",
|
|
672
|
+
[y.MISSING_GAS_DATA_GENERIC]: "Missing gas data.",
|
|
673
|
+
[y.MISSING_TOKEN_INFO_GENERIC]: "Missing token info.",
|
|
674
|
+
[y.CANT_FIND_TOKEN_LIST]: "Can't find tokenlist {0}.",
|
|
675
|
+
[y.NO_PRICE]: "No price for asset {0}.",
|
|
676
|
+
[y.PRICE_IS_STALE]: "Price is stale for asset {0}.",
|
|
677
|
+
[y.ADDRESS_NOT_WHITELISTED]: "Address {0} not whitelisted for airdrop.",
|
|
678
|
+
[y.ADDRESS_ALREADY_CLAIMED]: "Address {0} already claimed the airdrop."
|
|
679
|
+
}, re = (e, t) => {
|
|
680
|
+
let n = at[e];
|
|
681
681
|
for (let a = 0; a < t.length; a++)
|
|
682
682
|
n = n.replace(`{${a}}`, t[a]);
|
|
683
683
|
return t.length === 0 ? n.replace("{0}", "") : n;
|
|
684
684
|
};
|
|
685
|
-
let
|
|
685
|
+
let bn = class Ce extends Error {
|
|
686
686
|
constructor({
|
|
687
687
|
status: t,
|
|
688
688
|
revision: n,
|
|
689
689
|
module: a,
|
|
690
|
-
code:
|
|
690
|
+
code: s,
|
|
691
691
|
message: r,
|
|
692
|
-
type:
|
|
693
|
-
options: { shouldLog:
|
|
692
|
+
type: o,
|
|
693
|
+
options: { shouldLog: p, shouldThrow: d, shouldTrace: l } = {
|
|
694
694
|
shouldLog: !0,
|
|
695
695
|
shouldThrow: !0,
|
|
696
696
|
shouldTrace: !0
|
|
697
697
|
},
|
|
698
|
-
displayMessageParams:
|
|
698
|
+
displayMessageParams: u
|
|
699
699
|
}) {
|
|
700
|
-
const
|
|
701
|
-
super(
|
|
702
|
-
shouldLog:
|
|
703
|
-
shouldTrace:
|
|
704
|
-
shouldThrow:
|
|
705
|
-
}, this.displayMessageParams =
|
|
700
|
+
const c = r || re(s, u || []) || "";
|
|
701
|
+
super(c), C(this, "status"), C(this, "revision"), C(this, "type"), C(this, "module"), C(this, "code"), C(this, "message"), C(this, "display"), C(this, "stack"), C(this, "options"), C(this, "displayMessageParams"), this.status = t, this.revision = n || "NO_REVISION", this.module = a, this.message = c, this.display = re(s, u || []), this.code = s, this.type = o || ve.UNHANDLED_ERROR, this.options = {
|
|
702
|
+
shouldLog: p || !0,
|
|
703
|
+
shouldTrace: l || !0,
|
|
704
|
+
shouldThrow: d || !1
|
|
705
|
+
}, this.displayMessageParams = u || [], this.options.shouldTrace && Error.captureStackTrace(this);
|
|
706
706
|
}
|
|
707
707
|
static fromErrorInfo(t) {
|
|
708
|
-
return new
|
|
708
|
+
return new Ce(t);
|
|
709
709
|
}
|
|
710
710
|
toErrorInfo() {
|
|
711
711
|
return { ...this, identifier: this.identifier };
|
|
@@ -714,7 +714,7 @@ let Ut = class we extends Error {
|
|
|
714
714
|
return `${this.revision}-${this.type || "NO_TYPE"}-${this.module}-${this.code}`;
|
|
715
715
|
}
|
|
716
716
|
get displayMessage() {
|
|
717
|
-
return
|
|
717
|
+
return re(this.code, this.displayMessageParams || []);
|
|
718
718
|
}
|
|
719
719
|
handle() {
|
|
720
720
|
const t = `[${this.identifier}]: ${this.message}`;
|
|
@@ -724,8 +724,8 @@ let Ut = class we extends Error {
|
|
|
724
724
|
return this.toErrorInfo();
|
|
725
725
|
}
|
|
726
726
|
};
|
|
727
|
-
var
|
|
728
|
-
const
|
|
727
|
+
var i = /* @__PURE__ */ ((e) => (e.Arbitrum = "ARB", e.Avalanche = "AVAX", e.Binance = "BNB", e.BinanceSmartChain = "BSC", e.Bitcoin = "BTC", e.BitcoinCash = "BCH", e.Cosmos = "GAIA", e.Dogecoin = "DOGE", e.Ethereum = "ETH", e.Kujira = "KUJI", e.Litecoin = "LTC", e.Maya = "MAYA", e.Optimism = "OP", e.Polygon = "MATIC", e.THORChain = "THOR", e))(i || {}), st = /* @__PURE__ */ ((e) => (e.ARB = "0x0000000000000000000000000000000000000000", e.AVAX = "0x0000000000000000000000000000000000000000", e.ETH = "0x0000000000000000000000000000000000000000", e.BSC = "0x0000000000000000000000000000000000000000", e.MATIC = "0x0000000000000000000000000000000000001010", e.OP = "0x4200000000000000000000000000000000000042", e))(st || {}), it = /* @__PURE__ */ ((e) => (e.ARB = "m/44'/60'/0'/0", e.AVAX = "m/44'/60'/0'/0", e.BCH = "m/44'/145'/0'/0", e.BNB = "m/44'/714'/0'/0", e.BSC = "m/44'/60'/0'/0", e.BTC = "m/84'/0'/0'/0", e.DOGE = "m/44'/3'/0'/0", e.ETH = "m/44'/60'/0'/0", e.GAIA = "m/44'/118'/0'/0", e.KUJI = "m/44'/118'/0'/0", e.LTC = "m/84'/2'/0'/0", e.MATIC = "m/44'/60'/0'/0", e.MAYA = "m/44'/931'/0'/0", e.OP = "m/44'/60'/0'/0", e.THOR = "m/44'/931'/0'/0", e))(it || {});
|
|
728
|
+
const wn = {
|
|
729
729
|
ARB: [44, 60, 0, 0, 0],
|
|
730
730
|
AVAX: [44, 60, 0, 0, 0],
|
|
731
731
|
BCH: [44, 145, 0, 0, 0],
|
|
@@ -742,8 +742,8 @@ const Ht = {
|
|
|
742
742
|
OP: [44, 60, 0, 0, 0],
|
|
743
743
|
THOR: [44, 931, 0, 0, 0]
|
|
744
744
|
};
|
|
745
|
-
var
|
|
746
|
-
const
|
|
745
|
+
var w = /* @__PURE__ */ ((e) => (e[e.ARB = 18] = "ARB", e[e.AVAX = 18] = "AVAX", e[e.BCH = 8] = "BCH", e[e.BNB = 8] = "BNB", e[e.BSC = 18] = "BSC", e[e.BTC = 8] = "BTC", e[e.DASH = 8] = "DASH", e[e.DOGE = 8] = "DOGE", e[e.ETH = 18] = "ETH", e[e.GAIA = 6] = "GAIA", e[e.KUJI = 6] = "KUJI", e[e.LTC = 8] = "LTC", e[e.MATIC = 18] = "MATIC", e[e.MAYA = 10] = "MAYA", e[e.OP = 18] = "OP", e[e.THOR = 8] = "THOR", e))(w || {});
|
|
746
|
+
const rt = [
|
|
747
747
|
"ETH",
|
|
748
748
|
"AVAX",
|
|
749
749
|
"BSC",
|
|
@@ -751,38 +751,50 @@ const $t = [
|
|
|
751
751
|
"OP",
|
|
752
752
|
"MATIC"
|
|
753
753
|
/* Polygon */
|
|
754
|
-
],
|
|
754
|
+
], An = [
|
|
755
755
|
"BTC",
|
|
756
756
|
"BCH",
|
|
757
757
|
"DOGE",
|
|
758
758
|
"LTC"
|
|
759
759
|
/* Litecoin */
|
|
760
|
-
],
|
|
760
|
+
], En = [
|
|
761
761
|
"GAIA",
|
|
762
762
|
"THOR",
|
|
763
763
|
"BNB"
|
|
764
764
|
/* Binance */
|
|
765
|
+
], Rn = [
|
|
766
|
+
"AVAX",
|
|
767
|
+
"BNB",
|
|
768
|
+
"BSC",
|
|
769
|
+
"BTC",
|
|
770
|
+
"BCH",
|
|
771
|
+
"GAIA",
|
|
772
|
+
"DOGE",
|
|
773
|
+
"ETH",
|
|
774
|
+
"LTC",
|
|
775
|
+
"THOR"
|
|
776
|
+
/* THORChain */
|
|
765
777
|
];
|
|
766
|
-
var
|
|
767
|
-
const
|
|
778
|
+
var _e = /* @__PURE__ */ ((e) => (e.Arbitrum = "42161", e.ArbitrumHex = "0xa4b1", e.Avalanche = "43114", e.AvalancheHex = "0xa86a", e.Binance = "Binance-Chain-Tigris", e.BinanceSmartChain = "56", e.BinanceSmartChainHex = "0x38", e.Bitcoin = "bitcoin", e.BitcoinCash = "bitcoincash", e.Cosmos = "cosmoshub-4", e.Dogecoin = "dogecoin", e.Kujira = "kaiyo-1", e.Ethereum = "1", e.EthereumHex = "0x1", e.Litecoin = "litecoin", e.Maya = "mayachain-mainnet-v1", e.MayaStagenet = "mayachain-stagenet-v1", e.Optimism = "10", e.OptimismHex = "0xa", e.Polygon = "137", e.PolygonHex = "0x89", e.THORChain = "thorchain-mainnet-v1", e.THORChainStagenet = "thorchain-stagenet-v2", e))(_e || {}), Me = /* @__PURE__ */ ((e) => (e.Arbitrum = "https://arb1.arbitrum.io/rpc", e.Avalanche = "https://node-router.thorswap.net/avalanche-c", e.Binance = "", e.BinanceSmartChain = "https://bsc-dataseed.binance.org", e.Bitcoin = "https://node-router.thorswap.net/bitcoin", e.BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash", e.Cosmos = "https://node-router.thorswap.net/cosmos/rpc", e.Kujira = "https://rpc-kujira.synergynodes.com/", e.Dogecoin = "https://node-router.thorswap.net/dogecoin", e.Ethereum = "https://node-router.thorswap.net/ethereum", e.Litecoin = "https://node-router.thorswap.net/litecoin", e.Maya = "https://tendermint.mayachain.info", e.MayaStagenet = "https://stagenet.tendermint.mayachain.info", e.Optimism = "https://mainnet.optimism.io", e.Polygon = "https://polygon-rpc.com", e.THORChain = "https://rpc.thorswap.net", e.THORChainStagenet = "https://stagenet-rpc.ninerealms.com", e))(Me || {}), q = /* @__PURE__ */ ((e) => (e.Cosmos = "https://node-router.thorswap.net/cosmos/rest", e.Kujira = "https://lcd-kujira.synergynodes.com/", e.MayanodeMainnet = "https://mayanode.mayachain.info", e.MayanodeStagenet = "https://stagenet.mayanode.mayachain.info", e.ThornodeMainnet = "https://thornode.thorswap.net", e.ThornodeStagenet = "https://stagenet-thornode.ninerealms.com", e.ThorswapApi = "https://api.thorswap.finance", e.ThorswapStatic = "https://static.thorswap.net", e))(q || {});
|
|
779
|
+
const ae = Object.values(i), ot = Object.keys(i), fe = ae.reduce(
|
|
768
780
|
(e, t) => {
|
|
769
|
-
const n =
|
|
781
|
+
const n = ot.find((a) => i[a] === t);
|
|
770
782
|
return n && (e[t] = n), e;
|
|
771
783
|
},
|
|
772
784
|
{}
|
|
773
|
-
),
|
|
774
|
-
(e, t) => (e[t] =
|
|
785
|
+
), pt = ae.reduce(
|
|
786
|
+
(e, t) => (e[t] = _e[fe[t]], e),
|
|
775
787
|
{}
|
|
776
|
-
),
|
|
777
|
-
(e, t) => (e[t] =
|
|
788
|
+
), dt = ae.reduce(
|
|
789
|
+
(e, t) => (e[t] = Me[fe[t]], e),
|
|
778
790
|
{}
|
|
779
|
-
),
|
|
791
|
+
), gn = ae.reduce(
|
|
780
792
|
(e, t) => {
|
|
781
|
-
const n = `${
|
|
782
|
-
return e[t] =
|
|
793
|
+
const n = `${fe[t]}Hex`;
|
|
794
|
+
return e[t] = _e[n], e;
|
|
783
795
|
},
|
|
784
796
|
{}
|
|
785
|
-
),
|
|
797
|
+
), On = {
|
|
786
798
|
"0xa4b1": "ARB",
|
|
787
799
|
42161: "ARB",
|
|
788
800
|
"0xa86a": "AVAX",
|
|
@@ -807,7 +819,7 @@ const te = Object.values(s), Ke = Object.keys(s), me = te.reduce(
|
|
|
807
819
|
"thorchain-stagenet-v2": "THOR",
|
|
808
820
|
"thorchain-mainnet-v1": "THOR"
|
|
809
821
|
/* THORChain */
|
|
810
|
-
},
|
|
822
|
+
}, Ne = {
|
|
811
823
|
ARB: "https://arbiscan.io",
|
|
812
824
|
AVAX: "https://snowtrace.io",
|
|
813
825
|
BSC: "https://bscscan.com",
|
|
@@ -822,308 +834,658 @@ const te = Object.values(s), Ke = Object.keys(s), me = te.reduce(
|
|
|
822
834
|
MAYA: "https://www.mayascan.org",
|
|
823
835
|
OP: "https://optimistic.etherscan.io",
|
|
824
836
|
MATIC: "https://polygonscan.com",
|
|
825
|
-
THOR: "https://
|
|
837
|
+
THOR: "https://runescan.io"
|
|
826
838
|
};
|
|
827
|
-
var
|
|
839
|
+
var ut = /* @__PURE__ */ ((e) => (e[e.NoError = 36864] = "NoError", e))(ut || {}), h = /* @__PURE__ */ ((e) => (e.BOND = "BOND", e.DEPOSIT = "+", e.LEAVE = "LEAVE", e.THORNAME_REGISTER = "~", e.UNBOND = "UNBOND", e.WITHDRAW = "-", e.OPEN_LOAN = "$+", e.CLOSE_LOAN = "$-", e))(h || {}), F = /* @__PURE__ */ ((e) => (e.Average = "average", e.Fast = "fast", e.Fastest = "fastest", e))(F || {}), lt = /* @__PURE__ */ ((e) => (e.KEYSTORE = "KEYSTORE", e.XDEFI = "XDEFI", e.METAMASK = "METAMASK", e.COINBASE_WEB = "COINBASE_WEB", e.TREZOR = "TREZOR", e.TRUSTWALLET_WEB = "TRUSTWALLET_WEB", e.LEDGER = "LEDGER", e.KEPLR = "KEPLR", e.OKX = "OKX", e.BRAVE = "BRAVE", e.WALLETCONNECT = "WALLETCONNECT", e))(lt || {}), yt = Object.defineProperty, ct = (e, t, n) => t in e ? yt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, I = (e, t, n) => (ct(e, typeof t != "symbol" ? t + "" : t, n), n), mt = (e, t, n) => {
|
|
828
840
|
if (!t.has(e))
|
|
829
841
|
throw TypeError("Cannot " + n);
|
|
830
|
-
},
|
|
842
|
+
}, $ = (e, t, n) => {
|
|
831
843
|
if (t.has(e))
|
|
832
844
|
throw TypeError("Cannot add the same private member more than once");
|
|
833
845
|
t instanceof WeakSet ? t.add(e) : t.set(e, n);
|
|
834
|
-
}, R = (e, t, n) => (
|
|
835
|
-
const
|
|
836
|
-
if (e < 0)
|
|
837
|
-
throw new Error("Invalid number of year");
|
|
838
|
-
return 10 + e;
|
|
839
|
-
}, Kt = (e) => {
|
|
840
|
-
if (e.length > 30)
|
|
841
|
-
return !1;
|
|
842
|
-
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
843
|
-
return !!e.match(t);
|
|
844
|
-
}, Yt = ([e, t, n, a, i]) => `${e}'/${t}'/${n}'/${a}${typeof i != "number" ? "" : `/${i}`}`, Oe = async (e, t) => {
|
|
845
|
-
const n = Object.entries(t || {}).reduce(
|
|
846
|
-
(a, [i, r]) => (r && (a[i] = r), a),
|
|
847
|
-
{}
|
|
848
|
-
);
|
|
849
|
-
return (await fetch(
|
|
850
|
-
`${e}${t ? `?${new URLSearchParams(n).toString()}` : ""}`,
|
|
851
|
-
{ method: "GET", mode: "cors", credentials: "omit", referrer: "https://sk.thorswap.net" }
|
|
852
|
-
)).json();
|
|
853
|
-
}, et = async (e, t, n, a = !1) => {
|
|
854
|
-
const i = await fetch(`${e}`, {
|
|
855
|
-
body: t,
|
|
856
|
-
headers: n,
|
|
857
|
-
method: "POST",
|
|
858
|
-
referrer: "https://sk.thorswap.net"
|
|
859
|
-
});
|
|
860
|
-
return a ? i.text() : i.json();
|
|
861
|
-
}, tt = "0x313ce567", Ie = async ({ chain: e, to: t }) => {
|
|
846
|
+
}, R = (e, t, n) => (mt(e, t, "access private method"), n);
|
|
847
|
+
const Tt = "0x313ce567", xe = async ({ chain: e, to: t }) => {
|
|
862
848
|
try {
|
|
863
|
-
const n = await
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
849
|
+
const { result: n } = await we.post(dt[e], {
|
|
850
|
+
headers: {
|
|
851
|
+
accept: "*/*",
|
|
852
|
+
"content-type": "application/json",
|
|
853
|
+
"cache-control": "no-cache"
|
|
854
|
+
},
|
|
855
|
+
body: JSON.stringify({
|
|
868
856
|
id: 44,
|
|
869
|
-
jsonrpc: "2.0"
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
return parseInt(BigInt(
|
|
857
|
+
jsonrpc: "2.0",
|
|
858
|
+
method: "eth_call",
|
|
859
|
+
params: [{ to: t.toLowerCase(), data: Tt }, "latest"]
|
|
860
|
+
})
|
|
861
|
+
});
|
|
862
|
+
return parseInt(BigInt(n).toString());
|
|
875
863
|
} catch (n) {
|
|
876
|
-
return console.error(n),
|
|
864
|
+
return console.error(n), w[e];
|
|
877
865
|
}
|
|
878
|
-
},
|
|
879
|
-
if (e ===
|
|
880
|
-
return
|
|
866
|
+
}, ht = async (e) => {
|
|
867
|
+
if (e === i.Ethereum)
|
|
868
|
+
return w.ETH;
|
|
881
869
|
const [, t] = e.split("-");
|
|
882
|
-
return t != null && t.startsWith("0x") ?
|
|
883
|
-
},
|
|
870
|
+
return t != null && t.startsWith("0x") ? xe({ chain: i.Ethereum, to: t }) : w.ETH;
|
|
871
|
+
}, _t = async (e) => {
|
|
884
872
|
const [, t] = e.split("-");
|
|
885
|
-
return t != null && t.startsWith("0x") ?
|
|
886
|
-
},
|
|
873
|
+
return t != null && t.startsWith("0x") ? xe({ chain: i.Avalanche, to: t.toLowerCase() }) : w.AVAX;
|
|
874
|
+
}, ft = async (e) => (e === i.BinanceSmartChain, w.BSC), bt = async ({ chain: e, symbol: t }) => {
|
|
887
875
|
switch (e) {
|
|
888
|
-
case
|
|
889
|
-
return
|
|
890
|
-
case
|
|
891
|
-
return
|
|
892
|
-
case
|
|
893
|
-
return
|
|
876
|
+
case i.Ethereum:
|
|
877
|
+
return ht(t);
|
|
878
|
+
case i.Avalanche:
|
|
879
|
+
return _t(t);
|
|
880
|
+
case i.BinanceSmartChain:
|
|
881
|
+
return ft(t);
|
|
894
882
|
default:
|
|
895
|
-
return
|
|
883
|
+
return w[e];
|
|
896
884
|
}
|
|
897
|
-
},
|
|
885
|
+
}, wt = {
|
|
898
886
|
[F.Average]: 1.2,
|
|
899
887
|
[F.Fast]: 1.5,
|
|
900
888
|
[F.Fastest]: 2
|
|
901
|
-
},
|
|
889
|
+
}, De = ({ chain: e, symbol: t }) => {
|
|
902
890
|
switch (e) {
|
|
903
|
-
case
|
|
904
|
-
case
|
|
905
|
-
case
|
|
906
|
-
case
|
|
907
|
-
case
|
|
908
|
-
case
|
|
909
|
-
case
|
|
891
|
+
case i.Bitcoin:
|
|
892
|
+
case i.BitcoinCash:
|
|
893
|
+
case i.Litecoin:
|
|
894
|
+
case i.Dogecoin:
|
|
895
|
+
case i.Binance:
|
|
896
|
+
case i.Ethereum:
|
|
897
|
+
case i.Avalanche:
|
|
910
898
|
return t === e;
|
|
911
|
-
case
|
|
912
|
-
case
|
|
899
|
+
case i.Arbitrum:
|
|
900
|
+
case i.Optimism:
|
|
913
901
|
return t === "ETH";
|
|
914
|
-
case
|
|
902
|
+
case i.Maya:
|
|
915
903
|
return t === "CACAO";
|
|
916
|
-
case
|
|
904
|
+
case i.Kujira:
|
|
917
905
|
return t === "KUJI";
|
|
918
|
-
case
|
|
906
|
+
case i.Cosmos:
|
|
919
907
|
return t === "ATOM";
|
|
920
|
-
case
|
|
908
|
+
case i.Polygon:
|
|
921
909
|
return t === "MATIC";
|
|
922
|
-
case
|
|
910
|
+
case i.BinanceSmartChain:
|
|
923
911
|
return t === "BNB";
|
|
924
|
-
case
|
|
912
|
+
case i.THORChain:
|
|
925
913
|
return t === "RUNE";
|
|
926
914
|
}
|
|
927
|
-
},
|
|
915
|
+
}, At = (e) => {
|
|
928
916
|
switch (e) {
|
|
929
917
|
case "ETH.THOR":
|
|
930
918
|
return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
|
|
931
919
|
case "ETH.vTHOR":
|
|
932
920
|
return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
|
|
933
|
-
case
|
|
934
|
-
return { identifier: "GAIA.ATOM", decimal:
|
|
935
|
-
case
|
|
936
|
-
return { identifier: "THOR.RUNE", decimal:
|
|
937
|
-
case
|
|
938
|
-
return { identifier: "BSC.BNB", decimal:
|
|
939
|
-
case
|
|
940
|
-
return { identifier: "MAYA.CACAO", decimal:
|
|
921
|
+
case i.Cosmos:
|
|
922
|
+
return { identifier: "GAIA.ATOM", decimal: w[e] };
|
|
923
|
+
case i.THORChain:
|
|
924
|
+
return { identifier: "THOR.RUNE", decimal: w[e] };
|
|
925
|
+
case i.BinanceSmartChain:
|
|
926
|
+
return { identifier: "BSC.BNB", decimal: w[e] };
|
|
927
|
+
case i.Maya:
|
|
928
|
+
return { identifier: "MAYA.CACAO", decimal: w.MAYA };
|
|
941
929
|
case "MAYA.MAYA":
|
|
942
930
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
943
|
-
case
|
|
944
|
-
case
|
|
945
|
-
case
|
|
946
|
-
case
|
|
947
|
-
case
|
|
948
|
-
case
|
|
949
|
-
case
|
|
950
|
-
case
|
|
951
|
-
case
|
|
952
|
-
case
|
|
953
|
-
case
|
|
954
|
-
return { identifier: `${e}.${e}`, decimal:
|
|
955
|
-
}
|
|
956
|
-
},
|
|
931
|
+
case i.Kujira:
|
|
932
|
+
case i.Arbitrum:
|
|
933
|
+
case i.Optimism:
|
|
934
|
+
case i.BitcoinCash:
|
|
935
|
+
case i.Litecoin:
|
|
936
|
+
case i.Dogecoin:
|
|
937
|
+
case i.Binance:
|
|
938
|
+
case i.Avalanche:
|
|
939
|
+
case i.Polygon:
|
|
940
|
+
case i.Bitcoin:
|
|
941
|
+
case i.Ethereum:
|
|
942
|
+
return { identifier: `${e}.${e}`, decimal: w[e] };
|
|
943
|
+
}
|
|
944
|
+
}, Et = ({ chain: e, symbol: t }) => {
|
|
957
945
|
if (t.includes("/"))
|
|
958
946
|
return "Synth";
|
|
959
947
|
switch (e) {
|
|
960
|
-
case
|
|
961
|
-
case
|
|
962
|
-
case
|
|
963
|
-
case
|
|
964
|
-
case
|
|
965
|
-
case
|
|
948
|
+
case i.Bitcoin:
|
|
949
|
+
case i.BitcoinCash:
|
|
950
|
+
case i.Dogecoin:
|
|
951
|
+
case i.Litecoin:
|
|
952
|
+
case i.Maya:
|
|
953
|
+
case i.THORChain:
|
|
966
954
|
return "Native";
|
|
967
|
-
case
|
|
968
|
-
return t === "ATOM" ? "Native" :
|
|
969
|
-
case
|
|
970
|
-
return t ===
|
|
971
|
-
case
|
|
972
|
-
return t ===
|
|
973
|
-
case
|
|
974
|
-
return t ===
|
|
975
|
-
case
|
|
976
|
-
return t ===
|
|
977
|
-
case
|
|
978
|
-
return t ===
|
|
979
|
-
case
|
|
980
|
-
return t ===
|
|
981
|
-
case
|
|
982
|
-
return [
|
|
983
|
-
case
|
|
984
|
-
return [
|
|
985
|
-
}
|
|
986
|
-
},
|
|
955
|
+
case i.Cosmos:
|
|
956
|
+
return t === "ATOM" ? "Native" : i.Cosmos;
|
|
957
|
+
case i.Kujira:
|
|
958
|
+
return t === i.Kujira ? "Native" : i.Kujira;
|
|
959
|
+
case i.Binance:
|
|
960
|
+
return t === i.Binance ? "Native" : "BEP2";
|
|
961
|
+
case i.BinanceSmartChain:
|
|
962
|
+
return t === i.Binance ? "Native" : "BEP20";
|
|
963
|
+
case i.Ethereum:
|
|
964
|
+
return t === i.Ethereum ? "Native" : "ERC20";
|
|
965
|
+
case i.Avalanche:
|
|
966
|
+
return t === i.Avalanche ? "Native" : i.Avalanche;
|
|
967
|
+
case i.Polygon:
|
|
968
|
+
return t === i.Polygon ? "Native" : "POLYGON";
|
|
969
|
+
case i.Arbitrum:
|
|
970
|
+
return [i.Ethereum, i.Arbitrum].includes(t) ? "Native" : "ARBITRUM";
|
|
971
|
+
case i.Optimism:
|
|
972
|
+
return [i.Ethereum, i.Optimism].includes(t) ? "Native" : "OPTIMISM";
|
|
973
|
+
}
|
|
974
|
+
}, Sn = (e) => {
|
|
987
975
|
var t;
|
|
988
|
-
const [n, ...a] = e.split("."),
|
|
989
|
-
return { chain: n, symbol: r, ticker:
|
|
990
|
-
},
|
|
976
|
+
const [n, ...a] = e.split("."), s = e.includes("/"), r = a.join("."), o = (t = r == null ? void 0 : r.split("-")) == null ? void 0 : t[0];
|
|
977
|
+
return { chain: n, symbol: r, ticker: o, synth: s };
|
|
978
|
+
}, Rt = new RegExp(
|
|
979
|
+
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
980
|
+
"gmi"
|
|
981
|
+
), gt = (e) => {
|
|
982
|
+
const [t, n] = e.split(".");
|
|
983
|
+
if (!rt.includes(t))
|
|
984
|
+
return !0;
|
|
985
|
+
const [, a] = n.split("-");
|
|
986
|
+
return De({ chain: t, symbol: n }) || !!a;
|
|
987
|
+
}, In = (e) => e.filter((t) => {
|
|
988
|
+
const n = `${t.chain}.${t.symbol}`;
|
|
989
|
+
return !Rt.test(n) && gt(n) && t.value !== "0";
|
|
990
|
+
}), Ot = ({
|
|
991
991
|
liquidityUnits: e,
|
|
992
992
|
poolUnits: t,
|
|
993
993
|
runeDepth: n
|
|
994
994
|
}) => {
|
|
995
|
-
const a =
|
|
996
|
-
return
|
|
997
|
-
},
|
|
995
|
+
const a = g(e), s = g(t), r = g(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), l = a.mul(a), u = s.mul(s).mul(s);
|
|
996
|
+
return o.mul(p.sub(d).add(l)).div(u);
|
|
997
|
+
}, St = ({
|
|
998
998
|
liquidityUnits: e,
|
|
999
999
|
poolUnits: t,
|
|
1000
1000
|
assetDepth: n
|
|
1001
1001
|
}) => {
|
|
1002
|
-
const a =
|
|
1003
|
-
return
|
|
1004
|
-
},
|
|
1002
|
+
const a = g(e), s = g(t), r = g(n), o = a.mul(r), p = s.mul(s).mul(2), d = s.mul(a).mul(2), l = a.mul(a), u = o.mul(p.sub(d).add(l)), c = s.mul(s).mul(s);
|
|
1003
|
+
return u.div(c);
|
|
1004
|
+
}, vn = ({
|
|
1005
1005
|
percent: e,
|
|
1006
1006
|
runeDepth: t,
|
|
1007
1007
|
liquidityUnits: n,
|
|
1008
1008
|
poolUnits: a
|
|
1009
|
-
}) =>
|
|
1009
|
+
}) => Ot({ runeDepth: t, liquidityUnits: n, poolUnits: a }).mul(e), Cn = ({
|
|
1010
1010
|
percent: e,
|
|
1011
1011
|
assetDepth: t,
|
|
1012
1012
|
liquidityUnits: n,
|
|
1013
1013
|
poolUnits: a
|
|
1014
|
-
}) =>
|
|
1014
|
+
}) => St({ assetDepth: t, liquidityUnits: n, poolUnits: a }).mul(e), g = (e) => x.fromBigInt(BigInt(e), w.THOR), It = ({
|
|
1015
1015
|
liquidityUnits: e,
|
|
1016
1016
|
poolUnits: t,
|
|
1017
1017
|
runeDepth: n,
|
|
1018
1018
|
assetDepth: a
|
|
1019
1019
|
}) => ({
|
|
1020
|
-
assetAmount:
|
|
1021
|
-
runeAmount:
|
|
1022
|
-
}),
|
|
1020
|
+
assetAmount: g(a).mul(e).div(t),
|
|
1021
|
+
runeAmount: g(n).mul(e).div(t)
|
|
1022
|
+
}), Mn = ({
|
|
1023
1023
|
liquidityUnits: e,
|
|
1024
1024
|
poolUnits: t,
|
|
1025
1025
|
runeDepth: n,
|
|
1026
1026
|
assetDepth: a,
|
|
1027
|
-
percent:
|
|
1027
|
+
percent: s
|
|
1028
1028
|
}) => Object.fromEntries(
|
|
1029
|
-
Object.entries(
|
|
1030
|
-
([r,
|
|
1029
|
+
Object.entries(It({ liquidityUnits: e, poolUnits: t, runeDepth: n, assetDepth: a })).map(
|
|
1030
|
+
([r, o]) => [r, o.mul(s)]
|
|
1031
1031
|
)
|
|
1032
|
-
),
|
|
1032
|
+
), Nn = ({
|
|
1033
1033
|
runeDepth: e,
|
|
1034
1034
|
poolUnits: t,
|
|
1035
1035
|
assetDepth: n,
|
|
1036
1036
|
liquidityUnits: a,
|
|
1037
|
-
runeAmount:
|
|
1037
|
+
runeAmount: s,
|
|
1038
1038
|
assetAmount: r
|
|
1039
1039
|
}) => {
|
|
1040
|
-
const
|
|
1041
|
-
if (S.
|
|
1042
|
-
return
|
|
1043
|
-
const
|
|
1044
|
-
return
|
|
1045
|
-
},
|
|
1040
|
+
const o = new x({ value: e, decimal: 8 }), p = new x({ value: n, decimal: 8 }), d = new x({ value: t, decimal: 8 }), l = new x({ value: s, decimal: 8 }), u = new x({ value: r, decimal: 8 }), c = l.mul(p), _ = u.mul(o), b = l.mul(u), A = o.mul(p), E = d.mul(c.add(_.add(b.mul(2)))), O = c.add(_.add(A.mul(2))), S = E.div(O), D = g(a).add(S);
|
|
1041
|
+
if (S.getBaseValue("number") === 0)
|
|
1042
|
+
return D.div(d).getBaseValue("number");
|
|
1043
|
+
const ie = d.add(D);
|
|
1044
|
+
return D.div(ie).getBaseValue("number");
|
|
1045
|
+
}, xn = ({
|
|
1046
1046
|
runeAmount: e,
|
|
1047
1047
|
assetAmount: t,
|
|
1048
1048
|
runeDepth: n,
|
|
1049
1049
|
assetDepth: a
|
|
1050
1050
|
}) => {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1051
|
+
if (e === "0" || t === "0" || n === "0" || a === "0")
|
|
1052
|
+
return 0;
|
|
1053
|
+
const s = g(n), r = g(a), o = g(t), p = g(e), d = o.mul(s).sub(r.mul(p)), l = r.mul(p).add(s.mul(r));
|
|
1054
|
+
return Math.abs(d.div(l).getBaseValue("number"));
|
|
1055
|
+
}, vt = ({
|
|
1054
1056
|
symbol: e,
|
|
1055
1057
|
ticker: t,
|
|
1056
1058
|
chain: n
|
|
1057
|
-
}) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e,
|
|
1059
|
+
}) => n === "ETH" && t !== "ETH" ? `${t}-${e.slice(-3)}` : e, N = (e, t) => {
|
|
1058
1060
|
switch (e) {
|
|
1059
|
-
case
|
|
1060
|
-
case
|
|
1061
|
+
case h.LEAVE:
|
|
1062
|
+
case h.BOND: {
|
|
1061
1063
|
const { address: n } = t;
|
|
1062
1064
|
return `${e}:${n}`;
|
|
1063
1065
|
}
|
|
1064
|
-
case
|
|
1066
|
+
case h.UNBOND: {
|
|
1065
1067
|
const { address: n, unbondAmount: a } = t;
|
|
1066
1068
|
return `${e}:${n}:${a * 10 ** 8}`;
|
|
1067
1069
|
}
|
|
1068
|
-
case
|
|
1069
|
-
const { name: n, chain: a, address:
|
|
1070
|
-
return `${e}:${n}:${a}:${
|
|
1070
|
+
case h.THORNAME_REGISTER: {
|
|
1071
|
+
const { name: n, chain: a, address: s, owner: r } = t;
|
|
1072
|
+
return `${e}:${n}:${a}:${s}${r ? `:${r}` : ""}`;
|
|
1071
1073
|
}
|
|
1072
|
-
case
|
|
1073
|
-
const { chain: n, symbol: a, address:
|
|
1074
|
-
return r ? `${e}:${n}/${a}::t:0` : `${e}:${n}.${a}:${
|
|
1074
|
+
case h.DEPOSIT: {
|
|
1075
|
+
const { chain: n, symbol: a, address: s, singleSide: r } = t;
|
|
1076
|
+
return r ? `${e}:${n}/${a}::t:0` : `${e}:${n}.${a}:${s || ""}:t:0`;
|
|
1075
1077
|
}
|
|
1076
|
-
case
|
|
1077
|
-
const { chain: n, ticker: a, symbol:
|
|
1078
|
-
return `${e}:${n}${
|
|
1078
|
+
case h.WITHDRAW: {
|
|
1079
|
+
const { chain: n, ticker: a, symbol: s, basisPoints: r, targetAssetString: o, singleSide: p } = t, d = !p && o ? `:${o}` : "", l = vt({ chain: n, symbol: s, ticker: a });
|
|
1080
|
+
return `${e}:${n}${p ? "/" : "."}${l}:${r}${d}`;
|
|
1079
1081
|
}
|
|
1080
|
-
case
|
|
1081
|
-
case
|
|
1082
|
+
case h.OPEN_LOAN:
|
|
1083
|
+
case h.CLOSE_LOAN: {
|
|
1082
1084
|
const { asset: n, address: a } = t;
|
|
1083
1085
|
return `${e}:${n}:${a}`;
|
|
1084
1086
|
}
|
|
1085
1087
|
default:
|
|
1086
1088
|
return "";
|
|
1087
1089
|
}
|
|
1088
|
-
},
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
}) => {
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
""
|
|
1102
|
-
|
|
1103
|
-
|
|
1090
|
+
}, Dn = (e) => {
|
|
1091
|
+
if (e < 0)
|
|
1092
|
+
throw new Error("Invalid number of year");
|
|
1093
|
+
return 10 + e;
|
|
1094
|
+
}, Pn = (e) => {
|
|
1095
|
+
if (e.length > 30)
|
|
1096
|
+
return !1;
|
|
1097
|
+
const t = /^[a-zA-Z0-9+_-]+$/g;
|
|
1098
|
+
return !!e.match(t);
|
|
1099
|
+
}, Bn = ([e, t, n, a, s]) => `${e}'/${t}'/${n}'/${a}${typeof s != "number" ? "" : `/${s}`}`;
|
|
1100
|
+
class Ae extends Error {
|
|
1101
|
+
constructor(t, n, a) {
|
|
1102
|
+
const s = t.status || t.status === 0 ? t.status : "", r = t.statusText || "", o = `${s} ${r}`.trim(), p = o ? `status code ${o}` : "an unknown error";
|
|
1103
|
+
super(`Request failed with ${p}`), Object.defineProperty(this, "response", {
|
|
1104
|
+
enumerable: !0,
|
|
1105
|
+
configurable: !0,
|
|
1106
|
+
writable: !0,
|
|
1107
|
+
value: void 0
|
|
1108
|
+
}), Object.defineProperty(this, "request", {
|
|
1109
|
+
enumerable: !0,
|
|
1110
|
+
configurable: !0,
|
|
1111
|
+
writable: !0,
|
|
1112
|
+
value: void 0
|
|
1113
|
+
}), Object.defineProperty(this, "options", {
|
|
1114
|
+
enumerable: !0,
|
|
1115
|
+
configurable: !0,
|
|
1116
|
+
writable: !0,
|
|
1117
|
+
value: void 0
|
|
1118
|
+
}), this.name = "HTTPError", this.response = t, this.request = n, this.options = a;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
class Pe extends Error {
|
|
1122
|
+
constructor(t) {
|
|
1123
|
+
super("Request timed out"), Object.defineProperty(this, "request", {
|
|
1124
|
+
enumerable: !0,
|
|
1125
|
+
configurable: !0,
|
|
1126
|
+
writable: !0,
|
|
1127
|
+
value: void 0
|
|
1128
|
+
}), this.name = "TimeoutError", this.request = t;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
const J = (e) => e !== null && typeof e == "object", X = (...e) => {
|
|
1132
|
+
for (const t of e)
|
|
1133
|
+
if ((!J(t) || Array.isArray(t)) && t !== void 0)
|
|
1134
|
+
throw new TypeError("The `options` argument must be an object");
|
|
1135
|
+
return be({}, ...e);
|
|
1136
|
+
}, Be = (e = {}, t = {}) => {
|
|
1137
|
+
const n = new globalThis.Headers(e), a = t instanceof globalThis.Headers, s = new globalThis.Headers(t);
|
|
1138
|
+
for (const [r, o] of s.entries())
|
|
1139
|
+
a && o === "undefined" || o === void 0 ? n.delete(r) : n.set(r, o);
|
|
1140
|
+
return n;
|
|
1141
|
+
}, be = (...e) => {
|
|
1142
|
+
let t = {}, n = {};
|
|
1143
|
+
for (const a of e)
|
|
1144
|
+
if (Array.isArray(a))
|
|
1145
|
+
Array.isArray(t) || (t = []), t = [...t, ...a];
|
|
1146
|
+
else if (J(a)) {
|
|
1147
|
+
for (let [s, r] of Object.entries(a))
|
|
1148
|
+
J(r) && s in t && (r = be(t[s], r)), t = { ...t, [s]: r };
|
|
1149
|
+
J(a.headers) && (n = Be(n, a.headers), t.headers = n);
|
|
1150
|
+
}
|
|
1151
|
+
return t;
|
|
1152
|
+
}, Ct = (() => {
|
|
1153
|
+
let e = !1, t = !1;
|
|
1154
|
+
const n = typeof globalThis.ReadableStream == "function", a = typeof globalThis.Request == "function";
|
|
1155
|
+
return n && a && (t = new globalThis.Request("https://empty.invalid", {
|
|
1156
|
+
body: new globalThis.ReadableStream(),
|
|
1157
|
+
method: "POST",
|
|
1158
|
+
// @ts-expect-error - Types are outdated.
|
|
1159
|
+
get duplex() {
|
|
1160
|
+
return e = !0, "half";
|
|
1161
|
+
}
|
|
1162
|
+
}).headers.has("Content-Type")), e && !t;
|
|
1163
|
+
})(), Mt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", xt = typeof globalThis.FormData == "function", Le = ["get", "post", "put", "patch", "head", "delete"], Dt = {
|
|
1164
|
+
json: "application/json",
|
|
1165
|
+
text: "text/*",
|
|
1166
|
+
formData: "multipart/form-data",
|
|
1167
|
+
arrayBuffer: "*/*",
|
|
1168
|
+
blob: "*/*"
|
|
1169
|
+
}, oe = 2147483647, Ve = Symbol("stop"), Pt = {
|
|
1170
|
+
json: !0,
|
|
1171
|
+
parseJson: !0,
|
|
1172
|
+
searchParams: !0,
|
|
1173
|
+
prefixUrl: !0,
|
|
1174
|
+
retry: !0,
|
|
1175
|
+
timeout: !0,
|
|
1176
|
+
hooks: !0,
|
|
1177
|
+
throwHttpErrors: !0,
|
|
1178
|
+
onDownloadProgress: !0,
|
|
1179
|
+
fetch: !0
|
|
1180
|
+
}, Bt = {
|
|
1181
|
+
method: !0,
|
|
1182
|
+
headers: !0,
|
|
1183
|
+
body: !0,
|
|
1184
|
+
mode: !0,
|
|
1185
|
+
credentials: !0,
|
|
1186
|
+
cache: !0,
|
|
1187
|
+
redirect: !0,
|
|
1188
|
+
referrer: !0,
|
|
1189
|
+
referrerPolicy: !0,
|
|
1190
|
+
integrity: !0,
|
|
1191
|
+
keepalive: !0,
|
|
1192
|
+
signal: !0,
|
|
1193
|
+
window: !0,
|
|
1194
|
+
dispatcher: !0,
|
|
1195
|
+
duplex: !0
|
|
1196
|
+
}, Lt = (e) => Le.includes(e) ? e.toUpperCase() : e, Vt = ["get", "put", "head", "delete", "options", "trace"], Ut = [408, 413, 429, 500, 502, 503, 504], Ue = [413, 429, 503], Ee = {
|
|
1197
|
+
limit: 2,
|
|
1198
|
+
methods: Vt,
|
|
1199
|
+
statusCodes: Ut,
|
|
1200
|
+
afterStatusCodes: Ue,
|
|
1201
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
1202
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
1203
|
+
delay: (e) => 0.3 * 2 ** (e - 1) * 1e3
|
|
1204
|
+
}, Ht = (e = {}) => {
|
|
1205
|
+
if (typeof e == "number")
|
|
1206
|
+
return {
|
|
1207
|
+
...Ee,
|
|
1208
|
+
limit: e
|
|
1209
|
+
};
|
|
1210
|
+
if (e.methods && !Array.isArray(e.methods))
|
|
1211
|
+
throw new Error("retry.methods must be an array");
|
|
1212
|
+
if (e.statusCodes && !Array.isArray(e.statusCodes))
|
|
1213
|
+
throw new Error("retry.statusCodes must be an array");
|
|
1214
|
+
return {
|
|
1215
|
+
...Ee,
|
|
1216
|
+
...e,
|
|
1217
|
+
afterStatusCodes: Ue
|
|
1218
|
+
};
|
|
1219
|
+
};
|
|
1220
|
+
async function $t(e, t, n, a) {
|
|
1221
|
+
return new Promise((s, r) => {
|
|
1222
|
+
const o = setTimeout(() => {
|
|
1223
|
+
n && n.abort(), r(new Pe(e));
|
|
1224
|
+
}, a.timeout);
|
|
1225
|
+
a.fetch(e, t).then(s).catch(r).then(() => {
|
|
1226
|
+
clearTimeout(o);
|
|
1227
|
+
});
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
async function kt(e, { signal: t }) {
|
|
1231
|
+
return new Promise((n, a) => {
|
|
1232
|
+
t && (t.throwIfAborted(), t.addEventListener("abort", s, { once: !0 }));
|
|
1233
|
+
function s() {
|
|
1234
|
+
clearTimeout(r), a(t.reason);
|
|
1235
|
+
}
|
|
1236
|
+
const r = setTimeout(() => {
|
|
1237
|
+
t == null || t.removeEventListener("abort", s), n();
|
|
1238
|
+
}, e);
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
const Ft = (e, t) => {
|
|
1242
|
+
const n = {};
|
|
1243
|
+
for (const a in t)
|
|
1244
|
+
!(a in Bt) && !(a in Pt) && !(a in e) && (n[a] = t[a]);
|
|
1245
|
+
return n;
|
|
1246
|
+
};
|
|
1247
|
+
class Z {
|
|
1248
|
+
static create(t, n) {
|
|
1249
|
+
const a = new Z(t, n), s = async () => {
|
|
1250
|
+
if (typeof a._options.timeout == "number" && a._options.timeout > oe)
|
|
1251
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${oe}`);
|
|
1252
|
+
await Promise.resolve();
|
|
1253
|
+
let o = await a._fetch();
|
|
1254
|
+
for (const p of a._options.hooks.afterResponse) {
|
|
1255
|
+
const d = await p(a.request, a._options, a._decorateResponse(o.clone()));
|
|
1256
|
+
d instanceof globalThis.Response && (o = d);
|
|
1257
|
+
}
|
|
1258
|
+
if (a._decorateResponse(o), !o.ok && a._options.throwHttpErrors) {
|
|
1259
|
+
let p = new Ae(o, a.request, a._options);
|
|
1260
|
+
for (const d of a._options.hooks.beforeError)
|
|
1261
|
+
p = await d(p);
|
|
1262
|
+
throw p;
|
|
1263
|
+
}
|
|
1264
|
+
if (a._options.onDownloadProgress) {
|
|
1265
|
+
if (typeof a._options.onDownloadProgress != "function")
|
|
1266
|
+
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
1267
|
+
if (!Nt)
|
|
1268
|
+
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
1269
|
+
return a._stream(o.clone(), a._options.onDownloadProgress);
|
|
1270
|
+
}
|
|
1271
|
+
return o;
|
|
1272
|
+
}, r = a._options.retry.methods.includes(a.request.method.toLowerCase()) ? a._retry(s) : s();
|
|
1273
|
+
for (const [o, p] of Object.entries(Dt))
|
|
1274
|
+
r[o] = async () => {
|
|
1275
|
+
a.request.headers.set("accept", a.request.headers.get("accept") || p);
|
|
1276
|
+
const d = (await r).clone();
|
|
1277
|
+
if (o === "json") {
|
|
1278
|
+
if (d.status === 204 || (await d.clone().arrayBuffer()).byteLength === 0)
|
|
1279
|
+
return "";
|
|
1280
|
+
if (n.parseJson)
|
|
1281
|
+
return n.parseJson(await d.text());
|
|
1282
|
+
}
|
|
1283
|
+
return d[o]();
|
|
1284
|
+
};
|
|
1285
|
+
return r;
|
|
1286
|
+
}
|
|
1287
|
+
// eslint-disable-next-line complexity
|
|
1288
|
+
constructor(t, n = {}) {
|
|
1289
|
+
if (Object.defineProperty(this, "request", {
|
|
1290
|
+
enumerable: !0,
|
|
1291
|
+
configurable: !0,
|
|
1292
|
+
writable: !0,
|
|
1293
|
+
value: void 0
|
|
1294
|
+
}), Object.defineProperty(this, "abortController", {
|
|
1295
|
+
enumerable: !0,
|
|
1296
|
+
configurable: !0,
|
|
1297
|
+
writable: !0,
|
|
1298
|
+
value: void 0
|
|
1299
|
+
}), Object.defineProperty(this, "_retryCount", {
|
|
1300
|
+
enumerable: !0,
|
|
1301
|
+
configurable: !0,
|
|
1302
|
+
writable: !0,
|
|
1303
|
+
value: 0
|
|
1304
|
+
}), Object.defineProperty(this, "_input", {
|
|
1305
|
+
enumerable: !0,
|
|
1306
|
+
configurable: !0,
|
|
1307
|
+
writable: !0,
|
|
1308
|
+
value: void 0
|
|
1309
|
+
}), Object.defineProperty(this, "_options", {
|
|
1310
|
+
enumerable: !0,
|
|
1311
|
+
configurable: !0,
|
|
1312
|
+
writable: !0,
|
|
1313
|
+
value: void 0
|
|
1314
|
+
}), this._input = t, this._options = {
|
|
1315
|
+
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
|
1316
|
+
credentials: this._input.credentials || "same-origin",
|
|
1317
|
+
...n,
|
|
1318
|
+
headers: Be(this._input.headers, n.headers),
|
|
1319
|
+
hooks: be({
|
|
1320
|
+
beforeRequest: [],
|
|
1321
|
+
beforeRetry: [],
|
|
1322
|
+
beforeError: [],
|
|
1323
|
+
afterResponse: []
|
|
1324
|
+
}, n.hooks),
|
|
1325
|
+
method: Lt(n.method ?? this._input.method),
|
|
1326
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
1327
|
+
prefixUrl: String(n.prefixUrl || ""),
|
|
1328
|
+
retry: Ht(n.retry),
|
|
1329
|
+
throwHttpErrors: n.throwHttpErrors !== !1,
|
|
1330
|
+
timeout: n.timeout ?? 1e4,
|
|
1331
|
+
fetch: n.fetch ?? globalThis.fetch.bind(globalThis)
|
|
1332
|
+
}, typeof this._input != "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request))
|
|
1333
|
+
throw new TypeError("`input` must be a string, URL, or Request");
|
|
1334
|
+
if (this._options.prefixUrl && typeof this._input == "string") {
|
|
1335
|
+
if (this._input.startsWith("/"))
|
|
1336
|
+
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
1337
|
+
this._options.prefixUrl.endsWith("/") || (this._options.prefixUrl += "/"), this._input = this._options.prefixUrl + this._input;
|
|
1338
|
+
}
|
|
1339
|
+
if (Mt) {
|
|
1340
|
+
if (this.abortController = new globalThis.AbortController(), this._options.signal) {
|
|
1341
|
+
const a = this._options.signal;
|
|
1342
|
+
this._options.signal.addEventListener("abort", () => {
|
|
1343
|
+
this.abortController.abort(a.reason);
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
this._options.signal = this.abortController.signal;
|
|
1347
|
+
}
|
|
1348
|
+
if (Ct && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
|
|
1349
|
+
const a = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), s = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, a);
|
|
1350
|
+
(xt && 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(s, { ...this.request }), this._options);
|
|
1351
|
+
}
|
|
1352
|
+
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 }));
|
|
1353
|
+
}
|
|
1354
|
+
_calculateRetryDelay(t) {
|
|
1355
|
+
if (this._retryCount++, this._retryCount < this._options.retry.limit && !(t instanceof Pe)) {
|
|
1356
|
+
if (t instanceof Ae) {
|
|
1357
|
+
if (!this._options.retry.statusCodes.includes(t.response.status))
|
|
1358
|
+
return 0;
|
|
1359
|
+
const a = t.response.headers.get("Retry-After");
|
|
1360
|
+
if (a && this._options.retry.afterStatusCodes.includes(t.response.status)) {
|
|
1361
|
+
let s = Number(a);
|
|
1362
|
+
return Number.isNaN(s) ? s = Date.parse(a) - Date.now() : s *= 1e3, this._options.retry.maxRetryAfter !== void 0 && s > this._options.retry.maxRetryAfter ? 0 : s;
|
|
1363
|
+
}
|
|
1364
|
+
if (t.response.status === 413)
|
|
1365
|
+
return 0;
|
|
1366
|
+
}
|
|
1367
|
+
const n = this._options.retry.delay(this._retryCount);
|
|
1368
|
+
return Math.min(this._options.retry.backoffLimit, n);
|
|
1369
|
+
}
|
|
1370
|
+
return 0;
|
|
1371
|
+
}
|
|
1372
|
+
_decorateResponse(t) {
|
|
1373
|
+
return this._options.parseJson && (t.json = async () => this._options.parseJson(await t.text())), t;
|
|
1374
|
+
}
|
|
1375
|
+
async _retry(t) {
|
|
1376
|
+
try {
|
|
1377
|
+
return await t();
|
|
1378
|
+
} catch (n) {
|
|
1379
|
+
const a = Math.min(this._calculateRetryDelay(n), oe);
|
|
1380
|
+
if (a !== 0 && this._retryCount > 0) {
|
|
1381
|
+
await kt(a, { signal: this._options.signal });
|
|
1382
|
+
for (const s of this._options.hooks.beforeRetry)
|
|
1383
|
+
if (await s({
|
|
1384
|
+
request: this.request,
|
|
1385
|
+
options: this._options,
|
|
1386
|
+
error: n,
|
|
1387
|
+
retryCount: this._retryCount
|
|
1388
|
+
}) === Ve)
|
|
1389
|
+
return;
|
|
1390
|
+
return this._retry(t);
|
|
1391
|
+
}
|
|
1392
|
+
throw n;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
async _fetch() {
|
|
1396
|
+
for (const n of this._options.hooks.beforeRequest) {
|
|
1397
|
+
const a = await n(this.request, this._options);
|
|
1398
|
+
if (a instanceof Request) {
|
|
1399
|
+
this.request = a;
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
if (a instanceof Response)
|
|
1403
|
+
return a;
|
|
1404
|
+
}
|
|
1405
|
+
const t = Ft(this.request, this._options);
|
|
1406
|
+
return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : $t(this.request.clone(), t, this.abortController, this._options);
|
|
1407
|
+
}
|
|
1408
|
+
/* istanbul ignore next */
|
|
1409
|
+
_stream(t, n) {
|
|
1410
|
+
const a = Number(t.headers.get("content-length")) || 0;
|
|
1411
|
+
let s = 0;
|
|
1412
|
+
return t.status === 204 ? (n && n({ percent: 1, totalBytes: a, transferredBytes: s }, new Uint8Array()), new globalThis.Response(null, {
|
|
1413
|
+
status: t.status,
|
|
1414
|
+
statusText: t.statusText,
|
|
1415
|
+
headers: t.headers
|
|
1416
|
+
})) : new globalThis.Response(new globalThis.ReadableStream({
|
|
1417
|
+
async start(r) {
|
|
1418
|
+
const o = t.body.getReader();
|
|
1419
|
+
n && n({ percent: 0, transferredBytes: 0, totalBytes: a }, new Uint8Array());
|
|
1420
|
+
async function p() {
|
|
1421
|
+
const { done: d, value: l } = await o.read();
|
|
1422
|
+
if (d) {
|
|
1423
|
+
r.close();
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
if (n) {
|
|
1427
|
+
s += l.byteLength;
|
|
1428
|
+
const u = a === 0 ? 0 : s / a;
|
|
1429
|
+
n({ percent: u, transferredBytes: s, totalBytes: a }, l);
|
|
1430
|
+
}
|
|
1431
|
+
r.enqueue(l), await p();
|
|
1432
|
+
}
|
|
1433
|
+
await p();
|
|
1434
|
+
}
|
|
1435
|
+
}), {
|
|
1436
|
+
status: t.status,
|
|
1437
|
+
statusText: t.statusText,
|
|
1438
|
+
headers: t.headers
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
/*! MIT License © Sindre Sorhus */
|
|
1443
|
+
const ue = (e) => {
|
|
1444
|
+
const t = (n, a) => Z.create(n, X(e, a));
|
|
1445
|
+
for (const n of Le)
|
|
1446
|
+
t[n] = (a, s) => Z.create(a, X(e, s, { method: n }));
|
|
1447
|
+
return t.create = (n) => ue(X(n)), t.extend = (n) => ue(X(e, n)), t.stop = Ve, t;
|
|
1448
|
+
}, Gt = ue(), qt = Gt, Wt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, Re = qt.create({ headers: Wt }), we = {
|
|
1449
|
+
get: (e, t) => Re.get(e, t).json(),
|
|
1450
|
+
post: (e, t) => Re.post(e, t).json()
|
|
1451
|
+
}, ge = Object.values(i), jt = (e = "") => {
|
|
1104
1452
|
const t = e.toUpperCase(), [n] = t.split(".");
|
|
1105
|
-
if (
|
|
1453
|
+
if (ge.includes(n))
|
|
1106
1454
|
return !0;
|
|
1107
1455
|
const [a] = t.split("/");
|
|
1108
|
-
if (
|
|
1456
|
+
if (ge.includes(a))
|
|
1109
1457
|
return !0;
|
|
1110
1458
|
throw new Error(
|
|
1111
1459
|
`Invalid identifier: ${e}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
|
|
1112
1460
|
);
|
|
1113
|
-
},
|
|
1114
|
-
|
|
1115
|
-
|
|
1461
|
+
}, W = 8, L = (e) => 10n ** BigInt(e), G = (e) => Math.log10(parseFloat(e.toString()));
|
|
1462
|
+
function se({
|
|
1463
|
+
value: e,
|
|
1464
|
+
bigIntDecimal: t = W,
|
|
1465
|
+
decimal: n = W
|
|
1466
|
+
}) {
|
|
1467
|
+
const a = e < 0n;
|
|
1468
|
+
let s = e.toString().substring(a ? 1 : 0);
|
|
1469
|
+
const r = n - (s.length - 1);
|
|
1470
|
+
r > 0 && (s = "0".repeat(r) + s);
|
|
1471
|
+
const o = s.length - n;
|
|
1472
|
+
let p = s.slice(-n);
|
|
1473
|
+
return parseInt(p[t]) >= 5 ? p = `${p.substring(0, t - 1)}${(parseInt(p[t - 1]) + 1).toString()}` : p = p.substring(0, t), `${a ? "-" : ""}${s.slice(0, o)}.${p}`.replace(
|
|
1474
|
+
/\.?0*$/,
|
|
1475
|
+
""
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
var U, k, B, H, le, He, Q, pe, ee, ye;
|
|
1479
|
+
const Kt = class $e {
|
|
1116
1480
|
constructor(t) {
|
|
1117
|
-
|
|
1118
|
-
const n =
|
|
1119
|
-
this.decimal =
|
|
1120
|
-
Math.max(R(this, Z, oe).call(this, R(this, H, W).call(this, a)), this.decimal || 0)
|
|
1121
|
-
), R(this, ie, ve).call(this, a);
|
|
1481
|
+
$(this, U), $(this, B), $(this, le), $(this, Q), $(this, ee), I(this, "decimalMultiplier", 10n ** 8n), I(this, "bigIntValue", 0n), I(this, "decimal");
|
|
1482
|
+
const n = me(t), a = typeof t == "object";
|
|
1483
|
+
this.decimal = a ? t.decimal : void 0, this.decimalMultiplier = a && "decimalMultiplier" in t ? t.decimalMultiplier : L(Math.max(ke(te(n)), this.decimal || 0)), R(this, le, He).call(this, n);
|
|
1122
1484
|
}
|
|
1123
1485
|
static fromBigInt(t, n) {
|
|
1124
|
-
return new
|
|
1486
|
+
return new $e({
|
|
1125
1487
|
decimal: n,
|
|
1126
|
-
value:
|
|
1488
|
+
value: se({ value: t, bigIntDecimal: n, decimal: n })
|
|
1127
1489
|
});
|
|
1128
1490
|
}
|
|
1129
1491
|
static shiftDecimals({
|
|
@@ -1131,179 +1493,260 @@ const mt = class Q {
|
|
|
1131
1493
|
from: n,
|
|
1132
1494
|
to: a
|
|
1133
1495
|
}) {
|
|
1134
|
-
return
|
|
1135
|
-
|
|
1496
|
+
return this.fromBigInt(
|
|
1497
|
+
t.getBaseValue("bigint") * L(a) / L(n),
|
|
1136
1498
|
a
|
|
1137
1499
|
);
|
|
1138
1500
|
}
|
|
1139
|
-
|
|
1140
|
-
return
|
|
1141
|
-
}
|
|
1142
|
-
get baseValue() {
|
|
1143
|
-
return R(this, k, J).call(this, "string");
|
|
1144
|
-
}
|
|
1145
|
-
get baseValueNumber() {
|
|
1146
|
-
return R(this, k, J).call(this, "number");
|
|
1147
|
-
}
|
|
1148
|
-
get baseValueBigInt() {
|
|
1149
|
-
return R(this, k, J).call(this, "number");
|
|
1150
|
-
}
|
|
1151
|
-
get value() {
|
|
1152
|
-
return this.formatBigIntToSafeValue(
|
|
1153
|
-
this.bigIntValue,
|
|
1154
|
-
this.decimal || G(this.decimalMultiplier)
|
|
1155
|
-
);
|
|
1501
|
+
set(t) {
|
|
1502
|
+
return new this.constructor({ decimal: this.decimal, value: t, identifier: this.toString() });
|
|
1156
1503
|
}
|
|
1157
1504
|
add(...t) {
|
|
1158
|
-
return R(this,
|
|
1505
|
+
return R(this, U, k).call(this, "add", ...t);
|
|
1159
1506
|
}
|
|
1160
1507
|
sub(...t) {
|
|
1161
|
-
return R(this,
|
|
1508
|
+
return R(this, U, k).call(this, "sub", ...t);
|
|
1162
1509
|
}
|
|
1163
1510
|
mul(...t) {
|
|
1164
|
-
return R(this,
|
|
1511
|
+
return R(this, U, k).call(this, "mul", ...t);
|
|
1165
1512
|
}
|
|
1166
1513
|
div(...t) {
|
|
1167
|
-
return R(this,
|
|
1514
|
+
return R(this, U, k).call(this, "div", ...t);
|
|
1168
1515
|
}
|
|
1169
1516
|
gt(t) {
|
|
1170
|
-
return this
|
|
1517
|
+
return R(this, B, H).call(this, "gt", t);
|
|
1171
1518
|
}
|
|
1172
1519
|
gte(t) {
|
|
1173
|
-
return this
|
|
1520
|
+
return R(this, B, H).call(this, "gte", t);
|
|
1174
1521
|
}
|
|
1175
1522
|
lt(t) {
|
|
1176
|
-
return this
|
|
1523
|
+
return R(this, B, H).call(this, "lt", t);
|
|
1177
1524
|
}
|
|
1178
1525
|
lte(t) {
|
|
1179
|
-
return this
|
|
1526
|
+
return R(this, B, H).call(this, "lte", t);
|
|
1180
1527
|
}
|
|
1181
1528
|
eqValue(t) {
|
|
1182
|
-
return this
|
|
1529
|
+
return R(this, B, H).call(this, "eqValue", t);
|
|
1530
|
+
}
|
|
1531
|
+
// @ts-expect-error False positive
|
|
1532
|
+
getValue(t) {
|
|
1533
|
+
const n = this.formatBigIntToSafeValue(
|
|
1534
|
+
this.bigIntValue,
|
|
1535
|
+
this.decimal || G(this.decimalMultiplier)
|
|
1536
|
+
);
|
|
1537
|
+
switch (t) {
|
|
1538
|
+
case "number":
|
|
1539
|
+
return Number(n);
|
|
1540
|
+
case "string":
|
|
1541
|
+
return n;
|
|
1542
|
+
case "bigint":
|
|
1543
|
+
return this.bigIntValue * 10n ** BigInt(this.decimal || 8n) / this.decimalMultiplier;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
// @ts-expect-error
|
|
1547
|
+
getBaseValue(t) {
|
|
1548
|
+
const n = this.decimalMultiplier / L(this.decimal || w.THOR), a = this.bigIntValue / n;
|
|
1549
|
+
switch (t) {
|
|
1550
|
+
case "number":
|
|
1551
|
+
return Number(a);
|
|
1552
|
+
case "string":
|
|
1553
|
+
return a.toString();
|
|
1554
|
+
case "bigint":
|
|
1555
|
+
return a;
|
|
1556
|
+
}
|
|
1183
1557
|
}
|
|
1184
1558
|
getBigIntValue(t, n) {
|
|
1185
|
-
|
|
1559
|
+
if (!n && typeof t == "object")
|
|
1560
|
+
return t.bigIntValue;
|
|
1561
|
+
const a = me(t), s = te(a);
|
|
1562
|
+
return s === "0" || s === "undefined" ? 0n : R(this, ee, ye).call(this, s, n);
|
|
1563
|
+
}
|
|
1564
|
+
toSignificant(t = 6) {
|
|
1565
|
+
const [n, a] = this.getValue("string").split("."), s = n || "", r = a || "";
|
|
1566
|
+
if ((parseInt(s) ? s.length + r.length : r.length) <= t)
|
|
1567
|
+
return this.getValue("string");
|
|
1568
|
+
if (s.length >= t)
|
|
1569
|
+
return s.slice(0, t).padEnd(s.length, "0");
|
|
1570
|
+
if (parseInt(s))
|
|
1571
|
+
return `${s}.${r.slice(0, t - s.length)}`.padEnd(
|
|
1572
|
+
t - s.length,
|
|
1573
|
+
"0"
|
|
1574
|
+
);
|
|
1575
|
+
const o = parseInt(r), p = `${o}`.slice(0, t);
|
|
1576
|
+
return `0.${p.padStart(
|
|
1577
|
+
r.length - `${o}`.length + p.length,
|
|
1578
|
+
"0"
|
|
1579
|
+
)}`;
|
|
1580
|
+
}
|
|
1581
|
+
toFixed(t = 6) {
|
|
1582
|
+
const [n, a] = this.getValue("string").split("."), s = n || "", r = a || "";
|
|
1583
|
+
if (parseInt(s))
|
|
1584
|
+
return `${s}.${r.slice(0, t)}`.padEnd(t, "0");
|
|
1585
|
+
const o = parseInt(r), p = `${o}`.slice(0, t);
|
|
1586
|
+
return `0.${p.padStart(
|
|
1587
|
+
r.length - `${o}`.length + p.length,
|
|
1588
|
+
"0"
|
|
1589
|
+
)}`;
|
|
1590
|
+
}
|
|
1591
|
+
toAbbreviation(t = 2) {
|
|
1592
|
+
const n = this.getValue("number"), a = ["", "K", "M", "B", "T", "Q", "Qi", "S"], s = Math.floor(Math.log10(Math.abs(n)) / 3), r = a[s];
|
|
1593
|
+
if (!r)
|
|
1594
|
+
return this.getValue("string");
|
|
1595
|
+
const o = 10 ** (s * 3);
|
|
1596
|
+
return `${(n / o).toFixed(t)}${r}`;
|
|
1597
|
+
}
|
|
1598
|
+
toCurrency(t = "$", {
|
|
1599
|
+
currencyPosition: n = "start",
|
|
1600
|
+
decimal: a = 2,
|
|
1601
|
+
decimalSeparator: s = ".",
|
|
1602
|
+
thousandSeparator: r = ","
|
|
1603
|
+
} = {}) {
|
|
1604
|
+
const o = this.getValue("number"), [p, d = ""] = o.toFixed(6).split("."), l = p.replace(/\B(?=(\d{3})+(?!\d))/g, r), u = !p && !d ? "0.00" : p === "0" ? `${parseFloat(`0.${d}`)}`.replace(".", s) : `${l}${parseInt(d) ? `${s}${d.slice(0, a)}` : ""}`;
|
|
1605
|
+
return `${n === "start" ? t : ""}${u}${n === "end" ? t : ""}`;
|
|
1186
1606
|
}
|
|
1187
1607
|
formatBigIntToSafeValue(t, n) {
|
|
1188
|
-
const a = n || this.decimal ||
|
|
1608
|
+
const a = n || this.decimal || W, s = Math.max(
|
|
1189
1609
|
a,
|
|
1190
1610
|
G(this.decimalMultiplier)
|
|
1191
|
-
), r = t < 0n;
|
|
1192
|
-
let
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
return parseInt(c[a]) >= 5 ? c = `${c.substring(0, a - 1)}${(parseInt(c[a - 1]) + 1).toString()}` : c = c.substring(0, a), `${r ? "-" : ""}${p.slice(0, l)}.${c}`.replace(
|
|
1198
|
-
/\.?0*$/,
|
|
1199
|
-
""
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
toSignificant(t) {
|
|
1203
|
-
const n = this.value.split("."), a = n[0], i = n[1];
|
|
1204
|
-
return i ? `${a}.${i.slice(0, t || this.decimal)}`.replace(
|
|
1205
|
-
/\.?0*$/,
|
|
1206
|
-
""
|
|
1207
|
-
) : a;
|
|
1611
|
+
), r = t < 0n, o = t.toString().substring(r ? 1 : 0), p = s - (o.length - 1), d = p > 0 ? "0".repeat(p) + o : o, l = d.length - s;
|
|
1612
|
+
let u = d.slice(-s);
|
|
1613
|
+
return parseInt(u[a]) >= 5 ? u = `${u.substring(0, a - 1)}${(parseInt(u[a - 1]) + 1).toString()}` : u = u.substring(0, a), `${r ? "-" : ""}${d.slice(
|
|
1614
|
+
0,
|
|
1615
|
+
l
|
|
1616
|
+
)}.${u}`.replace(/\.?0*$/, "");
|
|
1208
1617
|
}
|
|
1209
1618
|
};
|
|
1210
|
-
|
|
1211
|
-
const n = R(this,
|
|
1619
|
+
U = /* @__PURE__ */ new WeakSet(), k = function(e, ...t) {
|
|
1620
|
+
const n = R(this, Q, pe).call(this, this, ...t), a = Math.max(n, G(this.decimalMultiplier)), s = L(a), r = t.reduce(
|
|
1212
1621
|
(p, d) => {
|
|
1213
|
-
const l = this.getBigIntValue(d,
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1622
|
+
const l = this.getBigIntValue(d, a);
|
|
1623
|
+
switch (e) {
|
|
1624
|
+
case "add":
|
|
1625
|
+
return p + l;
|
|
1626
|
+
case "sub":
|
|
1627
|
+
return p - l;
|
|
1628
|
+
case "mul":
|
|
1629
|
+
return p * l / s;
|
|
1630
|
+
case "div": {
|
|
1631
|
+
if (l === 0n)
|
|
1632
|
+
throw new RangeError("Division by zero");
|
|
1633
|
+
return p * s / l;
|
|
1634
|
+
}
|
|
1635
|
+
default:
|
|
1636
|
+
return p;
|
|
1637
|
+
}
|
|
1217
1638
|
},
|
|
1218
1639
|
//normalize is to precision multiplier base
|
|
1219
|
-
this.bigIntValue *
|
|
1220
|
-
),
|
|
1221
|
-
bigIntDecimal:
|
|
1222
|
-
decimal:
|
|
1223
|
-
value:
|
|
1640
|
+
this.bigIntValue * s / this.decimalMultiplier
|
|
1641
|
+
), o = se({
|
|
1642
|
+
bigIntDecimal: a,
|
|
1643
|
+
decimal: a,
|
|
1644
|
+
value: r
|
|
1224
1645
|
});
|
|
1225
|
-
return new this.constructor({
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
).
|
|
1233
|
-
return Math.max(...t, K);
|
|
1234
|
-
}, z = /* @__PURE__ */ new WeakSet(), pe = function(e, t) {
|
|
1235
|
-
const n = t ? U(t) : this.decimalMultiplier, a = G(n), [i, r = ""] = e.split(".");
|
|
1236
|
-
return BigInt(`${i}${r.padEnd(a, "0")}`);
|
|
1237
|
-
}, H = /* @__PURE__ */ new WeakSet(), W = function(e) {
|
|
1238
|
-
const t = `${typeof e == "number" ? Number(e).toLocaleString("fullwide", {
|
|
1239
|
-
useGrouping: !1,
|
|
1240
|
-
maximumFractionDigits: 20
|
|
1241
|
-
}) : e}`.replaceAll(",", ".").split(".");
|
|
1242
|
-
return t.length > 1 ? `${t.slice(0, -1).join("")}.${t.at(-1)}` : t[0];
|
|
1243
|
-
}, Z = /* @__PURE__ */ new WeakSet(), oe = function(e) {
|
|
1244
|
-
var t;
|
|
1245
|
-
const n = ((t = e.split(".")[1]) == null ? void 0 : t.length) || 0;
|
|
1246
|
-
return Math.max(n, K);
|
|
1247
|
-
}, k = /* @__PURE__ */ new WeakSet(), J = function(e) {
|
|
1248
|
-
const t = this.decimalMultiplier / U(this.decimal || 0), n = this.bigIntValue / t;
|
|
1646
|
+
return new this.constructor({
|
|
1647
|
+
decimalMultiplier: L(a),
|
|
1648
|
+
decimal: this.decimal,
|
|
1649
|
+
value: o,
|
|
1650
|
+
identifier: this.toString()
|
|
1651
|
+
});
|
|
1652
|
+
}, B = /* @__PURE__ */ new WeakSet(), H = function(e, ...t) {
|
|
1653
|
+
const n = R(this, Q, pe).call(this, this, ...t), a = this.getBigIntValue(t[0], n), s = this.getBigIntValue(this, n);
|
|
1249
1654
|
switch (e) {
|
|
1250
|
-
case "
|
|
1251
|
-
return
|
|
1252
|
-
case "
|
|
1253
|
-
return
|
|
1254
|
-
|
|
1255
|
-
return
|
|
1655
|
+
case "gt":
|
|
1656
|
+
return s > a;
|
|
1657
|
+
case "gte":
|
|
1658
|
+
return s >= a;
|
|
1659
|
+
case "lt":
|
|
1660
|
+
return s < a;
|
|
1661
|
+
case "lte":
|
|
1662
|
+
return s <= a;
|
|
1663
|
+
case "eqValue":
|
|
1664
|
+
return s === a;
|
|
1256
1665
|
}
|
|
1666
|
+
}, le = /* @__PURE__ */ new WeakSet(), He = function(e) {
|
|
1667
|
+
const t = te(e) || "0";
|
|
1668
|
+
this.bigIntValue = R(this, ee, ye).call(this, t);
|
|
1669
|
+
}, Q = /* @__PURE__ */ new WeakSet(), pe = function(...e) {
|
|
1670
|
+
const t = e.map((n) => typeof n == "object" ? n.decimal || G(n.decimalMultiplier) : ke(te(n))).filter(Boolean);
|
|
1671
|
+
return Math.max(...t, W);
|
|
1672
|
+
}, ee = /* @__PURE__ */ new WeakSet(), ye = function(e, t) {
|
|
1673
|
+
const n = t ? L(t) : this.decimalMultiplier, a = G(n), [s = "", r = ""] = e.split(".");
|
|
1674
|
+
return BigInt(`${s}${r.padEnd(a, "0")}`);
|
|
1257
1675
|
};
|
|
1258
|
-
let
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1676
|
+
let ce = Kt;
|
|
1677
|
+
const Yt = Intl.NumberFormat("fullwide", {
|
|
1678
|
+
useGrouping: !1,
|
|
1679
|
+
maximumFractionDigits: 20
|
|
1680
|
+
});
|
|
1681
|
+
function te(e) {
|
|
1682
|
+
const t = `${typeof e == "number" ? Yt.format(e) : me(e)}`.replaceAll(",", ".").split(".");
|
|
1683
|
+
return t.length > 1 ? `${t.slice(0, -1).join("")}.${t.at(-1)}` : t[0];
|
|
1684
|
+
}
|
|
1685
|
+
function ke(e) {
|
|
1686
|
+
var t;
|
|
1687
|
+
const n = ((t = e.split(".")[1]) == null ? void 0 : t.length) || 0;
|
|
1688
|
+
return Math.max(n, W);
|
|
1689
|
+
}
|
|
1690
|
+
function me(e) {
|
|
1691
|
+
return typeof e == "object" ? "getValue" in e ? e.getValue("string") : e.value : e;
|
|
1692
|
+
}
|
|
1693
|
+
const z = (e, t) => typeof e == "bigint" ? se({ value: e, bigIntDecimal: t, decimal: t }) : e;
|
|
1694
|
+
let Te;
|
|
1695
|
+
const Oe = (e) => {
|
|
1696
|
+
if (!Te)
|
|
1261
1697
|
throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
|
|
1262
|
-
return
|
|
1263
|
-
},
|
|
1264
|
-
|
|
1265
|
-
const n = await
|
|
1266
|
-
return new
|
|
1698
|
+
return Te.get(e.toUpperCase()) || { decimal: w.THOR, identifier: "" };
|
|
1699
|
+
}, Se = async (e, t = 0) => {
|
|
1700
|
+
jt(e);
|
|
1701
|
+
const n = await bt(he(e)), a = z(t, n);
|
|
1702
|
+
return new M({ decimal: n, value: a, identifier: e });
|
|
1267
1703
|
};
|
|
1268
|
-
class
|
|
1704
|
+
class M extends ce {
|
|
1269
1705
|
constructor(t) {
|
|
1706
|
+
const n = "identifier" in t ? t.identifier : `${t.chain}.${t.symbol}`;
|
|
1270
1707
|
super(
|
|
1271
|
-
t.value instanceof
|
|
1272
|
-
),
|
|
1273
|
-
const
|
|
1274
|
-
this.type =
|
|
1708
|
+
t.value instanceof ce ? t.value : { decimal: t.decimal, value: t.value }
|
|
1709
|
+
), I(this, "address"), I(this, "chain"), I(this, "isGasAsset", !1), I(this, "isSynthetic", !1), I(this, "symbol"), I(this, "tax"), I(this, "ticker"), I(this, "type");
|
|
1710
|
+
const a = he(n);
|
|
1711
|
+
this.type = Et(a), this.chain = a.chain, this.ticker = a.ticker, this.symbol = a.symbol, this.address = a.address, this.isSynthetic = a.isSynthetic, this.isGasAsset = a.isGasAsset, this.tax = t.tax;
|
|
1712
|
+
}
|
|
1713
|
+
toString(t = !1) {
|
|
1714
|
+
const n = this.isSynthetic ? this.symbol : this.ticker;
|
|
1715
|
+
return t ? (
|
|
1716
|
+
// ETH/THOR-0xa5f2211b9b8170f694421f2046281775e8468044 | USDT
|
|
1717
|
+
n
|
|
1718
|
+
) : (
|
|
1719
|
+
// THOR.ETH/ETH | ETH.USDT-0x1234567890
|
|
1720
|
+
`${this.chain}.${this.symbol}`
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
toUrl() {
|
|
1724
|
+
return this.isSynthetic ? `${this.chain}.${this.symbol.replace("/", ".")}` : this.toString();
|
|
1725
|
+
}
|
|
1726
|
+
eq({ chain: t, symbol: n }) {
|
|
1727
|
+
return this.chain === t && this.symbol === n;
|
|
1275
1728
|
}
|
|
1276
1729
|
static async fromString(t, n = 0) {
|
|
1277
|
-
return
|
|
1730
|
+
return Se(t, n);
|
|
1278
1731
|
}
|
|
1279
1732
|
static fromStringSync(t, n = 0) {
|
|
1280
|
-
const {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1733
|
+
const { isSynthetic: a } = he(t), {
|
|
1734
|
+
tax: s,
|
|
1735
|
+
decimal: r,
|
|
1736
|
+
identifier: o
|
|
1737
|
+
} = Oe(t), p = z(n, r);
|
|
1738
|
+
return o ? new M({ tax: s, decimal: r, identifier: o, value: p }) : a ? new M({ tax: s, decimal: 8, identifier: t, value: p }) : void 0;
|
|
1284
1739
|
}
|
|
1285
1740
|
static async fromIdentifier(t, n = 0) {
|
|
1286
|
-
return
|
|
1741
|
+
return Se(t, n);
|
|
1287
1742
|
}
|
|
1288
1743
|
static fromIdentifierSync(t, n = 0) {
|
|
1289
|
-
const { decimal: a, identifier:
|
|
1290
|
-
return new
|
|
1744
|
+
const { decimal: a, identifier: s } = Oe(t), r = z(n, a);
|
|
1745
|
+
return new M({ decimal: a, identifier: s, value: r });
|
|
1291
1746
|
}
|
|
1292
1747
|
static fromChainOrSignature(t, n = 0) {
|
|
1293
|
-
const { decimal: a, identifier:
|
|
1294
|
-
return new
|
|
1295
|
-
}
|
|
1296
|
-
static async fromTCQuote(t, n = 0) {
|
|
1297
|
-
const a = await Se(ye(t)), i = this.shiftDecimals({ value: n, from: E.THOR, to: a });
|
|
1298
|
-
return new v({ value: i, identifier: t, decimal: a });
|
|
1299
|
-
}
|
|
1300
|
-
static fromTCQuoteStatic(t, n = 0) {
|
|
1301
|
-
const a = se(t), i = this.shiftDecimals({
|
|
1302
|
-
value: n,
|
|
1303
|
-
from: E.THOR,
|
|
1304
|
-
to: a.decimal
|
|
1305
|
-
});
|
|
1306
|
-
return new v({ ...a, value: i });
|
|
1748
|
+
const { decimal: a, identifier: s } = At(t), r = z(n, a);
|
|
1749
|
+
return new M({ value: r, decimal: a, identifier: s });
|
|
1307
1750
|
}
|
|
1308
1751
|
static async loadStaticAssets() {
|
|
1309
1752
|
return new Promise(
|
|
@@ -1313,14 +1756,14 @@ class v extends de {
|
|
|
1313
1756
|
// Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
|
1314
1757
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1315
1758
|
ThorchainList: a,
|
|
1316
|
-
NativeList:
|
|
1759
|
+
NativeList: s,
|
|
1317
1760
|
...r
|
|
1318
1761
|
} = await import("@swapkit/tokens");
|
|
1319
|
-
|
|
1320
|
-
(
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
}),
|
|
1762
|
+
Te = [s, ...Object.values(r)].reduce(
|
|
1763
|
+
(o, { tokens: p }) => (p.forEach(({ identifier: d, chain: l, ...u }) => {
|
|
1764
|
+
const c = "decimals" in u ? u.decimals : w[l];
|
|
1765
|
+
o.set(d, { identifier: d, decimal: c });
|
|
1766
|
+
}), o),
|
|
1324
1767
|
/* @__PURE__ */ new Map()
|
|
1325
1768
|
), t({ ok: !0 });
|
|
1326
1769
|
} catch (a) {
|
|
@@ -1333,45 +1776,36 @@ class v extends de {
|
|
|
1333
1776
|
}
|
|
1334
1777
|
);
|
|
1335
1778
|
}
|
|
1336
|
-
get assetValue() {
|
|
1337
|
-
return `${this.value} ${this.ticker}`;
|
|
1338
|
-
}
|
|
1339
|
-
toString() {
|
|
1340
|
-
return `${this.chain}.${this.symbol}`;
|
|
1341
|
-
}
|
|
1342
|
-
eq({ chain: t, symbol: n }) {
|
|
1343
|
-
return this.chain === t && this.symbol === n;
|
|
1344
|
-
}
|
|
1345
1779
|
}
|
|
1346
|
-
const
|
|
1347
|
-
const t =
|
|
1780
|
+
const de = (e) => {
|
|
1781
|
+
const t = M.fromChainOrSignature(e);
|
|
1348
1782
|
switch (e) {
|
|
1349
|
-
case
|
|
1350
|
-
case
|
|
1351
|
-
case
|
|
1352
|
-
return t.
|
|
1353
|
-
case
|
|
1354
|
-
return t.
|
|
1355
|
-
case
|
|
1356
|
-
case
|
|
1357
|
-
return t.
|
|
1358
|
-
case
|
|
1359
|
-
case
|
|
1360
|
-
return t.
|
|
1783
|
+
case i.Bitcoin:
|
|
1784
|
+
case i.Litecoin:
|
|
1785
|
+
case i.BitcoinCash:
|
|
1786
|
+
return t.set(10001e-8);
|
|
1787
|
+
case i.Dogecoin:
|
|
1788
|
+
return t.set(1.00000001);
|
|
1789
|
+
case i.Avalanche:
|
|
1790
|
+
case i.Ethereum:
|
|
1791
|
+
return t.set(1e-8);
|
|
1792
|
+
case i.THORChain:
|
|
1793
|
+
case i.Maya:
|
|
1794
|
+
return t.set(0);
|
|
1361
1795
|
default:
|
|
1362
|
-
return t.
|
|
1796
|
+
return t.set(1e-8);
|
|
1363
1797
|
}
|
|
1364
|
-
},
|
|
1365
|
-
const t = e.slice(0, 14).includes("/"), n = e.includes(".") ? e : `${
|
|
1798
|
+
}, he = (e) => {
|
|
1799
|
+
const t = e.slice(0, 14).includes("/"), [n, a] = e.split(".").pop().split("/"), s = e.includes(".") && !t ? e : `${i.THORChain}.${a}`, [r, o] = s.split("."), [p, d] = (t ? a : o).split("-");
|
|
1366
1800
|
return {
|
|
1367
|
-
address:
|
|
1368
|
-
chain:
|
|
1369
|
-
isGasAsset:
|
|
1801
|
+
address: d == null ? void 0 : d.toLowerCase(),
|
|
1802
|
+
chain: r,
|
|
1803
|
+
isGasAsset: De({ chain: r, symbol: o }),
|
|
1370
1804
|
isSynthetic: t,
|
|
1371
|
-
symbol:
|
|
1372
|
-
ticker:
|
|
1805
|
+
symbol: (t ? `${n}/` : "") + (d ? `${p}-${(d == null ? void 0 : d.toLowerCase()) ?? ""}` : o),
|
|
1806
|
+
ticker: p
|
|
1373
1807
|
};
|
|
1374
|
-
},
|
|
1808
|
+
}, Xt = {
|
|
1375
1809
|
/**
|
|
1376
1810
|
* Core
|
|
1377
1811
|
*/
|
|
@@ -1430,18 +1864,21 @@ const fe = (e) => {
|
|
|
1430
1864
|
};
|
|
1431
1865
|
class m extends Error {
|
|
1432
1866
|
constructor(t, n) {
|
|
1433
|
-
console.error(n), super(t, { cause: { code:
|
|
1867
|
+
console.error(n, { stack: n == null ? void 0 : n.stack, message: n == null ? void 0 : n.message }), super(t, { cause: { code: Xt[t], message: t } }), Object.setPrototypeOf(this, m.prototype);
|
|
1434
1868
|
}
|
|
1435
1869
|
}
|
|
1436
|
-
class
|
|
1870
|
+
class x extends ce {
|
|
1437
1871
|
eq(t) {
|
|
1438
1872
|
return this.eqValue(t);
|
|
1439
1873
|
}
|
|
1440
|
-
|
|
1441
|
-
return
|
|
1874
|
+
static fromBigInt(t, n) {
|
|
1875
|
+
return new x({
|
|
1876
|
+
decimal: n,
|
|
1877
|
+
value: se({ value: t, bigIntDecimal: n, decimal: n })
|
|
1878
|
+
});
|
|
1442
1879
|
}
|
|
1443
1880
|
}
|
|
1444
|
-
const
|
|
1881
|
+
const Jt = [
|
|
1445
1882
|
{
|
|
1446
1883
|
inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
|
|
1447
1884
|
stateMutability: "nonpayable",
|
|
@@ -1532,7 +1969,7 @@ const _t = [
|
|
|
1532
1969
|
type: "function"
|
|
1533
1970
|
},
|
|
1534
1971
|
{ stateMutability: "payable", type: "receive" }
|
|
1535
|
-
],
|
|
1972
|
+
], Qt = [
|
|
1536
1973
|
{
|
|
1537
1974
|
inputs: [
|
|
1538
1975
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -1676,7 +2113,7 @@ const _t = [
|
|
|
1676
2113
|
type: "function"
|
|
1677
2114
|
},
|
|
1678
2115
|
{ stateMutability: "payable", type: "receive" }
|
|
1679
|
-
],
|
|
2116
|
+
], zt = [
|
|
1680
2117
|
{
|
|
1681
2118
|
inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
|
|
1682
2119
|
stateMutability: "nonpayable",
|
|
@@ -1781,7 +2218,7 @@ const _t = [
|
|
|
1781
2218
|
type: "function"
|
|
1782
2219
|
},
|
|
1783
2220
|
{ stateMutability: "payable", type: "receive" }
|
|
1784
|
-
],
|
|
2221
|
+
], Zt = [
|
|
1785
2222
|
{
|
|
1786
2223
|
inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
|
|
1787
2224
|
stateMutability: "nonpayable",
|
|
@@ -1872,7 +2309,7 @@ const _t = [
|
|
|
1872
2309
|
type: "function"
|
|
1873
2310
|
},
|
|
1874
2311
|
{ stateMutability: "payable", type: "receive" }
|
|
1875
|
-
],
|
|
2312
|
+
], en = [
|
|
1876
2313
|
{
|
|
1877
2314
|
inputs: [
|
|
1878
2315
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2016,7 +2453,7 @@ const _t = [
|
|
|
2016
2453
|
type: "function"
|
|
2017
2454
|
},
|
|
2018
2455
|
{ stateMutability: "payable", type: "receive" }
|
|
2019
|
-
],
|
|
2456
|
+
], tn = [
|
|
2020
2457
|
{
|
|
2021
2458
|
inputs: [
|
|
2022
2459
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2135,7 +2572,7 @@ const _t = [
|
|
|
2135
2572
|
type: "function"
|
|
2136
2573
|
},
|
|
2137
2574
|
{ stateMutability: "payable", type: "receive" }
|
|
2138
|
-
],
|
|
2575
|
+
], nn = [
|
|
2139
2576
|
{
|
|
2140
2577
|
inputs: [
|
|
2141
2578
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2254,7 +2691,7 @@ const _t = [
|
|
|
2254
2691
|
type: "function"
|
|
2255
2692
|
},
|
|
2256
2693
|
{ stateMutability: "payable", type: "receive" }
|
|
2257
|
-
],
|
|
2694
|
+
], an = [
|
|
2258
2695
|
{
|
|
2259
2696
|
inputs: [
|
|
2260
2697
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2373,7 +2810,7 @@ const _t = [
|
|
|
2373
2810
|
type: "function"
|
|
2374
2811
|
},
|
|
2375
2812
|
{ stateMutability: "payable", type: "receive" }
|
|
2376
|
-
],
|
|
2813
|
+
], sn = [
|
|
2377
2814
|
{
|
|
2378
2815
|
inputs: [
|
|
2379
2816
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2492,7 +2929,7 @@ const _t = [
|
|
|
2492
2929
|
type: "function"
|
|
2493
2930
|
},
|
|
2494
2931
|
{ stateMutability: "payable", type: "receive" }
|
|
2495
|
-
],
|
|
2932
|
+
], rn = [
|
|
2496
2933
|
{
|
|
2497
2934
|
inputs: [
|
|
2498
2935
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2619,7 +3056,7 @@ const _t = [
|
|
|
2619
3056
|
type: "function"
|
|
2620
3057
|
},
|
|
2621
3058
|
{ stateMutability: "payable", type: "receive" }
|
|
2622
|
-
],
|
|
3059
|
+
], on = [
|
|
2623
3060
|
{
|
|
2624
3061
|
inputs: [
|
|
2625
3062
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2746,7 +3183,7 @@ const _t = [
|
|
|
2746
3183
|
type: "function"
|
|
2747
3184
|
},
|
|
2748
3185
|
{ stateMutability: "payable", type: "receive" }
|
|
2749
|
-
],
|
|
3186
|
+
], pn = [
|
|
2750
3187
|
{
|
|
2751
3188
|
inputs: [
|
|
2752
3189
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -2873,7 +3310,7 @@ const _t = [
|
|
|
2873
3310
|
type: "function"
|
|
2874
3311
|
},
|
|
2875
3312
|
{ stateMutability: "payable", type: "receive" }
|
|
2876
|
-
],
|
|
3313
|
+
], dn = [
|
|
2877
3314
|
{
|
|
2878
3315
|
inputs: [
|
|
2879
3316
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -3000,7 +3437,7 @@ const _t = [
|
|
|
3000
3437
|
type: "function"
|
|
3001
3438
|
},
|
|
3002
3439
|
{ stateMutability: "payable", type: "receive" }
|
|
3003
|
-
],
|
|
3440
|
+
], un = [
|
|
3004
3441
|
{
|
|
3005
3442
|
inputs: [
|
|
3006
3443
|
{ internalType: "address", name: "_ttp", type: "address" },
|
|
@@ -3127,236 +3564,240 @@ const _t = [
|
|
|
3127
3564
|
type: "function"
|
|
3128
3565
|
},
|
|
3129
3566
|
{ stateMutability: "payable", type: "receive" }
|
|
3130
|
-
],
|
|
3131
|
-
["0x7C38b8B2efF28511ECc14a621e263857Fb5771d3".toLowerCase()]:
|
|
3132
|
-
["0xB6fA6f1DcD686F4A573Fd243a6FABb4ba36Ba98c".toLowerCase()]:
|
|
3133
|
-
["0xd31f7e39afECEc4855fecc51b693F9A0Cec49fd2".toLowerCase()]:
|
|
3134
|
-
},
|
|
3135
|
-
...
|
|
3567
|
+
], Fe = {
|
|
3568
|
+
["0x7C38b8B2efF28511ECc14a621e263857Fb5771d3".toLowerCase()]: Jt,
|
|
3569
|
+
["0xB6fA6f1DcD686F4A573Fd243a6FABb4ba36Ba98c".toLowerCase()]: zt,
|
|
3570
|
+
["0xd31f7e39afECEc4855fecc51b693F9A0Cec49fd2".toLowerCase()]: Zt
|
|
3571
|
+
}, ln = {
|
|
3572
|
+
...Fe,
|
|
3136
3573
|
// AVAX
|
|
3137
|
-
["0x942c6dA485FD6cEf255853ef83a149d43A73F18a".toLowerCase()]:
|
|
3138
|
-
["0x5505BE604dFA8A1ad402A71f8A357fba47F9bf5a".toLowerCase()]:
|
|
3139
|
-
["0x3b7DbdD635B99cEa39D3d95Dbd0217F05e55B212".toLowerCase()]:
|
|
3574
|
+
["0x942c6dA485FD6cEf255853ef83a149d43A73F18a".toLowerCase()]: tn,
|
|
3575
|
+
["0x5505BE604dFA8A1ad402A71f8A357fba47F9bf5a".toLowerCase()]: Qt,
|
|
3576
|
+
["0x3b7DbdD635B99cEa39D3d95Dbd0217F05e55B212".toLowerCase()]: an,
|
|
3140
3577
|
// BSC
|
|
3141
|
-
["0x30912B38618D3D37De3191A4FFE982C65a9aEC2E".toLowerCase()]:
|
|
3578
|
+
["0x30912B38618D3D37De3191A4FFE982C65a9aEC2E".toLowerCase()]: en,
|
|
3142
3579
|
// ETH
|
|
3143
|
-
["0xbf365e79aA44A2164DA135100C57FDB6635ae870".toLowerCase()]:
|
|
3144
|
-
["0x86904Eb2b3c743400D03f929F2246EfA80B91215".toLowerCase()]:
|
|
3145
|
-
["0x3660dE6C56cFD31998397652941ECe42118375DA".toLowerCase()]:
|
|
3146
|
-
["0xBd68cBe6c247e2c3a0e36B8F0e24964914f26Ee8".toLowerCase()]:
|
|
3147
|
-
["0xe4ddca21881bac219af7f217703db0475d2a9f02".toLowerCase()]:
|
|
3148
|
-
["0x11733abf0cdb43298f7e949c930188451a9a9ef2".toLowerCase()]:
|
|
3149
|
-
["0xb33874810e5395eb49d8bd7e912631db115d5a03".toLowerCase()]:
|
|
3150
|
-
},
|
|
3580
|
+
["0xbf365e79aA44A2164DA135100C57FDB6635ae870".toLowerCase()]: nn,
|
|
3581
|
+
["0x86904Eb2b3c743400D03f929F2246EfA80B91215".toLowerCase()]: sn,
|
|
3582
|
+
["0x3660dE6C56cFD31998397652941ECe42118375DA".toLowerCase()]: rn,
|
|
3583
|
+
["0xBd68cBe6c247e2c3a0e36B8F0e24964914f26Ee8".toLowerCase()]: on,
|
|
3584
|
+
["0xe4ddca21881bac219af7f217703db0475d2a9f02".toLowerCase()]: pn,
|
|
3585
|
+
["0x11733abf0cdb43298f7e949c930188451a9a9ef2".toLowerCase()]: dn,
|
|
3586
|
+
["0xb33874810e5395eb49d8bd7e912631db115d5a03".toLowerCase()]: un
|
|
3587
|
+
}, yn = ({
|
|
3151
3588
|
streamSwap: e,
|
|
3152
3589
|
contractAddress: t,
|
|
3153
3590
|
recipient: n,
|
|
3154
3591
|
toChecksumAddress: a,
|
|
3155
3592
|
calldata: {
|
|
3156
|
-
amount:
|
|
3593
|
+
amount: s,
|
|
3157
3594
|
amountOutMin: r = "",
|
|
3158
|
-
data:
|
|
3159
|
-
deadline:
|
|
3160
|
-
memo:
|
|
3161
|
-
router:
|
|
3162
|
-
memoStreamingSwap:
|
|
3163
|
-
tcMemo:
|
|
3164
|
-
tcRouter:
|
|
3165
|
-
tcVault:
|
|
3166
|
-
vault:
|
|
3167
|
-
token:
|
|
3595
|
+
data: o = "",
|
|
3596
|
+
deadline: p,
|
|
3597
|
+
memo: d,
|
|
3598
|
+
router: l,
|
|
3599
|
+
memoStreamingSwap: u,
|
|
3600
|
+
tcMemo: c,
|
|
3601
|
+
tcRouter: _,
|
|
3602
|
+
tcVault: b,
|
|
3603
|
+
vault: A,
|
|
3604
|
+
token: E
|
|
3168
3605
|
}
|
|
3169
3606
|
}) => {
|
|
3170
|
-
const
|
|
3171
|
-
if (
|
|
3607
|
+
const O = !!Fe[t.toLowerCase()];
|
|
3608
|
+
if (O && !l)
|
|
3172
3609
|
throw new Error("Router is required on calldata for swapIn with GenericContract");
|
|
3173
|
-
const S =
|
|
3174
|
-
if (!
|
|
3610
|
+
const S = c || d, D = e && u || S;
|
|
3611
|
+
if (!b && !A)
|
|
3175
3612
|
throw new Error("TC Vault is required on calldata");
|
|
3176
|
-
if (!
|
|
3613
|
+
if (!_ && !l)
|
|
3177
3614
|
throw new Error("TC Router is required on calldata");
|
|
3178
|
-
if (!
|
|
3615
|
+
if (!D)
|
|
3179
3616
|
throw new Error("TC Memo is required on calldata");
|
|
3180
|
-
if (!
|
|
3617
|
+
if (!E)
|
|
3181
3618
|
throw new Error("Token is required on calldata");
|
|
3182
|
-
const
|
|
3619
|
+
const ie = [
|
|
3183
3620
|
// v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
|
|
3184
|
-
a(
|
|
3185
|
-
a(
|
|
3186
|
-
|
|
3187
|
-
a(
|
|
3188
|
-
|
|
3189
|
-
],
|
|
3190
|
-
return [...
|
|
3191
|
-
},
|
|
3192
|
-
const n =
|
|
3621
|
+
a(_ || l),
|
|
3622
|
+
a(b || A),
|
|
3623
|
+
D.replace("{recipientAddress}", n),
|
|
3624
|
+
a(E),
|
|
3625
|
+
s
|
|
3626
|
+
], Ge = O ? [a(l), o, p] : [r, p];
|
|
3627
|
+
return [...ie, ...Ge];
|
|
3628
|
+
}, cn = ({ chain: e, txHash: t }) => {
|
|
3629
|
+
const n = Ne[e];
|
|
3193
3630
|
switch (e) {
|
|
3194
|
-
case
|
|
3195
|
-
case
|
|
3196
|
-
case
|
|
3197
|
-
case
|
|
3198
|
-
case
|
|
3199
|
-
case
|
|
3200
|
-
return `${n}/tx/${t}`;
|
|
3201
|
-
case
|
|
3202
|
-
case
|
|
3203
|
-
case
|
|
3204
|
-
case
|
|
3205
|
-
case
|
|
3206
|
-
case
|
|
3631
|
+
case i.Binance:
|
|
3632
|
+
case i.Bitcoin:
|
|
3633
|
+
case i.BitcoinCash:
|
|
3634
|
+
case i.Maya:
|
|
3635
|
+
case i.Kujira:
|
|
3636
|
+
case i.THORChain:
|
|
3637
|
+
return `${n}/tx/${t.startsWith("0x") ? t.slice(2) : t}`;
|
|
3638
|
+
case i.Arbitrum:
|
|
3639
|
+
case i.Avalanche:
|
|
3640
|
+
case i.BinanceSmartChain:
|
|
3641
|
+
case i.Ethereum:
|
|
3642
|
+
case i.Optimism:
|
|
3643
|
+
case i.Polygon:
|
|
3207
3644
|
return `${n}/tx/${t.startsWith("0x") ? t : `0x${t}`}`;
|
|
3208
|
-
case
|
|
3645
|
+
case i.Cosmos:
|
|
3209
3646
|
return `${n}/transactions/${t}`;
|
|
3210
|
-
case
|
|
3647
|
+
case i.Dogecoin:
|
|
3211
3648
|
return `${n}/transaction/${t.toLowerCase()}`;
|
|
3212
|
-
case
|
|
3649
|
+
case i.Litecoin:
|
|
3213
3650
|
return `${n}/${t}`;
|
|
3214
3651
|
default:
|
|
3215
3652
|
throw new Error(`Unsupported chain: ${e}`);
|
|
3216
3653
|
}
|
|
3217
|
-
},
|
|
3218
|
-
const n =
|
|
3654
|
+
}, mn = ({ chain: e, address: t }) => {
|
|
3655
|
+
const n = Ne[e];
|
|
3219
3656
|
switch (e) {
|
|
3220
|
-
case
|
|
3221
|
-
case
|
|
3222
|
-
case
|
|
3223
|
-
case
|
|
3224
|
-
case
|
|
3225
|
-
case
|
|
3226
|
-
case
|
|
3227
|
-
case
|
|
3228
|
-
case
|
|
3229
|
-
case
|
|
3230
|
-
case
|
|
3231
|
-
case
|
|
3232
|
-
case
|
|
3657
|
+
case i.Arbitrum:
|
|
3658
|
+
case i.Avalanche:
|
|
3659
|
+
case i.Binance:
|
|
3660
|
+
case i.BinanceSmartChain:
|
|
3661
|
+
case i.Bitcoin:
|
|
3662
|
+
case i.BitcoinCash:
|
|
3663
|
+
case i.Dogecoin:
|
|
3664
|
+
case i.Ethereum:
|
|
3665
|
+
case i.Maya:
|
|
3666
|
+
case i.Optimism:
|
|
3667
|
+
case i.Polygon:
|
|
3668
|
+
case i.Kujira:
|
|
3669
|
+
case i.THORChain:
|
|
3233
3670
|
return `${n}/address/${t}`;
|
|
3234
|
-
case
|
|
3671
|
+
case i.Cosmos:
|
|
3235
3672
|
return `${n}/account/${t}`;
|
|
3236
|
-
case
|
|
3673
|
+
case i.Litecoin:
|
|
3237
3674
|
return `${n}/${t}`;
|
|
3238
3675
|
default:
|
|
3239
3676
|
throw new Error(`Unsupported chain: ${e}`);
|
|
3240
3677
|
}
|
|
3241
|
-
},
|
|
3678
|
+
}, Tn = (e) => {
|
|
3242
3679
|
const t = e ? q.ThornodeStagenet : q.ThornodeMainnet;
|
|
3243
|
-
return
|
|
3244
|
-
},
|
|
3680
|
+
return we.get(`${t}/thorchain/inbound_addresses`);
|
|
3681
|
+
}, hn = (e) => {
|
|
3245
3682
|
const t = e ? q.ThornodeStagenet : q.ThornodeMainnet;
|
|
3246
|
-
return
|
|
3247
|
-
},
|
|
3683
|
+
return we.get(`${t}/thorchain/mimir`);
|
|
3684
|
+
}, Ie = () => Object.values(i).reduce(
|
|
3248
3685
|
(e, t) => (e[t] = null, e),
|
|
3249
3686
|
{}
|
|
3250
3687
|
);
|
|
3251
|
-
var V,
|
|
3252
|
-
class
|
|
3688
|
+
var V, ne, j, v, K, Y;
|
|
3689
|
+
class Ln {
|
|
3253
3690
|
constructor({ stagenet: t } = {}) {
|
|
3254
|
-
T(this, "connectedChains",
|
|
3255
|
-
T(this, "connectedWallets",
|
|
3691
|
+
T(this, "connectedChains", Ie());
|
|
3692
|
+
T(this, "connectedWallets", Ie());
|
|
3256
3693
|
T(this, "stagenet", !1);
|
|
3257
3694
|
T(this, "getAddress", (t) => {
|
|
3258
3695
|
var n;
|
|
3259
3696
|
return ((n = this.connectedChains[t]) == null ? void 0 : n.address) || "";
|
|
3260
3697
|
});
|
|
3261
|
-
T(this, "getExplorerTxUrl", (t, n) =>
|
|
3698
|
+
T(this, "getExplorerTxUrl", (t, n) => cn({ chain: t, txHash: n }));
|
|
3262
3699
|
T(this, "getWallet", (t) => this.connectedWallets[t]);
|
|
3263
|
-
T(this, "getExplorerAddressUrl", (t, n) =>
|
|
3700
|
+
T(this, "getExplorerAddressUrl", (t, n) => mn({ chain: t, address: n }));
|
|
3264
3701
|
T(this, "getBalance", async (t, n) => {
|
|
3265
|
-
|
|
3266
|
-
if (!n)
|
|
3267
|
-
return ((i = this.connectedChains[t]) == null ? void 0 : i.balance) || [];
|
|
3268
|
-
const a = await this.getWalletByChain(t);
|
|
3702
|
+
const a = await this.getWalletByChain(t, n);
|
|
3269
3703
|
return (a == null ? void 0 : a.balance) || [];
|
|
3270
3704
|
});
|
|
3271
|
-
T(this, "swap", async ({ streamSwap: t, recipient: n, route: a, feeOptionKey:
|
|
3272
|
-
var
|
|
3273
|
-
const { quoteMode: r } = a.meta,
|
|
3705
|
+
T(this, "swap", async ({ streamSwap: t, recipient: n, route: a, feeOptionKey: s }) => {
|
|
3706
|
+
var p, d;
|
|
3707
|
+
const { quoteMode: r } = a.meta, o = r.startsWith("ERC20-") ? i.Ethereum : r.startsWith("ARC20-") ? i.Avalanche : i.BinanceSmartChain;
|
|
3274
3708
|
if (!a.complete)
|
|
3275
3709
|
throw new m("core_swap_route_not_complete");
|
|
3276
3710
|
try {
|
|
3277
|
-
if (
|
|
3278
|
-
const
|
|
3279
|
-
if (!(
|
|
3711
|
+
if (Ze.includes(r)) {
|
|
3712
|
+
const l = this.connectedWallets[o];
|
|
3713
|
+
if (!(l != null && l.sendTransaction))
|
|
3280
3714
|
throw new m("core_wallet_connection_not_found");
|
|
3281
|
-
if (!(t ? (
|
|
3715
|
+
if (!(t ? (p = a == null ? void 0 : a.streamingSwap) == null ? void 0 : p.transaction : a == null ? void 0 : a.transaction))
|
|
3282
3716
|
throw new m("core_swap_route_transaction_not_found");
|
|
3283
|
-
const {
|
|
3284
|
-
data:
|
|
3285
|
-
from:
|
|
3286
|
-
to:
|
|
3287
|
-
chainId: BigInt(
|
|
3288
|
-
value:
|
|
3289
|
-
value: _(b) ? b : O(b, "wei").toString(16)
|
|
3290
|
-
}).baseValueBigInt : 0n
|
|
3717
|
+
const { data: c, from: _, to: b, value: A } = a.transaction, E = {
|
|
3718
|
+
data: c,
|
|
3719
|
+
from: _,
|
|
3720
|
+
to: b.toLowerCase(),
|
|
3721
|
+
chainId: BigInt(pt[o]),
|
|
3722
|
+
value: A ? BigInt(A) : 0n
|
|
3291
3723
|
};
|
|
3292
|
-
return
|
|
3724
|
+
return l.sendTransaction(E, s);
|
|
3293
3725
|
}
|
|
3294
|
-
if (
|
|
3726
|
+
if (tt.includes(r)) {
|
|
3295
3727
|
if (!a.calldata.fromAsset)
|
|
3296
3728
|
throw new m("core_swap_asset_not_recognized");
|
|
3297
|
-
const
|
|
3298
|
-
if (!
|
|
3729
|
+
const l = await M.fromString(a.calldata.fromAsset);
|
|
3730
|
+
if (!l)
|
|
3299
3731
|
throw new m("core_swap_asset_not_recognized");
|
|
3300
|
-
const { address:
|
|
3301
|
-
contract:
|
|
3302
|
-
calldata: { amountIn:
|
|
3303
|
-
} = a,
|
|
3304
|
-
return this.deposit({
|
|
3732
|
+
const { address: u } = await f(this, V).call(this, l.chain), {
|
|
3733
|
+
contract: c,
|
|
3734
|
+
calldata: { expiration: _, amountIn: b, memo: A, memoStreamingSwap: E }
|
|
3735
|
+
} = a, O = l.add(x.fromBigInt(BigInt(b), l.decimal)), S = t && E || A;
|
|
3736
|
+
return this.deposit({
|
|
3737
|
+
expiration: _,
|
|
3738
|
+
assetValue: O,
|
|
3739
|
+
memo: S,
|
|
3740
|
+
feeOptionKey: s,
|
|
3741
|
+
router: c,
|
|
3742
|
+
recipient: u
|
|
3743
|
+
});
|
|
3305
3744
|
}
|
|
3306
|
-
if (
|
|
3307
|
-
const { calldata:
|
|
3308
|
-
if (!
|
|
3745
|
+
if (et.includes(r)) {
|
|
3746
|
+
const { calldata: l, contract: u } = a;
|
|
3747
|
+
if (!u)
|
|
3309
3748
|
throw new m("core_swap_contract_not_found");
|
|
3310
|
-
const
|
|
3311
|
-
if (!(
|
|
3749
|
+
const c = this.connectedWallets[o], _ = this.getAddress(o);
|
|
3750
|
+
if (!(c != null && c.sendTransaction) || !_)
|
|
3312
3751
|
throw new m("core_wallet_connection_not_found");
|
|
3313
|
-
const { getProvider:
|
|
3314
|
-
if (!
|
|
3315
|
-
throw new m("core_swap_contract_not_supported", { contractAddress:
|
|
3316
|
-
const
|
|
3317
|
-
|
|
3318
|
-
...Nt({
|
|
3752
|
+
const { getProvider: b, toChecksumAddress: A } = await import("@swapkit/toolbox-evm"), E = b(o), O = ln[u.toLowerCase()];
|
|
3753
|
+
if (!O)
|
|
3754
|
+
throw new m("core_swap_contract_not_supported", { contractAddress: u });
|
|
3755
|
+
const D = await (await ((d = c.createContract) == null ? void 0 : d.call(c, u, O, E))).getFunction("swapIn").populateTransaction(
|
|
3756
|
+
...yn({
|
|
3319
3757
|
streamSwap: t,
|
|
3320
|
-
toChecksumAddress:
|
|
3321
|
-
contractAddress:
|
|
3758
|
+
toChecksumAddress: A,
|
|
3759
|
+
contractAddress: u,
|
|
3322
3760
|
recipient: n,
|
|
3323
|
-
calldata:
|
|
3761
|
+
calldata: l
|
|
3324
3762
|
}),
|
|
3325
|
-
{ from:
|
|
3326
|
-
)
|
|
3327
|
-
return
|
|
3763
|
+
{ from: _ }
|
|
3764
|
+
);
|
|
3765
|
+
return c.sendTransaction(D, s);
|
|
3328
3766
|
}
|
|
3329
3767
|
throw new m("core_swap_quote_mode_not_supported", { quoteMode: r });
|
|
3330
|
-
} catch (
|
|
3331
|
-
throw new m("core_swap_transaction_error",
|
|
3768
|
+
} catch (l) {
|
|
3769
|
+
throw new m("core_swap_transaction_error", l);
|
|
3332
3770
|
}
|
|
3333
3771
|
});
|
|
3334
|
-
T(this, "getWalletByChain", async (t) => {
|
|
3335
|
-
var
|
|
3336
|
-
const
|
|
3337
|
-
if (!
|
|
3772
|
+
T(this, "getWalletByChain", async (t, n) => {
|
|
3773
|
+
var o, p;
|
|
3774
|
+
const a = this.getAddress(t);
|
|
3775
|
+
if (!a)
|
|
3338
3776
|
return null;
|
|
3339
|
-
const
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3777
|
+
const s = [M.fromChainOrSignature(t)], r = (o = this.connectedChains[t]) == null ? void 0 : o.walletType;
|
|
3778
|
+
try {
|
|
3779
|
+
const d = await ((p = this.getWallet(t)) == null ? void 0 : p.getBalance(a, n));
|
|
3780
|
+
return this.connectedChains[t] = {
|
|
3781
|
+
address: a,
|
|
3782
|
+
balance: d != null && d.length ? d : s,
|
|
3783
|
+
walletType: r
|
|
3784
|
+
}, { ...this.connectedChains[t] };
|
|
3785
|
+
} catch (d) {
|
|
3786
|
+
return console.error(d), { address: a, balance: s, walletType: r };
|
|
3787
|
+
}
|
|
3347
3788
|
});
|
|
3348
|
-
T(this, "approveAssetValue", (t, n) =>
|
|
3349
|
-
T(this, "isAssetValueApproved", (t, n) =>
|
|
3789
|
+
T(this, "approveAssetValue", (t, n) => f(this, j).call(this, { assetValue: t, type: "approve", contractAddress: n }));
|
|
3790
|
+
T(this, "isAssetValueApproved", (t, n) => f(this, j).call(this, { assetValue: t, contractAddress: n, type: "checkOnly" }));
|
|
3350
3791
|
T(this, "validateAddress", ({ address: t, chain: n }) => {
|
|
3351
|
-
var a,
|
|
3352
|
-
return (
|
|
3792
|
+
var a, s;
|
|
3793
|
+
return (s = (a = this.getWallet(n)) == null ? void 0 : a.validateAddress) == null ? void 0 : s.call(a, t);
|
|
3353
3794
|
});
|
|
3354
3795
|
T(this, "transfer", async (t) => {
|
|
3355
3796
|
const n = this.connectedWallets[t.assetValue.chain];
|
|
3356
3797
|
if (!n)
|
|
3357
3798
|
throw new m("core_wallet_connection_not_found");
|
|
3358
3799
|
try {
|
|
3359
|
-
return await n.transfer(
|
|
3800
|
+
return await n.transfer(f(this, Y).call(this, t));
|
|
3360
3801
|
} catch (a) {
|
|
3361
3802
|
throw new m("core_swap_transaction_error", a);
|
|
3362
3803
|
}
|
|
@@ -3365,43 +3806,45 @@ class en {
|
|
|
3365
3806
|
assetValue: t,
|
|
3366
3807
|
recipient: n,
|
|
3367
3808
|
router: a,
|
|
3368
|
-
...
|
|
3809
|
+
...s
|
|
3369
3810
|
}) => {
|
|
3370
|
-
const { chain: r, symbol:
|
|
3371
|
-
if (!
|
|
3811
|
+
const { chain: r, symbol: o, ticker: p } = t, d = this.connectedWallets[r];
|
|
3812
|
+
if (!d)
|
|
3372
3813
|
throw new m("core_wallet_connection_not_found");
|
|
3373
|
-
const
|
|
3814
|
+
const l = f(this, Y).call(this, { assetValue: t, recipient: n, router: a, ...s });
|
|
3374
3815
|
try {
|
|
3375
3816
|
switch (r) {
|
|
3376
|
-
case
|
|
3377
|
-
const
|
|
3378
|
-
return await (n === "" ?
|
|
3817
|
+
case i.THORChain: {
|
|
3818
|
+
const u = d;
|
|
3819
|
+
return await (n === "" ? u.deposit(l) : u.transfer(l));
|
|
3379
3820
|
}
|
|
3380
|
-
case
|
|
3381
|
-
case
|
|
3382
|
-
case
|
|
3383
|
-
const { getChecksumAddressFromAsset:
|
|
3384
|
-
return await
|
|
3385
|
-
abi:
|
|
3386
|
-
contractAddress: a || (await
|
|
3821
|
+
case i.Ethereum:
|
|
3822
|
+
case i.BinanceSmartChain:
|
|
3823
|
+
case i.Avalanche: {
|
|
3824
|
+
const { getChecksumAddressFromAsset: u } = await import("@swapkit/toolbox-evm"), c = r === i.Avalanche ? Je : r === i.BinanceSmartChain ? Qe : Xe;
|
|
3825
|
+
return await d.call({
|
|
3826
|
+
abi: c,
|
|
3827
|
+
contractAddress: a || (await f(this, V).call(this, r)).router,
|
|
3387
3828
|
funcName: "depositWithExpiry",
|
|
3388
3829
|
funcParams: [
|
|
3389
3830
|
n,
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
i.expiration
|
|
3831
|
+
u({ chain: r, symbol: o, ticker: p }, r),
|
|
3832
|
+
t.getBaseValue("string"),
|
|
3833
|
+
l.memo,
|
|
3834
|
+
s.expiration || parseInt(`${((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3) / 1e3}`)
|
|
3395
3835
|
],
|
|
3396
|
-
txOverrides: {
|
|
3836
|
+
txOverrides: {
|
|
3837
|
+
from: l.from,
|
|
3838
|
+
value: t.isGasAsset ? t.getBaseValue("bigint") : void 0
|
|
3839
|
+
}
|
|
3397
3840
|
});
|
|
3398
3841
|
}
|
|
3399
3842
|
default:
|
|
3400
|
-
return await
|
|
3843
|
+
return await d.transfer(l);
|
|
3401
3844
|
}
|
|
3402
|
-
} catch (
|
|
3403
|
-
const
|
|
3404
|
-
throw new m(
|
|
3845
|
+
} catch (u) {
|
|
3846
|
+
const c = ((u == null ? void 0 : u.message) || (u == null ? void 0 : u.toString())).toLowerCase(), _ = c == null ? void 0 : c.includes("insufficient funds"), b = c == null ? void 0 : c.includes("gas"), A = c == null ? void 0 : c.includes("server"), E = _ ? "core_transaction_deposit_insufficient_funds_error" : b ? "core_transaction_deposit_gas_error" : A ? "core_transaction_deposit_server_error" : "core_transaction_deposit_error";
|
|
3847
|
+
throw new m(E, u);
|
|
3405
3848
|
}
|
|
3406
3849
|
});
|
|
3407
3850
|
/**
|
|
@@ -3413,11 +3856,11 @@ class en {
|
|
|
3413
3856
|
}) => {
|
|
3414
3857
|
if (t.lte(0) || n.lte(0))
|
|
3415
3858
|
throw new m("core_transaction_create_liquidity_invalid_params");
|
|
3416
|
-
let a = "",
|
|
3859
|
+
let a = "", s = "";
|
|
3417
3860
|
try {
|
|
3418
|
-
a = await
|
|
3861
|
+
a = await f(this, v).call(this, {
|
|
3419
3862
|
assetValue: t,
|
|
3420
|
-
memo:
|
|
3863
|
+
memo: N(h.DEPOSIT, {
|
|
3421
3864
|
...n,
|
|
3422
3865
|
address: this.getAddress(n.chain)
|
|
3423
3866
|
})
|
|
@@ -3426,101 +3869,103 @@ class en {
|
|
|
3426
3869
|
throw new m("core_transaction_create_liquidity_rune_error", r);
|
|
3427
3870
|
}
|
|
3428
3871
|
try {
|
|
3429
|
-
|
|
3872
|
+
s = await f(this, v).call(this, {
|
|
3430
3873
|
assetValue: n,
|
|
3431
|
-
memo:
|
|
3874
|
+
memo: N(h.DEPOSIT, {
|
|
3432
3875
|
...n,
|
|
3433
|
-
address: this.getAddress(
|
|
3876
|
+
address: this.getAddress(i.THORChain)
|
|
3434
3877
|
})
|
|
3435
3878
|
});
|
|
3436
3879
|
} catch (r) {
|
|
3437
3880
|
throw new m("core_transaction_create_liquidity_asset_error", r);
|
|
3438
3881
|
}
|
|
3439
|
-
return { runeTx: a, assetTx:
|
|
3882
|
+
return { runeTx: a, assetTx: s };
|
|
3440
3883
|
});
|
|
3441
3884
|
T(this, "addLiquidity", async ({
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
mode: d = "sym"
|
|
3885
|
+
runeAssetValue: t,
|
|
3886
|
+
assetValue: n,
|
|
3887
|
+
runeAddr: a,
|
|
3888
|
+
assetAddr: s,
|
|
3889
|
+
isPendingSymmAsset: r,
|
|
3890
|
+
mode: o = "sym"
|
|
3449
3891
|
}) => {
|
|
3450
|
-
const
|
|
3451
|
-
if (!u && !
|
|
3892
|
+
const { chain: p, symbol: d } = n, l = o === "sym", u = (t == null ? void 0 : t.gt(0)) && (l || o === "rune"), c = (n == null ? void 0 : n.gt(0)) && (l || o === "asset"), _ = r || u, b = _ ? a || this.getAddress(i.THORChain) : "", A = l || o === "asset" ? s || this.getAddress(p) : "";
|
|
3893
|
+
if (!u && !c)
|
|
3452
3894
|
throw new m("core_transaction_add_liquidity_invalid_params");
|
|
3453
|
-
if (_ && !
|
|
3895
|
+
if (_ && !b)
|
|
3454
3896
|
throw new m("core_transaction_add_liquidity_no_rune_address");
|
|
3455
|
-
let
|
|
3456
|
-
|
|
3457
|
-
if (u && n)
|
|
3897
|
+
let E, O;
|
|
3898
|
+
if (u && t)
|
|
3458
3899
|
try {
|
|
3459
|
-
|
|
3460
|
-
assetValue:
|
|
3461
|
-
memo:
|
|
3900
|
+
E = await f(this, v).call(this, {
|
|
3901
|
+
assetValue: t,
|
|
3902
|
+
memo: N(h.DEPOSIT, { chain: p, symbol: d, address: A })
|
|
3462
3903
|
});
|
|
3463
|
-
} catch (
|
|
3464
|
-
throw new m("core_transaction_add_liquidity_rune_error",
|
|
3904
|
+
} catch (S) {
|
|
3905
|
+
throw new m("core_transaction_add_liquidity_rune_error", S);
|
|
3465
3906
|
}
|
|
3466
|
-
if (
|
|
3907
|
+
if (c && n)
|
|
3467
3908
|
try {
|
|
3468
|
-
|
|
3469
|
-
assetValue:
|
|
3470
|
-
memo:
|
|
3909
|
+
O = await f(this, v).call(this, {
|
|
3910
|
+
assetValue: n,
|
|
3911
|
+
memo: N(h.DEPOSIT, { chain: p, symbol: d, address: b })
|
|
3471
3912
|
});
|
|
3472
|
-
} catch (
|
|
3473
|
-
throw new m("core_transaction_add_liquidity_asset_error",
|
|
3913
|
+
} catch (S) {
|
|
3914
|
+
throw new m("core_transaction_add_liquidity_asset_error", S);
|
|
3474
3915
|
}
|
|
3475
|
-
return { runeTx:
|
|
3916
|
+
return { runeTx: E, assetTx: O };
|
|
3917
|
+
});
|
|
3918
|
+
T(this, "addLiquidityPart", ({
|
|
3919
|
+
assetValue: t,
|
|
3920
|
+
poolAddress: n,
|
|
3921
|
+
address: a,
|
|
3922
|
+
symmetric: s
|
|
3923
|
+
}) => {
|
|
3924
|
+
if (s && !a)
|
|
3925
|
+
throw new m("core_transaction_add_liquidity_invalid_params");
|
|
3926
|
+
const r = s && a || "";
|
|
3927
|
+
return f(this, v).call(this, { assetValue: t, memo: `+:${n}:${r}:t:0` });
|
|
3476
3928
|
});
|
|
3477
3929
|
T(this, "withdraw", async ({
|
|
3478
3930
|
memo: t,
|
|
3479
3931
|
assetValue: n,
|
|
3480
3932
|
percent: a,
|
|
3481
|
-
from:
|
|
3933
|
+
from: s,
|
|
3482
3934
|
to: r
|
|
3483
3935
|
}) => {
|
|
3484
|
-
const
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
targetAssetString: p == null ? void 0 : p.toString(),
|
|
3494
|
-
singleSide: !1
|
|
3495
|
-
})
|
|
3496
|
-
});
|
|
3497
|
-
} catch (d) {
|
|
3498
|
-
throw new m("core_transaction_withdraw_error", d);
|
|
3499
|
-
}
|
|
3936
|
+
const o = r === "rune" ? M.fromChainOrSignature(i.THORChain) : s === "sym" && r === "sym" || s === "rune" || s === "asset" ? void 0 : n, p = de(s === "asset" ? n.chain : i.THORChain), d = t || N(h.WITHDRAW, {
|
|
3937
|
+
symbol: n.symbol,
|
|
3938
|
+
chain: n.chain,
|
|
3939
|
+
ticker: n.ticker,
|
|
3940
|
+
basisPoints: Math.max(1e4, Math.round(a * 100)),
|
|
3941
|
+
targetAssetString: o == null ? void 0 : o.toString(),
|
|
3942
|
+
singleSide: !1
|
|
3943
|
+
});
|
|
3944
|
+
return f(this, v).call(this, { assetValue: p, memo: d });
|
|
3500
3945
|
});
|
|
3501
3946
|
T(this, "savings", async ({
|
|
3502
3947
|
assetValue: t,
|
|
3503
3948
|
memo: n,
|
|
3504
3949
|
percent: a,
|
|
3505
|
-
type:
|
|
3950
|
+
type: s
|
|
3506
3951
|
}) => {
|
|
3507
|
-
const r =
|
|
3952
|
+
const r = s === "add" ? h.DEPOSIT : h.WITHDRAW, o = n || N(r, {
|
|
3508
3953
|
ticker: t.ticker,
|
|
3509
3954
|
symbol: t.symbol,
|
|
3510
3955
|
chain: t.chain,
|
|
3511
3956
|
singleSide: !0,
|
|
3512
|
-
basisPoints: a ? Math.
|
|
3513
|
-
});
|
|
3514
|
-
return
|
|
3957
|
+
basisPoints: a ? Math.min(1e4, Math.round(a * 100)) : void 0
|
|
3958
|
+
}), p = r === h.DEPOSIT ? t : de(t.chain);
|
|
3959
|
+
return f(this, v).call(this, { memo: o, assetValue: p });
|
|
3515
3960
|
});
|
|
3516
3961
|
T(this, "loan", ({
|
|
3517
3962
|
assetValue: t,
|
|
3518
3963
|
memo: n,
|
|
3519
3964
|
minAmount: a,
|
|
3520
|
-
type:
|
|
3521
|
-
}) =>
|
|
3965
|
+
type: s
|
|
3966
|
+
}) => f(this, v).call(this, {
|
|
3522
3967
|
assetValue: t,
|
|
3523
|
-
memo: n ||
|
|
3968
|
+
memo: n || N(s === "open" ? h.OPEN_LOAN : h.CLOSE_LOAN, {
|
|
3524
3969
|
asset: t.toString(),
|
|
3525
3970
|
minAmount: a.toString(),
|
|
3526
3971
|
address: this.getAddress(t.chain)
|
|
@@ -3531,27 +3976,27 @@ class en {
|
|
|
3531
3976
|
assetValue: n,
|
|
3532
3977
|
address: a
|
|
3533
3978
|
}) => {
|
|
3534
|
-
const
|
|
3979
|
+
const s = t === "bond" ? h.BOND : t === "unbond" ? h.UNBOND : h.LEAVE, r = N(s, {
|
|
3535
3980
|
address: a,
|
|
3536
|
-
unbondAmount: t === "unbond" ? n.
|
|
3981
|
+
unbondAmount: t === "unbond" ? n.getBaseValue("number") : void 0
|
|
3537
3982
|
});
|
|
3538
|
-
return
|
|
3983
|
+
return f(this, K).call(this, {
|
|
3539
3984
|
memo: r,
|
|
3540
|
-
assetValue: t === "bond" ? n :
|
|
3985
|
+
assetValue: t === "bond" ? n : de(i.THORChain)
|
|
3541
3986
|
});
|
|
3542
3987
|
});
|
|
3543
3988
|
T(this, "registerThorname", ({
|
|
3544
3989
|
assetValue: t,
|
|
3545
3990
|
...n
|
|
3546
|
-
}) =>
|
|
3547
|
-
T(this, "extend", ({ wallets: t, config: n, apis: a = {}, rpcUrls:
|
|
3991
|
+
}) => f(this, K).call(this, { assetValue: t, memo: N(h.THORNAME_REGISTER, n) }));
|
|
3992
|
+
T(this, "extend", ({ wallets: t, config: n, apis: a = {}, rpcUrls: s = {} }) => {
|
|
3548
3993
|
try {
|
|
3549
3994
|
t.forEach((r) => {
|
|
3550
3995
|
this[r.connectMethodName] = r.connect({
|
|
3551
|
-
addChain:
|
|
3996
|
+
addChain: f(this, ne),
|
|
3552
3997
|
config: n || {},
|
|
3553
3998
|
apis: a,
|
|
3554
|
-
rpcUrls:
|
|
3999
|
+
rpcUrls: s
|
|
3555
4000
|
});
|
|
3556
4001
|
});
|
|
3557
4002
|
} catch (r) {
|
|
@@ -3564,28 +4009,28 @@ class en {
|
|
|
3564
4009
|
}) => {
|
|
3565
4010
|
const a = this.getWallet(t);
|
|
3566
4011
|
switch (t) {
|
|
3567
|
-
case
|
|
3568
|
-
case
|
|
3569
|
-
case
|
|
3570
|
-
case
|
|
3571
|
-
case
|
|
3572
|
-
case
|
|
3573
|
-
const { estimateMaxSendableAmount:
|
|
3574
|
-
return
|
|
4012
|
+
case i.Arbitrum:
|
|
4013
|
+
case i.Avalanche:
|
|
4014
|
+
case i.BinanceSmartChain:
|
|
4015
|
+
case i.Ethereum:
|
|
4016
|
+
case i.Optimism:
|
|
4017
|
+
case i.Polygon: {
|
|
4018
|
+
const { estimateMaxSendableAmount: s } = await import("@swapkit/toolbox-evm");
|
|
4019
|
+
return s({
|
|
3575
4020
|
...n,
|
|
3576
4021
|
toolbox: a
|
|
3577
4022
|
});
|
|
3578
4023
|
}
|
|
3579
|
-
case
|
|
3580
|
-
case
|
|
3581
|
-
case
|
|
3582
|
-
case
|
|
4024
|
+
case i.Bitcoin:
|
|
4025
|
+
case i.BitcoinCash:
|
|
4026
|
+
case i.Dogecoin:
|
|
4027
|
+
case i.Litecoin:
|
|
3583
4028
|
return a.estimateMaxSendableAmount(n);
|
|
3584
|
-
case
|
|
3585
|
-
case
|
|
3586
|
-
case
|
|
3587
|
-
const { estimateMaxSendableAmount:
|
|
3588
|
-
return
|
|
4029
|
+
case i.Binance:
|
|
4030
|
+
case i.THORChain:
|
|
4031
|
+
case i.Cosmos: {
|
|
4032
|
+
const { estimateMaxSendableAmount: s } = await import("@swapkit/toolbox-cosmos");
|
|
4033
|
+
return s({
|
|
3589
4034
|
...n,
|
|
3590
4035
|
toolbox: a
|
|
3591
4036
|
});
|
|
@@ -3625,71 +4070,71 @@ class en {
|
|
|
3625
4070
|
this.connectedChains[t] = null, this.connectedWallets[t] = null;
|
|
3626
4071
|
});
|
|
3627
4072
|
P(this, V, async (t) => {
|
|
3628
|
-
if (t ===
|
|
4073
|
+
if (t === i.THORChain)
|
|
3629
4074
|
return {
|
|
3630
4075
|
gas_rate: "0",
|
|
3631
4076
|
router: "0",
|
|
3632
4077
|
address: "",
|
|
3633
4078
|
halted: !1,
|
|
3634
|
-
chain:
|
|
4079
|
+
chain: i.THORChain
|
|
3635
4080
|
};
|
|
3636
|
-
const a = (await
|
|
4081
|
+
const a = (await Tn(this.stagenet)).find((s) => s.chain === t);
|
|
3637
4082
|
if (!a)
|
|
3638
4083
|
throw new m("core_inbound_data_not_found");
|
|
3639
4084
|
if (a != null && a.halted)
|
|
3640
4085
|
throw new m("core_chain_halted");
|
|
3641
4086
|
return a;
|
|
3642
4087
|
});
|
|
3643
|
-
P(this,
|
|
4088
|
+
P(this, ne, ({ chain: t, wallet: n, walletMethods: a }) => {
|
|
3644
4089
|
this.connectedChains[t] = n, this.connectedWallets[t] = a;
|
|
3645
4090
|
});
|
|
3646
|
-
P(this,
|
|
3647
|
-
assetValue:
|
|
3648
|
-
type:
|
|
3649
|
-
contractAddress:
|
|
4091
|
+
P(this, j, async ({
|
|
4092
|
+
assetValue: t,
|
|
4093
|
+
type: n = "checkOnly",
|
|
4094
|
+
contractAddress: a
|
|
3650
4095
|
}) => {
|
|
3651
|
-
const
|
|
3652
|
-
if (
|
|
4096
|
+
const { address: s, chain: r, isGasAsset: o, isSynthetic: p } = t, d = [i.Ethereum, i.Avalanche, i.BinanceSmartChain].includes(r);
|
|
4097
|
+
if (d && o || !d || p)
|
|
3653
4098
|
return !0;
|
|
3654
|
-
const
|
|
3655
|
-
if (!
|
|
4099
|
+
const u = this.connectedWallets[r], c = n === "checkOnly" ? u == null ? void 0 : u.isApproved : u == null ? void 0 : u.approve;
|
|
4100
|
+
if (!c)
|
|
3656
4101
|
throw new m("core_wallet_connection_not_found");
|
|
3657
|
-
const
|
|
3658
|
-
if (!
|
|
4102
|
+
const _ = this.getAddress(r);
|
|
4103
|
+
if (!s || !_)
|
|
3659
4104
|
throw new m("core_approve_asset_address_or_from_not_found");
|
|
3660
|
-
const
|
|
3661
|
-
return
|
|
3662
|
-
amount: t,
|
|
3663
|
-
assetAddress:
|
|
3664
|
-
from:
|
|
3665
|
-
spenderAddress:
|
|
4105
|
+
const b = a || (await f(this, V).call(this, r)).router;
|
|
4106
|
+
return c({
|
|
4107
|
+
amount: t.getBaseValue("bigint"),
|
|
4108
|
+
assetAddress: s,
|
|
4109
|
+
from: _,
|
|
4110
|
+
spenderAddress: b
|
|
3666
4111
|
});
|
|
3667
4112
|
});
|
|
3668
|
-
P(this,
|
|
4113
|
+
P(this, v, async ({
|
|
3669
4114
|
assetValue: t,
|
|
3670
4115
|
memo: n,
|
|
3671
4116
|
feeOptionKey: a = F.Fast
|
|
3672
4117
|
}) => {
|
|
3673
4118
|
const {
|
|
3674
|
-
gas_rate:
|
|
4119
|
+
gas_rate: s,
|
|
3675
4120
|
router: r,
|
|
3676
|
-
address:
|
|
3677
|
-
} = await
|
|
4121
|
+
address: o
|
|
4122
|
+
} = await f(this, V).call(this, t.chain), p = (parseInt(s) || 0) * wt[a];
|
|
3678
4123
|
return this.deposit({
|
|
3679
4124
|
assetValue: t,
|
|
3680
|
-
recipient:
|
|
4125
|
+
recipient: o,
|
|
3681
4126
|
memo: n,
|
|
3682
4127
|
router: r,
|
|
3683
|
-
feeRate:
|
|
4128
|
+
feeRate: p
|
|
3684
4129
|
});
|
|
3685
4130
|
});
|
|
3686
|
-
P(this,
|
|
3687
|
-
const a = await
|
|
4131
|
+
P(this, K, async ({ memo: t, assetValue: n }) => {
|
|
4132
|
+
const a = await hn(this.stagenet);
|
|
3688
4133
|
if (a.HALTCHAINGLOBAL >= 1 || a.HALTTHORCHAIN >= 1)
|
|
3689
4134
|
throw new m("core_chain_halted");
|
|
3690
4135
|
return this.deposit({ assetValue: n, recipient: "", memo: t });
|
|
3691
4136
|
});
|
|
3692
|
-
P(this,
|
|
4137
|
+
P(this, Y, ({ assetValue: t, ...n }) => ({
|
|
3693
4138
|
...n,
|
|
3694
4139
|
memo: n.memo || "",
|
|
3695
4140
|
from: this.getAddress(t.chain),
|
|
@@ -3698,65 +4143,66 @@ class en {
|
|
|
3698
4143
|
this.stagenet = !!t;
|
|
3699
4144
|
}
|
|
3700
4145
|
}
|
|
3701
|
-
V = new WeakMap(),
|
|
4146
|
+
V = new WeakMap(), ne = new WeakMap(), j = new WeakMap(), v = new WeakMap(), K = new WeakMap(), Y = new WeakMap();
|
|
3702
4147
|
export {
|
|
3703
|
-
|
|
3704
|
-
|
|
4148
|
+
Ze as AGG_SWAP,
|
|
4149
|
+
bn as ApiError,
|
|
3705
4150
|
q as ApiUrl,
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
4151
|
+
M as AssetValue,
|
|
4152
|
+
w as BaseDecimal,
|
|
4153
|
+
ce as BigIntArithmetics,
|
|
4154
|
+
i as Chain,
|
|
4155
|
+
_e as ChainId,
|
|
4156
|
+
On as ChainIdToChain,
|
|
4157
|
+
pt as ChainToChainId,
|
|
4158
|
+
Ne as ChainToExplorerUrl,
|
|
4159
|
+
gn as ChainToHexChainId,
|
|
4160
|
+
dt as ChainToRPC,
|
|
4161
|
+
st as ContractAddress,
|
|
4162
|
+
En as CosmosChainList,
|
|
4163
|
+
it as DerivationPath,
|
|
4164
|
+
y as ERROR_CODE,
|
|
4165
|
+
nt as ERROR_MODULE,
|
|
4166
|
+
ve as ERROR_TYPE,
|
|
4167
|
+
rt as EVMChainList,
|
|
4168
|
+
ut as ErrorCode,
|
|
3724
4169
|
F as FeeOption,
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
4170
|
+
h as MemoType,
|
|
4171
|
+
wn as NetworkDerivationPath,
|
|
4172
|
+
ze as QuoteMode,
|
|
4173
|
+
Me as RPCUrl,
|
|
4174
|
+
we as RequestClient,
|
|
4175
|
+
et as SWAP_IN,
|
|
4176
|
+
tt as SWAP_OUT,
|
|
4177
|
+
Ln as SwapKitCore,
|
|
3732
4178
|
m as SwapKitError,
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
4179
|
+
x as SwapKitNumber,
|
|
4180
|
+
Je as TCAvalancheDepositABI,
|
|
4181
|
+
Qe as TCBscDepositABI,
|
|
4182
|
+
Xe as TCEthereumVaultAbi,
|
|
4183
|
+
Rn as TCSupportedChainList,
|
|
4184
|
+
An as UTXOChainList,
|
|
4185
|
+
lt as WalletOption,
|
|
4186
|
+
Sn as assetFromString,
|
|
4187
|
+
Bn as derivationPathToString,
|
|
4188
|
+
fn as erc20ABI,
|
|
4189
|
+
In as filterAssets,
|
|
4190
|
+
se as formatBigIntToSafeValue,
|
|
4191
|
+
wt as gasFeeMultiplier,
|
|
4192
|
+
Et as getAssetType,
|
|
4193
|
+
St as getAsymmetricAssetShare,
|
|
4194
|
+
Cn as getAsymmetricAssetWithdrawAmount,
|
|
4195
|
+
Ot as getAsymmetricRuneShare,
|
|
4196
|
+
vn as getAsymmetricRuneWithdrawAmount,
|
|
4197
|
+
At as getCommonAssetInfo,
|
|
4198
|
+
bt as getDecimal,
|
|
4199
|
+
Nn as getEstimatedPoolShare,
|
|
4200
|
+
xn as getLiquiditySlippage,
|
|
4201
|
+
N as getMemoFor,
|
|
4202
|
+
de as getMinAmountByChain,
|
|
4203
|
+
It as getSymmetricPoolShare,
|
|
4204
|
+
Mn as getSymmetricWithdraw,
|
|
4205
|
+
Dn as getTHORNameCost,
|
|
4206
|
+
De as isGasAsset,
|
|
4207
|
+
Pn as validateTHORName
|
|
3762
4208
|
};
|