Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a CAL importer for casper #8904

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import fs from "fs";
import path from "path";
import { fetchTokensFromCALService } from "../../fetch";

type CasperToken = [
string, // assetCode
string, // assetIssuer
"Casper", // assetType (note: only used in Receive asset message and always should be "Casper")
string, // name
number, // precision
boolean, // enableCountervalues
];

export const importCasperTokens = async (outputDir: string) => {
try {
console.log("importing casper tokens...");
const { tokens, hash } = await fetchTokensFromCALService({ blockchain_name: "casper" }, [
"ticker",
"contract_address",
"name",
"decimals",
]);
const casperTokens: CasperToken[] = tokens.map(token => [
token.ticker.toLowerCase(),
token.contract_address.toLowerCase(),
"Casper",
token.name,
token.decimals,
true,
]);

const filePath = path.join(outputDir, "casper");
const casperTypeStringified = `export type CasperToken = [
string, // assetCode
string, // assetIssuer
"Casper", // assetType (note: only used in Receive asset message and always should be "Casper")
string, // name
number, // precision
boolean, // enableCountervalues
];`;

fs.writeFileSync(`${filePath}.json`, JSON.stringify(casperTokens));
if (hash) {
fs.writeFileSync(`${filePath}-hash.json`, JSON.stringify(hash));
}

fs.writeFileSync(
`${filePath}.ts`,
`${casperTypeStringified}

import tokens from "./casper.json";

${hash ? `export { default as hash } from "./casper-hash.json";` : ""}

export default tokens as CasperToken[];
`,
);

console.log("importing casper tokens sucess");
} catch (err) {
console.error(err);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";

import { importAsaTokens } from "./importers/asa";
import { importCardanoNativeTokens } from "./importers/cardanoNative";
import { importCasperTokens } from "./importers/casper";
import { importEIP712, importEIP712v2 } from "./importers/eip712";
import { importESDTTokens } from "./importers/esdt";
import { importEVMTokens } from "./importers/evm";
Expand All @@ -28,6 +29,7 @@ const importTokens = async () => {
importEVMTokens(outputFolder),
importAsaTokens(outputFolder),
importCardanoNativeTokens(outputFolder),
importCasperTokens(outputFolder),
importESDTTokens(outputFolder),
importSPLTokens(outputFolder),
importStellarTokens(outputFolder),
Expand Down
17 changes: 0 additions & 17 deletions libs/ledgerjs/packages/cryptoassets/src/data/casper.ts

This file was deleted.

Loading