diff --git a/packages/api/.env.example b/packages/api/.env.example index d2d363fe8d..89dfe17683 100644 --- a/packages/api/.env.example +++ b/packages/api/.env.example @@ -15,3 +15,10 @@ DISABLE_EXTERNAL_API=false DATABASE_STATEMENT_TIMEOUT_MS=90000 CONTRACT_VERIFICATION_API_URL=http://127.0.0.1:3070 NETWORK_NAME=testnet-sepolia +BASE_TOKEN_SYMBOL=wETH +BASE_TOKEN_DECIMALS=18 +BASE_TOKEN_L1_ADDRESS=0x8E9C82509488eD471A83824d20Dd474b8F534a0b +BASE_TOKEN_ICON_URL=https://assets.coingecko.com/coins/images/279/large/ethereum.png?1698873266 +BASE_TOKEN_NAME=Ether +BASE_TOKEN_LIQUIDITY=220000000000 +BASE_TOKEN_USDPRICE=1800 diff --git a/packages/api/src/api/account/account.controller.spec.ts b/packages/api/src/api/account/account.controller.spec.ts index f5b2f14c6e..8614220aa1 100644 --- a/packages/api/src/api/account/account.controller.spec.ts +++ b/packages/api/src/api/account/account.controller.spec.ts @@ -1,7 +1,7 @@ import { Test } from "@nestjs/testing"; import { mock } from "jest-mock-extended"; import { BadRequestException, Logger } from "@nestjs/common"; -import { L2_ETH_TOKEN_ADDRESS } from "../../common/constants"; +import { BASE_TOKEN_L2_ADDRESS } from "../../common/constants"; import { BlockService } from "../../block/block.service"; import { BlockDetails } from "../../block/blockDetails.entity"; import { TransactionService } from "../../transaction/transaction.service"; @@ -557,7 +557,7 @@ describe("AccountController", () => { describe("getAccountEtherBalance", () => { it("calls balanceService.getBalance and returns account ether balance", async () => { const response = await controller.getAccountEtherBalance(address); - expect(balanceServiceMock.getBalance).toBeCalledWith(address, L2_ETH_TOKEN_ADDRESS); + expect(balanceServiceMock.getBalance).toBeCalledWith(address, BASE_TOKEN_L2_ADDRESS); expect(response).toEqual({ status: ResponseStatus.OK, message: ResponseMessage.OK, @@ -588,7 +588,7 @@ describe("AccountController", () => { it("calls balanceService.getBalancesByAddresses and returns accounts ether balances", async () => { const response = await controller.getAccountsEtherBalances([address, "address2"]); - expect(balanceServiceMock.getBalancesByAddresses).toBeCalledWith([address, "address2"], L2_ETH_TOKEN_ADDRESS); + expect(balanceServiceMock.getBalancesByAddresses).toBeCalledWith([address, "address2"], BASE_TOKEN_L2_ADDRESS); expect(response).toEqual({ status: ResponseStatus.OK, message: ResponseMessage.OK, diff --git a/packages/api/src/api/account/account.controller.ts b/packages/api/src/api/account/account.controller.ts index 5299fa44b6..3a7608faed 100644 --- a/packages/api/src/api/account/account.controller.ts +++ b/packages/api/src/api/account/account.controller.ts @@ -1,6 +1,6 @@ import { Controller, Get, Query, Logger, UseFilters, ParseArrayPipe, BadRequestException } from "@nestjs/common"; import { ApiTags, ApiExcludeController } from "@nestjs/swagger"; -import { L2_ETH_TOKEN_ADDRESS } from "../../common/constants"; +import { BASE_TOKEN_L2_ADDRESS } from "../../common/constants"; import { TokenType } from "../../token/token.entity"; import { dateToTimestamp } from "../../common/utils"; import { BlockService } from "../../block/block.service"; @@ -176,7 +176,7 @@ export class AccountController { public async getAccountEtherBalance( @Query("address", new ParseAddressPipe()) address: string ): Promise { - const balance = await this.balanceService.getBalance(address, L2_ETH_TOKEN_ADDRESS); + const balance = await this.balanceService.getBalance(address, BASE_TOKEN_L2_ADDRESS); return { status: ResponseStatus.OK, message: ResponseMessage.OK, @@ -201,7 +201,7 @@ export class AccountController { if (uniqueAddresses.length > 20) { throw new BadRequestException("Maximum 20 addresses per request"); } - const balances = await this.balanceService.getBalancesByAddresses(addresses, L2_ETH_TOKEN_ADDRESS); + const balances = await this.balanceService.getBalancesByAddresses(addresses, BASE_TOKEN_L2_ADDRESS); const result = addresses.map((address) => ({ account: address, balance: balances.find((balance) => balance.address.toLowerCase() === address.toLowerCase())?.balance || "0", diff --git a/packages/api/src/api/mappers/internalTransactionMapper.spec.ts b/packages/api/src/api/mappers/internalTransactionMapper.spec.ts index ea81b68cfd..fc21c02074 100644 --- a/packages/api/src/api/mappers/internalTransactionMapper.spec.ts +++ b/packages/api/src/api/mappers/internalTransactionMapper.spec.ts @@ -1,6 +1,6 @@ import { Transfer } from "../../transfer/transfer.entity"; import { TransactionStatus } from "../../transaction/entities/transaction.entity"; -import { L2_ETH_TOKEN_ADDRESS } from "../../common/constants"; +import { BASE_TOKEN_L2_ADDRESS } from "../../common/constants"; import { mapInternalTransactionListItem } from "./internalTransactionMapper"; describe("internalTransactionMapper", () => { @@ -11,7 +11,7 @@ describe("internalTransactionMapper", () => { from: "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe35C", to: "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe35D", amount: "1000000", - tokenAddress: L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_L2_ADDRESS, transaction: { blockNumber: 20, receivedAt: new Date("2023-01-01"), diff --git a/packages/api/src/api/stats/stats.controller.spec.ts b/packages/api/src/api/stats/stats.controller.spec.ts index f9851dde0b..18e88a9815 100644 --- a/packages/api/src/api/stats/stats.controller.spec.ts +++ b/packages/api/src/api/stats/stats.controller.spec.ts @@ -2,8 +2,9 @@ import { Test } from "@nestjs/testing"; import { mock } from "jest-mock-extended"; import { Logger } from "@nestjs/common"; import { TokenService } from "../../token/token.service"; -import { Token, ETH_TOKEN } from "../../token/token.entity"; +import { Token } from "../../token/token.entity"; import { StatsController } from "./stats.controller"; +import { baseTokenData } from "../../config"; describe("StatsController", () => { let controller: StatsController; @@ -31,7 +32,7 @@ describe("StatsController", () => { describe("ethPrice", () => { it("returns ok response and ETH price when ETH token is found", async () => { jest.spyOn(tokenServiceMock, "findOne").mockResolvedValueOnce({ - usdPrice: ETH_TOKEN.usdPrice, + usdPrice: baseTokenData.usdPrice, offChainDataUpdatedAt: new Date("2023-03-03"), } as Token); @@ -40,7 +41,7 @@ describe("StatsController", () => { status: "1", message: "OK", result: { - ethusd: ETH_TOKEN.usdPrice.toString(), + ethusd: baseTokenData.usdPrice.toString(), ethusd_timestamp: Math.floor(new Date("2023-03-03").getTime() / 1000).toString(), }, }); diff --git a/packages/api/src/api/stats/stats.controller.ts b/packages/api/src/api/stats/stats.controller.ts index 972edb3680..04618357a5 100644 --- a/packages/api/src/api/stats/stats.controller.ts +++ b/packages/api/src/api/stats/stats.controller.ts @@ -4,8 +4,8 @@ import { ResponseStatus, ResponseMessage } from "../dtos/common/responseBase.dto import { ApiExceptionFilter } from "../exceptionFilter"; import { EthPriceResponseDto } from "../dtos/stats/ethPrice.dto"; import { TokenService } from "../../token/token.service"; -import { ETH_TOKEN } from "../../token/token.entity"; import { dateToTimestamp } from "../../common/utils"; +import { baseTokenData } from "../../config"; const entityName = "stats"; @@ -18,7 +18,10 @@ export class StatsController { @Get("/ethprice") public async ethPrice(): Promise { - const token = await this.tokenService.findOne(ETH_TOKEN.l2Address, { usdPrice: true, offChainDataUpdatedAt: true }); + const token = await this.tokenService.findOne(baseTokenData.l2Address, { + usdPrice: true, + offChainDataUpdatedAt: true, + }); return { status: token ? ResponseStatus.OK : ResponseStatus.NOTOK, message: token ? ResponseMessage.OK : ResponseMessage.NO_DATA_FOUND, diff --git a/packages/api/src/api/token/token.controller.spec.ts b/packages/api/src/api/token/token.controller.spec.ts index e3d44eee71..b1b2b38919 100644 --- a/packages/api/src/api/token/token.controller.spec.ts +++ b/packages/api/src/api/token/token.controller.spec.ts @@ -2,9 +2,10 @@ import { Test } from "@nestjs/testing"; import { mock } from "jest-mock-extended"; import { Logger } from "@nestjs/common"; import { TokenService } from "../../token/token.service"; -import { Token, ETH_TOKEN } from "../../token/token.entity"; +import { Token } from "../../token/token.entity"; import { TokenController } from "./token.controller"; - +import config from "../../config/index"; +const { baseTokenData } = config(); describe("TokenController", () => { let controller: TokenController; let tokenServiceMock: TokenService; @@ -32,22 +33,22 @@ describe("TokenController", () => { describe("tokenInfo", () => { it("returns ok response and token info when token is found", async () => { - jest.spyOn(tokenServiceMock, "findOne").mockResolvedValueOnce(ETH_TOKEN); - + const baseToken = baseTokenData as Token; + jest.spyOn(tokenServiceMock, "findOne").mockResolvedValueOnce(baseToken); const response = await controller.tokenInfo(contractAddress); expect(response).toEqual({ status: "1", message: "OK", result: [ { - contractAddress: ETH_TOKEN.l2Address, - iconURL: ETH_TOKEN.iconURL, - l1Address: ETH_TOKEN.l1Address, - liquidity: ETH_TOKEN.liquidity.toString(), - symbol: ETH_TOKEN.symbol, - tokenDecimal: ETH_TOKEN.decimals.toString(), - tokenName: ETH_TOKEN.name, - tokenPriceUSD: ETH_TOKEN.usdPrice.toString(), + contractAddress: baseToken.l2Address, + iconURL: baseToken.iconURL, + l1Address: baseToken.l1Address, + liquidity: baseToken.liquidity.toString(), + symbol: baseToken.symbol, + tokenDecimal: baseToken.decimals.toString(), + tokenName: baseToken.name, + tokenPriceUSD: baseToken.usdPrice.toString(), }, ], }); diff --git a/packages/api/src/api/token/token.controller.ts b/packages/api/src/api/token/token.controller.ts index 95c559696c..caa9ce8d30 100644 --- a/packages/api/src/api/token/token.controller.ts +++ b/packages/api/src/api/token/token.controller.ts @@ -5,7 +5,6 @@ import { ResponseStatus, ResponseMessage } from "../dtos/common/responseBase.dto import { ApiExceptionFilter } from "../exceptionFilter"; import { TokenInfoResponseDto } from "../dtos/token/tokenInfo.dto"; import { TokenService } from "../../token/token.service"; - const entityName = "token"; @ApiExcludeController() diff --git a/packages/api/src/balance/balance.entity.ts b/packages/api/src/balance/balance.entity.ts index 1d0dc898e5..34e3f7544c 100644 --- a/packages/api/src/balance/balance.entity.ts +++ b/packages/api/src/balance/balance.entity.ts @@ -1,9 +1,9 @@ import { Entity, Column, PrimaryColumn, Index, ManyToOne, JoinColumn, AfterLoad } from "typeorm"; import { BaseEntity } from "../common/entities/base.entity"; -import { Token, ETH_TOKEN } from "../token/token.entity"; +import { Token } from "../token/token.entity"; import { normalizeAddressTransformer } from "../common/transformers/normalizeAddress.transformer"; import { bigIntNumberTransformer } from "../common/transformers/bigIntNumber.transformer"; - +import { baseTokenData } from "../config/index"; @Entity({ name: "balances" }) export class Balance extends BaseEntity { @PrimaryColumn({ type: "bytea", transformer: normalizeAddressTransformer }) @@ -24,9 +24,12 @@ export class Balance extends BaseEntity { public readonly balance: string; @AfterLoad() - populateEthToken() { - if (this.tokenAddress === ETH_TOKEN.l2Address && !this.token) { - this.token = ETH_TOKEN; + populateBaseToken() { + if ( + !this.token && + (this.tokenAddress === undefined || this.tokenAddress.toLowerCase() === baseTokenData.l2Address.toLowerCase()) + ) { + this.token = baseTokenData as Token; } } } diff --git a/packages/api/src/common/constants.ts b/packages/api/src/common/constants.ts index 89ed3cf93b..99cc0c6649 100644 --- a/packages/api/src/common/constants.ts +++ b/packages/api/src/common/constants.ts @@ -1 +1 @@ -export const L2_ETH_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800a"; +export const BASE_TOKEN_L2_ADDRESS = "0x000000000000000000000000000000000000800A"; diff --git a/packages/api/src/config/index.spec.ts b/packages/api/src/config/index.spec.ts index 6803237f97..22bfe07416 100644 --- a/packages/api/src/config/index.spec.ts +++ b/packages/api/src/config/index.spec.ts @@ -1,5 +1,4 @@ import config from "../config"; - jest.mock("./featureFlags", () => ({ feature1Enabled: true, feature2Enabled: false, @@ -20,6 +19,71 @@ describe("config", () => { it("sets default values", () => { expect(config()).toEqual({ + baseTokenData: { + l2Address: "0x000000000000000000000000000000000000800A", + l1Address: "0x0000000000000000000000000000000000000001", + symbol: "ETH", + name: "Ether", + decimals: 18, + // Fallback data in case ETH token is not in the DB + iconURL: "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1698873266", + liquidity: 220000000000, + usdPrice: 1800, + }, + NODE_ENV: "test", + port: 3020, + metrics: { + port: 3005, + collectDbConnectionPoolMetricsInterval: 10000, + }, + typeORM: { + type: "postgres", + url: "postgres://postgres:postgres@127.0.0.1:5432/block-explorer", + poolSize: 300, + extra: { + idleTimeoutMillis: 60000, + statement_timeout: 90000, + }, + synchronize: true, + logging: false, + autoLoadEntities: true, + retryAttempts: 10, + retryDelay: 3000, + applicationName: "block-explorer-api", + }, + contractVerificationApiUrl: "http://127.0.0.1:3070", + featureFlags: { + feature1Enabled: true, + feature2Enabled: false, + }, + gracefulShutdownTimeoutMs: 0, + }); + }); + + it("sets default values with base ERC20", () => { + process.env = { + BASE_TOKEN_SYMBOL: "MTTL", + BASE_TOKEN_DECIMALS: "18", + BASE_TOKEN_L1_ADDRESS: "0xSomeAddress", + BASE_TOKEN_ICON_URL: "https://matter-labs.io", + BASE_TOKEN_NAME: "MatterLabs", + BASE_TOKEN_LIQUIDITY: "999999999999", + BASE_TOKEN_USDPRICE: "19", + NODE_ENV: "test", + }; + + expect(config()).toEqual({ + baseTokenData: { + l2Address: "0x000000000000000000000000000000000000800A", + l1Address: "0xSomeAddress", + symbol: "MTTL", + name: "MatterLabs", + decimals: 18, + // Fallback data in case ETH token is not in the DB + iconURL: "https://matter-labs.io", + liquidity: 999999999999, + usdPrice: 19, + }, NODE_ENV: "test", port: 3020, metrics: { @@ -28,7 +92,7 @@ describe("config", () => { }, typeORM: { type: "postgres", - url: "postgres://postgres:postgres@localhost:5432/block-explorer", + url: "postgres://postgres:postgres@127.0.0.1:5432/block-explorer", poolSize: 300, extra: { idleTimeoutMillis: 60000, diff --git a/packages/api/src/config/index.ts b/packages/api/src/config/index.ts index 840259b1fa..41077cd39b 100644 --- a/packages/api/src/config/index.ts +++ b/packages/api/src/config/index.ts @@ -1,5 +1,55 @@ import { TypeOrmModuleOptions } from "@nestjs/typeorm"; import * as featureFlags from "./featureFlags"; +import { BASE_TOKEN_L2_ADDRESS } from "../common/constants"; +type BaseToken = { + symbol: string; + decimals: number; + l1Address: string; + l2Address: string; + liquidity: number; + iconURL: string; + name: string; + usdPrice: number; +}; +const defaultEthBaseToken: BaseToken = { + l2Address: BASE_TOKEN_L2_ADDRESS, + l1Address: "0x0000000000000000000000000000000000000001", + symbol: "ETH", + name: "Ether", + decimals: 18, + // Fallback data in case ETH token is not in the DB + iconURL: "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1698873266", + liquidity: 220000000000, + usdPrice: 1800, +}; +const baseTokenFromEnv = (): BaseToken => { + const { + BASE_TOKEN_SYMBOL, + BASE_TOKEN_DECIMALS, + BASE_TOKEN_L1_ADDRESS, + BASE_TOKEN_ICON_URL, + BASE_TOKEN_NAME, + BASE_TOKEN_LIQUIDITY, + BASE_TOKEN_USDPRICE, + } = process.env; + const decimals = parseFloat(BASE_TOKEN_DECIMALS); + const liquidity = parseFloat(BASE_TOKEN_LIQUIDITY); + const usdPrice = parseFloat(BASE_TOKEN_USDPRICE); + if (BASE_TOKEN_L1_ADDRESS && BASE_TOKEN_SYMBOL) { + return { + symbol: BASE_TOKEN_SYMBOL, + decimals, + l1Address: BASE_TOKEN_L1_ADDRESS, + l2Address: BASE_TOKEN_L2_ADDRESS, + liquidity, + iconURL: BASE_TOKEN_ICON_URL, + usdPrice, + name: BASE_TOKEN_NAME, + }; + } else { + return defaultEthBaseToken; + } +}; export default () => { const { @@ -15,6 +65,8 @@ export default () => { GRACEFUL_SHUTDOWN_TIMEOUT_MS, } = process.env; + const baseTokenData: BaseToken = baseTokenFromEnv(); + const MAX_NUMBER_OF_REPLICA = 100; const getDatabaseReplicaSet = () => { @@ -32,7 +84,7 @@ export default () => { }; const getTypeOrmModuleOptions = (): TypeOrmModuleOptions => { - const master = { url: DATABASE_URL || "postgres://postgres:postgres@localhost:5432/block-explorer" }; + const master = { url: DATABASE_URL || "postgres://postgres:postgres@127.0.0.1:5432/block-explorer" }; const replicaSet = getDatabaseReplicaSet(); return { @@ -75,6 +127,9 @@ export default () => { typeORM: getTypeOrmModuleOptions(), contractVerificationApiUrl: CONTRACT_VERIFICATION_API_URL || "http://127.0.0.1:3070", featureFlags, + baseTokenData, gracefulShutdownTimeoutMs: parseInt(GRACEFUL_SHUTDOWN_TIMEOUT_MS, 10) || 0, }; }; + +export const baseTokenData = baseTokenFromEnv(); diff --git a/packages/api/src/token/token.entity.ts b/packages/api/src/token/token.entity.ts index 234bc60315..f8c563bbe5 100644 --- a/packages/api/src/token/token.entity.ts +++ b/packages/api/src/token/token.entity.ts @@ -1,25 +1,12 @@ import { Entity, Column, PrimaryColumn, Index } from "typeorm"; import { BaseEntity } from "../common/entities/base.entity"; import { normalizeAddressTransformer } from "../common/transformers/normalizeAddress.transformer"; - export enum TokenType { - ETH = "ETH", + BaseToken = "BASETOKEN", ERC20 = "ERC20", ERC721 = "ERC721", } -export const ETH_TOKEN: Token = { - l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", - symbol: "ETH", - name: "Ether", - decimals: 18, - // Fallback data in case ETH token is not in the DB - iconURL: "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1698873266", - liquidity: 220000000000, - usdPrice: 1800, -} as Token; - @Entity({ name: "tokens" }) @Index(["liquidity", "blockNumber", "logIndex"]) export class Token extends BaseEntity { diff --git a/packages/api/src/token/token.module.ts b/packages/api/src/token/token.module.ts index 5e74dfa05e..43799ffab0 100644 --- a/packages/api/src/token/token.module.ts +++ b/packages/api/src/token/token.module.ts @@ -6,7 +6,6 @@ import { Token } from "./token.entity"; import { Block } from "../block/block.entity"; import { Transaction } from "../transaction/entities/transaction.entity"; import { TransferModule } from "../transfer/transfer.module"; - @Module({ imports: [TypeOrmModule.forFeature([Token, Block, Transaction]), TransferModule], controllers: [TokenController], diff --git a/packages/api/src/token/token.service.spec.ts b/packages/api/src/token/token.service.spec.ts index 2b61764b4f..257d724335 100644 --- a/packages/api/src/token/token.service.spec.ts +++ b/packages/api/src/token/token.service.spec.ts @@ -3,9 +3,11 @@ import { mock } from "jest-mock-extended"; import { getRepositoryToken } from "@nestjs/typeorm"; import { Repository, SelectQueryBuilder, MoreThanOrEqual } from "typeorm"; import { TokenService } from "./token.service"; -import { Token, ETH_TOKEN } from "./token.entity"; +import { Token } from "./token.entity"; import { Pagination, IPaginationMeta } from "nestjs-typeorm-paginate"; import * as utils from "../common/utils"; +import config from "../config"; +const { baseTokenData } = config(); jest.mock("../common/utils"); @@ -73,7 +75,7 @@ describe("TokenService", () => { it("returns ETH token for ETH address", async () => { const result = await service.findOne("0x000000000000000000000000000000000000800a"); - expect(result).toEqual(ETH_TOKEN); + expect(result).toEqual(baseTokenData); }); it("returns null for non ETH address", async () => { diff --git a/packages/api/src/token/token.service.ts b/packages/api/src/token/token.service.ts index 4adafbc315..559606467c 100644 --- a/packages/api/src/token/token.service.ts +++ b/packages/api/src/token/token.service.ts @@ -4,8 +4,10 @@ import { Repository, FindOptionsSelect, MoreThanOrEqual } from "typeorm"; import { Pagination } from "nestjs-typeorm-paginate"; import { IPaginationOptions } from "../common/types"; import { paginate } from "../common/utils"; -import { Token, ETH_TOKEN } from "./token.entity"; - +import { Token } from "./token.entity"; +import { BASE_TOKEN_L2_ADDRESS } from "../common/constants"; +import config from "../config"; +const { baseTokenData } = config(); export interface FilterTokensOptions { minLiquidity?: number; } @@ -24,8 +26,8 @@ export class TokenService { }, select: fields, }); - if (!token && address.toLowerCase() === ETH_TOKEN.l2Address.toLowerCase()) { - return ETH_TOKEN; + if (!token && address.toLowerCase() === BASE_TOKEN_L2_ADDRESS.toLowerCase()) { + return baseTokenData as Token; } return token; } @@ -33,7 +35,7 @@ export class TokenService { public async exists(address: string): Promise { const tokenExists = (await this.tokenRepository.findOne({ where: { l2Address: address }, select: { l2Address: true } })) != null; - if (!tokenExists && address === ETH_TOKEN.l2Address.toLowerCase()) { + if (!tokenExists && address === BASE_TOKEN_L2_ADDRESS.toLowerCase()) { return true; } return tokenExists; diff --git a/packages/api/src/transaction/transaction.controller.ts b/packages/api/src/transaction/transaction.controller.ts index f8465723d9..846bf0f61c 100644 --- a/packages/api/src/transaction/transaction.controller.ts +++ b/packages/api/src/transaction/transaction.controller.ts @@ -101,13 +101,14 @@ export class TransactionController { throw new NotFoundException(); } - return await this.transferService.findAll( + const transfers = await this.transferService.findAll( { transactionHash }, { ...pagingOptions, route: `${entityName}/${transactionHash}/transfers`, } ); + return transfers; } @Get(":transactionHash/logs") diff --git a/packages/api/src/transfer/addressTransfer.entity.ts b/packages/api/src/transfer/addressTransfer.entity.ts index fad65ae22f..5b1a9a5a1c 100644 --- a/packages/api/src/transfer/addressTransfer.entity.ts +++ b/packages/api/src/transfer/addressTransfer.entity.ts @@ -38,7 +38,7 @@ export class AddressTransfer extends BaseEntity { @Column({ type: "enum", enum: TransferType, default: TransferType.Transfer }) public readonly type: TransferType; - @Column({ type: "enum", enum: TokenType, default: TokenType.ETH }) + @Column({ type: "enum", enum: TokenType, default: TokenType.BaseToken }) public readonly tokenType: TokenType; @Column({ type: "boolean" }) diff --git a/packages/api/src/transfer/transfer.entity.ts b/packages/api/src/transfer/transfer.entity.ts index c4ec6c6727..3cf5d3e3d0 100644 --- a/packages/api/src/transfer/transfer.entity.ts +++ b/packages/api/src/transfer/transfer.entity.ts @@ -1,10 +1,11 @@ import { Entity, Column, Index, ManyToOne, JoinColumn, PrimaryColumn, AfterLoad } from "typeorm"; import { BaseEntity } from "../common/entities/base.entity"; -import { Token, TokenType, ETH_TOKEN } from "../token/token.entity"; +import { Token, TokenType } from "../token/token.entity"; import { normalizeAddressTransformer } from "../common/transformers/normalizeAddress.transformer"; import { bigIntNumberTransformer } from "../common/transformers/bigIntNumber.transformer"; import { hexTransformer } from "../common/transformers/hex.transformer"; import { Transaction } from "../transaction/entities/transaction.entity"; +import { baseTokenData } from "../config/index"; export enum TransferType { Deposit = "deposit", @@ -64,7 +65,7 @@ export class Transfer extends BaseEntity { @Column({ type: "enum", enum: TransferType, default: TransferType.Transfer }) public readonly type: TransferType; - @Column({ type: "enum", enum: TokenType, default: TokenType.ETH }) + @Column({ type: "enum", enum: TokenType, default: TokenType.BaseToken }) public readonly tokenType: TokenType; @Column({ type: "boolean", select: false }) @@ -86,9 +87,9 @@ export class Transfer extends BaseEntity { } @AfterLoad() - populateEthToken() { - if (!this.token && this.tokenAddress === ETH_TOKEN.l2Address) { - this.token = ETH_TOKEN; + populateBaseToken() { + if (!this.token && this.tokenAddress.toLowerCase() === baseTokenData.l2Address.toLowerCase()) { + this.token = baseTokenData as Token; } } } diff --git a/packages/api/src/transfer/transfer.module.ts b/packages/api/src/transfer/transfer.module.ts index e79e618bad..0b1cdd174c 100644 --- a/packages/api/src/transfer/transfer.module.ts +++ b/packages/api/src/transfer/transfer.module.ts @@ -3,7 +3,6 @@ import { TypeOrmModule } from "@nestjs/typeorm"; import { TransferService } from "./transfer.service"; import { Transfer } from "./transfer.entity"; import { AddressTransfer } from "./addressTransfer.entity"; - @Module({ imports: [TypeOrmModule.forFeature([Transfer, AddressTransfer])], providers: [TransferService], diff --git a/packages/api/test/account-api.e2e-spec.ts b/packages/api/test/account-api.e2e-spec.ts index f529cc56aa..cee6dbd0ea 100644 --- a/packages/api/test/account-api.e2e-spec.ts +++ b/packages/api/test/account-api.e2e-spec.ts @@ -12,7 +12,7 @@ import { Token, TokenType } from "../src/token/token.entity"; import { Balance } from "../src/balance/balance.entity"; import { AddressTransfer } from "../src/transfer/addressTransfer.entity"; import { Transfer, TransferType } from "../src/transfer/transfer.entity"; -import { L2_ETH_TOKEN_ADDRESS } from "../src/common/constants"; +import { BASE_TOKEN_L2_ADDRESS } from "../src/common/constants"; import { AppModule } from "../src/app.module"; import { configureApp } from "../src/configureApp"; @@ -125,7 +125,7 @@ describe("Account API (e2e)", () => { const tokens = [ { - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, tokenAddress: "0x000000000000000000000000000000000000800a", }, { @@ -170,14 +170,14 @@ describe("Account API (e2e)", () => { await balanceRepository.insert({ address: "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe35C", - tokenAddress: L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_L2_ADDRESS, blockNumber: 1, balance: "1000", }); await balanceRepository.insert({ address: "0xc7e0220d02d549c4846A6EC31D89C3B670Ebe35E", - tokenAddress: L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_L2_ADDRESS, blockNumber: 1, balance: "100", }); diff --git a/packages/api/test/address.e2e-spec.ts b/packages/api/test/address.e2e-spec.ts index ecb56ccaa5..c47bb1a9e1 100644 --- a/packages/api/test/address.e2e-spec.ts +++ b/packages/api/test/address.e2e-spec.ts @@ -12,13 +12,15 @@ import { Transaction } from "../src/transaction/entities/transaction.entity"; import { AddressTransaction } from "../src/transaction/entities/addressTransaction.entity"; import { TransactionReceipt } from "../src/transaction/entities/transactionReceipt.entity"; import { Log } from "../src/log/log.entity"; -import { Token, TokenType, ETH_TOKEN } from "../src/token/token.entity"; +import { Token, TokenType } from "../src/token/token.entity"; import { BatchDetails } from "../src/batch/batchDetails.entity"; import { Counter } from "../src/counter/counter.entity"; import { Transfer, TransferType } from "../src/transfer/transfer.entity"; import { AddressTransfer } from "../src/transfer/addressTransfer.entity"; +import { baseTokenData } from "../src/config"; describe("AddressController (e2e)", () => { + const ETH_TOKEN = baseTokenData; let app: INestApplication; let addressRepository: Repository
; let blockRepository: Repository; @@ -325,7 +327,7 @@ describe("AddressController (e2e)", () => { transactionIndex: i, timestamp: new Date("2022-11-21T18:16:51.000Z"), type, - tokenType: i % 2 ? TokenType.ERC20 : TokenType.ETH, + tokenType: i % 2 ? TokenType.ERC20 : TokenType.BaseToken, tokenAddress: i % 2 ? "0x97d0a23f34e535e44df8ba84c53a0945cf0eeb67" : "0x000000000000000000000000000000000000800a", logIndex: i, @@ -398,7 +400,7 @@ describe("AddressController (e2e)", () => { balance: "34500", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -467,7 +469,7 @@ describe("AddressController (e2e)", () => { balance: "34500", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -536,7 +538,7 @@ describe("AddressController (e2e)", () => { balance: "34500", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -605,7 +607,7 @@ describe("AddressController (e2e)", () => { balance: "34500", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -676,7 +678,7 @@ describe("AddressController (e2e)", () => { balance: "34500", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -1224,7 +1226,7 @@ describe("AddressController (e2e)", () => { to: "0x91d0a23f34e535e44Df8Ba84c53a0945cf0eEB60", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1235,7 +1237,7 @@ describe("AddressController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e11", type: "transfer", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, { diff --git a/packages/api/test/stats-api.e2e-spec.ts b/packages/api/test/stats-api.e2e-spec.ts index c805e8648c..aed8ed3856 100644 --- a/packages/api/test/stats-api.e2e-spec.ts +++ b/packages/api/test/stats-api.e2e-spec.ts @@ -5,11 +5,13 @@ import * as request from "supertest"; import { Repository } from "typeorm"; import { BatchDetails } from "../src/batch/batchDetails.entity"; import { BlockDetails } from "../src/block/blockDetails.entity"; -import { Token, ETH_TOKEN } from "../src/token/token.entity"; +import { Token } from "../src/token/token.entity"; import { AppModule } from "../src/app.module"; import { configureApp } from "../src/configureApp"; +import { baseTokenData } from "../src/config"; describe("Stats API (e2e)", () => { + let ETH_TOKEN; let app: INestApplication; let blockRepository: Repository; let batchRepository: Repository; @@ -19,7 +21,7 @@ describe("Stats API (e2e)", () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); - + ETH_TOKEN = baseTokenData; app = moduleFixture.createNestApplication({ logger: false }); configureApp(app); await app.init(); diff --git a/packages/api/test/token-api.e2e-spec.ts b/packages/api/test/token-api.e2e-spec.ts index f3735bc8e2..7930145e7c 100644 --- a/packages/api/test/token-api.e2e-spec.ts +++ b/packages/api/test/token-api.e2e-spec.ts @@ -5,9 +5,10 @@ import * as request from "supertest"; import { Repository } from "typeorm"; import { BatchDetails } from "../src/batch/batchDetails.entity"; import { BlockDetails } from "../src/block/blockDetails.entity"; -import { Token, ETH_TOKEN } from "../src/token/token.entity"; +import { Token } from "../src/token/token.entity"; import { AppModule } from "../src/app.module"; import { configureApp } from "../src/configureApp"; +import { baseTokenData } from "../src/config"; describe("Token API (e2e)", () => { let app: INestApplication; @@ -55,16 +56,16 @@ describe("Token API (e2e)", () => { }); await tokenRepository.insert({ - l2Address: ETH_TOKEN.l2Address, - l1Address: ETH_TOKEN.l1Address, - symbol: ETH_TOKEN.symbol, - name: ETH_TOKEN.name, - decimals: ETH_TOKEN.decimals, + l2Address: baseTokenData.l2Address, + l1Address: baseTokenData.l1Address, + symbol: baseTokenData.symbol, + name: baseTokenData.name, + decimals: baseTokenData.decimals, blockNumber: 0, logIndex: 0, - usdPrice: ETH_TOKEN.usdPrice, - liquidity: ETH_TOKEN.liquidity, - iconURL: ETH_TOKEN.iconURL, + usdPrice: baseTokenData.usdPrice, + liquidity: baseTokenData.liquidity, + iconURL: baseTokenData.iconURL, }); await tokenRepository.insert({ @@ -128,21 +129,21 @@ describe("Token API (e2e)", () => { it("returns HTTP 200 and ETH token info for ETH token", () => { return request(app.getHttpServer()) - .get(`/api?module=token&action=tokeninfo&contractaddress=${ETH_TOKEN.l2Address}`) + .get(`/api?module=token&action=tokeninfo&contractaddress=${baseTokenData.l2Address}`) .expect(200) .expect((res) => expect(res.body).toStrictEqual({ message: "OK", result: [ { - contractAddress: ETH_TOKEN.l2Address, - iconURL: ETH_TOKEN.iconURL, - l1Address: ETH_TOKEN.l1Address, - liquidity: ETH_TOKEN.liquidity.toString(), - symbol: ETH_TOKEN.symbol, - tokenDecimal: ETH_TOKEN.decimals.toString(), - tokenName: ETH_TOKEN.name, - tokenPriceUSD: ETH_TOKEN.usdPrice.toString(), + contractAddress: baseTokenData.l2Address, + iconURL: baseTokenData.iconURL, + l1Address: baseTokenData.l1Address, + liquidity: baseTokenData.liquidity.toString(), + symbol: baseTokenData.symbol, + tokenDecimal: baseTokenData.decimals.toString(), + tokenName: baseTokenData.name, + tokenPriceUSD: baseTokenData.usdPrice.toString(), }, ], status: "1", diff --git a/packages/api/test/token.e2e-spec.ts b/packages/api/test/token.e2e-spec.ts index b307db3298..2afe851925 100644 --- a/packages/api/test/token.e2e-spec.ts +++ b/packages/api/test/token.e2e-spec.ts @@ -5,13 +5,15 @@ import { Repository } from "typeorm"; import { getRepositoryToken } from "@nestjs/typeorm"; import { AppModule } from "../src/app.module"; import { configureApp } from "../src/configureApp"; -import { Token, TokenType, ETH_TOKEN } from "../src/token/token.entity"; +import { Token, TokenType } from "../src/token/token.entity"; import { BlockDetails } from "../src/block/blockDetails.entity"; import { Transaction } from "../src/transaction/entities/transaction.entity"; import { Transfer, TransferType } from "../src/transfer/transfer.entity"; import { BatchDetails } from "../src/batch/batchDetails.entity"; +import { baseTokenData } from "../src/config"; describe("TokenController (e2e)", () => { + let ETH_TOKEN; let app: INestApplication; let tokenRepository: Repository; let blockRepository: Repository; @@ -23,7 +25,7 @@ describe("TokenController (e2e)", () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); - + ETH_TOKEN = baseTokenData; app = moduleFixture.createNestApplication({ logger: false }); configureApp(app); @@ -232,7 +234,7 @@ describe("TokenController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", amount: "1000", type: TransferType.Refund, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, logIndex: transferIndex++, transactionIndex: 0, timestamp: "2022-11-21T18:16:51.000Z", @@ -314,7 +316,7 @@ describe("TokenController (e2e)", () => { .expect((res) => expect(res.body).toStrictEqual({ l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -655,7 +657,7 @@ describe("TokenController (e2e)", () => { to: "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -664,7 +666,7 @@ describe("TokenController (e2e)", () => { usdPrice: null, }, tokenAddress: "0x000000000000000000000000000000000000800A", - tokenType: "ETH", + tokenType: "BASETOKEN", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "refund", }, @@ -678,7 +680,7 @@ describe("TokenController (e2e)", () => { to: "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -687,7 +689,7 @@ describe("TokenController (e2e)", () => { usdPrice: null, }, tokenAddress: "0x000000000000000000000000000000000000800A", - tokenType: "ETH", + tokenType: "BASETOKEN", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "refund", }, @@ -701,7 +703,7 @@ describe("TokenController (e2e)", () => { to: "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -710,7 +712,7 @@ describe("TokenController (e2e)", () => { usdPrice: null, }, tokenAddress: "0x000000000000000000000000000000000000800A", - tokenType: "ETH", + tokenType: "BASETOKEN", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "refund", }, diff --git a/packages/api/test/transaction.e2e-spec.ts b/packages/api/test/transaction.e2e-spec.ts index 28f55e29f1..cc6ee721cc 100644 --- a/packages/api/test/transaction.e2e-spec.ts +++ b/packages/api/test/transaction.e2e-spec.ts @@ -10,13 +10,14 @@ import { Token, TokenType } from "../src/token/token.entity"; import { BlockDetails } from "../src/block/blockDetails.entity"; import { Transaction } from "../src/transaction/entities/transaction.entity"; import { TransactionReceipt } from "../src/transaction/entities/transactionReceipt.entity"; -import { ETH_TOKEN } from "../src/token/token.entity"; import { AddressTransaction } from "../src/transaction/entities/addressTransaction.entity"; import { Transfer, TransferType } from "../src/transfer/transfer.entity"; import { Log } from "../src/log/log.entity"; import { BatchDetails } from "../src/batch/batchDetails.entity"; +import { baseTokenData } from "../src/config"; describe("TransactionController (e2e)", () => { + let ETH_TOKEN; let app: INestApplication; let tokenRepository: Repository; let blockRepository: Repository; @@ -31,7 +32,7 @@ describe("TransactionController (e2e)", () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); - + ETH_TOKEN = baseTokenData; app = moduleFixture.createNestApplication({ logger: false }); configureApp(app); @@ -207,7 +208,7 @@ describe("TransactionController (e2e)", () => { transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", tokenAddress: i % 2 ? "0xd754ff5e8a6f257e162f72578a4bb0493c068101" : "0x000000000000000000000000000000000000800a", - tokenType: i % 2 ? TokenType.ERC20 : TokenType.ETH, + tokenType: i % 2 ? TokenType.ERC20 : TokenType.BaseToken, amount: "2000", type, logIndex: i, @@ -1162,7 +1163,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1173,7 +1174,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "deposit", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, { @@ -1208,7 +1209,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1219,7 +1220,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "withdrawal", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, { @@ -1254,7 +1255,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1265,7 +1266,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "mint", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, { @@ -1300,7 +1301,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1311,7 +1312,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "deposit", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, { @@ -1346,7 +1347,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { l2Address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", symbol: "ETH", name: "Ether", decimals: 18, @@ -1357,7 +1358,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "transfer", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, ]) @@ -1414,7 +1415,7 @@ describe("TransactionController (e2e)", () => { to: "0x52312Ad6f01657413b2eae9287F6b9Adad93d5fd", token: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", name: "Ether", symbol: "ETH", @@ -1425,7 +1426,7 @@ describe("TransactionController (e2e)", () => { tokenAddress: "0x000000000000000000000000000000000000800A", transactionHash: "0x8a008b8dbbc18035e56370abb820e736b705d68d6ac12b203603db8d9ea87e10", type: "deposit", - tokenType: "ETH", + tokenType: "BASETOKEN", isInternal: false, }, ], diff --git a/packages/app/src/components/FeeData.vue b/packages/app/src/components/FeeData.vue index 037eda82a6..2e07f44784 100644 --- a/packages/app/src/components/FeeData.vue +++ b/packages/app/src/components/FeeData.vue @@ -57,12 +57,13 @@ import { BigNumber } from "ethers"; import TokenAmountPrice from "@/components/TokenAmountPrice.vue"; import TransferTableCell from "@/components/transactions/infoTable/TransferTableCell.vue"; +import useContext from "@/composables/useContext"; import useToken from "@/composables/useToken"; import type { Token } from "@/composables/useToken"; import type { FeeData } from "@/composables/useTransaction"; -import { ETH_TOKEN_L2_ADDRESS } from "@/utils/constants"; +const { currentNetwork } = useContext(); const props = defineProps({ showDetails: { @@ -81,7 +82,7 @@ const collapsed = ref(false); const buttonTitle = computed(() => collapsed.value ? t("transactions.table.feeDetails.closeDetails") : t("transactions.table.feeDetails.moreDetails") ); -getTokenInfo(ETH_TOKEN_L2_ADDRESS); +getTokenInfo(currentNetwork.value.baseTokenAddress); const initialFee = computed(() => { if (props.feeData) { diff --git a/packages/app/src/components/balances/Table.vue b/packages/app/src/components/balances/Table.vue index 4cc870264d..f69d1b8e62 100644 --- a/packages/app/src/components/balances/Table.vue +++ b/packages/app/src/components/balances/Table.vue @@ -58,12 +58,12 @@ import TableBodyColumn from "@/components/common/table/TableBodyColumn.vue"; import TableHeadColumn from "@/components/common/table/TableHeadColumn.vue"; import CopyContent from "@/components/common/table/fields/CopyContent.vue"; +import useContext from "@/composables/useContext"; import useTokenLibrary from "@/composables/useTokenLibrary"; import type { Balances } from "@/composables/useAddress"; -import { ETH_TOKEN_L2_ADDRESS } from "@/utils/constants"; - +const { currentNetwork } = useContext(); const { t } = useI18n(); const props = defineProps({ @@ -98,9 +98,9 @@ const displayedBalances = computed(() => { .sort((a, b) => { if (!a.token || !b.token) return 0; - if (a.token.l2Address === ETH_TOKEN_L2_ADDRESS) { + if (a.token.l2Address === currentNetwork.value.baseTokenAddress) { return -1; - } else if (b.token.l2Address === ETH_TOKEN_L2_ADDRESS) { + } else if (b.token.l2Address === currentNetwork.value.baseTokenAddress) { return 1; } diff --git a/packages/app/src/components/transactions/EthAmountPrice.vue b/packages/app/src/components/transactions/EthAmountPrice.vue index 60469e4281..c6e0a39317 100644 --- a/packages/app/src/components/transactions/EthAmountPrice.vue +++ b/packages/app/src/components/transactions/EthAmountPrice.vue @@ -6,11 +6,12 @@ import { computed, type PropType } from "vue"; import TokenAmountPrice from "@/components/TokenAmountPrice.vue"; +import useContext from "@/composables/useContext"; import useToken, { type Token } from "@/composables/useToken"; import type { BigNumberish } from "ethers"; -import { ETH_TOKEN_L2_ADDRESS } from "@/utils/constants"; +const { currentNetwork } = useContext(); defineProps({ amount: { @@ -21,7 +22,7 @@ defineProps({ }); const { getTokenInfo, tokenInfo } = useToken(); -getTokenInfo(ETH_TOKEN_L2_ADDRESS); +getTokenInfo(currentNetwork.value.baseTokenAddress); const token = computed(() => { return tokenInfo.value; diff --git a/packages/app/src/components/transactions/Table.vue b/packages/app/src/components/transactions/Table.vue index 447c5ab7bd..46597e9910 100644 --- a/packages/app/src/components/transactions/Table.vue +++ b/packages/app/src/components/transactions/Table.vue @@ -212,6 +212,7 @@ import TokenAmountPriceTableCell from "@/components/transactions/TokenAmountPric import TransactionDirectionTableCell from "@/components/transactions/TransactionDirectionTableCell.vue"; import TransactionNetworkSquareBlock from "@/components/transactions/TransactionNetworkSquareBlock.vue"; +import useContext from "@/composables/useContext"; import useToken, { type Token } from "@/composables/useToken"; import { decodeDataWithABI } from "@/composables/useTransactionData"; import useTransactions, { type TransactionListItem, type TransactionSearchParams } from "@/composables/useTransactions"; @@ -220,9 +221,10 @@ import type { Direction } from "@/components/transactions/TransactionDirectionTa import type { AbiFragment } from "@/composables/useAddress"; import type { NetworkOrigin } from "@/types"; -import { ETH_TOKEN_L2_ADDRESS } from "@/utils/constants"; import { utcStringFromISOString } from "@/utils/helpers"; +const { currentNetwork } = useContext(); + const { t, te } = useI18n(); const props = defineProps({ @@ -251,7 +253,7 @@ const searchParams = computed(() => props.searchParams ?? {}); const { data, load, total, pending, pageSize } = useTransactions(searchParams); const { getTokenInfo, tokenInfo, isRequestPending: isLoadingEthTokenInfo } = useToken(); -getTokenInfo(ETH_TOKEN_L2_ADDRESS); +getTokenInfo(currentNetwork.value.baseTokenAddress); const ethToken = computed(() => { return tokenInfo.value; diff --git a/packages/app/src/composables/useContext.ts b/packages/app/src/composables/useContext.ts index a03133aaa0..632611bcd5 100644 --- a/packages/app/src/composables/useContext.ts +++ b/packages/app/src/composables/useContext.ts @@ -8,6 +8,7 @@ import { DEFAULT_NETWORK } from "./useRuntimeConfig"; import type { NetworkConfig } from "@/configs"; +import { checksumAddress } from "@/utils/formatters"; import { getWindowLocation } from "@/utils/helpers"; const network = useStorage("selectedNetwork_v2", DEFAULT_NETWORK.name); @@ -26,9 +27,12 @@ export default (): Context => { const environmentConfig = useEnvironmentConfig(); const networks = computed(() => { - return Array.isArray(environmentConfig.networks.value) && environmentConfig.networks.value.length - ? environmentConfig.networks.value - : [DEFAULT_NETWORK]; + const configuredNetworks = + Array.isArray(environmentConfig.networks.value) && environmentConfig.networks.value.length + ? environmentConfig.networks.value + : [DEFAULT_NETWORK]; + configuredNetworks.forEach((network) => (network.baseTokenAddress = checksumAddress(network.baseTokenAddress))); + return configuredNetworks; }); const currentNetwork = computed(() => { return ( diff --git a/packages/app/src/composables/useEnvironmentConfig.ts b/packages/app/src/composables/useEnvironmentConfig.ts index 0bf3c76df6..30c4dbd8ae 100644 --- a/packages/app/src/composables/useEnvironmentConfig.ts +++ b/packages/app/src/composables/useEnvironmentConfig.ts @@ -2,6 +2,8 @@ import { computed, ref } from "vue"; import type { EnvironmentConfig, NetworkConfig, RuntimeConfig } from "@/configs"; +import { checksumAddress } from "@/utils/formatters"; + const config = ref(null); const HYPERCHAIN_CONFIG_NAME = "hyperchain"; @@ -24,6 +26,11 @@ export async function loadEnvironmentConfig(runtimeConfig: RuntimeConfig): Promi } else { envConfig = (await import(`../configs/${runtimeConfig.appEnvironment}.config.json`)).default; } + + envConfig.networks?.forEach((networkConfig) => { + networkConfig.baseTokenAddress = checksumAddress(networkConfig.baseTokenAddress); + }); + config.value = envConfig; } diff --git a/packages/app/src/composables/useRuntimeConfig.ts b/packages/app/src/composables/useRuntimeConfig.ts index 969b4f7a95..6e3899ba73 100644 --- a/packages/app/src/composables/useRuntimeConfig.ts +++ b/packages/app/src/composables/useRuntimeConfig.ts @@ -1,5 +1,6 @@ import type { NetworkConfig, RuntimeConfig } from "@/configs"; +import { checksumAddress } from "@/utils/formatters"; export const DEFAULT_NETWORK: NetworkConfig = { apiUrl: "https://block-explorer-api.sepolia.zksync.dev", verificationApiUrl: "https://explorer.sepolia.era.zksync.dev", @@ -13,6 +14,7 @@ export const DEFAULT_NETWORK: NetworkConfig = { name: "sepolia", published: true, rpcUrl: "https://sepolia.era.zksync.dev", + baseTokenAddress: checksumAddress("0x000000000000000000000000000000000000800A"), }; export default (): RuntimeConfig => { diff --git a/packages/app/src/composables/useToken.ts b/packages/app/src/composables/useToken.ts index 3f1a7c308f..7bb0196a06 100644 --- a/packages/app/src/composables/useToken.ts +++ b/packages/app/src/composables/useToken.ts @@ -9,7 +9,6 @@ import useTokenLibrary from "@/composables/useTokenLibrary"; import type { Hash } from "@/types"; export type Token = Api.Response.Token; - export const retrieveToken = useMemoize( (tokenAddress: Hash, context: Context = useContext()): Promise => { return $fetch(`${context.currentNetwork.value.apiUrl}/tokens/${tokenAddress}`); @@ -20,10 +19,8 @@ export const retrieveToken = useMemoize( }, } ); - export default () => { const { getToken, getTokens } = useTokenLibrary(); - const isRequestPending = ref(false); const isRequestFailed = ref(false); const tokenInfo = ref(null as Token | null); diff --git a/packages/app/src/composables/useTokenLibrary.ts b/packages/app/src/composables/useTokenLibrary.ts index d7e3dc12d0..e6728405c9 100644 --- a/packages/app/src/composables/useTokenLibrary.ts +++ b/packages/app/src/composables/useTokenLibrary.ts @@ -39,7 +39,6 @@ export default (context = useContext()) => { const isRequestPending = ref(false); const isRequestFailed = ref(false); const tokens = ref([]); - const getToken = (tokenAddress: string) => { return tokens.value.find((token) => token.l2Address === tokenAddress); }; diff --git a/packages/app/src/configs/dev.config.json b/packages/app/src/configs/dev.config.json index 5985e43d19..5db1f5c485 100644 --- a/packages/app/src/configs/dev.config.json +++ b/packages/app/src/configs/dev.config.json @@ -12,7 +12,8 @@ "maintenance": false, "name": "local", "published": true, - "rpcUrl": "http://localhost:3050" + "rpcUrl": "http://localhost:3050", + "baseTokenAddress": "0x000000000000000000000000000000000000800A" }, { "apiUrl": "https://block-explorer-api.sepolia.zksync.dev", @@ -26,7 +27,8 @@ "maintenance": false, "name": "sepolia", "published": true, - "rpcUrl": "https://sepolia.era.zksync.dev" + "rpcUrl": "https://sepolia.era.zksync.dev", + "baseTokenAddress": "0x000000000000000000000000000000000000800a" }, { "apiUrl": "https://block-explorer-api.stage.zksync.dev", @@ -41,7 +43,8 @@ "maintenance": false, "name": "goerli-beta", "published": true, - "rpcUrl": "https://z2-dev-api.zksync.dev" + "rpcUrl": "https://z2-dev-api.zksync.dev", + "baseTokenAddress": "0x000000000000000000000000000000000000800a" }, { "apiUrl": "https://block-explorer-api.mainnet.zksync.io", @@ -58,7 +61,8 @@ "name": "mainnet", "published": true, "rpcUrl": "https://mainnet.era.zksync.io", - "tokensMinLiquidity": 0 + "tokensMinLiquidity": 0, + "baseTokenAddress": "0x000000000000000000000000000000000000800a" } ] } diff --git a/packages/app/src/configs/index.ts b/packages/app/src/configs/index.ts index 4bac0d7c54..8e9d98fd8f 100644 --- a/packages/app/src/configs/index.ts +++ b/packages/app/src/configs/index.ts @@ -12,6 +12,7 @@ export type NetworkConfig = { published: boolean; hostnames: string[]; tokensMinLiquidity?: number; + baseTokenAddress: string; }; export type EnvironmentConfig = { diff --git a/packages/app/src/configs/local.config.json b/packages/app/src/configs/local.config.json index cbaee29f8a..e0e91d9a19 100644 --- a/packages/app/src/configs/local.config.json +++ b/packages/app/src/configs/local.config.json @@ -12,7 +12,8 @@ "maintenance": false, "name": "local", "published": true, - "rpcUrl": "http://localhost:3050" + "rpcUrl": "http://localhost:3050", + "baseTokenAddress": "0x000000000000000000000000000000000000800A" } ] } diff --git a/packages/app/src/configs/production.config.json b/packages/app/src/configs/production.config.json index 3c173160e9..b4b2f7a9ee 100644 --- a/packages/app/src/configs/production.config.json +++ b/packages/app/src/configs/production.config.json @@ -14,7 +14,8 @@ "maintenance": false, "name": "sepolia", "published": true, - "rpcUrl": "https://sepolia.era.zksync.dev" + "rpcUrl": "https://sepolia.era.zksync.dev", + "baseTokenAddress": "0x000000000000000000000000000000000000800a" }, { "apiUrl": "https://block-explorer-api.mainnet.zksync.io", @@ -31,7 +32,8 @@ "name": "mainnet", "published": true, "rpcUrl": "https://mainnet.era.zksync.io", - "tokensMinLiquidity": 0 + "tokensMinLiquidity": 0, + "baseTokenAddress": "0x000000000000000000000000000000000000800a" } ] } diff --git a/packages/app/src/configs/staging.config.json b/packages/app/src/configs/staging.config.json index 97afd00076..18bf193ac8 100644 --- a/packages/app/src/configs/staging.config.json +++ b/packages/app/src/configs/staging.config.json @@ -14,7 +14,8 @@ "maintenance": false, "name": "sepolia", "published": true, - "rpcUrl": "https://sepolia.era.zksync.dev" + "rpcUrl": "https://sepolia.era.zksync.dev", + "baseTokenAddress": "0x000000000000000000000000000000000000800a" }, { "apiUrl": "https://block-explorer-api.stage.zksync.dev", @@ -29,7 +30,8 @@ "maintenance": false, "name": "goerli-beta", "published": true, - "rpcUrl": "https://z2-dev-api.zksync.dev" + "rpcUrl": "https://z2-dev-api.zksync.dev", + "baseTokenAddress": "0x000000000000000000000000000000000000800a" }, { "apiUrl": "https://block-explorer-api.mainnet.zksync.io", @@ -46,7 +48,8 @@ "name": "mainnet", "published": true, "rpcUrl": "https://mainnet.era.zksync.io", - "tokensMinLiquidity": 0 + "tokensMinLiquidity": 0, + "baseTokenAddress": "0x000000000000000000000000000000000000800a" } ] } diff --git a/packages/app/src/utils/constants.ts b/packages/app/src/utils/constants.ts index 834827ee7b..7048c3c0ef 100644 --- a/packages/app/src/utils/constants.ts +++ b/packages/app/src/utils/constants.ts @@ -1,7 +1,3 @@ -import { checksumAddress } from "./formatters"; - -export const ETH_TOKEN_L2_ADDRESS = checksumAddress("0x000000000000000000000000000000000000800A"); - export const PROXY_CONTRACT_IMPLEMENTATION_ABI = [ { inputs: [], diff --git a/packages/app/tests/components/FeeData.spec.ts b/packages/app/tests/components/FeeData.spec.ts index c12493e2ca..d89e1cb2d7 100644 --- a/packages/app/tests/components/FeeData.spec.ts +++ b/packages/app/tests/components/FeeData.spec.ts @@ -46,7 +46,7 @@ const feeData = { { tokenInfo: { decimals: 18, - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x0000000000000000000000000000000000000000", symbol: "ETH", name: "Ether", diff --git a/packages/app/tests/components/transactions/GeneralInfo.spec.ts b/packages/app/tests/components/transactions/GeneralInfo.spec.ts index 63450cbd36..a5554ce777 100644 --- a/packages/app/tests/components/transactions/GeneralInfo.spec.ts +++ b/packages/app/tests/components/transactions/GeneralInfo.spec.ts @@ -49,7 +49,7 @@ const transaction: TransactionItem = { type: "refund", tokenInfo: { address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", symbol: "ETH", name: "Ether", @@ -65,7 +65,7 @@ const transaction: TransactionItem = { type: "refund", tokenInfo: { address: "0x000000000000000000000000000000000000800A", - l1Address: "0x0000000000000000000000000000000000000000", + l1Address: "0x0000000000000000000000000000000000000001", l2Address: "0x000000000000000000000000000000000000800A", symbol: "ETH", name: "Ether", diff --git a/packages/app/tests/composables/useTransaction.spec.ts b/packages/app/tests/composables/useTransaction.spec.ts index 8e4a00507b..3f637336db 100644 --- a/packages/app/tests/composables/useTransaction.spec.ts +++ b/packages/app/tests/composables/useTransaction.spec.ts @@ -404,6 +404,7 @@ describe("useTransaction:", () => { fee: "0x521f303519100", feeData: { amountPaid: "0x521f303519100", + paymasterAddress: undefined, isPaidByPaymaster: false, refunds: [ { @@ -519,6 +520,9 @@ describe("useTransaction:", () => { toNetwork: "L2", type: "transfer", tokenInfo: { + iconURL: undefined, + liquidity: undefined, + usdPrice: undefined, address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47D", l1Address: undefined, l2Address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47D", @@ -535,6 +539,9 @@ describe("useTransaction:", () => { toNetwork: "L2", type: "transfer", tokenInfo: { + iconURL: undefined, + liquidity: undefined, + usdPrice: undefined, address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47C", l1Address: null, l2Address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47C", diff --git a/packages/app/tests/mocks.ts b/packages/app/tests/mocks.ts index da3976f5ed..96fcdf7737 100644 --- a/packages/app/tests/mocks.ts +++ b/packages/app/tests/mocks.ts @@ -46,6 +46,7 @@ export const TESTNET_NETWORK: NetworkConfig = { maintenance: false, published: true, hostnames: [], + baseTokenAddress: checksumAddress("0x000000000000000000000000000000000000800A"), }; export const TESTNET_BETA_NETWORK: NetworkConfig = { name: "testnet-beta", @@ -58,6 +59,7 @@ export const TESTNET_BETA_NETWORK: NetworkConfig = { l1ExplorerUrl: "http://testnet-beta-block-explorer", maintenance: false, published: true, + baseTokenAddress: checksumAddress("0x000000000000000000000000000000000000800A"), hostnames: ["https://testnet-beta.staging-scan-v2.zksync.dev/"], }; diff --git a/packages/data-fetcher/src/balance/balance.service.spec.ts b/packages/data-fetcher/src/balance/balance.service.spec.ts index 4a2b2baed2..56c37ec14b 100644 --- a/packages/data-fetcher/src/balance/balance.service.spec.ts +++ b/packages/data-fetcher/src/balance/balance.service.spec.ts @@ -61,14 +61,14 @@ describe("BalanceService", () => { from: "0x36615cf349d7f6344891b1e7ca7c72883f5dc049", to: "0x0000000000000000000000000000000000008001", blockNumber: 10, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }), mock({ tokenAddress: "0x000000000000000000000000000000000000800a", from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", blockNumber: 10, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }), mock({ tokenAddress: "0x2392e98fb47cf05773144db3ce8002fac4f39c84", @@ -103,14 +103,14 @@ describe("BalanceService", () => { from: "0x000000000000000000000000000000000000800a", to: "0x0000000000000000000000000000000000008001", blockNumber: 10, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }), mock({ tokenAddress: "0x000000000000000000000000000000000000800a", from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000000000", blockNumber: 10, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }), mock({ tokenAddress: "0x2392e98fb47cf05773144db3ce8002fac4f39c84", @@ -189,7 +189,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( @@ -198,7 +198,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( @@ -207,7 +207,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( @@ -239,7 +239,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( blockChangedBalances @@ -252,7 +252,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( blockChangedBalances @@ -278,7 +278,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); }); @@ -287,7 +287,7 @@ describe("BalanceService", () => { existingBlockBalances.set( "0x0000000000000000000000000000000000008007", new Map([ - ["0x000000000000000000000000000000000000800a", { balance: undefined, tokenType: TokenType.ETH }], + ["0x000000000000000000000000000000000000800a", { balance: undefined, tokenType: TokenType.BaseToken }], ["0x0000000000000000000000000000000000008123", { balance: undefined, tokenType: TokenType.ERC20 }], ]) ); @@ -295,7 +295,7 @@ describe("BalanceService", () => { existingBlockBalances.set( "0x36615cf349d7f6344891b1e7ca7c72883f5dc049", new Map([ - ["0x000000000000000000000000000000000000800a", { balance: undefined, tokenType: TokenType.ETH }], + ["0x000000000000000000000000000000000000800a", { balance: undefined, tokenType: TokenType.BaseToken }], ]) ); @@ -317,7 +317,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( blockChangedBalances @@ -346,7 +346,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( blockChangedBalances @@ -359,7 +359,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); expect( blockChangedBalances @@ -385,7 +385,7 @@ describe("BalanceService", () => { .get("0x000000000000000000000000000000000000800a") ).toEqual({ balance: undefined, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }); }); }); @@ -404,21 +404,21 @@ describe("BalanceService", () => { blockBalances.set( utils.ETH_ADDRESS, new Map([ - [utils.ETH_ADDRESS, { balance: undefined, tokenType: TokenType.ETH }], + [utils.ETH_ADDRESS, { balance: undefined, tokenType: TokenType.BaseToken }], ]) ); blockBalances.set( addresses[0], new Map([ [tokenAddresses[0][0], { balance: undefined, tokenType: TokenType.ERC20 }], - [tokenAddresses[0][1], { balance: undefined, tokenType: TokenType.ETH }], + [tokenAddresses[0][1], { balance: undefined, tokenType: TokenType.BaseToken }], ]) ); blockBalances.set( addresses[1], new Map([ [tokenAddresses[1][0], { balance: undefined, tokenType: TokenType.ERC20 }], - [tokenAddresses[1][1], { balance: undefined, tokenType: TokenType.ETH }], + [tokenAddresses[1][1], { balance: undefined, tokenType: TokenType.BaseToken }], ]) ); balanceService.changedBalances.set(blockNumber, blockBalances); @@ -453,7 +453,7 @@ describe("BalanceService", () => { blockNumber: 5, tokenAddress: "0x0000000000000000000000000000000000000000", balance: BigNumber.from(1), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, { address: addresses[0], @@ -467,7 +467,7 @@ describe("BalanceService", () => { blockNumber: 5, tokenAddress: tokenAddresses[0][1], balance: BigNumber.from(3), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, { address: addresses[1], @@ -481,7 +481,7 @@ describe("BalanceService", () => { blockNumber: 5, tokenAddress: tokenAddresses[1][1], balance: BigNumber.from(5), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, ]); }); @@ -504,7 +504,7 @@ describe("BalanceService", () => { blockNumber: 5, tokenAddress: "0x0000000000000000000000000000000000000000", balance: BigNumber.from(1), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, { address: addresses[0], @@ -525,7 +525,7 @@ describe("BalanceService", () => { blockNumber: 5, tokenAddress: tokenAddresses[1][1], balance: BigNumber.from(5), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, ]); }); diff --git a/packages/data-fetcher/src/block/block.service.spec.ts b/packages/data-fetcher/src/block/block.service.spec.ts index 91f5a507fb..a4c4291d8b 100644 --- a/packages/data-fetcher/src/block/block.service.spec.ts +++ b/packages/data-fetcher/src/block/block.service.spec.ts @@ -105,7 +105,7 @@ describe("BlockService", () => { blockNumber: 5, tokenAddress: "0x0000000000000000000000000000000000000000", balance: BigNumber.from(1), - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, }, ]; diff --git a/packages/data-fetcher/src/blockchain/blockchain.service.ts b/packages/data-fetcher/src/blockchain/blockchain.service.ts index 16825128da..caabbf6f02 100644 --- a/packages/data-fetcher/src/blockchain/blockchain.service.ts +++ b/packages/data-fetcher/src/blockchain/blockchain.service.ts @@ -185,7 +185,6 @@ export class BlockchainService implements OnModuleInit { this.bridgeAddresses = { l2Erc20DefaultBridge: bridgeAddresses.erc20L2?.toLowerCase(), }; - this.logger.debug(`L2 ERC20 Bridge is set to: ${this.bridgeAddresses.l2Erc20DefaultBridge}`); } } diff --git a/packages/data-fetcher/src/constants.ts b/packages/data-fetcher/src/constants.ts index 2346236d6f..8acfc2bcb0 100644 --- a/packages/data-fetcher/src/constants.ts +++ b/packages/data-fetcher/src/constants.ts @@ -7,6 +7,8 @@ import * as transferEventWithNoIndexesAbi from "./abis/transferEventWithNoIndexe import * as l2StandardERC20Abi from "./abis/l2StandardERC20.json"; export const ZERO_HASH_64 = "0x0000000000000000000000000000000000000000000000000000000000000000"; +export const BASE_TOKEN_ADDRESS = "0x000000000000000000000000000000000000800a"; +export const ETH_L1_ADDRESS = "0x0000000000000000000000000000000000000001"; export const CONTRACT_INTERFACES = { ERC20: { diff --git a/packages/data-fetcher/src/token/token.service.spec.ts b/packages/data-fetcher/src/token/token.service.spec.ts index 075f0f84e9..1108c8f46b 100644 --- a/packages/data-fetcher/src/token/token.service.spec.ts +++ b/packages/data-fetcher/src/token/token.service.spec.ts @@ -1,5 +1,6 @@ import { mock } from "jest-mock-extended"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; +import { BASE_TOKEN_ADDRESS, ETH_L1_ADDRESS } from "../constants"; import { Test, TestingModule } from "@nestjs/testing"; import { Logger } from "@nestjs/common"; import { BlockchainService } from "../blockchain/blockchain.service"; @@ -103,22 +104,22 @@ describe("TokenService", () => { symbol: "ETH", decimals: 18, name: "Ethers", + l1Address: ETH_L1_ADDRESS, }; const deployedETHContractAddress = mock({ - address: utils.L2_ETH_TOKEN_ADDRESS, + address: BASE_TOKEN_ADDRESS, blockNumber: 0, transactionHash: "transactionHash", logIndex: 0, }); (blockchainServiceMock.getERC20TokenData as jest.Mock).mockResolvedValueOnce(ethTokenData); - const token = await tokenService.getERC20Token(deployedETHContractAddress, transactionReceipt); expect(token).toStrictEqual({ ...ethTokenData, blockNumber: deployedETHContractAddress.blockNumber, transactionHash: deployedETHContractAddress.transactionHash, - l2Address: deployedETHContractAddress.address, - l1Address: utils.ETH_ADDRESS, + l2Address: BASE_TOKEN_ADDRESS, + l1Address: ETH_L1_ADDRESS, logIndex: deployedETHContractAddress.logIndex, }); }); diff --git a/packages/data-fetcher/src/token/token.service.ts b/packages/data-fetcher/src/token/token.service.ts index d1a9a35261..a9ccf88a63 100644 --- a/packages/data-fetcher/src/token/token.service.ts +++ b/packages/data-fetcher/src/token/token.service.ts @@ -1,4 +1,4 @@ -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { Injectable, Logger } from "@nestjs/common"; import { InjectMetric } from "@willsoto/nestjs-prometheus"; import { Histogram } from "prom-client"; @@ -7,7 +7,7 @@ import { BlockchainService } from "../blockchain/blockchain.service"; import { GET_TOKEN_INFO_DURATION_METRIC_NAME } from "../metrics"; import { ContractAddress } from "../address/interface/contractAddress.interface"; import parseLog from "../utils/parseLog"; -import { CONTRACT_INTERFACES } from "../constants"; +import { CONTRACT_INTERFACES, BASE_TOKEN_ADDRESS, ETH_L1_ADDRESS } from "../constants"; export interface Token { l2Address: string; @@ -21,7 +21,7 @@ export interface Token { } export enum TokenType { - ETH = "ETH", + BaseToken = "BASETOKEN", ERC20 = "ERC20", ERC721 = "ERC721", } @@ -109,8 +109,8 @@ export class TokenService { l2Address: contractAddress.address, logIndex: contractAddress.logIndex, // add L1 address for ETH token - ...(contractAddress.address.toLowerCase() === utils.L2_ETH_TOKEN_ADDRESS && { - l1Address: utils.ETH_ADDRESS, + ...(contractAddress.address.toLowerCase() === BASE_TOKEN_ADDRESS && { + l1Address: ETH_L1_ADDRESS, }), }; } diff --git a/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.spec.ts b/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.spec.ts index ecf5e96b74..6f89d0cc43 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.spec.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.spec.ts @@ -1,10 +1,11 @@ import { BigNumber } from "ethers"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { mock } from "jest-mock-extended"; import { ZERO_HASH_64 } from "../../../constants"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { defaultFinalizeDepositHandler } from "./default.handler"; +import { BASE_TOKEN_ADDRESS } from "../../../../src/constants"; describe("defaultFinalizeDepositHandler", () => { let log: types.Log; @@ -66,8 +67,8 @@ describe("defaultFinalizeDepositHandler", () => { it("extracts transfer with L2_ETH_TOKEN_ADDRESS as a tokenAddress if l2Token is 0x0000000000000000000000000000000000000000", () => { log.topics[3] = ZERO_HASH_64; const result = defaultFinalizeDepositHandler.extract(log, blockDetails); - expect(result.tokenAddress).toBe(utils.L2_ETH_TOKEN_ADDRESS); - expect(result.tokenType).toBe(TokenType.ETH); + expect(result.tokenAddress).toBe(BASE_TOKEN_ADDRESS); + expect(result.tokenType).toBe(TokenType.BaseToken); }); it("extracts transfer with tokenAddress field populated with lower cased l2Token", () => { diff --git a/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.ts b/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.ts index f1b5158449..17d6d8d5dc 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/finalizeDeposit/default.handler.ts @@ -5,8 +5,8 @@ import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { unixTimeToDate } from "../../../utils/date"; import parseLog from "../../../utils/parseLog"; -import { CONTRACT_INTERFACES } from "../../../constants"; - +import { BASE_TOKEN_ADDRESS, CONTRACT_INTERFACES } from "../../../constants"; +import { isBaseToken } from "../../../utils/token"; export const defaultFinalizeDepositHandler: ExtractTransferHandler = { matches: (): boolean => true, extract: ( @@ -16,7 +16,7 @@ export const defaultFinalizeDepositHandler: ExtractTransferHandler = { ): Transfer => { const parsedLog = parseLog(CONTRACT_INTERFACES.L2_BRIDGE, log); const tokenAddress = - parsedLog.args.l2Token === utils.ETH_ADDRESS ? utils.L2_ETH_TOKEN_ADDRESS : parsedLog.args.l2Token.toLowerCase(); + parsedLog.args.l2Token === utils.ETH_ADDRESS ? BASE_TOKEN_ADDRESS : parsedLog.args.l2Token.toLowerCase(); return { from: parsedLog.args.l1Sender.toLowerCase(), @@ -26,7 +26,7 @@ export const defaultFinalizeDepositHandler: ExtractTransferHandler = { amount: parsedLog.args.amount, tokenAddress, type: TransferType.Deposit, - tokenType: tokenAddress === utils.L2_ETH_TOKEN_ADDRESS ? TokenType.ETH : TokenType.ERC20, + tokenType: isBaseToken(tokenAddress) ? TokenType.BaseToken : TokenType.ERC20, isFeeOrRefund: false, logIndex: log.logIndex, transactionIndex: log.transactionIndex, diff --git a/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.spec.ts b/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.spec.ts index 88cfd8fbd9..315d7f22dc 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.spec.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.spec.ts @@ -1,9 +1,10 @@ import { BigNumber } from "ethers"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { mock } from "jest-mock-extended"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { ethMintFromL1Handler } from "./ethMintFromL1.handler"; +import { BASE_TOKEN_ADDRESS } from "../../../constants"; describe("ethMintFromL1Handler", () => { let log: types.Log; @@ -63,7 +64,7 @@ describe("ethMintFromL1Handler", () => { it("extracts transfer with tokenType as ETH", () => { const result = ethMintFromL1Handler.extract(log, blockDetails); - expect(result.tokenType).toBe(TokenType.ETH); + expect(result.tokenType).toBe(TokenType.BaseToken); }); it("extracts transfer with populated amount", () => { @@ -73,7 +74,7 @@ describe("ethMintFromL1Handler", () => { it("extracts transfer with L2_ETH_TOKEN_ADDRESS as tokenAddress", () => { const result = ethMintFromL1Handler.extract(log, blockDetails); - expect(result.tokenAddress).toBe(utils.L2_ETH_TOKEN_ADDRESS); + expect(result.tokenAddress).toBe(BASE_TOKEN_ADDRESS); }); it("extracts transfer of deposit type", () => { diff --git a/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.ts b/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.ts index b113937558..b8a004da93 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/mint/ethMintFromL1.handler.ts @@ -1,14 +1,13 @@ -import { utils, types } from "zksync-web3"; +import { types } from "zksync-web3"; import { Transfer } from "../../interfaces/transfer.interface"; import { ExtractTransferHandler } from "../../interfaces/extractTransferHandler.interface"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { unixTimeToDate } from "../../../utils/date"; import parseLog from "../../../utils/parseLog"; -import { CONTRACT_INTERFACES } from "../../../constants"; - +import { BASE_TOKEN_ADDRESS, CONTRACT_INTERFACES } from "../../../constants"; export const ethMintFromL1Handler: ExtractTransferHandler = { - matches: (log: types.Log): boolean => log.address.toLowerCase() === utils.L2_ETH_TOKEN_ADDRESS, + matches: (log: types.Log): boolean => log.address.toLowerCase() === BASE_TOKEN_ADDRESS, extract: ( log: types.Log, blockDetails: types.BlockDetails, @@ -22,9 +21,9 @@ export const ethMintFromL1Handler: ExtractTransferHandler = { transactionHash: log.transactionHash, blockNumber: log.blockNumber, amount: parsedLog.args.amount, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, type: TransferType.Deposit, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, isFeeOrRefund: false, logIndex: log.logIndex, transactionIndex: log.transactionIndex, diff --git a/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.spec.ts b/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.spec.ts index 28b15d39ed..536e89187b 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.spec.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.spec.ts @@ -1,10 +1,10 @@ import { BigNumber } from "ethers"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { mock } from "jest-mock-extended"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { defaultTransferHandler } from "./default.handler"; - +import { BASE_TOKEN_ADDRESS } from "../../../../src/constants"; describe("defaultTransferHandler", () => { let log: types.Log; let blockDetails: types.BlockDetails; @@ -99,10 +99,10 @@ describe("defaultTransferHandler", () => { }); it("extracts transfer with 0x000000000000000000000000000000000000800a as a tokenAddress if log address is 0x000000000000000000000000000000000000800a", () => { - log.address = utils.L2_ETH_TOKEN_ADDRESS; + log.address = BASE_TOKEN_ADDRESS; const result = defaultTransferHandler.extract(log, blockDetails); - expect(result.tokenAddress).toBe(utils.L2_ETH_TOKEN_ADDRESS); - expect(result.tokenType).toBe(TokenType.ETH); + expect(result.tokenAddress).toBe(BASE_TOKEN_ADDRESS); + expect(result.tokenType).toBe(TokenType.BaseToken); }); it("extracts transfer with tokenAddress field populated with lower cased log address", () => { diff --git a/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.ts b/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.ts index e89f6f2602..2fe7911330 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/transfer/default.handler.ts @@ -5,6 +5,7 @@ import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { unixTimeToDate } from "../../../utils/date"; import parseLog from "../../../utils/parseLog"; +import { isBaseToken } from "../../../utils/token"; import { CONTRACT_INTERFACES } from "../../../constants"; export const defaultTransferHandler: ExtractTransferHandler = { @@ -36,7 +37,7 @@ export const defaultTransferHandler: ExtractTransferHandler = { amount: parsedLog.args.value, tokenAddress, type: transferType, - tokenType: tokenAddress === utils.L2_ETH_TOKEN_ADDRESS ? TokenType.ETH : TokenType.ERC20, + tokenType: isBaseToken(tokenAddress) ? TokenType.BaseToken : TokenType.ERC20, isFeeOrRefund: [TransferType.Fee, TransferType.Refund].includes(transferType), logIndex: log.logIndex, transactionIndex: log.transactionIndex, diff --git a/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.spec.ts b/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.spec.ts index 9d09253a1c..3cd7d65150 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.spec.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.spec.ts @@ -1,9 +1,10 @@ import { BigNumber } from "ethers"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { mock } from "jest-mock-extended"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { ethWithdrawalToL1Handler } from "./ethWithdrawalToL1.handler"; +import { BASE_TOKEN_ADDRESS } from "../../../constants"; describe("ethWithdrawalToL1Handler", () => { let log: types.Log; @@ -69,7 +70,7 @@ describe("ethWithdrawalToL1Handler", () => { it("extracts transfer with L2_ETH_TOKEN_ADDRESS as tokenAddress", () => { const result = ethWithdrawalToL1Handler.extract(log, blockDetails); - expect(result.tokenAddress).toBe(utils.L2_ETH_TOKEN_ADDRESS); + expect(result.tokenAddress).toBe(BASE_TOKEN_ADDRESS); }); it("extracts transfer of deposit type", () => { @@ -79,7 +80,7 @@ describe("ethWithdrawalToL1Handler", () => { it("extracts transfer of ETH token type", () => { const result = ethWithdrawalToL1Handler.extract(log, blockDetails); - expect(result.tokenType).toBe(TokenType.ETH); + expect(result.tokenType).toBe(TokenType.BaseToken); }); it("adds isFeeOrRefund as false", () => { diff --git a/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.ts b/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.ts index c387c4b96a..d7d97fa968 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/withdrawal/ethWithdrawalToL1.handler.ts @@ -1,14 +1,14 @@ -import { utils, types } from "zksync-web3"; +import { types } from "zksync-web3"; import { Transfer } from "../../interfaces/transfer.interface"; import { ExtractTransferHandler } from "../../interfaces/extractTransferHandler.interface"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { unixTimeToDate } from "../../../utils/date"; import parseLog from "../../../utils/parseLog"; -import { CONTRACT_INTERFACES } from "../../../constants"; +import { BASE_TOKEN_ADDRESS, CONTRACT_INTERFACES } from "../../../constants"; export const ethWithdrawalToL1Handler: ExtractTransferHandler = { - matches: (log: types.Log): boolean => log.address.toLowerCase() === utils.L2_ETH_TOKEN_ADDRESS, + matches: (log: types.Log): boolean => log.address.toLowerCase() === BASE_TOKEN_ADDRESS, extract: ( log: types.Log, blockDetails: types.BlockDetails, @@ -21,9 +21,9 @@ export const ethWithdrawalToL1Handler: ExtractTransferHandler = { transactionHash: log.transactionHash, blockNumber: log.blockNumber, amount: parsedLog.args._amount, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, type: TransferType.Withdrawal, - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, isFeeOrRefund: false, logIndex: log.logIndex, transactionIndex: log.transactionIndex, diff --git a/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.spec.ts b/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.spec.ts index 0ffdcecc46..f350a9bc20 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.spec.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.spec.ts @@ -1,10 +1,11 @@ import { BigNumber } from "ethers"; -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { mock } from "jest-mock-extended"; import { ZERO_HASH_64 } from "../../../constants"; import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { defaultWithdrawalInitiatedHandler } from "./default.handler"; +import { BASE_TOKEN_ADDRESS } from "../../../../src/constants"; describe("defaultWithdrawalInitiatedHandler", () => { let log: types.Log; @@ -66,8 +67,8 @@ describe("defaultWithdrawalInitiatedHandler", () => { it("extracts transfer with L2_ETH_TOKEN_ADDRESS as a tokenAddress if l2Token is 0x0000000000000000000000000000000000000000", () => { log.topics[3] = ZERO_HASH_64; const result = defaultWithdrawalInitiatedHandler.extract(log, blockDetails); - expect(result.tokenAddress).toBe(utils.L2_ETH_TOKEN_ADDRESS); - expect(result.tokenType).toBe(TokenType.ETH); + expect(result.tokenAddress).toBe(BASE_TOKEN_ADDRESS); + expect(result.tokenType).toBe(TokenType.BaseToken); }); it("extracts transfer with tokenAddress field populated with lower cased l2Token", () => { diff --git a/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.ts b/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.ts index 9699ae3c8f..1bfd806ee2 100644 --- a/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.ts +++ b/packages/data-fetcher/src/transfer/extractHandlers/withdrawalInitiated/default.handler.ts @@ -5,7 +5,8 @@ import { TransferType } from "../../transfer.service"; import { TokenType } from "../../../token/token.service"; import { unixTimeToDate } from "../../../utils/date"; import parseLog from "../../../utils/parseLog"; -import { CONTRACT_INTERFACES } from "../../../constants"; +import { isBaseToken } from "../../../utils/token"; +import { BASE_TOKEN_ADDRESS, CONTRACT_INTERFACES } from "../../../constants"; export const defaultWithdrawalInitiatedHandler: ExtractTransferHandler = { matches: (): boolean => true, @@ -17,7 +18,7 @@ export const defaultWithdrawalInitiatedHandler: ExtractTransferHandler = { const parsedLog = parseLog(CONTRACT_INTERFACES.L2_BRIDGE, log); const tokenAddress = - parsedLog.args.l2Token === utils.ETH_ADDRESS ? utils.L2_ETH_TOKEN_ADDRESS : parsedLog.args.l2Token.toLowerCase(); + parsedLog.args.l2Token === utils.ETH_ADDRESS ? BASE_TOKEN_ADDRESS : parsedLog.args.l2Token.toLowerCase(); return { from: parsedLog.args.l2Sender.toLowerCase(), @@ -27,7 +28,7 @@ export const defaultWithdrawalInitiatedHandler: ExtractTransferHandler = { amount: parsedLog.args.amount, tokenAddress, type: TransferType.Withdrawal, - tokenType: tokenAddress === utils.L2_ETH_TOKEN_ADDRESS ? TokenType.ETH : TokenType.ERC20, + tokenType: isBaseToken(tokenAddress) ? TokenType.BaseToken : TokenType.ERC20, isFeeOrRefund: false, logIndex: log.logIndex, transactionIndex: log.transactionIndex, diff --git a/packages/data-fetcher/src/transfer/transfer.service.spec.ts b/packages/data-fetcher/src/transfer/transfer.service.spec.ts index a2f4e22996..bc9f726b26 100644 --- a/packages/data-fetcher/src/transfer/transfer.service.spec.ts +++ b/packages/data-fetcher/src/transfer/transfer.service.spec.ts @@ -92,7 +92,6 @@ describe("TransferService", () => { describe("eth", () => { describe("deposit with no fee", () => { const txReceipt = toTxReceipt(ethDepositNoFee); - it("returns proper transfers", async () => { const expectedTransfers = [ { @@ -101,7 +100,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0xd206eaf6819007535e893410cfa01885ce40e99a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x7cc7cc0326af164b15de04de3b153a7a55afb14a7897298a0a84f9507d483d1d", type: "deposit", isFeeOrRefund: false, @@ -116,7 +115,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x7cc7cc0326af164b15de04de3b153a7a55afb14a7897298a0a84f9507d483d1d", type: "transfer", isFeeOrRefund: false, @@ -131,7 +130,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0xd206eaf6819007535e893410cfa01885ce40e99a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x7cc7cc0326af164b15de04de3b153a7a55afb14a7897298a0a84f9507d483d1d", type: "deposit", isFeeOrRefund: false, @@ -164,7 +163,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x2386f26fc10000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "deposit", isFeeOrRefund: false, isInternal: false, @@ -179,7 +178,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x2386f26fc10000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "transfer", isFeeOrRefund: false, isInternal: false, @@ -194,7 +193,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x0141b56ff62900"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -209,7 +208,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x29eb1faec300"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -241,7 +240,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x11c37937e08000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "deposit", isFeeOrRefund: false, isInternal: false, @@ -256,7 +255,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x11c37937e08000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "transfer", isFeeOrRefund: false, isInternal: false, @@ -271,7 +270,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x0150b5fa93bf00"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -286,7 +285,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0xdb01bc43a500"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -318,7 +317,7 @@ describe("TransferService", () => { blockNumber: 7485219, amount: BigNumber.from("0x010425b6917e00"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -333,7 +332,7 @@ describe("TransferService", () => { blockNumber: 7485219, amount: BigNumber.from("0x7c948f3acf00"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -364,7 +363,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xc697e19d80645ec37df566e1227edad4652d010e43c508bbd04efbaeb47e2c48", type: "fee", isFeeOrRefund: true, @@ -379,7 +378,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0xc9593dc3dcad5f3804aaa5af12a9d74d0c00e4b0", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xc697e19d80645ec37df566e1227edad4652d010e43c508bbd04efbaeb47e2c48", type: "transfer", isFeeOrRefund: false, @@ -409,7 +408,7 @@ describe("TransferService", () => { from: "0xd2229549f09af28dd0c21b1ade77f739aa8406b5", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x4ae2d3cf9b7e4d25b4323f7e8715521172bda4dfc88cfaf6b40c8cf80165b985", type: "fee", isFeeOrRefund: true, @@ -424,7 +423,7 @@ describe("TransferService", () => { from: "0xd2229549f09af28dd0c21b1ade77f739aa8406b5", to: "0x0000000000000000000000000000000000000000", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x4ae2d3cf9b7e4d25b4323f7e8715521172bda4dfc88cfaf6b40c8cf80165b985", type: "transfer", isFeeOrRefund: false, @@ -456,7 +455,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x69d3dcb5822096bab259dbba2a1b42bdfd6d1e5c4169196893cf1998ab2ca85f", type: "fee", isFeeOrRefund: true, @@ -471,7 +470,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x000000000000000000000000000000000000800a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x69d3dcb5822096bab259dbba2a1b42bdfd6d1e5c4169196893cf1998ab2ca85f", type: "transfer", isFeeOrRefund: false, @@ -486,7 +485,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x69d3dcb5822096bab259dbba2a1b42bdfd6d1e5c4169196893cf1998ab2ca85f", type: "withdrawal", isFeeOrRefund: false, @@ -501,7 +500,7 @@ describe("TransferService", () => { from: "0x0000000000000000000000000000000000008001", to: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x69d3dcb5822096bab259dbba2a1b42bdfd6d1e5c4169196893cf1998ab2ca85f", type: "refund", isFeeOrRefund: true, @@ -533,7 +532,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "fee", isFeeOrRefund: true, @@ -548,7 +547,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x000000000000000000000000000000000000800a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "transfer", isFeeOrRefund: false, @@ -563,7 +562,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0xd206eaf6819007535e893410cfa01885ce40e99a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "withdrawal", isFeeOrRefund: false, @@ -578,7 +577,7 @@ describe("TransferService", () => { from: "0x0000000000000000000000000000000000008001", to: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "refund", isFeeOrRefund: true, @@ -610,7 +609,7 @@ describe("TransferService", () => { blockNumber: 7508823, amount: BigNumber.from("0xb782effd8200"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -625,7 +624,7 @@ describe("TransferService", () => { blockNumber: 7508823, amount: BigNumber.from("0x00"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "withdrawal", isFeeOrRefund: false, isInternal: false, @@ -640,7 +639,7 @@ describe("TransferService", () => { blockNumber: 7508823, amount: BigNumber.from("0x71e06f110780"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -670,7 +669,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "fee", isFeeOrRefund: true, @@ -685,7 +684,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0x000000000000000000000000000000000000800a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "transfer", isFeeOrRefund: false, @@ -700,7 +699,7 @@ describe("TransferService", () => { from: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", to: "0xd206eaf6819007535e893410cfa01885ce40e99a", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "withdrawal", isFeeOrRefund: false, @@ -715,7 +714,7 @@ describe("TransferService", () => { from: "0x0000000000000000000000000000000000008001", to: "0xd754ff5e8a6f257e162f72578a4bb0493c0681d8", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x33bfd18a0aea94ba39742a9a1df595462322ecbbb25c0f767a0bf6acb41dfb2f", type: "refund", isFeeOrRefund: true, @@ -794,7 +793,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xf8835220234eecd1a6dfd4dc1be8594e6f076d73107497b665a97a6d694320ad", type: "fee", isFeeOrRefund: true, @@ -840,7 +839,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x37f670de38b93e28c3ecf5ede9b4c96a4d26f2aa6c53bb6ffc7a040f559d8abb", type: "fee", isFeeOrRefund: true, @@ -901,7 +900,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x85dc1a3b141cdc67ed5f787c688d9ea8976363c875b5c4d3347cac69bcd23108", type: "fee", isFeeOrRefund: true, @@ -964,7 +963,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x7ec71b1d5369b830af3f7af4b1ef0f04e62cc3775b1c090434a93493d1b68632", type: "fee", isFeeOrRefund: true, @@ -995,7 +994,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xaa4f89b2adc9ae0fc50d058ebc7d75ddd54b0d83c307474b09989def4a0f2fbe", type: "fee", isFeeOrRefund: true, @@ -1028,7 +1027,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x55f31c010dc9ae929e192cd9950027e09b647543b3d7b0f866cb74bc7941009d", type: "fee", isFeeOrRefund: true, @@ -1121,7 +1120,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x11c37937e08000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "deposit", isFeeOrRefund: false, isInternal: false, @@ -1136,7 +1135,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x11c37937e08000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "transfer", isFeeOrRefund: false, isInternal: false, @@ -1151,7 +1150,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0x0150b5fa93bf00"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -1166,7 +1165,7 @@ describe("TransferService", () => { blockNumber: 7483775, amount: BigNumber.from("0xdb01bc43a500"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -1196,7 +1195,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xbb9c4b21c235ada7be48da89ca574dfb3c1f9126f3b879060ace14e37239053d", type: "fee", isFeeOrRefund: true, @@ -1243,7 +1242,7 @@ describe("TransferService", () => { blockNumber: 7492781, amount: BigNumber.from("0xc51affb6ed80"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -1288,7 +1287,7 @@ describe("TransferService", () => { blockNumber: 7492781, amount: BigNumber.from("0x780bd72ca280"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "refund", isFeeOrRefund: true, isInternal: false, @@ -1320,7 +1319,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x9a9218b64947ffc0e7993c1dd2cbc3377b33c0773a445662e8c833ed17369cf3", type: "fee", isFeeOrRefund: true, @@ -1335,7 +1334,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x9a9218b64947ffc0e7993c1dd2cbc3377b33c0773a445662e8c833ed17369cf3", type: "transfer", isFeeOrRefund: false, @@ -1350,7 +1349,7 @@ describe("TransferService", () => { from: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", to: "0x65ebd487e692d688f2a36fb833729076dc85ed34", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x9a9218b64947ffc0e7993c1dd2cbc3377b33c0773a445662e8c833ed17369cf3", type: "transfer", isFeeOrRefund: false, @@ -1395,7 +1394,7 @@ describe("TransferService", () => { from: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", to: "0x65ebd487e692d688f2a36fb833729076dc85ed34", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x9a9218b64947ffc0e7993c1dd2cbc3377b33c0773a445662e8c833ed17369cf3", type: "transfer", isFeeOrRefund: false, @@ -1471,7 +1470,7 @@ describe("TransferService", () => { from: "0x0265d9a5af8af5fe070933e5e549d8fef08e09f4", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xeae0368e1457fa55da486ffc772cc654d3d5b95faa220fa971ff73077fccd370", type: "fee", isFeeOrRefund: true, @@ -1486,7 +1485,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xeae0368e1457fa55da486ffc772cc654d3d5b95faa220fa971ff73077fccd370", type: "transfer", isFeeOrRefund: false, @@ -1501,7 +1500,7 @@ describe("TransferService", () => { from: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", to: "0x65ebd487e692d688f2a36fb833729076dc85ed34", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xeae0368e1457fa55da486ffc772cc654d3d5b95faa220fa971ff73077fccd370", type: "transfer", isFeeOrRefund: false, @@ -1546,7 +1545,7 @@ describe("TransferService", () => { from: "0x08b222f412eb5d141fb32db443f2eed06ae65a24", to: "0x65ebd487e692d688f2a36fb833729076dc85ed34", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xeae0368e1457fa55da486ffc772cc654d3d5b95faa220fa971ff73077fccd370", type: "transfer", isFeeOrRefund: false, @@ -1622,7 +1621,7 @@ describe("TransferService", () => { from: "0x0265d9a5af8af5fe070933e5e549d8fef08e09f4", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x8ed4aa94bb4a28ce174e435d60297d765885dff83a543b49ad57adedec99cfe3", type: "fee", isFeeOrRefund: true, @@ -1637,7 +1636,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0xbba0cf82ce98acd455bd34d7a53bb565a31372a6", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x8ed4aa94bb4a28ce174e435d60297d765885dff83a543b49ad57adedec99cfe3", type: "transfer", isFeeOrRefund: false, @@ -1652,7 +1651,7 @@ describe("TransferService", () => { from: "0xbba0cf82ce98acd455bd34d7a53bb565a31372a6", to: "0x65ebd487e692d688f2a36fb833729076dc85ed34", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x8ed4aa94bb4a28ce174e435d60297d765885dff83a543b49ad57adedec99cfe3", type: "transfer", isFeeOrRefund: false, @@ -1667,7 +1666,7 @@ describe("TransferService", () => { from: "0xbba0cf82ce98acd455bd34d7a53bb565a31372a6", to: "0xc9593dc3dcad5f3804aaa5af12a9d74d0c00e4b0", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x8ed4aa94bb4a28ce174e435d60297d765885dff83a543b49ad57adedec99cfe3", type: "transfer", isFeeOrRefund: false, @@ -1700,7 +1699,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xc36a1b2d19085fbeff652e618a1e61d6d386f92cbe51373eac60077bb128b7cb", type: "fee", isFeeOrRefund: true, @@ -1731,7 +1730,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x30e3abe6ac3a1b47d961213e1b1302377786f5cd537a6cd34dd3cd6473a319d0", type: "fee", isFeeOrRefund: true, @@ -1778,7 +1777,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x4833645ed34e16c9e2ce4d26fee2d730202ab3e76c0cd155557e7bb9344990be", type: "fee", isFeeOrRefund: true, @@ -1809,7 +1808,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x6bedb809e97f58d987aea7aad4fcfa8a3f5ecc3cde9a97093b2f3a1a170692a0", type: "fee", isFeeOrRefund: true, @@ -1873,7 +1872,7 @@ describe("TransferService", () => { from: "0x0265d9a5af8af5fe070933e5e549d8fef08e09f4", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x191c7e02d6a78b6da6116ea8347f3560627caa4b7fbf766f96eccbd09bacc433", type: "fee", isFeeOrRefund: true, @@ -1906,7 +1905,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x2b9153e896c0d2651d2826e8e1a447c5e56a3e060ae7d60c2c0bfbcd966e4880", type: "fee", isFeeOrRefund: true, @@ -1952,7 +1951,7 @@ describe("TransferService", () => { from: "0xd206eaf6819007535e893410cfa01885ce40e99a", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x8a7a99459d2278c83a8450cc36c0e5b75bee250a60e4b66dea182325afd8fa07", type: "fee", isFeeOrRefund: true, @@ -1990,7 +1989,7 @@ describe("TransferService", () => { from: "0x088282b61a8cc1014186076698e35bcc92e88b0d", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xb12a02697dd2a0e414cb8f9436c6fb7a8eb82eb403e256644235a0c618ef508d", type: "fee", isFeeOrRefund: true, @@ -2020,7 +2019,7 @@ describe("TransferService", () => { from: "0x0000000000000000000000000000000000008001", to: "0x088282b61a8cc1014186076698e35bcc92e88b0d", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0xb12a02697dd2a0e414cb8f9436c6fb7a8eb82eb403e256644235a0c618ef508d", type: "refund", isFeeOrRefund: true, @@ -2116,7 +2115,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x2386f26fc10000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "deposit", isFeeOrRefund: false, isInternal: false, @@ -2131,7 +2130,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x2386f26fc10000"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "transfer", isFeeOrRefund: false, isInternal: false, @@ -2146,7 +2145,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x0141b56ff62900"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -2178,7 +2177,7 @@ describe("TransferService", () => { blockNumber: 7485644, amount: BigNumber.from("0x0141b56ff62900"), tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, type: "fee", isFeeOrRefund: true, isInternal: false, @@ -2209,7 +2208,7 @@ describe("TransferService", () => { from: "0x481e48ce19781c3ca573967216dee75fdcf70f54", to: "0x0000000000000000000000000000000000008001", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, transactionHash: "0x7ec71b1d5369b830af3f7af4b1ef0f04e62cc3775b1c090434a93493d1b68632", type: "fee", isFeeOrRefund: true, @@ -2240,7 +2239,7 @@ describe("TransferService", () => { timestamp: blockDate, to: "0xa9232040bf0e0aea2578a5b2243f2916dbfc0a69", tokenAddress: "0x000000000000000000000000000000000000800a", - tokenType: "ETH", + tokenType: "BASETOKEN", transactionHash: "0x0000000000000000000000000000000000000000000000000000000000000000", transactionIndex: 0, type: "transfer", diff --git a/packages/data-fetcher/src/transfer/transfer.service.ts b/packages/data-fetcher/src/transfer/transfer.service.ts index b4191a4915..117eed0329 100644 --- a/packages/data-fetcher/src/transfer/transfer.service.ts +++ b/packages/data-fetcher/src/transfer/transfer.service.ts @@ -13,7 +13,7 @@ import { ethMintFromL1Handler, ethWithdrawalToL1Handler, } from "./extractHandlers"; - +import { BASE_TOKEN_ADDRESS } from "../constants"; export enum TransferType { Deposit = "deposit", Transfer = "transfer", @@ -89,7 +89,7 @@ export class TransferService { return; } const ethDeposits = transfers.filter( - (t) => t.type === TransferType.Deposit && t.tokenAddress === utils.L2_ETH_TOKEN_ADDRESS + (t) => t.type === TransferType.Deposit && t.tokenAddress === BASE_TOKEN_ADDRESS ); const feeDeposit = ethDeposits.find((t) => t.to === utils.BOOTLOADER_FORMAL_ADDRESS); if (!feeDeposit) { diff --git a/packages/data-fetcher/src/utils/isInternalTransaction.spec.ts b/packages/data-fetcher/src/utils/isInternalTransaction.spec.ts index 3990be8302..4bd387f32b 100644 --- a/packages/data-fetcher/src/utils/isInternalTransaction.spec.ts +++ b/packages/data-fetcher/src/utils/isInternalTransaction.spec.ts @@ -2,7 +2,7 @@ import { types, utils } from "zksync-web3"; import { Transfer } from "../transfer/interfaces/transfer.interface"; import { TransferType } from "../transfer/transfer.service"; import isInternalTransaction from "./isInternalTransaction"; - +import { BASE_TOKEN_ADDRESS } from "../../src/constants"; describe("isInternalTransaction", () => { it("returns false when transfer type is not transfer", () => { expect(isInternalTransaction({ type: TransferType.Deposit } as Transfer)).toBeFalsy(); @@ -19,7 +19,7 @@ describe("isInternalTransaction", () => { isInternalTransaction( { type: TransferType.Transfer, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, from: "FROM", to: "to", } as Transfer, @@ -36,7 +36,7 @@ describe("isInternalTransaction", () => { isInternalTransaction( { type: TransferType.Transfer, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, from: "from1", to: "to", } as Transfer, @@ -53,7 +53,7 @@ describe("isInternalTransaction", () => { isInternalTransaction( { type: TransferType.Transfer, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, from: "from", to: "to1", } as Transfer, @@ -70,7 +70,7 @@ describe("isInternalTransaction", () => { isInternalTransaction( { type: TransferType.Transfer, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, from: "from1", to: "to1", } as Transfer, @@ -86,7 +86,7 @@ describe("isInternalTransaction", () => { expect( isInternalTransaction({ type: TransferType.Transfer, - tokenAddress: utils.L2_ETH_TOKEN_ADDRESS, + tokenAddress: BASE_TOKEN_ADDRESS, from: "from", to: "to1", } as Transfer) diff --git a/packages/data-fetcher/src/utils/isInternalTransaction.ts b/packages/data-fetcher/src/utils/isInternalTransaction.ts index 1283e74ee5..2587123b32 100644 --- a/packages/data-fetcher/src/utils/isInternalTransaction.ts +++ b/packages/data-fetcher/src/utils/isInternalTransaction.ts @@ -1,12 +1,13 @@ -import { types, utils } from "zksync-web3"; +import { types } from "zksync-web3"; import { Transfer } from "../transfer/interfaces/transfer.interface"; import { TransferType } from "../transfer/transfer.service"; +import { BASE_TOKEN_ADDRESS } from "../constants"; export default function isInternalTransaction(transfer: Transfer, transactionReceipt?: types.TransactionReceipt) { if (transfer.type !== TransferType.Transfer) { return false; } - if (transfer.tokenAddress.toLowerCase() !== utils.L2_ETH_TOKEN_ADDRESS.toLowerCase()) { + if (transfer.tokenAddress.toLowerCase() !== BASE_TOKEN_ADDRESS.toLowerCase()) { return false; } if ( diff --git a/packages/data-fetcher/src/utils/token.ts b/packages/data-fetcher/src/utils/token.ts new file mode 100644 index 0000000000..7e51d903e4 --- /dev/null +++ b/packages/data-fetcher/src/utils/token.ts @@ -0,0 +1,4 @@ +import { BASE_TOKEN_ADDRESS } from "../constants"; +export const isBaseToken = (tokenAddress: string): boolean => { + return BASE_TOKEN_ADDRESS.toLowerCase() === tokenAddress.toLowerCase(); +}; diff --git a/packages/worker/src/balance/balance.service.spec.ts b/packages/worker/src/balance/balance.service.spec.ts index 5a64f4dd33..91111385e7 100644 --- a/packages/worker/src/balance/balance.service.spec.ts +++ b/packages/worker/src/balance/balance.service.spec.ts @@ -91,7 +91,7 @@ describe("BalanceService", () => { address: "address4", tokenAddress: "tokenAddresses3", balance: "400", - tokenType: TokenType.ETH, + tokenType: TokenType.BaseToken, } as ChangedBalance, ]; diff --git a/packages/worker/src/blockchain/blockchain.service.ts b/packages/worker/src/blockchain/blockchain.service.ts index 06108ce16b..4ef2335b1d 100644 --- a/packages/worker/src/blockchain/blockchain.service.ts +++ b/packages/worker/src/blockchain/blockchain.service.ts @@ -177,7 +177,6 @@ export class BlockchainService implements OnModuleInit { this.bridgeAddresses = { l2Erc20DefaultBridge: bridgeAddresses.erc20L2?.toLowerCase(), }; - this.logger.debug(`L2 ERC20 Bridge is set to: ${this.bridgeAddresses.l2Erc20DefaultBridge}`); } } diff --git a/packages/worker/src/entities/addressTransfer.entity.ts b/packages/worker/src/entities/addressTransfer.entity.ts index b6b41757a4..3942942989 100644 --- a/packages/worker/src/entities/addressTransfer.entity.ts +++ b/packages/worker/src/entities/addressTransfer.entity.ts @@ -45,7 +45,7 @@ export class AddressTransfer extends BaseEntity { @Column({ type: "enum", enum: TransferType, default: TransferType.Transfer }) public readonly type: TransferType; - @Column({ type: "enum", enum: TokenType, default: TokenType.ETH }) + @Column({ type: "enum", enum: TokenType, default: TokenType.BaseToken }) public readonly tokenType: TokenType; @Column({ type: "boolean" }) diff --git a/packages/worker/src/entities/token.entity.ts b/packages/worker/src/entities/token.entity.ts index 9cead7572c..e4afefc869 100644 --- a/packages/worker/src/entities/token.entity.ts +++ b/packages/worker/src/entities/token.entity.ts @@ -7,7 +7,7 @@ import { hexTransformer } from "../transformers/hex.transformer"; import { BaseEntity } from "./base.entity"; export enum TokenType { - ETH = "ETH", + BaseToken = "BASETOKEN", ERC20 = "ERC20", ERC721 = "ERC721", } diff --git a/packages/worker/src/entities/transfer.entity.ts b/packages/worker/src/entities/transfer.entity.ts index 8411a189ed..ac0516a6bd 100644 --- a/packages/worker/src/entities/transfer.entity.ts +++ b/packages/worker/src/entities/transfer.entity.ts @@ -63,7 +63,7 @@ export class Transfer extends CountableEntity { @Column({ type: "enum", enum: TransferType, default: TransferType.Transfer }) public readonly type: TransferType; - @Column({ type: "enum", enum: TokenType, default: TokenType.ETH }) + @Column({ type: "enum", enum: TokenType, default: TokenType.BaseToken }) public readonly tokenType: TokenType; @Column({ type: "boolean" }) diff --git a/packages/worker/src/migrations/1706115493392-BaseTokenEnumVariant.ts b/packages/worker/src/migrations/1706115493392-BaseTokenEnumVariant.ts new file mode 100644 index 0000000000..10dfa09f5c --- /dev/null +++ b/packages/worker/src/migrations/1706115493392-BaseTokenEnumVariant.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class BaseTokenEnumVariant1706115493392 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TYPE "public"."transfers_tokentype_enum" RENAME VALUE 'ETH' TO 'BASETOKEN'`); + await queryRunner.query(`ALTER TYPE "public"."addressTransfers_tokentype_enum" RENAME VALUE 'ETH' TO 'BASETOKEN'`); + + await queryRunner.query(`ALTER TABLE "transfers" ALTER COLUMN "tokenType" SET DEFAULT 'BASETOKEN'`); + await queryRunner.query(`ALTER TABLE "addressTransfers" ALTER COLUMN "tokenType" SET DEFAULT 'BASETOKEN'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TYPE "public"."transfers_tokentype_enum" RENAME VALUE 'BASETOKEN' TO 'ETH'`); + await queryRunner.query(`ALTER TYPE "public"."addressTransfers_tokentype_enum" RENAME VALUE 'BASETOKEN' TO 'ETH'`); + + await queryRunner.query(`ALTER TABLE "transfers" ALTER COLUMN "tokenType" SET DEFAULT 'ETH'`); + await queryRunner.query(`ALTER TABLE "addressTransfers" ALTER COLUMN "tokenType" SET DEFAULT 'ETH'`); + } +} diff --git a/packages/worker/src/typeorm.config.ts b/packages/worker/src/typeorm.config.ts index 0c4df91531..d08f3f9e76 100644 --- a/packages/worker/src/typeorm.config.ts +++ b/packages/worker/src/typeorm.config.ts @@ -21,7 +21,6 @@ export const typeOrmModuleOptions: DataSourceOptions = { subscribers: [], migrations: ["dist/migrations/*.js"], }; - const typeOrmCliDataSource = new DataSource({ ...typeOrmModuleOptions, entities: ["src/**/*.entity.{ts,js}"],