Skip to content

Commit

Permalink
fix broken buildTokenList function with hack
Browse files Browse the repository at this point in the history
  • Loading branch information
macalinao committed Dec 4, 2023
1 parent 2d8f193 commit 8725cde
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 461 deletions.
2 changes: 1 addition & 1 deletion .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint",
"version": "8.54.0-sdk",
"version": "8.55.0-sdk",
"main": "./lib/api.js",
"type": "commonjs",
"bin": {
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"packageManager": "[email protected]",
"devDependencies": {
"@rushstack/eslint-patch": "^1.6.0",
"@saberhq/eslint-config": "^3.2.0",
"@saberhq/tsconfig": "^3.2.0",
"@saberhq/eslint-config": "^3.2.1",
"@saberhq/tsconfig": "^3.2.1",
"@types/bn.js": "^5.1.5",
"@types/eslint": "^8.44.8",
"@types/lodash": "^4.14.202",
"@types/node": "^17.0.45",
"@types/node": "^18",
"@types/prettier": "^3.0.0",
"eslint": "^8.54.0",
"eslint": "^8.55.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import": "^2.29.0",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
Expand Down Expand Up @@ -54,5 +54,8 @@
"lint-staged": {
"*.ts": "eslint --cache --fix",
"*.{md,json,js,yml,yaml,html}": "prettier --write"
},
"engines": {
"node": ">=18"
}
}
58 changes: 46 additions & 12 deletions src/scripts/buildTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TokenInfo, TokenList } from "@saberhq/token-utils";
import { deserializeMint, networkToChainId, Token } from "@saberhq/token-utils";
import { PublicKey } from "@solana/web3.js";
import * as fs from "fs/promises";
import { chunk, uniq, zip } from "lodash";
import { uniq, zip } from "lodash";
import invariant from "tiny-invariant";

import type { RewarderInfo, RewarderMeta } from "../types.js";
Expand Down Expand Up @@ -182,18 +182,52 @@ export const buildTokenList = async (network: Network): Promise<void> => {
const missingMintsNonReplica = missingMints.filter(
(mm) => !missingReplicaMappings.find((mrm) => mrm.replicaMint.equals(mm)),
);
const missingMintsData = (
await Promise.all(
chunk(missingMintsNonReplica, 100).map(async (mintsChunk) =>
provider.connection.getMultipleAccountsInfo(mintsChunk),
),
)
).flat();
const missingTokens = zip(missingMintsNonReplica, missingMintsData).map(
([mint, mintDataRaw]) => {
console.log(
`${network}: There are ${
missingMintsNonReplica.length
} missing mints (${missingMintsNonReplica
.map((x) => x.toBase58())
.join(", ")})`,
);

const missingMintsDecimals = await Promise.all(
missingMintsNonReplica.map(async (mint) => {
if (network === "mainnet-beta") {
// TODO(igm): this is hardcoded for now since there's something wrong with getAccountInfo.
// We will investigate this when there is less time pressure.
if (
mint.toString() === "6sdr6tCfBwMzEbEhrv5oxde3KBBrJftfHQZr7xgP4C56"
) {
return 6;
}
if (
mint.toString() === "2wL27tLE24Vs4DmSNTnF1SPiNin2aVMPuReXesyPQFMR"
) {
return 6;
}
}

const mintDataRaw = await provider.connection.getAccountInfo(mint);
if (!mintDataRaw) {
throw new Error(`"Mint ${mint.toString()} not found on chain`);
}
return deserializeMint(mintDataRaw.data).decimals;
}),
);

// const missingMintsData = (
// await Promise.all(
// chunk(missingMintsNonReplica, 100).map(async (mintsChunk) =>
// provider.connection.getMultipleAccountsInfo(mintsChunk),
// ),
// )
// ).flat();
console.log(`${network}: Mints fetched`);
const missingTokens = zip(missingMintsNonReplica, missingMintsDecimals).map(
([mint, mintDecimalsRaw]) => {
invariant(mint);
invariant(mintDataRaw);
return Token.fromMint(mint, deserializeMint(mintDataRaw.data).decimals, {
invariant(mintDecimalsRaw);
return Token.fromMint(mint, mintDecimalsRaw, {
chainId: networkToChainId(network),
}).info;
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const makeProvider = (network: Network) => {
connection: new Connection(
network === "mainnet-beta"
? process.env.MAINNET_SOLANA_RPC_ENDPOINT ??
"https://samaria-8hm1z4-fast-mainnet.helius-rpc.com/"
"https://mainnet.helius-rpc.com/?api-key=26bec238-00c2-4961-ba13-faa7c0a2d767"
: "https://api.devnet.solana.com",
),
wallet: new SignerWallet(Keypair.generate()),
Expand Down
Loading

0 comments on commit 8725cde

Please sign in to comment.