Skip to content

Commit 05e1c49

Browse files
Merge pull request #1292 from curvefi/fix/market-url
fix: mint market links
2 parents 156c871 + 7a6032f commit 05e1c49

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

apps/main/src/llamalend/entities/llama-markets.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { countBy } from 'lodash'
12
import { ethAddress } from 'viem'
23
import { Chain } from '@curvefi/prices-api'
34
import { recordValues } from '@curvefi/prices-api/objects.util'
@@ -257,19 +258,13 @@ const convertMintMarket = (
257258

258259
/**
259260
* Creates a function that counts the number of markets for each collateral token.
260-
* This is used to create unique names for markets with the same collateral token, used in the URL.
261-
* The order is expected to be by market creation date, so the first market will have count 1, the second 2, etc.
262-
* The backend is hardcoded to return markets in the order of creation, so this should work correctly.
261+
* Numbers are added to the first items (e.g., first ETH gets 3, second gets 2, last gets 1).
263262
* @returns A function that takes a MintMarket and returns the count of markets for the collateral token.
264263
*/
265-
function createCountMarket() {
266-
const marketCountByCollateral = new Map<string, number>()
267-
return ({ collateralToken }: MintMarket) => {
268-
const [symbol] = getCollateral(collateralToken)
269-
const count = (marketCountByCollateral.get(symbol) ?? 0) + 1
270-
marketCountByCollateral.set(symbol, count)
271-
return count
272-
}
264+
function createCountMarket(data: MintMarket[] | undefined = []) {
265+
const getName = ({ collateralToken }: MintMarket) => getCollateral(collateralToken)[0]
266+
const marketCountByCollateral = countBy(data, getName)
267+
return (m: MintMarket) => marketCountByCollateral[getName(m)]--
273268
}
274269

275270
/**
@@ -303,7 +298,7 @@ export const useLlamaMarkets = (userAddress?: Address, enabled = true) =>
303298
const userBorrows = new Set(recordValues(userLendingVaults.data ?? {}).flat())
304299
const userMints = new Set(recordValues(userMintMarkets.data ?? {}).flat())
305300
const userSupplied = new Set(recordValues(userSuppliedMarkets.data ?? {}).flat())
306-
const countMarket = createCountMarket()
301+
const countMarket = createCountMarket(mintMarkets.data)
307302

308303
// only render table when both lending and mint markets are ready, however show one of them if the other is in error
309304
const showData = (lendingVaults.data && mintMarkets.data) || lendingVaults.isError || mintMarkets.isError

packages/prices-api/src/crvusd/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getMarkets(
1818
return resp.data.map(Parsers.parseMarket)
1919
}
2020

21-
/** Retrieve all markets across all chains, sorted by date of creation. */
21+
/** Retrieve all markets across all chains, sorted by date of creation descending. */
2222
export async function getAllMarkets(
2323
params: {
2424
page?: number

packages/prices-api/src/crvusd/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type Market = {
2626
pending: number
2727
collected: number
2828
}
29+
created_at: Date
2930
}
3031

3132
export type Snapshot = {

packages/prices-api/src/crvusd/parsers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const parseMarket = (x: Responses.GetMarketsResponse['data'][number]): Mo
2929
pending: x.pending_fees,
3030
collected: x.collected_fees,
3131
},
32+
created_at: new Date(x.created_at),
3233
})
3334

3435
export const parseAllMarkets = (resp: Responses.GetAllMarketsResponse) =>

packages/prices-api/src/crvusd/responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type GetMarketsResponse = {
2525
address: Address
2626
rebasing_yield: number | null
2727
}
28+
created_at: string
2829
}[]
2930
count: number
3031
}

0 commit comments

Comments
 (0)