Skip to content

Commit

Permalink
Feat/polygon exchange importer (#7507) (#7515)
Browse files Browse the repository at this point in the history
* Feature: Add Polygon ERC20 importers for exchange
  • Loading branch information
CremaFR authored Aug 6, 2024
1 parent 10494a2 commit 50b6db6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-beers-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/cryptoassets": minor
---

Adding support for polygon ERC20 exchange importing
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fs from "fs";
import { fetchTokens } from "../fetch";

type PolygonERC20Exchange = [string, string, string];

export const importPolygonERC20Exchange = async (outputDir: string) => {
console.log("importing Polygon-ERC20 exchange...");
try {
const [polygonERC20Exchange, hash] = await fetchTokens<PolygonERC20Exchange>(
"evm/137/erc20-exchange.json",
);
fs.writeFileSync(
`${outputDir}/exchange/polygon-erc20.json`,
JSON.stringify(polygonERC20Exchange),
);
if (hash) {
fs.writeFileSync(`${outputDir}/exchange/polygon-erc20-hash.json`, JSON.stringify(hash));
}

const polygonerc20typeStringified = `export type PolygonERC20Exchange = [string, string, string];`;
const hashStringified = hash
? `export { default as hash } from "./polygon-erc20-hash.json";`
: "";
const exchangesStringified = `import exchanges from "./polygon-erc20.json";`;
const exportStringified = `export default exchanges as PolygonERC20Exchange[];`;

fs.writeFileSync(
`${outputDir}/exchange/polygon-erc20.ts`,
`${polygonerc20typeStringified}
${hashStringified}
${exchangesStringified}
${exportStringified}
`,
);

console.log("importing Polygon-ERC20 exchange success");
} catch (err) {
console.error(err);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { importBEP20Exchange } from "./exchange/bep20";
import { importERC20Exchange } from "./exchange/erc20";
import { importCoinsExchange } from "./exchange/coins";
import { importTRC20Exchange } from "./exchange/trc20";
import { importPolygonERC20Exchange } from "./exchange/polygon-erc20";

import { importERC20Signatures } from "./importers/erc20-signature";

Expand Down Expand Up @@ -48,6 +49,7 @@ const importExchangeTokens = async () => {
importERC20Exchange(outputFolder),
importCoinsExchange(outputFolder),
importTRC20Exchange(outputFolder),
importPolygonERC20Exchange(outputFolder),
];

await Promise.allSettled(promises);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\"8f79337368e2cde5075fa2ddb1b3361a\""

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type PolygonERC20Exchange = [string, string, string];

export { default as hash } from "./polygon-erc20-hash.json";

import exchanges from "./polygon-erc20.json";

export default exchanges as PolygonERC20Exchange[];
3 changes: 2 additions & 1 deletion libs/ledgerjs/packages/cryptoassets/src/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import erc20 from "./data/exchange/erc20";
import coins from "./data/exchange/coins";
import bep20 from "./data/exchange/bep20";
import trc20 from "./data/exchange/trc20";
import polygon20 from "./data/exchange/polygon-erc20";

const all = [...coins, ...erc20, ...bep20, ...trc20];
const all = [...coins, ...erc20, ...bep20, ...trc20, ...polygon20];
const configs = {};

for (const [id, config, signature] of all) {
Expand Down

0 comments on commit 50b6db6

Please sign in to comment.