From 3beb153365d140c2db8c8243d9c1761be35b8ac5 Mon Sep 17 00:00:00 2001 From: Ignat Date: Thu, 26 Sep 2024 13:48:27 +0500 Subject: [PATCH 1/3] chore: update API usage from `lending-api` --- apps/lend/package.json | 2 +- apps/lend/src/lib/apiLending.ts | 17 +++++++++-------- apps/lend/src/shared/config/api.ts | 1 + apps/lend/src/shared/config/index.ts | 1 + apps/lend/src/store/createAppSlice.ts | 10 +++++----- 5 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 apps/lend/src/shared/config/api.ts create mode 100644 apps/lend/src/shared/config/index.ts diff --git a/apps/lend/package.json b/apps/lend/package.json index ffdf580a1..6de3e50a8 100644 --- a/apps/lend/package.json +++ b/apps/lend/package.json @@ -18,7 +18,7 @@ "analyze": "ANALYZE=true next build" }, "dependencies": { - "@curvefi/lending-api": "^2.2.1", + "@curvefi/lending-api": "^2.3.0", "@lingui/detect-locale": "^4.6.0", "@lingui/react": "^4.6.0", "@supercharge/promise-pool": "^2.3.2", diff --git a/apps/lend/src/lib/apiLending.ts b/apps/lend/src/lib/apiLending.ts index ddd5293f2..56e2d22df 100644 --- a/apps/lend/src/lib/apiLending.ts +++ b/apps/lend/src/lib/apiLending.ts @@ -9,6 +9,7 @@ import { INVALID_ADDRESS } from '@/constants' import { fulfilledValue, getErrorMessage, log } from '@/utils/helpers' import { BN, shortenAccount } from '@/ui/utils' import networks from '@/networks' +import { USE_API } from '@/shared/config' export const helpers = { initApi: async (chainId: ChainId, wallet: Wallet | null) => { @@ -48,7 +49,7 @@ export const helpers = { const resp = { marketList: [] as string[], error: '' } try { log('fetchMarkets', api.chainId) - await api.oneWayfactory.fetchMarkets() + await api.oneWayfactory.fetchMarkets(, USE_API) resp.marketList = api.oneWayfactory.getMarketList() return resp } catch (error) { @@ -206,7 +207,7 @@ const market = { results[owm.id] = { borrowed: '', collateral: '', error } }) .process(async ({ owm }) => { - const resp = await owm.stats.ammBalances(useMultiCall) + const resp = await owm.stats.ammBalances(useMultiCall, USE_API) results[owm.id] = { ...resp, error: '' } }) @@ -224,7 +225,7 @@ const market = { results[owm.id] = { cap: '', available: '', error } }) .process(async ({ owm }) => { - const resp = await owm.stats.capAndAvailable(useMultiCall) + const resp = await owm.stats.capAndAvailable(useMultiCall, USE_API) results[owm.id] = { ...resp, error: '' } }) @@ -242,7 +243,7 @@ const market = { results[owm.id] = { totalDebt: '', error } }) .process(async ({ owm }) => { - const totalDebt = await owm.stats.totalDebt(useMultiCall) + const totalDebt = await owm.stats.totalDebt(useMultiCall, USE_API) results[owm.id] = { totalDebt, error: '' } }) @@ -291,7 +292,7 @@ const market = { results[owm.id] = { rates: null, error } }) .process(async ({ owm }) => { - const rates = await owm.stats.rates(useMultiCall) + const rates = await owm.stats.rates(useMultiCall, USE_API) results[owm.id] = { rates, error: '' } }) @@ -341,10 +342,10 @@ const market = { // isRewardsOnly = both CRV and other comes from same endpoint. if (isRewardsOnly) { - const rewardsResp = await owm.vault.rewardsApr(useMultiCall) + const rewardsResp = await owm.vault.rewardsApr(useMultiCall, USE_API) rewards.other = _filterZeroApy(rewardsResp) } else { - const [others, crv] = await Promise.all([owm.vault.rewardsApr(useMultiCall), owm.vault.crvApr(useMultiCall)]) + const [others, crv] = await Promise.all([owm.vault.rewardsApr(useMultiCall, USE_API), owm.vault.crvApr(useMultiCall)]) rewards.other = _filterZeroApy(others) rewards.crv = crv } @@ -390,7 +391,7 @@ const market = { const { collateral_token, borrowed_token } = owm const [ammBalance, collateralUsdRate, borrowedUsdRate] = await Promise.all([ - owm.stats.ammBalances(useMultiCall), + owm.stats.ammBalances(useMultiCall, USE_API), api.getUsdRate(collateral_token.address), api.getUsdRate(borrowed_token.address), ]) diff --git a/apps/lend/src/shared/config/api.ts b/apps/lend/src/shared/config/api.ts new file mode 100644 index 000000000..5fc2e4966 --- /dev/null +++ b/apps/lend/src/shared/config/api.ts @@ -0,0 +1 @@ +export const USE_API = true as const diff --git a/apps/lend/src/shared/config/index.ts b/apps/lend/src/shared/config/index.ts new file mode 100644 index 000000000..3318fdbc9 --- /dev/null +++ b/apps/lend/src/shared/config/index.ts @@ -0,0 +1 @@ +export * from './api' diff --git a/apps/lend/src/store/createAppSlice.ts b/apps/lend/src/store/createAppSlice.ts index 1b5704079..11be9ac8a 100644 --- a/apps/lend/src/store/createAppSlice.ts +++ b/apps/lend/src/store/createAppSlice.ts @@ -129,7 +129,7 @@ const createAppSlice = (set: SetState, get: GetState): AppSlice => set( produce((state) => { state[key] = value - }) + }), ) }, getTvl: (api: Api) => { @@ -158,7 +158,7 @@ const createAppSlice = (set: SetState, get: GetState): AppSlice => state[sliceKey][key] = parsedValue } } - }) + }), ) }, setAppStateByKey: (sliceKey: SliceKey, key: StateKey, value: T, showLog?: boolean) => { @@ -171,7 +171,7 @@ const createAppSlice = (set: SetState, get: GetState): AppSlice => } state[sliceKey][key] = value } - }) + }), ) }, setAppStateByKeys: (sliceKey: SliceKey, sliceState: T, showLog?: boolean) => { @@ -186,7 +186,7 @@ const createAppSlice = (set: SetState, get: GetState): AppSlice => } state[sliceKey][key] = value } - }) + }), ) } }, @@ -197,7 +197,7 @@ const createAppSlice = (set: SetState, get: GetState): AppSlice => ...state[sliceKey], ...defaultState, } - }) + }), ) }, }) From 1aaf37f697bf50f2f1376451e76c69fa007117ed Mon Sep 17 00:00:00 2001 From: Ignat Date: Thu, 3 Oct 2024 21:56:53 +0500 Subject: [PATCH 2/3] chore: update `lend` lib --- apps/lend/package.json | 2 +- apps/lend/src/lib/apiLending.ts | 94 ++++++++++++++++----------------- yarn.lock | 10 ++-- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/apps/lend/package.json b/apps/lend/package.json index 6de3e50a8..03a3e9ccb 100644 --- a/apps/lend/package.json +++ b/apps/lend/package.json @@ -18,7 +18,7 @@ "analyze": "ANALYZE=true next build" }, "dependencies": { - "@curvefi/lending-api": "^2.3.0", + "@curvefi/lending-api": "^2.3.2", "@lingui/detect-locale": "^4.6.0", "@lingui/react": "^4.6.0", "@supercharge/promise-pool": "^2.3.2", diff --git a/apps/lend/src/lib/apiLending.ts b/apps/lend/src/lib/apiLending.ts index 56e2d22df..8a68d3dca 100644 --- a/apps/lend/src/lib/apiLending.ts +++ b/apps/lend/src/lib/apiLending.ts @@ -31,7 +31,7 @@ export const helpers = { getIsUserCloseToLiquidation: ( userFirstBand: number, userLiquidationBand: number | null, - oraclePriceBand: number | null | undefined + oraclePriceBand: number | null | undefined, ) => { if (typeof userLiquidationBand !== null && typeof oraclePriceBand !== 'number') { return false @@ -49,7 +49,7 @@ export const helpers = { const resp = { marketList: [] as string[], error: '' } try { log('fetchMarkets', api.chainId) - await api.oneWayfactory.fetchMarkets(, USE_API) + await api.oneWayfactory.fetchMarkets(USE_API) resp.marketList = api.oneWayfactory.getMarketList() return resp } catch (error) { @@ -121,7 +121,7 @@ export const helpers = { }, waitForTransactions: async (hashes: string[], provider: Provider) => { const { results, errors } = await PromisePool.for(hashes).process( - async (hash) => await provider.waitForTransaction(hash) + async (hash) => await provider.waitForTransaction(hash), ) if (Array.isArray(errors) && errors.length > 0) { throw errors @@ -177,7 +177,7 @@ const market = { _sortBands(bandsBalances), liquidationBand, owmData, - true + true, ) results[owm.id] = { @@ -342,10 +342,10 @@ const market = { // isRewardsOnly = both CRV and other comes from same endpoint. if (isRewardsOnly) { - const rewardsResp = await owm.vault.rewardsApr(useMultiCall, USE_API) + const rewardsResp = await owm.vault.rewardsApr(useMultiCall) rewards.other = _filterZeroApy(rewardsResp) } else { - const [others, crv] = await Promise.all([owm.vault.rewardsApr(useMultiCall, USE_API), owm.vault.crvApr(useMultiCall)]) + const [others, crv] = await Promise.all([owm.vault.rewardsApr(useMultiCall), owm.vault.crvApr(useMultiCall)]) rewards.other = _filterZeroApy(others) rewards.crv = crv } @@ -517,13 +517,13 @@ const user = { const isCloseToLiquidation = helpers.getIsUserCloseToLiquidation( reversedUserBands[0], liquidationBand, - oraclePriceBand + oraclePriceBand, ) const parsedBandsBalances = await _fetchChartBandBalancesData( _sortBands(bandsBalances), liquidationBand, owmData, - false + false, ) results[userActiveKey] = { @@ -597,7 +597,7 @@ const loanCreate = { userCollateral: string, userBorrowed: string, n: number, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -656,7 +656,7 @@ const loanCreate = { userBorrowed: string, debt: string, n: number, - maxSlippage: string + maxSlippage: string, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -712,7 +712,7 @@ const loanCreate = { userCollateral: string, userBorrowed: string, debt: string, - isLeverage: boolean + isLeverage: boolean, ) => { totalCollateral = totalCollateral || '0' userCollateral = userCollateral || '0' @@ -800,7 +800,7 @@ const loanCreate = { debt: string, n: number, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -817,8 +817,8 @@ const loanCreate = { ? await owm.leverage.estimateGas.createLoan(userCollateral, userBorrowed, debt, n, +maxSlippage) : await owm.estimateGas.createLoan(userCollateral, debt, n) : isLeverage - ? await owm.leverage.estimateGas.createLoanApprove(userCollateral, userBorrowed) - : await owm.estimateGas.createLoanApprove(userCollateral) + ? await owm.leverage.estimateGas.createLoanApprove(userCollateral, userBorrowed) + : await owm.estimateGas.createLoanApprove(userCollateral) return resp } catch (error) { console.error(error) @@ -832,7 +832,7 @@ const loanCreate = { { owm }: OWMData, userCollateral: string, userBorrowed: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -852,7 +852,7 @@ const loanCreate = { debt: string, n: number, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -907,7 +907,7 @@ const loanBorrowMore = { { signerAddress }: Api, { owm }: OWMData, userCollateral: string, - debt: string + debt: string, ) => { userCollateral = userCollateral || '0' debt = debt || '0' @@ -947,7 +947,7 @@ const loanBorrowMore = { userCollateral: string, userBorrowed: string, debt: string, - slippage: string + slippage: string, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -1008,7 +1008,7 @@ const loanBorrowMore = { userBorrowed: string, debt: string, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -1025,8 +1025,8 @@ const loanBorrowMore = { ? await owm.leverage.estimateGas.borrowMore(userCollateral, userBorrowed, debt, +maxSlippage) : await owm.estimateGas.borrowMore(userCollateral, debt) : isLeverage - ? await owm.leverage.estimateGas.borrowMoreApprove(userCollateral, userBorrowed) - : await owm.estimateGas.borrowMoreApprove(userCollateral) + ? await owm.leverage.estimateGas.borrowMoreApprove(userCollateral, userBorrowed) + : await owm.estimateGas.borrowMoreApprove(userCollateral) return resp } catch (error) { console.error(error) @@ -1044,7 +1044,7 @@ const loanBorrowMore = { { owm }: OWMData, userCollateral: string, userBorrowed: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -1063,7 +1063,7 @@ const loanBorrowMore = { userBorrowed: string, debt: string, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { userCollateral = userCollateral || '0' userBorrowed = userBorrowed || '0' @@ -1082,7 +1082,7 @@ const loanRepay = { { owm }: OWMData, stateCollateral: string, userCollateral: string, - userBorrowed: string + userBorrowed: string, ) => { stateCollateral = stateCollateral || '0' userCollateral = userCollateral || '0' @@ -1105,7 +1105,7 @@ const loanRepay = { { owm }: OWMData, userBorrowed: string, isFullRepay: boolean, - userStateDebt: string + userStateDebt: string, ) => { log('detailInfo', userBorrowed) let resp: { activeKey: string; resp: DetailInfoResp | null; error: string } = { activeKey, resp: null, error: '' } @@ -1144,7 +1144,7 @@ const loanRepay = { userCollateral: string, userBorrowed: string, maxSlippage: string, - userStateDebt: string + userStateDebt: string, ) => { stateCollateral = stateCollateral || '0' userCollateral = userCollateral || '0' @@ -1229,7 +1229,7 @@ const loanRepay = { userBorrowed: string, isFullRepay: boolean, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { stateCollateral = stateCollateral || '0' userCollateral = userCollateral || '0' @@ -1240,7 +1240,7 @@ const loanRepay = { userCollateral, userBorrowed, isFullRepay, - maxSlippage + maxSlippage, ) let resp = { activeKey, isApproved: false, estimatedGas: null as EstimatedGas, error: '' } @@ -1248,19 +1248,19 @@ const loanRepay = { resp.isApproved = isLeverage ? await owm.leverage.repayIsApproved(userCollateral, userBorrowed) : isFullRepay - ? await owm.fullRepayIsApproved() - : await owm.repayIsApproved(userBorrowed) + ? await owm.fullRepayIsApproved() + : await owm.repayIsApproved(userBorrowed) resp.estimatedGas = isLeverage ? resp.isApproved ? await owm.leverage.estimateGas.repay(stateCollateral, userCollateral, userBorrowed, +maxSlippage) : await owm.leverage.estimateGas.repayApprove(userCollateral, userBorrowed) : resp.isApproved - ? isFullRepay - ? await owm.estimateGas.fullRepay() - : await owm.estimateGas.repay(userBorrowed) - : isFullRepay - ? await owm.estimateGas.fullRepayApprove() - : await owm.estimateGas.repayApprove(userBorrowed) + ? isFullRepay + ? await owm.estimateGas.fullRepay() + : await owm.estimateGas.repay(userBorrowed) + : isFullRepay + ? await owm.estimateGas.fullRepayApprove() + : await owm.estimateGas.repayApprove(userBorrowed) return resp } catch (error) { console.error(error) @@ -1276,7 +1276,7 @@ const loanRepay = { userCollateral: string, userBorrowed: string, isFullRepay: boolean, - isLeverage: boolean + isLeverage: boolean, ) => { stateCollateral = stateCollateral || '0' userCollateral = userCollateral || '0' @@ -1286,8 +1286,8 @@ const loanRepay = { isLeverage ? await owm.leverage.repayApprove(userCollateral, userBorrowed) : isFullRepay - ? await owm.fullRepayApprove() - : await owm.repayApprove(userBorrowed) + ? await owm.fullRepayApprove() + : await owm.repayApprove(userBorrowed) return await approve(activeKey, fn, provider) }, repay: async ( @@ -1299,7 +1299,7 @@ const loanRepay = { userBorrowed: string, isFullRepay: boolean, maxSlippage: string, - isLeverage: boolean + isLeverage: boolean, ) => { stateCollateral = stateCollateral || '0' userCollateral = userCollateral || '0' @@ -1309,8 +1309,8 @@ const loanRepay = { isLeverage ? await owm.leverage.repay(stateCollateral, userCollateral, userBorrowed, +maxSlippage) : isFullRepay - ? await owm.fullRepay() - : await owm.repay(userBorrowed) + ? await owm.fullRepay() + : await owm.repay(userBorrowed) return await submit(activeKey, fn, provider) }, } @@ -1376,7 +1376,7 @@ const loanCollateralAdd = { { signerAddress }: Api, { owm }: OWMData, collateral: string, - address?: string + address?: string, ) => { log('detailInfo', collateral) let resp: { activeKey: string; resp: DetailInfoResp | null; error: string } = { activeKey, resp: null, error: '' } @@ -1454,7 +1454,7 @@ const loanCollateralRemove = { { signerAddress }: Api, { owm }: OWMData, collateral: string, - address?: string + address?: string, ) => { log('loanCollateralRemoveHealthPricesBands', owm.collateral_token.symbol, collateral) let resp: { activeKey: string; resp: DetailInfoResp | null; error: string } = { activeKey, resp: null, error: '' } @@ -1768,7 +1768,7 @@ const vaultWithdraw = { { owm }: OWMData, isFullWithdraw: boolean, amount: string, - vaultShares: string + vaultShares: string, ) => { log('vaultWithdraw', owm.id, amount, 'isFullWithdraw', isFullWithdraw, 'vaultShares', vaultShares) @@ -2007,7 +2007,7 @@ async function _fetchChartBandBalancesData( { bandsBalances, bandsBalancesArr }: { bandsBalances: BandsBalances; bandsBalancesArr: BandsBalancesArr }, liquidationBand: number | null, { owm }: OWMData, - isMarket: boolean + isMarket: boolean, ) { // filter out bands that doesn't have borrowed or collaterals const ns = isMarket @@ -2094,7 +2094,7 @@ function _getPriceImpactResp(priceImpactResp: PromiseSettledResult, - bandsResp: PromiseSettledResult<[number, number]> + bandsResp: PromiseSettledResult<[number, number]>, ) { let errorMessage = '' diff --git a/yarn.lock b/yarn.lock index cd5141a2d..d6fadeeed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2115,16 +2115,16 @@ __metadata: languageName: node linkType: hard -"@curvefi/lending-api@npm:^2.2.1": - version: 2.2.1 - resolution: "@curvefi/lending-api@npm:2.2.1" +"@curvefi/lending-api@npm:^2.3.2": + version: 2.3.2 + resolution: "@curvefi/lending-api@npm:2.3.2" dependencies: axios: "npm:^0.21.1" bignumber.js: "npm:^9.0.1" ethcall: "npm:^6.0.2" ethers: "npm:^6.10.0" memoizee: "npm:^0.4.15" - checksum: 10c0/6a25cab08458acae8d595b2d43f651059d8d0d649c804d933bbf450323334da673a151cc84f0e7592c51c1b159f08971791e89a50f2549c9fad743d31e86eb64 + checksum: 10c0/b2397089c8092956064acda95aa385e657ea82351093bb87c67f75f8e7196bdebf6cfd917f6be42733b76fef59f51923aae6534dfd130a23e737db3a02a46c03 languageName: node linkType: hard @@ -16202,7 +16202,7 @@ __metadata: version: 0.0.0-use.local resolution: "lend@workspace:apps/lend" dependencies: - "@curvefi/lending-api": "npm:^2.2.1" + "@curvefi/lending-api": "npm:^2.3.2" "@lingui/cli": "npm:^4.6.0" "@lingui/detect-locale": "npm:^4.6.0" "@lingui/loader": "npm:^4.6.0" From 3e57d04f7ad230ead02391deacd38fda145fe79b Mon Sep 17 00:00:00 2001 From: Ignat Date: Tue, 8 Oct 2024 13:13:23 +0500 Subject: [PATCH 3/3] build: update lend-api version --- apps/lend/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/lend/package.json b/apps/lend/package.json index 03a3e9ccb..f29b970dc 100644 --- a/apps/lend/package.json +++ b/apps/lend/package.json @@ -18,7 +18,7 @@ "analyze": "ANALYZE=true next build" }, "dependencies": { - "@curvefi/lending-api": "^2.3.2", + "@curvefi/lending-api": "^2.3.3", "@lingui/detect-locale": "^4.6.0", "@lingui/react": "^4.6.0", "@supercharge/promise-pool": "^2.3.2", diff --git a/yarn.lock b/yarn.lock index d6fadeeed..09ae4fa32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2115,16 +2115,16 @@ __metadata: languageName: node linkType: hard -"@curvefi/lending-api@npm:^2.3.2": - version: 2.3.2 - resolution: "@curvefi/lending-api@npm:2.3.2" +"@curvefi/lending-api@npm:^2.3.3": + version: 2.3.3 + resolution: "@curvefi/lending-api@npm:2.3.3" dependencies: axios: "npm:^0.21.1" bignumber.js: "npm:^9.0.1" ethcall: "npm:^6.0.2" ethers: "npm:^6.10.0" memoizee: "npm:^0.4.15" - checksum: 10c0/b2397089c8092956064acda95aa385e657ea82351093bb87c67f75f8e7196bdebf6cfd917f6be42733b76fef59f51923aae6534dfd130a23e737db3a02a46c03 + checksum: 10c0/88d112d0cbac5c79c9163166c5a8da3745f3044400838c906b006965348db69eedfbc21aff5ce36468739acd72a9fe7f831c573bc5cecfe7468bd6463d4c166a languageName: node linkType: hard @@ -16202,7 +16202,7 @@ __metadata: version: 0.0.0-use.local resolution: "lend@workspace:apps/lend" dependencies: - "@curvefi/lending-api": "npm:^2.3.2" + "@curvefi/lending-api": "npm:^2.3.3" "@lingui/cli": "npm:^4.6.0" "@lingui/detect-locale": "npm:^4.6.0" "@lingui/loader": "npm:^4.6.0"