Skip to content
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

perf: minimise asset data size #8423

Merged
merged 58 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
bd04c84
fix: dont use stale related asset data when generating the related as…
woodenfurniture Dec 20, 2024
84fc3e5
Revert "fix: dont use stale related asset data when generating the re…
woodenfurniture Dec 20, 2024
b38b23f
fix: dont use stale related asset data when generating the related as…
woodenfurniture Dec 20, 2024
065070f
chore regenerate related asset index
woodenfurniture Dec 20, 2024
9e52b92
fix: dont choose a relatedAssetKey for an asset we dont have data for
woodenfurniture Dec 20, 2024
c645cd6
chore: regenerate relatedAssetIndex.json
woodenfurniture Dec 20, 2024
2f2dfde
measure time spent fetching top 1000 assets on boot
woodenfurniture Dec 18, 2024
5fc8821
perf: load assets on boot without redux rain dance
woodenfurniture Dec 18, 2024
08813ee
chore: remove unused action
woodenfurniture Dec 18, 2024
046f2ec
chore: cleanup getAssetDescription a bit
woodenfurniture Dec 18, 2024
7d880ca
chore: use createThrottle from utils
woodenfurniture Dec 18, 2024
df6d1e2
feat: implemented asset data encoder and decoder
woodenfurniture Dec 19, 2024
6de2e87
chore: add asset with relatedAssetKey to test data
woodenfurniture Dec 19, 2024
e36b55c
chore: ensure test checks assetId sorting
woodenfurniture Dec 19, 2024
1bfff4c
feat: dont encode base assets
woodenfurniture Dec 19, 2024
bebee27
chore: update coingecko utils to support specifying page meta
woodenfurniture Dec 19, 2024
92dc716
feat: update asset generation script to consume asset data encoder
woodenfurniture Dec 19, 2024
ea07719
feat: asset data encoding reconciling against full dataset
woodenfurniture Dec 19, 2024
0841e99
feat: compress assetIds
woodenfurniture Dec 20, 2024
3d8dd3f
chore: revert changes to generatedAssetData.json
woodenfurniture Dec 20, 2024
a6e0264
Merge branch 'develop' into asset-list-sorting
woodenfurniture Jan 1, 2025
126c637
feat: encode relatedAsssetIndex
woodenfurniture Jan 1, 2025
cd94ede
chore: cleanup temporary asset data files
woodenfurniture Jan 1, 2025
8c0d212
feat: wire up encoding to generation scripts
woodenfurniture Jan 1, 2025
0ba1545
feat: created migration utility to upgrade the asset data to new schema
woodenfurniture Jan 2, 2025
d4edc53
fix: migration utility should actually work
woodenfurniture Jan 2, 2025
be34d21
feat: initial migrated asset data
woodenfurniture Jan 2, 2025
7fd2020
Merge branch 'develop' into asset-list-sorting
woodenfurniture Jan 3, 2025
cb09142
chore: regenerate asset data
woodenfurniture Jan 3, 2025
b0c94b7
feat: wire in encoded asset data to asset service
woodenfurniture Jan 3, 2025
582890f
feat: use singleton pattern for asset service
woodenfurniture Jan 3, 2025
d311bb4
fix: skill issue passing data
woodenfurniture Jan 3, 2025
dce2ad7
chore: update asset service in tests
woodenfurniture Jan 3, 2025
118d739
chore: update tsconfig.json
woodenfurniture Jan 3, 2025
8c99306
chore: remove unused CSP entry
woodenfurniture Jan 3, 2025
0210fe3
chore: avoid re-import of asset data
woodenfurniture Jan 3, 2025
69c3464
chore: simplify asset selectors
woodenfurniture Jan 3, 2025
6dbf3c8
chore: linting
woodenfurniture Jan 5, 2025
dc5fd23
fix: mutation of readonly objects
woodenfurniture Jan 5, 2025
fe2c679
fix: broken exhaustiveness checks in switch statements
woodenfurniture Jan 5, 2025
0553bba
fix: add missing export
woodenfurniture Jan 5, 2025
f8d3312
fix: asset generation script
woodenfurniture Jan 6, 2025
8f7d405
fix: wrong filepaths for asset gen sript
woodenfurniture Jan 6, 2025
fbcfda5
chore: revert migration increment
woodenfurniture Jan 6, 2025
2dc5981
Merge branch 'develop' into asset-list-sorting
woodenfurniture Jan 6, 2025
536d9b3
fix: consume base assets from compiled package
woodenfurniture Jan 7, 2025
56d89bb
chore: cleanup
woodenfurniture Jan 7, 2025
96ce4cf
chore: delete unused tests for asset data
woodenfurniture Jan 7, 2025
7afaa73
chore: use correct naming for icon decoding
woodenfurniture Jan 7, 2025
ebc1cd0
chore: use correct naming for relatedAssetKey decoding
woodenfurniture Jan 7, 2025
d3df239
chore: better readability for isPool decoding
woodenfurniture Jan 7, 2025
f83b54f
feat: increase page size to 250
woodenfurniture Jan 7, 2025
b1e6cf3
chore: exhaustiveness for assetNamespace switch
woodenfurniture Jan 7, 2025
0472e75
Merge branch 'develop' into asset-list-sorting
woodenfurniture Jan 7, 2025
7b96686
chore: resync asset data
woodenfurniture Jan 7, 2025
dd7b979
chore: delete migration script
woodenfurniture Jan 7, 2025
b346f56
chore: delete generatedAssetData.json and relatedAssetIndex.json
woodenfurniture Jan 7, 2025
3f6a39f
chore: update tsconfig.json
woodenfurniture Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"generate:caip-adapters": "yarn workspace @shapeshiftoss/caip generate",
"generate:asset-data": "yarn tsx ./scripts/generateAssetData/generateAssetData.ts && yarn run codemod:clear-assets-migration",
"generate:related-asset-index": "yarn tsx ./scripts/generateAssetData/generateRelatedAssetIndex.ts && yarn run codemod:clear-assets-migration",
"generate:encode-asset-data": "yarn tsx ./scripts/encodeAssetData.ts",
"generate:color-map": "yarn tsx ./scripts/generateAssetData/generateColorMap.ts",
"generate:thor-asset-map": "yarn tsx ./scripts/generateTradableThorAssetMap/generateTradableThorAssetMap.ts",
"generate:thor-longtail-tokens": "yarn tsx ./scripts/generateThorLongtailTokens/generateThorLongtailTokens.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/ethersProviderSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const rpcUrlByChainId = (chainId: EvmChainId): string => {
case KnownChainIds.BaseMainnet:
return process.env.REACT_APP_BASE_NODE_URL
default:
assertUnreachable(chainId)
return assertUnreachable(chainId)
}
})()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const fetchArbitrumBridgeSwap = async <T extends 'quote' | 'rate'>({
return { request: maybeRequest, networkFeeCryptoBaseUnit, allowanceContract: '0x0' }
}
default:
assertUnreachable(bridgeType)
return assertUnreachable(bridgeType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ export const getThorTradeQuote = async (
case TradeType.LongTailToLongTail:
return Err(makeSwapErrorRight({ message: 'Not implemented yet' }))
default:
assertUnreachable(tradeType)
return assertUnreachable(tradeType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ export const getThorTradeRate = async (
case TradeType.LongTailToLongTail:
return Err(makeSwapErrorRight({ message: 'Not implemented yet' }))
default:
assertUnreachable(tradeType)
return assertUnreachable(tradeType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const checkOutputTxConfirmations = async (
case ThorchainChain.BSC:
throw Error(`${latestOutTx.chain} not supported`)
default:
assertUnreachable(latestOutTx.chain)
return assertUnreachable(latestOutTx.chain)
}
})()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,6 @@ export const getL1Rate = async (
}

default:
assertUnreachable(chainNamespace)
return assertUnreachable(chainNamespace)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,6 @@ export const getL1Quote = async (
}

default:
assertUnreachable(chainNamespace)
return assertUnreachable(chainNamespace)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const getLatestThorTxStatusMessage = (
: 'Outbound transaction scheduled, waiting on destination chain...'
}
default:
assertUnreachable(key)
return assertUnreachable(key)
}
}
}
150 changes: 150 additions & 0 deletions packages/utils/src/assetData/assetData.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import type { AssetsById } from '@shapeshiftoss/types'
import fs from 'fs'
import path from 'path'
import { describe, expect, it } from 'vitest'

import { decodeAssetData } from './decodeAssetData'
import { encodeAssetData } from './encodeAssetData'

const mockGeneratedAssetData: AssetsById = {
'bip122:000000000019d6689c085ae165831e93/slip44:0': {
assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
chainId: 'bip122:000000000019d6689c085ae165831e93',
symbol: 'BTC',
name: 'Bitcoin',
networkName: 'Bitcoin',
precision: 8,
color: '#FF9800',
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/bitcoin/info/logo.png',
explorer: 'https://live.blockcypher.com',
explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
relatedAssetKey: null,
},
'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c': {
assetId: 'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
chainId: 'eip155:1',
name: 'Inception Restaked ETH on Ethereum',
precision: 18,
color: '#D6D1E4',
icon: 'https://assets.coingecko.com/coins/images/34127/large/inETH.png?1715036464',
symbol: 'INETH',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: 'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
},
'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd': {
assetId: 'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd',
chainId: 'eip155:1',
name: 'EveryCoin',
precision: 12,
color: '#0483CB',
icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xEEd3aE7b0F8b5B9BB8C035A9941382B1822671CD/logo.png',
symbol: 'EVY',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: null,
},
'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d': {
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
color: '#FFFFFF',
icon: undefined,
icons: [
'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xD9A442856C234a39a81a089C06451EBAa4306a72/logo.png',
'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0/logo.png',
],
name: 'Curve PUFETH/WSTETH Pool',
precision: 18,
symbol: 'pufETHwstE',
chainId: 'eip155:1',
assetId: 'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d',
relatedAssetKey: null,
isPool: true,
},
'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf': {
assetId: 'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf',
chainId: 'eip155:1',
name: 'The QWAN',
precision: 18,
color: '#18B6BE',
icon: 'https://assets.coingecko.com/coins/images/30613/large/qwan.jpg?1696529482',
symbol: 'QWAN',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: null,
},
'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33': {
assetId: 'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33',
chainId: 'eip155:1',
name: 'Big Tom',
precision: 9,
color: '#27DD08',
icon: 'https://assets.coingecko.com/coins/images/38555/large/huyah_%281%29.jpg?1717999187',
symbol: 'TOM',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: null,
},
'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f': {
assetId: 'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f',
chainId: 'eip155:1',
name: 'Forgotten Playland',
precision: 18,
color: '#35355D',
icon: 'https://assets.coingecko.com/coins/images/35339/large/200.png?1708515043',
symbol: 'FP',
explorer: 'https://etherscan.io',
explorerAddressLink: 'https://etherscan.io/address/',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: null,
},
}

// Order of these is deliberately shuffled to test sorting is preserved
const mockSortedAssetIds = [
'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33', // big tom
'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f', // forgotten playland
'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd', // everycoin
'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c', // Inception Restaked ETH on Ethereum
'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf', // the qwan
'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d', // Curve PUFETH/WSTETH Pool
'bip122:000000000019d6689c085ae165831e93/slip44:0', // BTC
]

describe('assetData', () => {
it('can encode and decode asset data as a complete round trip', () => {
const encodedAssetData = encodeAssetData(mockSortedAssetIds, mockGeneratedAssetData)
const { assetData, sortedAssetIds } = decodeAssetData(encodedAssetData)
expect(assetData).toEqual(mockGeneratedAssetData)
expect(sortedAssetIds).toEqual(mockSortedAssetIds)
})

// Used to check correctness of encode/decode before we migrated to storing encoded asset data
it.skip('reconciles against full dataset', () => {
const generatedAssetsPath = path.join(
__dirname,
'../../../../src/lib/asset-service/service/generatedAssetData.json',
)

const removeUndefined = (obj: object) => JSON.parse(JSON.stringify(obj))

const generatedAssetData = JSON.parse(fs.readFileSync(generatedAssetsPath, 'utf8'))
const assetIds = Object.keys(generatedAssetData).sort()
const encodedAssetData = encodeAssetData(assetIds, generatedAssetData)

console.time('decodeAssetData')
woodenfurniture marked this conversation as resolved.
Show resolved Hide resolved
const { assetData, sortedAssetIds } = decodeAssetData(encodedAssetData)
console.timeEnd('decodeAssetData')
woodenfurniture marked this conversation as resolved.
Show resolved Hide resolved
Object.entries(generatedAssetData).forEach(([assetId, expectedAsset]) => {
const actualAsset = assetData[assetId]
expect(removeUndefined(actualAsset)).toEqual(expectedAsset)
})
expect(sortedAssetIds).toEqual(assetIds)
})
})
Loading