Skip to content

Commit 7d13309

Browse files
committed
add default chain id for markets
1 parent 51df4a8 commit 7d13309

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

src/app/leverage/constants.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { arbitrum, base, mainnet } from 'viem/chains'
77
import { getLeverageBaseToken } from '@/app/leverage/utils/get-leverage-base-token'
88
import { getLeverageType } from '@/app/leverage/utils/get-leverage-type'
99
import { ARBITRUM, BASE, MAINNET } from '@/constants/chains'
10-
import { ETH, Token, USDC, USDT, WBTC, WETH } from '@/constants/tokens'
10+
import { ETH, type Token, USDC, USDT, WBTC, WETH } from '@/constants/tokens'
1111

1212
import {
1313
LeverageMarket,
14-
LeverageRatio,
14+
type LeverageRatio,
1515
LeverageStrategy,
16-
LeverageToken,
16+
type LeverageToken,
1717
LeverageType,
18-
Market,
18+
type Market,
1919
} from './types'
2020

2121
export enum LendingProtocol {
@@ -76,13 +76,14 @@ export function getPathForMarket(market: string, chainId?: number) {
7676
const existingMarket = markets.find((m) => m.market === market)
7777
if (!existingMarket) return null
7878

79-
const { defaultAsset } = existingMarket
79+
const { defaultAsset, defaultChainId } = existingMarket
8080

8181
const queryChainId =
8282
chainId && existingMarket.networks.some((network) => network.id === chainId)
8383
? chainId
84-
: defaultAsset.chainId
85-
return `/leverage?sell=ETH&buy=${defaultAsset.symbol}&network=${queryChainId}`
84+
: defaultChainId
85+
console.log(queryChainId, defaultAsset, existingMarket)
86+
return `/leverage?sell=ETH&buy=${defaultAsset[queryChainId]}&network=${queryChainId}`
8687
}
8788

8889
const defaultAssets = {
@@ -155,7 +156,12 @@ export const markets: Market[] = [
155156
change24h: 0,
156157
low24h: 0,
157158
high24h: 0,
158-
defaultAsset: { symbol: 'ETH3X', chainId: base.id },
159+
defaultAsset: {
160+
[arbitrum.id]: 'ETH3X',
161+
[base.id]: 'ETH3X',
162+
[mainnet.id]: 'ETH2X',
163+
},
164+
defaultChainId: base.id,
159165
lendingProtocol: LendingProtocol.aave,
160166
},
161167
{
@@ -168,7 +174,12 @@ export const markets: Market[] = [
168174
change24h: 0,
169175
low24h: 0,
170176
high24h: 0,
171-
defaultAsset: { symbol: 'BTC3X', chainId: base.id },
177+
defaultAsset: {
178+
[arbitrum.id]: 'BTC3X',
179+
[base.id]: 'BTC3X',
180+
[mainnet.id]: 'BTC2X',
181+
},
182+
defaultChainId: base.id,
172183
lendingProtocol: LendingProtocol.aave,
173184
},
174185
{
@@ -181,7 +192,10 @@ export const markets: Market[] = [
181192
change24h: 0,
182193
low24h: 0,
183194
high24h: 0,
184-
defaultAsset: { symbol: 'uSOL2x', chainId: base.id },
195+
defaultAsset: {
196+
[base.id]: 'uSOL2x',
197+
},
198+
defaultChainId: base.id,
185199
lendingProtocol: LendingProtocol.morpho,
186200
},
187201
{
@@ -194,7 +208,10 @@ export const markets: Market[] = [
194208
change24h: 0,
195209
low24h: 0,
196210
high24h: 0,
197-
defaultAsset: { symbol: 'uSUI2x', chainId: base.id },
211+
defaultAsset: {
212+
[base.id]: 'uSUI2x',
213+
},
214+
defaultChainId: base.id,
198215
lendingProtocol: LendingProtocol.morpho,
199216
},
200217
{
@@ -207,7 +224,10 @@ export const markets: Market[] = [
207224
change24h: 0,
208225
low24h: 0,
209226
high24h: 0,
210-
defaultAsset: { symbol: 'ETH2xBTC', chainId: arbitrum.id },
227+
defaultAsset: {
228+
[arbitrum.id]: 'ETH2xBTC',
229+
},
230+
defaultChainId: arbitrum.id,
211231
lendingProtocol: LendingProtocol.aave,
212232
},
213233
{
@@ -220,7 +240,10 @@ export const markets: Market[] = [
220240
change24h: 0,
221241
low24h: 0,
222242
high24h: 0,
223-
defaultAsset: { symbol: 'BTC2xETH', chainId: arbitrum.id },
243+
defaultAsset: {
244+
[arbitrum.id]: 'BTC2xETH',
245+
},
246+
defaultChainId: arbitrum.id,
224247
lendingProtocol: LendingProtocol.aave,
225248
},
226249
]

src/app/leverage/types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { Chain } from 'viem'
2-
3-
import { Token } from '@/constants/tokens'
1+
import type { Token } from '@/constants/tokens'
2+
import type { Chain } from 'viem'
43

54
export enum LeverageType {
6-
Long2x,
7-
Long3x,
8-
Short,
5+
Long2x = 0,
6+
Long3x = 1,
7+
Short = 2,
98
}
109

1110
export enum LeverageMarket {
@@ -63,7 +62,8 @@ export interface Market {
6362
high24h: number
6463
symbol: 'ETH' | 'BTC' | 'SOL' | 'SUI'
6564
currency: 'USD' | 'BTC' | 'ETH'
66-
defaultAsset: { symbol: string; chainId: number }
65+
defaultAsset: { [key: number]: string }
66+
defaultChainId: number
6767
lendingProtocol: string
6868
}
6969

0 commit comments

Comments
 (0)