Skip to content

Commit

Permalink
fix: make ci work on testnets (#681)
Browse files Browse the repository at this point in the history
* fix: make ci work on testnets

* fix: cleanup deps

* fix: handle throwing on rpc-env-side

* fix: tksync casing
  • Loading branch information
sakulstra authored Nov 5, 2024
1 parent de1275e commit 1611ebd
Show file tree
Hide file tree
Showing 48 changed files with 102 additions and 291 deletions.
174 changes: 36 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
"homepage": "https://github.com/bgd-labs/aave-address-book#readme",
"devDependencies": {
"@bgd-labs/js-utils": "1.4.2",
"@bgd-labs/rpc-env": "^1.0.3",
"@bgd-labs/react-web3-icons": "^1.5.3",
"@types/node": "^22.4.1",
"@uniswap/token-lists": "^1.0.0-beta.33",
Expand All @@ -94,4 +94,4 @@
"viem": "^2.21.19"
},
"packageManager": "^npm@10.0.0"
}
}
104 changes: 11 additions & 93 deletions scripts/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,90 +25,11 @@ import {
zksync,
} from 'viem/chains';
import {Client} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId, getRPCUrl} from '@bgd-labs/rpc-env';

const commonConfig: HttpTransportConfig = {timeout: 30_000, batch: true};
const batchConfig = {batch: {multicall: true}};

// @notice: fetched from alchemy private trpc api
// const data = await(await fetch('https://app-api.alchemy.com/trpc/config.getNetworkConfig')).json();
// data.result.data.reduce((acc,val) => {
// acc[val.networkChainId] = val.kebabCaseId;
// return acc;
// },{})
const alchemyNetworks: Record<number, string> = {
1: 'eth-mainnet',
3: 'eth-ropsten',
4: 'eth-rinkeby',
5: 'eth-goerli',
10: 'opt-mainnet',
42: 'eth-kovan',
56: 'bnb-mainnet',
69: 'opt-kovan',
97: 'bnb-testnet',
100: 'gnosis-mainnet',
137: 'polygon-mainnet',
204: 'opbnb-mainnet',
250: 'fantom-mainnet',
252: 'frax-mainnet',
300: 'zksync-sepolia',
324: 'zksync-mainnet',
420: 'opt-goerli',
592: 'astar-mainnet',
747: 'flow-mainnet',
1088: 'metis-mainnet',
1101: 'polygonzkevm-mainnet',
1301: 'unichain-sepolia',
1442: 'polygonzkevm-testnet',
1946: 'soneium-minato',
2442: 'polygonzkevm-cardona',
2522: 'frax-sepolia',
4002: 'fantom-testnet',
5611: 'opbnb-testnet',
7000: 'zetachain-mainnet',
7001: 'zetachain-testnet',
8453: 'base-mainnet',
10200: 'gnosis-chiado',
11011: 'shape-sepolia',
42161: 'arb-mainnet',
42170: 'arbnova-mainnet',
43113: 'avax-fuji',
43114: 'avax-mainnet',
59141: 'linea-sepolia',
59144: 'linea-mainnet',
80001: 'polygon-mumbai',
80002: 'polygon-amoy',
80084: 'berachain-bartio',
81457: 'blast-mainnet',
84531: 'base-goerli',
84532: 'base-sepolia',
421611: 'arb-rinkeby',
421613: 'arb-goerli',
421614: 'arb-sepolia',
534351: 'scroll-sepolia',
534352: 'scroll-mainnet',
7777777: 'zora-mainnet',
11155111: 'eth-sepolia',
11155420: 'opt-sepolia',
168587773: 'blast-sepolia',
999999999: 'zora-sepolia',
};

const networkEnv: Record<number, string> = {
[ChainId.mainnet]: 'RPC_MAINNET',
[ChainId.optimism]: 'RPC_OPTIMISM',
[ChainId.bnb]: 'RPC_BNB',
[ChainId.gnosis]: 'RPC_GNOSIS',
[ChainId.polygon]: 'RPC_POLYGON',
[ChainId.fantom]: 'RPC_FANTOM',
[ChainId.zkSync]: 'RPC_ZKSYNC',
[ChainId.metis]: 'RPC_METIS',
[ChainId.base]: 'RPC_BASE',
[ChainId.arbitrum_one]: 'RPC_ARBITRUM',
[ChainId.avalanche]: 'RPC_AVALANCHE',
[ChainId.scroll]: 'RPC_SCROLL',
};

