Skip to content

Commit 2de8a2a

Browse files
committed
fix: versioning update
1 parent 815f6dc commit 2de8a2a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/versioning/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { difference, isEqual } from 'lodash'
33

44
/**
55
* Calculates a new version object from two token lists.
6-
* Important: This function assumes the input lists do not include tokens with duplicate addresses or different chainIds (which is the case when pulling with the view contract). It also assumes the token addresses are checksummed.
6+
* Important: This function assumes the input lists do not include tokens with duplicate addresses. It also assumes the token addresses are checksummed.
77
* @param previousTokens The previous list to compare the new with.
88
* @param latestTokens The new list.
99
* @param invalidTokens These are tokens that failed uniswap-tokenlists validation rules.
@@ -20,22 +20,26 @@ export function getNewErc20ListVersion(
2020
// 4- Changing a token address or chain ID is considered both a remove and an add which produce a major version update.
2121
// Note that for the case of the using a view contract, number 4 will never happen.
2222

23-
const oldTokensMapping: { [key: string]: unknown } = {}
23+
const tokenToKey = (token: TokenInfo) => `${token.chainId}:${token.address}`
24+
25+
const oldTokensMapping: { [key: string]: TokenInfo } = {}
2426
previousTokens.tokens.forEach((token: TokenInfo) => {
25-
oldTokensMapping[token.address] = token
27+
oldTokensMapping[tokenToKey(token)] = token
2628
})
2729

30+
const invalidTokenKeys = invalidTokens.map((i) => tokenToKey(i))
31+
2832
let incrementMajor = false
2933
let incrementMinor = false
3034
let incrementPatch = false
3135
for (const latestToken of latestTokens) {
32-
const previousToken = oldTokensMapping[latestToken.address]
33-
const invalidTokenAddresses = invalidTokens.map((i) => i.address)
36+
const previousToken = oldTokensMapping[tokenToKey(latestToken)]
3437

3538
if (!previousToken) {
36-
if (invalidTokenAddresses.includes(latestToken.address)) {
39+
if (invalidTokenKeys.includes(tokenToKey(latestToken))) {
3740
// Check if this token was not added because it failed uniswap
3841
// tokenlist rules.
42+
// If so, it wasn't included before either, so ignore it.
3943
continue
4044
}
4145
incrementMinor = true // Token added.
@@ -53,12 +57,12 @@ export function getNewErc20ListVersion(
5357
if (
5458
difference(
5559
Object.keys(oldTokensMapping),
56-
latestTokens.map((t) => t.address),
60+
latestTokens.map((t) => tokenToKey(t)),
5761
).length > 0
5862
) {
5963
const diff = difference(
6064
Object.keys(oldTokensMapping),
61-
latestTokens.map((t) => t.address),
65+
latestTokens.map((t) => tokenToKey(t)),
6266
)
6367
console.info('diff:', diff)
6468
incrementMajor = true

0 commit comments

Comments
 (0)