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

Feat/upgrade pool #46

Open
wants to merge 67 commits into
base: feat/prod
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d22623f
1st draft) create LP for wombat commit
MuesliW Aug 16, 2023
26f54a1
Merge pull request #42 from Kinza-Finance/feat/prod
MuesliW Aug 23, 2023
ba7b50f
2nd draft (including use of a new AToken impl that stake LP into Mast…
MuesliW Aug 23, 2023
a64cc35
consolidate the change into 1 contract: ATokenMagpieStaker
MuesliW Aug 29, 2023
acfb648
add basic fork test setup; add bsc mainnet contract dependency
MuesliW Aug 29, 2023
ca0fdd0
basic integration test setup, 1 test
MuesliW Aug 31, 2023
a700cca
update fetching of wombatStaking() from the new helper, not the old
MuesliW Aug 31, 2023
b9daf40
refactor to add direct wombat staking since magpie does not support L…
MuesliW Aug 31, 2023
15d9ba4
change directory name
MuesliW Aug 31, 2023
d35b0b0
1st working wombat minimal test suite
MuesliW Aug 31, 2023
e29aa6f
add profile for targeted test run
MuesliW Aug 31, 2023
7a7f6ec
add test to verify flashloan, borrow are disabled on all cases
MuesliW Sep 1, 2023
0ec7263
add setup oracle
MuesliW Sep 1, 2023
4ed3a26
add basic fuzzing
MuesliW Sep 1, 2023
e645bf6
add testing on reward distribution and accrual;
MuesliW Sep 3, 2023
386f0d1
pendingRewards are retrived in getUserRewards instead of AccruedRewards
MuesliW Sep 4, 2023
5feb3b9
remove unnecessary reminder
MuesliW Sep 4, 2023
114b2b0
add reward splitting test
MuesliW Sep 4, 2023
43add3e
make change to function name to improve readeability
MuesliW Sep 4, 2023
e103005
add test on enable/disable collateral
MuesliW Sep 5, 2023
fbac6a4
setup test for eMode and liquidation check, both inside and outside e…
MuesliW Sep 5, 2023
efd73d6
update enableCollateral behavior due to validateUseAsCollateral check
MuesliW Sep 5, 2023
7c3a5a2
update reward distribute check
VinciXie Sep 5, 2023
88de10a
add test for transfer, use startPrank instead of prank to override pr…
MuesliW Sep 6, 2023
8aa9f05
update startPrank instead of prank in reward test
MuesliW Sep 6, 2023
b83dd02
add some reward fuzz testing
VinciXie Sep 6, 2023
646e197
add custom price feed for emode
MuesliW Sep 7, 2023
6f669fa
MVP for leverageHelper
MuesliW Sep 11, 2023
ce4e6eb
refactor levHelper to work for generalized underlying and lp
MuesliW Sep 11, 2023
f1c3379
minimal test for leverage helper
MuesliW Sep 11, 2023
6782f1f
add loop test to levHelper
MuesliW Sep 11, 2023
021b7ac
support first deposit
MuesliW Sep 12, 2023
aa9c74b
a minimal change to test poolUpgrade
MuesliW Sep 12, 2023
3382743
allowance object updated
MuesliW Sep 13, 2023
2ab6ab3
the previous version is wrong with the depositing function, using the…
MuesliW Sep 13, 2023
001a852
Merge pull request #44 from Kinza-Finance/feat/wombat-LP
MuesliW Sep 13, 2023
83e40fd
update deployment script to use the new poolImpl with new supplyLogic…
MuesliW Sep 13, 2023
b6e2d34
add use of whitelist to control deposit in the beginning
MuesliW Sep 14, 2023
0c19e26
add testnet deployment and config
MuesliW Sep 14, 2023
2d7708d
update deployment scripts
MuesliW Sep 14, 2023
e402f61
minor update on source code.
MuesliW Sep 14, 2023
a29c5ba
update deployment of eMode to not use emode feed
MuesliW Sep 14, 2023
a72a165
add test coverage to verify LP cannot be liquidated outside emode, ev…
MuesliW Sep 14, 2023
74e5d40
use noraml price feed instead of emode price feed
MuesliW Sep 14, 2023
5f629c3
wrong mainnet addresses
MuesliW Sep 14, 2023
097728a
add test coverage, verify the borrow loop works
MuesliW Sep 15, 2023
129ce02
make leverageHelper generic
MuesliW Sep 15, 2023
5b10578
add a vanilia loop function
MuesliW Sep 15, 2023
95b7156
add scrript
MuesliW Sep 15, 2023
f340ccb
Merge branch 'feat/prod' into feat/upgradePool
MuesliW Sep 15, 2023
592843f
remove redundent files
MuesliW Sep 15, 2023
9a2bceb
Merge branch 'feat/upgradePool' of https://github.com/Kinza-Finance/K…
MuesliW Sep 15, 2023
768fbff
remove redundent file
MuesliW Sep 15, 2023
3af3903
update mainnet supplyLogic
MuesliW Sep 15, 2023
8ed1fae
update mainnet supplyLogic in deployment
MuesliW Sep 15, 2023
ed1fd8c
remove unneeded interface
MuesliW Sep 16, 2023
f73fd1f
add emissionManager setup scrtip for WOM emission
MuesliW Sep 18, 2023
4fff4f8
add emergencyWithdraw which withdraw all deposit from masterWombat ba…
MuesliW Sep 18, 2023
5b86f64
Update ValidationLogic.sol
MuesliW Sep 19, 2023
10dacfe
merge test into unit.t.sol using proxyUpgrade, remove fallbackOracle
MuesliW Sep 19, 2023
c9a7e20
remove error 34 check
MuesliW Sep 19, 2023
b8233df
Revert "Update ValidationLogic.sol"
MuesliW Sep 19, 2023
d4e7eaa
revert change in validateUseAsCollateral from 3.0.2
MuesliW Sep 22, 2023
13d87bd
revert COLLATERAL_BALANCE_IS_ZERO check
MuesliW Sep 22, 2023
9c2914f
add space for diff
MuesliW Sep 22, 2023
6021d3a
Update ValidationLogic.sol
MuesliW Sep 22, 2023
b8a18ca
Update ValidationLogic.sol
MuesliW Sep 22, 2023
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
Prev Previous commit
Next Next commit
consolidate the change into 1 contract: ATokenMagpieStaker
1. ATokenMagpieStaker that inherit AToken
- forbid borrow/flashloan
- stake/unstake LP upon mint/burn
- allow admin to claim rewards and send it over to EmissionAdminAndDirectTransferStrategy

2. EmissionAdminAndDirectTransferStrategy
- keep rewards token for emission
- act as the transferStrategy too
- direct rewards to emissionManager
  • Loading branch information
MuesliW committed Aug 29, 2023
commit a64cc35db5699853b0733294db22152f5b00ffde
4 changes: 4 additions & 0 deletions src/core/interfaces/IEmissionAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface IEmissionAdmin {
function notify(address[] memory rewards, uint256[] memory amounts) external;

}
5 changes: 5 additions & 0 deletions src/core/interfaces/IMasterMagpie.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface IMasterMagpie {
function multiClaim(address[] memory stakingTokens) external;
function withdraw(address stakingToken, uint256 amount) external;

}
6 changes: 0 additions & 6 deletions src/core/interfaces/IMasterWombatV3.sol

This file was deleted.

5 changes: 5 additions & 0 deletions src/core/interfaces/IWombatHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface IWombatHelper {
function depositLP(uint256 amonut) external;
function wombatStaking() external returns(address);

}
110 changes: 110 additions & 0 deletions src/core/protocol/tokenization/ATokenMagpieStaker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.10;

import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {GPv2SafeERC20} from '../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';
import {IMasterMagpie} from '../../interfaces/IMasterMagpie.sol';
import {IWombatHelper} from '../../interfaces/IWombatHelper.sol';
import {IEmissionAdmin} from '../../interfaces/IEmissionAdmin.sol';
import {IPool} from '../../interfaces/IPool.sol';
import {AToken} from './AToken.sol';

/**
* @notice Implementation of the AToken with the underlying LP staked
* stake on an external gauge; rewards are claimed to the Atoken proxy
* and distributed upon the discretion of an admin
*/
contract ATokenMagpieStaker is AToken {
using GPv2SafeERC20 for IERC20;
IMasterMagpie public _masterMagpie;
IWombatHelper public _wombatHelper;
// manage emission on internal EmissionManager
address public _emissionAdmin;

event StakingRewardClaimed();
/**
* @dev Constructor.
* @param pool The address of the Pool contract
*/
constructor(
IPool pool
) AToken(pool) {
// Intentionally left blank
}

function updateMasterMagpie(address masterMagpie) external onlyPoolAdmin {
// this is fine since it's a proxy
require(address(_masterMagpie) == address(0), "masterMagpie can only be set once");
_masterMagpie = IMasterMagpie(masterMagpie);
}
function updateWombatHelper(address wombatHelper) external onlyPoolAdmin {
// this is fine the contract is quite immutable
require(address(_wombatHelper) == address(0), "wombatHelper can only be set once");
address wombatStaking = _wombatHelper.wombatStaking();
// wombatHerlp::depositLP would trigger wombatStaking which pull LP token from this contract
IERC20(_underlyingAsset).approve(wombatStaking, type(uint256).max);
_wombatHelper = IWombatHelper(wombatHelper);
}

function updateEmissionAdmin(address emissionAdmin) external onlyPoolAdmin {
_emissionAdmin = emissionAdmin;
}

function multiClaim() public onlyPoolAdmin {
address[] memory stakingTokens = new address[](1);
stakingTokens[0] = _underlyingAsset;
/// @dev that is no return data from multiclaim; also masterMagpie is a proxy.
_masterMagpie.multiClaim(stakingTokens);
emit StakingRewardClaimed();
}

function sendEmission(address[] memory rewards) external onlyPoolAdmin {
// claim
multiClaim();
uint256[] memory amounts = new uint256[](rewards.length);
for (uint i; i < rewards.length;) {
require(rewards[i] != _underlyingAsset, "underlying token cannot be sent as rewards");
amounts[i] = IERC20(rewards[i]).balanceOf(address(this));
// avoid unnecessary allowance
// reward are sent to the corresponding vault
IERC20(rewards[i]).transfer(_emissionAdmin, amounts[i]);
unchecked {
i++;
}
}
// emissionAdmin define the distribution details regarding the reward token
IEmissionAdmin(_emissionAdmin).notify(rewards, amounts);
}

function mint(
address caller,
address onBehalfOf,
uint256 amount,
uint256 index
) external virtual override onlyPool returns (bool) {
// helper takes our LP, call wombat staking,
// then stake the wombat stakingToken on magpie itself
_wombatHelper.depositLP(amount);
return _mintScaled(caller, onBehalfOf, amount, index);
}

function burn(
address from,
address receiverOfUnderlying,
uint256 amount,
uint256 index
) external virtual override onlyPool {
address stakingToken = _underlyingAsset;
_masterMagpie.withdraw(stakingToken, amount);
_burnScaled(from, receiverOfUnderlying, amount, index);
if (receiverOfUnderlying != address(this)) {
IERC20(_underlyingAsset).safeTransfer(receiverOfUnderlying, amount);
}
}

/// * @dev Used by the Pool to transfer assets in borrow(() and flashLoan() --- not used in withdraw
function transferUnderlyingTo(address target, uint256 amount) external virtual override onlyPool {
revert("ATokenStaker does not allow flashloan or borrow");
}

}
Loading