export const CHAIN_ID_CHAIN_MAP: Record<number, Chain> = {
[ChainId.mainnet]: mainnet,
[ChainId.sepolia]: sepolia,
Expand All @@ -119,7 +40,7 @@ export const CHAIN_ID_CHAIN_MAP: Record<number, Chain> = {
[ChainId.polygon]: polygon,
[ChainId.fantom]: fantom,
[ChainId.fantom_testnet]: fantomTestnet,
[ChainId.zkSync]: zksync,
[ChainId.zksync]: zksync,
[ChainId.metis]: metis,
[ChainId.base]: base,
[ChainId.base_sepolia]: baseSepolia,
Expand All @@ -134,24 +55,21 @@ export const CHAIN_ID_CHAIN_MAP: Record<number, Chain> = {
[ChainId.celo]: celo,
};

/**
* Selects a rpc based on a predefined priorization:
* 1. env.RPC_URL_<network>
* 2. alchemy if available
*/
function getRPCUrl(chainId: number): string | undefined {
if (process.env[networkEnv[chainId]]) return process.env[networkEnv[chainId]];
if (alchemyNetworks[chainId] && process.env.ALCHEMY_API_KEY)
return `https://${alchemyNetworks[chainId]}.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`;
}

const clientCache: Record<number, Client> = {};

export function getClient(chainId: number) {
if (!clientCache[chainId]) {
let rpcURL;
try {
rpcURL = getRPCUrl(chainId as any);
} catch (e) {
// if we cannot find an rpc in env we'll pass undefined
// which will select the most reliable public rpc
}
console.log(chainId);
clientCache[chainId] = createClient({
chain: CHAIN_ID_CHAIN_MAP[chainId],
transport: http(getRPCUrl(chainId), commonConfig),
transport: http(rpcURL, commonConfig),
...batchConfig,
});
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigArbitrum: GovernanceConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/avalanche.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigFuji: GovernanceConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GovernanceConfig} from '../types';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';

export const governanceConfigBase: GovernanceConfig = {
name: 'Base',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/bnb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GovernanceConfig} from '../types';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';

export const governanceConfigBNB: GovernanceConfig = {
name: 'BNB',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

// OUTDATED ABI
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GovernanceConfig} from '../types';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';

export const governanceConfigGnosis: GovernanceConfig = {
name: 'Gnosis',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/metis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GovernanceConfig} from '../types';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';

export const governanceConfigMetis: GovernanceConfig = {
name: 'Metis',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigOptimism: GovernanceConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigPolygon: GovernanceConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/polygonZkEvm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigPolygonZkEvm: GovernanceConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/governance/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigScroll: GovernanceConfig = {
Expand Down
4 changes: 2 additions & 2 deletions scripts/configs/governance/zksync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {GovernanceConfig} from '../types';

export const governanceConfigZkSync: GovernanceConfig = {
name: 'ZkSync',
CHAIN_ID: ChainId.zkSync,
CHAIN_ID: ChainId.zksync,
ADDRESSES: {
CROSS_CHAIN_CONTROLLER: '0x800813f4714BC7A0a95310e3fB9e4f18872CA92C',
PAYLOADS_CONTROLLER: '0x2E79349c3F5e4751E87b966812C9E65E805996F1',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const arbitrumAddresses: NetworkAddresses<{
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/avalanche.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const avalancheAddresses: NetworkAddresses = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const baseAddresses: NetworkAddresses<{
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/bnb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const bnbAddresses: NetworkAddresses = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {AddressInfo, NetworkAddresses} from '../types';

export const ethereumAddresses: NetworkAddresses<{
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/fantom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const fantomAddresses: NetworkAddresses = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const gnosisAddresses: NetworkAddresses<{wstETH_stETH_AGGREGATOR: Hex}> = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/metis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';
import {Hex} from 'viem';

Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const optimismAddresses: NetworkAddresses<{
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const polygonAddresses: NetworkAddresses<{
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/polygonZkEvm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NetworkAddresses} from '../types';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';

export const polygonZkEvmAddresses: NetworkAddresses = {
name: 'PolygonZkEvm',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/networks/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const scrollAddresses: NetworkAddresses<{
Expand Down
4 changes: 2 additions & 2 deletions scripts/configs/networks/zksync.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Hex} from 'viem';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {NetworkAddresses} from '../types';

export const zkSyncAddresses: NetworkAddresses = {
name: 'ZkSync',
chainId: ChainId.zkSync,
chainId: ChainId.zksync,
addresses: {
TRANSPARENT_PROXY_FACTORY: '0x903A3228c4C58e94787CB33EE83e087bCFcF0a91',
PROXY_ADMIN: '0x158d6c497317367CEa3CBAb0BD84E6de236F060D',
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/arbitrum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const arbitrumProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/avalanche.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const fujiProtoV2: PoolConfig = {
Expand Down
4 changes: 2 additions & 2 deletions scripts/configs/pools/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const baseProtoV3: PoolConfig = {
Expand Down Expand Up @@ -59,5 +59,5 @@ export const baseSepoliaLidoProtoV3: PoolConfig = {
UI_POOL_DATA_PROVIDER: '0x912D4A80f8cA3959eB49Ce38f060c46323D1e3A4',
WALLET_BALANCE_PROVIDER: '0x2a5208950631917efE7EbE969eC1be68EE46AB16',
WETH_GATEWAY: '0x63bBa35193cB5E061E8F0318F8A1788EA34E5198',
}
},
};
2 changes: 1 addition & 1 deletion scripts/configs/pools/bnb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const bnbProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const sepoliaProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/fantom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const fantomTestnetProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/gnosis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const gnosisProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/harmony.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const harmonyProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/metis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const metisProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/optimism.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const optimismProtoV3: PoolConfig = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/configs/pools/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {PoolConfig} from '../types';

export const polygonProtoV2: PoolConfig = {
Expand Down
Loading

0 comments on commit 1611ebd

Please sign in to comment.