|
| 1 | +const sdk = require('@defillama/sdk'); |
| 2 | +const utils = require('../utils'); |
| 3 | + |
| 4 | +const { formatUnits } = require("ethers").utils; |
| 5 | + |
| 6 | +const BUSD_ADDRESS = "0x602BaeaB9B0DE4a99C457cf1249088932AA04FaC"; |
| 7 | +const SBUSD_ADDRESS = "0x451812019238785086CFAC408D8A64f06898f6f5"; |
| 8 | +const SPOT_PRICE_ORACLE_ADDRESS = "0x095e7e8993A436adf87C90Da2314Da1EfB8F1bA0"; |
| 9 | + |
| 10 | +const CHAIN = "sonic"; |
| 11 | + |
| 12 | +const apy = async () => { |
| 13 | + const [ |
| 14 | + { output: rewardRatePerSecond }, |
| 15 | + { output: rewardDistributionEnd }, |
| 16 | + { output: totalReserves }, |
| 17 | + { output: pendingReward }, |
| 18 | + { output: balance }, |
| 19 | + { output: [,underlyingPrice] } |
| 20 | + ] = await Promise.all([ |
| 21 | + sdk.api.abi.call({ |
| 22 | + target: SBUSD_ADDRESS, |
| 23 | + abi: "function rewardRatePerSecond() view returns (uint256)", |
| 24 | + chain: CHAIN, |
| 25 | + }), |
| 26 | + sdk.api.abi.call({ |
| 27 | + target: SBUSD_ADDRESS, |
| 28 | + abi: "function rewardDistributionEnd() view returns (uint256)", |
| 29 | + chain: CHAIN, |
| 30 | + }), |
| 31 | + sdk.api.abi.call({ |
| 32 | + target: SBUSD_ADDRESS, |
| 33 | + abi: "function totalReserves() view returns (uint256)", |
| 34 | + chain: CHAIN, |
| 35 | + }), |
| 36 | + sdk.api.abi.call({ |
| 37 | + target: SBUSD_ADDRESS, |
| 38 | + abi: "function pendingReward() view returns (uint256)", |
| 39 | + chain: CHAIN, |
| 40 | + }), |
| 41 | + sdk.api.abi.call({ |
| 42 | + target: BUSD_ADDRESS, |
| 43 | + abi: "function balanceOf(address) view returns (uint256)", |
| 44 | + params: [SBUSD_ADDRESS], |
| 45 | + chain: CHAIN, |
| 46 | + }), |
| 47 | + sdk.api.abi.call({ |
| 48 | + target: SPOT_PRICE_ORACLE_ADDRESS, |
| 49 | + abi: "function currentPrice() view returns (uint256,uint256)", |
| 50 | + chain: CHAIN, |
| 51 | + }), |
| 52 | + ]); |
| 53 | + |
| 54 | + const tvl = BigInt(balance) - BigInt(pendingReward) - BigInt(totalReserves); |
| 55 | + |
| 56 | + // underlyingPrice has 8 decimals, BUSD is 18 decimals => scale to 10^26 |
| 57 | + const tvlUsd = Number(formatUnits(tvl * BigInt(underlyingPrice), 26)); |
| 58 | + |
| 59 | + const now = Math.floor(Date.now() / 1000); |
| 60 | + const apr = (tvl > 0n && rewardDistributionEnd > now) |
| 61 | + ? formatUnits(BigInt(rewardRatePerSecond) * 86400n * 365n * 1_0000_0000n / tvl, 6) // scale factor = 1e6 |
| 62 | + : 0; |
| 63 | + |
| 64 | + return [ |
| 65 | + { |
| 66 | + pool: SBUSD_ADDRESS, |
| 67 | + chain: CHAIN, |
| 68 | + project: 'brunch', |
| 69 | + symbol: utils.formatSymbol('sbUSD'), |
| 70 | + tvlUsd, |
| 71 | + underlyingTokens: [BUSD_ADDRESS], |
| 72 | + apyBase: utils.aprToApy(apr), |
| 73 | + apyReward: 0, |
| 74 | + rewardTokens: null, |
| 75 | + } |
| 76 | + ]; |
| 77 | +}; |
| 78 | + |
| 79 | +module.exports = { |
| 80 | + timetravel: false, |
| 81 | + apy, |
| 82 | + url: 'https://brunch.finance/stake', |
| 83 | +}; |
0 commit comments