forked from neptune-mutual-blue/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a check on strategy withdrawal to ensure that redeeming aTokens or cTokens results in stablecoin withdrawals - Added `getLendingPeriods` to `ILiquidityEngine` - Refactored `getLendingPeriodKey` and `getWithdrawalWindowKey` on StrategyLibV1 to drop `ignoreMissingKey` check - Added more tests to increase coverage
- Loading branch information
Showing
26 changed files
with
1,108 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,32 @@ | ||
// Neptune Mutual Protocol (https://neptunemutual.com) | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.0; | ||
import "../interfaces/external/IAaveV2LendingPoolLike.sol"; | ||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | ||
import "./FakeToken.sol"; | ||
|
||
contract FaultyAaveLendingPool is IAaveV2LendingPoolLike, ERC20 { | ||
FakeToken public aToken; | ||
|
||
constructor(FakeToken _aToken) ERC20("aDAI", "aDAI") { | ||
aToken = _aToken; | ||
} | ||
|
||
function deposit( | ||
address asset, | ||
uint256 amount, | ||
address, | ||
uint16 | ||
) external override { | ||
IERC20(asset).transferFrom(msg.sender, address(this), amount); | ||
} | ||
|
||
function withdraw( | ||
address, /*asset*/ | ||
uint256 amount, | ||
address /*to*/ | ||
) external override returns (uint256) { | ||
aToken.transferFrom(msg.sender, address(this), amount); | ||
return amount; | ||
} | ||
} |
This file contains 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,48 @@ | ||
// Neptune Mutual Protocol (https://neptunemutual.com) | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.0; | ||
import "../interfaces/external/ICompoundERC20DelegatorLike.sol"; | ||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | ||
import "./FakeToken.sol"; | ||
|
||
contract FaultyCompoundDaiDelegator is ICompoundERC20DelegatorLike, ERC20 { | ||
FakeToken public dai; | ||
FakeToken public cDai; | ||
uint256 public returnValue; | ||
|
||
function setReturnValue(uint256 _returnValue) external { | ||
returnValue = _returnValue; | ||
} | ||
|
||
constructor( | ||
FakeToken _dai, | ||
FakeToken _cDai, | ||
uint256 _returnValue | ||
) ERC20("cDAI", "cDAI") { | ||
dai = _dai; | ||
cDai = _cDai; | ||
returnValue = _returnValue; | ||
} | ||
|
||
/** | ||
* @notice Sender supplies assets into the market and receives cTokens in exchange | ||
* @dev Accrues interest whether or not the operation succeeds, unless reverted | ||
* @param mintAmount The amount of the underlying asset to supply | ||
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) | ||
*/ | ||
function mint(uint256 mintAmount) external override returns (uint256) { | ||
dai.transferFrom(msg.sender, address(this), mintAmount); | ||
return returnValue; | ||
} | ||
|
||
/** | ||
* @notice Sender redeems cTokens in exchange for the underlying asset | ||
* @dev Accrues interest whether or not the operation succeeds, unless reverted | ||
* @param redeemTokens The number of cTokens to redeem into underlying | ||
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) | ||
*/ | ||
function redeem(uint256 redeemTokens) external override returns (uint256) { | ||
cDai.transferFrom(msg.sender, address(this), redeemTokens); | ||
return returnValue; | ||
} | ||
} |
This file contains 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,17 @@ | ||
// Neptune Mutual Protocol (https://neptunemutual.com) | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.0; | ||
|
||
import "../core/liquidity/strategies/AaveStrategy.sol"; | ||
|
||
contract InvalidStrategy is AaveStrategy { | ||
constructor( | ||
IStore _s, | ||
IAaveV2LendingPoolLike _lendingPool, | ||
address _aToken | ||
) AaveStrategy(_s, _lendingPool, _aToken) {} // solhint-disable-line | ||
|
||
function getWeight() external pure override returns (uint256) { | ||
return 20_000; // 100% | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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,37 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
const BigNumber = require('bignumber.js') | ||
const { deployer, key, helper } = require('../../../../../util') | ||
const { deployDependencies } = require('../deps') | ||
const cache = null | ||
|
||
require('chai') | ||
.use(require('chai-as-promised')) | ||
.use(require('chai-bignumber')(BigNumber)) | ||
.should() | ||
|
||
describe('Aave Strategy Constructor', () => { | ||
let deployed, aaveLendingPool, aToken | ||
|
||
beforeEach(async () => { | ||
deployed = await deployDependencies() | ||
|
||
aToken = await deployer.deploy(cache, 'FakeToken', 'aToken', 'aToken', helper.ether(100_000_000)) | ||
aaveLendingPool = await deployer.deploy(cache, 'FakeAaveLendingPool', aToken.address) | ||
}) | ||
|
||
it('correctly deploys', async () => { | ||
const aaveStrategy = await deployer.deployWithLibraries(cache, 'AaveStrategy', { | ||
AccessControlLibV1: deployed.accessControlLibV1.address, | ||
BaseLibV1: deployed.baseLibV1.address, | ||
NTransferUtilV2: deployed.transferLib.address, | ||
ProtoUtilV1: deployed.protoUtilV1.address, | ||
RegistryLibV1: deployed.registryLibV1.address, | ||
StoreKeyUtil: deployed.storeKeyUtil.address, | ||
ValidationLibV1: deployed.validationLibV1.address | ||
}, deployed.store.address, aaveLendingPool.address, aToken.address) | ||
|
||
; (await aaveStrategy.getKey()).should.equal(ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], ['lending', 'strategy', 'aave', 'v2'])) | ||
; (await aaveStrategy.version()).should.equal(key.toBytes32('v0.1')) | ||
; (await aaveStrategy.getName()).should.equal(key.PROTOCOL.CNAME.STRATEGY_AAVE) | ||
}) | ||
}) |
Oops, something went wrong.