Skip to content

Commit

Permalink
Merge pull request #43 from IndexCoop/task/update-tokenlists-test
Browse files Browse the repository at this point in the history
  • Loading branch information
janndriessen authored Oct 3, 2024
2 parents 3555fc1 + 29334d5 commit 4c7b53d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 120 deletions.
145 changes: 38 additions & 107 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"access": "public"
},
"dependencies": {
"@indexcoop/tokenlists": "1.54.0",
"@nsorcell/exp-tokenlist": "1.18.0",
"ethers": "5.7.2"
}
}
10 changes: 8 additions & 2 deletions src/providers/analytics/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { utils } from "ethers"
import { getIndexTokenDataByAddress } from "@indexcoop/tokenlists"
import {
getChainProductTokenList,
isAddressEqual,
} from "@nsorcell/exp-tokenlist"

import {
CoinGeckoService,
Expand Down Expand Up @@ -58,7 +61,10 @@ export class IndexAnalyticsProvider implements AnalyticsProvider {
include24hrVolume: true,
},
): Promise<IndexAnalytics> {
const token = getIndexTokenDataByAddress(address, chainId)
const indices = getChainProductTokenList(chainId)
const token = indices.find((token) =>
isAddressEqual(token.address, address),
)
if (!token) {
throw new Error("Unknown index token or wrong chainId")
}
Expand Down
6 changes: 3 additions & 3 deletions src/providers/nav/fli-nav-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getIndexTokenData } from "@indexcoop/tokenlists"
import { getTokenByChainAndSymbol } from "@nsorcell/exp-tokenlist"

import { buildAlchemyProvider, CoinGeckoService } from "../../utils"
import { FliNavProvider } from "./fli-nav-provider"
Expand All @@ -9,14 +9,14 @@ const rpcProvider = buildAlchemyProvider(1, process.env.ALCHEMY_API_KEY!)

describe("FliNavProvider", () => {
test("returns NAV for BTC2x-FLI", async () => {
const btc2xfli = getIndexTokenData("BTC2x-FLI")!.address
const btc2xfli = getTokenByChainAndSymbol(1, "BTC2x-FLI").address
const provider = new FliNavProvider(rpcProvider, coingeckoService)
const nav = await provider.getNav(btc2xfli)
expect(nav).toBeGreaterThan(1)
})

test("returns NAV for ETH2xFLI", async () => {
const eth2xfli = getIndexTokenData("ETH2x-FLI")!.address
const eth2xfli = getTokenByChainAndSymbol(1, "ETH2x-FLI").address
const provider = new FliNavProvider(rpcProvider, coingeckoService)
const nav = await provider.getNav(eth2xfli)
expect(nav).toBeGreaterThan(1)
Expand Down
17 changes: 10 additions & 7 deletions src/providers/nav/fli-nav-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { providers, utils } from "ethers"

import { getIndexTokenData } from "@indexcoop/tokenlists"
import {
getTokenByChainAndAddress,
getTokenByChainAndSymbol,
} from "@nsorcell/exp-tokenlist"

import { CoinGeckoService } from "utils/coingecko"
import { getPositions } from "../../utils/positions"
Expand All @@ -18,13 +21,13 @@ export class FliNavProvider {
async getNav(address: string): Promise<number> {
const { coingeckoService, provider } = this
const positions = await getPositions(address, provider)
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const isEth2xFli =
address.toLowerCase() ===
getIndexTokenData("ETH2x-FLI")!.address.toLowerCase()
const component = getIndexTokenData(isEth2xFli ? "ETH2X" : "BTC2X")!.address
const componentSymbol =
getTokenByChainAndAddress(1, address)?.symbol === "ETH2x-FLI"
? "ETH2X"
: "BTC2X"
const component = getTokenByChainAndSymbol(1, componentSymbol)
const navProvider = new IndexNavProvider(provider, coingeckoService)
const fliNav = await navProvider.getNav(component)
const fliNav = await navProvider.getNav(component.address)
const unit = utils.formatUnits(positions[0].unit.toString(), 18)
const nav = Number(unit) * fliNav
return nav
Expand Down

0 comments on commit 4c7b53d

Please sign in to comment.