@swapkit/helpers 1.0.0-rc.107 → 1.0.0-rc.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +54 -5
- package/dist/index.js.map +9 -9
- package/package.json +1 -1
- package/src/helpers/__tests__/asset.test.ts +40 -1
- package/src/helpers/__tests__/memo.test.ts +1 -1
- package/src/helpers/__tests__/others.test.ts +4 -2
- package/src/helpers/asset.ts +40 -3
- package/src/helpers/others.ts +17 -0
- package/src/modules/__tests__/assetValue.test.ts +46 -0
- package/src/types/chains.ts +6 -0
- package/src/types/commonTypes.ts +4 -0
- package/src/types/derivationPath.ts +2 -0
- package/src/types/index.ts +1 -0
- package/src/types/network.ts +2 -0
- package/src/types/radix.ts +14 -0
- package/src/types/wallet.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -953,6 +953,7 @@ var RPCUrl;
|
|
|
953
953
|
RPCUrl2["Optimism"] = "https://mainnet.optimism.io";
|
|
954
954
|
RPCUrl2["Polkadot"] = "wss://rpc.polkadot.io";
|
|
955
955
|
RPCUrl2["Polygon"] = "https://polygon-rpc.com";
|
|
956
|
+
RPCUrl2["Radix"] = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core";
|
|
956
957
|
RPCUrl2["THORChain"] = "https://rpc.thorswap.net";
|
|
957
958
|
RPCUrl2["THORChainStagenet"] = "https://stagenet-rpc.ninerealms.com";
|
|
958
959
|
})(RPCUrl || (RPCUrl = {}));
|
|
@@ -975,6 +976,7 @@ var ExplorerUrl;
|
|
|
975
976
|
ExplorerUrl2["Optimism"] = "https://optimistic.etherscan.io";
|
|
976
977
|
ExplorerUrl2["Polkadot"] = "https://polkadot.subscan.io/";
|
|
977
978
|
ExplorerUrl2["Polygon"] = "https://polygonscan.com";
|
|
979
|
+
ExplorerUrl2["Radix"] = "https://dashboard.radixdlt.com";
|
|
978
980
|
ExplorerUrl2["THORChain"] = "https://runescan.io";
|
|
979
981
|
})(ExplorerUrl || (ExplorerUrl = {}));
|
|
980
982
|
|
|
@@ -998,6 +1000,7 @@ var Chain;
|
|
|
998
1000
|
Chain2["Polkadot"] = "DOT";
|
|
999
1001
|
Chain2["Chainflip"] = "FLIP";
|
|
1000
1002
|
Chain2["Polygon"] = "MATIC";
|
|
1003
|
+
Chain2["Radix"] = "XRD";
|
|
1001
1004
|
Chain2["THORChain"] = "THOR";
|
|
1002
1005
|
})(Chain || (Chain = {}));
|
|
1003
1006
|
var ChainId;
|
|
@@ -1026,6 +1029,7 @@ var ChainId;
|
|
|
1026
1029
|
ChainId2["Polkadot"] = "polkadot";
|
|
1027
1030
|
ChainId2["Polygon"] = "137";
|
|
1028
1031
|
ChainId2["PolygonHex"] = "0x89";
|
|
1032
|
+
ChainId2["Radix"] = "radix-mainnet";
|
|
1029
1033
|
ChainId2["THORChain"] = "thorchain-mainnet-v1";
|
|
1030
1034
|
ChainId2["THORChainStagenet"] = "thorchain-stagenet-v2";
|
|
1031
1035
|
})(ChainId || (ChainId = {}));
|
|
@@ -1054,6 +1058,7 @@ var ChainIdToChain = {
|
|
|
1054
1058
|
[ChainId.Polkadot]: Chain.Polkadot,
|
|
1055
1059
|
[ChainId.PolygonHex]: Chain.Polygon,
|
|
1056
1060
|
[ChainId.Polygon]: Chain.Polygon,
|
|
1061
|
+
[ChainId.Radix]: Chain.Radix,
|
|
1057
1062
|
[ChainId.THORChainStagenet]: Chain.THORChain,
|
|
1058
1063
|
[ChainId.THORChain]: Chain.THORChain
|
|
1059
1064
|
};
|
|
@@ -1080,6 +1085,7 @@ var BaseDecimal;
|
|
|
1080
1085
|
BaseDecimal2[BaseDecimal2["OP"] = 18] = "OP";
|
|
1081
1086
|
BaseDecimal2[BaseDecimal2["THOR"] = 8] = "THOR";
|
|
1082
1087
|
BaseDecimal2[BaseDecimal2["ZEC"] = 8] = "ZEC";
|
|
1088
|
+
BaseDecimal2[BaseDecimal2["XRD"] = 18] = "XRD";
|
|
1083
1089
|
})(BaseDecimal || (BaseDecimal = {}));
|
|
1084
1090
|
var SubstrateChains = [Chain.Polkadot, Chain.Chainflip];
|
|
1085
1091
|
var EVMChains = [
|
|
@@ -1214,6 +1220,7 @@ var DerivationPath;
|
|
|
1214
1220
|
DerivationPath2["MATIC"] = "m/44'/60'/0'/0";
|
|
1215
1221
|
DerivationPath2["MAYA"] = "m/44'/931'/0'/0";
|
|
1216
1222
|
DerivationPath2["OP"] = "m/44'/60'/0'/0";
|
|
1223
|
+
DerivationPath2["XRD"] = "////";
|
|
1217
1224
|
DerivationPath2["THOR"] = "m/44'/931'/0'/0";
|
|
1218
1225
|
})(DerivationPath || (DerivationPath = {}));
|
|
1219
1226
|
var NetworkDerivationPath = {
|
|
@@ -1233,6 +1240,7 @@ var NetworkDerivationPath = {
|
|
|
1233
1240
|
MAYA: [44, 931, 0, 0, 0],
|
|
1234
1241
|
OP: [44, 60, 0, 0, 0],
|
|
1235
1242
|
THOR: [44, 931, 0, 0, 0],
|
|
1243
|
+
XRD: [0, 0, 0, 0, 0],
|
|
1236
1244
|
DOT: [0, 0, 0, 0, 0],
|
|
1237
1245
|
FLIP: [0, 0, 0, 0, 0]
|
|
1238
1246
|
};
|
|
@@ -1255,6 +1263,7 @@ var WalletOption;
|
|
|
1255
1263
|
WalletOption2["WALLETCONNECT"] = "WALLETCONNECT";
|
|
1256
1264
|
WalletOption2["EIP6963"] = "EIP6963";
|
|
1257
1265
|
WalletOption2["EXODUS"] = "EXODUS";
|
|
1266
|
+
WalletOption2["RADIX_WALLET"] = "RADIX_WALLET";
|
|
1258
1267
|
})(WalletOption || (WalletOption = {}));
|
|
1259
1268
|
var LedgerErrorCode;
|
|
1260
1269
|
(function(LedgerErrorCode2) {
|
|
@@ -1916,9 +1925,6 @@ var numberFormatter = Intl.NumberFormat("fullwide", {
|
|
|
1916
1925
|
|
|
1917
1926
|
// src/modules/swapKitNumber.ts
|
|
1918
1927
|
class SwapKitNumber extends BigIntArithmetics {
|
|
1919
|
-
constructor() {
|
|
1920
|
-
super(...arguments);
|
|
1921
|
-
}
|
|
1922
1928
|
eq(value) {
|
|
1923
1929
|
return this.eqValue(value);
|
|
1924
1930
|
}
|
|
@@ -2199,11 +2205,30 @@ var getContractDecimals = async ({ chain, to }) => {
|
|
|
2199
2205
|
return BaseDecimal[chain];
|
|
2200
2206
|
}
|
|
2201
2207
|
};
|
|
2208
|
+
var getRadixResourceDecimals = async ({ symbol }) => {
|
|
2209
|
+
try {
|
|
2210
|
+
const resourceAddress = symbol.split("-")[1]?.toLowerCase();
|
|
2211
|
+
const { manager } = await RequestClient.post(`${ChainToRPC[Chain.Radix]}/state/resource`, {
|
|
2212
|
+
headers: {
|
|
2213
|
+
Accept: "*/*",
|
|
2214
|
+
"Content-Type": "application/json"
|
|
2215
|
+
},
|
|
2216
|
+
body: JSON.stringify({
|
|
2217
|
+
network: "mainnet",
|
|
2218
|
+
resource_address: resourceAddress
|
|
2219
|
+
})
|
|
2220
|
+
});
|
|
2221
|
+
return manager.divisibility.value.divisibility;
|
|
2222
|
+
} catch (error) {
|
|
2223
|
+
console.error(error);
|
|
2224
|
+
return BaseDecimal[Chain.Radix];
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2202
2227
|
var getETHAssetDecimal = (symbol) => {
|
|
2203
2228
|
if (symbol === Chain.Ethereum)
|
|
2204
2229
|
return BaseDecimal.ETH;
|
|
2205
2230
|
const splitSymbol = symbol.split("-");
|
|
2206
|
-
const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1];
|
|
2231
|
+
const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1]?.toLowerCase();
|
|
2207
2232
|
return address?.startsWith("0x") ? getContractDecimals({ chain: Chain.Ethereum, to: address }) : BaseDecimal.ETH;
|
|
2208
2233
|
};
|
|
2209
2234
|
var getAVAXAssetDecimal = (symbol) => {
|
|
@@ -2216,6 +2241,11 @@ var getBSCAssetDecimal = (symbol) => {
|
|
|
2216
2241
|
return BaseDecimal.BSC;
|
|
2217
2242
|
return BaseDecimal.BSC;
|
|
2218
2243
|
};
|
|
2244
|
+
var getRadixAssetDecimal = (symbol) => {
|
|
2245
|
+
if (symbol === Chain.Radix)
|
|
2246
|
+
return BaseDecimal.XRD;
|
|
2247
|
+
return getRadixResourceDecimals({ symbol });
|
|
2248
|
+
};
|
|
2219
2249
|
var getDecimal = ({ chain, symbol }) => {
|
|
2220
2250
|
switch (chain) {
|
|
2221
2251
|
case Chain.Ethereum:
|
|
@@ -2224,6 +2254,8 @@ var getDecimal = ({ chain, symbol }) => {
|
|
|
2224
2254
|
return getAVAXAssetDecimal(symbol);
|
|
2225
2255
|
case Chain.BinanceSmartChain:
|
|
2226
2256
|
return getBSCAssetDecimal(symbol);
|
|
2257
|
+
case Chain.Radix:
|
|
2258
|
+
return getRadixAssetDecimal(symbol);
|
|
2227
2259
|
default:
|
|
2228
2260
|
return BaseDecimal[chain];
|
|
2229
2261
|
}
|
|
@@ -2284,6 +2316,8 @@ var getCommonAssetInfo = (assetString) => {
|
|
|
2284
2316
|
return { identifier: "MAYA.MAYA", decimal: 4 };
|
|
2285
2317
|
case `${Chain.Kujira}.USK`:
|
|
2286
2318
|
return { identifier: `${Chain.Kujira}.USK`, decimal: 6 };
|
|
2319
|
+
case Chain.Radix:
|
|
2320
|
+
return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal.XRD };
|
|
2287
2321
|
default:
|
|
2288
2322
|
return { identifier: `${assetString}.${assetString}`, decimal: BaseDecimal[assetString] };
|
|
2289
2323
|
}
|
|
@@ -2310,6 +2344,8 @@ var getAssetType = ({ chain, symbol }) => {
|
|
|
2310
2344
|
return [Chain.Ethereum, Chain.Arbitrum].includes(symbol) ? "Native" : "ARBITRUM";
|
|
2311
2345
|
case Chain.Optimism:
|
|
2312
2346
|
return [Chain.Ethereum, Chain.Optimism].includes(symbol) ? "Native" : "OPTIMISM";
|
|
2347
|
+
case Chain.Radix:
|
|
2348
|
+
return symbol === Chain.Radix ? "Native" : "RADIX";
|
|
2313
2349
|
default:
|
|
2314
2350
|
return "Native";
|
|
2315
2351
|
}
|
|
@@ -2633,6 +2669,18 @@ function wrapWithThrow(fn, errorKey) {
|
|
|
2633
2669
|
return console.error(error);
|
|
2634
2670
|
}
|
|
2635
2671
|
}
|
|
2672
|
+
var getChainIdentifier = (chain) => {
|
|
2673
|
+
switch (chain) {
|
|
2674
|
+
case Chain.THORChain:
|
|
2675
|
+
return `${chain}.RUNE`;
|
|
2676
|
+
case Chain.Cosmos:
|
|
2677
|
+
return `${chain}.ATOM`;
|
|
2678
|
+
case Chain.BinanceSmartChain:
|
|
2679
|
+
return `${chain}`;
|
|
2680
|
+
default:
|
|
2681
|
+
return `${chain}.${chain}`;
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2636
2684
|
// src/helpers/web3wallets.ts
|
|
2637
2685
|
function getEIP6963Wallets() {
|
|
2638
2686
|
const providers = [];
|
|
@@ -2775,6 +2823,7 @@ export {
|
|
|
2775
2823
|
getDerivationPathFor,
|
|
2776
2824
|
getDecimal,
|
|
2777
2825
|
getCommonAssetInfo,
|
|
2826
|
+
getChainIdentifier,
|
|
2778
2827
|
getAsymmetricRuneWithdrawAmount,
|
|
2779
2828
|
getAsymmetricRuneShare,
|
|
2780
2829
|
getAsymmetricAssetWithdrawAmount,
|
|
@@ -2845,4 +2894,4 @@ export {
|
|
|
2845
2894
|
AGG_SWAP
|
|
2846
2895
|
};
|
|
2847
2896
|
|
|
2848
|
-
//# debugId=
|
|
2897
|
+
//# debugId=E69CEDE40279DEC964756e2164756e21
|