Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new chains #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chain>`
- test the api is working: `LOG_LEVEL=trace yarn --silent ts-node ./src/script/inspect/api.ts -c <chain> -h 0 > api.log`
- test we can get a contract balance: `LOG_LEVEL=trace yarn ts-node ./src/script/inspect/balance.ts -c <chain> -a <some address> > balance.log`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 6 additions & 0 deletions src/lib/addressbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -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[];
46 changes: 46 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,22 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
},
},
},
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',
Expand Down Expand Up @@ -567,6 +583,22 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
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',
Expand Down Expand Up @@ -729,6 +761,13 @@ export const EXPLORER_CONFIG: Record<Chain, ExplorerConfig> = {
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}',
Expand Down Expand Up @@ -769,6 +808,13 @@ export const EXPLORER_CONFIG: Record<Chain, ExplorerConfig> = {
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}',
Expand Down
7 changes: 6 additions & 1 deletion src/lib/rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +21,9 @@ import {
metis,
optimism,
polygonZkEvm,
gnosis,
linea,
scroll,
zkSync,
} from 'viem/chains';
import { addressBook } from 'blockchain-addressbook';
Expand Down Expand Up @@ -112,7 +115,9 @@ const VIEM_CHAINS: Record<Chain, ViemChain | null> = {
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),
Expand Down
3 changes: 3 additions & 0 deletions src/script/inspect/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/script/inspect/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 10 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2405,6 +2398,11 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==

[email protected]:
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"
Expand Down Expand Up @@ -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==

[email protected]:
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"
Expand Down Expand Up @@ -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:
Expand Down