fix: adjust stablecoin outstanding supply for reserve holdings and lost tokens#88
fix: adjust stablecoin outstanding supply for reserve holdings and lost tokens#88
Conversation
…st tokens Subtract from total outstanding stablecoin supply: - Stablecoins held directly by reserve addresses - Stablecoins deposited in AAVE by the reserve - Lost tokens (stablecoins held by their own contract addresses) Also removes USDm/EURm from reserve AAVE holdings since they are liabilities, not assets. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🚀 Preview DeploymentYour preview deployment is ready! 🔗 Preview URL: https://analytics-api-preview-feat-fix-accounting-a4neydykmq-uc.a.run.app/docs 📝 Details:
This preview will be automatically updated with each new commit to this PR and will be deleted when the PR is merged or closed. |
Remove configurable dead addresses - only check tokens held by their own contract address (self-held tokens that are unrecoverable). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tokens passed to adjustments service already come from Mento SDK's getStableTokens(), so no need to filter again. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…died Funds Remove Celo Community Shared Reserve (0x9d65E69aC940dCB469fd7C46368C1e094250a400) and add Falcon Finance Custodied Funds (0x619600F4ec13C38868841cB83100F611eCF94eE8) tracking CELO tokens on Celo network. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Instead of using the totalSupply value returned by the Mento SDK, fetch it directly from each token contract on Celo. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use Promise.all to fetch all token/holder balance combinations concurrently instead of sequentially. The rate limiter will still queue requests appropriately, but this queues them all upfront rather than waiting for each to complete before starting the next. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add [TIMING] logs to: - Reserve controller getReserveStats - Reserve service fetchReserveHoldingsInternal - Stablecoins service getStablecoins - Stablecoin adjustments service (all methods) Also parallelize reserve holdings and stablecoins fetch in getReserveStats. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Increase global RPC concurrency from 1 to 10, per-chain from 1 to 5, and reduce minimum delay between requests from 500ms to 50ms. This dramatically reduces /api/v1/reserve/stats response time from ~62s to a few seconds. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| import { ExchangeRatesService } from '@/common/services/exchange-rates.service'; | ||
| import { Chain } from '@types'; | ||
| import { withRetry, RETRY_CONFIGS } from '@/utils'; | ||
| import { ERC20_ABI, ViemAdapter, AAVESupplyCalculator } from '@mento-protocol/mento-sdk'; |
There was a problem hiding this comment.
nit: We should have moved this AAVESupplyCalculator along with any of the remaining supply adjustment logic out of the sdk and into the API, since they're no longer being used there.
There was a problem hiding this comment.
Yeah I had the same thought but punted it initially. But I did it in the end.
| label: 'Mento Pools Liquidity Reserve', | ||
| }, | ||
| { | ||
| address: '0x87647780180b8f55980c7d3ffefe08a9b29e9ae1', |
There was a problem hiding this comment.
nit: This doesn't break anything, but the same address is lower case here vs checksummed on line 43. Also, acknowledge that I've done the same in the addresses config file..
| private blockWatchers = new Map<Chain, () => void>(); | ||
| private rpcLimiters = new Map<Chain, ReturnType<typeof pLimit>>(); | ||
| private globalRpcLimiter = pLimit(1); | ||
| private globalRpcLimiter = pLimit(10); |
There was a problem hiding this comment.
i vaguely remember that @Andrew718PLTS played a lot with these values to reduce RPC errors we saw in sentry quite frequently
should keep an eye on those errors popping back up, let's see how it works in practice
Summary
This PR moves reserve accounting logic from the SDK into the API. The SDK will now return raw on-chain totalSupply values (see mento-sdk#116), and the API handles all adjustments for accurate outstanding supply calculation.
Stablecoin Accounting Fixes
Reserve Address Updates
0x619600F4ec13C38868841cB83100F611eCF94eE8)Performance Improvements
SDK Migration
AAVESupplyCalculatorfrom SDK to API (src/common/services/calculators)UniV3SupplyCalculatorfrom SDK to APIERC20_ABIand UniV3 ABIs to local constantssrc/common/config/aave.config.ts)ViemAdapterdependency - calculators now useChainClientServicedirectlyMentoclass is now imported from@mento-protocol/mento-sdkTest plan
/api/v1/stablecoinsreturns adjusted supplies/api/v1/reserve/statscollateralization ratio uses adjusted outstanding🤖 Generated with Claude Code