MCPcopy Create free account
hub / github.com/wevm/viem / writeTokenSets

Function writeTokenSets

scripts/generateTokenlist.ts:306–341  ·  view source on GitHub ↗
(tokenDefinitions: TokenDefinition[])

Source from the content-addressed store, hash-verified

304}
305
306async function writeTokenSets(tokenDefinitions: TokenDefinition[]) {
307 const allNames = getDefinitionExports(tokenDefinitions)
308 const tempoNames = tokenDefinitions
309 .map((token) => token.importName)
310 .sort((a, b) => a.localeCompare(b))
311 const popularNames = allNames.filter((name) => {
312 const file = new URL(`${name}.ts`, definitionsDir)
313 return /\bpopular:\s*true\b/.test(readFileSync(file, 'utf8'))
314 })
315
316 const list = (names: string[]) =>
317 names.length === 0
318 ? '[] as const satisfies Tokens'
319 : `[\n${names.map((name) => ` ${name},`).join('\n')}\n] as const satisfies Tokens`
320
321 await Bun.write(
322 tokenSetsFile,
323 `${generatedBanner}
324
325import type { Tokens } from './defineToken.js'
326${allNames.map((name) => `import { ${name} } from './definitions/${name}.js'`).join('\n')}
327
328/** Every token definition. */
329const all = ${list(allNames)}
330
331/** Tokens flagged as popular. */
332const popular = ${list(popularNames)}
333
334/** All tokens available on Tempo chains. */
335const tempo = ${list(tempoNames)}
336
337/** Curated token sets that can be passed to a Client's \`tokens\` property. */
338export const tokens = { all, popular, tempo }
339`,
340 )
341}
342
343function getTokenDefinitionSource(token: TokenDefinition) {
344 const addresses = Array.from(token.addresses.entries())

Callers 1

Calls 2

getDefinitionExportsFunction · 0.85
listFunction · 0.70

Tested by

no test coverage detected