Skip to content

Commit

Permalink
track zivoe #12792
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Dec 20, 2024
1 parent 79b376a commit 34aadf0
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions projects/zivoe/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { getLogs2 } = require("../helper/cache/getLogs");

const LOANS_FROM_BLOCK = 20973423;

// On-Chain Credit Locker
const OCC_USDC = "0xfAb4e880467e26ED46F00c669C28fEaC58262698";

// TVL Owners
const DAO = "0xB65a66621D7dE34afec9b9AC0755133051550dD7";
const YDL = "0xfB7920B55887840643e20952f22Eb18dDC474B2B";
const ST_STT = "0x0D45c292baCdC47CE850E4c83a2FA2e8509DEd5D";
const ST_JTT = "0xcacdB1A5a11F824E02De4CA6E7b2D12BB278aA7c";

// TVL Asset
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";

async function borrowed(api) {
const loansIds = await getLogs2({
api,
target: OCC_USDC,
eventAbi: "event OfferAccepted(uint256 indexed id, uint256 principal, address indexed borrower, uint256 paymentDueBy)",
fromBlock: LOANS_FROM_BLOCK,
customCacheFunction: ({ cache, logs }) => {
if (!cache.logs) cache.logs = []
cache.logs.push(...logs.map(i => i.id.toString()))
cache.logs = [...new Set(cache.logs)]
return cache
},
});

const loans = await api.multiCall({
abi: "function loans(uint256) view returns (address borrower, uint256 principalOwed, uint256 APR, uint256 APRLateFee, uint256 paymentDueBy, uint256 paymentsRemaining, uint256 term, uint256 paymentInterval, uint256 offerExpiry, uint256 gracePeriod, int8 paymentSchedule, uint8 state)",
target: OCC_USDC,
calls: loansIds,
});
const owedAmounts = loans.map(({ principalOwed }) => principalOwed);

const occAsset = await api.call({ abi: "address:stablecoin", target: OCC_USDC });
const tokens = Array(owedAmounts.length).fill(occAsset);

api.addTokens(tokens, owedAmounts);
}

module.exports = {
ethereum: {
tvl: () => ({}),
borrowed,
},
};

0 comments on commit 34aadf0

Please sign in to comment.