-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: baseTokens & chainIds #43
Merged
+1,712
−194
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,42 +17,44 @@ import { | |
BatchesInfo, | ||
ChainId, | ||
ChainType, | ||
erc20Tokens, | ||
ETH_TOKEN_ADDRESS, | ||
nativeToken, | ||
Token, | ||
TokenType, | ||
vitalikAddress, | ||
WETH, | ||
} from "@zkchainhub/shared"; | ||
import { nativeToken, WETH } from "@zkchainhub/shared/tokens/tokens"; | ||
|
||
// Mock implementations of the dependencies | ||
const mockEvmProviderService = createMock<EvmProviderService>(); | ||
|
||
const mockPricingService = createMock<IPricingService>(); | ||
|
||
const ONE_ETHER = parseEther("1"); | ||
jest.mock("@zkchainhub/shared/tokens/tokens", () => ({ | ||
...jest.requireActual("@zkchainhub/shared/tokens/tokens"), | ||
get erc20Tokens() { | ||
return [ | ||
{ | ||
name: "USDC", | ||
symbol: "USDC", | ||
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", | ||
coingeckoId: "usd-coin", | ||
imageUrl: | ||
"https://coin-images.coingecko.com/coins/images/6319/large/usdc.png?1696506694", | ||
type: "erc20", | ||
decimals: 6, | ||
}, | ||
{ | ||
name: "Wrapped BTC", | ||
symbol: "WBTC", | ||
contractAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", | ||
coingeckoId: "wrapped-bitcoin", | ||
imageUrl: | ||
"https://coin-images.coingecko.com/coins/images/7598/large/wrapped_bitcoin_wbtc.png?1696507857", | ||
type: "erc20", | ||
decimals: 8, | ||
}, | ||
]; | ||
jest.mock("@zkchainhub/shared/constants/token", () => ({ | ||
...jest.requireActual("@zkchainhub/shared/constants/token"), | ||
erc20Tokens: { | ||
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": { | ||
name: "USDC", | ||
symbol: "USDC", | ||
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", | ||
coingeckoId: "usd-coin", | ||
imageUrl: | ||
"https://coin-images.coingecko.com/coins/images/6319/large/usdc.png?1696506694", | ||
type: "erc20", | ||
decimals: 6, | ||
}, | ||
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": { | ||
name: "Wrapped BTC", | ||
symbol: "WBTC", | ||
contractAddress: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", | ||
coingeckoId: "wrapped-bitcoin", | ||
imageUrl: | ||
"https://coin-images.coingecko.com/coins/images/7598/large/wrapped_bitcoin_wbtc.png?1696507857", | ||
type: "erc20", | ||
decimals: 8, | ||
}, | ||
}, | ||
get tokens() { | ||
return [ | ||
|
@@ -785,7 +787,29 @@ describe("L1MetricsService", () => { | |
}); | ||
|
||
describe("getBaseTokens", () => { | ||
it("returns baseTokens", async () => { | ||
it("returns known tokens", async () => { | ||
const mockedChainIds = [1n, 2n]; | ||
const knownTokenAddress1 = Object.keys(erc20Tokens)[0]; | ||
const knownTokenAddress2 = Object.keys(erc20Tokens)[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the duplicated usage of the |
||
|
||
if (!knownTokenAddress1 || !knownTokenAddress2) { | ||
throw new Error("ERC20 tokens are not defined"); | ||
} | ||
const mockedMulticallReturnValue = [knownTokenAddress1, knownTokenAddress2]; | ||
jest.spyOn(mockEvmProviderService, "multicall").mockResolvedValue( | ||
mockedMulticallReturnValue, | ||
); | ||
const mockedReturnData: Token<TokenType>[] = [ | ||
erc20Tokens[knownTokenAddress1 as Address] as Token<"erc20">, | ||
erc20Tokens[knownTokenAddress2 as Address] as Token<"erc20">, | ||
]; | ||
|
||
const result = await l1MetricsService.getBaseTokens(mockedChainIds); | ||
|
||
expect(result).toEqual(mockedReturnData); | ||
}); | ||
|
||
it("returns unknown tokens", async () => { | ||
const mockedChainIds = [1n, 2n]; | ||
const mockedMulticallReturnValue = [ | ||
"0x1234567890123456789012345678901234567123", | ||
|
@@ -794,12 +818,30 @@ describe("L1MetricsService", () => { | |
jest.spyOn(mockEvmProviderService, "multicall").mockResolvedValue( | ||
mockedMulticallReturnValue, | ||
); | ||
const mockedReturnData: Token<TokenType>[] = [ | ||
{ | ||
contractAddress: "0x1234567890123456789012345678901234567123", | ||
symbol: "unknown", | ||
name: "unknown", | ||
decimals: 18, | ||
type: "erc20", | ||
coingeckoId: "unknown", | ||
}, | ||
{ | ||
contractAddress: "0x1234567890123456789012345678901234567345", | ||
symbol: "unknown", | ||
name: "unknown", | ||
decimals: 18, | ||
type: "erc20", | ||
coingeckoId: "unknown", | ||
}, | ||
]; | ||
|
||
const result = await l1MetricsService.getBaseTokens(mockedChainIds); | ||
|
||
expect(result).toEqual(mockedMulticallReturnValue); | ||
expect(result).toEqual(mockedReturnData); | ||
}); | ||
it("returns baseTokens", async () => { | ||
it("returns empty array if chainIds is empty", async () => { | ||
const mockedChainIds: ChainId[] = []; | ||
const result = await l1MetricsService.getBaseTokens(mockedChainIds); | ||
expect(result).toEqual([]); | ||
|
@@ -809,6 +851,11 @@ describe("L1MetricsService", () => { | |
jest.spyOn(mockEvmProviderService, "multicall").mockRejectedValue(new Error()); | ||
await expect(l1MetricsService.getBaseTokens(mockedChainIds)).rejects.toThrow(Error); | ||
}); | ||
it("returns eth token", async () => { | ||
const mockedChainIds: ChainId[] = [1n, 2n]; | ||
jest.spyOn(mockEvmProviderService, "multicall").mockRejectedValue(new Error()); | ||
await expect(l1MetricsService.getBaseTokens(mockedChainIds)).rejects.toThrow(Error); | ||
}); | ||
}); | ||
|
||
describe("feeParams", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./addresses"; | ||
export * from "./token"; | ||
export const TOKEN_CACHE_TTL_IN_SEC = 60; | ||
export const BASE_CURRENCY = "usd"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add a task to enhancements to fetch decimals, name and symbol from the contract now that i think of it but for now it's good since we know that baseTokens are permisioned and practically it'll be Ether most of the times