diff --git a/README.md b/README.md index 49a3909..4db44a3 100644 --- a/README.md +++ b/README.md @@ -111,10 +111,11 @@ In case you want to contribute, please follow next steps: - update the addressbook version: `npx ncu --upgrade blockchain-addressbook` - install the new addressbook: `yarn` -- apply migrations (only needed locally, migrations are applied on deploy): `yarn db:migrate` +- Fix TS errors `yarn test:ts` + - If needed update `viem/chains` with the new chain `npx ncu --upgrade viem` and `yarn` - create an explorer api key (important to verify the lens contract later on) - add the rpc url, explorer url and api key in `.env` -- Fix TS errors `yarn test:ts` +- apply migrations (only needed locally, migrations are applied on deploy): `yarn db:migrate` - inspect the final chain config: `LOG_LEVEL=error yarn --silent ts-node ./src/script/inspect/config.ts -c ` - test the api is working: `LOG_LEVEL=trace yarn --silent ts-node ./src/script/inspect/api.ts -c -h 0 > api.log` - test we can get a contract balance: `LOG_LEVEL=trace yarn ts-node ./src/script/inspect/balance.ts -c -a > balance.log` diff --git a/package.json b/package.json index 4552342..8ff1865 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "pg-format": "^1.0.4", "pino": "^8.15.1", "table": "^6.8.1", - "viem": "^1.10.12", + "viem": "^1.18.1", "yaml": "^2.3.2", "yargs": "^17.7.2" }, diff --git a/src/lib/addressbook.ts b/src/lib/addressbook.ts index b28da6c..9bedf80 100644 --- a/src/lib/addressbook.ts +++ b/src/lib/addressbook.ts @@ -3,16 +3,22 @@ import { Chain } from './chain'; import { Hex } from 'viem'; export function getChainWNativeTokenSymbol(chain: Chain): string { + if (chain === 'linea') return 'ETH'; + if (chain === 'scroll') return 'ETH'; const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.symbol; } export function getChainWNativeTokenAddress(chain: Chain): Hex { + if (chain === 'linea') return '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f'; + if (chain === 'scroll') return '0x5300000000000000000000000000000000000004'; const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.address as Hex; } export function getNetworkId(chain: Chain): number { + if (chain === 'linea') return 59144; + if (chain === 'scroll') return 534352; const tokens = addressbook.addressBook[chain].tokens; return tokens.WNATIVE.chainId; } diff --git a/src/lib/chain.ts b/src/lib/chain.ts index 3410490..126032a 100644 --- a/src/lib/chain.ts +++ b/src/lib/chain.ts @@ -1,5 +1,5 @@ import { addressBook } from 'blockchain-addressbook'; -export type Chain = keyof typeof addressBook; +export type Chain = keyof typeof addressBook | 'linea' | 'scroll'; -export const allChainIds: Chain[] = Object.keys(addressBook) as Chain[]; +export const allChainIds: Chain[] = Object.keys(addressBook).concat(['linea', 'scroll']) as Chain[]; diff --git a/src/lib/config.ts b/src/lib/config.ts index 38ec6d1..a9ac9c0 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -449,6 +449,22 @@ export const RPC_CONFIG: Record = { }, }, }, + linea: { + ...defaultConfig, + url: RPC_FORCE_URL || process.env.LINEA_RPC_URL || 'https://rpc.linea.build', + harvest: { + ...defaultHarvestConfig, + profitabilityCheck: { + ...defaultHarvestConfig.profitabilityCheck, + enabled: true, + }, + }, + unwrap: { + ...defaultUnwrapConfig, + minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.5), + maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.5), + }, + }, metis: { ...defaultConfig, url: RPC_FORCE_URL || process.env.METIS_RPC_URL || 'https://andromeda.metis.io/?owner=1088', @@ -567,6 +583,22 @@ export const RPC_CONFIG: Record = { maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 5.0), }, }, + scroll: { + ...defaultConfig, + url: RPC_FORCE_URL || process.env.SCROLL_RPC_URL || 'https://rpc.scroll.io', + harvest: { + ...defaultHarvestConfig, + profitabilityCheck: { + ...defaultHarvestConfig.profitabilityCheck, + enabled: true, + }, + }, + unwrap: { + ...defaultUnwrapConfig, + minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.5), + maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.5), + }, + }, zkevm: { ...defaultConfig, url: RPC_FORCE_URL || process.env.ZKEVM_RPC_URL || 'https://rpc.ankr.com/polygon_zkevm', @@ -729,6 +761,13 @@ export const EXPLORER_CONFIG: Record = { apiUrl: process.env.KAVA_EXPLORER_API_URL || 'https://kavascan.com/api?', type: 'blockscout', }, + linea: { + addressLinkTemplate: 'https://lineascan.build/address/${address}', + transactionLinkTemplate: 'https://lineascan.build/tx/${hash}', + apiUrl: process.env.LINEA_EXPLORER_API_URL || 'https://api.lineascan.build/api', + apiKey: process.env.LINEA_EXPLORER_API_KEY || '', + type: 'etherscan', + }, metis: { addressLinkTemplate: 'https://andromeda-explorer.metis.io/address/${address}', transactionLinkTemplate: 'https://andromeda-explorer.metis.io/tx/${hash}', @@ -769,6 +808,13 @@ export const EXPLORER_CONFIG: Record = { apiKey: process.env.POLYGON_EXPLORER_API_KEY || '', type: 'etherscan', }, + scroll: { + addressLinkTemplate: 'https://scrollscan.com/address/${address}', + transactionLinkTemplate: 'https://scrollscan.com/tx/${hash}', + apiUrl: process.env.SCROLL_EXPLORER_API_URL || 'https://api.scrollscan.com/api', + apiKey: process.env.SCROLL_EXPLORER_API_KEY || '', + type: 'etherscan', + }, zkevm: { addressLinkTemplate: 'https://zkevm.polygonscan.com/address/${address}', transactionLinkTemplate: 'https://zkevm.polygonscan.com/tx/${hash}', diff --git a/src/lib/rpc-client.ts b/src/lib/rpc-client.ts index 4a49713..2bf2944 100644 --- a/src/lib/rpc-client.ts +++ b/src/lib/rpc-client.ts @@ -2,8 +2,8 @@ import { createPublicClient, createWalletClient } from 'viem'; import { type Chain } from './chain'; import { privateKeyToAccount } from 'viem/accounts'; import { RPC_CONFIG } from './config'; -import { gnosis, type Chain as ViemChain } from 'viem/chains'; import { + type Chain as ViemChain, arbitrum, aurora, avalanche, @@ -21,6 +21,9 @@ import { metis, optimism, polygonZkEvm, + gnosis, + linea, + scroll, zkSync, } from 'viem/chains'; import { addressBook } from 'blockchain-addressbook'; @@ -112,7 +115,9 @@ const VIEM_CHAINS: Record = { fuse: applyConfig('fuse', fuse), gnosis: applyConfig('gnosis', gnosis), kava: applyConfig('kava', kava), + linea: applyConfig('linea', linea), polygon: applyConfig('polygon', polygon), + scroll: applyConfig('scroll', scroll), moonbeam: applyConfig('moonbeam', moonbeam), moonriver: applyConfig('moonriver', moonriver), metis: applyConfig('metis', metis), diff --git a/src/script/inspect/api.ts b/src/script/inspect/api.ts index c3d694b..4ab9465 100644 --- a/src/script/inspect/api.ts +++ b/src/script/inspect/api.ts @@ -40,6 +40,9 @@ async function main() { for (const chain of options.chains) { console.log(chain); + if (!vaults[chain]) { + continue; + } for (const vault of vaults[chain]) { if (vault.eol) { continue; diff --git a/src/script/inspect/balance.ts b/src/script/inspect/balance.ts index 2979501..e1e0b78 100644 --- a/src/script/inspect/balance.ts +++ b/src/script/inspect/balance.ts @@ -6,6 +6,7 @@ import { rootLogger } from '../../util/logger'; import { Hex } from 'viem'; import { fetchCollectorBalance } from '../../lib/collector-balance'; import { getChainWNativeTokenAddress } from '../../lib/addressbook'; +import { getWalletAccount } from '../../lib/rpc-client'; const logger = rootLogger.child({ module: 'inspect', component: 'balance' }); type CmdOptions = { @@ -44,6 +45,9 @@ async function main() { }; logger.trace({ msg: 'running with options', data: options }); + const walletAccount = getWalletAccount({ chain: options.chain }); + // override the wallet account with the address provided + walletAccount.address = options.collectorAddress; const res = await Promise.allSettled([fetchCollectorBalance({ chain: options.chain })]); console.dir( diff --git a/yarn.lock b/yarn.lock index 25c87ce..2b406ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -953,13 +953,6 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c" integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw== -"@types/ws@^8.5.5": - version "8.5.5" - resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb" - integrity sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg== - dependencies: - "@types/node" "*" - "@types/yargs-parser@*": version "21.0.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b" @@ -2405,6 +2398,11 @@ isexe@^2.0.0: resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== +isows@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74" + integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg== + istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz#189e7909d0a39fa5a3dfad5b03f71947770191d3" @@ -4671,11 +4669,6 @@ untildify@^4.0.0: resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b" integrity sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw== -unws@0.2.4: - version "0.2.4" - resolved "https://registry.yarnpkg.com/unws/-/unws-0.2.4.tgz#cb6f27a98a7fab4bf1c2f842648f9a2fc8be80f2" - integrity sha512-/N1ajiqrSp0A/26/LBg7r10fOcPtGXCqJRJ61sijUFoGZMr6ESWGYn7i0cwr7fR7eEECY5HsitqtjGHDZLAu2w== - update-browserslist-db@^1.0.11: version "1.0.11" resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.11.tgz#9a2a641ad2907ae7b3616506f4b977851db5b940" @@ -4745,19 +4738,18 @@ validate-npm-package-name@^5.0.0: dependencies: builtins "^5.0.0" -viem@^1.10.12: - version "1.10.12" - resolved "https://registry.yarnpkg.com/viem/-/viem-1.10.12.tgz#aefbd10acab48316290f6223d19defc4f03afa21" - integrity sha512-Q6v6rKxRiswAcLbHMaqmpEUKtgANjzBNEeco04WVX/yxFihDafLcuRmz17AtgvgbN+ROclZcbY3lsKOiSABUJg== +viem@^1.18.1: + version "1.18.1" + resolved "https://registry.yarnpkg.com/viem/-/viem-1.18.1.tgz#5a91170f539b896b0b4f4f1f34e06fc20256be35" + integrity sha512-dkZG1jI8iL7G0+KZ8ZKHCXbzZxzu8Iib7OLCxkdaqdrlNrWTEMIZSp/2AHpbjpPeAg3VFD1CUayKPTJv2ZMXCg== dependencies: "@adraffy/ens-normalize" "1.9.4" "@noble/curves" "1.2.0" "@noble/hashes" "1.3.2" "@scure/bip32" "1.3.2" "@scure/bip39" "1.2.1" - "@types/ws" "^8.5.5" abitype "0.9.8" - unws "0.2.4" + isows "1.0.3" ws "8.13.0" walker@^1.0.8: