Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/chain-type
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkenj1 committed Aug 8, 2024
2 parents 0bc2d04 + fd88b1f commit ed9bb46
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 452 deletions.
3 changes: 0 additions & 3 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ runs:
with:
node-version: 20
cache: "pnpm"

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
3 changes: 0 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@ jobs:

- name: Run Linter
run: pnpm lint

- name: Run Contracts Linter
run: pnpm lint:contracts:check
17 changes: 0 additions & 17 deletions .solhint.json

This file was deleted.

21 changes: 0 additions & 21 deletions .solhint.tests.json

This file was deleted.

19 changes: 0 additions & 19 deletions contracts/foundry.toml

This file was deleted.

4 changes: 0 additions & 4 deletions contracts/remappings.txt

This file was deleted.

50 changes: 0 additions & 50 deletions contracts/src/contracts/TokenBalances.sol

This file was deleted.

9 changes: 0 additions & 9 deletions contracts/src/interfaces/IERC20.sol

This file was deleted.

100 changes: 0 additions & 100 deletions contracts/test/TokenBalances.t.sol

This file was deleted.

1 change: 0 additions & 1 deletion libs/metrics/src/l1/abis/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./bridgeHub.abi";
export * from "./diamondProxy.abi";
export * from "./sharedBridge.abi";
export * from "./tokenBalances.abi";
14 changes: 0 additions & 14 deletions libs/metrics/src/l1/abis/tokenBalances.abi.ts

This file was deleted.

2 changes: 0 additions & 2 deletions libs/metrics/src/l1/bytecode/index.ts

This file was deleted.

41 changes: 17 additions & 24 deletions libs/metrics/src/l1/l1MetricsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { Inject, Injectable, LoggerService } from "@nestjs/common";
import { WINSTON_MODULE_NEST_PROVIDER } from "nest-winston";
import {
Address,
ContractConstructorArgs,
encodeFunctionData,
erc20Abi,
formatUnits,
parseAbiParameters,
parseEther,
parseUnits,
zeroAddress,
Expand All @@ -19,13 +17,7 @@ import {
InvalidChainType,
L1MetricsServiceException,
} from "@zkchainhub/metrics/exceptions";
import {
bridgeHubAbi,
diamondProxyAbi,
sharedBridgeAbi,
tokenBalancesAbi,
} from "@zkchainhub/metrics/l1/abis";
import { tokenBalancesBytecode } from "@zkchainhub/metrics/l1/bytecode";
import { bridgeHubAbi, diamondProxyAbi, sharedBridgeAbi } from "@zkchainhub/metrics/l1/abis";
import { AssetTvl, GasInfo } from "@zkchainhub/metrics/types";
import { IPricingService, PRICING_PROVIDER } from "@zkchainhub/pricing";
import { EvmProviderService } from "@zkchainhub/providers";
Expand Down Expand Up @@ -136,29 +128,30 @@ export class L1MetricsService {

/**
* Fetches the token balances for the given addresses and ETH balance.
* Note: The last balance in the returned array is the ETH balance, so the fetch length should be addresses.length + 1.
* @param addresses - An array of addresses for which to fetch the token balances.
* @returns A promise that resolves to an object containing the ETH balance and an array of address balances.
*/
private async fetchTokenBalances(
addresses: Address[],
): Promise<{ ethBalance: bigint; addressesBalance: bigint[] }> {
const returnAbiParams = parseAbiParameters("uint256[]");
const args: ContractConstructorArgs<typeof tokenBalancesAbi> = [
L1_CONTRACTS.SHARED_BRIDGE,
addresses,
];

const [balances] = await this.evmProviderService.batchRequest(
tokenBalancesAbi,
tokenBalancesBytecode,
args,
returnAbiParams,
);
const balances = await this.evmProviderService.multicall({
contracts: [
...addresses.map((tokenAddress) => {
return {
address: tokenAddress,
abi: erc20Abi,
functionName: "balanceOf",
args: [this.sharedBridge.address],
} as const;
}),
],
allowFailure: false,
});
const ethBalance = await this.evmProviderService.getBalance(this.sharedBridge.address);

assert(balances.length === addresses.length + 1, "Invalid balances length");
assert(balances.length === addresses.length, "Invalid balances length");

return { ethBalance: balances[addresses.length]!, addressesBalance: balances.slice(0, -1) };
return { ethBalance: ethBalance, addressesBalance: balances };
}

/**
Expand Down
Loading

0 comments on commit ed9bb46

Please sign in to comment.