From d2e112c2ea9b2c26642690685f1875160f41924e Mon Sep 17 00:00:00 2001 From: antoncoding Date: Mon, 9 Jun 2025 15:04:54 +0800 Subject: [PATCH 1/3] feat: add unichain configs --- app/api/balances/route.ts | 1 + package.json | 2 +- src/contexts/MarketsContext.tsx | 1 + src/hooks/useUserBalances.ts | 4 +- src/imgs/chains/unichain.svg | 11 +++ src/store/createWagmiConfig.ts | 4 +- src/store/supportedChains.ts | 10 +-- src/utils/external.ts | 6 ++ src/utils/morpho.ts | 10 ++- src/utils/networks.ts | 6 ++ src/utils/rpc.ts | 12 ++- src/utils/subgraph-urls.ts | 5 ++ src/utils/tokens.ts | 10 ++- yarn.lock | 152 +++++++++++++++++++++++++++++++- 14 files changed, 219 insertions(+), 15 deletions(-) create mode 100644 src/imgs/chains/unichain.svg diff --git a/app/api/balances/route.ts b/app/api/balances/route.ts index 4c7bb251..c4e6dfe9 100644 --- a/app/api/balances/route.ts +++ b/app/api/balances/route.ts @@ -5,6 +5,7 @@ const ALCHEMY_URLS = { '1': `https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, '8453': `https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, '137': `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, + '130': `https://unichain-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`, }; type TokenBalance = { diff --git a/package.json b/package.json index c6ed05bc..eb52d329 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "shikiji-core": "^0.9.17", "tailwind-merge": "^2.5.5", "unified": "^11.0.4", - "viem": "2.x", + "viem": "2.31.0", "wagmi": "^2.10.2", "workbox-webpack-plugin": "^7.0.0", "zod": "^3.24.2" diff --git a/src/contexts/MarketsContext.tsx b/src/contexts/MarketsContext.tsx index 75c265f1..0050634b 100644 --- a/src/contexts/MarketsContext.tsx +++ b/src/contexts/MarketsContext.tsx @@ -78,6 +78,7 @@ export function MarketsProvider({ children }: MarketsProviderProps) { SupportedNetworks.Mainnet, SupportedNetworks.Base, SupportedNetworks.Polygon, + SupportedNetworks.Unichain ]; let combinedMarkets: Market[] = []; let fetchErrors: unknown[] = []; diff --git a/src/hooks/useUserBalances.ts b/src/hooks/useUserBalances.ts index 52d94800..aa9d369f 100644 --- a/src/hooks/useUserBalances.ts +++ b/src/hooks/useUserBalances.ts @@ -51,10 +51,11 @@ export function useUserBalances() { try { // Fetch balances from both chains - const [mainnetBalances, baseBalances, polygonBalances] = await Promise.all([ + const [mainnetBalances, baseBalances, polygonBalances, unichainBalances] = await Promise.all([ fetchBalances(SupportedNetworks.Mainnet), fetchBalances(SupportedNetworks.Base), fetchBalances(SupportedNetworks.Polygon), + fetchBalances(SupportedNetworks.Unichain), ]); // Process and filter tokens @@ -79,6 +80,7 @@ export function useUserBalances() { processTokens(mainnetBalances, 1); processTokens(baseBalances, 8453); processTokens(polygonBalances, 137); + processTokens(unichainBalances, 130); setBalances(processedBalances); } catch (err) { setError(err instanceof Error ? err : new Error('Unknown error occurred')); diff --git a/src/imgs/chains/unichain.svg b/src/imgs/chains/unichain.svg new file mode 100644 index 00000000..bec3ea56 --- /dev/null +++ b/src/imgs/chains/unichain.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/store/createWagmiConfig.ts b/src/store/createWagmiConfig.ts index 868b9e8e..5b09a070 100644 --- a/src/store/createWagmiConfig.ts +++ b/src/store/createWagmiConfig.ts @@ -11,7 +11,7 @@ import { } from '@rainbow-me/rainbowkit/wallets'; import { safe } from '@wagmi/connectors'; import { createConfig, http } from 'wagmi'; -import { base, mainnet, polygon } from 'wagmi/chains'; +import { base, mainnet, polygon, unichain } from 'wagmi/chains'; import { getChainsForEnvironment } from './supportedChains'; const alchemyKey = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY; @@ -19,6 +19,7 @@ const alchemyKey = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY; const rpcMainnet = `https://eth-mainnet.g.alchemy.com/v2/${alchemyKey}`; const rpcBase = `https://base-mainnet.g.alchemy.com/v2/${alchemyKey}`; const rpcPolygon = `https://polygon-mainnet.g.alchemy.com/v2/${alchemyKey}`; +const rpcUnichain = `https://unichain-mainnet.g.alchemy.com/v2/${alchemyKey}`; export function createWagmiConfig(projectId: string) { const connectors = connectorsForWallets( @@ -53,6 +54,7 @@ export function createWagmiConfig(projectId: string) { [mainnet.id]: http(rpcMainnet), [base.id]: http(rpcBase), [polygon.id]: http(rpcPolygon), + [unichain.id]: http(rpcUnichain), }, connectors: [ ...connectors, diff --git a/src/store/supportedChains.ts b/src/store/supportedChains.ts index 5f208910..b16680ed 100644 --- a/src/store/supportedChains.ts +++ b/src/store/supportedChains.ts @@ -1,12 +1,12 @@ -import { base, Chain, mainnet, polygon } from 'viem/chains'; +import { base, Chain, mainnet, polygon, unichain } from 'viem/chains'; import { Environment, getCurrentEnvironment } from './environment'; // The list of supported Chains for a given environment export const SUPPORTED_CHAINS: Record = { - [Environment.localhost]: [mainnet, base, polygon], - [Environment.development]: [mainnet, base, polygon], - [Environment.staging]: [mainnet, base, polygon], - [Environment.production]: [mainnet, base, polygon], + [Environment.localhost]: [mainnet, base, polygon, unichain], + [Environment.development]: [mainnet, base, polygon, unichain], + [Environment.staging]: [mainnet, base, polygon, unichain], + [Environment.production]: [mainnet, base, polygon, unichain], }; /** diff --git a/src/utils/external.ts b/src/utils/external.ts index 43942f8b..36242c2c 100644 --- a/src/utils/external.ts +++ b/src/utils/external.ts @@ -11,6 +11,8 @@ export const getAssetURL = (address: string, chain: SupportedNetworks): string = return `https://basescan.org/token/${address}`; case SupportedNetworks.Polygon: return `https://polygonscan.com/token/${address}`; + case SupportedNetworks.Unichain: + return `https://uniscan.xyz/token/${address}`; default: return `https://etherscan.io/token/${address}`; } @@ -22,6 +24,8 @@ export const getExplorerURL = (address: string, chain: SupportedNetworks): strin return `https://basescan.org/address/${address}`; case SupportedNetworks.Polygon: return `https://polygonscan.com/address/${address}`; + case SupportedNetworks.Unichain: + return `https://uniscan.xyz/address/${address}`; default: return `https://etherscan.io/address/${address}`; } @@ -33,6 +37,8 @@ export const getExplorerTxURL = (hash: string, chain: SupportedNetworks): string return `https://basescan.org/tx/${hash}`; case SupportedNetworks.Polygon: return `https://polygonscan.com/tx/${hash}`; + case SupportedNetworks.Unichain: + return `https://uniscan.xyz/tx/${hash}`; default: return `https://etherscan.io/tx/${hash}`; } diff --git a/src/utils/morpho.ts b/src/utils/morpho.ts index ed3ace35..288dde47 100644 --- a/src/utils/morpho.ts +++ b/src/utils/morpho.ts @@ -15,6 +15,8 @@ export const getMorphoAddress = (chain: SupportedNetworks) => { return '0xbbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb'; case SupportedNetworks.Polygon: return '0x1bf0c2541f820e775182832f06c0b7fc27a25f67'; + case SupportedNetworks.Unichain: + return '0x8f5ae9cddb9f68de460c77730b018ae7e04a140a'; default: return zeroAddress; } @@ -30,7 +32,8 @@ export const getBundlerV2 = (chain: SupportedNetworks) => { case SupportedNetworks.Polygon: // ChainAgnosticBundlerV2 return '0x5738366B9348f22607294007e75114922dF2a16A'; - + case SupportedNetworks.Unichain: + return '0x5738366B9348f22607294007e75114922dF2a16A'; default: return zeroAddress; } @@ -44,6 +47,8 @@ export const getIRMTitle = (address: string) => { return 'Adaptive Curve'; case '0xe675a2161d4a6e2de2eed70ac98eebf257fbf0b0': // on polygon return 'Adaptive Curve'; + case '0x9a6061d51743b31d2c3be75d83781fa423f53f0e': // on unichain + return 'Adaptive Curve'; default: return 'Unknown IRM'; } @@ -65,6 +70,7 @@ export const actionTypeToText = (type: UserTxTypes) => { const MAINNET_GENESIS_DATE = new Date('2023-12-28T09:09:23.000Z'); const BASE_GENESIS_DATE = new Date('2024-05-03T13:40:43.000Z'); const POLYGON_GENESIS_DATE = new Date('2025-01-20T02:03:12.000Z'); +const UNICHAIN_GENESIS_DATE = new Date('2025-02-18T02:03:6.000Z'); export function getMorphoGenesisDate(chainId: number): Date { switch (chainId) { @@ -74,6 +80,8 @@ export function getMorphoGenesisDate(chainId: number): Date { return BASE_GENESIS_DATE; case SupportedNetworks.Polygon: return POLYGON_GENESIS_DATE; + case SupportedNetworks.Unichain: + return UNICHAIN_GENESIS_DATE; default: return MAINNET_GENESIS_DATE; // default to mainnet } diff --git a/src/utils/networks.ts b/src/utils/networks.ts index ac4af2af..cfdd9055 100644 --- a/src/utils/networks.ts +++ b/src/utils/networks.ts @@ -2,6 +2,7 @@ enum SupportedNetworks { Mainnet = 1, Base = 8453, Polygon = 137, + Unichain = 130, } const isSupportedChain = (chainId: number) => { @@ -30,6 +31,11 @@ const networks = [ logo: require('../imgs/chains/polygon.png') as string, name: 'Polygon', }, + { + network: SupportedNetworks.Unichain, + logo: require('../imgs/chains/unichain.svg') as string, + name: 'Unichain', + }, ]; const getNetworkImg = (chainId: number) => { diff --git a/src/utils/rpc.ts b/src/utils/rpc.ts index 183d98fe..a57bace9 100644 --- a/src/utils/rpc.ts +++ b/src/utils/rpc.ts @@ -1,5 +1,5 @@ import { createPublicClient, http } from 'viem'; -import { base, mainnet, polygon } from 'viem/chains'; +import { base, mainnet, polygon, unichain } from 'viem/chains'; import { SupportedNetworks } from './networks'; // Initialize Alchemy clients for each chain @@ -18,6 +18,11 @@ export const polygonClient = createPublicClient({ transport: http(`https://polygon-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`), }); +export const unichainClient = createPublicClient({ + chain: unichain, + transport: http(`https://unichain-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`), +}); + export const getClient = (chainId: SupportedNetworks) => { switch (chainId) { case SupportedNetworks.Mainnet: @@ -26,6 +31,8 @@ export const getClient = (chainId: SupportedNetworks) => { return baseClient; case SupportedNetworks.Polygon: return polygonClient; + case SupportedNetworks.Unichain: + return unichainClient; default: throw new Error(`Unsupported chainId: ${chainId}`); } @@ -35,18 +42,21 @@ export const BLOCK_TIME = { [SupportedNetworks.Mainnet]: 12, // Ethereum mainnet: 12 seconds [SupportedNetworks.Base]: 2, // Base: 2 seconds [SupportedNetworks.Polygon]: 2, // Polygon: 2 seconds + [SupportedNetworks.Unichain]: 1, // Unichain: 2 seconds } as const; export const GENESIS_BLOCK = { [SupportedNetworks.Mainnet]: 18883124, // Ethereum mainnet [SupportedNetworks.Base]: 13977148, // Base [SupportedNetworks.Polygon]: 66931042, // Polygon + [SupportedNetworks.Unichain]: 9139027, // Unichain } as const; export const LATEST_BLOCK_DELAY = { [SupportedNetworks.Mainnet]: 0, // Ethereum mainnet [SupportedNetworks.Base]: 20, // Base [SupportedNetworks.Polygon]: 20, // Polygon + [SupportedNetworks.Unichain]: 20, // Unichain }; type BlockResponse = { diff --git a/src/utils/subgraph-urls.ts b/src/utils/subgraph-urls.ts index d5d66807..a2cad40f 100644 --- a/src/utils/subgraph-urls.ts +++ b/src/utils/subgraph-urls.ts @@ -21,11 +21,16 @@ const polygonSubgraphUrl = apiKey ? `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/EhFokmwryNs7qbvostceRqVdjc3petuD13mmdUiMBw8Y` : undefined; +const unichainSubgraphUrl = apiKey + ? `https://gateway.thegraph.com/api/${apiKey}/subgraphs/id/ESbNRVHte3nwhcHveux9cK4FFAZK3TTLc5mKQNtpYgmu` + : undefined; + // Map network IDs (from SupportedNetworks) to Subgraph URLs export const SUBGRAPH_URLS: { [key in SupportedNetworks]?: string } = { [SupportedNetworks.Base]: baseSubgraphUrl, [SupportedNetworks.Mainnet]: mainnetSubgraphUrl, [SupportedNetworks.Polygon]: polygonSubgraphUrl, + [SupportedNetworks.Unichain]: unichainSubgraphUrl, }; export const getSubgraphUrl = (network: SupportedNetworks): string | undefined => { diff --git a/src/utils/tokens.ts b/src/utils/tokens.ts index 3e49cf53..f1670294 100644 --- a/src/utils/tokens.ts +++ b/src/utils/tokens.ts @@ -1,4 +1,4 @@ -import { Chain, base, mainnet, polygon } from 'viem/chains'; +import { Chain, base, mainnet, polygon, unichain } from 'viem/chains'; import { SupportedNetworks } from './networks'; export type SingleChainERC20Basic = { @@ -52,6 +52,7 @@ const supportedTokens = [ { chain: mainnet, address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' }, { chain: base, address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' }, { chain: polygon, address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359' }, + { chain: unichain, address: '0x078d782b760474a361dda0af3839290b0ef57ad6' }, ], peg: TokenPeg.USD, }, @@ -205,7 +206,7 @@ const supportedTokens = [ networks: [ { chain: mainnet, address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' }, { chain: base, address: '0x4200000000000000000000000000000000000006' }, - + { chain: unichain, address: '0x4200000000000000000000000000000000000006' }, // wrapped eth on polygon, defined here as it will not be interpreted as "WETH Contract" // which is determined by isWETH function // This is solely for displaying and linking to eth. @@ -461,7 +462,10 @@ const supportedTokens = [ symbol: 'UNI', img: require('../imgs/tokens/uni.webp') as string, decimals: 18, - networks: [{ chain: mainnet, address: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984' }], + networks: [ + { chain: mainnet, address: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'}, + { chain: unichain, address: '0x8f187aa05619a017077f5308904739877ce9ea21'} + ], }, { symbol: 'AERO', diff --git a/yarn.lock b/yarn.lock index f68090e2..140d82c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19,6 +19,13 @@ __metadata: languageName: node linkType: hard +"@adraffy/ens-normalize@npm:^1.10.1": + version: 1.11.0 + resolution: "@adraffy/ens-normalize@npm:1.11.0" + checksum: 10c0/5111d0f1a273468cb5661ed3cf46ee58de8f32f84e2ebc2365652e66c1ead82649df94c736804e2b9cfa831d30ef24e1cc3575d970dbda583416d3a98d8870a6 + languageName: node + linkType: hard + "@alloc/quick-lru@npm:^5.2.0": version: 5.2.0 resolution: "@alloc/quick-lru@npm:5.2.0" @@ -4498,6 +4505,13 @@ __metadata: languageName: node linkType: hard +"@noble/ciphers@npm:^1.3.0": + version: 1.3.0 + resolution: "@noble/ciphers@npm:1.3.0" + checksum: 10c0/3ba6da645ce45e2f35e3b2e5c87ceba86b21dfa62b9466ede9edfb397f8116dae284f06652c0cd81d99445a2262b606632e868103d54ecc99fd946ae1af8cd37 + languageName: node + linkType: hard + "@noble/curves@npm:1.4.0": version: 1.4.0 resolution: "@noble/curves@npm:1.4.0" @@ -4516,6 +4530,24 @@ __metadata: languageName: node linkType: hard +"@noble/curves@npm:1.9.1": + version: 1.9.1 + resolution: "@noble/curves@npm:1.9.1" + dependencies: + "@noble/hashes": "npm:1.8.0" + checksum: 10c0/39c84dbfecdca80cfde2ecea4b06ef2ec1255a4df40158d22491d1400057a283f57b2b26c8b1331006e6e061db791f31d47764961c239437032e2f45e8888c1e + languageName: node + linkType: hard + +"@noble/curves@npm:^1.6.0, @noble/curves@npm:~1.9.0": + version: 1.9.2 + resolution: "@noble/curves@npm:1.9.2" + dependencies: + "@noble/hashes": "npm:1.8.0" + checksum: 10c0/21d049ae4558beedbf5da0004407b72db84360fa29d64822d82dc9e80251e1ecb46023590cc4b20e70eed697d1b87279b4911dc39f8694c51c874289cfc8e9a7 + languageName: node + linkType: hard + "@noble/hashes@npm:1.4.0, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:^1.4.0, @noble/hashes@npm:~1.4.0": version: 1.4.0 resolution: "@noble/hashes@npm:1.4.0" @@ -4523,6 +4555,13 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:1.8.0, @noble/hashes@npm:^1.5.0, @noble/hashes@npm:~1.8.0": + version: 1.8.0 + resolution: "@noble/hashes@npm:1.8.0" + checksum: 10c0/06a0b52c81a6fa7f04d67762e08b2c476a00285858150caeaaff4037356dd5e119f45b2a530f638b77a5eeca013168ec1b655db41bae3236cb2e9d511484fc77 + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 resolution: "@nodelib/fs.scandir@npm:2.1.5" @@ -7315,6 +7354,13 @@ __metadata: languageName: node linkType: hard +"@scure/base@npm:~1.2.5": + version: 1.2.6 + resolution: "@scure/base@npm:1.2.6" + checksum: 10c0/49bd5293371c4e062cb6ba689c8fe3ea3981b7bb9c000400dc4eafa29f56814cdcdd27c04311c2fec34de26bc373c593a1d6ca6d754398a488d587943b7c128a + languageName: node + linkType: hard + "@scure/bip32@npm:1.4.0": version: 1.4.0 resolution: "@scure/bip32@npm:1.4.0" @@ -7326,6 +7372,17 @@ __metadata: languageName: node linkType: hard +"@scure/bip32@npm:1.7.0, @scure/bip32@npm:^1.5.0": + version: 1.7.0 + resolution: "@scure/bip32@npm:1.7.0" + dependencies: + "@noble/curves": "npm:~1.9.0" + "@noble/hashes": "npm:~1.8.0" + "@scure/base": "npm:~1.2.5" + checksum: 10c0/e3d4c1f207df16abcd79babcdb74d36f89bdafc90bf02218a5140cc5cba25821d80d42957c6705f35210cc5769714ea9501d4ae34732cdd1c26c9ff182a219f7 + languageName: node + linkType: hard + "@scure/bip39@npm:1.3.0": version: 1.3.0 resolution: "@scure/bip39@npm:1.3.0" @@ -7336,6 +7393,16 @@ __metadata: languageName: node linkType: hard +"@scure/bip39@npm:1.6.0, @scure/bip39@npm:^1.4.0": + version: 1.6.0 + resolution: "@scure/bip39@npm:1.6.0" + dependencies: + "@noble/hashes": "npm:~1.8.0" + "@scure/base": "npm:~1.2.5" + checksum: 10c0/73a54b5566a50a3f8348a5cfd74d2092efeefc485efbed83d7a7374ffd9a75defddf446e8e5ea0385e4adb49a94b8ae83c5bad3e16333af400e932f7da3aaff8 + languageName: node + linkType: hard + "@sinclair/typebox@npm:^0.27.8": version: 0.27.8 resolution: "@sinclair/typebox@npm:0.27.8" @@ -8733,6 +8800,21 @@ __metadata: languageName: node linkType: hard +"abitype@npm:1.0.8, abitype@npm:^1.0.6": + version: 1.0.8 + resolution: "abitype@npm:1.0.8" + peerDependencies: + typescript: ">=5.0.4" + zod: ^3 >=3.22.0 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + checksum: 10c0/d3393f32898c1f0f6da4eed2561da6830dcd0d5129a160fae9517214236ee6a6c8e5a0380b8b960c5bc1b949320bcbd015ec7f38b5d7444f8f2b854a1b5dd754 + languageName: node + linkType: hard + "abitype@npm:^0.10.3": version: 0.10.3 resolution: "abitype@npm:0.10.3" @@ -13426,6 +13508,15 @@ __metadata: languageName: node linkType: hard +"isows@npm:1.0.7": + version: 1.0.7 + resolution: "isows@npm:1.0.7" + peerDependencies: + ws: "*" + checksum: 10c0/43c41fe89c7c07258d0be3825f87e12da8ac9023c5b5ae6741ec00b2b8169675c04331ea73ef8c172d37a6747066f4dc93947b17cd369f92828a3b3e741afbda + languageName: node + linkType: hard + "istanbul-lib-coverage@npm:^3.0.0, istanbul-lib-coverage@npm:^3.2.0": version: 3.2.2 resolution: "istanbul-lib-coverage@npm:3.2.2" @@ -15332,7 +15423,7 @@ __metadata: ts-jest: "npm:^29.1.1" typescript: "npm:~5.3.3" unified: "npm:^11.0.4" - viem: "npm:2.x" + viem: "npm:2.31.0" wagmi: "npm:^2.10.2" workbox-webpack-plugin: "npm:^7.0.0" zod: "npm:^3.24.2" @@ -15875,6 +15966,27 @@ __metadata: languageName: node linkType: hard +"ox@npm:0.7.1": + version: 0.7.1 + resolution: "ox@npm:0.7.1" + dependencies: + "@adraffy/ens-normalize": "npm:^1.10.1" + "@noble/ciphers": "npm:^1.3.0" + "@noble/curves": "npm:^1.6.0" + "@noble/hashes": "npm:^1.5.0" + "@scure/bip32": "npm:^1.5.0" + "@scure/bip39": "npm:^1.4.0" + abitype: "npm:^1.0.6" + eventemitter3: "npm:5.0.1" + peerDependencies: + typescript: ">=5.4.0" + peerDependenciesMeta: + typescript: + optional: true + checksum: 10c0/15370d76f7e5fe1b06c5b9986bc709a8c433e4242660900b3d1adb2a56c8f762a2010a9166bdb95bdf531806cde7891911456c7ec8ba135fc232a5d5037ac673 + languageName: node + linkType: hard + "p-limit@npm:^2.2.0": version: 2.3.0 resolution: "p-limit@npm:2.3.0" @@ -19381,7 +19493,28 @@ __metadata: languageName: node linkType: hard -"viem@npm:2.x, viem@npm:^2.1.1": +"viem@npm:2.31.0": + version: 2.31.0 + resolution: "viem@npm:2.31.0" + dependencies: + "@noble/curves": "npm:1.9.1" + "@noble/hashes": "npm:1.8.0" + "@scure/bip32": "npm:1.7.0" + "@scure/bip39": "npm:1.6.0" + abitype: "npm:1.0.8" + isows: "npm:1.0.7" + ox: "npm:0.7.1" + ws: "npm:8.18.2" + peerDependencies: + typescript: ">=5.0.4" + peerDependenciesMeta: + typescript: + optional: true + checksum: 10c0/4f327af609d41720f94664546eae1b8a892ae787630c0259a95ca145f7b07ef82387975b6ab8c223decd34ead69650119226af360d02ac7c17dbc4b60cfdf523 + languageName: node + linkType: hard + +"viem@npm:^2.1.1": version: 2.18.7 resolution: "viem@npm:2.18.7" dependencies: @@ -20171,6 +20304,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:8.18.2": + version: 8.18.2 + resolution: "ws@npm:8.18.2" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ">=5.0.2" + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 10c0/4b50f67931b8c6943c893f59c524f0e4905bbd183016cfb0f2b8653aa7f28dad4e456b9d99d285bbb67cca4fedd9ce90dfdfaa82b898a11414ebd66ee99141e4 + languageName: node + linkType: hard + "ws@npm:^7.5.1": version: 7.5.10 resolution: "ws@npm:7.5.10" From 6f28ef06b5eba739f60bb00399682702ec172e31 Mon Sep 17 00:00:00 2001 From: antoncoding Date: Mon, 9 Jun 2025 15:41:13 +0800 Subject: [PATCH 2/3] fix: fetch position error --- app/api/positions/historical/route.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/positions/historical/route.ts b/app/api/positions/historical/route.ts index 40448ee8..84f3f5b5 100644 --- a/app/api/positions/historical/route.ts +++ b/app/api/positions/historical/route.ts @@ -98,7 +98,7 @@ async function getPositionAtBlock( abi: morphoABI, functionName: 'market', args: [marketId as `0x${string}`], - blockNumber: BigInt(blockNumber), + blockNumber: isNow ? undefined : BigInt(blockNumber), })) as readonly bigint[]; // Convert array to market object @@ -129,6 +129,7 @@ async function getPositionAtBlock( marketId, userAddress, blockNumber, + chainId, error, }); throw error; @@ -143,6 +144,10 @@ export async function GET(request: NextRequest) { const userAddress = searchParams.get('userAddress'); const chainId = parseInt(searchParams.get('chainId') ?? '1'); + if (chainId === 130) { + console.log('Unichain position API is not supported yet'); + } + if (!marketId || !userAddress || (!blockNumber && blockNumber !== 0)) { console.error('Missing required parameters:', { blockNumber: !!blockNumber, @@ -159,7 +164,7 @@ export async function GET(request: NextRequest) { position, }); } catch (error) { - console.error('Error in historical position API:', error); + // console.error('Error', error); return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); } } From a6f236a82b0ef59940fb348d9c7fc8d5e9deb253 Mon Sep 17 00:00:00 2001 From: antoncoding Date: Mon, 9 Jun 2025 16:14:20 +0800 Subject: [PATCH 3/3] chore: remove wrong log --- app/api/positions/historical/route.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/api/positions/historical/route.ts b/app/api/positions/historical/route.ts index 84f3f5b5..fc6f580f 100644 --- a/app/api/positions/historical/route.ts +++ b/app/api/positions/historical/route.ts @@ -144,10 +144,6 @@ export async function GET(request: NextRequest) { const userAddress = searchParams.get('userAddress'); const chainId = parseInt(searchParams.get('chainId') ?? '1'); - if (chainId === 130) { - console.log('Unichain position API is not supported yet'); - } - if (!marketId || !userAddress || (!blockNumber && blockNumber !== 0)) { console.error('Missing required parameters:', { blockNumber: !!blockNumber,