Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add R Savings Rate (Raft) from Base #1016

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/adaptors/raft/abis/RSavingsRate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"issuanceRate": {
"inputs": [],
"name": "issuanceRate",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
"totalAssets": {
"inputs": [],
"name": "totalAssets",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
}
64 changes: 31 additions & 33 deletions src/adaptors/raft/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
const { default: BigNumber } = require('bignumber.js');
const sdk = require('@defillama/sdk');
const sdk = require('@defillama/sdk4');
const utils = require('../utils');
const rSavingsRateAbi = require('./abis/RSavingsRate.json');

const RR = '0x2ba26baE6dF1153e29813d7f926143f9c94402f3';
const RR = {
ethereum: '0x2ba26baE6dF1153e29813d7f926143f9c94402f3',
base: '0xA5b3FEe253f9DE67201dC8572Bd2CbB4a81c1bEc',
};
const HOUR = 60 * 60;
const DAY = 24 * HOUR;
const SECONDS_PER_YEAR = 365 * DAY;

async function apy() {
async function chainApy(chain) {
const issuanceRate = await sdk.api.abi.call({
target: RR,
abi: {
inputs: [],
name: 'issuanceRate',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
},
target: RR[chain],
chain,
abi: rSavingsRateAbi.issuanceRate,
});
const totalAssets = await sdk.api.abi.call({
target: RR,
abi: {
inputs: [],
name: 'totalAssets',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
},
target: RR[chain],
chain,
abi: rSavingsRateAbi.totalAssets,
});

const apy = 100 * BigNumber(issuanceRate.output)
.times(SECONDS_PER_YEAR)
.div(1e18)
.toNumber();
const apy =
100 *
BigNumber(issuanceRate.output).times(SECONDS_PER_YEAR).div(1e18).toNumber();
const tvlUsd = BigNumber(totalAssets.output).div(1e18).toNumber();

return [
{
pool: RR,
project: 'raft',
symbol: 'R',
chain: 'ethereum',
poolMeta: 'R Savings Rate',
apy,
tvlUsd,
},
];
return {
pool: `${RR[chain]}-${chain}`.toLowerCase(),
project: 'raft',
symbol: 'R',
chain: utils.formatChain(chain),
poolMeta: 'R Savings Rate',
apy,
tvlUsd,
};
}

async function apy() {
return Promise.all(['ethereum', 'base'].map(chainApy));
}

module.exports = {
apy,
url: 'https://app.raft.com/savings',
url: 'https://app.raft.fi/savings',
};
Loading