Socket
Socket
Sign inDemoInstall

@swapkit/helpers

Package Overview
Dependencies
3
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-nightly-20240530180405 to 0.0.0-nightly-20240606092108

src/types/radix.ts

6

package.json

@@ -9,3 +9,3 @@ {

"devDependencies": {
"@swapkit/tokens": "0.0.0-nightly-20240530180405",
"@swapkit/tokens": "0.0.0-nightly-20240606092108",
"bun-types": "1.1.8",

@@ -15,3 +15,3 @@ "ethers": "6.11.1"

"peerDependencies": {
"@swapkit/tokens": "0.0.0-nightly-20240530180405",
"@swapkit/tokens": "0.0.0-nightly-20240606092108",
"ky": "1.2.3",

@@ -43,3 +43,3 @@ "zod": "3.23.8"

"types": "./src/index.ts",
"version": "0.0.0-nightly-20240530180405"
"version": "0.0.0-nightly-20240606092108"
}
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";

@@ -4,0 +4,0 @@ import { findAssetBy } from "../asset.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";

@@ -37,2 +38,27 @@

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) => {

@@ -63,2 +89,8 @@ if (symbol === Chain.Ethereum) return BaseDecimal.ETH;

const getRadixAssetDecimal = (symbol: string) => {
if (symbol === Chain.Radix) return BaseDecimal.XRD;
return getRadixResourceDecimals({ symbol });
};
export const getDecimal = ({ chain, symbol }: { chain: Chain; symbol: string }) => {

@@ -72,2 +104,4 @@ switch (chain) {

return getBSCAssetDecimal(symbol);
case Chain.Radix:
return getRadixAssetDecimal(symbol);
default:

@@ -85,4 +119,2 @@ return BaseDecimal[chain];

return symbol === "CACAO";
case Chain.Kujira:
return symbol === "KUJI";
case Chain.Cosmos:

@@ -124,5 +156,6 @@ return symbol === "ATOM";

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 };

@@ -153,3 +186,2 @@ default:

return symbol === Chain.Polygon ? "Native" : "POLYGON";
case Chain.Arbitrum:

@@ -159,2 +191,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";

@@ -161,0 +195,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,3 +21,3 @@ import { ExplorerUrl, RPCUrl } from "./network";

Polygon = "MATIC",
Radix = "RADIX",
Radix = "XRD",
THORChain = "THOR",

@@ -110,4 +110,3 @@ }

ZEC = 8,
// TODO do some research on this
RADIX = 8,
XRD = 18,
}

@@ -114,0 +113,0 @@

@@ -30,3 +30,3 @@ import type { Chain } from "./chains";

OP = "m/44'/60'/0'/0",
RADIX = "////",
XRD = "////",
THOR = "m/44'/931'/0'/0",

@@ -56,5 +56,5 @@ }

// Polkadot and related network derivation path is not number based
RADIX: [0, 0, 0, 0, 0],
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";

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc