-
Notifications
You must be signed in to change notification settings - Fork 33
Boni #521
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
Open
sypeer
wants to merge
25
commits into
develop
Choose a base branch
from
feature/tToken-bonus-int
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Boni #521
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b03e197
adding additional storage variables
sypeer eae9d3a
updated tToken strategy for compound with bonus int
sypeer 24295bc
using 365 days instead of BLOCKS_PER_YEAR constant
sypeer 7eb578c
removing unused uint
sypeer 797401e
updating return
sypeer 60aa92b
removing mint
sypeer 9ec8896
updating strategy2 to extend from strategy1
sypeer cd1eb3b
adding virtual modifier to strategy1 init to allow for extensibility
sypeer d4db271
updating ttoken strategy deployment to pass in additional arg
sypeer 62a14d8
updating test setup to set an allowance on the tToken from the 'gnosis'
sypeer eae86ef
gnosisSafe address > immutable, updating the int calc, +ing constructor
sypeer f297d8b
updating market config to use compound strategy 2
sypeer a65503e
basic test setup
sypeer e3c206a
updating testEnv to return hre
sypeer 457daf4
updating tToken strategy test
sypeer 01ee254
init funny?
sypeer 34285bc
updating test setup to use a fresh deployment
sypeer 7aa78ff
updating test to use moment to advance time
sypeer 52411e5
parsing interest calc
sypeer 26150cf
moving bonus int token approval to deploy script
sypeer 6827a21
remove poly ci
sypeer b72e604
adding named signer `gnosisSafe`
sypeer bca1349
using gnosisSafe signer in place of deployer account
sypeer 4b54ff4
adding allowance check for gnosisSafe account
sypeer f90f553
Move balance check inside if statement
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
contracts/lending/ttoken/strategies/compound/TTokenCompoundStrategy_2.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| // Contracts | ||
| import { TTokenCompoundStrategy_1 } from "./TTokenCompoundStrategy_1.sol"; | ||
|
|
||
| // Interfaces | ||
| import { ICErc20 } from "../../../../shared/interfaces/ICErc20.sol"; | ||
| import { LibMeta } from "../../../../shared/libraries/LibMeta.sol"; | ||
|
|
||
| contract TTokenCompoundStrategy_2 is TTokenCompoundStrategy_1 { | ||
| address immutable bonusGnosisSafe; | ||
|
|
||
| /* External Functions */ | ||
|
|
||
| function totalUnderlyingSupply() public override returns (uint256) { | ||
| // Get current supply | ||
| uint256 currentSupply = super.totalUnderlyingSupply(); | ||
|
|
||
| // Calculate bonus interest due | ||
| uint256 interestTimeperiod = block.timestamp - | ||
| compoundStore().lastBonusIntTimestamp; | ||
| uint256 dailyInterest = ((currentSupply / 10) / 365 days) * 1 days; | ||
| uint256 bonusInterest = dailyInterest * (interestTimeperiod / 1 days); | ||
|
|
||
| if (bonusInterest > 0) { | ||
| uint256 gnosisBalance = tokenStore().underlying.balanceOf( | ||
| bonusGnosisSafe | ||
| ); | ||
| if (gnosisBalance < bonusInterest) { | ||
| bonusInterest = gnosisBalance; | ||
| } | ||
|
|
||
| // Deposit into | ||
| tokenStore().underlying.transferFrom( | ||
| bonusGnosisSafe, | ||
| address(this), | ||
| bonusInterest | ||
| ); | ||
| } | ||
|
|
||
| return currentSupply + bonusInterest; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Sets the Compound token that should be used to manage the underlying Teller Token asset. | ||
| * @param cTokenAddress Address of the Compound token that has the same underlying asset as the TToken. | ||
| * @param balanceRatioMin Percentage indicating the _ limit of underlying token balance should remain on the TToken | ||
| * @param balanceRatioMax Percentage indicating the _ limit of underlying token balance should remain on the TToken | ||
| * @dev Note that the balanceRatio percentages have to be scaled by ONE_HUNDRED_PERCENT | ||
| */ | ||
| function init( | ||
| address cTokenAddress, | ||
| uint16 balanceRatioMin, | ||
| uint16 balanceRatioMax | ||
| ) public override { | ||
| super.init(cTokenAddress, balanceRatioMin, balanceRatioMax); | ||
| compoundStore().lastBonusIntTimestamp = block.timestamp; | ||
| NAME = "CompoundStrategy_2"; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Sets the address of the bonus gnosis safe for the bonus interest disbursment | ||
| * @param _bonusGnosisSafe The address of the gnosisSafe to pull funds from for bonus interest | ||
| */ | ||
| constructor(address _bonusGnosisSafe) { | ||
| bonusGnosisSafe = _bonusGnosisSafe; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import chai, { expect } from 'chai' | ||
| import { solidity } from 'ethereum-waffle' | ||
| import { contracts, ethers, network, toBN } from 'hardhat' | ||
| import moment from 'moment' | ||
|
|
||
| import { ERC20, TTokenV3 } from '../../types/typechain' | ||
| import { getFunds } from '../helpers/get-funds' | ||
| import { advanceBlock } from '../helpers/misc' | ||
| import { setTestEnv, TestEnv } from '../helpers/set-test-env' | ||
|
|
||
| chai.should() | ||
| chai.use(solidity) | ||
|
|
||
| setTestEnv('Lending - TToken bonus interest', (testEnv: TestEnv) => { | ||
| it.only('Should accurately dispense the bonus interest', async () => { | ||
| // Load tToken | ||
| const { tokens, tellerDiamond, lender, hre } = testEnv | ||
|
|
||
| const dai: ERC20 = tokens.find((o) => o.name === 'DAI')!.token | ||
|
|
||
| const tDai = await contracts.get<TTokenV3>('ITToken', { | ||
| at: await tellerDiamond.getTTokenFor(dai.address), | ||
| }) | ||
|
|
||
| const bnedAmount = toBN(1000, 18) | ||
|
|
||
| // Get funds for lender | ||
| await getFunds({ | ||
| to: lender, | ||
| tokenSym: await dai.symbol(), | ||
| amount: bnedAmount, | ||
| hre, | ||
| }) | ||
|
|
||
| // Deposit as lender | ||
| const exchangeRateBefore = await tDai.callStatic.exchangeRate() | ||
| const totalUnderlyingBefore = await tDai.callStatic.totalUnderlyingSupply() | ||
|
|
||
| // Approve protocol | ||
| await dai | ||
| .connect(lender) | ||
| .approve(tDai.address, bnedAmount) | ||
| .then(({ wait }) => wait()) | ||
| // Deposit funds | ||
| await tDai | ||
| .connect(lender) | ||
| .mint(bnedAmount) | ||
| .then(({ wait }) => wait()) | ||
|
|
||
| // Advance time | ||
| await hre.ethers.provider.send('evm_increaseTime', [ | ||
| moment.duration(365, 'days').asSeconds(), | ||
| ]) | ||
| await hre.ethers.provider.send('evm_mine', []) | ||
|
|
||
| // Check tToken total underlying | ||
| const totalUnderlyingAfter = await tDai.callStatic.totalUnderlyingSupply() | ||
|
|
||
| // Check tToken exchange rate | ||
| const exchangeRateAfter = await tDai.callStatic.exchangeRate() | ||
|
|
||
| // Assertions | ||
| expect(totalUnderlyingAfter).to.be.gt(totalUnderlyingBefore.add(bnedAmount)) | ||
| expect(exchangeRateAfter).to.be.gt(exchangeRateBefore) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.