-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
streamlined json inputs for registries
- Loading branch information
Showing
14 changed files
with
638 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,4 +512,4 @@ | |
"2713017997578000": { | ||
"nativeSlip44": 60 | ||
} | ||
} | ||
} |
77 changes: 39 additions & 38 deletions
77
apps/armory/src/shared/core/script/build-chain-registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,54 @@ | ||
import { ApplicationException } from '../../exception/application.exception' | ||
import { extractChain } from 'viem' | ||
import * as fs from 'fs' | ||
import { ChainRegistry } from 'packages/transaction-request-intent/src/lib/registry/chain-registry' | ||
import * as path from 'path' | ||
import { registeredCoinTypes } from 'slip44' | ||
import * as chainObject from 'viem/chains' | ||
import { registeredCoinTypes } from 'slip44'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { ChainRegistry } from '@narval/transaction-request-intent'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/* eslint-disable no-console */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
export const buildNativeSlip44 = (): ChainRegistry => { | ||
const chains = Object.values(chainObject); | ||
const chains = Object.values(chainObject) | ||
|
||
let count = 0; | ||
const chainRegistry: ChainRegistry = new Map(); | ||
let count = 0 | ||
const chainRegistry: ChainRegistry = new Map() | ||
chains.forEach((chain) => { | ||
const tokenSlip44 = registeredCoinTypes.find(([ | ||
_coinType, | ||
_derivationPathComponent, | ||
symbol, | ||
_name, | ||
]) => { | ||
return symbol === chain.nativeCurrency.symbol; | ||
}); | ||
const tokenSlip44 = registeredCoinTypes.find(([_coinType, _derivationPathComponent, symbol, _name]) => { | ||
return symbol === chain.nativeCurrency.symbol | ||
}) | ||
if (tokenSlip44) { | ||
chainRegistry.set(chain.id, { | ||
nativeSlip44: tokenSlip44[0], | ||
}); | ||
nativeSlip44: tokenSlip44[0] | ||
}) | ||
} else { | ||
console.error(`Slip44 not found for native token: ${JSON.stringify({ | ||
symbol: chain.nativeCurrency.symbol, | ||
chainId: chain.id, | ||
name: chain.name | ||
}, null, 2)}`); | ||
count++; | ||
console.error( | ||
`Slip44 not found for native token: ${JSON.stringify( | ||
{ | ||
symbol: chain.nativeCurrency.symbol, | ||
chainId: chain.id, | ||
name: chain.name | ||
}, | ||
null, | ||
2 | ||
)}` | ||
) | ||
count++ | ||
} | ||
}); | ||
}) | ||
|
||
console.log(`Slip44 not found for ${count} native tokens`); | ||
return chainRegistry; | ||
console.log(`Slip44 not found for ${count} native tokens`) | ||
return chainRegistry | ||
} | ||
|
||
const main = () => { | ||
const fileName = 'chain-registry.json'; | ||
const relativePath = '../resource'; | ||
const filePath = path.resolve(__dirname, relativePath, fileName); | ||
const fileName = 'chain-registry.json' | ||
const relativePath = '../resource' | ||
const filePath = path.resolve(__dirname, relativePath, fileName) | ||
|
||
const registry = buildNativeSlip44(); | ||
const obj = Object.fromEntries(registry); | ||
fs.writeFileSync(filePath, JSON.stringify(obj, null, 2), 'utf8'); | ||
console.log(`JSON written to ${filePath}`); | ||
}; | ||
const registry = buildNativeSlip44() | ||
const obj = Object.fromEntries(registry) | ||
fs.writeFileSync(filePath, JSON.stringify(obj, null, 2), 'utf8') | ||
console.log(`JSON written to ${filePath}`) | ||
} | ||
|
||
main(); | ||
main() |
Oops, something went wrong.