Skip to content

Commit

Permalink
streamlined json inputs for registries
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger committed Aug 20, 2024
1 parent 41b110a commit 3e2cf5a
Show file tree
Hide file tree
Showing 14 changed files with 638 additions and 638 deletions.
2 changes: 1 addition & 1 deletion apps/armory/src/shared/core/resource/chain-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,4 @@
"2713017997578000": {
"nativeSlip44": 60
}
}
}
77 changes: 39 additions & 38 deletions apps/armory/src/shared/core/script/build-chain-registry.ts
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()
Loading

0 comments on commit 3e2cf5a

Please sign in to comment.