Skip to content

Retroactive airdrop linear releases #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d24b48d
Merge pull request #32 from OpenLeverageDev/biswap
Fatel-Dev Apr 7, 2022
9426f18
Merge branch 'main' into kcc
Paul-D-Ant Apr 7, 2022
5d2f35b
Merge pull request #33 from OpenLeverageDev/kcc
Fatel-Dev Apr 12, 2022
9f754c0
update contracts
Paul-D-Ant Apr 12, 2022
e0ea155
Merge pull request #34 from OpenLeverageDev/kcc
Fatel-Dev Apr 12, 2022
636417a
modify xole share fees
Apr 19, 2022
d90589d
Merge pull request #35 from OpenLeverageDev/share-fees
Fatel-Dev Apr 20, 2022
048b9f3
add olelp stake automator
May 30, 2022
a987bc7
fix governor test
May 31, 2022
1938734
add gas log
Jun 1, 2022
1040939
modify xole event
Jun 7, 2022
6f303dd
modify xole min locktime for 2 weeks
Jun 17, 2022
d3e9db5
Merge pull request #40 from OpenLeverageDev/xole-lpstake
Fatel-Dev Jul 4, 2022
82953a5
Update node.js.yml
Fatel-Dev Jul 5, 2022
b0b6770
support limit order
Jul 29, 2022
d999d87
fix move insurance
Aug 1, 2022
588ba2d
Merge branch 'main' into limit-order
Aug 2, 2022
31c053b
add support cronos chain
Paul-D-Ant Aug 3, 2022
79a70d8
add limit-order actions
Aug 16, 2022
ce562bf
add support cronos chain
Paul-D-Ant Aug 17, 2022
f6a6d0c
add cronos batch test
Paul-D-Ant Aug 17, 2022
fefe82c
add cronos batch test
Paul-D-Ant Aug 17, 2022
2bf4795
update verify-script.sh
Paul-D-Ant Aug 19, 2022
84c21eb
update verify-script.sh
Paul-D-Ant Aug 19, 2022
db1297b
add insurance reduce test
Aug 19, 2022
ad0d4b8
Merge branch 'main' into limit-order
Aug 22, 2022
d5892c0
add returns for some functions
Aug 22, 2022
1e3374e
Merge remote-tracking branch 'origin/main' into cronos
Paul-D-Ant Aug 29, 2022
ada457e
add support cronos chain
Paul-D-Ant Aug 31, 2022
19554d1
update LTimePool test
Paul-D-Ant Sep 9, 2022
59856a9
Update LTimePoolTest.js
jimmy-openlev Sep 9, 2022
2e23593
add support cronos chain
Paul-D-Ant Sep 19, 2022
1c102d3
add financing payoff support
Paul-D-Ant Oct 8, 2022
3c6731a
add financing payoff support
Paul-D-Ant Oct 9, 2022
9822f3c
add financing payoff support
Paul-D-Ant Oct 9, 2022
8f2c97d
Merge pull request #47 from OpenLeverageDev/cronos
Paul-D-Ant Oct 9, 2022
a6cc2c8
Merge remote-tracking branch 'origin/dev' into financing_payoff
Paul-D-Ant Oct 9, 2022
d8401d1
Merge pull request #48 from OpenLeverageDev/financing_payoff
Paul-D-Ant Oct 9, 2022
5c95a69
add dev workflow
Paul-D-Ant Oct 9, 2022
f685bad
update dexAgg decimal
Oct 10, 2022
94467ff
Merge branch 'dev' into limit-order
Oct 10, 2022
aad4bad
reduce contract size
Oct 11, 2022
2bac63b
change dexAgg decimal
Oct 11, 2022
bfa8c99
fix test
Oct 11, 2022
13937a6
Merge pull request #50 from OpenLeverageDev/dev
Fatel-Dev Oct 21, 2022
824a1d2
add retroactive airdrop linear releases contract
Paul-D-Ant Oct 25, 2022
91b522e
add retroactive airdrop linear releases contract
Paul-D-Ant Oct 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Node.js CI

on:
push:
branches: [ main, tax-token-support, bsc ]
branches: [ main, tax-token-support, bsc, dev, limit-order, retroactive_airdrop_linear_releases ]
pull_request:
branches: [ main ]

