@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.108 to 1.0.0-rc.109
@@ -41,3 +41,3 @@ { | ||
"types": "./src/index.ts", | ||
"version": "1.0.0-rc.108" | ||
"version": "1.0.0-rc.109" | ||
} |
import { describe, expect, test } from "bun:test"; | ||
import { BaseDecimal, Chain } from "@swapkit/helpers"; | ||
import { BaseDecimal, Chain } from "../../types"; | ||
@@ -66,2 +66,9 @@ import { assetFromString, getAssetType, getDecimal } from "../asset.ts"; | ||
}); | ||
describe("for Radix chain", () => { | ||
test('should return "RADIX" for non-XRD tickers', () => { | ||
const result = getAssetType({ chain: Chain.Radix, symbol: "NOT_XRD" }); | ||
expect(result).toBe("RADIX"); | ||
}); | ||
}); | ||
}); | ||
@@ -176,2 +183,21 @@ }); | ||
}); | ||
describe("Radix", () => { | ||
test( | ||
"returns proper decimal for radix and it's assets", | ||
async () => { | ||
const radixDecimal = await getDecimal({ chain: Chain.Radix, symbol: "XRD" }); | ||
expect(radixDecimal).toBe(BaseDecimal.XRD); | ||
await Bun.sleep(500); | ||
const xwBTCDecimal = await getDecimal({ | ||
chain: Chain.Radix, | ||
symbol: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
}); | ||
expect(xwBTCDecimal).toBe(8); | ||
await Bun.sleep(500); | ||
}, | ||
{ retry: 3 }, | ||
); | ||
}); | ||
}); | ||
@@ -203,2 +229,15 @@ | ||
}); | ||
test("should return the correct object for Radix resource", () => { | ||
const assetString = | ||
"XRD.xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75"; | ||
const result = assetFromString(assetString); | ||
expect(result).toEqual({ | ||
chain: Chain.Radix, | ||
symbol: "xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
ticker: "xwBTC", | ||
synth: false, | ||
}); | ||
}); | ||
}); |
import { describe, expect, test } from "bun:test"; | ||
import { Chain, MemoType } from "@swapkit/helpers"; | ||
import { Chain, MemoType } from "../../types"; | ||
@@ -4,0 +4,0 @@ import { getMemoFor } from "../memo.ts"; |
import { describe, expect, test } from "bun:test"; | ||
import { Chain, type DerivationPathArray } from "@swapkit/helpers"; | ||
import { Chain, type DerivationPathArray } from "../../types"; | ||
@@ -52,3 +52,5 @@ import { findAssetBy } from "../asset.ts"; | ||
}); | ||
expect(assetByChainAndContract).toBe("ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"); | ||
expect(assetByChainAndContract?.toUpperCase()).toBe( | ||
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48", | ||
); | ||
}); | ||
@@ -55,0 +57,0 @@ |
import { AssetValue } from "../modules/assetValue.ts"; | ||
import { RequestClient } from "../modules/requestClient.ts"; | ||
import { BaseDecimal, Chain, ChainToRPC, type EVMChain, EVMChains } from "../types/chains.ts"; | ||
import type { RadixCoreStateResourceDTO } from "../types/radix.ts"; | ||
import type { TokenNames } from "../types/tokens.ts"; | ||
@@ -38,6 +39,32 @@ | ||
const getRadixResourceDecimals = async ({ symbol }: { symbol: string }) => { | ||
try { | ||
const resourceAddress = symbol.split("-")[1]?.toLowerCase(); | ||
const { manager } = await RequestClient.post<RadixCoreStateResourceDTO>( | ||
`${ChainToRPC[Chain.Radix]}/state/resource`, | ||
{ | ||
headers: { | ||
Accept: "*/*", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
network: "mainnet", | ||
resource_address: resourceAddress, | ||
}), | ||
}, | ||
); | ||
return manager.divisibility.value.divisibility; | ||
} catch (error) { | ||
console.error(error); | ||
return BaseDecimal[Chain.Radix]; | ||
} | ||
}; | ||
const getETHAssetDecimal = (symbol: string) => { | ||
if (symbol === Chain.Ethereum) return BaseDecimal.ETH; | ||
const splitSymbol = symbol.split("-"); | ||
const address = splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1]; | ||
const address = | ||
splitSymbol.length === 1 ? undefined : splitSymbol[splitSymbol.length - 1]?.toLowerCase(); | ||
@@ -64,2 +91,8 @@ return address?.startsWith("0x") | ||
const getRadixAssetDecimal = (symbol: string) => { | ||
if (symbol === Chain.Radix) return BaseDecimal.XRD; | ||
return getRadixResourceDecimals({ symbol }); | ||
}; | ||
export const getDecimal = ({ chain, symbol }: { chain: Chain; symbol: string }) => { | ||
@@ -73,2 +106,4 @@ switch (chain) { | ||
return getBSCAssetDecimal(symbol); | ||
case Chain.Radix: | ||
return getRadixAssetDecimal(symbol); | ||
default: | ||
@@ -139,5 +174,6 @@ return BaseDecimal[chain]; | ||
return { identifier: "MAYA.MAYA", decimal: 4 }; | ||
case `${Chain.Kujira}.USK`: | ||
return { identifier: `${Chain.Kujira}.USK`, decimal: 6 }; | ||
case Chain.Radix: | ||
return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal.XRD }; | ||
@@ -168,3 +204,2 @@ default: | ||
return symbol === Chain.Polygon ? "Native" : "POLYGON"; | ||
case Chain.Arbitrum: | ||
@@ -174,2 +209,4 @@ return [Chain.Ethereum, Chain.Arbitrum].includes(symbol as Chain) ? "Native" : "ARBITRUM"; | ||
return [Chain.Ethereum, Chain.Optimism].includes(symbol as Chain) ? "Native" : "OPTIMISM"; | ||
case Chain.Radix: | ||
return symbol === Chain.Radix ? "Native" : "RADIX"; | ||
@@ -176,0 +213,0 @@ default: |
@@ -44,2 +44,13 @@ import { describe, expect, test } from "bun:test"; | ||
expect(atomDerived.toString()).toBe("THOR.ATOM"); | ||
const radixXWBTC = new AssetValue({ | ||
identifier: | ||
"RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
decimal: 8, | ||
value: 11112222, | ||
}); | ||
expect(radixXWBTC.toString()).toBe( | ||
"RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
); | ||
}); | ||
@@ -159,2 +170,3 @@ }); | ||
}); | ||
test("creates AssetValue from string with multiple dashes", async () => { | ||
@@ -194,2 +206,3 @@ const ethPendleLptAsset = await AssetValue.fromIdentifier("ETH.PENDLE-LPT-0x1234"); | ||
}); | ||
test("creates AssetValue from string with multiple dashes", async () => { | ||
@@ -211,2 +224,20 @@ const fakeAvaxAssetString = "AVAX.ASDF-LP-1234"; | ||
}); | ||
test("creates AssetValue with _ symbol", async () => { | ||
const radixXWBTC = await AssetValue.fromString( | ||
"XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
); | ||
expect(radixXWBTC).toEqual( | ||
expect.objectContaining({ | ||
address: "resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
chain: Chain.Radix, | ||
decimal: 8, | ||
isGasAsset: false, | ||
isSynthetic: false, | ||
symbol: "XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
ticker: "XWBTC", | ||
}), | ||
); | ||
}); | ||
}); | ||
@@ -445,2 +476,3 @@ | ||
Chain.Optimism, | ||
Chain.Radix, | ||
]; | ||
@@ -574,2 +606,16 @@ const filteredChains = Object.values(Chain).filter((c) => !customBaseAsset.includes(c)); | ||
); | ||
const xrdAsset = AssetValue.fromChainOrSignature(Chain.Radix); | ||
expect(xrdAsset).toEqual( | ||
expect.objectContaining({ | ||
address: undefined, | ||
chain: Chain.Radix, | ||
decimal: BaseDecimal.XRD, | ||
isGasAsset: true, | ||
isSynthetic: false, | ||
symbol: "XRD", | ||
ticker: "XRD", | ||
type: "Native", | ||
}), | ||
); | ||
}); | ||
@@ -576,0 +622,0 @@ }); |
@@ -21,2 +21,3 @@ import { ExplorerUrl, RPCUrl } from "./network"; | ||
Polygon = "MATIC", | ||
Radix = "XRD", | ||
THORChain = "THOR", | ||
@@ -52,2 +53,3 @@ } | ||
PolygonHex = "0x89", | ||
Radix = "radix-mainnet", | ||
THORChain = "thorchain-mainnet-v1", | ||
@@ -82,2 +84,3 @@ THORChainStagenet = "thorchain-stagenet-v2", | ||
[ChainId.Polygon]: Chain.Polygon, | ||
[ChainId.Radix]: Chain.Radix, | ||
[ChainId.THORChainStagenet]: Chain.THORChain, | ||
@@ -111,2 +114,3 @@ [ChainId.THORChain]: Chain.THORChain, | ||
ZEC = 8, | ||
XRD = 18, | ||
} | ||
@@ -113,0 +117,0 @@ |
@@ -30,2 +30,3 @@ import type { Chain } from "./chains"; | ||
OP = "m/44'/60'/0'/0", | ||
XRD = "////", | ||
THOR = "m/44'/931'/0'/0", | ||
@@ -55,4 +56,5 @@ } | ||
// Polkadot and related network derivation path is not number based | ||
XRD: [0, 0, 0, 0, 0], | ||
DOT: [0, 0, 0, 0, 0], | ||
FLIP: [0, 0, 0, 0, 0], | ||
}; |
@@ -12,1 +12,2 @@ export * from "./abis/erc20"; | ||
export * from "./quotes"; | ||
export * from "./radix"; |
@@ -20,2 +20,3 @@ export enum RPCUrl { | ||
Polygon = "https://polygon-rpc.com", | ||
Radix = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core", | ||
THORChain = "https://rpc.thorswap.net", | ||
@@ -43,3 +44,4 @@ THORChainStagenet = "https://stagenet-rpc.ninerealms.com", | ||
Polygon = "https://polygonscan.com", | ||
Radix = "https://dashboard.radixdlt.com", | ||
THORChain = "https://runescan.io", | ||
} |
@@ -28,2 +28,3 @@ import type { Eip1193Provider } from "ethers"; | ||
EXODUS = "EXODUS", | ||
RADIX_WALLET = "RADIX_WALLET", | ||
} | ||
@@ -30,0 +31,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462044
37
7745