Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5421,6 +5421,8 @@

"jsontokens/@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],

"jsontokens/@noble/secp256k1": ["@noble/[email protected]", "", {}, "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw=="],

"k-rpc-socket/bencode": ["[email protected]", "", {}, "sha512-D/vrAD4dLVX23NalHwb8dSvsUsxeRPO8Y7ToKA015JQYq69MLDOMkC0uGZYA/MPpltLO8rt8eqFC2j8DxjTZ/w=="],

"keccak/node-addon-api": ["[email protected]", "", {}, "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA=="],
Expand Down
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
coverageReporter = ["text", "lcov"]
7 changes: 6 additions & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
},
"description": "SwapKit - Browser SDK",
"exports": {
".": { "import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/types/index.d.ts" }
".": {
"bun": "./src/index.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/types/index.d.ts"
}
},
"files": ["dist/"],
"homepage": "https://github.com/swapkit/SwapKit",
Expand Down
7 changes: 6 additions & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"author": "swapkit-oss",
"description": "SwapKit - Contracts",
"exports": {
".": { "import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/types/index.d.ts" }
".": {
"bun": "./src/index.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/types/index.d.ts"
}
},
"files": ["dist/"],
"homepage": "https://github.com/swapkit/SwapKit",
Expand Down
7 changes: 6 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"description": "SwapKit - Core",
"devDependencies": { "ts-pattern": "5.8.0" },
"exports": {
".": { "import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/types/index.d.ts" }
".": {
"bun": "./src/index.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/types/index.d.ts"
}
},
"files": ["dist/"],
"homepage": "https://github.com/swapkit/SwapKit",
Expand Down
16 changes: 14 additions & 2 deletions packages/helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,30 @@
"zustand": "5.0.8"
},
"exports": {
".": { "default": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/types/index.d.ts" },
".": {
"bun": "./src/index.ts",
"default": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/types/index.d.ts"
},
"./api": {
"bun": "./src/api/index.ts",
"default": "./dist/api/index.js",
"require": "./dist/api/index.cjs",
"types": "./dist/types/api/index.d.ts"
},
"./contracts": {
"bun": "./src/contracts.ts",
"default": "./dist/contracts.js",
"require": "./dist/contracts.cjs",
"types": "./dist/types/contracts.d.ts"
},
"./tokens": { "default": "./dist/tokens.js", "require": "./dist/tokens.cjs", "types": "./dist/types/tokens.d.ts" }
"./tokens": {
"bun": "./src/tokens.ts",
"default": "./dist/tokens.js",
"require": "./dist/tokens.cjs",
"types": "./dist/types/tokens.d.ts"
}
},
"files": ["dist/"],
"homepage": "https://github.com/swapkit/SwapKit",
Expand Down
130 changes: 130 additions & 0 deletions packages/helpers/src/modules/__tests__/assetValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1445,4 +1445,134 @@ describe("asyncTokenLookup", () => {
expect(assetValue.address).toBe("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
});
});

describe("getIconUrl", () => {
test("returns logoURI when token is in static map", async () => {
await AssetValue.loadStaticAssets();
const asset = AssetValue.from({ asset: "BTC.BTC" });

expect(asset.getIconUrl()).toBeString();
expect(asset.getIconUrl()?.length).toBeGreaterThan(0);
});

test("returns undefined for custom token not in map", () => {
AssetValue.setStaticAssets(new Map());

const asset = AssetValue.from({ asset: "BTC.BTC" });
expect(asset.getIconUrl()).toBeUndefined();

void AssetValue.loadStaticAssets();
});
});

describe("setStaticAssets", () => {
test("sets custom static assets map", () => {
const customMap = new Map();

customMap.set("ETH.CUSTOMTOKEN-0X123", {
address: "0x123",
chain: Chain.Ethereum,
decimal: 18,
identifier: "ETH.CUSTOMTOKEN-0x123",
tax: undefined,
});

const result = AssetValue.setStaticAssets(customMap);
expect(result).toBe(true);

const asset = AssetValue.from({ asset: "ETH.CUSTOMTOKEN-0X123" });
expect(asset.decimal).toBe(18);
expect(asset.toString()).toBe("ETH.CUSTOMTOKEN-0x123");
});

test("clears existing static assets when setting new ones", () => {
const map1 = new Map();
map1.set("BTC.TOKEN1", { chain: Chain.Bitcoin, decimal: 8, identifier: "BTC.TOKEN1" });

AssetValue.setStaticAssets(map1);

const map2 = new Map();
map2.set("ETH.TOKEN2-0xABC", {
address: "0xABC",
chain: Chain.Ethereum,
decimal: 18,
identifier: "ETH.TOKEN2-0xABC",
});

AssetValue.setStaticAssets(map2);

// TOKEN2 should exist
const asset2 = AssetValue.from({ asset: "ETH.TOKEN2-0xABC" });
expect(asset2.decimal).toBe(18);
});

test("handles token with decimals property", () => {
const customMap = new Map();

customMap.set("AVAX.CUSTOMUSDC-0X456", {
address: "0x456",
chain: Chain.Avalanche,
decimals: 6,
identifier: "AVAX.CUSTOMUSDC-0x456",
});

AssetValue.setStaticAssets(customMap);

const asset = AssetValue.from({ asset: "AVAX.CUSTOMUSDC-0X456" });
expect(asset.decimal).toBe(6);
});

test("handles case sensitive chains correctly", () => {
const customMap = new Map();

// SOL is case sensitive
customMap.set("SOL.CUSTOMTOKEN-ADDRESS123", {
address: "ADDRESS123",
chain: Chain.Solana,
decimal: 9,
identifier: "SOL.CUSTOMTOKEN-ADDRESS123",
});

AssetValue.setStaticAssets(customMap);

const asset = AssetValue.from({ asset: "SOL.CUSTOMTOKEN-ADDRESS123" });
expect(asset.decimal).toBe(9);
expect(asset.address).toBe("ADDRESS123");
});

test("populates chain:address map for lookups", () => {
const customMap = new Map();

customMap.set("BSC.TOKEN-0XDEF", {
address: "0xDEF",
chain: Chain.BinanceSmartChain,
decimal: 18,
identifier: "BSC.TOKEN-0xDEF",
});

AssetValue.setStaticAssets(customMap);

// Should be able to find by chain:address
const asset = AssetValue.from({ address: "0XDEF", chain: Chain.BinanceSmartChain });
expect(asset.decimal).toBe(18);
});

test("handles tokens with tax property", () => {
const customMap = new Map();

const tax = { buy: 0.1, sell: 0.2 };
customMap.set("ETH.TAXTOKEN-0X789", {
address: "0x789",
chain: Chain.Ethereum,
decimal: 18,
identifier: "ETH.TAXTOKEN-0x789",
tax,
});

AssetValue.setStaticAssets(customMap);

const asset = AssetValue.from({ asset: "ETH.TAXTOKEN-0X789" });
expect(asset.tax).toEqual(tax);
});
});
});
Loading