mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 22:43:12 +08:00
fix: handle case when market has been deleted (#16980)
This commit is contained in:
@@ -39,6 +39,9 @@ async function withRetry(fn, maxAttempts = MAX_RETRY_ATTEMPTS, delayMs = RETRY_D
|
|||||||
return await fn()
|
return await fn()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
lastError = error
|
lastError = error
|
||||||
|
if (error.message && error.message.includes('does not exist')) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
if (attempt === maxAttempts) throw lastError
|
if (attempt === maxAttempts) throw lastError
|
||||||
console.log(`Attempt ${attempt} failed, retrying in ${delayMs}ms: ${error.message}`)
|
console.log(`Attempt ${attempt} failed, retrying in ${delayMs}ms: ${error.message}`)
|
||||||
await sleep(delayMs)
|
await sleep(delayMs)
|
||||||
@@ -205,6 +208,7 @@ async function fetchDeploymentsFromContract(registryContract) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processMarket(marketContract) {
|
async function processMarket(marketContract) {
|
||||||
|
try {
|
||||||
const [snapshotRaw, configurationRaw] = await Promise.all([
|
const [snapshotRaw, configurationRaw] = await Promise.all([
|
||||||
safeCall(marketContract, 'get_current_snapshot', {}),
|
safeCall(marketContract, 'get_current_snapshot', {}),
|
||||||
safeCall(marketContract, 'get_configuration', {}),
|
safeCall(marketContract, 'get_configuration', {}),
|
||||||
@@ -243,6 +247,13 @@ async function processMarket(marketContract) {
|
|||||||
borrowDecimals,
|
borrowDecimals,
|
||||||
collateralDecimals,
|
collateralDecimals,
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error.message && error.message.includes('does not exist')) {
|
||||||
|
console.log(`Market ${marketContract} has been deleted, skipping...`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tvl() {
|
async function tvl() {
|
||||||
@@ -258,6 +269,9 @@ async function tvl() {
|
|||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === 'fulfilled') {
|
if (result.status === 'fulfilled') {
|
||||||
|
if (result.value === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const { borrowAssetToken, collateralAssetToken, availableLiquidity, totalCollateral, borrowDecimals, collateralDecimals } = result.value
|
const { borrowAssetToken, collateralAssetToken, availableLiquidity, totalCollateral, borrowDecimals, collateralDecimals } = result.value
|
||||||
sumSingleBalance(balances, borrowAssetToken, scaleTokenAmount(availableLiquidity, borrowAssetToken, borrowDecimals))
|
sumSingleBalance(balances, borrowAssetToken, scaleTokenAmount(availableLiquidity, borrowAssetToken, borrowDecimals))
|
||||||
sumSingleBalance(balances, collateralAssetToken, scaleTokenAmount(totalCollateral, collateralAssetToken, collateralDecimals))
|
sumSingleBalance(balances, collateralAssetToken, scaleTokenAmount(totalCollateral, collateralAssetToken, collateralDecimals))
|
||||||
@@ -282,6 +296,9 @@ async function borrowed() {
|
|||||||
|
|
||||||
results.forEach((result, index) => {
|
results.forEach((result, index) => {
|
||||||
if (result.status === 'fulfilled') {
|
if (result.status === 'fulfilled') {
|
||||||
|
if (result.value === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const { borrowAssetToken, totalBorrowed, borrowDecimals } = result.value
|
const { borrowAssetToken, totalBorrowed, borrowDecimals } = result.value
|
||||||
sumSingleBalance(balances, borrowAssetToken, scaleTokenAmount(totalBorrowed, borrowAssetToken, borrowDecimals))
|
sumSingleBalance(balances, borrowAssetToken, scaleTokenAmount(totalBorrowed, borrowAssetToken, borrowDecimals))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user