Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca5ba9b
feat: Initial fork testing
Apegurus Dec 3, 2021
d0be482
fix: run CI on PR
Apegurus Dec 3, 2021
2ff8784
chore: Update test command
Apegurus Dec 3, 2021
c04b6b9
chore: Remove yarn csche
Apegurus Dec 3, 2021
3bf8401
ci: Add cache
DeFiFoFum Dec 4, 2021
05f97ed
feat: Initial VaulApe MasterChef testing
Apegurus Dec 4, 2021
227dd1f
Merge branch 'feat/fork-testing' of github.com-apeswap:ApeSwapFinance…
Apegurus Dec 4, 2021
e7aa762
refactor: Update postinstall script
DeFiFoFum Dec 4, 2021
5ab3a06
refactor: CI script
DeFiFoFum Dec 4, 2021
9004d80
refactor: Update CI cache action
DeFiFoFum Dec 4, 2021
8bb8e1a
refactor: CI cache key
DeFiFoFum Dec 4, 2021
e8f45ed
refactor: Modularize VaultApe testing
Apegurus Dec 4, 2021
3e0f856
refactor: VaultApe tests add all strategies
Apegurus Dec 4, 2021
58a3fab
chore: Updated packages
Apegurus Dec 5, 2021
affa59b
fix: Import capitalization
Apegurus Dec 5, 2021
4555997
refactor: Revert CI
Apegurus Dec 5, 2021
c7855f6
fix: Import casing
Apegurus Dec 5, 2021
d0191e2
fix: Import typo
Apegurus Dec 5, 2021
007238c
chore: Disable CI cache
Apegurus Dec 5, 2021
f76d4e8
feat: Added new tests
Doublo54 Dec 23, 2021
cec6c97
feat: Improved new tests
Doublo54 Jan 5, 2022
4cef0eb
feat: Added Strategy4Belt. Added tests for BeltToken and 4Belt strate…
Doublo54 Jan 9, 2022
2d07484
fix: userInfo as view
Doublo54 Jan 12, 2022
7cf1e51
fix: pcs router for just belt vaults
Doublo54 Jan 12, 2022
cf5e15e
fix: fixed some tests
Doublo54 Jan 12, 2022
95d0367
refactor: removed some unused variables
Doublo54 Jan 14, 2022
50e2c44
feat: Added specific current block for node fork
Doublo54 Jan 28, 2022
c4a28ea
feat: disabled panic test because of "Number can only safely store up…
Doublo54 Jan 28, 2022
1baa7ba
Merge pull request #2 from ApeSwapFinance/feat/new-tests
Apegurus Jan 30, 2022
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
MAINNET_DEPLOYER_KEY=
TESTNET_DEPLOYER_KEY=

ARCHIVE_NODE_FORK=

# Contract verification api keys
ETHERSCAN_API_KEY=
BSCSCAN_API_KEY=
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name: CI
name: tests

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
strategy:
matrix:
node: ['12.x', '14.x']
node: ['12.x']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

