├── Depth.DEX
├── interfaces
│ ├── IDepthswapCallee.sol
│ ├── IERC20.sol
│ ├── IDepthswapFactory.sol
│ ├── IDepthswapERC20.sol
│ ├── IDepthswapPair.sol
│ └── IDepthswapRouter.sol
├── library
│ ├── UQ112x112.sol
│ ├── TransferHelper.sol
│ ├── SafeMath.sol
│ └── DepthswapLibrary.sol
├── Multicall.sol
├── DepthswapERC20.sol
├── DepthFee.sol
└── DepthswapFactory.sol
├── Depth.DAO
├── README.md
└── Voting.sol
├── depth.otc
├── interfaces
│ ├── IDepth.sol
│ ├── IOtcV2.sol
│ └── IOtcV1.sol
└── OtcStorageV2.sol
├── README.md
├── BSCContracts
├── FundingManager.sol
├── Channels-3Pool
│ └── SellLendPlatformToken.sol
└── vault
│ ├── dDepBxhVault.sol
│ ├── dDepVenusVault.sol
│ └── dCowVault.sol
├── depth.vault
├── interface
│ └── IVault.sol
├── dCowVault.sol
├── dBackVault.sol
├── dPilotVault.sol
├── dCompVault.sol
├── dBoosterVault.sol
└── dVaultRouter.sol
├── depthStableSwapV2
├── SellLendPlatformToken(Filda).sol
└── SellLendPlatformToken(Lendhub).sol
├── HandleCan.sol
├── fildaPool
├── handleFilda.sol
└── CurveTokenV1.vy
├── lendhub-eth-beth
├── handLHB.sol
└── CurveTokenV1.vy
├── SingleTokenPool
└── SingleTokenPool.sol
├── DepthTokenV1.vy
├── channelsPool
└── LPToken.vy
├── lendhubPool
├── CurveTokenV1.vy
└── handLHB.sol
├── husdSwap.sol
└── ActivityPool.sol
/Depth.DEX/interfaces/IDepthswapCallee.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.0;
2 |
3 | interface IDepthswapCallee {
4 | function DepthswapCall(address sender, uint amount0, uint amount1, bytes calldata data) external;
5 | }
6 |
--------------------------------------------------------------------------------
/Depth.DAO/README.md:
--------------------------------------------------------------------------------
1 | ### DAOPool.sol
2 | DAOPool receives HUSD from Filda, Channels, Lendhub-HUSD-USDT, Lenhub-ETH-BETH Pools. HUSD is converted from platform tokens like (FilDa, CAN, LHB) and pool fees.
3 |
4 | ### handleXXX.sol
5 | handleXXX.sol converts platform token, admin fees to HUSD and sends HUSD to DAOPool.
6 |
7 | ### xDep.sol
8 | Contract of xDep token.
9 |
--------------------------------------------------------------------------------
/Depth.DEX/library/UQ112x112.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
4 |
5 | // range: [0, 2**112 - 1]
6 | // resolution: 1 / 2**112
7 |
8 | library UQ112x112 {
9 | uint224 constant Q112 = 2**112;
10 |
11 | // encode a uint112 as a UQ112x112
12 | function encode(uint112 y) internal pure returns (uint224 z) {
13 | z = uint224(y) * Q112; // never overflows
14 | }
15 |
16 | // divide a UQ112x112 by a uint112, returning a UQ112x112
17 | function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
18 | z = x / uint224(y);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/depth.otc/interfaces/IDepth.sol:
--------------------------------------------------------------------------------
1 |
2 | pragma solidity ^0.8.0;
3 |
4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5 |
6 | interface stakeContract {
7 | function poolInfo(uint256) external view returns(address lpToken,uint256 allocPoint,uint256 lastRewardBlock,uint256 accPiggyPerShare,uint256 totalDeposit,address migrator);
8 | function userInfo(uint256,address) external view returns(uint256,uint256,uint256,bool);
9 | function stake(uint256,uint256) external;
10 | function pendingPiggy(uint256 _pid, address _user) external view returns (uint256) ;
11 | function claim(uint256 _pid) external;
12 | function unStake(uint256 _pid, uint256 _amount) external ;
13 | }
14 |
--------------------------------------------------------------------------------
/Depth.DEX/interfaces/IERC20.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | interface IERC20 {
4 | event Approval(address indexed owner, address indexed spender, uint value);
5 | event Transfer(address indexed from, address indexed to, uint value);
6 |
7 | function name() external view returns (string memory);
8 | function symbol() external view returns (string memory);
9 | function decimals() external view returns (uint8);
10 | function totalSupply() external view returns (uint);
11 | function balanceOf(address owner) external view returns (uint);
12 | function allowance(address owner, address spender) external view returns (uint);
13 |
14 | function approve(address spender, uint value) external returns (bool);
15 | function transfer(address to, uint value) external returns (bool);
16 | function transferFrom(address from, address to, uint value) external returns (bool);
17 | }
18 |
--------------------------------------------------------------------------------
/Depth.DEX/interfaces/IDepthswapFactory.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | interface IDepthswapFactory {
4 | event PairCreated(address indexed token0, address indexed token1, address pair, uint);
5 |
6 | function feeTo() external view returns (address);
7 | function feeToSetter() external view returns (address);
8 |
9 | function getPair(address tokenA, address tokenB) external view returns (address pair);
10 | function allPairs(uint) external view returns (address pair);
11 | function allPairsLength() external view returns (uint);
12 |
13 | function createPair(address tokenA, address tokenB) external returns (address pair);
14 |
15 | function setFeeTo(address) external;
16 | function setFeeToSetter(address) external;
17 |
18 | function setallowAllOn(bool _bvalue) external;
19 |
20 | function getFeeRate(address _address) external view returns (uint256);
21 |
22 | function FEE_RATE_DENOMINATOR() external view returns (uint256);
23 | function feeRateNumerator() external view returns (uint256);
24 | }
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Depth Smart Contracts
2 | ### This repo contains the underlying smart contracts of the Depth dApp.
3 |
4 |
5 |
6 | ## Verified Contract Links
7 | | Contract | Description| Link |
8 | | -----|--------| ----------- |
9 | | Channels Deposit | Deposit/withdarw HUSD and USDT | https://hecoinfo.com/address/0x11bFEE9D8625ac4cDa6Ce52EeBF5caC7DC033d15#code |
10 | | Channels Swap | Swap HUSD/USDT/cHUSD/cUSDT
Deposit/withdarw cHUSD and cUSDT | https://hecoinfo.com/address/0x1D1cF3b43bC54B7D8e0F763B6b8957F480367834#code |
11 | | Channels LP | Channels pool LP token | https://hecoinfo.com/address/0x8b65b86dc3CaDcA97b50D4757BB8A686E6ea0cE1#code |
12 | | Handle CAN | Contract that sell can to cHUSD/cUSDT | https://hecoinfo.com/address/0xCeE590c515B18a3de4AB61AD3A729F27C1E6623C#code |
13 | | Mining | Staking LP to mine DEP | https://hecoinfo.com/address/0x59F8AD2495236B25BA95E3161154F0024fbDBDCe#code |
14 | | DEP Token | Contract of DEP token | https://hecoinfo.com/address/0x48C859531254F25e57D1C1A8E030Ef0B1c895c27#code |
15 |
--------------------------------------------------------------------------------
/depth.otc/interfaces/IOtcV2.sol:
--------------------------------------------------------------------------------
1 |
2 | pragma solidity ^0.8.0;
3 |
4 | import "../openzeppelin/contracts/token/ERC20/IERC20.sol";
5 |
6 | interface IOtcV2 {
7 | event Swap(
8 | uint256 indexed nonce,
9 | uint256 timestamp,
10 | address indexed makerAddress,
11 | address makerToken,
12 | uint256 makerAmount,
13 | address indexed takerAddress,
14 | address takerToken,
15 | uint256 takerAmount,
16 | uint256 feeAmount
17 | );
18 |
19 | event Cancel(uint256 indexed nonce, address indexed makerAddress);
20 |
21 | event Authorize(address indexed signer, address indexed makerAddress);
22 |
23 | event Revoke(address indexed signer, address indexed makerAddress);
24 |
25 | }
26 | interface IHusdSwap {
27 | function swapTokensToHusd(address _token,uint256 _amount) external;
28 | }
29 |
30 | interface IStorage {
31 | function saveTradeInfo(uint256 _amount,uint256 _fee) external;
32 | }
33 | interface IDao {
34 | function donateHUSD(uint256 amount) external;
35 | }
36 | interface ISwapMining{
37 | function takerWithdraw() external;
38 | }
39 |
--------------------------------------------------------------------------------
/Depth.DEX/interfaces/IDepthswapERC20.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.0;
2 |
3 | interface IDepthswapERC20 {
4 | event Approval(address indexed owner, address indexed spender, uint value);
5 | event Transfer(address indexed from, address indexed to, uint value);
6 |
7 | function name() external pure returns (string memory);
8 | function symbol() external pure returns (string memory);
9 | function decimals() external pure returns (uint8);
10 | function totalSupply() external view returns (uint);
11 | function balanceOf(address owner) external view returns (uint);
12 | function allowance(address owner, address spender) external view returns (uint);
13 |
14 | function approve(address spender, uint value) external returns (bool);
15 | function transfer(address to, uint value) external returns (bool);
16 | function transferFrom(address from, address to, uint value) external returns (bool);
17 |
18 | function DOMAIN_SEPARATOR() external view returns (bytes32);
19 | function PERMIT_TYPEHASH() external pure returns (bytes32);
20 | function nonces(address owner) external view returns (uint);
21 |
22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
23 | }
24 |
--------------------------------------------------------------------------------
/Depth.DEX/library/TransferHelper.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
4 | library TransferHelper {
5 | function safeApprove(address token, address to, uint value) internal {
6 | // bytes4(keccak256(bytes('approve(address,uint256)')));
7 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
8 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
9 | }
10 |
11 | function safeTransfer(address token, address to, uint value) internal {
12 | // bytes4(keccak256(bytes('transfer(address,uint256)')));
13 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
14 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
15 | }
16 |
17 | function safeTransferFrom(address token, address from, address to, uint value) internal {
18 | // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
19 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
20 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
21 | }
22 |
23 | function safeTransferETH(address to, uint value) internal {
24 | (bool success,) = to.call{value:value}(new bytes(0));
25 | require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
26 | }
27 | }
--------------------------------------------------------------------------------
/Depth.DEX/Multicall.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0;
2 | pragma experimental ABIEncoderV2;
3 |
4 | contract Multicall {
5 | struct Call {
6 | address target;
7 | bytes callData;
8 | }
9 | function aggregate(Call[] memory calls) public returns (uint256 blockNumber, bytes[] memory returnData) {
10 | blockNumber = block.number;
11 | returnData = new bytes[](calls.length);
12 | for(uint256 i = 0; i < calls.length; i++) {
13 | (bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
14 | require(success);
15 | returnData[i] = ret;
16 | }
17 | }
18 | // Helper functions
19 | function getEthBalance(address addr) public view returns (uint256 balance) {
20 | balance = addr.balance;
21 | }
22 | function getBlockHash(uint256 blockNumber) public view returns (bytes32 blockHash) {
23 | blockHash = blockhash(blockNumber);
24 | }
25 | function getLastBlockHash() public view returns (bytes32 blockHash) {
26 | blockHash = blockhash(block.number - 1);
27 | }
28 | function getCurrentBlockTimestamp() public view returns (uint256 timestamp) {
29 | timestamp = block.timestamp;
30 | }
31 | function getCurrentBlockDifficulty() public view returns (uint256 difficulty) {
32 | difficulty = block.difficulty;
33 | }
34 | function getCurrentBlockGasLimit() public view returns (uint256 gaslimit) {
35 | gaslimit = block.gaslimit;
36 | }
37 | function getCurrentBlockCoinbase() public view returns (address coinbase) {
38 | coinbase = block.coinbase;
39 | }
40 | }
--------------------------------------------------------------------------------
/depth.otc/OtcStorageV2.sol:
--------------------------------------------------------------------------------
1 |
2 | pragma solidity ^0.8.0;
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 |
6 |
7 |
8 | /**
9 | * @title OtcV1: Simple otc swap v2
10 | * @notice https://www.depth.fi/
11 | */
12 | contract OtcStorageV2 is Ownable {
13 | using SafeMath for uint256;
14 |
15 | bool public isPaused;
16 | mapping (address=>bool) public otcContracts;//ony in this list can call saveMoney function
17 |
18 |
19 | uint256 public totalTradeAmount;//total trade amount by husd
20 | uint256 public totalFeeAmount;//total fee amount by husd;
21 |
22 |
23 |
24 |
25 | constructor() public {
26 |
27 | }
28 |
29 |
30 |
31 | function addOtcContract(address _address) external onlyOwner {
32 | otcContracts[_address] = true;
33 | }
34 |
35 | function removeOtcContract(address _address) external onlyOwner {
36 | if (otcContracts[_address] ){
37 | delete otcContracts[_address];
38 | }
39 | }
40 |
41 | //save otc trade amount info
42 | function saveTradeInfo(uint256 _amount,uint256 _fee) external{
43 | require(!isPaused,"paused");
44 | //check the caller in otc contracts
45 | require(otcContracts[msg.sender],"invalid otc contract address");
46 |
47 | if(_amount<=0){
48 | return;
49 | }
50 | totalTradeAmount=totalTradeAmount.add(_amount);//add global trade amount;
51 | totalFeeAmount=totalFeeAmount.add(_fee);//add global fee amount
52 |
53 |
54 | }
55 |
56 | //return global trade datas
57 | function getTradeDatas() external view returns(uint256,uint256){
58 | return (totalTradeAmount,totalFeeAmount);
59 |
60 | }
61 |
62 |
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/depth.otc/interfaces/IOtcV1.sol:
--------------------------------------------------------------------------------
1 |
2 | pragma solidity ^0.8.0;
3 |
4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5 |
6 | interface IOtcV1 {
7 | event Swap(
8 | uint256 indexed nonce,
9 | uint256 timestamp,
10 | address indexed makerAddress,
11 | IERC20 makerToken,
12 | uint256 makerAmount,
13 | address indexed takerAddress,
14 | IERC20 takerToken,
15 | uint256 takerAmount,
16 | uint256 feeAmount
17 | );
18 |
19 | event Cancel(uint256 indexed nonce, address indexed makerAddress);
20 |
21 | event Authorize(address indexed signer, address indexed makerAddress);
22 |
23 | event Revoke(address indexed signer, address indexed makerAddress);
24 |
25 | function swap(
26 | uint256 nonce,
27 | uint256 expiry,
28 | address makerAddress,
29 | IERC20 makerToken,
30 | uint256 makerAmount,
31 | address takerAddress,
32 | IERC20 takerToken,
33 | uint256 takerAmount,
34 | uint8 v,
35 | bytes32 r,
36 | bytes32 s
37 | ) external;
38 |
39 | function authorize(address sender) external;
40 |
41 | function revoke() external;
42 |
43 | function cancel(uint256[] calldata nonces) external;
44 |
45 | function nonceUsed(address, uint256) external view returns (bool);
46 |
47 | function authorized(address) external view returns (address);
48 | }
49 | interface UsdtSwapRouter {
50 | function exchange_underlying(int128, int128, uint256, uint256) external;
51 | }
52 | interface HusdSwapRouter {
53 | function getAmountsOut(uint amountIn, address[] calldata path) external returns (uint256[] memory);
54 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
55 | }
56 | interface IStorage {
57 | function saveTradeInfo(address _maker,address _taker,address _makeToken,address _takeToken,uint256 _amount,uint256 _fee) external;
58 | }
59 | interface IDao {
60 | function donateHUSD(uint256 amount) external;
61 | }
62 | interface ISwapMining{
63 | function takerWithdraw() external;
64 | }
65 |
--------------------------------------------------------------------------------
/BSCContracts/FundingManager.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 | import "@openzeppelin/contracts/access/Ownable.sol";
3 | import "@openzeppelin/contracts/utils/math/SafeMath.sol";
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5 | import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 |
7 | contract FundingManager is Ownable {
8 |
9 | using SafeMath for uint256;
10 | using SafeERC20 for IERC20;
11 |
12 | struct FundingHolderInfo {
13 | uint256 ratio;
14 | string name;
15 | address addr;
16 | }
17 |
18 | IERC20 public depToken;
19 |
20 | // Info of each funding.
21 | FundingHolderInfo[] public fundingHolders;
22 |
23 | constructor(IERC20 _address) public {
24 | depToken = _address;
25 | }
26 |
27 |
28 | //Update funding pool
29 | function addFunding(string memory _name, address _addr, uint256 _ratio) public onlyOwner {
30 |
31 | fundingHolders.push(FundingHolderInfo({
32 | name : _name,
33 | addr : _addr,
34 | ratio : _ratio
35 | }));
36 |
37 | }
38 |
39 | //Update funding pool
40 | function setFunding(uint256 pid, string memory _name, address _addr, uint256 _ratio) public onlyOwner {
41 |
42 | FundingHolderInfo storage fhi = fundingHolders[pid];
43 |
44 | fhi.name = _name;
45 | fhi.addr = _addr;
46 | fhi.ratio = _ratio;
47 | }
48 |
49 | // Return the pool pending balance.
50 | function getPendingBalance(uint256 pid) public view returns (uint256){
51 | FundingHolderInfo storage fhi = fundingHolders[pid];
52 | uint256 _balance = depToken.balanceOf(address(this));
53 | uint _amount = _balance.mul(fhi.ratio).div(100);
54 | return _amount;
55 | }
56 |
57 | function claim() public {
58 | uint256 _balance = depToken.balanceOf(address(this));
59 | for (uint256 i = 0; i < fundingHolders.length; i++) {
60 | FundingHolderInfo storage fhi = fundingHolders[i];
61 | uint _amount = _balance.mul(fhi.ratio).div(100);
62 | depToken.safeTransfer(fhi.addr, _amount);
63 | }
64 |
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/Depth.DEX/interfaces/IDepthswapPair.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | interface IDepthswapPair {
4 | event Approval(address indexed owner, address indexed spender, uint value);
5 | event Transfer(address indexed from, address indexed to, uint value);
6 |
7 | function name() external pure returns (string memory);
8 | function symbol() external pure returns (string memory);
9 | function decimals() external pure returns (uint8);
10 | function totalSupply() external view returns (uint);
11 | function balanceOf(address owner) external view returns (uint);
12 | function allowance(address owner, address spender) external view returns (uint);
13 |
14 | function approve(address spender, uint value) external returns (bool);
15 | function transfer(address to, uint value) external returns (bool);
16 | function transferFrom(address from, address to, uint value) external returns (bool);
17 |
18 | function DOMAIN_SEPARATOR() external view returns (bytes32);
19 | function PERMIT_TYPEHASH() external pure returns (bytes32);
20 | function nonces(address owner) external view returns (uint);
21 |
22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
23 |
24 | event Mint(address indexed sender, uint amount0, uint amount1);
25 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
26 | event Swap(
27 | address indexed sender,
28 | uint amount0In,
29 | uint amount1In,
30 | uint amount0Out,
31 | uint amount1Out,
32 | address indexed to
33 | );
34 | event Sync(uint112 reserve0, uint112 reserve1);
35 |
36 | function MINIMUM_LIQUIDITY() external pure returns (uint);
37 | function factory() external view returns (address);
38 | function token0() external view returns (address);
39 | function token1() external view returns (address);
40 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
41 | function price0CumulativeLast() external view returns (uint);
42 | function price1CumulativeLast() external view returns (uint);
43 | //function kLast() external view returns (uint);
44 |
45 | function mint(address to) external returns (uint liquidity);
46 | function burn(address to) external returns (uint amount0, uint amount1);
47 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
48 | function skim(address to) external;
49 | function sync() external;
50 |
51 | function initialize(address, address) external;
52 | }
--------------------------------------------------------------------------------
/Depth.DEX/DepthswapERC20.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.0;
2 |
3 | import './interfaces/IDepthswapERC20.sol';
4 | import './library/SafeMath.sol';
5 |
6 | contract DepthswapERC20 is IDepthswapERC20 {
7 | using SafeMath for uint;
8 |
9 | string public constant name = 'DepthSwap LP Token';
10 | string public constant symbol = 'HDEPDX';
11 | uint8 public constant decimals = 18;
12 | uint public totalSupply;
13 | mapping(address => uint) public balanceOf;
14 | mapping(address => mapping(address => uint)) public allowance;
15 |
16 | bytes32 public DOMAIN_SEPARATOR;
17 | // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
18 | bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
19 | mapping(address => uint) public nonces;
20 |
21 | event Approval(address indexed owner, address indexed spender, uint value);
22 | event Transfer(address indexed from, address indexed to, uint value);
23 |
24 | constructor() public {
25 | uint chainId;
26 | assembly {
27 | chainId := chainid()
28 | }
29 | DOMAIN_SEPARATOR = keccak256(
30 | abi.encode(
31 | keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
32 | keccak256(bytes(name)),
33 | keccak256(bytes('1')),
34 | chainId,
35 | address(this)
36 | )
37 | );
38 | }
39 |
40 | function _mint(address to, uint value) internal {
41 | totalSupply = totalSupply.add(value);
42 | balanceOf[to] = balanceOf[to].add(value);
43 | emit Transfer(address(0), to, value);
44 | }
45 |
46 | function _burn(address from, uint value) internal {
47 | balanceOf[from] = balanceOf[from].sub(value);
48 | totalSupply = totalSupply.sub(value);
49 | emit Transfer(from, address(0), value);
50 | }
51 |
52 | function _approve(address owner, address spender, uint value) private {
53 | allowance[owner][spender] = value;
54 | emit Approval(owner, spender, value);
55 | }
56 |
57 | function _transfer(address from, address to, uint value) private {
58 | balanceOf[from] = balanceOf[from].sub(value);
59 | balanceOf[to] = balanceOf[to].add(value);
60 | emit Transfer(from, to, value);
61 | }
62 |
63 | function approve(address spender, uint value) external returns (bool) {
64 | _approve(msg.sender, spender, value);
65 | return true;
66 | }
67 |
68 | function transfer(address to, uint value) external returns (bool) {
69 | _transfer(msg.sender, to, value);
70 | return true;
71 | }
72 |
73 | function transferFrom(address from, address to, uint value) external returns (bool) {
74 | if (allowance[from][msg.sender] != uint(-1)) {
75 | allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
76 | }
77 | _transfer(from, to, value);
78 | return true;
79 | }
80 |
81 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
82 | require(deadline >= block.timestamp, 'DepthswapERC20: EXPIRED');
83 | bytes32 digest = keccak256(
84 | abi.encodePacked(
85 | '\x19\x01',
86 | DOMAIN_SEPARATOR,
87 | keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
88 | )
89 | );
90 | address recoveredAddress = ecrecover(digest, v, r, s);
91 | require(recoveredAddress != address(0) && recoveredAddress == owner, 'DepthswapERC20: INVALID_SIGNATURE');
92 | _approve(owner, spender, value);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/depth.vault/interface/IVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "../openzeppelin/contracts/token/ERC20/IERC20.sol";
4 |
5 | interface CToken {
6 | function balanceOf(address owner) external view returns (uint256);
7 | function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
8 | function balanceOfUnderlying(address owner) external returns (uint256);
9 | function mint(uint256 mintAmount) external returns (uint256);
10 | function getAccountSnapshot(address account)
11 | external
12 | view
13 | returns (
14 | uint256,
15 | uint256,
16 | uint256,
17 | uint256
18 | );
19 | function underlying() external view returns (address);
20 | function comptroller() external view returns (address);
21 | }
22 | interface CompControl {
23 | // Claim all the COMP accrued by holder in specific markets
24 | function claimComp(address holder, address[] calldata cTokens) external;
25 | function getCompAddress() external view returns (address);
26 | function claimCan(address holder, address[] calldata cTokens) external;
27 | function getCanAddress() external view returns (address);
28 |
29 | }
30 | interface IHusdSwap {
31 | function swapTokensToHusd(address _token,uint256 _amount) external;
32 | }
33 | interface IDao {
34 | function donateHUSD(uint256 amount) external;
35 | }
36 | interface ISwapMining{
37 | function takerWithdraw() external;
38 | }
39 |
40 | interface IPilot{
41 | function totalToken(address token) external view returns (uint256);
42 | function deposit(address token, uint256 amount) external;
43 | function withdraw(address token, uint256 pAmount) external;
44 | function banks(address _token) external view returns(address tokenAddr,
45 | address pTokenAddr,
46 | bool isOpen,
47 | bool canDeposit,
48 | bool canWithdraw,
49 | uint256 totalVal,
50 | uint256 totalDebt,
51 | uint256 totalDebtShare,
52 | uint256 totalReserve,
53 | uint256 lastInterestTime);
54 | }
55 | interface IBack{
56 | function supplyToken() external view returns (address);
57 | function getTotalShare() external view returns (uint256);
58 | function totalSupply() external view returns (uint256);
59 | function totalBorrow() external view returns (uint256);
60 | function poolReserve() external view returns (uint256);
61 | function totalInterestToPay() external view returns (uint256);
62 | function queryBack(address) external view returns(uint256);
63 | function deposit(address _token,uint256 _amount) external;
64 | function withdraw(address _token,uint256 _amount) external;
65 | function mintBack() external;
66 | }
67 | interface ICow{
68 | function poolLength() external view returns(uint256);
69 | function deposit(address _token, uint256 _amount) external;
70 | function withdraw(address _token, uint256 _amount) external;
71 | function pending(uint256 _poolId,address _userAddress) external view returns(uint256,uint256,uint256);
72 | function pendingCow(uint256 _poolId,address _userAddress) external view returns(uint256);
73 | function poolInfo(uint256 _poolId) external view returns(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256);
74 | }
75 | interface IBooster{
76 | function deposit(uint256 _value) external ;
77 | function withdraw(uint256 _tTokenAmount) external;
78 | function poolDepositId() external view returns(uint256);
79 | function token() external view returns(address);
80 | function getBaseTokenPerLPToken() external view returns(uint256);
81 | }
82 | interface IBoosterStakePool{
83 | function deposit(uint256 _pid, uint256 _amount) external;
84 | function withdraw(uint256 _pid, uint256 _amount) external;
85 | function pendingRewards(uint256 _pid, address _user) external view returns (uint256 value);
86 | function claim(uint256 _pid) external;
87 | function getATUserAmount(uint256 _pid,address _user) external view returns(uint256);
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/Depth.DEX/DepthFee.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
4 | import "./openzeppelin/contracts/access/Ownable.sol";
5 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 |
7 |
8 | interface depthStableSwapRouter {
9 | function exchange_underlying(int128, int128, uint256, uint256) external;
10 | function get_dy_underlying( int128, int128, uint256) external view returns(uint256);
11 | }
12 |
13 | interface dexSwapRouter {
14 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
15 | }
16 |
17 | interface IDao {
18 | function donateHUSD(uint256 amount) external;
19 | }
20 |
21 | contract GetDepthFee is Ownable {
22 | using SafeERC20 for IERC20;
23 | using SafeMath for uint256;
24 |
25 | address constant public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
26 | address constant public usdt =0xa71EdC38d189767582C38A3145b5873052c3e47a;
27 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //dao address
28 | address public depthStableSwapAddress =0x1D1cF3b43bC54B7D8e0F763B6b8957F480367834;//usdt to husd
29 | address public dexAddress= 0xED7d5F38C79115ca12fe6C0041abb22F0A06C300; //swap other token fee to husd
30 |
31 | function swapTokensToUsd(address[] memory _tokens) public{
32 | for(uint i=0;i<_tokens.length;i++){
33 | if (_tokens[i]!=address(0)){
34 | swapTokenToHusd(_tokens[i]);
35 | }
36 | }
37 | }
38 | function swapTokenToHusd(address _token) public{
39 | require(_token != address(0), "INVALID ADDRESS");
40 |
41 | if (_token == usdt){ // swap usdt to husd
42 | uint256 usdtAmount = IERC20(usdt).balanceOf(address(this));
43 | IERC20(usdt).safeApprove(depthStableSwapAddress, usdtAmount);
44 | depthStableSwapRouter(depthStableSwapAddress).exchange_underlying(1, 0, usdtAmount, 0);
45 | }else if (_token != husd) { // swap other token to husd
46 |
47 | uint256 _amountIn = IERC20(_token).balanceOf(address(this));
48 | address[] memory _sellPath = new address[](2);
49 | _sellPath[0]=_token;
50 | _sellPath[1]=husd;
51 | IERC20(_token).safeApprove(dexAddress, _amountIn);
52 | dexSwapRouter(dexAddress).swapExactTokensForTokens(_amountIn, 0, _sellPath, address(this), block.timestamp.add(1800));
53 | }
54 |
55 | uint256 feeHusdAmount = IERC20(husd).balanceOf(address(this));
56 | if (feeHusdAmount>0){
57 | IERC20(husd).safeApprove(daoAddress,feeHusdAmount);
58 | IDao(daoAddress).donateHUSD(feeHusdAmount);
59 | }
60 | }
61 |
62 | //withdraw
63 | function withdraw(address _token) public onlyOwner {
64 | require(_token != address(0), "INVALID ADDRESS");
65 | uint256 _amount = IERC20(_token).balanceOf(address(this));
66 | require(_amount>0,"invalid amount");
67 |
68 | IERC20(_token).safeTransfer(msg.sender, _amount);
69 | }
70 |
71 | function withdrawAmount(address _token, uint256 _amount) public onlyOwner {
72 | require(_token != address(0), "INVALID ADDRESS");
73 | uint256 _amountBalance = IERC20(_token).balanceOf(address(this));
74 | require(_amount>0,"invalid amount");
75 | require(_amountBalance>=_amount,"invalid amount");
76 |
77 | IERC20(_token).safeTransfer(msg.sender, _amount);
78 | }
79 |
80 |
81 | function setDaoAddress(address _address) public onlyOwner {
82 | require(_address != address(0), "INVALID ADDRESS");
83 | daoAddress = _address;
84 | }
85 |
86 | function setDexAddress(address _address) public onlyOwner {
87 | require(_address != address(0), "INVALID ADDRESS");
88 | dexAddress = _address;
89 | }
90 |
91 | function setdepthStableSwapAddress(address _address) public onlyOwner {
92 | require(_address != address(0), "INVALID ADDRESS");
93 | depthStableSwapAddress = _address;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/Depth.DEX/library/SafeMath.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.1;
2 |
3 | library SafeMath {
4 | uint256 constant WAD = 10 ** 18;
5 | uint256 constant RAY = 10 ** 27;
6 |
7 | function wad() public pure returns (uint256) {
8 | return WAD;
9 | }
10 |
11 | function ray() public pure returns (uint256) {
12 | return RAY;
13 | }
14 |
15 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
16 | uint256 c = a + b;
17 | require(c >= a, "SafeMath: addition overflow");
18 |
19 | return c;
20 | }
21 |
22 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
23 | return sub(a, b, "SafeMath: subtraction overflow");
24 | }
25 |
26 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
27 | require(b <= a, errorMessage);
28 | uint256 c = a - b;
29 |
30 | return c;
31 | }
32 |
33 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
34 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
35 | // benefit is lost if 'b' is also tested.
36 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
37 | if (a == 0) {
38 | return 0;
39 | }
40 |
41 | uint256 c = a * b;
42 | require(c / a == b, "SafeMath: multiplication overflow");
43 |
44 | return c;
45 | }
46 |
47 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
48 | return div(a, b, "SafeMath: division by zero");
49 | }
50 |
51 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
52 | // Solidity only automatically asserts when dividing by 0
53 | require(b > 0, errorMessage);
54 | uint256 c = a / b;
55 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold
56 |
57 | return c;
58 | }
59 |
60 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
61 | return mod(a, b, "SafeMath: modulo by zero");
62 | }
63 |
64 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
65 | require(b != 0, errorMessage);
66 | return a % b;
67 | }
68 |
69 | function min(uint256 a, uint256 b) internal pure returns (uint256) {
70 | return a <= b ? a : b;
71 | }
72 |
73 | function max(uint256 a, uint256 b) internal pure returns (uint256) {
74 | return a >= b ? a : b;
75 | }
76 |
77 | function sqrt(uint256 a) internal pure returns (uint256 b) {
78 | if (a > 3) {
79 | b = a;
80 | uint256 x = a / 2 + 1;
81 | while (x < b) {
82 | b = x;
83 | x = (a / x + x) / 2;
84 | }
85 | } else if (a != 0) {
86 | b = 1;
87 | }
88 | }
89 |
90 | function wmul(uint256 a, uint256 b) internal pure returns (uint256) {
91 | return mul(a, b) / WAD;
92 | }
93 |
94 | function wmulRound(uint256 a, uint256 b) internal pure returns (uint256) {
95 | return add(mul(a, b), WAD / 2) / WAD;
96 | }
97 |
98 | function rmul(uint256 a, uint256 b) internal pure returns (uint256) {
99 | return mul(a, b) / RAY;
100 | }
101 |
102 | function rmulRound(uint256 a, uint256 b) internal pure returns (uint256) {
103 | return add(mul(a, b), RAY / 2) / RAY;
104 | }
105 |
106 | function wdiv(uint256 a, uint256 b) internal pure returns (uint256) {
107 | return div(mul(a, WAD), b);
108 | }
109 |
110 | function wdivRound(uint256 a, uint256 b) internal pure returns (uint256) {
111 | return add(mul(a, WAD), b / 2) / b;
112 | }
113 |
114 | function rdiv(uint256 a, uint256 b) internal pure returns (uint256) {
115 | return div(mul(a, RAY), b);
116 | }
117 |
118 | function rdivRound(uint256 a, uint256 b) internal pure returns (uint256) {
119 | return add(mul(a, RAY), b / 2) / b;
120 | }
121 |
122 | function wpow(uint256 x, uint256 n) internal pure returns (uint256) {
123 | uint256 result = WAD;
124 | while (n > 0) {
125 | if (n % 2 != 0) {
126 | result = wmul(result, x);
127 | }
128 | x = wmul(x, x);
129 | n /= 2;
130 | }
131 | return result;
132 | }
133 |
134 | function rpow(uint256 x, uint256 n) internal pure returns (uint256) {
135 | uint256 result = RAY;
136 | while (n > 0) {
137 | if (n % 2 != 0) {
138 | result = rmul(result, x);
139 | }
140 | x = rmul(x, x);
141 | n /= 2;
142 | }
143 | return result;
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/Depth.DEX/library/DepthswapLibrary.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.0;
2 |
3 | import "./SafeMath.sol";
4 | import '../interfaces/IDepthswapPair.sol';
5 | import '../interfaces/IDepthswapFactory.sol';
6 |
7 | library DepthswapLibrary {
8 | using SafeMath for uint;
9 |
10 | uint256 public constant FEE_RATE_DENOMINATOR = 10000;
11 |
12 | // returns sorted token addresses, used to handle return values from pairs sorted in this order
13 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
14 | require(tokenA != tokenB, 'DepthswapLibrary: IDENTICAL_ADDRESSES');
15 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
16 | require(token0 != address(0), 'DepthswapLibrary: ZERO_ADDRESS');
17 | }
18 |
19 | // calculates the CREATE2 address for a pair without making any external calls
20 | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
21 | (address token0, address token1) = sortTokens(tokenA, tokenB);
22 | pair = address(uint(keccak256(abi.encodePacked(
23 | hex'ff',
24 | factory,
25 | keccak256(abi.encodePacked(token0, token1)),
26 | hex'd9b57cd352954a077ee559170bd6e95ea1316ddd3aad8523243882826888e34e' // init code hash
27 | ))));
28 | }
29 |
30 | // fetches and sorts the reserves for a pair
31 | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
32 | (address token0,) = sortTokens(tokenA, tokenB);
33 | (uint reserve0, uint reserve1,) = IDepthswapPair(pairFor(factory, tokenA, tokenB)).getReserves();
34 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
35 | }
36 |
37 | // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
38 | function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
39 | require(amountA > 0, 'DepthswapLibrary: INSUFFICIENT_AMOUNT');
40 | require(reserveA > 0 && reserveB > 0, 'DepthswapLibrary: INSUFFICIENT_LIQUIDITY');
41 | amountB = amountA.mul(reserveB) / reserveA;
42 | }
43 |
44 | // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
45 | function getAmountOut(address factory, uint amountIn, uint reserveIn, uint reserveOut) internal view returns (uint amountOut) {
46 | require(amountIn > 0, 'DepthswapLibrary: INSUFFICIENT_INPUT_AMOUNT');
47 | require(reserveIn > 0 && reserveOut > 0, 'DepthswapLibrary: INSUFFICIENT_LIQUIDITY');
48 |
49 | uint256 fee = IDepthswapFactory(factory).getFeeRate(tx.origin);
50 | require(fee >=0 && fee <=50, "INVALID_FEE");
51 |
52 | uint amountInWithFee = amountIn.mul(FEE_RATE_DENOMINATOR.sub(fee));
53 | uint numerator = amountInWithFee.mul(reserveOut);
54 | uint denominator = reserveIn.mul(FEE_RATE_DENOMINATOR).add(amountInWithFee);
55 | amountOut = numerator / denominator;
56 | }
57 |
58 | // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
59 | function getAmountIn(address factory, uint amountOut, uint reserveIn, uint reserveOut) internal view returns (uint amountIn) {
60 | require(amountOut > 0, 'DepthswapLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
61 | require(reserveIn > 0 && reserveOut > 0, 'DepthswapLibrary: INSUFFICIENT_LIQUIDITY');
62 |
63 | uint256 fee = IDepthswapFactory(factory).getFeeRate(tx.origin);
64 | require(fee >=0 && fee <=50, "INVALID_FEE");
65 |
66 | uint numerator = reserveIn.mul(amountOut).mul(FEE_RATE_DENOMINATOR);
67 | uint denominator = reserveOut.sub(amountOut).mul(FEE_RATE_DENOMINATOR.sub(fee));
68 | amountIn = (numerator / denominator).add(1);
69 | }
70 |
71 | // performs chained getAmountOut calculations on any number of pairs
72 | function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
73 | require(path.length >= 2, 'DepthswapLibrary: INVALID_PATH');
74 | amounts = new uint[](path.length);
75 | amounts[0] = amountIn;
76 | for (uint i; i < path.length - 1; i++) {
77 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
78 | amounts[i + 1] = getAmountOut(factory, amounts[i], reserveIn, reserveOut);
79 | }
80 | }
81 |
82 | // performs chained getAmountIn calculations on any number of pairs
83 | function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
84 | require(path.length >= 2, 'DepthswapLibrary: INVALID_PATH');
85 | amounts = new uint[](path.length);
86 | amounts[amounts.length - 1] = amountOut;
87 | for (uint i = path.length - 1; i > 0; i--) {
88 | (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
89 | amounts[i - 1] = getAmountIn(factory, amounts[i], reserveIn, reserveOut);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Depth.DEX/DepthswapFactory.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.5.0 <0.8.0;
2 |
3 | import './interfaces/IDepthswapFactory.sol';
4 | import './DepthswapPair.sol';
5 |
6 | contract DepthswapFactory is IDepthswapFactory {
7 | using SafeMath for uint256;
8 | address public feeTo;
9 | address public feeToSetter;
10 | bytes32 public initCodeHash;
11 |
12 | struct FeeInfo{
13 | uint256 stakeAmount;
14 | uint256 feeRate;
15 | }
16 | FeeInfo[] public feeInfo;
17 | uint256 public constant FEE_RATE_DENOMINATOR = 10000;
18 | uint256 public feeRateNumerator = 30;
19 | address public constant xdepAddress = 0xDeEfD50FE964Cd03694EF7AbFB4147Cb1dd41c9B;
20 |
21 | bool public allowAllOn;
22 | mapping(address => bool) public whiteList;
23 |
24 | mapping(address => mapping(address => address)) public getPair;
25 | address[] public allPairs;
26 |
27 | event PairCreated(address indexed token0, address indexed token1, address pair, uint);
28 |
29 | constructor(address _feeToSetter) public {
30 | feeToSetter = _feeToSetter;
31 | initCodeHash = keccak256(abi.encodePacked(type(DepthswapPair).creationCode));
32 | }
33 |
34 | function allPairsLength() external view returns (uint) {
35 | return allPairs.length;
36 | }
37 |
38 | function createPair(address tokenA, address tokenB) external returns (address pair) {
39 |
40 | if (allowAllOn == false){
41 | require(whiteList[tokenA] == true, "token not in whiteList");
42 | require(whiteList[tokenB] == true, "token not in whiteList");
43 | }
44 |
45 | require(tokenA != tokenB, 'DepthSwapFactory: IDENTICAL_ADDRESSES');
46 | (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
47 | require(token0 != address(0), 'DepthSwapFactory: ZERO_ADDRESS');
48 | require(getPair[token0][token1] == address(0), 'DepthSwapFactory: PAIR_EXISTS'); // single check is sufficient
49 | bytes memory bytecode = type(DepthswapPair).creationCode;
50 | bytes32 salt = keccak256(abi.encodePacked(token0, token1));
51 | assembly {
52 | pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
53 | }
54 | IDepthswapPair(pair).initialize(token0, token1);
55 | getPair[token0][token1] = pair;
56 | getPair[token1][token0] = pair; // populate mapping in the reverse direction
57 | allPairs.push(pair);
58 | emit PairCreated(token0, token1, pair, allPairs.length);
59 | }
60 |
61 | function setFeeTo(address _feeTo) external {
62 | require(msg.sender == feeToSetter, 'DepthSwap: FORBIDDEN');
63 | feeTo = _feeTo;
64 | }
65 |
66 | function setFeeToSetter(address _feeToSetter) external {
67 | require(msg.sender == feeToSetter, 'DepthSwap: FORBIDDEN');
68 | feeToSetter = _feeToSetter;
69 | }
70 |
71 | function addWhiteList(address _address) public {
72 | require(msg.sender == feeToSetter, 'DepthSwapFactory: FORBIDDEN');
73 | whiteList[_address] = true;
74 | }
75 |
76 | function deleteWhiteList(address _address) public {
77 | require(msg.sender == feeToSetter, 'DepthSwapFactory: FORBIDDEN');
78 | whiteList[_address] = false;
79 | }
80 |
81 | function setallowAllOn(bool _bvalue) public {
82 | require(msg.sender == feeToSetter, 'DepthSwapFactory: FORBIDDEN');
83 | allowAllOn = _bvalue;
84 | }
85 |
86 | //set fee feeRate
87 | function setFeeRate(uint256 index, uint256 stakeAmount, uint256 rate) public {
88 | require(msg.sender == feeToSetter, 'DepthSwapFactory: FORBIDDEN');
89 | // Ensure the fee is less than divisor
90 | require(rate <= 50, "INVALID_FEE");
91 | uint256 len = feeInfo.length;
92 | require(index <= len, "INVALID_INDEX");
93 |
94 | FeeInfo memory _new = FeeInfo({
95 | stakeAmount : stakeAmount,
96 | feeRate : rate
97 | });
98 | if (len==0||index==len){
99 | feeInfo.push(_new);
100 | }else{
101 | feeInfo[index] = _new;
102 | }
103 | }
104 |
105 | // Set default fee ,max is 0.003%
106 | function setFeeRateNumerator(uint256 _feeRateNumerator) public {
107 | require(msg.sender == feeToSetter, 'MdexSwapFactory: FORBIDDEN');
108 | require(_feeRateNumerator <= 50, "MdexSwapFactory: EXCEEDS_FEE_RATE_DENOMINATOR");
109 | feeRateNumerator = _feeRateNumerator;
110 | }
111 |
112 | //return address swap fee
113 | function getFeeRate(address _address) public view returns (uint256){
114 | require(_address != address(0), "INVALID_ADDRESS");
115 | uint256 balance = IERC20(xdepAddress).balanceOf(_address);
116 | //loop the fee rate array
117 | uint256 lastAmount = 0;
118 | uint256 feeRate = feeRateNumerator;
119 | for(uint i = 0; i < feeInfo.length; i++) {
120 | if (balance>=feeInfo[i].stakeAmount&&feeInfo[i].stakeAmount>lastAmount){
121 | feeRate = feeInfo[i].feeRate;
122 | lastAmount = feeInfo[i].stakeAmount;
123 | }
124 | }
125 |
126 | return feeRate;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/Depth.DEX/interfaces/IDepthswapRouter.sol:
--------------------------------------------------------------------------------
1 | //pragma solidity =0.6.6;
2 | pragma solidity >=0.5.0 <0.8.1;
3 |
4 | interface IDepthswapRouter {
5 | function factory() external pure returns (address);
6 | function WHT() external pure returns (address);
7 |
8 | function addLiquidity(
9 | address tokenA,
10 | address tokenB,
11 | uint amountADesired,
12 | uint amountBDesired,
13 | uint amountAMin,
14 | uint amountBMin,
15 | address to,
16 | uint deadline
17 | ) external returns (uint amountA, uint amountB, uint liquidity);
18 | function addLiquidityETH(
19 | address token,
20 | uint amountTokenDesired,
21 | uint amountTokenMin,
22 | uint amountHTMin,
23 | address to,
24 | uint deadline
25 | ) external payable returns (uint amountToken, uint amountHT, uint liquidity);
26 | function removeLiquidity(
27 | address tokenA,
28 | address tokenB,
29 | uint liquidity,
30 | uint amountAMin,
31 | uint amountBMin,
32 | address to,
33 | uint deadline
34 | ) external returns (uint amountA, uint amountB);
35 | function removeLiquidityETH(
36 | address token,
37 | uint liquidity,
38 | uint amountTokenMin,
39 | uint amountHTMin,
40 | address to,
41 | uint deadline
42 | ) external returns (uint amountToken, uint amountHT);
43 | function removeLiquidityWithPermit(
44 | address tokenA,
45 | address tokenB,
46 | uint liquidity,
47 | uint amountAMin,
48 | uint amountBMin,
49 | address to,
50 | uint deadline,
51 | bool approveMax, uint8 v, bytes32 r, bytes32 s
52 | ) external returns (uint amountA, uint amountB);
53 | function removeLiquidityETHWithPermit(
54 | address token,
55 | uint liquidity,
56 | uint amountTokenMin,
57 | uint amountHTMin,
58 | address to,
59 | uint deadline,
60 | bool approveMax, uint8 v, bytes32 r, bytes32 s
61 | ) external returns (uint amountToken, uint amountHT);
62 | function swapExactTokensForTokens(
63 | uint amountIn,
64 | uint amountOutMin,
65 | address[] calldata path,
66 | address to,
67 | uint deadline
68 | ) external returns (uint[] memory amounts);
69 | function swapTokensForExactTokens(
70 | uint amountOut,
71 | uint amountInMax,
72 | address[] calldata path,
73 | address to,
74 | uint deadline
75 | ) external returns (uint[] memory amounts);
76 | function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
77 | external
78 | payable
79 | returns (uint[] memory amounts);
80 | function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
81 | external
82 | returns (uint[] memory amounts);
83 | function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
84 | external
85 | returns (uint[] memory amounts);
86 | function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
87 | external
88 | payable
89 | returns (uint[] memory amounts);
90 |
91 | function quote(uint amountA, uint reserveA, uint reserveB) external view returns (uint amountB);
92 | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external returns (uint amountOut);
93 | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external returns (uint amountIn);
94 | function getAmountsOut(uint amountIn, address[] calldata path) external returns (uint[] memory amounts);
95 | function getAmountsIn(uint amountOut, address[] calldata path) external returns (uint[] memory amounts);
96 |
97 | function removeLiquidityETHSupportingFeeOnTransferTokens(
98 | address token,
99 | uint liquidity,
100 | uint amountTokenMin,
101 | uint amountHTMin,
102 | address to,
103 | uint deadline
104 | ) external returns (uint amountHT);
105 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
106 | address token,
107 | uint liquidity,
108 | uint amountTokenMin,
109 | uint amountHTMin,
110 | address to,
111 | uint deadline,
112 | bool approveMax, uint8 v, bytes32 r, bytes32 s
113 | ) external returns (uint amountHT);
114 |
115 | function swapExactTokensForTokensSupportingFeeOnTransferTokens(
116 | uint amountIn,
117 | uint amountOutMin,
118 | address[] calldata path,
119 | address to,
120 | uint deadline
121 | ) external;
122 | function swapExactETHForTokensSupportingFeeOnTransferTokens(
123 | uint amountOutMin,
124 | address[] calldata path,
125 | address to,
126 | uint deadline
127 | ) external payable;
128 | function swapExactTokensForETHSupportingFeeOnTransferTokens(
129 | uint amountIn,
130 | uint amountOutMin,
131 | address[] calldata path,
132 | address to,
133 | uint deadline
134 | ) external;
135 | }
136 |
137 |
--------------------------------------------------------------------------------
/BSCContracts/Channels-3Pool/SellLendPlatformToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 |
4 | library SafeMath {
5 |
6 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
7 | if (a == 0)
8 | return 0;
9 | uint256 c = a * b;
10 | require(c / a == b);
11 | return c;
12 | }
13 |
14 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
15 | require(b > 0);
16 | uint256 c = a / b;
17 | return c;
18 | }
19 |
20 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
21 | require(b > 0);
22 | uint256 c = a / b;
23 | if(a % b != 0)
24 | c = c + 1;
25 | return c;
26 | }
27 |
28 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
29 | require(b <= a);
30 | uint256 c = a - b;
31 | return c;
32 | }
33 |
34 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
35 | uint256 c = a + b;
36 | require(c >= a);
37 | return c;
38 | }
39 |
40 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
41 | require(b != 0);
42 | return a % b;
43 | }
44 |
45 | int256 constant private INT256_MIN = -2^255;
46 |
47 | function mul(int256 a, int256 b) internal pure returns (int256) {
48 | if (a == 0)
49 | return 0;
50 | int256 c = a * b;
51 | require(c / a == b && (a != -1 || b != INT256_MIN));
52 | return c;
53 | }
54 |
55 | function div(int256 a, int256 b) internal pure returns (int256) {
56 | require(b != 0 && (b != -1 || a != INT256_MIN));
57 | int256 c = a / b;
58 | return c;
59 | }
60 |
61 | function sub(int256 a, int256 b) internal pure returns (int256) {
62 | int256 c = a - b;
63 | require((b >= 0 && c <= a) || (b < 0 && c > a));
64 | return c;
65 | }
66 |
67 | function add(int256 a, int256 b) internal pure returns (int256) {
68 | int256 c = a + b;
69 | require((b >= 0 && c >= a) || (b < 0 && c < a));
70 | return c;
71 | }
72 |
73 | function sqrt(int256 x) internal pure returns (int256) {
74 | int256 z = add(x / 2, 1);
75 | int256 y = x;
76 | while (z < y)
77 | {
78 | y = z;
79 | z = ((add((x / z), z)) / 2);
80 | }
81 | return y;
82 | }
83 | }
84 |
85 | interface ERC20 {
86 | using SafeMath for uint256;
87 |
88 | function totalSupply() external view returns (uint256);
89 |
90 | function balanceOf(address owner) external view returns (uint256);
91 |
92 | function allowance(address owner, address spender) external view returns (uint256);
93 |
94 | function transfer(address to, uint256 value) external returns (bool);
95 |
96 | function approve(address spender, uint256 value) external returns (bool);
97 |
98 | function transferFrom(address from, address to, uint256 value) external returns (bool);
99 |
100 | }
101 |
102 | interface CERC20 is ERC20 {
103 | function mint(uint256) external returns (uint256);
104 | }
105 |
106 | interface ClaimCan {
107 | function claimCan(address holder) external;
108 | }
109 |
110 | interface UniswapRouter {
111 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
112 | function getAmountsOut(uint amountIn, address[] calldata path) external returns (uint256[] memory);
113 | }
114 |
115 | interface DAOPool {
116 | function donateHUSD(uint256 amount) external;
117 | }
118 |
119 | contract SellLendPlatformToken{
120 |
121 | UniswapRouter constant uniswap = UniswapRouter(0x10ED43C718714eb63d5aA57B78B54704E256024E);
122 | ERC20 constant can = ERC20(0xdE9a73272BC2F28189CE3c243e36FaFDA2485212);
123 | ERC20 constant busd = ERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
124 | ERC20 constant wbnb = ERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
125 | ClaimCan constant claimCANContract = ClaimCan(0x8Cd2449Ed0469D90a7C4321DF585e7913dd6E715);
126 |
127 | function claim_lending_platform_token() external {
128 | // This method calim CAN token for main contract.
129 | // Since this contract is replaceable, we can rewrite this method if we have to.
130 | claimCANContract.claimCan(msg.sender);
131 | }
132 |
133 | function sell_lending_platform_token(uint256 amount) external returns (bool){
134 | require(can.transferFrom(msg.sender, address(this), amount));
135 |
136 | address[] memory path = new address[](3);
137 | path[0] = address(can);
138 | path[1] = address(wbnb);
139 | path[2] = address(busd);
140 |
141 | can.approve(address(uniswap), amount);
142 | try uniswap.swapExactTokensForTokens(amount, 0, path, address(this), now) returns (uint256[] memory amounts) {
143 | uint256 busdBalance = busd.balanceOf(address(this));
144 | if(busdBalance == 0)
145 | return true;
146 | busd.transfer(msg.sender, busdBalance);
147 | return true;
148 | } catch (bytes memory) {
149 | // swap failed, return token back to main contract
150 | can.transfer(msg.sender, amount);
151 | return true;
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/depthStableSwapV2/SellLendPlatformToken(Filda).sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 | library SafeMath {
4 |
5 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
6 | if (a == 0)
7 | return 0;
8 | uint256 c = a * b;
9 | require(c / a == b);
10 | return c;
11 | }
12 |
13 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
14 | require(b > 0);
15 | uint256 c = a / b;
16 | return c;
17 | }
18 |
19 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
20 | require(b > 0);
21 | uint256 c = a / b;
22 | if(a % b != 0)
23 | c = c + 1;
24 | return c;
25 | }
26 |
27 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
28 | require(b <= a);
29 | uint256 c = a - b;
30 | return c;
31 | }
32 |
33 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
34 | uint256 c = a + b;
35 | require(c >= a);
36 | return c;
37 | }
38 |
39 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
40 | require(b != 0);
41 | return a % b;
42 | }
43 |
44 | int256 constant private INT256_MIN = -2^255;
45 |
46 | function mul(int256 a, int256 b) internal pure returns (int256) {
47 | if (a == 0)
48 | return 0;
49 | int256 c = a * b;
50 | require(c / a == b && (a != -1 || b != INT256_MIN));
51 | return c;
52 | }
53 |
54 | function div(int256 a, int256 b) internal pure returns (int256) {
55 | require(b != 0 && (b != -1 || a != INT256_MIN));
56 | int256 c = a / b;
57 | return c;
58 | }
59 |
60 | function sub(int256 a, int256 b) internal pure returns (int256) {
61 | int256 c = a - b;
62 | require((b >= 0 && c <= a) || (b < 0 && c > a));
63 | return c;
64 | }
65 |
66 | function add(int256 a, int256 b) internal pure returns (int256) {
67 | int256 c = a + b;
68 | require((b >= 0 && c >= a) || (b < 0 && c < a));
69 | return c;
70 | }
71 |
72 | function sqrt(int256 x) internal pure returns (int256) {
73 | int256 z = add(x / 2, 1);
74 | int256 y = x;
75 | while (z < y)
76 | {
77 | y = z;
78 | z = ((add((x / z), z)) / 2);
79 | }
80 | return y;
81 | }
82 | }
83 |
84 | interface ERC20 {
85 | using SafeMath for uint256;
86 |
87 | function totalSupply() external view returns (uint256);
88 |
89 | function balanceOf(address owner) external view returns (uint256);
90 |
91 | function allowance(address owner, address spender) external view returns (uint256);
92 |
93 | function transfer(address to, uint256 value) external returns (bool);
94 |
95 | function approve(address spender, uint256 value) external returns (bool);
96 |
97 | function transferFrom(address from, address to, uint256 value) external returns (bool);
98 |
99 | }
100 |
101 | interface CERC20 is ERC20 {
102 | function mint(uint256) external returns (uint256);
103 | }
104 |
105 | interface ClaimComp is ERC20 {
106 | function claimComp(address holder) external;
107 | }
108 |
109 | interface MDexRouter {
110 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
111 | function getAmountsOut(uint amountIn, address[] calldata path) external returns (uint256[] memory);
112 | }
113 |
114 | contract SellLendPlatformToken{
115 |
116 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
117 | ERC20 constant filda = ERC20(0xE36FFD17B2661EB57144cEaEf942D95295E637F0);
118 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
119 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
120 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
121 | CERC20 constant lhusd = CERC20(0x1C478D5d1823D51c4c4b196652912A89D9b46c30);
122 | CERC20 constant lusdt = CERC20(0xc502F3f6f1b71CB7d856E70B574D27d942C2993C);
123 | ClaimComp constant claimFILDAContract = ClaimComp(0xb74633f2022452f377403B638167b0A135DB096d);
124 |
125 | function claim_lending_platform_token() external {
126 | claimFILDAContract.claimComp(msg.sender);
127 | }
128 |
129 | function sell_lending_platform_token(uint256 amount) external returns (bool){
130 | require(filda.transferFrom(msg.sender, address(this), amount));
131 | address[] memory path;
132 | path = new address[](2);
133 | path[0] = address(filda);
134 | path[1] = address(husd);
135 | filda.approve(address(mdex), amount);
136 | // Try to swap FILDA for fHUSD or fUSDT. This action may fail beacuse lack of liqudility.
137 | try mdex.swapExactTokensForTokens(amount, 0, path, address(this), now) returns (uint256[] memory amounts) {
138 | uint256 husdBalance = husd.balanceOf(address(this));
139 | if(husdBalance == 0)
140 | return true;
141 | husd.transfer(msg.sender, husdBalance);
142 | return true;
143 | } catch (bytes memory) {
144 | // swap failed, return token back to sender
145 | filda.transfer(msg.sender, amount);
146 | return true;
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/Depth.DAO/Voting.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 | pragma experimental ABIEncoderV2;
3 |
4 |
5 |
6 | interface ERC20 {
7 |
8 | function totalSupply() external view returns (uint256);
9 |
10 | function balanceOf(address owner) external view returns (uint256);
11 |
12 | function allowance(address owner, address spender) external view returns (uint256);
13 |
14 | function transfer(address to, uint256 value) external returns (bool);
15 |
16 | function approve(address spender, uint256 value) external returns (bool);
17 |
18 | function transferFrom(address from, address to, uint256 value) external returns (bool);
19 |
20 |
21 |
22 | }
23 |
24 |
25 |
26 | abstract contract Context {
27 | function _msgSender() internal view virtual returns (address payable) {
28 | return msg.sender;
29 | }
30 |
31 | function _msgData() internal view virtual returns (bytes memory) {
32 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
33 | return msg.data;
34 | }
35 | }
36 |
37 | contract Ownable is Context {
38 | address private _owner;
39 |
40 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
41 |
42 | constructor () internal {
43 | address msgSender = _msgSender();
44 | _owner = msgSender;
45 | emit OwnershipTransferred(address(0), msgSender);
46 | }
47 |
48 | function owner() public view returns (address) {
49 | return _owner;
50 | }
51 |
52 | modifier onlyOwner() {
53 | require(_owner == _msgSender(), "Ownable: caller is not the owner");
54 | _;
55 | }
56 |
57 | function renounceOwnership() public virtual onlyOwner {
58 | emit OwnershipTransferred(_owner, address(0));
59 | _owner = address(0);
60 | }
61 |
62 | function transferOwnership(address newOwner) public virtual onlyOwner {
63 | require(newOwner != address(0), "Ownable: new owner is the zero address");
64 | emit OwnershipTransferred(_owner, newOwner);
65 | _owner = newOwner;
66 | }
67 | }
68 |
69 | contract Voting is Ownable{
70 |
71 | event Vote(address indexed user, uint256 indexed index, uint16 option, uint256 votes);
72 |
73 | struct VotingInfo {
74 | uint256 startsAt;
75 | uint256 period;
76 | string title;
77 | string description;
78 | uint16 voteOptionsCount;
79 | string[] voteTitles;
80 | mapping (uint256 => uint256) votes;
81 | }
82 |
83 | struct UserVoting {
84 | uint256 index;
85 | uint16 voteOptionsCount;
86 | mapping (uint256 => uint256) votes;
87 | }
88 |
89 | mapping (uint256 => VotingInfo) public votingInfoMap;
90 |
91 | mapping (address => UserVoting) public userVotingMap;
92 |
93 | uint256 constant private maxPeriod = 5 minutes;
94 |
95 | uint256 public lastIndex = 0;
96 |
97 | ERC20 private xDep;
98 |
99 | constructor(address tokenAddress) public{
100 | xDep = ERC20(tokenAddress);
101 | }
102 |
103 | function hasVotesToWithdraw(address user) public view returns (bool) {
104 | UserVoting memory userVoting = userVotingMap[user];
105 | return userVoting.index > 0 && (userVoting.index != lastIndex || !votingInProcess());
106 | }
107 |
108 | function votingInProcess() public view returns (bool) {
109 | VotingInfo memory info = votingInfoMap[lastIndex];
110 | return info.startsAt + info.period > now;
111 | }
112 |
113 | function userVoteCountForOption(address user, uint16 option) public view returns (uint256) {
114 | return userVotingMap[user].votes[option];
115 | }
116 |
117 | function voteCountForOption(uint256 round, uint16 option) public view returns (uint256) {
118 | return votingInfoMap[round].votes[option];
119 | }
120 |
121 | function voteTitleForOption(uint256 round, uint16 option) public view returns (string memory) {
122 | return votingInfoMap[round].voteTitles[option];
123 | }
124 |
125 | function withdrawPreviousVote() public {
126 | require(hasVotesToWithdraw(msg.sender), "No votes to withdraw");
127 |
128 | UserVoting storage userVoting = userVotingMap[msg.sender];
129 | uint256 totalVotes = 0;
130 | for (uint16 i = 0; i < userVoting.voteOptionsCount; i ++) {
131 | totalVotes += userVoting.votes[i];
132 | userVoting.votes[i] = 0;
133 | }
134 | xDep.transfer(msg.sender, totalVotes);
135 | userVotingMap[msg.sender] = UserVoting(0, 0);
136 | }
137 |
138 | function vote(uint16 index, uint256 votes) public {
139 | // validation
140 | require(votingInProcess(), "No voting in process");
141 | require(!hasVotesToWithdraw(msg.sender), "Previous votes not withdrawed");
142 | VotingInfo storage info = votingInfoMap[lastIndex];
143 | require(info.voteOptionsCount - 1 >= index, "Out of options");
144 |
145 | // update
146 | UserVoting storage userVoting = userVotingMap[msg.sender];
147 | xDep.transferFrom(msg.sender, address(this), votes);
148 | if (userVoting.index != lastIndex) {
149 | userVoting.index = lastIndex;
150 | userVoting.voteOptionsCount = info.voteOptionsCount;
151 | }
152 | userVoting.votes[index] += votes;
153 | info.votes[index] += votes;
154 |
155 | emit Vote(msg.sender, lastIndex, index, votes);
156 | }
157 |
158 | function startNewVoting(uint256 period, string memory title, string memory description, string[] memory voteTitles, uint16 optionsCount) public onlyOwner {
159 | require(period <= maxPeriod, "Maximum period exceeded");
160 | require(period > 0, "Period must be larger than 0");
161 | require(!votingInProcess(), "There is a pending voting");
162 | require(optionsCount >= 1, "At least one options are needed");
163 | require(voteTitles.length == optionsCount, "Inconsistence");
164 |
165 | lastIndex += 1;
166 | VotingInfo memory info = VotingInfo(now, period, title, description, optionsCount, voteTitles);
167 | votingInfoMap[lastIndex] = info;
168 | }
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/HandleCan.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 | library SafeMath {
4 |
5 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
6 | if (a == 0)
7 | return 0;
8 | uint256 c = a * b;
9 | require(c / a == b);
10 | return c;
11 | }
12 |
13 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
14 | require(b > 0);
15 | uint256 c = a / b;
16 | return c;
17 | }
18 |
19 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
20 | require(b > 0);
21 | uint256 c = a / b;
22 | if(a % b != 0)
23 | c = c + 1;
24 | return c;
25 | }
26 |
27 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
28 | require(b <= a);
29 | uint256 c = a - b;
30 | return c;
31 | }
32 |
33 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
34 | uint256 c = a + b;
35 | require(c >= a);
36 | return c;
37 | }
38 |
39 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
40 | require(b != 0);
41 | return a % b;
42 | }
43 |
44 | int256 constant private INT256_MIN = -2^255;
45 |
46 | function mul(int256 a, int256 b) internal pure returns (int256) {
47 | if (a == 0)
48 | return 0;
49 | int256 c = a * b;
50 | require(c / a == b && (a != -1 || b != INT256_MIN));
51 | return c;
52 | }
53 |
54 | function div(int256 a, int256 b) internal pure returns (int256) {
55 | require(b != 0 && (b != -1 || a != INT256_MIN));
56 | int256 c = a / b;
57 | return c;
58 | }
59 |
60 | function sub(int256 a, int256 b) internal pure returns (int256) {
61 | int256 c = a - b;
62 | require((b >= 0 && c <= a) || (b < 0 && c > a));
63 | return c;
64 | }
65 |
66 | function add(int256 a, int256 b) internal pure returns (int256) {
67 | int256 c = a + b;
68 | require((b >= 0 && c >= a) || (b < 0 && c < a));
69 | return c;
70 | }
71 |
72 | function sqrt(int256 x) internal pure returns (int256) {
73 | int256 z = add(x / 2, 1);
74 | int256 y = x;
75 | while (z < y)
76 | {
77 | y = z;
78 | z = ((add((x / z), z)) / 2);
79 | }
80 | return y;
81 | }
82 | }
83 |
84 | interface ERC20 {
85 | using SafeMath for uint256;
86 |
87 | function totalSupply() external view returns (uint256);
88 |
89 | function balanceOf(address owner) external view returns (uint256);
90 |
91 | function allowance(address owner, address spender) external view returns (uint256);
92 |
93 | function transfer(address to, uint256 value) external returns (bool);
94 |
95 | function approve(address spender, uint256 value) external returns (bool);
96 |
97 | function transferFrom(address from, address to, uint256 value) external returns (bool);
98 |
99 | }
100 |
101 | interface CERC20 is ERC20 {
102 | function mint(uint256) external returns (uint256);
103 | }
104 |
105 | interface ClaimCan is ERC20 {
106 | function claimCan(address holder) external;
107 | }
108 |
109 | interface MDexRouter {
110 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
111 | }
112 |
113 | contract HandleCan{
114 |
115 | address internal _mainContractAddress;
116 |
117 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
118 | ERC20 constant can = ERC20(0x1e6395E6B059fc97a4ddA925b6c5ebf19E05c69f);
119 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
120 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
121 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
122 | CERC20 constant chusd = CERC20(0x9a57eAB16d371048c56cbE0c4D608096aEC5b405);
123 | CERC20 constant cusdt = CERC20(0x3dA74C09ccb8faBa3153b7f6189dDA9d7F28156A);
124 | ClaimCan constant claimCanContract = ClaimCan(0x8955aeC67f06875Ee98d69e6fe5BDEA7B60e9770);
125 |
126 | constructor(address mainContractAddress) public {
127 | _mainContractAddress = mainContractAddress;
128 | }
129 |
130 | function claim_CAN() external {
131 | assert(msg.sender == _mainContractAddress);
132 | // This method calim CAN token for main contract.
133 | // Since this contract is replaceable, we can rewrite this method if we have to.
134 | claimCanContract.claimCan(msg.sender);
135 | }
136 |
137 | function swap_CAN_to_cToken(bool is_HUSD, uint256 canAmount) external returns (uint256){
138 | assert(msg.sender == _mainContractAddress);
139 | require(can.transferFrom(msg.sender, address(this), canAmount));
140 | address[] memory path = new address[](3);
141 | path[0] = address(can);
142 | path[1] = address(wht);
143 | path[2] = is_HUSD ? address(husd) : address(usdt);
144 | can.approve(address(mdex), canAmount);
145 | // Try to swap CAN for cHUSD or cUSDT. This action may fail beacuse lack of liqudility.
146 | try mdex.swapExactTokensForTokens(canAmount, 0, path, address(this), now) returns (uint256[] memory amounts) {
147 | if(amounts[2]==0)
148 | return 0;
149 | if (is_HUSD) {
150 | husd.approve(address(chusd),amounts[2]);
151 | uint256 minted= chusd.mint(amounts[2]);
152 | chusd.approve(msg.sender, minted);
153 | return minted;
154 | } else{
155 | usdt.approve(address(cusdt),amounts[2]);
156 | uint256 minted= cusdt.mint(amounts[2]);
157 | cusdt.approve(msg.sender, minted);
158 | return minted;
159 | }
160 | } catch (bytes memory) {
161 | // swap failed, return token back to main contract
162 | can.transfer(msg.sender, canAmount);
163 | return 0;
164 | }
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/depth.vault/dCowVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./interfaces/IVault.sol";
9 | /**depth.fi vault***/
10 | contract dCowVault is ERC20,Ownable,Pausable {
11 | using SafeERC20 for IERC20;
12 | using SafeMath for uint256;
13 |
14 | address public want;
15 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
16 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //DEP DAO ADDRESS
17 | address public husdSwapAddress;
18 | address public mdxAddress = 0x25D2e80cB6B86881Fd7e07dd263Fb79f4AbE033c;
19 | address public cowAddress = 0x80861A817106665bcA173DB6AC2ab628a738c737;
20 | address public cowCtrlAddress = 0x22F560e032b256e8C7Cb50253591B0850162cb74;
21 | uint256 public balance;//total token balance
22 | uint256 public minClaim=1;//min interest to claim
23 | uint256 public maxLimit;// max balance limit
24 | uint256 public cowPoolId;
25 | constructor (address _want,address _husdSwapAddress) ERC20(
26 | string(abi.encodePacked("Depth.Fi Vault Cow", ERC20(_want).symbol())),
27 | string(abi.encodePacked("dcow", ERC20(_want).symbol()))
28 | ) {
29 |
30 | require(_want != address(0), "INVALID TOKEN ADDRESS");
31 | want = _want;
32 | ICow cow=ICow(cowCtrlAddress);
33 | uint256 _poolLength=cow.poolLength();
34 | bool bFound=false;
35 | for(uint256 i=0;i<_poolLength;i++){
36 | (address _token,,,,,,,,,,)=cow.poolInfo(i);
37 | if (want==_token){
38 | bFound=true;
39 | cowPoolId = i;
40 | break;
41 | }
42 | }
43 | require(bFound,"not supported want token!");
44 | husdSwapAddress = _husdSwapAddress;
45 |
46 | }
47 | // set min claim interest
48 | function setMinClaim(uint256 _min) external onlyOwner{
49 | minClaim = _min;
50 | }
51 | // set max deposit limit
52 | function setMaxLimit(uint256 _max) external onlyOwner{
53 | maxLimit = _max;
54 | }
55 | // set husd swap contract address
56 | function setHusdSwapAddress(address _address) external onlyOwner{
57 | require(_address!=address(0),"no address!");
58 | husdSwapAddress = _address;
59 | }
60 |
61 | // set dao contract address
62 | function setDaoAddress(address _address) external onlyOwner{
63 | require(_address!=address(0),"no address!");
64 | daoAddress = _address;
65 | }
66 |
67 | function swapTokensToHusd(address _token) internal{
68 | require(husdSwapAddress!=address(0),"not set husd swap address!");
69 | uint256 _amount = IERC20(_token).balanceOf(address(this));
70 | if (_amount==0){
71 | return;
72 | }
73 | IERC20(_token).safeApprove(husdSwapAddress,_amount);
74 | IHusdSwap(husdSwapAddress).swapTokensToHusd(_token,_amount);
75 | }
76 | function getMdxAmount() public view returns(uint256){
77 | (uint256 _mdxAmount,,) = ICow(cowCtrlAddress).pending(cowPoolId,address(this));
78 | return _mdxAmount;
79 | }
80 | function getCowAmount() public view returns(uint256){
81 | return ICow(cowCtrlAddress).pendingCow(cowPoolId,address(this));
82 | }
83 | function getRemaining() public view returns(uint256){
84 | ICow cow=ICow(cowCtrlAddress);
85 | (,,,,,uint256 _totalAmount,uint256 _totalAmountLimit,,,,)=cow.poolInfo(cowPoolId);
86 | uint256 _remaining = _totalAmountLimit.sub(_totalAmount);
87 | if(maxLimit>0){
88 | if (maxLimit<=balance){
89 | _remaining =0;
90 | }else{
91 | _remaining = _remaining>maxLimit.sub(balance)?maxLimit.sub(balance):_remaining;
92 | }
93 | }
94 | return _remaining;
95 | }
96 | function harvest() public{
97 | //claim interest
98 |
99 | uint256 _mdxAmount = getMdxAmount();
100 | uint256 _cowAmount = getCowAmount();
101 | if (_mdxAmount>=minClaim||_cowAmount>=minClaim){
102 | ICow(cowCtrlAddress).withdraw(want,0);
103 | swapTokensToHusd(mdxAddress);
104 | swapTokensToHusd(cowAddress);
105 | }
106 | //donate husd to dao
107 | uint256 _husdBalance = IERC20(husd).balanceOf(address(this));
108 | IERC20(husd).safeApprove(daoAddress,_husdBalance);
109 | //call dao address donate husd
110 | IDao(daoAddress).donateHUSD(_husdBalance);
111 |
112 |
113 | }
114 | //deposit
115 | function deposit(uint256 _amount) external whenNotPaused {
116 | require(_amount>0,"invalid amount");
117 | require(getRemaining()>=_amount,"exceed max deposit limit");
118 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
119 | //deposit token to compound
120 | IERC20(want).safeApprove(cowCtrlAddress, _amount);
121 | ICow(cowCtrlAddress).deposit(want,_amount);
122 | balance=balance.add(_amount);
123 | _mint(msg.sender, _amount);
124 | }
125 | //withdraw
126 | function withdraw(uint256 _amount) external {
127 | require(_amount>0,"invalid amount");
128 | _burn(msg.sender, _amount);
129 | ICow(cowCtrlAddress).withdraw(want,_amount);
130 |
131 | IERC20(want).safeTransfer(msg.sender, _amount);
132 | balance=balance.sub(_amount);
133 |
134 | }
135 | //claim exchange token like mdx to owner.
136 | function claimExchangeMiningToken(address _swapAddress,address _miningToken) external onlyOwner{
137 | require(_swapAddress!=address(0),"invalid swap address");
138 | require(_miningToken!=address(0),"invalid mining token address");
139 | ISwapMining(_swapAddress).takerWithdraw();
140 | IERC20(_miningToken).safeTransfer(msg.sender,IERC20(_miningToken).balanceOf(address(this)));
141 |
142 | }
143 |
144 | function pause() external onlyOwner {
145 | _pause();
146 | }
147 | function decimals() public view override returns (uint8) {
148 | return ERC20(want).decimals();
149 | }
150 |
151 |
152 | function unpause() external onlyOwner {
153 | _unpause();
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/depthStableSwapV2/SellLendPlatformToken(Lendhub).sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 |
4 | library SafeMath {
5 |
6 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
7 | if (a == 0)
8 | return 0;
9 | uint256 c = a * b;
10 | require(c / a == b);
11 | return c;
12 | }
13 |
14 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
15 | require(b > 0);
16 | uint256 c = a / b;
17 | return c;
18 | }
19 |
20 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
21 | require(b > 0);
22 | uint256 c = a / b;
23 | if(a % b != 0)
24 | c = c + 1;
25 | return c;
26 | }
27 |
28 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
29 | require(b <= a);
30 | uint256 c = a - b;
31 | return c;
32 | }
33 |
34 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
35 | uint256 c = a + b;
36 | require(c >= a);
37 | return c;
38 | }
39 |
40 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
41 | require(b != 0);
42 | return a % b;
43 | }
44 |
45 | int256 constant private INT256_MIN = -2^255;
46 |
47 | function mul(int256 a, int256 b) internal pure returns (int256) {
48 | if (a == 0)
49 | return 0;
50 | int256 c = a * b;
51 | require(c / a == b && (a != -1 || b != INT256_MIN));
52 | return c;
53 | }
54 |
55 | function div(int256 a, int256 b) internal pure returns (int256) {
56 | require(b != 0 && (b != -1 || a != INT256_MIN));
57 | int256 c = a / b;
58 | return c;
59 | }
60 |
61 | function sub(int256 a, int256 b) internal pure returns (int256) {
62 | int256 c = a - b;
63 | require((b >= 0 && c <= a) || (b < 0 && c > a));
64 | return c;
65 | }
66 |
67 | function add(int256 a, int256 b) internal pure returns (int256) {
68 | int256 c = a + b;
69 | require((b >= 0 && c >= a) || (b < 0 && c < a));
70 | return c;
71 | }
72 |
73 | function sqrt(int256 x) internal pure returns (int256) {
74 | int256 z = add(x / 2, 1);
75 | int256 y = x;
76 | while (z < y)
77 | {
78 | y = z;
79 | z = ((add((x / z), z)) / 2);
80 | }
81 | return y;
82 | }
83 | }
84 |
85 | interface ERC20 {
86 | using SafeMath for uint256;
87 |
88 | function totalSupply() external view returns (uint256);
89 |
90 | function balanceOf(address owner) external view returns (uint256);
91 |
92 | function allowance(address owner, address spender) external view returns (uint256);
93 |
94 | function transfer(address to, uint256 value) external returns (bool);
95 |
96 | function approve(address spender, uint256 value) external returns (bool);
97 |
98 | function transferFrom(address from, address to, uint256 value) external returns (bool);
99 |
100 | }
101 |
102 | interface CERC20 is ERC20 {
103 | function mint(uint256) external returns (uint256);
104 | }
105 |
106 | interface ClaimComp is ERC20 {
107 | function claimComp(address holder, address[] memory cTokens) external;
108 | }
109 |
110 | interface MDexRouter {
111 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
112 | function getAmountsOut(uint amountIn, address[] calldata path) external returns (uint256[] memory);
113 | }
114 |
115 | contract SellLendPlatformToken{
116 |
117 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
118 | ERC20 constant lhb = ERC20(0x8F67854497218043E1f72908FFE38D0Ed7F24721);
119 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
120 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
121 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
122 | CERC20 constant lhusd = CERC20(0x1C478D5d1823D51c4c4b196652912A89D9b46c30);
123 | CERC20 constant lusdt = CERC20(0xc502F3f6f1b71CB7d856E70B574D27d942C2993C);
124 | ClaimComp constant claimLHBContract = ClaimComp(0x6537d6307ca40231939985BCF7D83096Dd1B4C09);
125 |
126 | function claim_lending_platform_token() external {
127 | // This method calim LHB token for main contract.
128 | // Since this contract is replaceable, we can rewrite this method if we have to.
129 | address[] memory cTokens = new address[](2);
130 | cTokens[0] = 0x1C478D5d1823D51c4c4b196652912A89D9b46c30; // Add lHUSD
131 | cTokens[1] = 0xc502F3f6f1b71CB7d856E70B574D27d942C2993C; // Add lUSDT
132 | claimLHBContract.claimComp(msg.sender, cTokens);
133 | }
134 |
135 | function sell_lending_platform_token(uint256 lhbAmount) external returns (bool){
136 | require(lhb.transferFrom(msg.sender, address(this), lhbAmount));
137 |
138 | address[] memory path1 = new address[](3);
139 | path1[0] = address(lhb);
140 | path1[1] = address(wht);
141 | path1[2] = address(husd);
142 | uint256 amount1 = mdex.getAmountsOut(lhbAmount, path1)[2];
143 |
144 | address[] memory path2 = new address[](3);
145 | path2[0] = address(lhb);
146 | path2[1] = address(usdt);
147 | path2[2] = address(husd);
148 | uint256 amount2 = mdex.getAmountsOut(lhbAmount, path2)[2];
149 |
150 | address[] memory path;
151 |
152 | if (amount1 > amount2) {
153 | path = path1;
154 | } else {
155 | path = path2;
156 | }
157 |
158 | lhb.approve(address(mdex), lhbAmount);
159 |
160 | // Try to swap LHB for lHUSD or lUSDT. This action may fail beacuse lack of liqudility.
161 | try mdex.swapExactTokensForTokens(lhbAmount, 0, path, address(this), now) returns (uint256[] memory amounts) {
162 | uint256 husdBalance = husd.balanceOf(address(this));
163 | if(husdBalance == 0)
164 | return true;
165 | husd.transfer(msg.sender, husdBalance);
166 | return true;
167 | } catch (bytes memory) {
168 | // swap failed, return token back to main contract
169 | lhb.transfer(msg.sender, lhbAmount);
170 | return true;
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/depth.vault/dBackVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./interfaces/IVault.sol";
9 | /**depth.fi vault***/
10 | contract dBackVault is ERC20,Ownable,Pausable {
11 | using SafeERC20 for IERC20;
12 | using SafeMath for uint256;
13 |
14 | address public want;
15 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
16 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //DEP DAO ADDRESS
17 | //address public usdtSwapAddress=0x07c8689FfC95caf92DA7Cc2A55bCbE7dAFCf0A47; //DEP swap usdt to husd
18 | address public husdSwapAddress;//swap compound token to husd
19 | uint256 public maxLimit;// max balance limit
20 | address public cTokenAddress;
21 | uint256 public balance;//total token balance
22 | uint256 public minClaim=1;//min interest to claim default 1
23 | address public blackPlatform = 0x9c5dDcD6825413c52e7DA2ADBCFD30638D3B7A0d;
24 | constructor (address _cTokenAddress,address _husdSwapAddress) ERC20(
25 | string(abi.encodePacked("Depth.Fi Vault ", ERC20(_cTokenAddress).symbol())),
26 | string(abi.encodePacked("d", ERC20(_cTokenAddress).symbol()))
27 | ) {
28 |
29 | require(_cTokenAddress != address(0), "INVALID CTOKEN ADDRESS");
30 | want = IBack(_cTokenAddress).supplyToken();
31 | cTokenAddress=_cTokenAddress;
32 | husdSwapAddress = _husdSwapAddress;
33 |
34 | }
35 | // set min claim interest
36 | function setMinClaim(uint256 _min) external onlyOwner{
37 | minClaim = _min;
38 | }
39 |
40 | // set husd swap contract address
41 | function setHusdSwapAddress(address _address) external onlyOwner{
42 | husdSwapAddress = _address;
43 | }
44 |
45 | // set dao contract address
46 | function setDaoAddress(address _address) external onlyOwner{
47 | daoAddress = _address;
48 | }
49 |
50 | // set max deposit limit
51 | function setMaxLimit(uint256 _max) external onlyOwner{
52 | maxLimit = _max;
53 | }
54 |
55 | function swapTokensToHusd(address _token) internal{
56 | require(husdSwapAddress!=address(0),"not set husd swap address!");
57 | uint256 _amount = IERC20(_token).balanceOf(address(this));
58 | if (_amount==0){
59 | return;
60 | }
61 | IERC20(_token).safeApprove(husdSwapAddress,_amount);
62 | IHusdSwap(husdSwapAddress).swapTokensToHusd(_token,_amount);
63 | }
64 |
65 | function isCan() internal view returns(bool){
66 | if (cTokenAddress==0x9a57eAB16d371048c56cbE0c4D608096aEC5b405||cTokenAddress==0x3dA74C09ccb8faBa3153b7f6189dDA9d7F28156A){
67 | return true;
68 | }else{
69 | return false;
70 | }
71 | }
72 |
73 | function harvest() public{
74 | IBack backPool = IBack(cTokenAddress);
75 | //claim interest
76 | uint256 _selfUnderlying = getSelfUnderlying();
77 | uint256 _compUnderlyingBalance = backPool.getTotalShare().sub(backPool.totalBorrow()).sub(backPool.totalInterestToPay()).sub(backPool.poolReserve());
78 | uint256 _interest = _selfUnderlying.sub(balance);
79 | if (_interest>=minClaim){
80 | uint256 _claimAmount = _interest<_compUnderlyingBalance?_interest:_compUnderlyingBalance;
81 | IBack(blackPlatform).withdraw(want,_claimAmount);
82 | if (want!=husd){
83 | swapTokensToHusd(want);
84 | }
85 | }
86 |
87 | address _compTokenAddress = 0x6474bc11F512DfE6A5162b2167e3f94b61471d05;
88 | swapTokensToHusd(_compTokenAddress);
89 |
90 | //donate husd to dao
91 | uint256 _husdBalance = IERC20(husd).balanceOf(address(this));
92 | if (_husdBalance>0){
93 | IERC20(husd).approve(daoAddress,_husdBalance);
94 | //call dao address donate husd
95 | IDao(daoAddress).donateHUSD(_husdBalance);
96 | }
97 |
98 |
99 | }
100 | //get underlying amount in back pool
101 | function getSelfUnderlying() public view returns (uint256) {
102 | IBack backPool = IBack(cTokenAddress);
103 | uint256 _totalSupply = backPool.totalSupply();
104 | if (_totalSupply==0){
105 | return 0;
106 | }
107 | return IERC20(cTokenAddress).balanceOf(address(this)).mul(backPool.getTotalShare()).div(backPool.totalSupply());
108 | }
109 |
110 | //deposit
111 | function deposit(uint256 _amount) external whenNotPaused {
112 | require(_amount>0,"invalid amount");
113 | require(maxLimit==0||balance.add(_amount)<=maxLimit,"exceed max deposit limit");
114 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
115 | //deposit token to compound
116 | IERC20(want).safeApprove(blackPlatform, _amount);
117 | IBack(blackPlatform).deposit(want,_amount);
118 | balance=balance.add(_amount);
119 | _mint(msg.sender, _amount);
120 | }
121 | //withdraw
122 | function withdraw(uint256 _amount) external {
123 | require(_amount>0,"invalid amount");
124 | _burn(msg.sender, _amount);
125 |
126 | //uint256 _before = IERC20(want).balanceOf(address(this));
127 | //redeemUnderlying
128 |
129 | IBack(blackPlatform).withdraw(want,_amount) ;
130 | IERC20(want).safeTransfer(msg.sender, _amount);
131 | balance=balance.sub(_amount);
132 |
133 | }
134 | //claim exchange token like mdx to owner.
135 | function claimExchangeMiningToken(address _swapAddress,address _miningToken) external onlyOwner{
136 | require(_swapAddress!=address(0),"invalid swap address");
137 | require(_miningToken!=address(0),"invalid mining token address");
138 | ISwapMining(_swapAddress).takerWithdraw();
139 | require(_miningToken!=cTokenAddress,"can not claim ctoken");
140 | IERC20(_miningToken).safeTransfer(msg.sender,IERC20(_miningToken).balanceOf(address(this)));
141 |
142 | }
143 |
144 | function pause() external onlyOwner {
145 | _pause();
146 | }
147 |
148 |
149 | function unpause() external onlyOwner {
150 | _unpause();
151 | }
152 | function decimals() public view override returns (uint8) {
153 | return ERC20(want).decimals();
154 | }
155 |
156 | }
157 |
--------------------------------------------------------------------------------
/fildaPool/handleFilda.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 | library SafeMath {
4 |
5 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
6 | if (a == 0)
7 | return 0;
8 | uint256 c = a * b;
9 | require(c / a == b);
10 | return c;
11 | }
12 |
13 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
14 | require(b > 0);
15 | uint256 c = a / b;
16 | return c;
17 | }
18 |
19 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
20 | require(b > 0);
21 | uint256 c = a / b;
22 | if(a % b != 0)
23 | c = c + 1;
24 | return c;
25 | }
26 |
27 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
28 | require(b <= a);
29 | uint256 c = a - b;
30 | return c;
31 | }
32 |
33 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
34 | uint256 c = a + b;
35 | require(c >= a);
36 | return c;
37 | }
38 |
39 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
40 | require(b != 0);
41 | return a % b;
42 | }
43 |
44 | int256 constant private INT256_MIN = -2^255;
45 |
46 | function mul(int256 a, int256 b) internal pure returns (int256) {
47 | if (a == 0)
48 | return 0;
49 | int256 c = a * b;
50 | require(c / a == b && (a != -1 || b != INT256_MIN));
51 | return c;
52 | }
53 |
54 | function div(int256 a, int256 b) internal pure returns (int256) {
55 | require(b != 0 && (b != -1 || a != INT256_MIN));
56 | int256 c = a / b;
57 | return c;
58 | }
59 |
60 | function sub(int256 a, int256 b) internal pure returns (int256) {
61 | int256 c = a - b;
62 | require((b >= 0 && c <= a) || (b < 0 && c > a));
63 | return c;
64 | }
65 |
66 | function add(int256 a, int256 b) internal pure returns (int256) {
67 | int256 c = a + b;
68 | require((b >= 0 && c >= a) || (b < 0 && c < a));
69 | return c;
70 | }
71 |
72 | function sqrt(int256 x) internal pure returns (int256) {
73 | int256 z = add(x / 2, 1);
74 | int256 y = x;
75 | while (z < y)
76 | {
77 | y = z;
78 | z = ((add((x / z), z)) / 2);
79 | }
80 | return y;
81 | }
82 | }
83 |
84 | interface ERC20 {
85 | using SafeMath for uint256;
86 |
87 | function totalSupply() external view returns (uint256);
88 |
89 | function balanceOf(address owner) external view returns (uint256);
90 |
91 | function allowance(address owner, address spender) external view returns (uint256);
92 |
93 | function transfer(address to, uint256 value) external returns (bool);
94 |
95 | function approve(address spender, uint256 value) external returns (bool);
96 |
97 | function transferFrom(address from, address to, uint256 value) external returns (bool);
98 |
99 | }
100 |
101 | interface CERC20 is ERC20 {
102 | function mint(uint256) external returns (uint256);
103 | }
104 |
105 | interface ClaimComp is ERC20 {
106 | function claimComp(address holder) external;
107 | }
108 |
109 | interface MDexRouter {
110 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
111 | }
112 |
113 | contract HandleFILDA{
114 |
115 | address internal _mainContractAddress;
116 |
117 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
118 | ERC20 constant filda = ERC20(0xE36FFD17B2661EB57144cEaEf942D95295E637F0);
119 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
120 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
121 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
122 | CERC20 constant fhusd = CERC20(0xB16Df14C53C4bcfF220F4314ebCe70183dD804c0);
123 | CERC20 constant fusdt = CERC20(0xAab0C9561D5703e84867670Ac78f6b5b4b40A7c1);
124 | ClaimComp constant claimFILDAContract = ClaimComp(0xb74633f2022452f377403B638167b0A135DB096d);
125 |
126 | constructor(address mainContractAddress) public {
127 | _mainContractAddress = mainContractAddress;
128 | }
129 |
130 | function claim_FILDA() external {
131 | assert(msg.sender == _mainContractAddress);
132 | // This method calim FILDA token for main contract.
133 | // Since this contract is replaceable, we FILDA rewrite this method if we have to.
134 | claimFILDAContract.claimComp(msg.sender);
135 | }
136 |
137 | function swap_FILDA_to_fToken(bool is_HUSD, uint256 fildaAmount) external returns (uint256){
138 | assert(msg.sender == _mainContractAddress);
139 | require(filda.transferFrom(msg.sender, address(this), fildaAmount));
140 | address[] memory path;
141 | if (is_HUSD) {
142 | path = new address[](2);
143 | path[0] = address(filda);
144 | path[1] = address(husd);
145 | } else{
146 | path = new address[](3);
147 | path[0] = address(filda);
148 | path[1] = address(wht);
149 | path[2] = address(usdt);
150 | }
151 | filda.approve(address(mdex), fildaAmount);
152 | // Try to swap FILDA for fHUSD or fUSDT. This action may fail beacuse lack of liqudility.
153 | try mdex.swapExactTokensForTokens(fildaAmount, 0, path, address(this), now) returns (uint256[] memory amounts) {
154 | if (is_HUSD) {
155 | if(amounts[1] == 0)
156 | return 0;
157 | husd.approve(address(fhusd),amounts[1]);
158 | fhusd.mint(amounts[1]);
159 | uint256 balance = fhusd.balanceOf(address(this));
160 | fhusd.approve(msg.sender, balance);
161 | return balance;
162 | } else{
163 | if(amounts[2] == 0)
164 | return 0;
165 | usdt.approve(address(fusdt),amounts[2]);
166 | fusdt.mint(amounts[2]);
167 | uint256 balance = fusdt.balanceOf(address(this));
168 | fusdt.approve(msg.sender, balance);
169 | return balance;
170 | }
171 | } catch (bytes memory) {
172 | // swap failed, return token back to main contract
173 | filda.transfer(msg.sender, fildaAmount);
174 | return 0;
175 | }
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/lendhub-eth-beth/handLHB.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 |
4 | library SafeMath {
5 |
6 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
7 | if (a == 0)
8 | return 0;
9 | uint256 c = a * b;
10 | require(c / a == b);
11 | return c;
12 | }
13 |
14 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
15 | require(b > 0);
16 | uint256 c = a / b;
17 | return c;
18 | }
19 |
20 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
21 | require(b > 0);
22 | uint256 c = a / b;
23 | if(a % b != 0)
24 | c = c + 1;
25 | return c;
26 | }
27 |
28 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
29 | require(b <= a);
30 | uint256 c = a - b;
31 | return c;
32 | }
33 |
34 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
35 | uint256 c = a + b;
36 | require(c >= a);
37 | return c;
38 | }
39 |
40 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
41 | require(b != 0);
42 | return a % b;
43 | }
44 |
45 | int256 constant private INT256_MIN = -2^255;
46 |
47 | function mul(int256 a, int256 b) internal pure returns (int256) {
48 | if (a == 0)
49 | return 0;
50 | int256 c = a * b;
51 | require(c / a == b && (a != -1 || b != INT256_MIN));
52 | return c;
53 | }
54 |
55 | function div(int256 a, int256 b) internal pure returns (int256) {
56 | require(b != 0 && (b != -1 || a != INT256_MIN));
57 | int256 c = a / b;
58 | return c;
59 | }
60 |
61 | function sub(int256 a, int256 b) internal pure returns (int256) {
62 | int256 c = a - b;
63 | require((b >= 0 && c <= a) || (b < 0 && c > a));
64 | return c;
65 | }
66 |
67 | function add(int256 a, int256 b) internal pure returns (int256) {
68 | int256 c = a + b;
69 | require((b >= 0 && c >= a) || (b < 0 && c < a));
70 | return c;
71 | }
72 |
73 | function sqrt(int256 x) internal pure returns (int256) {
74 | int256 z = add(x / 2, 1);
75 | int256 y = x;
76 | while (z < y)
77 | {
78 | y = z;
79 | z = ((add((x / z), z)) / 2);
80 | }
81 | return y;
82 | }
83 | }
84 |
85 | interface ERC20 {
86 | using SafeMath for uint256;
87 |
88 | function totalSupply() external view returns (uint256);
89 |
90 | function balanceOf(address owner) external view returns (uint256);
91 |
92 | function allowance(address owner, address spender) external view returns (uint256);
93 |
94 | function transfer(address to, uint256 value) external returns (bool);
95 |
96 | function approve(address spender, uint256 value) external returns (bool);
97 |
98 | function transferFrom(address from, address to, uint256 value) external returns (bool);
99 |
100 | }
101 |
102 | interface CERC20 is ERC20 {
103 | function mint(uint256) external returns (uint256);
104 | }
105 |
106 | interface ClaimComp is ERC20 {
107 | function claimComp(address holder, address[] memory cTokens) external;
108 | }
109 |
110 | interface MDexRouter {
111 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
112 | }
113 |
114 | contract HandleLendPlatformToken{
115 |
116 | address internal _mainContractAddress;
117 |
118 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
119 | ERC20 constant lhb = ERC20(0x8F67854497218043E1f72908FFE38D0Ed7F24721);
120 | ERC20 constant eth = ERC20(0x64FF637fB478863B7468bc97D30a5bF3A428a1fD);
121 | ERC20 constant beth = ERC20(0xB6F4c418514dd4680F76d5caa3bB42dB4A893aCb);
122 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
123 | CERC20 constant leth = CERC20(0x505Bdd86108E7d9d662234F6a5F8A4CBAeCE81AB);
124 | CERC20 constant lbeth = CERC20(0xEf4bBD27C75674A7c562d0d02E79415587c1595C);
125 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
126 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
127 | ClaimComp constant claimLHBContract = ClaimComp(0x6537d6307ca40231939985BCF7D83096Dd1B4C09);
128 |
129 | constructor(address mainContractAddress) public {
130 | _mainContractAddress = mainContractAddress;
131 | }
132 |
133 | function claim_lending_platform_token() external {
134 | assert(msg.sender == _mainContractAddress);
135 | // This method calim LHB token for main contract.
136 | // Since this contract is replaceable, we can rewrite this method if we have to.
137 | address[] memory cTokens = new address[](2);
138 | cTokens[0] = 0x505Bdd86108E7d9d662234F6a5F8A4CBAeCE81AB; // Add lETH
139 | cTokens[1] = 0xEf4bBD27C75674A7c562d0d02E79415587c1595C; // Add lBETH
140 | claimLHBContract.claimComp(msg.sender, cTokens);
141 | }
142 |
143 | function sell_lending_platform_token(bool isCoin1, uint256 lhbAmount) external returns (uint256){
144 | assert(msg.sender == _mainContractAddress);
145 | require(lhb.transferFrom(msg.sender, address(this), lhbAmount));
146 | // Sell lhb for eth even the amount of eth is larger than beth's
147 | // because mdex does not support beth currently.
148 | address[] memory path;
149 | path = new address[](4);
150 | path[0] = address(lhb);
151 | path[1] = address(usdt);
152 | path[2] = address(husd);
153 | path[3] = address(eth);
154 | lhb.approve(address(mdex), lhbAmount);
155 | // This action may fail beacuse lack of liqudility.
156 | try mdex.swapExactTokensForTokens(lhbAmount, 0, path, address(this), now) returns (uint256[] memory amounts) {
157 | if(amounts[1] == 0)
158 | return 0;
159 | eth.approve(address(leth),amounts[1]);
160 | leth.mint(amounts[1]);
161 | uint256 balance = leth.balanceOf(address(this));
162 | leth.approve(msg.sender, balance);
163 | return balance;
164 | } catch (bytes memory) {
165 | // Swap failed, return token back to main contract
166 | lhb.transfer(msg.sender, lhbAmount);
167 | return 0;
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/SingleTokenPool/SingleTokenPool.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 | import "./openzeppelin/contracts/security/Pausable.sol";
7 | contract SingleTokenPool is Ownable,Pausable {
8 | using SafeERC20 for IERC20;
9 | using SafeMath for uint256;
10 | address public rewardToken;
11 | uint256 public totalReward;
12 | uint256 public totalClaimedReward;
13 | uint256 public totalClaimedLock;
14 | uint256 public totalLockAmount;
15 | address public lockToken;
16 | uint256 public lockLimitAmount;
17 | uint256 public startTime;
18 | uint256 public endTime;
19 | uint256 public lastRewardTime;
20 | uint256 public rewardPerLock;
21 | mapping(address=>UserInfo) public userInfo;
22 | struct UserInfo{
23 | uint256 lockAmount;
24 | uint256 rewardDebt;
25 | uint256 pendingReward;
26 | }
27 | constructor (address _lockToken, address _rewardToken,uint256 _lockLimitAmount,uint256 _totalReward,uint256 _startTime,uint256 _lockDays) {
28 |
29 | require(_lockToken != address(0), "invalid lock token");
30 | require(_rewardToken != address(0), "invalid reward token");
31 | lockToken = _lockToken;
32 | rewardToken = _rewardToken;
33 | lockLimitAmount = _lockLimitAmount;
34 | totalReward = _totalReward;
35 | startTime = _startTime;
36 | lastRewardTime = _startTime;
37 | uint256 currentTime = block.timestamp;
38 | require(startTime==0||startTime>=currentTime,"start time must over now!");
39 | if (_lockDays>0&&startTime>0){
40 | endTime = startTime.add(86400*_lockDays);
41 | }
42 | }
43 | function setSetting(uint256 _lockLimitAmount,uint256 _totalReward,uint256 _startTime,uint256 _lockDays) external onlyOwner{
44 | uint256 currentTime = block.timestamp;
45 |
46 | if(_totalReward>0){
47 | require(startTime==0||startTime>currentTime,"The activity has begun!");
48 | totalReward = _totalReward;
49 | }
50 | if(_startTime>0){
51 | require(startTime==0||(startTime>currentTime&&_startTime>currentTime&&_lockDays>0),"invalid start time!");
52 | startTime = _startTime;
53 | lastRewardTime = _startTime;
54 | }
55 | if (_lockDays>0){
56 | require(startTime>0&&startTime>currentTime,"The activity has begun!");
57 | endTime = startTime.add(86400*_lockDays);
58 | }
59 | if (_lockLimitAmount>0){
60 | lockLimitAmount = _lockLimitAmount;
61 | }
62 | }
63 | function lock(uint256 _amount) external{
64 | uint256 currentTime = block.timestamp;
65 | require(startTime > 0,"no start time!");
66 | require(currentTime0){
68 | require(totalLockAmount.add(_amount)<=lockLimitAmount,"exceed lock limit amount!");
69 | }
70 | UserInfo storage _user= userInfo[msg.sender];
71 |
72 | updatePool();
73 | if (_user.lockAmount>0){
74 | uint256 _pending = _user.lockAmount.mul(rewardPerLock).div(10**12).sub(_user.rewardDebt);
75 | if (_pending>0){
76 | _user.pendingReward = _user.pendingReward.add(_pending);
77 | }
78 | }
79 | if (_amount>0){
80 | IERC20(lockToken).safeTransferFrom(msg.sender,address(this),_amount);
81 | _user.lockAmount = _user.lockAmount.add(_amount);
82 | totalLockAmount = totalLockAmount.add(_amount);
83 | }
84 | _user.rewardDebt = _user.lockAmount.mul(rewardPerLock).div(10**12);
85 | }
86 | function unLock() external{
87 | updatePool();
88 | uint256 currentTime = block.timestamp;
89 | require(currentTime > endTime,"The activity is not over");
90 | UserInfo storage _user= userInfo[msg.sender];
91 | uint256 _pending = _user.lockAmount.mul(rewardPerLock).div(10**12).sub(_user.rewardDebt);
92 | uint256 _reward = _user.pendingReward.add(_pending);
93 | if (_user.lockAmount>0){
94 | IERC20(lockToken).safeTransfer(msg.sender,_user.lockAmount);
95 | }
96 | if (_reward>0){
97 | uint256 _balance = IERC20(rewardToken).balanceOf(address(this));
98 | require(_balance>=_reward,"not enough balance!");
99 | totalClaimedReward = totalClaimedReward.add(_reward);
100 | totalClaimedLock = totalClaimedLock.add(_user.lockAmount);
101 |
102 |
103 | }
104 | delete userInfo[msg.sender];
105 | IERC20(rewardToken).safeTransfer(msg.sender,_reward);
106 | }
107 |
108 | function emergencyWithdraw() external{
109 | uint256 currentTime = block.timestamp;
110 | require(currentTime > endTime,"The activity is not over");
111 | UserInfo storage _user= userInfo[msg.sender];
112 | require(_user.lockAmount>0,"haven't stake!");
113 | IERC20(lockToken).safeTransfer(msg.sender,_user.lockAmount);
114 | delete userInfo[msg.sender];
115 | }
116 | function pendingReward(address _address) public view returns(uint256){
117 | UserInfo memory _user= userInfo[_address];
118 | uint256 currentTime = block.timestamp;
119 | if (currentTime<=startTime||startTime==0||endTime==0||totalLockAmount==0){
120 | return 0;
121 | }
122 | uint256 _endTime = currentTime>endTime?endTime:currentTime;
123 | uint256 _totalTimes = _endTime.sub(startTime);
124 | uint256 _rewardPerLock =rewardPerLock.add(getRewardPerTime().mul(_totalTimes).div(totalLockAmount));
125 | return _user.lockAmount.mul(_rewardPerLock).div(10**12).add(_user.pendingReward).sub(_user.rewardDebt);
126 | }
127 |
128 | function getRewardPerTime() public view returns(uint256){
129 | if (endTime==0){
130 | return 0;
131 | }
132 | return totalReward.mul(10**12).div(endTime.sub(startTime));
133 | }
134 | function updatePool() public{
135 | uint256 currentTime = block.timestamp;
136 | if (currentTime<=lastRewardTime){
137 | return;
138 | }
139 | if (totalLockAmount==0){
140 | lastRewardTime = currentTime;
141 | return;
142 | }
143 | uint256 _endTime = currentTime>endTime?endTime:currentTime;
144 | uint256 _totalTimes = _endTime.sub(lastRewardTime);
145 | rewardPerLock =rewardPerLock.add(getRewardPerTime().mul(_totalTimes).div(totalLockAmount));
146 | lastRewardTime = _endTime;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/DepthTokenV1.vy:
--------------------------------------------------------------------------------
1 | # @version 0.1.0b16
2 |
3 | # @title Curve LP Token
4 | # @author Curve.Fi
5 | # @notice Used in combination with all pools compiled by vyper 0.1.0-beta.x
6 | # @dev Follows the ERC-20 token standard as defined at
7 | # https://eips.ethereum.org/EIPS/eip-20
8 |
9 | from vyper.interfaces import ERC20
10 |
11 | implements: ERC20
12 |
13 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
14 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
15 |
16 | name: public(string[64])
17 | symbol: public(string[32])
18 | decimals: public(uint256)
19 |
20 | # NOTE: By declaring `balanceOf` as public, vyper automatically generates a 'balanceOf()' getter
21 | # method to allow access to account balances.
22 | # The _KeyType will become a required parameter for the getter and it will return _ValueType.
23 | # See: https://vyper.readthedocs.io/en/v0.1.0-beta.8/types.html?highlight=getter#mappings
24 | balanceOf: public(map(address, uint256))
25 | allowances: map(address, map(address, uint256))
26 | total_supply: uint256
27 | minter: address
28 |
29 |
30 | @public
31 | def __init__(_name: string[64], _symbol: string[32], _decimals: uint256, _supply: uint256):
32 | init_supply: uint256 = _supply * 10 ** _decimals
33 | self.name = _name
34 | self.symbol = _symbol
35 | self.decimals = _decimals
36 | self.balanceOf[msg.sender] = init_supply
37 | self.total_supply = init_supply
38 | self.minter = msg.sender
39 | log.Transfer(ZERO_ADDRESS, msg.sender, init_supply)
40 |
41 |
42 | @public
43 | def set_minter(_minter: address):
44 | assert msg.sender == self.minter
45 | self.minter = _minter
46 |
47 |
48 | @public
49 | @constant
50 | def totalSupply() -> uint256:
51 | """
52 | @dev Total number of tokens in existence.
53 | """
54 | return self.total_supply
55 |
56 |
57 | @public
58 | @constant
59 | def allowance(_owner : address, _spender : address) -> uint256:
60 | """
61 | @dev Function to check the amount of tokens that an owner allowed to a spender.
62 | @param _owner The address which owns the funds.
63 | @param _spender The address which will spend the funds.
64 | @return An uint256 specifying the amount of tokens still available for the spender.
65 | """
66 | return self.allowances[_owner][_spender]
67 |
68 |
69 | @public
70 | def transfer(_to : address, _value : uint256) -> bool:
71 | """
72 | @dev Transfer token for a specified address
73 | @param _to The address to transfer to.
74 | @param _value The amount to be transferred.
75 | """
76 | # NOTE: vyper does not allow underflows
77 | # so the following subtraction would revert on insufficient balance
78 | self.balanceOf[msg.sender] -= _value
79 | self.balanceOf[_to] += _value
80 | log.Transfer(msg.sender, _to, _value)
81 | return True
82 |
83 |
84 | @public
85 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
86 | """
87 | @dev Transfer tokens from one address to another.
88 | Note that while this function emits a Transfer event, this is not required as per the specification,
89 | and other compliant implementations may not emit the event.
90 | @param _from address The address which you want to send tokens from
91 | @param _to address The address which you want to transfer to
92 | @param _value uint256 the amount of tokens to be transferred
93 | """
94 | # NOTE: vyper does not allow underflows
95 | # so the following subtraction would revert on insufficient balance
96 | self.balanceOf[_from] -= _value
97 | self.balanceOf[_to] += _value
98 | if msg.sender != self.minter: # minter is allowed to transfer anything
99 | # NOTE: vyper does not allow underflows
100 | # so the following subtraction would revert on insufficient allowance
101 | self.allowances[_from][msg.sender] -= _value
102 | log.Transfer(_from, _to, _value)
103 | return True
104 |
105 |
106 | @public
107 | def approve(_spender : address, _value : uint256) -> bool:
108 | """
109 | @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
110 | Beware that changing an allowance with this method brings the risk that someone may use both the old
111 | and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
112 | race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
113 | https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
114 | @param _spender The address which will spend the funds.
115 | @param _value The amount of tokens to be spent.
116 | """
117 | assert _value == 0 or self.allowances[msg.sender][_spender] == 0
118 | self.allowances[msg.sender][_spender] = _value
119 | log.Approval(msg.sender, _spender, _value)
120 | return True
121 |
122 |
123 | @public
124 | def mint(_to: address, _value: uint256):
125 | """
126 | @dev Mint an amount of the token and assigns it to an account.
127 | This encapsulates the modification of balances such that the
128 | proper events are emitted.
129 | @param _to The account that will receive the created tokens.
130 | @param _value The amount that will be created.
131 | """
132 | assert msg.sender == self.minter
133 | assert _to != ZERO_ADDRESS
134 | self.total_supply += _value
135 | self.balanceOf[_to] += _value
136 | log.Transfer(ZERO_ADDRESS, _to, _value)
137 |
138 |
139 | @private
140 | def _burn(_to: address, _value: uint256):
141 | """
142 | @dev Internal function that burns an amount of the token of a given
143 | account.
144 | @param _to The account whose tokens will be burned.
145 | @param _value The amount that will be burned.
146 | """
147 | assert _to != ZERO_ADDRESS
148 | self.total_supply -= _value
149 | self.balanceOf[_to] -= _value
150 | log.Transfer(_to, ZERO_ADDRESS, _value)
151 |
152 |
153 | @public
154 | def burn(_value: uint256):
155 | """
156 | @dev Burn an amount of the token of msg.sender.
157 | @param _value The amount that will be burned.
158 | """
159 | assert msg.sender == self.minter, "Only minter is allowed to burn"
160 | self._burn(msg.sender, _value)
161 |
162 |
163 | @public
164 | def burnFrom(_to: address, _value: uint256):
165 | """
166 | @dev Burn an amount of the token from a given account.
167 | @param _to The account whose tokens will be burned.
168 | @param _value The amount that will be burned.
169 | """
170 | assert msg.sender == self.minter, "Only minter is allowed to burn"
171 | self._burn(_to, _value)
172 |
--------------------------------------------------------------------------------
/channelsPool/LPToken.vy:
--------------------------------------------------------------------------------
1 | # @version 0.1.0b16
2 |
3 | # @title Curve LP Token
4 | # @author Curve.Fi
5 | # @notice Used in combination with all pools compiled by vyper 0.1.0-beta.x
6 | # @dev Follows the ERC-20 token standard as defined at
7 | # https://eips.ethereum.org/EIPS/eip-20
8 |
9 | from vyper.interfaces import ERC20
10 |
11 | implements: ERC20
12 |
13 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
14 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
15 |
16 | name: public(string[64])
17 | symbol: public(string[32])
18 | decimals: public(uint256)
19 |
20 | # NOTE: By declaring `balanceOf` as public, vyper automatically generates a 'balanceOf()' getter
21 | # method to allow access to account balances.
22 | # The _KeyType will become a required parameter for the getter and it will return _ValueType.
23 | # See: https://vyper.readthedocs.io/en/v0.1.0-beta.8/types.html?highlight=getter#mappings
24 | balanceOf: public(map(address, uint256))
25 | allowances: map(address, map(address, uint256))
26 | total_supply: uint256
27 | minter: address
28 |
29 |
30 | @public
31 | def __init__(_name: string[64], _symbol: string[32], _decimals: uint256, _supply: uint256):
32 | init_supply: uint256 = _supply * 10 ** _decimals
33 | self.name = _name
34 | self.symbol = _symbol
35 | self.decimals = _decimals
36 | self.balanceOf[msg.sender] = init_supply
37 | self.total_supply = init_supply
38 | self.minter = msg.sender
39 | log.Transfer(ZERO_ADDRESS, msg.sender, init_supply)
40 |
41 |
42 | @public
43 | def set_minter(_minter: address):
44 | assert msg.sender == self.minter
45 | self.minter = _minter
46 |
47 |
48 | @public
49 | @constant
50 | def totalSupply() -> uint256:
51 | """
52 | @dev Total number of tokens in existence.
53 | """
54 | return self.total_supply
55 |
56 |
57 | @public
58 | @constant
59 | def allowance(_owner : address, _spender : address) -> uint256:
60 | """
61 | @dev Function to check the amount of tokens that an owner allowed to a spender.
62 | @param _owner The address which owns the funds.
63 | @param _spender The address which will spend the funds.
64 | @return An uint256 specifying the amount of tokens still available for the spender.
65 | """
66 | return self.allowances[_owner][_spender]
67 |
68 |
69 | @public
70 | def transfer(_to : address, _value : uint256) -> bool:
71 | """
72 | @dev Transfer token for a specified address
73 | @param _to The address to transfer to.
74 | @param _value The amount to be transferred.
75 | """
76 | # NOTE: vyper does not allow underflows
77 | # so the following subtraction would revert on insufficient balance
78 | self.balanceOf[msg.sender] -= _value
79 | self.balanceOf[_to] += _value
80 | log.Transfer(msg.sender, _to, _value)
81 | return True
82 |
83 |
84 | @public
85 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
86 | """
87 | @dev Transfer tokens from one address to another.
88 | Note that while this function emits a Transfer event, this is not required as per the specification,
89 | and other compliant implementations may not emit the event.
90 | @param _from address The address which you want to send tokens from
91 | @param _to address The address which you want to transfer to
92 | @param _value uint256 the amount of tokens to be transferred
93 | """
94 | # NOTE: vyper does not allow underflows
95 | # so the following subtraction would revert on insufficient balance
96 | self.balanceOf[_from] -= _value
97 | self.balanceOf[_to] += _value
98 | if msg.sender != self.minter: # minter is allowed to transfer anything
99 | # NOTE: vyper does not allow underflows
100 | # so the following subtraction would revert on insufficient allowance
101 | self.allowances[_from][msg.sender] -= _value
102 | log.Transfer(_from, _to, _value)
103 | return True
104 |
105 |
106 | @public
107 | def approve(_spender : address, _value : uint256) -> bool:
108 | """
109 | @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
110 | Beware that changing an allowance with this method brings the risk that someone may use both the old
111 | and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
112 | race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
113 | https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
114 | @param _spender The address which will spend the funds.
115 | @param _value The amount of tokens to be spent.
116 | """
117 | assert _value == 0 or self.allowances[msg.sender][_spender] == 0
118 | self.allowances[msg.sender][_spender] = _value
119 | log.Approval(msg.sender, _spender, _value)
120 | return True
121 |
122 |
123 | @public
124 | def mint(_to: address, _value: uint256):
125 | """
126 | @dev Mint an amount of the token and assigns it to an account.
127 | This encapsulates the modification of balances such that the
128 | proper events are emitted.
129 | @param _to The account that will receive the created tokens.
130 | @param _value The amount that will be created.
131 | """
132 | assert msg.sender == self.minter
133 | assert _to != ZERO_ADDRESS
134 | self.total_supply += _value
135 | self.balanceOf[_to] += _value
136 | log.Transfer(ZERO_ADDRESS, _to, _value)
137 |
138 |
139 | @private
140 | def _burn(_to: address, _value: uint256):
141 | """
142 | @dev Internal function that burns an amount of the token of a given
143 | account.
144 | @param _to The account whose tokens will be burned.
145 | @param _value The amount that will be burned.
146 | """
147 | assert _to != ZERO_ADDRESS
148 | self.total_supply -= _value
149 | self.balanceOf[_to] -= _value
150 | log.Transfer(_to, ZERO_ADDRESS, _value)
151 |
152 |
153 | @public
154 | def burn(_value: uint256):
155 | """
156 | @dev Burn an amount of the token of msg.sender.
157 | @param _value The amount that will be burned.
158 | """
159 | assert msg.sender == self.minter, "Only minter is allowed to burn"
160 | self._burn(msg.sender, _value)
161 |
162 |
163 | @public
164 | def burnFrom(_to: address, _value: uint256):
165 | """
166 | @dev Burn an amount of the token from a given account.
167 | @param _to The account whose tokens will be burned.
168 | @param _value The amount that will be burned.
169 | """
170 | assert msg.sender == self.minter, "Only minter is allowed to burn"
171 | self._burn(_to, _value)
172 |
--------------------------------------------------------------------------------
/fildaPool/CurveTokenV1.vy:
--------------------------------------------------------------------------------
1 | # @version 0.1.0b16
2 |
3 | # @title Curve LP Token
4 | # @author Curve.Fi
5 | # @notice Used in combination with all pools compiled by vyper 0.1.0-beta.x
6 | # @dev Follows the ERC-20 token standard as defined at
7 | # https://eips.ethereum.org/EIPS/eip-20
8 |
9 | from vyper.interfaces import ERC20
10 |
11 | implements: ERC20
12 |
13 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
14 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
15 |
16 | name: public(string[64])
17 | symbol: public(string[32])
18 | decimals: public(uint256)
19 |
20 | # NOTE: By declaring `balanceOf` as public, vyper automatically generates a 'balanceOf()' getter
21 | # method to allow access to account balances.
22 | # The _KeyType will become a required parameter for the getter and it will return _ValueType.
23 | # See: https://vyper.readthedocs.io/en/v0.1.0-beta.8/types.html?highlight=getter#mappings
24 | balanceOf: public(map(address, uint256))
25 | allowances: map(address, map(address, uint256))
26 | total_supply: uint256
27 | minter: address
28 |
29 |
30 | @public
31 | def __init__(_name: string[64], _symbol: string[32], _decimals: uint256, _supply: uint256):
32 | init_supply: uint256 = _supply * 10 ** _decimals
33 | self.name = _name
34 | self.symbol = _symbol
35 | self.decimals = _decimals
36 | self.balanceOf[msg.sender] = init_supply
37 | self.total_supply = init_supply
38 | self.minter = msg.sender
39 | log.Transfer(ZERO_ADDRESS, msg.sender, init_supply)
40 |
41 |
42 | @public
43 | def set_minter(_minter: address):
44 | assert msg.sender == self.minter
45 | self.minter = _minter
46 |
47 |
48 | @public
49 | @constant
50 | def totalSupply() -> uint256:
51 | """
52 | @dev Total number of tokens in existence.
53 | """
54 | return self.total_supply
55 |
56 |
57 | @public
58 | @constant
59 | def allowance(_owner : address, _spender : address) -> uint256:
60 | """
61 | @dev Function to check the amount of tokens that an owner allowed to a spender.
62 | @param _owner The address which owns the funds.
63 | @param _spender The address which will spend the funds.
64 | @return An uint256 specifying the amount of tokens still available for the spender.
65 | """
66 | return self.allowances[_owner][_spender]
67 |
68 |
69 | @public
70 | def transfer(_to : address, _value : uint256) -> bool:
71 | """
72 | @dev Transfer token for a specified address
73 | @param _to The address to transfer to.
74 | @param _value The amount to be transferred.
75 | """
76 | # NOTE: vyper does not allow underflows
77 | # so the following subtraction would revert on insufficient balance
78 | self.balanceOf[msg.sender] -= _value
79 | self.balanceOf[_to] += _value
80 | log.Transfer(msg.sender, _to, _value)
81 | return True
82 |
83 |
84 | @public
85 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
86 | """
87 | @dev Transfer tokens from one address to another.
88 | Note that while this function emits a Transfer event, this is not required as per the specification,
89 | and other compliant implementations may not emit the event.
90 | @param _from address The address which you want to send tokens from
91 | @param _to address The address which you want to transfer to
92 | @param _value uint256 the amount of tokens to be transferred
93 | """
94 | # NOTE: vyper does not allow underflows
95 | # so the following subtraction would revert on insufficient balance
96 | self.balanceOf[_from] -= _value
97 | self.balanceOf[_to] += _value
98 | if msg.sender != self.minter: # minter is allowed to transfer anything
99 | # NOTE: vyper does not allow underflows
100 | # so the following subtraction would revert on insufficient allowance
101 | self.allowances[_from][msg.sender] -= _value
102 | log.Transfer(_from, _to, _value)
103 | return True
104 |
105 |
106 | @public
107 | def approve(_spender : address, _value : uint256) -> bool:
108 | """
109 | @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
110 | Beware that changing an allowance with this method brings the risk that someone may use both the old
111 | and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
112 | race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
113 | https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
114 | @param _spender The address which will spend the funds.
115 | @param _value The amount of tokens to be spent.
116 | """
117 | assert _value == 0 or self.allowances[msg.sender][_spender] == 0
118 | self.allowances[msg.sender][_spender] = _value
119 | log.Approval(msg.sender, _spender, _value)
120 | return True
121 |
122 |
123 | @public
124 | def mint(_to: address, _value: uint256):
125 | """
126 | @dev Mint an amount of the token and assigns it to an account.
127 | This encapsulates the modification of balances such that the
128 | proper events are emitted.
129 | @param _to The account that will receive the created tokens.
130 | @param _value The amount that will be created.
131 | """
132 | assert msg.sender == self.minter
133 | assert _to != ZERO_ADDRESS
134 | self.total_supply += _value
135 | self.balanceOf[_to] += _value
136 | log.Transfer(ZERO_ADDRESS, _to, _value)
137 |
138 |
139 | @private
140 | def _burn(_to: address, _value: uint256):
141 | """
142 | @dev Internal function that burns an amount of the token of a given
143 | account.
144 | @param _to The account whose tokens will be burned.
145 | @param _value The amount that will be burned.
146 | """
147 | assert _to != ZERO_ADDRESS
148 | self.total_supply -= _value
149 | self.balanceOf[_to] -= _value
150 | log.Transfer(_to, ZERO_ADDRESS, _value)
151 |
152 |
153 | @public
154 | def burn(_value: uint256):
155 | """
156 | @dev Burn an amount of the token of msg.sender.
157 | @param _value The amount that will be burned.
158 | """
159 | assert msg.sender == self.minter, "Only minter is allowed to burn"
160 | self._burn(msg.sender, _value)
161 |
162 |
163 | @public
164 | def burnFrom(_to: address, _value: uint256):
165 | """
166 | @dev Burn an amount of the token from a given account.
167 | @param _to The account whose tokens will be burned.
168 | @param _value The amount that will be burned.
169 | """
170 | assert msg.sender == self.minter, "Only minter is allowed to burn"
171 | self._burn(_to, _value)
172 |
--------------------------------------------------------------------------------
/lendhubPool/CurveTokenV1.vy:
--------------------------------------------------------------------------------
1 | # @version 0.1.0b16
2 |
3 | # @title Curve LP Token
4 | # @author Curve.Fi
5 | # @notice Used in combination with all pools compiled by vyper 0.1.0-beta.x
6 | # @dev Follows the ERC-20 token standard as defined at
7 | # https://eips.ethereum.org/EIPS/eip-20
8 |
9 | from vyper.interfaces import ERC20
10 |
11 | implements: ERC20
12 |
13 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
14 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
15 |
16 | name: public(string[64])
17 | symbol: public(string[32])
18 | decimals: public(uint256)
19 |
20 | # NOTE: By declaring `balanceOf` as public, vyper automatically generates a 'balanceOf()' getter
21 | # method to allow access to account balances.
22 | # The _KeyType will become a required parameter for the getter and it will return _ValueType.
23 | # See: https://vyper.readthedocs.io/en/v0.1.0-beta.8/types.html?highlight=getter#mappings
24 | balanceOf: public(map(address, uint256))
25 | allowances: map(address, map(address, uint256))
26 | total_supply: uint256
27 | minter: address
28 |
29 |
30 | @public
31 | def __init__(_name: string[64], _symbol: string[32], _decimals: uint256, _supply: uint256):
32 | init_supply: uint256 = _supply * 10 ** _decimals
33 | self.name = _name
34 | self.symbol = _symbol
35 | self.decimals = _decimals
36 | self.balanceOf[msg.sender] = init_supply
37 | self.total_supply = init_supply
38 | self.minter = msg.sender
39 | log.Transfer(ZERO_ADDRESS, msg.sender, init_supply)
40 |
41 |
42 | @public
43 | def set_minter(_minter: address):
44 | assert msg.sender == self.minter
45 | self.minter = _minter
46 |
47 |
48 | @public
49 | @constant
50 | def totalSupply() -> uint256:
51 | """
52 | @dev Total number of tokens in existence.
53 | """
54 | return self.total_supply
55 |
56 |
57 | @public
58 | @constant
59 | def allowance(_owner : address, _spender : address) -> uint256:
60 | """
61 | @dev Function to check the amount of tokens that an owner allowed to a spender.
62 | @param _owner The address which owns the funds.
63 | @param _spender The address which will spend the funds.
64 | @return An uint256 specifying the amount of tokens still available for the spender.
65 | """
66 | return self.allowances[_owner][_spender]
67 |
68 |
69 | @public
70 | def transfer(_to : address, _value : uint256) -> bool:
71 | """
72 | @dev Transfer token for a specified address
73 | @param _to The address to transfer to.
74 | @param _value The amount to be transferred.
75 | """
76 | # NOTE: vyper does not allow underflows
77 | # so the following subtraction would revert on insufficient balance
78 | self.balanceOf[msg.sender] -= _value
79 | self.balanceOf[_to] += _value
80 | log.Transfer(msg.sender, _to, _value)
81 | return True
82 |
83 |
84 | @public
85 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
86 | """
87 | @dev Transfer tokens from one address to another.
88 | Note that while this function emits a Transfer event, this is not required as per the specification,
89 | and other compliant implementations may not emit the event.
90 | @param _from address The address which you want to send tokens from
91 | @param _to address The address which you want to transfer to
92 | @param _value uint256 the amount of tokens to be transferred
93 | """
94 | # NOTE: vyper does not allow underflows
95 | # so the following subtraction would revert on insufficient balance
96 | self.balanceOf[_from] -= _value
97 | self.balanceOf[_to] += _value
98 | if msg.sender != self.minter: # minter is allowed to transfer anything
99 | # NOTE: vyper does not allow underflows
100 | # so the following subtraction would revert on insufficient allowance
101 | self.allowances[_from][msg.sender] -= _value
102 | log.Transfer(_from, _to, _value)
103 | return True
104 |
105 |
106 | @public
107 | def approve(_spender : address, _value : uint256) -> bool:
108 | """
109 | @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
110 | Beware that changing an allowance with this method brings the risk that someone may use both the old
111 | and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
112 | race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
113 | https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
114 | @param _spender The address which will spend the funds.
115 | @param _value The amount of tokens to be spent.
116 | """
117 | assert _value == 0 or self.allowances[msg.sender][_spender] == 0
118 | self.allowances[msg.sender][_spender] = _value
119 | log.Approval(msg.sender, _spender, _value)
120 | return True
121 |
122 |
123 | @public
124 | def mint(_to: address, _value: uint256):
125 | """
126 | @dev Mint an amount of the token and assigns it to an account.
127 | This encapsulates the modification of balances such that the
128 | proper events are emitted.
129 | @param _to The account that will receive the created tokens.
130 | @param _value The amount that will be created.
131 | """
132 | assert msg.sender == self.minter
133 | assert _to != ZERO_ADDRESS
134 | self.total_supply += _value
135 | self.balanceOf[_to] += _value
136 | log.Transfer(ZERO_ADDRESS, _to, _value)
137 |
138 |
139 | @private
140 | def _burn(_to: address, _value: uint256):
141 | """
142 | @dev Internal function that burns an amount of the token of a given
143 | account.
144 | @param _to The account whose tokens will be burned.
145 | @param _value The amount that will be burned.
146 | """
147 | assert _to != ZERO_ADDRESS
148 | self.total_supply -= _value
149 | self.balanceOf[_to] -= _value
150 | log.Transfer(_to, ZERO_ADDRESS, _value)
151 |
152 |
153 | @public
154 | def burn(_value: uint256):
155 | """
156 | @dev Burn an amount of the token of msg.sender.
157 | @param _value The amount that will be burned.
158 | """
159 | assert msg.sender == self.minter, "Only minter is allowed to burn"
160 | self._burn(msg.sender, _value)
161 |
162 |
163 | @public
164 | def burnFrom(_to: address, _value: uint256):
165 | """
166 | @dev Burn an amount of the token from a given account.
167 | @param _to The account whose tokens will be burned.
168 | @param _value The amount that will be burned.
169 | """
170 | assert msg.sender == self.minter, "Only minter is allowed to burn"
171 | self._burn(_to, _value)
172 |
--------------------------------------------------------------------------------
/lendhub-eth-beth/CurveTokenV1.vy:
--------------------------------------------------------------------------------
1 | # @version 0.1.0b16
2 |
3 | # @title Curve LP Token
4 | # @author Curve.Fi
5 | # @notice Used in combination with all pools compiled by vyper 0.1.0-beta.x
6 | # @dev Follows the ERC-20 token standard as defined at
7 | # https://eips.ethereum.org/EIPS/eip-20
8 |
9 | from vyper.interfaces import ERC20
10 |
11 | implements: ERC20
12 |
13 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
14 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
15 |
16 | name: public(string[64])
17 | symbol: public(string[32])
18 | decimals: public(uint256)
19 |
20 | # NOTE: By declaring `balanceOf` as public, vyper automatically generates a 'balanceOf()' getter
21 | # method to allow access to account balances.
22 | # The _KeyType will become a required parameter for the getter and it will return _ValueType.
23 | # See: https://vyper.readthedocs.io/en/v0.1.0-beta.8/types.html?highlight=getter#mappings
24 | balanceOf: public(map(address, uint256))
25 | allowances: map(address, map(address, uint256))
26 | total_supply: uint256
27 | minter: address
28 |
29 |
30 | @public
31 | def __init__(_name: string[64], _symbol: string[32], _decimals: uint256, _supply: uint256):
32 | init_supply: uint256 = _supply * 10 ** _decimals
33 | self.name = _name
34 | self.symbol = _symbol
35 | self.decimals = _decimals
36 | self.balanceOf[msg.sender] = init_supply
37 | self.total_supply = init_supply
38 | self.minter = msg.sender
39 | log.Transfer(ZERO_ADDRESS, msg.sender, init_supply)
40 |
41 |
42 | @public
43 | def set_minter(_minter: address):
44 | assert msg.sender == self.minter
45 | self.minter = _minter
46 |
47 |
48 | @public
49 | @constant
50 | def totalSupply() -> uint256:
51 | """
52 | @dev Total number of tokens in existence.
53 | """
54 | return self.total_supply
55 |
56 |
57 | @public
58 | @constant
59 | def allowance(_owner : address, _spender : address) -> uint256:
60 | """
61 | @dev Function to check the amount of tokens that an owner allowed to a spender.
62 | @param _owner The address which owns the funds.
63 | @param _spender The address which will spend the funds.
64 | @return An uint256 specifying the amount of tokens still available for the spender.
65 | """
66 | return self.allowances[_owner][_spender]
67 |
68 |
69 | @public
70 | def transfer(_to : address, _value : uint256) -> bool:
71 | """
72 | @dev Transfer token for a specified address
73 | @param _to The address to transfer to.
74 | @param _value The amount to be transferred.
75 | """
76 | # NOTE: vyper does not allow underflows
77 | # so the following subtraction would revert on insufficient balance
78 | self.balanceOf[msg.sender] -= _value
79 | self.balanceOf[_to] += _value
80 | log.Transfer(msg.sender, _to, _value)
81 | return True
82 |
83 |
84 | @public
85 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
86 | """
87 | @dev Transfer tokens from one address to another.
88 | Note that while this function emits a Transfer event, this is not required as per the specification,
89 | and other compliant implementations may not emit the event.
90 | @param _from address The address which you want to send tokens from
91 | @param _to address The address which you want to transfer to
92 | @param _value uint256 the amount of tokens to be transferred
93 | """
94 | # NOTE: vyper does not allow underflows
95 | # so the following subtraction would revert on insufficient balance
96 | self.balanceOf[_from] -= _value
97 | self.balanceOf[_to] += _value
98 | if msg.sender != self.minter: # minter is allowed to transfer anything
99 | # NOTE: vyper does not allow underflows
100 | # so the following subtraction would revert on insufficient allowance
101 | self.allowances[_from][msg.sender] -= _value
102 | log.Transfer(_from, _to, _value)
103 | return True
104 |
105 |
106 | @public
107 | def approve(_spender : address, _value : uint256) -> bool:
108 | """
109 | @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
110 | Beware that changing an allowance with this method brings the risk that someone may use both the old
111 | and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
112 | race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
113 | https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
114 | @param _spender The address which will spend the funds.
115 | @param _value The amount of tokens to be spent.
116 | """
117 | assert _value == 0 or self.allowances[msg.sender][_spender] == 0
118 | self.allowances[msg.sender][_spender] = _value
119 | log.Approval(msg.sender, _spender, _value)
120 | return True
121 |
122 |
123 | @public
124 | def mint(_to: address, _value: uint256):
125 | """
126 | @dev Mint an amount of the token and assigns it to an account.
127 | This encapsulates the modification of balances such that the
128 | proper events are emitted.
129 | @param _to The account that will receive the created tokens.
130 | @param _value The amount that will be created.
131 | """
132 | assert msg.sender == self.minter
133 | assert _to != ZERO_ADDRESS
134 | self.total_supply += _value
135 | self.balanceOf[_to] += _value
136 | log.Transfer(ZERO_ADDRESS, _to, _value)
137 |
138 |
139 | @private
140 | def _burn(_to: address, _value: uint256):
141 | """
142 | @dev Internal function that burns an amount of the token of a given
143 | account.
144 | @param _to The account whose tokens will be burned.
145 | @param _value The amount that will be burned.
146 | """
147 | assert _to != ZERO_ADDRESS
148 | self.total_supply -= _value
149 | self.balanceOf[_to] -= _value
150 | log.Transfer(_to, ZERO_ADDRESS, _value)
151 |
152 |
153 | @public
154 | def burn(_value: uint256):
155 | """
156 | @dev Burn an amount of the token of msg.sender.
157 | @param _value The amount that will be burned.
158 | """
159 | assert msg.sender == self.minter, "Only minter is allowed to burn"
160 | self._burn(msg.sender, _value)
161 |
162 |
163 | @public
164 | def burnFrom(_to: address, _value: uint256):
165 | """
166 | @dev Burn an amount of the token from a given account.
167 | @param _to The account whose tokens will be burned.
168 | @param _value The amount that will be burned.
169 | """
170 | assert msg.sender == self.minter, "Only minter is allowed to burn"
171 | self._burn(_to, _value)
172 |
--------------------------------------------------------------------------------
/lendhubPool/handLHB.sol:
--------------------------------------------------------------------------------
1 | pragma solidity 0.6.12;
2 |
3 |
4 | library SafeMath {
5 |
6 | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
7 | if (a == 0)
8 | return 0;
9 | uint256 c = a * b;
10 | require(c / a == b);
11 | return c;
12 | }
13 |
14 | function div(uint256 a, uint256 b) internal pure returns (uint256) {
15 | require(b > 0);
16 | uint256 c = a / b;
17 | return c;
18 | }
19 |
20 | function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
21 | require(b > 0);
22 | uint256 c = a / b;
23 | if(a % b != 0)
24 | c = c + 1;
25 | return c;
26 | }
27 |
28 | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
29 | require(b <= a);
30 | uint256 c = a - b;
31 | return c;
32 | }
33 |
34 | function add(uint256 a, uint256 b) internal pure returns (uint256) {
35 | uint256 c = a + b;
36 | require(c >= a);
37 | return c;
38 | }
39 |
40 | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
41 | require(b != 0);
42 | return a % b;
43 | }
44 |
45 | int256 constant private INT256_MIN = -2^255;
46 |
47 | function mul(int256 a, int256 b) internal pure returns (int256) {
48 | if (a == 0)
49 | return 0;
50 | int256 c = a * b;
51 | require(c / a == b && (a != -1 || b != INT256_MIN));
52 | return c;
53 | }
54 |
55 | function div(int256 a, int256 b) internal pure returns (int256) {
56 | require(b != 0 && (b != -1 || a != INT256_MIN));
57 | int256 c = a / b;
58 | return c;
59 | }
60 |
61 | function sub(int256 a, int256 b) internal pure returns (int256) {
62 | int256 c = a - b;
63 | require((b >= 0 && c <= a) || (b < 0 && c > a));
64 | return c;
65 | }
66 |
67 | function add(int256 a, int256 b) internal pure returns (int256) {
68 | int256 c = a + b;
69 | require((b >= 0 && c >= a) || (b < 0 && c < a));
70 | return c;
71 | }
72 |
73 | function sqrt(int256 x) internal pure returns (int256) {
74 | int256 z = add(x / 2, 1);
75 | int256 y = x;
76 | while (z < y)
77 | {
78 | y = z;
79 | z = ((add((x / z), z)) / 2);
80 | }
81 | return y;
82 | }
83 | }
84 |
85 | interface ERC20 {
86 | using SafeMath for uint256;
87 |
88 | function totalSupply() external view returns (uint256);
89 |
90 | function balanceOf(address owner) external view returns (uint256);
91 |
92 | function allowance(address owner, address spender) external view returns (uint256);
93 |
94 | function transfer(address to, uint256 value) external returns (bool);
95 |
96 | function approve(address spender, uint256 value) external returns (bool);
97 |
98 | function transferFrom(address from, address to, uint256 value) external returns (bool);
99 |
100 | }
101 |
102 | interface CERC20 is ERC20 {
103 | function mint(uint256) external returns (uint256);
104 | }
105 |
106 | interface ClaimComp is ERC20 {
107 | function claimComp(address holder, address[] memory cTokens) external;
108 | }
109 |
110 | interface MDexRouter {
111 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
112 | }
113 |
114 | contract HandleLendPlatformToken{
115 |
116 | address internal _mainContractAddress;
117 |
118 | MDexRouter constant mdex = MDexRouter(0xED7d5F38C79115ca12fe6C0041abb22F0A06C300);
119 | ERC20 constant lhb = ERC20(0x8F67854497218043E1f72908FFE38D0Ed7F24721);
120 | ERC20 constant husd = ERC20(0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047);
121 | ERC20 constant usdt = ERC20(0xa71EdC38d189767582C38A3145b5873052c3e47a);
122 | ERC20 constant wht = ERC20(0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F);
123 | CERC20 constant lhusd = CERC20(0x1C478D5d1823D51c4c4b196652912A89D9b46c30);
124 | CERC20 constant lusdt = CERC20(0xc502F3f6f1b71CB7d856E70B574D27d942C2993C);
125 | ClaimComp constant claimLHBContract = ClaimComp(0x6537d6307ca40231939985BCF7D83096Dd1B4C09);
126 |
127 | constructor(address mainContractAddress) public {
128 | _mainContractAddress = mainContractAddress;
129 | }
130 |
131 | function claim_lending_platform_token() external {
132 | assert(msg.sender == _mainContractAddress);
133 | // This method calim LHB token for main contract.
134 | // Since this contract is replaceable, we can rewrite this method if we have to.
135 | address[] memory cTokens = new address[](2);
136 | cTokens[0] = 0x1C478D5d1823D51c4c4b196652912A89D9b46c30; // Add lHUSD
137 | cTokens[1] = 0xc502F3f6f1b71CB7d856E70B574D27d942C2993C; // Add lUSDT
138 | claimLHBContract.claimComp(msg.sender, cTokens);
139 | }
140 |
141 | function sell_lending_platform_token(bool is_HUSD, uint256 lhbAmount) external returns (uint256){
142 | assert(msg.sender == _mainContractAddress);
143 | require(lhb.transferFrom(msg.sender, address(this), lhbAmount));
144 | address[] memory path;
145 | if (is_HUSD) {
146 | path = new address[](2);
147 | path[0] = address(lhb);
148 | path[1] = address(husd);
149 | } else{
150 | path = new address[](3);
151 | path[0] = address(lhb);
152 | path[1] = address(wht);
153 | path[2] = address(usdt);
154 | }
155 | lhb.approve(address(mdex), lhbAmount);
156 | // Try to swap LHB for lHUSD or lUSDT. This action may fail beacuse lack of liqudility.
157 | try mdex.swapExactTokensForTokens(lhbAmount, 0, path, address(this), now) returns (uint256[] memory amounts) {
158 | if (is_HUSD) {
159 | if(amounts[1] == 0)
160 | return 0;
161 | husd.approve(address(lhusd),amounts[1]);
162 | lhusd.mint(amounts[1]);
163 | uint256 balance = lhusd.balanceOf(address(this));
164 | lhusd.approve(msg.sender, balance);
165 | return balance;
166 | } else{
167 | if(amounts[2] == 0)
168 | return 0;
169 | usdt.approve(address(lusdt),amounts[2]);
170 | lusdt.mint(amounts[2]);
171 | uint256 balance = lusdt.balanceOf(address(this));
172 | lusdt.approve(msg.sender, balance);
173 | return balance;
174 | }
175 | } catch (bytes memory) {
176 | // swap failed, return token back to main contract
177 | lhb.transfer(msg.sender, lhbAmount);
178 | return 0;
179 | }
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/depth.vault/dPilotVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./interfaces/IVault.sol";
9 | /**depth.fi vault***/
10 | contract dPilotVault is ERC20,Ownable,Pausable {
11 | using SafeERC20 for IERC20;
12 | using SafeMath for uint256;
13 |
14 | address public want;
15 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
16 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //DEP DAO ADDRESS
17 | address public husdSwapAddress;
18 | address public pilotAddress =0xD42Ef222d33E3cB771DdA783f48885e15c9D5CeD;
19 | address public pTokenAddress;
20 | uint256 public balance;//total token balance
21 | uint256 public minClaim=1;//min interest to claim
22 | uint256 public maxLimit;// max balance limit
23 | constructor (address _want,address _husdSwapAddress) ERC20(
24 | string(abi.encodePacked("Depth.Fi Vault p", ERC20(_want).symbol())),
25 | string(abi.encodePacked("dp", ERC20(_want).symbol()))
26 | ) {
27 |
28 | require(_want != address(0), "INVALID TOKEN ADDRESS");
29 | want = _want;
30 | (,
31 | address _pTokenAddr,
32 | ,
33 | ,
34 | ,
35 | ,
36 | ,
37 | ,
38 | ,
39 | ) = IPilot(pilotAddress).banks(_want);
40 | pTokenAddress = _pTokenAddr;
41 | husdSwapAddress = _husdSwapAddress;
42 |
43 | }
44 | // set min claim interest
45 | function setMinClaim(uint256 _min) external onlyOwner{
46 | minClaim = _min;
47 | }
48 | // set max deposit limit
49 | function setMaxLimit(uint256 _max) external onlyOwner{
50 | maxLimit = _max;
51 | }
52 | // set husd swap contract address
53 | function setHusdSwapAddress(address _address) external onlyOwner{
54 | require(_address!=address(0),"no address!");
55 | husdSwapAddress = _address;
56 | }
57 |
58 | // set dao contract address
59 | function setDaoAddress(address _address) external onlyOwner{
60 | require(_address!=address(0),"no address!");
61 | daoAddress = _address;
62 | }
63 |
64 | function swapTokensToHusd(address _token) internal{
65 | require(husdSwapAddress!=address(0),"not set husd swap address!");
66 | uint256 _amount = IERC20(_token).balanceOf(address(this));
67 | if (_amount==0){
68 | return;
69 | }
70 | IERC20(_token).safeApprove(husdSwapAddress,_amount);
71 | IHusdSwap(husdSwapAddress).swapTokensToHusd(_token,_amount);
72 | }
73 | function getPTokenAmount(uint256 _amount) public view returns(uint256){
74 | uint256 total =IPilot(pilotAddress).totalToken(want);
75 | uint256 pTotal = IERC20(pTokenAddress).totalSupply();
76 | uint256 pAmount = (total == 0 || pTotal == 0) ? _amount: _amount.mul(pTotal).div(total);
77 | return pAmount;
78 | }
79 | function harvest() public{
80 | //claim interest
81 | uint256 _selfUnderlying = getSelfUnderlying();
82 | (,
83 | ,
84 | ,
85 | ,
86 | ,
87 | uint256 _compUnderlyingBalance,
88 | ,
89 | ,
90 | ,
91 | ) = IPilot(pilotAddress).banks(want);
92 |
93 | uint256 _interest = _selfUnderlying.sub(balance);
94 | if (_interest>=minClaim){
95 | uint256 _claimAmount = _interest<_compUnderlyingBalance?_interest:_compUnderlyingBalance;
96 | uint256 pAmount = getPTokenAmount(_claimAmount);
97 | uint256 _before = IERC20(want).balanceOf(address(this));
98 | //IERC20(pTokenAddress).safeApprove(pilotAddress, pAmount);
99 | IPilot(pilotAddress).withdraw(want,pAmount);
100 | uint256 _after = IERC20(want).balanceOf(address(this));
101 |
102 | require(_after.sub(_before)>_claimAmount,"sub flow!");
103 |
104 | swapTokensToHusd(want);
105 | }
106 |
107 | //donate husd to dao
108 | uint256 _husdBalance = IERC20(husd).balanceOf(address(this));
109 | IERC20(husd).safeApprove(daoAddress,_husdBalance);
110 | //call dao address donate husd
111 | IDao(daoAddress).donateHUSD(_husdBalance);
112 |
113 |
114 | }
115 | //get underlying amount in compound pool
116 | function getSelfUnderlying() public view returns (uint256) {
117 | uint256 pAmount = IERC20(pTokenAddress).balanceOf(address(this));
118 | uint256 amount = pAmount.mul(IPilot(pilotAddress).totalToken(want)).div(IERC20(pTokenAddress).totalSupply());
119 |
120 | return amount;
121 | }
122 |
123 | //deposit
124 | function deposit(uint256 _amount) external whenNotPaused {
125 | require(_amount>0,"invalid amount");
126 |
127 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
128 | //deposit token to compound
129 | IERC20(want).safeApprove(pilotAddress, _amount);
130 | IPilot(pilotAddress).deposit(want,_amount);
131 | balance=balance.add(_amount);
132 | _mint(msg.sender, _amount);
133 | }
134 | //withdraw
135 | function withdraw(uint256 _amount) external {
136 | require(_amount>0,"invalid amount");
137 | _burn(msg.sender, _amount);
138 | uint256 pAmount = getPTokenAmount(_amount);
139 | require(pAmount>0,"invalid pAmount");
140 | uint256 _before = IERC20(want).balanceOf(address(this));
141 | //IERC20(pTokenAddress).safeIncreaseAllowance(pilotAddress, pAmount);
142 | IPilot(pilotAddress).withdraw(want,pAmount);
143 | uint256 _after = IERC20(want).balanceOf(address(this));
144 |
145 | require(_after.sub(_before)>_amount,"sub flow!");
146 |
147 | IERC20(want).safeTransfer(msg.sender, _amount);
148 | balance=balance.sub(_amount);
149 |
150 | }
151 | //claim exchange token like mdx to owner.
152 | function claimExchangeMiningToken(address _swapAddress,address _miningToken) external onlyOwner{
153 | require(_swapAddress!=address(0),"invalid swap address");
154 | require(_miningToken!=address(0),"invalid mining token address");
155 | require(_miningToken!=pTokenAddress,"can not claim ptoken");
156 | ISwapMining(_swapAddress).takerWithdraw();
157 | IERC20(_miningToken).safeTransfer(msg.sender,IERC20(_miningToken).balanceOf(address(this)));
158 |
159 | }
160 |
161 | function pause() external onlyOwner {
162 | _pause();
163 | }
164 | function decimals() public view override returns (uint8) {
165 | return ERC20(want).decimals();
166 | }
167 |
168 |
169 | function unpause() external onlyOwner {
170 | _unpause();
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/depth.vault/dCompVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./interfaces/IVault.sol";
9 | /**depth.fi vault***/
10 | contract dCompVault is ERC20,Ownable,Pausable {
11 | using SafeERC20 for IERC20;
12 | using SafeMath for uint256;
13 |
14 | address public want;
15 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
16 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //DEP DAO ADDRESS
17 | //address public usdtSwapAddress=0x07c8689FfC95caf92DA7Cc2A55bCbE7dAFCf0A47; //DEP swap usdt to husd
18 | address public husdSwapAddress;//swap compound token to husd
19 | uint256 public maxLimit;// max balance limit
20 | address public cTokenAddress;
21 | uint256 public balance;//total token balance
22 | uint256 public minClaim=1;//min interest to claim default 1
23 | constructor (address _cTokenAddress,address _husdSwapAddress) ERC20(
24 | string(abi.encodePacked("Depth.Fi Vault ", ERC20(_cTokenAddress).symbol())),
25 | string(abi.encodePacked("d", ERC20(_cTokenAddress).symbol()))
26 | ) {
27 |
28 | require(_cTokenAddress != address(0), "INVALID CTOKEN ADDRESS");
29 | want = CToken(_cTokenAddress).underlying();
30 | cTokenAddress=_cTokenAddress;
31 | husdSwapAddress = _husdSwapAddress;
32 |
33 | }
34 | // set min claim interest
35 | function setMinClaim(uint256 _min) external onlyOwner{
36 | minClaim = _min;
37 | }
38 |
39 | // set husd swap contract address
40 | function setHusdSwapAddress(address _address) external onlyOwner{
41 | husdSwapAddress = _address;
42 | }
43 |
44 | // set dao contract address
45 | function setDaoAddress(address _address) external onlyOwner{
46 | daoAddress = _address;
47 | }
48 |
49 | // set max deposit limit
50 | function setMaxLimit(uint256 _max) external onlyOwner{
51 | maxLimit = _max;
52 | }
53 |
54 | function swapTokensToHusd(address _token) internal{
55 | require(husdSwapAddress!=address(0),"not set husd swap address!");
56 | uint256 _amount = IERC20(_token).balanceOf(address(this));
57 | if (_amount==0){
58 | return;
59 | }
60 | IERC20(_token).safeApprove(husdSwapAddress,_amount);
61 | IHusdSwap(husdSwapAddress).swapTokensToHusd(_token,_amount);
62 | }
63 |
64 | function isCan() internal view returns(bool){
65 | if (cTokenAddress==0x9a57eAB16d371048c56cbE0c4D608096aEC5b405||cTokenAddress==0x3dA74C09ccb8faBa3153b7f6189dDA9d7F28156A){
66 | return true;
67 | }else{
68 | return false;
69 | }
70 | }
71 |
72 | function harvest() public{
73 | harvest(true);
74 | }
75 |
76 | function harvest(bool claimCompToken) public{
77 | //claim interest
78 | uint256 _selfUnderlying = getSelfUnderlying();
79 | uint256 _compUnderlyingBalance = IERC20(want).balanceOf(cTokenAddress);
80 | uint256 _interest = _selfUnderlying.sub(balance);
81 | if (_interest>=minClaim){
82 | uint256 _claimAmount = _interest<_compUnderlyingBalance?_interest:_compUnderlyingBalance;
83 | require(CToken(cTokenAddress).redeemUnderlying(_claimAmount) == 0, "!redeem");
84 | if (want!=husd){
85 | swapTokensToHusd(want);
86 | }
87 | }
88 | if (claimCompToken){
89 | //claim mining token
90 | address[] memory markets = new address[](1);
91 | markets[0] = cTokenAddress;
92 | address _compControlAddress = CToken(cTokenAddress).comptroller();
93 | address _compTokenAddress;
94 | if (isCan()){
95 | CompControl(_compControlAddress).claimCan(address(this), markets);
96 | _compTokenAddress = CompControl(_compControlAddress).getCanAddress();
97 | }else{
98 | CompControl(_compControlAddress).claimComp(address(this), markets);
99 | _compTokenAddress = CompControl(_compControlAddress).getCompAddress();
100 | }
101 |
102 | swapTokensToHusd(_compTokenAddress);
103 | }
104 | //donate husd to dao
105 | uint256 _husdBalance = IERC20(husd).balanceOf(address(this));
106 | if (_husdBalance>0){
107 | IERC20(husd).approve(daoAddress,_husdBalance);
108 | //call dao address donate husd
109 | IDao(daoAddress).donateHUSD(_husdBalance);
110 | }
111 |
112 |
113 | }
114 | //get underlying amount in compound pool
115 | function getSelfUnderlying() public view returns (uint256) {
116 | (, uint256 cTokenBal, , uint256 exchangeRate) =
117 | CToken(cTokenAddress).getAccountSnapshot(address(this));
118 |
119 | return cTokenBal.mul(exchangeRate).div(1e18);
120 | }
121 |
122 | //deposit
123 | function deposit(uint256 _amount) external whenNotPaused {
124 | require(_amount>0,"invalid amount");
125 | require(maxLimit==0||balance.add(_amount)<=maxLimit,"exceed max deposit limit");
126 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
127 | //deposit token to compound
128 | IERC20(want).safeApprove(cTokenAddress, _amount);
129 | require(CToken(cTokenAddress).mint(_amount) == 0, "!deposit");
130 | balance=balance.add(_amount);
131 | _mint(msg.sender, _amount);
132 | }
133 | //withdraw
134 | function withdraw(uint256 _amount) external {
135 | require(_amount>0,"invalid amount");
136 | _burn(msg.sender, _amount);
137 |
138 | //uint256 _before = IERC20(want).balanceOf(address(this));
139 | //redeemUnderlying
140 |
141 | require(CToken(cTokenAddress).redeemUnderlying(_amount) == 0, "!withdraw");
142 | IERC20(want).safeTransfer(msg.sender, _amount);
143 | balance=balance.sub(_amount);
144 |
145 | }
146 | //claim exchange token like mdx to owner.
147 | function claimExchangeMiningToken(address _swapAddress,address _miningToken) external onlyOwner{
148 | require(_swapAddress!=address(0),"invalid swap address");
149 | require(_miningToken!=address(0),"invalid mining token address");
150 | ISwapMining(_swapAddress).takerWithdraw();
151 | require(_miningToken!=cTokenAddress,"can not claim ctoken");
152 | IERC20(_miningToken).safeTransfer(msg.sender,IERC20(_miningToken).balanceOf(address(this)));
153 |
154 | }
155 |
156 | function pause() external onlyOwner {
157 | _pause();
158 | }
159 |
160 |
161 | function unpause() external onlyOwner {
162 | _unpause();
163 | }
164 | function decimals() public view override returns (uint8) {
165 | return ERC20(want).decimals();
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/husdSwap.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 | interface depthRouter {
7 | function exchange_underlying(int128, int128, uint256, uint256) external;
8 | function get_dy_underlying( int128, int128, uint256) external view returns(uint256);
9 | }
10 | interface uniRouter {
11 | function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory);
12 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
13 | }
14 | interface ISwapMining{
15 | function takerWithdraw() external;
16 | }
17 | /**depth.fi vault***/
18 | contract husdSwap is Ownable {
19 | using SafeERC20 for IERC20;
20 | using SafeMath for uint256;
21 |
22 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
23 | address public usdt =0xa71EdC38d189767582C38A3145b5873052c3e47a;
24 | address public wht = 0x5545153CCFcA01fbd7Dd11C0b23ba694D9509A6F;
25 | address public depth=0x1D1cF3b43bC54B7D8e0F763B6b8957F480367834;//depth swap address .convert usdt to husd
26 | address public mdex=0xED7d5F38C79115ca12fe6C0041abb22F0A06C300;//other token swap.default is mdex swap
27 | mapping(string=>address) public dexs;
28 | uint256 public dexLength;
29 | mapping(uint256=>string) public dexIndex;
30 | mapping(string=>mapping(address=>address[][])) public paths;
31 |
32 | constructor () public {
33 |
34 | }
35 | function addPaths(string memory _dex,address _token,address[][] memory _paths) external onlyOwner{
36 | paths[_dex][_token]=_paths;
37 | }
38 | function deletePaths(string memory _dex,address _token) external onlyOwner{
39 | delete paths[_dex][_token];
40 | }
41 | function getPaths(string memory _dex,address _token) public view returns(address[][] memory){
42 |
43 | return paths[_dex][_token];
44 | }
45 | function getUniAmountOut(string memory _dex,uint _amountIn, address[] memory _path) public view returns(uint256){
46 | try uniRouter(dexs[_dex]).getAmountsOut(_amountIn, _path) returns(uint256[] memory _amount){
47 | return _amount[_path.length-1];
48 | }catch{
49 | return 0;
50 | }
51 | }
52 | function setUniSwapAddress(string memory _dexName,address _address) external onlyOwner{
53 | if (dexs[_dexName]==address(0)){
54 | dexIndex[dexLength] = _dexName;
55 | dexLength+=1;
56 | }
57 | dexs[_dexName] = _address;
58 |
59 | }
60 | function getDefaultPaths(address _token) public view returns(address[][] memory){
61 | address[][] memory _paths = new address[][](4);
62 | _paths[0] = new address[](2);
63 | _paths[0][0] = _token;
64 | _paths[0][1] = husd;
65 | _paths[1] = new address[](2);
66 | _paths[1][0] = _token;
67 | _paths[1][1] = usdt;
68 | _paths[2] = new address[](3);
69 | _paths[2][0] = _token;
70 | _paths[2][1] = wht;
71 | _paths[2][2] = husd;
72 | _paths[3] = new address[](3);
73 | _paths[3][0] = _token;
74 | _paths[3][1] = wht;
75 | _paths[3][2] = usdt;
76 | return _paths;
77 | }
78 | function getBestSellPath(address _token,uint256 _amount) public view returns(address dex,uint256 bestAmount,address[] memory sellPath){
79 | bestAmount = 0;
80 | for(uint256 i=0;ihusd token->usdt token->wht->husd token->wht->usdt
86 | _paths = getDefaultPaths(_token);
87 | }
88 | if (_paths.length==0){
89 | continue;
90 | }
91 | for(uint256 j=0;j<_paths.length;j++){
92 | //only support sell to usdt or husd
93 | address sellToToken = _paths[j][_paths[j].length-1];
94 | if (sellToToken!=usdt&&sellToToken!=husd){
95 | continue;
96 | }
97 | (uint256 outAmount)=getUniAmountOut(_dexName,_amount,_paths[j]);
98 | if (sellToToken==usdt){
99 | outAmount =outAmount.div(10**10);
100 | }
101 | if (outAmount>bestAmount){
102 | dex = _uniAddress;
103 | bestAmount = outAmount;
104 | sellPath = _paths[j];
105 | }
106 | }
107 | }
108 | }
109 | // set husd swap contract address
110 | function setDepthSwapAddress(address _address) external onlyOwner{
111 | depth = _address;
112 | }
113 |
114 |
115 | function swapTokensToHusd(address _token,uint256 _amount) external{
116 | if (_amount==0){
117 | return;
118 | }
119 | uint256 _beforeHusdBalance = IERC20(husd).balanceOf(address(this));
120 | IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);
121 |
122 | if (_token==usdt){
123 | IERC20(usdt).safeApprove(depth,_amount);
124 | depthRouter(depth).exchange_underlying(1,0,_amount,0);
125 | }else if(_token!=husd){
126 | (address dex,uint256 bestAmount,address[] memory sellPath)=getBestSellPath(_token,_amount);
127 | if (bestAmount ==0||sellPath.length==0){
128 | return;
129 | }
130 |
131 | IERC20(_token).safeApprove(dex, _amount);
132 | uniRouter(dex).swapExactTokensForTokens(_amount, 0, sellPath, address(this), block.timestamp.add(1800));
133 | //if last sellPath is usdt.convert it to husd;
134 | if (sellPath[sellPath.length-1]==usdt){
135 | uint256 usdBalance = IERC20(usdt).balanceOf(address(this));
136 | IERC20(usdt).safeApprove(depth,usdBalance);
137 | depthRouter(depth).exchange_underlying(1,0,usdBalance,0);
138 | }
139 | }
140 | uint256 _afterHusdBalance = IERC20(husd).balanceOf(address(this)).sub(_beforeHusdBalance);
141 | if(_afterHusdBalance>0){
142 | IERC20(husd).safeTransfer(msg.sender, _afterHusdBalance);
143 | }
144 | }
145 |
146 | function claimToken(IERC20 token) external onlyOwner{
147 | uint256 balance = token.balanceOf(address(this));
148 | if (balance>0){
149 | token.safeTransfer(msg.sender, balance);
150 | }
151 | }
152 |
153 | //claim exchange token like mdx to owner.
154 | function claimMdexMiningToken() external{
155 | address mdxMiningAddress = 0x7373c42502874C88954bDd6D50b53061F018422e;
156 | ISwapMining(mdxMiningAddress).takerWithdraw();
157 |
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/depth.vault/dBoosterVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./interfaces/IVault.sol";
9 | /**depth.fi vault***/
10 | contract dBoosterVault is ERC20,Ownable,Pausable {
11 | using SafeERC20 for IERC20;
12 | using SafeMath for uint256;
13 |
14 | address public want;
15 | address public husd =0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047;
16 | address public daoAddress=0xfbaC8c66D9B7461EEfa7d8601568887c7b6f96AD; //DEP DAO ADDRESS
17 | address public husdSwapAddress;
18 | address public boosterSafeBox;
19 | address public boosterTokenAddress=0xff96dccf2763D512B6038Dc60b7E96d1A9142507;
20 | address public boosterStakeAddress=0xBa92b862ac310D42A8a3DE613dcE917d0d63D98c;
21 | uint256 public balance;//total token balance
22 | uint256 public minClaim=1;//min interest to claim
23 | uint256 public maxLimit;// max balance limit
24 | constructor (address _boosterSafeBox,address _husdSwapAddress) ERC20(
25 | string(abi.encodePacked("Depth.Fi Vault ", ERC20(_boosterSafeBox).symbol())),
26 | string(abi.encodePacked("d", ERC20(_boosterSafeBox).symbol()))
27 | ) {
28 |
29 | require(_boosterSafeBox != address(0), "INVALID BOOSTER POOL ADDRESS");
30 | want = IBooster(_boosterSafeBox).token();
31 |
32 | boosterSafeBox = _boosterSafeBox;
33 | husdSwapAddress = _husdSwapAddress;
34 |
35 | }
36 | function getBoosterStakePoolId() public view returns(uint256){
37 | return IBooster(boosterSafeBox).poolDepositId();
38 | }
39 | // set min claim interest
40 | function setMinClaim(uint256 _min) external onlyOwner{
41 | minClaim = _min;
42 | }
43 | // set max deposit limit
44 | function setMaxLimit(uint256 _max) external onlyOwner{
45 | maxLimit = _max;
46 | }
47 | // set husd swap contract address
48 | function setHusdSwapAddress(address _address) external onlyOwner{
49 | require(_address!=address(0),"no address!");
50 | husdSwapAddress = _address;
51 | }
52 |
53 | // set dao contract address
54 | function setDaoAddress(address _address) external onlyOwner{
55 | require(_address!=address(0),"no address!");
56 | daoAddress = _address;
57 | }
58 |
59 | function swapTokensToHusd(address _token) internal{
60 | require(husdSwapAddress!=address(0),"not set husd swap address!");
61 | uint256 _amount = IERC20(_token).balanceOf(address(this));
62 | if (_amount==0){
63 | return;
64 | }
65 | IERC20(_token).safeApprove(husdSwapAddress,_amount);
66 | IHusdSwap(husdSwapAddress).swapTokensToHusd(_token,_amount);
67 | }
68 |
69 | //convert base token amount to bof lp token amount.
70 | function getBofTokenAmount(uint256 _amount) public view returns(uint256){
71 | return _amount.mul(10**18).div(IBooster(boosterSafeBox).getBaseTokenPerLPToken());
72 | }
73 | function harvest() public{
74 | //claim interest
75 | uint256 _selfUnderlying = getSelfUnderlying();
76 |
77 | uint256 _interest = _selfUnderlying.sub(balance);
78 | if (_interest>=minClaim){
79 |
80 | uint256 bofTokenAmount = getBofTokenAmount(_interest);
81 | IBoosterStakePool(boosterStakeAddress).withdraw(getBoosterStakePoolId(),bofTokenAmount);
82 | //withdraw base token
83 |
84 | IBooster(boosterSafeBox).withdraw(bofTokenAmount);
85 |
86 | require(getSelfUnderlying()>=balance,"not enough balance!");
87 | if (want!=husd){
88 | swapTokensToHusd(want);
89 | }
90 |
91 | }
92 | //claim boo
93 | IBoosterStakePool(boosterStakeAddress).claim(getBoosterStakePoolId());
94 | swapTokensToHusd(boosterTokenAddress);
95 | //donate husd to dao
96 | uint256 _husdBalance = IERC20(husd).balanceOf(address(this));
97 | IERC20(husd).safeApprove(daoAddress,_husdBalance);
98 | //call dao address donate husd
99 | IDao(daoAddress).donateHUSD(_husdBalance);
100 |
101 |
102 | }
103 | //get underlying amount in compound pool
104 | function getSelfUnderlying() public view returns (uint256) {
105 | uint256 bofTokenAmount = IBoosterStakePool(boosterStakeAddress).getATUserAmount(getBoosterStakePoolId(),address(this));
106 | uint256 amount = bofTokenAmount.mul(IBooster(boosterSafeBox).getBaseTokenPerLPToken()).div(10**18);
107 |
108 | return amount;
109 | }
110 |
111 | //deposit
112 | function deposit(uint256 _amount) external whenNotPaused {
113 | require(_amount>0,"invalid amount");
114 | require(maxLimit==0||balance.add(_amount)<=maxLimit,"exceed max deposit limit");
115 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
116 | //deposit token to compound
117 | IERC20(want).safeApprove(boosterSafeBox, _amount);
118 | IBooster(boosterSafeBox).deposit(_amount);
119 | //stake bofToken
120 | uint256 bofTokenAmount = IERC20(boosterSafeBox).balanceOf(address(this));
121 | IERC20(boosterSafeBox).safeApprove(boosterStakeAddress, bofTokenAmount);
122 | IBoosterStakePool(boosterStakeAddress).deposit(getBoosterStakePoolId(),bofTokenAmount);
123 | balance=balance.add(_amount);
124 | _mint(msg.sender, _amount);
125 | }
126 | //withdraw
127 | function withdraw(uint256 _amount) external {
128 | require(_amount>0,"invalid amount");
129 | _burn(msg.sender, _amount);
130 | uint256 bofTokenAmount = getBofTokenAmount(_amount);
131 | require(bofTokenAmount>0,"invalid amount");
132 | //unstake bof token
133 | IBoosterStakePool(boosterStakeAddress).withdraw(getBoosterStakePoolId(),bofTokenAmount);
134 | //withdraw base token
135 | uint256 _before = IERC20(want).balanceOf(address(this));
136 | //IERC20(pTokenAddress).safeIncreaseAllowance(pilotAddress, pAmount);
137 | IBooster(boosterSafeBox).withdraw(bofTokenAmount);
138 | uint256 _after = IERC20(want).balanceOf(address(this));
139 |
140 | require(_after.sub(_before)>=_amount,"sub flow!");
141 |
142 | IERC20(want).safeTransfer(msg.sender, _amount);
143 | balance=balance.sub(_amount);
144 |
145 | }
146 | //claim exchange token like mdx to owner.
147 | function claimExchangeMiningToken(address _swapAddress,address _miningToken) external onlyOwner{
148 | require(_swapAddress!=address(0),"invalid swap address");
149 | require(_miningToken!=address(0),"invalid mining token address");
150 | require(_miningToken!=boosterSafeBox,"can not claim bof token");
151 | ISwapMining(_swapAddress).takerWithdraw();
152 | IERC20(_miningToken).safeTransfer(msg.sender,IERC20(_miningToken).balanceOf(address(this)));
153 |
154 | }
155 |
156 | function pause() external onlyOwner {
157 | _pause();
158 | }
159 | function decimals() public view override returns (uint8) {
160 | return ERC20(want).decimals();
161 | }
162 |
163 |
164 | function unpause() external onlyOwner {
165 | _unpause();
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/ActivityPool.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 | import "./openzeppelin/contracts/security/Pausable.sol";
7 | contract ActivityPool is Ownable,Pausable {
8 | using SafeERC20 for IERC20;
9 | using SafeMath for uint256;
10 | address public rewardToken;
11 | uint256 public totalReward;
12 | uint256 public totalClaimedReward;
13 | uint256 public totalClaimedLock;
14 | uint256 public totalLockAmount;
15 | address public lockToken;
16 | uint256 public lockLimitAmount;
17 | uint256 public startTime;
18 | uint256 public endTime;
19 | uint256 public lastRewardTime;
20 | uint256 public rewardPerLock;
21 | bool public canUnLockBeforeFinished;
22 | mapping(address=>UserInfo) public userInfo;
23 | struct UserInfo{
24 | uint256 lockAmount;
25 | uint256 rewardDebt;
26 | }
27 | event Lock(
28 | address indexed user,
29 | uint256 amount
30 | );
31 | event UnLock(
32 | address indexed user,
33 | uint256 amount
34 | );
35 | event Claim(
36 | address indexed user
37 | );
38 | constructor (address _lockToken, address _rewardToken,uint256 _lockLimitAmount,uint256 _totalReward,uint256 _startTime,uint256 _lockDays,bool _canUnLockBeforeFinished) {
39 |
40 | require(_lockToken != address(0), "invalid lock token");
41 | require(_rewardToken != address(0), "invalid reward token");
42 | lockToken = _lockToken;
43 | rewardToken = _rewardToken;
44 | lockLimitAmount = _lockLimitAmount;
45 | totalReward = _totalReward;
46 | startTime = _startTime;
47 | lastRewardTime = _startTime;
48 | canUnLockBeforeFinished = _canUnLockBeforeFinished;
49 | uint256 currentTime = block.timestamp;
50 | require(startTime==0||startTime>=currentTime,"start time must over now!");
51 | if (_lockDays>0&&startTime>0){
52 | endTime = startTime.add(86400*_lockDays);
53 | }
54 | }
55 | function setSetting(uint256 _lockLimitAmount,uint256 _totalReward,uint256 _startTime,uint256 _lockDays,bool _canUnLockBeforeFinished) external onlyOwner{
56 | uint256 currentTime = block.timestamp;
57 |
58 | if(_totalReward>0){
59 | require(startTime==0||startTime>currentTime,"The activity has begun!");
60 | totalReward = _totalReward;
61 | }
62 | if(_startTime>0){
63 | require(startTime==0||(startTime>currentTime&&_startTime>currentTime&&_lockDays>0),"invalid start time!");
64 | startTime = _startTime;
65 | lastRewardTime = _startTime;
66 | }
67 | if (_lockDays>0){
68 | require(startTime>0&&startTime>currentTime,"The activity has begun!");
69 | endTime = startTime.add(86400*_lockDays);
70 | }
71 | if (_lockLimitAmount>0){
72 | lockLimitAmount = _lockLimitAmount;
73 | }
74 | canUnLockBeforeFinished = _canUnLockBeforeFinished;
75 | }
76 | function lock(uint256 _amount) external whenNotPaused{
77 | uint256 currentTime = block.timestamp;
78 | require(startTime > 0,"no start time!");
79 | require(currentTime0){
81 | require(totalLockAmount.add(_amount)<=lockLimitAmount,"exceed lock limit amount!");
82 | }
83 | UserInfo storage _user= userInfo[msg.sender];
84 |
85 | updatePool();
86 | if (_user.lockAmount>0){
87 | uint256 _pending = _user.lockAmount.mul(rewardPerLock).div(10**12).sub(_user.rewardDebt);
88 | if (_pending>0){
89 | transferReward(_pending);
90 |
91 | }
92 | }
93 | if (_amount>0){
94 | IERC20(lockToken).safeTransferFrom(msg.sender,address(this),_amount);
95 | _user.lockAmount = _user.lockAmount.add(_amount);
96 | totalLockAmount = totalLockAmount.add(_amount);
97 | }
98 | _user.rewardDebt = _user.lockAmount.mul(rewardPerLock).div(10**12);
99 | emit Lock(msg.sender,_amount);
100 | }
101 | function transferReward(uint256 _reward) internal{
102 | uint256 _balance = IERC20(rewardToken).balanceOf(address(this));
103 | require(_balance>=_reward,"not enough balance!");
104 | IERC20(rewardToken).transfer(msg.sender,_reward);
105 | totalClaimedReward = totalClaimedReward.add(_reward);
106 | }
107 | function unLock(uint256 _amount) external{
108 | if (canUnLockBeforeFinished==false){
109 | uint256 currentTime = block.timestamp;
110 | require(currentTime > endTime,"The activity is not over");
111 | }
112 | updatePool();
113 |
114 | UserInfo storage _user= userInfo[msg.sender];
115 | require(_user.lockAmount >= _amount, "not enough lock amount!");
116 |
117 | uint256 _pending = _user.lockAmount.mul(rewardPerLock).div(10**12).sub(_user.rewardDebt);
118 | if (_pending>0){
119 | transferReward(_pending);
120 |
121 | }
122 |
123 | if (_amount>0){
124 | IERC20(lockToken).safeTransfer(msg.sender,_amount);
125 | _user.lockAmount = _user.lockAmount.sub(_amount);
126 | totalLockAmount = totalLockAmount.sub(_amount);
127 | }
128 | _user.rewardDebt = _user.lockAmount.mul(rewardPerLock).div(10**12);
129 | emit Lock(msg.sender,_amount);
130 | }
131 |
132 | function claim() external whenNotPaused{
133 | updatePool();
134 | UserInfo storage _user= userInfo[msg.sender];
135 | if (_user.lockAmount>0){
136 | uint256 _pending = _user.lockAmount.mul(rewardPerLock).div(10**12).sub(_user.rewardDebt);
137 | if (_pending>0){
138 | transferReward(_pending);
139 |
140 | }
141 |
142 | _user.rewardDebt = _user.lockAmount.mul(rewardPerLock).div(10**12);
143 | emit Claim(msg.sender);
144 | }
145 | }
146 |
147 | function pendingReward(address _address) public view returns(uint256){
148 | UserInfo memory _user= userInfo[_address];
149 | uint256 currentTime = block.timestamp;
150 | if (currentTime<=startTime||startTime==0||endTime==0||totalLockAmount==0){
151 | return 0;
152 | }
153 | uint256 _endTime = currentTime>endTime?endTime:currentTime;
154 | uint256 _totalTimes = _endTime.sub(lastRewardTime);
155 | uint256 _rewardPerLock =rewardPerLock.add(getRewardPerTime().mul(_totalTimes).div(totalLockAmount));
156 | return _user.lockAmount.mul(_rewardPerLock).div(10**12).sub(_user.rewardDebt);
157 | }
158 |
159 | function getRewardPerTime() public view returns(uint256){
160 | if (endTime==0){
161 | return 0;
162 | }
163 | return totalReward.mul(10**12).div(endTime.sub(startTime));
164 | }
165 | function updatePool() public{
166 | uint256 currentTime = block.timestamp;
167 | if (currentTime<=lastRewardTime){
168 | return;
169 | }
170 | if (totalLockAmount==0){
171 | lastRewardTime = currentTime;
172 | return;
173 | }
174 | uint256 _endTime = currentTime>endTime?endTime:currentTime;
175 | uint256 _totalTimes = _endTime.sub(lastRewardTime);
176 | rewardPerLock =rewardPerLock.add(getRewardPerTime().mul(_totalTimes).div(totalLockAmount));
177 | lastRewardTime = _endTime;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/BSCContracts/vault/dDepBxhVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 |
9 | interface Ixbxh {
10 | function stake(uint256 amount) external;
11 | function withdraw(uint256 amount) external;
12 | }
13 |
14 | interface ISwap {
15 | function swapTokensToEarnToken(address _token, uint256 _amount) external;
16 | }
17 |
18 | interface IDao {
19 | function donateHUSD(uint256 amount) external;
20 | }
21 |
22 | interface IWBNB{
23 | function deposit() external payable;
24 | function transfer(address to, uint value) external returns (bool);
25 | function withdraw(uint) external;
26 | }
27 |
28 | interface IMining {
29 |
30 | function deposit(uint256 _pid, uint256 _amount) external;
31 |
32 | function withdraw(uint256 _pid, uint256 _amount) external;
33 | }
34 |
35 | interface ISwapRouter {
36 | function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts);
37 | }
38 |
39 | contract dDepBxhVault is ERC20,Ownable,Pausable {
40 | using SafeERC20 for IERC20;
41 | using SafeMath for uint256;
42 |
43 | address public want; // deposit address busd usdt wbnb
44 |
45 | address public constant busd = 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56; //BUSD ADDRESS
46 | address public constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
47 | address public constant BXH = 0x8F0528cE5eF7B51152A59745bEfDD91D97091d2F; // BXH TOKEN
48 |
49 | address public daoAddress; //DEP DAO ADDRESS
50 | address public teamAddress=0x01D61BE40bFF0c48A617F79e6FAC6d09D7a52aAF;
51 | address public earnToken=0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56;
52 |
53 | address public dexSwapAddress;
54 | address public xTokenAddress; // bxh xtoken
55 | address public miningAddress; // BXH XToken mining address
56 | uint256 public miningPid; // mining pool pid
57 |
58 | uint256 public balance; // total token balance
59 | uint256 public minClaim=1; // min interest to claim
60 | uint256 public maxLimit; // max balance limit
61 |
62 | event Deposit(address indexed user, uint256 amount);
63 | event Withdraw(address indexed user, uint256 amount);
64 |
65 | mapping(address => address[]) public paths;
66 |
67 | constructor (address _want, address _tokenAddress,address _swapAddress, address _miningAddress, uint256 _pid) ERC20(
68 | string(abi.encodePacked("Depth.Fi Vault BXH", ERC20(_want).symbol())),
69 | string(abi.encodePacked("da", ERC20(_want).symbol()))
70 | ) {
71 | require(_want != address(0), "INVALID _want ADDRESS");
72 | require(_swapAddress != address(0), "INVALID _swapAddress ADDRESS");
73 | require(_miningAddress != address(0), "INVALID _miningAddress ADDRESS");
74 |
75 | want = _want; // deposit token address
76 | miningAddress = _miningAddress; // mining address
77 | miningPid = _pid;
78 |
79 | xTokenAddress = _tokenAddress; // bxh xtoken address
80 | dexSwapAddress = _swapAddress;
81 |
82 | paths[BXH] = [BXH, busd];
83 | }
84 |
85 | // set min claim interest
86 | function setMinClaim(uint256 _min) external onlyOwner{
87 | minClaim = _min;
88 | }
89 |
90 | // set max deposit limit
91 | function setMaxLimit(uint256 _max) external onlyOwner{
92 | maxLimit = _max;
93 | }
94 |
95 | // set SwapAddress
96 | function setSwapAddress(address _address) external onlyOwner{
97 | require(_address!=address(0),"invalid address");
98 | dexSwapAddress = _address;
99 | }
100 |
101 | // set dao contract address
102 | function setDaoAddress(address _address) external onlyOwner{
103 | daoAddress = _address;
104 | }
105 |
106 | // set miningAddress
107 | function setMiningAddress(address _address) external onlyOwner{
108 | require(_address!=address(0),"invalid address");
109 | miningAddress = _address;
110 | }
111 |
112 | // set miningPid
113 | function setPid(uint256 _pid) external onlyOwner{
114 | miningPid = _pid;
115 | }
116 |
117 | function setTeamAddress(address _address) public onlyOwner{
118 | require(_address!=address(0),"invalid address");
119 | teamAddress = _address;
120 | }
121 |
122 | function setDexSwappaths(address _address, address[] memory _paths) public onlyOwner {
123 | require(_address != address(0), "invalid address!");
124 | paths[_address] = _paths;
125 | }
126 |
127 | function bxhTokenMining(uint256 amount) internal {
128 | require(amount>0, "invalid amount");
129 | IERC20(xTokenAddress).safeApprove(miningAddress, amount);
130 | IMining(miningAddress).deposit(miningPid, amount);
131 | }
132 |
133 | //deposit busd usdt ....
134 | function deposit(uint256 _amount) external whenNotPaused payable {
135 | require(_amount>0, "invalid amount");
136 |
137 | if (msg.value != 0 && want == WBNB) {
138 | require(_amount == msg.value, "_amount != msg.value");
139 | IWBNB(WBNB).deposit{value:msg.value}();
140 | } else {
141 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
142 | }
143 |
144 | IERC20(want).safeApprove(xTokenAddress, _amount);
145 | Ixbxh(xTokenAddress).stake(_amount);
146 | bxhTokenMining(_amount);
147 |
148 | balance=balance.add(_amount);
149 | _mint(msg.sender, _amount);
150 |
151 | emit Deposit(msg.sender, _amount);
152 | }
153 |
154 | //withdraw busd usdt bnb....
155 | function withdraw(uint256 _amount) external {
156 | require(_amount>0, "invalid amount");
157 | _burn(msg.sender, _amount);
158 |
159 | IMining(miningAddress).withdraw(miningPid,_amount);
160 | Ixbxh(xTokenAddress).withdraw(_amount);
161 |
162 | if (want==WBNB){
163 | IWBNB(WBNB).withdraw(_amount);
164 | payable(msg.sender).transfer(_amount);
165 | }else{
166 | IERC20(want).safeTransfer(msg.sender, _amount);
167 | }
168 | balance=balance.sub(_amount);
169 | emit Withdraw(msg.sender, _amount);
170 | }
171 |
172 | function harvest() public {
173 | // get bxh token
174 | IMining(miningAddress).deposit(miningPid,0);
175 |
176 | uint256 abalance = IERC20(BXH).balanceOf(address(this));
177 | if (abalance > 0) {
178 | address[] memory path = paths[BXH];
179 | IERC20(BXH).safeApprove(dexSwapAddress, abalance);
180 | ISwapRouter(dexSwapAddress).swapExactTokensForTokens(abalance, 0, path, address(this), block.timestamp.add(1800));
181 | }
182 |
183 | //donate bxh token to dao
184 | uint256 _earnTokenBalance = IERC20(earnToken).balanceOf(address(this));
185 | if (_earnTokenBalance>0){
186 | if (daoAddress!=address(0)){
187 | IERC20(earnToken).safeApprove(daoAddress,_earnTokenBalance);
188 | IDao(daoAddress).donateHUSD(_earnTokenBalance);
189 | }else{
190 | IERC20(earnToken).safeTransfer(teamAddress,_earnTokenBalance);
191 | }
192 | }
193 | }
194 |
195 | function pause() external onlyOwner {
196 | _pause();
197 | }
198 |
199 | function unpause() external onlyOwner {
200 | _unpause();
201 | }
202 |
203 | function decimals() public view override returns (uint8) {
204 | return ERC20(want).decimals();
205 | }
206 |
207 | /// @dev Fallback function to accept BNB.
208 | receive() external payable {}
209 |
210 | }
211 |
--------------------------------------------------------------------------------
/depth.vault/dVaultRouter.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 | import "./openzeppelin/contracts/security/ReentrancyGuard.sol";
9 | interface IVaultPool{
10 | function deposit(uint256 _amount) external;
11 | function withdraw(uint256 _amount) external;
12 | }
13 | /**depth.fi vault***/
14 | contract dVaultRouter is ERC20,Ownable,Pausable,ReentrancyGuard {
15 | using SafeERC20 for IERC20;
16 | using SafeMath for uint256;
17 | uint256 public totalAllocPoint;
18 | struct PoolInfo{
19 | address vaultAddress;
20 | uint256 allocPoint;
21 | uint256 balance;
22 | }
23 | PoolInfo[] public poolInfo;
24 | address public want;
25 | uint256 public maxLimit;// max balance limit
26 | uint256 public totalBalance;//total token balance
27 | constructor (address _want) ERC20(
28 | string(abi.encodePacked("Depth.Fi Vault ", ERC20(_want).symbol())),
29 | string(abi.encodePacked("dv", ERC20(_want).symbol()))
30 | ) {
31 |
32 | require(_want != address(0), "INVALID TOKEN ADDRESS");
33 | want = _want;
34 |
35 | }
36 |
37 | function poolLength() public view returns (uint256) {
38 | return poolInfo.length;
39 | }
40 |
41 | function addPool(uint256 _allocPoint, address _vaultAddress) external onlyOwner{
42 | totalAllocPoint = totalAllocPoint.add(_allocPoint);
43 | poolInfo.push(PoolInfo({
44 | vaultAddress : _vaultAddress,
45 | allocPoint : _allocPoint,
46 | balance : 0
47 | }));
48 | }
49 |
50 | function getMostInsufficientPool() public view returns(uint256 poolId,address poolAddress){
51 | uint256 _maxCanDeposit=0;
52 | for(uint256 i=0;i=_needDepositAmount?0:_needDepositAmount.sub(_poolBalance);
59 | if (_canDepositAmount>=_maxCanDeposit){
60 | poolId = i;
61 | poolAddress = poolInfo[i].vaultAddress;
62 | _maxCanDeposit = _canDepositAmount;
63 | }
64 | }
65 | }
66 |
67 | function getMostOverLockedPool(uint256 _withdrawAmount) public view returns(uint256 poolId,address poolAddress,uint256 availableWithdrawAmount){
68 | uint256 _totalBalance=totalBalance.sub(_withdrawAmount);
69 | for(uint256 i=0;i=_optimal&&_current.sub(_optimal)>=availableWithdrawAmount){
76 | poolId = i;
77 | poolAddress = poolInfo[i].vaultAddress;
78 | availableWithdrawAmount = _current.sub(_optimal);
79 | }
80 | }
81 | }
82 | function getMostLockedPool() public view returns(uint256 poolId,address poolAddress,uint256 maxBalance){
83 | for(uint256 i=0;i=maxBalance){
87 | poolId = i;
88 | poolAddress = poolInfo[i].vaultAddress;
89 | maxBalance = _current;
90 | }
91 | }
92 | }
93 | function movePool(uint256 _fromPoolId,uint256 _toPoolId,uint256 _amount) public onlyOwner{
94 | address _fromAddress = poolInfo[_fromPoolId].vaultAddress;
95 | address _toAddress = poolInfo[_toPoolId].vaultAddress;
96 | require(_fromAddress!=address(0)&&_toAddress!=address(0),"invalid pool id!");
97 | require(_amount>0,"invalid amount!");
98 | IVaultPool(_fromAddress).withdraw(_amount);
99 | poolInfo[_fromPoolId].balance=poolInfo[_fromPoolId].balance.sub(_amount);
100 |
101 |
102 | IERC20(want).safeApprove(_toAddress,_amount);
103 | IVaultPool(_toAddress).deposit(_amount);
104 | poolInfo[_toPoolId].balance=poolInfo[_toPoolId].balance.add(_amount);
105 | }
106 | function updatePools() external nonReentrant{
107 | (uint256 _fromPoolId,address _fromPoolAddress,uint256 _overAmount) = getMostOverLockedPool(0);
108 | if (_overAmount>0){
109 | (uint256 _toPoolId,address _toPoolAddress) = getMostInsufficientPool();
110 |
111 | IVaultPool(_fromPoolAddress).withdraw(_overAmount);
112 | poolInfo[_fromPoolId].balance=poolInfo[_fromPoolId].balance.sub(_overAmount);
113 |
114 |
115 | IERC20(want).safeApprove(_toPoolAddress,_overAmount);
116 | IVaultPool(_toPoolAddress).deposit(_overAmount);
117 | poolInfo[_toPoolId].balance=poolInfo[_toPoolId].balance.add(_overAmount);
118 | }
119 | }
120 |
121 |
122 |
123 | // set max deposit limit
124 | function setMaxLimit(uint256 _max) external onlyOwner{
125 | maxLimit = _max;
126 | }
127 |
128 |
129 | function setAllocPoint(uint256 _pid, uint256 _allocPoint) public onlyOwner {
130 |
131 | //update totalAllocPoint
132 | totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
133 |
134 | //update poolInfo
135 | poolInfo[_pid].allocPoint = _allocPoint;
136 | }
137 |
138 | //get underlying amount in compound pool
139 | function getSelfUnderlying() public view returns (uint256) {
140 |
141 | return totalBalance;
142 | }
143 | function _deposit(uint256 _amount) internal nonReentrant{
144 | (uint256 _poolId,address _poolAddress) = getMostInsufficientPool();
145 | IERC20(want).safeApprove(_poolAddress,_amount);
146 | IVaultPool(_poolAddress).deposit(_amount);
147 | poolInfo[_poolId].balance=poolInfo[_poolId].balance.add(_amount);
148 | totalBalance=totalBalance.add(_amount);
149 |
150 | _mint(msg.sender, _amount);
151 | }
152 | //deposit
153 | function deposit(uint256 _amount) external whenNotPaused {
154 | require(_amount>0,"invalid amount");
155 | require(maxLimit==0||totalBalance.add(_amount)<=maxLimit,"exceed max deposit limit");
156 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
157 | _deposit(_amount);
158 | }
159 | function _withdraw(uint256 _amount) internal nonReentrant{
160 | _burn(msg.sender, _amount);
161 | (uint256 _poolId,address _poolAddress,uint256 _maxWithdrawAmount) = getMostOverLockedPool(_amount);
162 | if (_poolAddress==address(0)||_maxWithdrawAmount==0){
163 | (_poolId,_poolAddress,_maxWithdrawAmount)= getMostLockedPool();
164 | require(_maxWithdrawAmount>=_amount,"too big amount to withdraw!");
165 | }
166 | IVaultPool(_poolAddress).withdraw(_amount);
167 | poolInfo[_poolId].balance=poolInfo[_poolId].balance.sub(_amount);
168 | totalBalance=totalBalance.sub(_amount);
169 | }
170 | //withdraw
171 | function withdraw(uint256 _amount) external {
172 | require(_amount>0,"invalid amount");
173 |
174 | _withdraw(_amount);
175 |
176 | IERC20(want).safeTransfer(msg.sender, _amount);
177 |
178 |
179 | }
180 |
181 |
182 | function pause() external onlyOwner {
183 | _pause();
184 | }
185 |
186 |
187 | function unpause() external onlyOwner {
188 | _unpause();
189 | }
190 | function decimals() public view override returns (uint8) {
191 | return ERC20(want).decimals();
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/BSCContracts/vault/dDepVenusVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.3;
2 |
3 | import "./openzeppelin/contracts/access/Ownable.sol";
4 | import "./openzeppelin/contracts/utils/math/SafeMath.sol";
5 | import "./openzeppelin/contracts/token/ERC20/ERC20.sol";
6 | import "./openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 | import "./openzeppelin/contracts/security/Pausable.sol";
8 |
9 | interface VToken {
10 | function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
11 | function balanceOfUnderlying(address owner) external returns (uint256);
12 | function mint(uint256 mintAmount) external returns (uint256);
13 | function getAccountSnapshot(address account) external view returns (uint256, uint256, uint256, uint256);
14 | function underlying() external view returns (address);
15 | function comptroller() external view returns (address);
16 | function getCash() external view returns (uint256);
17 | }
18 |
19 | interface ISwap {
20 | function swapTokensToEarnToken(address _token,uint256 _amount) external;
21 | }
22 |
23 | interface IVenusComptroller {
24 | // Claim all the COMP accrued by holder in specific markets
25 | function claimVenus(address holder) external;
26 | function getXVSAddress() external view returns (address);
27 | }
28 |
29 | interface IDao {
30 | function donateHUSD(uint256 amount) external;
31 | }
32 |
33 | interface IComptroller {
34 | /*** Treasury Data ***/
35 | function treasuryAddress() external view returns (address);
36 | function treasuryPercent() external view returns (uint);
37 | }
38 |
39 | contract dDepVenusVault is ERC20, Ownable, Pausable {
40 | using SafeERC20 for IERC20;
41 | using SafeMath for uint256;
42 |
43 | address public want;
44 | address public vTokenAddress; // VBep20Delegator
45 | address public constant busd = 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56; //BUSD ADDRESS
46 | address public constant WBNB= 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
47 |
48 | address public daoAddress; // DEP DAO ADDRESS
49 | address public teamAddress = 0x01D61BE40bFF0c48A617F79e6FAC6d09D7a52aAF;
50 | address public earnToken = 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56;
51 |
52 | address public busdSwapAddress; // swap compound token to usdt
53 | uint256 public maxLimit; // max balance limit
54 | uint256 public balance; // total token balance
55 | uint256 public minClaim=1; // min interest to claim default 1
56 |
57 | event Deposit(address indexed user, uint256 amount);
58 | event Withdraw(address indexed user, uint256 amount);
59 |
60 | constructor (address _vTokenAddress, address _swapAddress) ERC20(
61 | string(abi.encodePacked("Depth.Fi Vault Venus", ERC20(_vTokenAddress).symbol())),
62 | string(abi.encodePacked("dv", ERC20(_vTokenAddress).symbol()))
63 | ) {
64 |
65 | require(_vTokenAddress != address(0), "INVALID VTOKEN ADDRESS");
66 | want = VToken(_vTokenAddress).underlying();
67 | vTokenAddress = _vTokenAddress;
68 |
69 | busdSwapAddress = _swapAddress;
70 | }
71 |
72 | // set min claim interest
73 | function setMinClaim(uint256 _min) external onlyOwner {
74 | minClaim = _min;
75 | }
76 |
77 | // set max deposit limit
78 | function setMaxLimit(uint256 _max) external onlyOwner{
79 | maxLimit = _max;
80 | }
81 |
82 | // set SwapAddress
83 | function setSwapAddress(address _address) external onlyOwner{
84 | require(_address!=address(0),"invalid address");
85 | busdSwapAddress = _address;
86 | }
87 |
88 | // set dao contract address
89 | function setDaoAddress(address _address) external onlyOwner{
90 | daoAddress = _address;
91 | }
92 |
93 | function setTeamAddress(address _address) public onlyOwner{
94 | require(_address!=address(0),"invalid address");
95 | teamAddress = _address;
96 | }
97 |
98 | //deposit
99 | function deposit(uint256 _amount) external whenNotPaused {
100 |
101 | require(_amount>0, "invalid amount");
102 | require(maxLimit==0 || balance.add(_amount)<=maxLimit, "exceed max deposit limit");
103 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
104 | //deposit token to compound
105 | IERC20(want).safeApprove(vTokenAddress, _amount);
106 | require(VToken(vTokenAddress).mint(_amount) == 0, "!deposit");
107 | balance = balance.add(_amount);
108 | _mint(msg.sender, _amount);
109 |
110 | emit Deposit(msg.sender, _amount);
111 | }
112 |
113 | //withdraw
114 | function withdraw(uint256 _amount) external {
115 | require(_amount>0, "invalid amount");
116 | _burn(msg.sender, _amount);
117 |
118 | //redeemUnderlying
119 | uint256 beforeVaule = IERC20(want).balanceOf(address(this));
120 | require(VToken(vTokenAddress).redeemUnderlying(_amount) == 0, "!withdraw");
121 | uint256 afterVaule = IERC20(want).balanceOf(address(this));
122 | uint256 getValue = afterVaule.sub(beforeVaule);
123 | require(getValue>0, "invalid amount, !withdraw");
124 |
125 | IERC20(want).safeTransfer(msg.sender, getValue);
126 | balance = balance.sub(_amount);
127 |
128 | emit Withdraw(msg.sender, _amount);
129 | }
130 |
131 | function swapTokensToBusd(address _token) internal{
132 | require(busdSwapAddress!=address(0), "not set husd swap address!");
133 | uint256 _amount = IERC20(_token).balanceOf(address(this));
134 | if (_amount==0){
135 | return;
136 | }
137 | IERC20(_token).safeApprove(busdSwapAddress, _amount);
138 | ISwap(busdSwapAddress).swapTokensToEarnToken(_token, _amount);
139 | }
140 |
141 | //get underlying amount in compound pool
142 | function getSelfUnderlying() public view returns (uint256) {
143 | (, uint256 vTokenBalance, , uint256 exchangeRate) = VToken(vTokenAddress).getAccountSnapshot(address(this));
144 | return vTokenBalance.mul(exchangeRate).div(1e18);
145 | }
146 |
147 | function harvest() public{
148 | harvest(true);
149 | }
150 |
151 | function harvest(bool claimCompToken) public {
152 | //claim interest
153 | uint256 _selfUnderlying = getSelfUnderlying();
154 | uint256 _compUnderlyingBalance = VToken(vTokenAddress).getCash();
155 | uint256 _interest = _selfUnderlying.sub(balance);
156 | if (_interest>=minClaim) {
157 | uint256 _claimAmount = _interest<_compUnderlyingBalance?_interest:_compUnderlyingBalance;
158 | require(VToken(vTokenAddress).redeemUnderlying(_claimAmount) == 0, "!redeem");
159 | if (want!= busd){
160 | swapTokensToBusd(want);
161 | }
162 | }
163 |
164 | if (claimCompToken) {
165 | //claim mining token
166 | address _comptrollerAddress = VToken(vTokenAddress).comptroller();
167 | address _compTokenAddress;
168 |
169 | IVenusComptroller(_comptrollerAddress).claimVenus(address(this));
170 | _compTokenAddress = IVenusComptroller(_comptrollerAddress).getXVSAddress();
171 |
172 | swapTokensToBusd(_compTokenAddress);
173 | }
174 |
175 | //donate earnToken to dao
176 | uint256 _earnTokenBalance = IERC20(earnToken).balanceOf(address(this));
177 | if (_earnTokenBalance>0) {
178 | if (daoAddress!=address(0)){
179 | IERC20(earnToken).safeApprove(daoAddress,_earnTokenBalance);
180 | IDao(daoAddress).donateHUSD(_earnTokenBalance);
181 | }else{
182 | IERC20(earnToken).safeTransfer(teamAddress,_earnTokenBalance);
183 | }
184 | }
185 | }
186 |
187 | function pause() external onlyOwner {
188 | _pause();
189 | }
190 |
191 | function unpause() external onlyOwner {
192 | _unpause();
193 | }
194 |
195 | function decimals() public view override returns (uint8) {
196 | return ERC20(want).decimals();
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/BSCContracts/vault/dCowVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.8.0;
2 | import "@openzeppelin/contracts/access/Ownable.sol";
3 | import "@openzeppelin/contracts/utils/math/SafeMath.sol";
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5 | import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6 | import "@openzeppelin/contracts/security/Pausable.sol";
7 |
8 |
9 |
10 | interface IEarnTokenSwap {
11 | function swapTokensToEarnToken(address _token,uint256 _amount) external;
12 | }
13 | interface IDao {
14 | function donateHUSD(uint256 amount) external;
15 | }
16 | interface ICow{
17 | function poolLength() external view returns(uint256);
18 | function deposit(address _token, uint256 _amount) external;
19 | function withdraw(address _token, uint256 _amount) external;
20 | function pending(uint256 _poolId,address _userAddress) external view returns(uint256,uint256,uint256);
21 | function pendingCow(uint256 _poolId,address _userAddress) external view returns(uint256);
22 | function poolInfo(uint256 _poolId) external view returns(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256);
23 | }
24 | interface IWbnb{
25 | function deposit() external payable;
26 | function withdraw(uint256 _amount) external;
27 | }
28 | /**depth.fi vault***/
29 | contract dCowVault is ERC20,Ownable,Pausable {
30 | using SafeMath for uint256;
31 | using SafeERC20 for IERC20;
32 | address public want;
33 | address public earnToken =0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56;
34 | address public teamAddress=0x01D61BE40bFF0c48A617F79e6FAC6d09D7a52aAF;
35 | address public daoAddress;
36 | address public earnTokenSwapAddress;
37 | address public mdxAddress = 0x9C65AB58d8d978DB963e63f2bfB7121627e3a739;
38 | address public cowAddress = 0x422E3aF98bC1dE5a1838BE31A56f75DB4Ad43730;
39 | address public cowCtrlAddress = 0x52d22F040dEE3027422e837312320b42e1fD737f;
40 | address public wbnb = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
41 | uint256 public balance;//total token balance
42 | uint256 public minClaim=1;//min interest to claim
43 | uint256 public maxLimit;// max balance limit
44 | uint256 public cowPoolId;
45 | event Deposit(address indexed user, uint256 amount);
46 | event Withdraw(address indexed user, uint256 amount);
47 | constructor (address _want,address _earnTokenSwapAddress) ERC20(
48 | string(abi.encodePacked("Depth.Fi Vault Cow", ERC20(_want).symbol())),
49 | string(abi.encodePacked("dcow", ERC20(_want).symbol()))
50 | ) {
51 |
52 | require(_want != address(0), "INVALID TOKEN ADDRESS");
53 | want = _want;
54 | ICow cow=ICow(cowCtrlAddress);
55 | uint256 _poolLength=cow.poolLength();
56 | bool bFound=false;
57 | for(uint256 i=0;i<_poolLength;i++){
58 | (address _token,,,,,,,,,,)=cow.poolInfo(i);
59 | if (want==_token){
60 | bFound=true;
61 | cowPoolId = i;
62 | break;
63 | }
64 | }
65 | require(bFound,"not supported want token!");
66 | earnTokenSwapAddress = _earnTokenSwapAddress;
67 |
68 | }
69 | function setTeamAddress(address _address) public onlyOwner{
70 | require(_address!=address(0),"invalid address");
71 | teamAddress = _address;
72 | }
73 |
74 | function setDaoAddress(address _address) public onlyOwner{
75 | require(_address!=address(0),"invalid address");
76 | daoAddress = _address;
77 | }
78 |
79 | // set min claim interest
80 | function setMinClaim(uint256 _min) external onlyOwner{
81 | minClaim = _min;
82 | }
83 | // set max deposit limit
84 | function setMaxLimit(uint256 _max) external onlyOwner{
85 | maxLimit = _max;
86 | }
87 | // set earnToken swap contract address
88 | function setEarnTokenSwapAddress(address _address) external onlyOwner{
89 | require(_address!=address(0),"no address!");
90 | earnTokenSwapAddress = _address;
91 | }
92 |
93 | function swapTokensToEarnToken(address _token) internal{
94 | require(earnTokenSwapAddress!=address(0),"not set earnToken swap address!");
95 | uint256 _amount = IERC20(_token).balanceOf(address(this));
96 | if (_amount==0){
97 | return;
98 | }
99 | IERC20(_token).safeApprove(earnTokenSwapAddress,_amount);
100 | IEarnTokenSwap(earnTokenSwapAddress).swapTokensToEarnToken(_token,_amount);
101 | }
102 | function getMdxAmount() public view returns(uint256){
103 | (uint256 _mdxAmount,,) = ICow(cowCtrlAddress).pending(cowPoolId,address(this));
104 | return _mdxAmount;
105 | }
106 | function getCowAmount() public view returns(uint256){
107 | return ICow(cowCtrlAddress).pendingCow(cowPoolId,address(this));
108 | }
109 | function getRemaining() public view returns(uint256){
110 | ICow cow=ICow(cowCtrlAddress);
111 | (,,,,,uint256 _totalAmount,uint256 _totalAmountLimit,,,,)=cow.poolInfo(cowPoolId);
112 | uint256 _remaining = _totalAmountLimit.sub(_totalAmount);
113 | if(maxLimit>0){
114 | if (maxLimit<=balance){
115 | _remaining =0;
116 | }else{
117 | _remaining = _remaining>maxLimit.sub(balance)?maxLimit.sub(balance):_remaining;
118 | }
119 | }
120 | return _remaining;
121 | }
122 | function harvest() public{
123 | //claim interest
124 |
125 | uint256 _mdxAmount = getMdxAmount();
126 | uint256 _cowAmount = getCowAmount();
127 | if (_mdxAmount>=minClaim||_cowAmount>=minClaim){
128 | ICow(cowCtrlAddress).withdraw(want,0);
129 | swapTokensToEarnToken(mdxAddress);
130 | swapTokensToEarnToken(cowAddress);
131 | }
132 | //donate earnToken to dao
133 | uint256 _earnTokenBalance = IERC20(earnToken).balanceOf(address(this));
134 | if (_earnTokenBalance>0){
135 | if (daoAddress!=address(0)){
136 | IERC20(earnToken).safeApprove(daoAddress,_earnTokenBalance);
137 | IDao(daoAddress).donateHUSD(_earnTokenBalance);
138 | }else{
139 | IERC20(earnToken).safeTransfer(teamAddress,_earnTokenBalance);
140 | }
141 | }
142 |
143 |
144 | }
145 | //deposit
146 | function deposit(uint256 _amount) external payable whenNotPaused {
147 | require(_amount>0,"invalid amount");
148 | require(getRemaining()>=_amount,"exceed max deposit limit");
149 | //if want is wbnb,need user to deposit bnb
150 | if (want==wbnb){
151 | require(msg.value==_amount,"invalid amount!");
152 | IWbnb(wbnb).deposit{value:msg.value}();
153 | }else{
154 | IERC20(want).safeTransferFrom(msg.sender, address(this), _amount);
155 | }
156 | //deposit token to compound
157 | IERC20(want).safeApprove(cowCtrlAddress, _amount);
158 | ICow(cowCtrlAddress).deposit(want,_amount);
159 | balance=balance.add(_amount);
160 | _mint(msg.sender, _amount);
161 | emit Deposit(msg.sender, _amount);
162 | }
163 | //withdraw
164 | function withdraw(uint256 _amount) external {
165 | require(_amount>0,"invalid amount");
166 | _burn(msg.sender, _amount);
167 | ICow(cowCtrlAddress).withdraw(want,_amount);
168 | if (want==wbnb){
169 | IWbnb(wbnb).withdraw(_amount);
170 | payable(msg.sender).transfer(_amount);
171 | }else{
172 | IERC20(want).safeTransfer(msg.sender, _amount);
173 | }
174 | balance=balance.sub(_amount);
175 | emit Withdraw(msg.sender, _amount);
176 | }
177 |
178 | function pause() external onlyOwner {
179 | _pause();
180 | }
181 | function decimals() public view override returns (uint8) {
182 | return ERC20(want).decimals();
183 | }
184 |
185 |
186 | function unpause() external onlyOwner {
187 | _unpause();
188 | }
189 |
190 | receive() external payable {}
191 | }
192 |
--------------------------------------------------------------------------------