Skip to content

Commit

Permalink
Add TEMP staking yields (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvukasin authored Oct 20, 2023
1 parent 8711550 commit 24d392c
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/adaptors/tempus-finance/abis/TempStaking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"totalStakedSupply": {
"inputs": [],
"name": "totalStakedSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
"rewardPrograms": {
"inputs": [
{ "internalType": "contract IERC20", "name": "", "type": "address" }
],
"name": "rewardPrograms",
"outputs": [
{
"internalType": "uint256",
"name": "rewardPerSecond",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "lastRewardPerTokenCached",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "lastUpdateTime",
"type": "uint256"
},
{ "internalType": "uint256", "name": "startTime", "type": "uint256" },
{ "internalType": "uint256", "name": "finishTime", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
"timeMultiplierIncreasePerSec": {
"inputs": [],
"name": "timeMultiplierIncreasePerSec",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
}
}
105 changes: 105 additions & 0 deletions src/adaptors/tempus-finance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const { default: BigNumber } = require('bignumber.js');
const axios = require('axios');
const sdk = require('@defillama/sdk4');
const tempStaking = require('./abis/TempStaking.json');

const STAKING = '0x6C6D4753a1107585121599746c2E398cCbEa5119';
const TEMP = '0xA36FDBBAE3c9d55a1d67EE5821d53B50B63A1aB9';
const RAFT = '0x4C5Cb5D87709387f8821709f7a6664f00DcF0C93';

async function getEstimatedApy(
rewardPerSecond,
timeMultiplierIncreasePerSec,
stakeAmount,
totalTempStaked,
tempPrice,
raftPrice,
stakeStart,
stakeEnd
) {
// rewards = (stakeAmount / (stakeAmount + totalTempStaked)) * rewardsPerSecond * (stakeEnd - stakeStart) * (1 + timeMultiplierIncreasePerSec * (stakeEnd - stakeStart));
const rewards = stakeAmount
.times(1e18)
.div(stakeAmount.plus(totalTempStaked))
.times(rewardPerSecond)
.div(1e18)
.times(stakeEnd - stakeStart)
.times(
BigNumber(1).plus(
timeMultiplierIncreasePerSec.times(stakeEnd - stakeStart).div(1e18)
)
);

// apr = rewards * (raftPrice / tempPrice) * (SECONDS_IN_A_YEAR / stakeEnd) / stakeAmount;
return rewards
.times(raftPrice / tempPrice)
.times((60 * 60 * 24 * 365) / stakeEnd)
.div(stakeAmount);
}

async function getTokenPrice(token) {
const networkTokenPair = `ethereum:${token}`;
return (
await axios.get(`https://coins.llama.fi/prices/current/${networkTokenPair}`)
).data.coins[networkTokenPair].price;
}

async function apy() {
const totalStaked = BigNumber(
(
await sdk.api.abi.call({
target: STAKING,
abi: tempStaking.totalStakedSupply,
})
).output
);
const rewardPerSecond = BigNumber(
(
await sdk.api.abi.call({
target: STAKING,
abi: tempStaking.rewardPrograms,
params: [RAFT],
})
).output.rewardPerSecond
);
const timeMultiplierIncreasePerSec = BigNumber(
(
await sdk.api.abi.call({
target: STAKING,
abi: tempStaking.timeMultiplierIncreasePerSec,
})
).output
);
const tempPrice = await getTokenPrice(TEMP);
const raftPrice = await getTokenPrice(RAFT);

const apy = await getEstimatedApy(
rewardPerSecond,
timeMultiplierIncreasePerSec,
BigNumber(1),
totalStaked,
tempPrice,
raftPrice,
0,
1
);
const totalStakedUsd = totalStaked.times(tempPrice).div(1e18).toNumber();

return [
{
pool: `${STAKING}-${RAFT}`.toLowerCase(),
project: 'tempus-finance',
symbol: 'TEMP',
chain: 'Ethereum',
poolMeta: 'TEMP Staking',
apyReward: apy.toNumber() * 100,
rewardTokens: [RAFT],
tvlUsd: totalStakedUsd,
},
];
}

module.exports = {
apy,
url: 'https://stake.tempus.finance/',
};

0 comments on commit 24d392c

Please sign in to comment.