env:
ARCHIVE_NODE_FORK: ${{ secrets.ARCHIVE_NODE_FORK }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand All @@ -23,13 +24,14 @@ jobs:

- run: npm install -g yarn

- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
# - id: yarn-cache
# run: echo "::set-output name=dir::$(yarn cache dir)"
# - uses: actions/cache@v1
# with:
# path: ${{ steps.yarn-cache.outputs.dir }}
# key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ matrix.os }}-yarn-
- run: yarn
- run: yarn test
- run: yarn audit --groups dependencies
- run: yarn test:ci
506 changes: 273 additions & 233 deletions configs/vaults.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions contracts/BaseStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/token/ERC20/Utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/Security/Pausable.sol";
import "@openzeppelin/contracts/Utils/Math/SafeMath.sol";
import "@openzeppelin/contracts/Utils/Math/Math.sol";
import "@openzeppelin/contracts/Security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

import "./libs/IStrategyBanana.sol";
import "./libs/IUniPair.sol";
Expand All @@ -24,7 +24,7 @@ abstract contract BaseStrategy is Ownable, ReentrancyGuard, Pausable {
address public usdAddress;
address public bananaAddress;
// Wrapped native token address (WBNB/WMATIC)
address public wNativeAdress = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270;
address public wNativeAdress = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;

address public rewardAddress = 0x4EB6b0A7543508f6EbD81c2E9c7cA7A471475e73;
address public withdrawFeeAddress = 0x4EB6b0A7543508f6EbD81c2E9c7cA7A471475e73;
Expand Down
158 changes: 158 additions & 0 deletions contracts/Strategy4Belt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "./libs/IBeltLP.sol";
import "./libs/IMasterBelt.sol";
import "./BaseStrategySingle.sol";

// https://bscscan.com/address/0x5df9ce05ea92af1ea324996d12f139847af3dfc7#code
contract Strategy4Belt is BaseStrategySingle, Initializable {
using SafeERC20 for IERC20;
using SafeMath for uint256;

// Third party contracts
address public masterBelt; // address(0xD4BbC80b9B102b77B21A06cb77E954049605E6c1);
address public beltLP; // address(0x9cb73F20164e399958261c289Eb5F9846f4D1404);
uint256 public pid; // 3

/**
address[8] _configAddresses,
_configAddresses[0] _vaultChefAddress,
_configAddresses[1] _masterBelt,
_configAddresses[2] _uniRouterAddress,
_configAddresses[3] _wantAddress,
_configAddress[4] _earnedAddress
_configAddress[5] _usdAddress
_configAddress[6] _bananaAddress
_configAddress[7] _beltLp
*/
function initialize(
address[8] memory _configAddresses,
address[] memory _earnedToWnativePath,
address[] memory _earnedToUsdPath,
address[] memory _earnedToBananaPath,
uint256 _pid
) external initializer {

govAddress = msg.sender;
vaultChefAddress = _configAddresses[0];
masterBelt = _configAddresses[1];
uniRouterAddress = _configAddresses[2];
beltLP = _configAddresses[7];

wantAddress = _configAddresses[3];

pid = _pid;
earnedAddress = _configAddresses[4];
usdAddress = _configAddresses[5];
bananaAddress = _configAddresses[6];

earnedToWnativePath = _earnedToWnativePath;
earnedToUsdPath = _earnedToUsdPath;
earnedToBananaPath = _earnedToBananaPath;

transferOwnership(vaultChefAddress);

_resetAllowances();
}

// puts the funds to work
function _vaultDeposit(uint256 _amount) internal override {
IMasterBelt(masterBelt).deposit(pid, _amount);
}

function _vaultWithdraw(uint256 _amount) internal override {
IMasterBelt(masterBelt).withdraw(pid, _amount);
}

function _vaultHarvest() internal override {
IMasterBelt(masterBelt).deposit(pid, 0);
}

function earn() external override nonReentrant whenNotPaused {
_earn(_msgSender());
}

function earn(address _to) external override nonReentrant whenNotPaused {
_earn(_to);
}

function _earn(address _to) internal {
_vaultHarvest();
uint256 earnedAmt = IERC20(earnedAddress).balanceOf(address(this));

if (earnedAmt > 0) {
earnedAmt = distributeFees(earnedAmt, _to);
earnedAmt = distributeRewards(earnedAmt);
earnedAmt = buyBack(earnedAmt);

// Converts farm tokens into want tokens and farms
_addLiquidity();
_farm();

lastEarnBlock = block.number;
}
}

// Adds liquidity to AMM and gets more LP tokens.
function _addLiquidity() internal {
uint256 autoBal = IERC20(earnedAddress).balanceOf(address(this));
_safeSwap(
autoBal,
earnedToUsdPath,
address(this)
);

uint256 busdBal = IERC20(usdAddress).balanceOf(address(this));
uint256[4] memory uamounts = [0, 0, 0, busdBal];
IBeltLP(beltLP).add_liquidity(uamounts, 0);
}

// calculate the total underlaying 'want' held by the strat.
function wantLockedTotal() public override view returns (uint256) {
return balanceOfWant().add(vaultSharesTotal());
}

// it calculates how much 'want' this contract holds.
function balanceOfWant() public view returns (uint256) {
return IERC20(wantAddress).balanceOf(address(this));
}

// it calculates how much 'want' the strategy has working in the farm.
function vaultSharesTotal() public override view returns (uint256) {
(uint256 amount,) = IMasterBelt(masterBelt).userInfo(pid, address(this));
return amount;
// return IMasterBelt(masterBelt).stakedWantTokens(pid, address(this));
}

// pauses deposits and withdraws all funds from third party systems.
function _emergencyVaultWithdraw() internal override {
IMasterBelt(masterBelt).emergencyWithdraw(pid);
}

function _resetAllowances() internal override {
IERC20(wantAddress).safeApprove(masterBelt, uint256(0));
IERC20(wantAddress).safeApprove(masterBelt, type(uint256).max);

IERC20(earnedAddress).safeApprove(uniRouterAddress, uint256(0));
IERC20(earnedAddress).safeApprove(uniRouterAddress, type(uint256).max);

IERC20(usdAddress).safeApprove(beltLP, uint256(0));
IERC20(usdAddress).safeApprove(beltLP, type(uint256).max);
}

function _removeAllowances() internal {
IERC20(wantAddress).safeApprove(masterBelt, 0);
IERC20(earnedAddress).safeApprove(uniRouterAddress, 0);
IERC20(usdAddress).safeApprove(beltLP, 0);
}

function _beforeDeposit(address _to) internal override {

}

function _beforeWithdraw(address _to) internal override {

}
}
2 changes: 1 addition & 1 deletion contracts/StrategyAutoBeltToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ contract StrategyAutoBeltToken is BaseStrategySingle, Initializable {
vaultChefAddress = _configAddresses[0];
autoFarm = _configAddresses[1];
uniRouterAddress = _configAddresses[2];
oToken = _configAddresses[7];

wantAddress = _configAddresses[3];

pid = _pid;
earnedAddress = _configAddresses[4];
usdAddress = _configAddresses[5];
bananaAddress = _configAddresses[6];
oToken = _configAddresses[7];

earnedToWnativePath = _earnedToWnativePath;
earnedToUsdPath = _earnedToUsdPath;
Expand Down
4 changes: 2 additions & 2 deletions contracts/StrategyBeltToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract StrategyBeltToken is BaseStrategy, Initializable {
earnedAmt = buyBack(earnedAmt);

if (earnedAddress != oToken) {
// Swap earned to token0
// Swap earned to token which can be swapped to beltToken
_safeSwap(
earnedAmt,
earnedToWantPath,
Expand Down Expand Up @@ -143,7 +143,7 @@ contract StrategyBeltToken is BaseStrategy, Initializable {
masterBelt,
type(uint256).max
);

IERC20(earnedAddress).safeApprove(uniRouterAddress, uint256(0));
IERC20(earnedAddress).safeIncreaseAllowance(
uniRouterAddress,
Expand Down
8 changes: 4 additions & 4 deletions contracts/VaultApe.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "@openzeppelin/contracts/token/ERC20/Utils/SafeERC20.sol";
import "@openzeppelin/contracts/Utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/Security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/Utils/Math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "./libs/IStrategy.sol";
Expand Down
6 changes: 3 additions & 3 deletions contracts/VaultApeWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity 0.8.6;

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/token/ERC20/Utils/SafeERC20.sol";
import "@openzeppelin/contracts/Security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/Utils/Math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";

Expand Down
74 changes: 74 additions & 0 deletions contracts/libs/IMasterBelt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
interface IMasterBelt {
function owner() external view returns (address);

function BELT() external returns (address);

function burnAddress() external returns (address);

function ownerBELTReward() external returns (uint256);

function BELTPerBlock() external returns (uint256);

function startBlock() external returns (uint256);

function poolInfo(uint256)
external
returns (
address want,
uint256 allocPoint,
uint256 lastRewardBlock,
uint256 accBELTPerShare,
address strat
);

function userInfo(uint256, address)
external
view
returns (uint256 shares, uint256 rewardDebt);

function totalAllocPoint() external returns (uint256);

function poolLength() external view returns (uint256);

function add(
uint256 _allocPoint,
address _want,
bool _withUpdate,
address _strat
) external;

function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) external;

function getMultiplier(uint256 _from, uint256 _to)
external
view
returns (uint256);

function pendingBELT(uint256 _pid, address _user)
external
view
returns (uint256);

function stakedWantTokens(uint256 _pid, address _user)
external
view
returns (uint256);

function massUpdatePools() external;

function updatePool(uint256 _pid) external;

function deposit(uint256 _pid, uint256 _wantAmt) external;

function withdraw(uint256 _pid, uint256 _wantAmt) external;

function withdrawAll(uint256 _pid) external;

function emergencyWithdraw(uint256 _pid) external;

function inCaseTokensGetStuck(address _token, uint256 _amount) external;
}
2 changes: 2 additions & 0 deletions contracts/libs/IUniPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ pragma solidity 0.8.6;
interface IUniPair {
function token0() external view returns (address);
function token1() external view returns (address);
function transfer(address to, uint value) external returns (bool);
function balanceOf(address owner) external view returns (uint);
}
Loading