Expand All @@ -29,7 +29,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm init -y
- run: npm install truffle -g
- run: npm install truffle@5.5.2 -g
- run: npm install ganache-cli -g
- run: npm install
- run: truffle compile
Expand Down
17 changes: 16 additions & 1 deletion CONTRACTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,19 @@ OpenLeverage source code is maintained by the Openleverage development team at [
| **TimeLock** | [`0x7B041bD2f676EEd1ab22A17c9eD5b6b3cb794673`](https://bscscan.com/address/0x7B041bD2f676EEd1ab22A17c9eD5b6b3cb794673) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/main/contracts/gov/Timelock.sol |
| **ControllerDelegator** | [`0x912C0462474c933499a6923a6Afc6AC1E58b8Ce4`](https://bscscan.com/address/0x912C0462474c933499a6923a6Afc6AC1E58b8Ce4) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.5-bsc/contracts/ControllerDelegator.sol |
| **DexAggregatorDelegator** | [`0xE9E321D1cb6b540E922a5e4d8720FEed0749e93F`](https://bscscan.com/address/0xE9E321D1cb6b540E922a5e4d8720FEed0749e93F) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.5-bsc/contracts/dex/DexAggregatorDelegator.sol |
| **OpenLevDelegator** | [`0x6A75aC4b8d8E76d15502E69Be4cb6325422833B4`](https://bscscan.com/address/0x6A75aC4b8d8E76d15502E69Be4cb6325422833B4) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.5-bsc/contracts/OpenLevDelegator.sol |
| **OpenLevDelegator** | [`0x6A75aC4b8d8E76d15502E69Be4cb6325422833B4`](https://bscscan.com/address/0x6A75aC4b8d8E76d15502E69Be4cb6325422833B4) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.5-bsc/contracts/OpenLevDelegator.sol |

## KuCoin Community Chain
| Contract | Address | Source Code |
|-----------------------------|------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| **ControllerV1** | [`0x01Af643dD8dD41ed1F1066FAc465cc8bfc52D6EB`](https://scan.kcc.io/address/0x01Af643dD8dD41ed1F1066FAc465cc8bfc52D6EB) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/ControllerV1.sol |
| **kccDexAggregatorV1** | [`0x2Ff5BDEE4EeFd7a3a052dAE9469dDA22f364d686`](https://scan.kcc.io/address/0x2Ff5BDEE4EeFd7a3a052dAE9469dDA22f364d686) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/dex/kcc/KccDexAggregatorV1.sol |
| **LPool** | [`0x15d530E620Da0BACdDBDea7fb37eaaaBB4ae1d07`](https://scan.kcc.io/address/0x15d530E620Da0BACdDBDea7fb37eaaaBB4ae1d07) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/liquidity/LPool.sol |
| **LPoolDepositor** | [`0xC7C3333f713eB2b100Dc6bdC9F79FA43a2A5dDc8`](https://scan.kcc.io/address/0xC7C3333f713eB2b100Dc6bdC9F79FA43a2A5dDc8) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/liquidity/LPoolDepositor.sol |
| **LPoolDepositorDelegator** | [`0xCC25Bcd56E425B13AbB6C8C653C50A1F6Adb7b18`](https://scan.kcc.io/address/0xCC25Bcd56E425B13AbB6C8C653C50A1F6Adb7b18) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/liquidity/LPoolDepositor.sol |
| **OpenLevV1** | [`0x7C0d5BF86427C02F6A841E28Ff7cF2934AA83B34`](https://scan.kcc.io/address/0x7C0d5BF86427C02F6A841E28Ff7cF2934AA83B34) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/OpenLevV1.sol |
| **QueryHelper** | [`0xbd51d161fb4109f2cde5b430ace615fc83062273`](https://scan.kcc.io/address/0xbd51d161fb4109f2cde5b430ace615fc83062273) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/periphery/QueryHelper.sol |
| **TimeLock** | [`0xAd0BFA476FB71215BA026EBE60FfA9b31D98Efe7`](https://scan.kcc.io/address/0xAd0BFA476FB71215BA026EBE60FfA9b31D98Efe7) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/main/contracts/gov/Timelock.sol |
| **ControllerDelegator** | [`0x8A2F01b39319de1dFE219090018B6F460e968e00`](https://scan.kcc.io/address/0x8A2F01b39319de1dFE219090018B6F460e968e00) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/ControllerDelegator.sol |
| **DexAggregatorDelegator** | [`0xc2E51Ab824cC088CB5253E74963B00a15Be7d234`](https://scan.kcc.io/address/0xc2E51Ab824cC088CB5253E74963B00a15Be7d234) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/dex/DexAggregatorDelegator.sol |
| **OpenLevDelegator** | [`0xEF6890d740E1244fEa42E3D1B9Ff515C24c004Ce`](https://scan.kcc.io/address/0xEF6890d740E1244fEa42E3D1B9Ff515C24c004Ce) | https://github.com/OpenLeverageDev/openleverage-contracts/blob/v1.0.7-kcc/contracts/OpenLevDelegator.sol |
176 changes: 176 additions & 0 deletions contracts/OleLpStakeAutomator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "./DelegateInterface.sol";
import "./Adminable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "./OleLpStakeAutomatorInterface.sol";
import "./lib/TransferHelper.sol";

contract OleLpStakeAutomator is DelegateInterface, Adminable, ReentrancyGuard, OleLpStakeAutomatorInterface, OleLpStakeAutomatorStorage {
using TransferHelper for IERC20;
using SafeMath for uint;

function initialize(
XOLEInterface _xole,
IERC20 _ole,
IERC20 _otherToken,
IERC20 _lpToken,
IWETH _nativeToken,
IUniswapV2Router01 _router
) public {
require(msg.sender == admin, "NAD");
xole = _xole;
ole = _ole;
otherToken = _otherToken;
lpToken = _lpToken;
nativeToken = _nativeToken;
router = _router;
}

function createLockBoth(uint oleAmount, uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) external payable override nonReentrant {
transferInBothAndLock(oleAmount, otherAmount, unlockTime, oleMin, otherMin);
}

function createLockOLE(uint oleAmount, uint unlockTime, uint oleMin, uint otherMin) external override nonReentrant {
transferInOleAndLock(oleAmount, unlockTime, oleMin, otherMin);
}

function createLockOther(uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) external payable override nonReentrant {
transferInOtherAndLock(otherAmount, unlockTime, oleMin, otherMin);
}


function increaseAmountBoth(uint oleAmount, uint otherAmount, uint oleMin, uint otherMin) external payable override nonReentrant {
transferInBothAndLock(oleAmount, otherAmount, 0, oleMin, otherMin);
}

function increaseAmountOLE(uint oleAmount, uint oleMin, uint otherMin) external override nonReentrant {
transferInOleAndLock(oleAmount, 0, oleMin, otherMin);
}

function increaseAmountOther(uint otherAmount, uint oleMin, uint otherMin) external payable override nonReentrant {
transferInOtherAndLock(otherAmount, 0, oleMin, otherMin);
}


function withdrawBoth(uint oleMin, uint otherMin) external override nonReentrant {
(uint oleOut, uint otherOut) = removeLiquidity(oleMin, otherMin);
doTransferOut(msg.sender, ole, oleOut);
doTransferOut(msg.sender, otherToken, otherOut);
}

function withdrawOle(uint oleMin, uint otherMin) external override nonReentrant {
(uint oleOut, uint otherOut) = removeLiquidity(oleMin, otherMin);
//swap
otherToken.safeApprove(address(router), otherOut);
uint[] memory amounts = router.swapExactTokensForTokens(otherOut, 0, getPath(ole), address(this), timestamp());
uint oleSwapIn = amounts[1];
doTransferOut(msg.sender, ole, oleOut.add(oleSwapIn));
}

function withdrawOther(uint oleMin, uint otherMin) external override nonReentrant {
(uint oleOut, uint otherOut) = removeLiquidity(oleMin, otherMin);
//swap
ole.safeApprove(address(router), oleOut);
uint[] memory amounts = router.swapExactTokensForTokens(oleOut, 0, getPath(otherToken), address(this), timestamp());
uint otherSwapIn = amounts[1];
doTransferOut(msg.sender, otherToken, otherOut.add(otherSwapIn));
}

function transferInBothAndLock(uint oleAmount, uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) internal {
// transferIn
uint oleIn = transferIn(msg.sender, ole, oleAmount);
uint otherIn = transferIn(msg.sender, otherToken, otherAmount);
// add liquidity and increase amount
addLiquidityAndLock(oleIn, otherIn, unlockTime, oleMin, otherMin);
}

function transferInOleAndLock(uint oleAmount, uint unlockTime, uint oleMin, uint otherMin) internal {
// transferIn
uint oleIn = transferIn(msg.sender, ole, oleAmount);
// swap
uint oleSwapOut = oleIn.div(2);
ole.safeApprove(address(router), oleSwapOut);
uint[] memory amounts = router.swapExactTokensForTokens(oleSwapOut, 0, getPath(otherToken), address(this), timestamp());
uint otherIn = amounts[1];
// add liquidity and create lock
addLiquidityAndLock(oleIn.sub(oleSwapOut), otherIn, unlockTime, oleMin, otherMin);
}

function transferInOtherAndLock(uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) internal {
// transferIn
uint otherIn = transferIn(msg.sender, otherToken, otherAmount);
// swap
uint otherSwapOut = otherIn.div(2);
otherToken.safeApprove(address(router), otherSwapOut);
uint[] memory amounts = router.swapExactTokensForTokens(otherSwapOut, 0, getPath(ole), address(this), timestamp());
uint oleIn = amounts[1];
// add liquidity and create lock
addLiquidityAndLock(oleIn, otherIn.sub(otherSwapOut), unlockTime, oleMin, otherMin);
}

function addLiquidityAndLock(uint oleIn, uint otherIn, uint unlockTime, uint oleMin, uint otherMin) internal {
// add liquidity
ole.safeApprove(address(router), oleIn);
otherToken.safeApprove(address(router), otherIn);
(uint oleOut, uint otherOut, uint liquidity) = router.addLiquidity(address(ole), address(otherToken), oleIn, otherIn, oleMin, otherMin, address(this), timestamp());
// create lock
lpToken.safeApprove(address(xole), liquidity);
if (unlockTime > 0) {
xole.create_lock_for(msg.sender, liquidity, unlockTime);
} else {
xole.increase_amount_for(msg.sender, liquidity);
}
// back remainder
if (oleIn > oleOut) {
doTransferOut(msg.sender, ole, oleIn - oleOut);
}
if (otherIn > otherOut) {
doTransferOut(msg.sender, otherToken, otherIn - otherOut);
}
}

function removeLiquidity(uint oleMin, uint otherMin) internal returns (uint oleOut, uint otherOut){
//withdraw
xole.withdraw_automator(msg.sender);
uint liquidity = lpToken.balanceOf(address(this));
lpToken.safeApprove(address(router), liquidity);
//remove liquidity
(oleOut, otherOut) = router.removeLiquidity(address(ole), address(otherToken), liquidity, oleMin, otherMin, address(this), timestamp());
}

function transferIn(address from, IERC20 token, uint amount) internal returns (uint) {
if (isNativeToken(token)) {
nativeToken.deposit{value : msg.value}();
return msg.value;
} else {
return token.safeTransferFrom(from, address(this), amount);
}
}

function doTransferOut(address to, IERC20 token, uint amount) internal {
if (isNativeToken(token)) {
nativeToken.withdraw(amount);
(bool success,) = to.call{value : amount}("");
require(success);
} else {
token.safeTransfer(to, amount);
}
}

function isNativeToken(IERC20 token) internal view returns (bool) {
return address(token) == address(nativeToken);
}

function getPath(IERC20 destToken) internal view returns (address[] memory path) {
path = new address[](2);
path[0] = address(destToken) == address(ole) ? address(otherToken) : address(ole);
path[1] = address(destToken) == address(ole) ? address(ole) : address(otherToken);
}

function timestamp() internal view returns (uint){
return block.timestamp;
}
}

42 changes: 42 additions & 0 deletions contracts/OleLpStakeAutomatorDelegator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "./Adminable.sol";
import "./DelegatorInterface.sol";


contract OleLpStakeAutomatorDelegator is DelegatorInterface, Adminable {

constructor(address _xole,
address _ole,
address _otherToken,
address _lpToken,
address _nativeToken,
address _router,
address payable admin_,
address implementation_) {
admin = msg.sender;
// Creator of the contract is admin during initialization
// First delegate gets to initialize the delegator (i.e. storage contract)
delegateTo(implementation_, abi.encodeWithSignature("initialize(address,address,address,address,address,address)",
_xole,
_ole,
_otherToken,
_lpToken,
_nativeToken,
_router));
implementation = implementation_;
// Set the proper admin now that initialization is done
admin = admin_;
}

/**
* Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
*/
function setImplementation(address implementation_) public override onlyAdmin {
address oldImplementation = implementation;
implementation = implementation_;
emit NewImplementation(oldImplementation, implementation);
}
}
41 changes: 41 additions & 0 deletions contracts/OleLpStakeAutomatorInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.7.6;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol';
import "./XOLEInterface.sol";
import "./IWETH.sol";

contract OleLpStakeAutomatorStorage {
XOLEInterface public xole;
IERC20 public ole;
IERC20 public otherToken;
IERC20 public lpToken;
IWETH public nativeToken;
IUniswapV2Router01 router;
}

interface OleLpStakeAutomatorInterface {

function createLockBoth(uint oleAmount, uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) external payable;

function createLockOLE(uint oleAmount, uint unlockTime, uint oleMin, uint otherMin) external ;

function createLockOther(uint otherAmount, uint unlockTime, uint oleMin, uint otherMin) external payable;


function increaseAmountBoth(uint oleAmount, uint otherAmount, uint oleMin, uint otherMin) external payable;

function increaseAmountOLE(uint oleAmount, uint oleMin, uint otherMin) external ;

function increaseAmountOther(uint otherAmount, uint oleMin, uint otherMin) external payable;


function withdrawBoth(uint oleMin, uint otherMin) external;

function withdrawOle(uint oleMin, uint otherMin) external;

function withdrawOther(uint oleMin, uint otherMin) external;


}
21 changes: 13 additions & 8 deletions contracts/OpenLevInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract contract OpenLevStorage {
mapping(address => mapping(uint16 => mapping(bool => Types.Trade))) public activeTrades;

//useless
mapping(address => bool) public allowedDepositTokens;
mapping(address => bool) internal allowedDepositTokens;

CalculateConfig public calculateConfig;

Expand All @@ -59,6 +59,8 @@ abstract contract OpenLevStorage {
// map(marketId, tokenAddress, index) => taxRate)
mapping(uint16 => mapping(address => mapping(uint => uint24))) public taxes;

address public opLimitOrder;

event MarginTrade(
address trader,
uint16 marketId,
Expand Down Expand Up @@ -135,21 +137,22 @@ interface OpenLevInterface {
) external returns (uint16);


function marginTrade(uint16 marketId, bool longToken, bool depositToken, uint deposit, uint borrow, uint minBuyAmount, bytes memory dexData) external payable;
function marginTrade(uint16 marketId, bool longToken, bool depositToken, uint deposit, uint borrow, uint minBuyAmount, bytes memory dexData) external payable returns (uint256);

function marginTradeFor(address trader, uint16 marketId, bool longToken, bool depositToken, uint deposit, uint borrow, uint minBuyAmount, bytes memory dexData) external payable returns (uint256);

function closeTrade(uint16 marketId, bool longToken, uint closeAmount, uint minOrMaxAmount, bytes memory dexData) external returns (uint256);

function closeTradeFor(address trader, uint16 marketId, bool longToken, uint closeHeld, uint minOrMaxAmount, bytes memory dexData) external returns (uint256);

function closeTrade(uint16 marketId, bool longToken, uint closeAmount, uint minOrMaxAmount, bytes memory dexData) external;
function payoffTrade(uint16 marketId, bool longToken) external payable;

function liquidate(address owner, uint16 marketId, bool longToken, uint minBuy, uint maxAmount, bytes memory dexData) external;

function marginRatio(address owner, uint16 marketId, bool longToken, bytes memory dexData) external view returns (uint current, uint cAvg, uint hAvg, uint32 limit);

function updatePrice(uint16 marketId, bytes memory dexData) external;

function shouldUpdatePrice(uint16 marketId, bytes memory dexData) external view returns (bool);

function getMarketSupportDexs(uint16 marketId) external view returns (uint32[] memory);

// function getCalculateConfig() external view returns (OpenLevStorage.CalculateConfig memory);

/*** Admin Functions ***/
function setCalculateConfig(uint16 defaultFeesRate, uint8 insuranceRatio, uint16 defaultMarginLimit, uint16 priceDiffientRatio,
Expand All @@ -165,4 +168,6 @@ interface OpenLevInterface {

function setTaxRate(uint16 marketId, address token, uint index, uint24 tax) external;

function setOpLimitOrder(address _opLimitOrder) external;

}
Loading