Skip to content

Commit

Permalink
auction change and script change
Browse files Browse the repository at this point in the history
  • Loading branch information
mak2296 committed Sep 14, 2020
1 parent 4803bf7 commit c36cc9d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 55 deletions.
22 changes: 13 additions & 9 deletions constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ const whiteListSecondary = "0x82c2935d9b3F800fb80A167070C38aA835041B98"; // whit

const realEstate = "0xA41A44e6084833f82E73a5edda6Caaf4C206AcC9";

const governance = "0xAb7594A440e3354AFe1f0B9792EFb76Dd90fF71d"; // GovernanceProxy address is here dynamic
const governance = "0x2071195F2071c066853a904F9459A8668f0B3e46"; // GovernanceProxy address is here dynamic
const escrow = "0x352e2708aC8f671a2FE46e244D8255dcd17D7d35"; // dynamic

const gateWay = "0x7f1eAAE18E0CCdb9ECBA86e0bBe3ef76718245C7"; // dynamic

// bancor address
const baseTokenAddress = "0x98474564a00d15989f16bfb7c162c782b0e2b336";// dynamic
const relayTokenAddress = "0x32d9a18826e76afcdc6c9df1ab79bd888ab40d2e";// dynamic
const ethTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; // dynamic
const ethBaseTokenRelayAddress = "0x884058297ec1FfD6C8FA4F9F2d4f066057255a03";// dynamic
const bancorConverterAddress = "0x4eb0845ca823205D16135E64c184bd2B2D591169"; // dynamic
const bancorNetworkAddress = "0xE3042915EeaE7974bFe5a2653911d7fa05003eea";// dynamic

const baseTokenAddress = "0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c";// dynamic
const ethTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; // dynamic

const ethBaseTokenRelayAddress = "0xb1CD6e4153B2a390Cf00A6556b0fC1458C4A5533";// dynamic
const bancorNetworkAddress = "0x2F9EC37d6CcFFf1caB21733BdaDEdE11c823cCB0";// dynamic

// now this two varibale need to chnage after maintoken Deployed we deploy bancor reserve
// and then we get this parameter
const relayTokenAddress = "0x32d9a18826e76afcdc6c9df1ab79bd888ab40d2e";// dynamic
const bancorConverterAddress = "0x4eb0845ca823205D16135E64c184bd2B2D591169"; // dynamic

const baseLinePrice = "1162999999"; // dynamic
const mainTokenHoldBack = 0; // threre is no holdback days
Expand Down Expand Up @@ -75,5 +77,7 @@ module.exports = {
minAuctionTime:minAuctionTime,
intervalTime:intervalTime,
baseLinePrice:baseLinePrice,
realEstate:realEstate
realEstate:realEstate,
gateWay:gateWay,
bancorNetworkAddress:bancorNetworkAddress
}
12 changes: 6 additions & 6 deletions contracts/Auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ contract AuctionFundCollector is IndividualBonus {
{
IERC20Token mainToken = IERC20Token(mainTokenAddress);

uint256 _mainTokenPrice = ICurrencyPrices(currencyPricesAddress)
.getCurrencyPrice(mainTokenAddress);
uint256 _mainTokenPrice = currentMarketPrice;

require(_mainTokenPrice > 0, "ERR_TOKEN_PRICE_NOT_SET");

Expand Down Expand Up @@ -608,11 +607,10 @@ contract Auction is Upgradeable, AuctionFundCollector, AuctionInitializeInterfac
"ERR_MIN_TIME_IS_NOT_OVER"
);

uint256 _mainTokenPrice = ICurrencyPrices(currencyPricesAddress)
.getCurrencyPrice(mainTokenAddress);

_pushEthToLiquidity();

uint256 _mainTokenPrice = currentMarketPrice;

if (todayContribution == 0) {

uint256 _ethPrice = ICurrencyPrices(currencyPricesAddress)
Expand Down Expand Up @@ -878,6 +876,8 @@ contract Auction is Upgradeable, AuctionFundCollector, AuctionInitializeInterfac

}

function() external payable {}
function() external payable {
revert("ERR_CAN'T_FORCE_ETH");
}

}
79 changes: 45 additions & 34 deletions contracts/Liquidity/AuctionLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ contract RegisteryLiquidity is
triggerAddress = getAddressOf(CONTRIBUTION_TRIGGER);
auctionAddress = getAddressOf(AUCTION);
escrowAddress = getAddressOf(ESCROW);

// bancor network
bancorNetwork = addressOf(BANCOR_NETWORK);
}
Expand Down Expand Up @@ -203,7 +203,6 @@ contract LiquidityUtils is RegisteryLiquidity {
return _updateTokenPath();
}


function setSideReseverRatio(uint256 _sideReseverRatio)
public
onlyOwner()
Expand Down Expand Up @@ -541,7 +540,9 @@ contract Liquidity is
lastReserveBalance = IERC20Token(baseToken).balanceOf(converter);
}

function recoverPriceVolatility() external onlySystem() returns (bool) {
function recoverPriceVolatility() external returns (bool) {
_recoverPriceDueToManipulation();

uint256 baseTokenPrice = ICurrencyPrices(currencyPricesAddress)
.getCurrencyPrice(address(baseToken));

Expand Down Expand Up @@ -580,7 +581,6 @@ contract Liquidity is
uint256 volatilty;

uint256 _baseTokenBalance = IERC20Token(baseToken).balanceOf(converter);

bool isMainToken;

if (_baseTokenBalance > lastReserveBalance) {
Expand All @@ -598,11 +598,7 @@ contract Liquidity is
return true;
}

function recoverPriceDueToManipulation()
external
onlySystem()
returns (bool)
{
function recoverPriceDueToManipulation() external returns (bool) {
return _recoverPriceDueToManipulation();
}

Expand Down Expand Up @@ -653,43 +649,51 @@ contract Liquidity is
return _priceRecoveryWithConvertMainToken(_percent);
}
}


// if not have enough ether we sell relay
// exmple reserve have 100 token and we need 25 token to recover
// we need to sell 25% relay
// _amount*100/reserveBalance
// (25*100)/100 so we get 25%
// we multiply it with price PRICE_NOMINATOR so we can get excat amount
function _recoverAfterRedemption(uint256 _amount) internal returns (bool) {
bool isEtherToken = false;

uint256 totalEthAmount = getReturnByPath(ethToBaseToken, _amount);

if (etherTokens(baseToken)) {
isEtherToken = true;
totalEthAmount = _amount;
}

// this change because we convert all base token to ether
if (address(this).balance >= totalEthAmount ) {
if (address(this).balance >= totalEthAmount) {
IBancorNetwork(bancorNetwork).convertByPath.value(totalEthAmount)(
ethToMainToken,
ethToBaseToken,
totalEthAmount,
1,
vaultAddress,
address(0),
address(0),
0
);
return true;

return _convertWithToken(_amount, baseTokenToMainToken);
} else {
uint256 converterBalance = IERC20Token(baseToken).balanceOf(
converter
);

uint256 _tempRelayPercent = relayPercent;
uint256 _tempRelayPercent;

if (converterBalance > _amount) {
_tempRelayPercent = safeDiv(
safeMul(safeSub(converterBalance, _amount), 100),
_amount
safeMul(safeMul(_amount, PRICE_NOMINATOR), 100),
converterBalance
);
if (_tempRelayPercent > 99) _tempRelayPercent = 99;
} else {
_tempRelayPercent = safeMul(relayPercent, PRICE_NOMINATOR);
}
_liquadate(safeMul(_tempRelayPercent, PRICE_NOMINATOR));
_amount = safeSub(_amount, safeDiv(_amount, _tempRelayPercent));

_liquadate(_tempRelayPercent);

_amount = safeSub(
_amount,
safeDiv(safeMul(_amount, PRICE_NOMINATOR), _tempRelayPercent)
);

return _convertWithToken(_amount, baseTokenToMainToken);
}
}
Expand All @@ -716,12 +720,12 @@ contract Liquidity is
address payable _caller,
address payable _reciver
) internal returns (bool) {
require(address(_path[0]) == address(mainToken), "ERR_MAIN_TOKEN");
require(_path[0] == mainToken, "ERR_MAIN_TOKEN");

address primaryWallet = IWhiteList(whiteListAddress).address_belongs(
_reciver
);

uint256 auctionDay = IAuction(auctionAddress).auctionDay();

require(primaryWallet != address(0), "ERR_WHITELIST");
Expand All @@ -736,14 +740,15 @@ contract Liquidity is
if (_beforeBalance != lastReserveBalance) {
_recoverPriceDueToManipulation();
}

ensureTransferFrom(
IERC20Token(_path[0]),
IERC20Token(mainToken),
_caller,
address(this),
_amount
);
approveTransferFrom(IERC20Token(_path[0]), bancorNetwork, _amount);

approveTransferFrom(IERC20Token(mainToken), bancorNetwork, _amount);

uint256 returnAmount = IBancorNetwork(bancorNetwork)
.convertByPath
Expand Down Expand Up @@ -816,18 +821,21 @@ contract Liquidity is
uint256 _mainTokenBalance = IERC20Token(mainToken).balanceOf(
address(this)
);

uint256 _baseTokenBalance = IERC20Token(baseToken).balanceOf(
address(this)
);

uint256 sellRelay = safeDiv(
safeMul(
IERC20Token(relayToken).balanceOf(address(triggerAddress)),
IERC20Token(relayToken).balanceOf(triggerAddress),
_relayPercent
),
safeMul(100, PRICE_NOMINATOR)
);

require(sellRelay > 0, "ERR_RELAY_ZERO");

IContributionTrigger(triggerAddress).transferTokenLiquidity(
IERC20Token(relayToken),
address(this),
Expand Down Expand Up @@ -885,7 +893,9 @@ contract Liquidity is
returns (bool)
{
if (address(_token) == address(0))
IContributionTrigger(triggerAddress).contributeTowardLiquidity(_value);
IContributionTrigger(triggerAddress).contributeTowardLiquidity(
_value
);
else
IContributionTrigger(triggerAddress).transferTokenLiquidity(
_token,
Expand All @@ -909,6 +919,7 @@ contract Liquidity is
vaultAddress,
mainTokenBalance
);
return true;
}

function convertBaseTokenToEth() external returns (bool) {
Expand Down
20 changes: 15 additions & 5 deletions migrations/4_Whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const {
stockMaturityDays,
byPassCode,
escrow,
realEstate
gateWay,
realEstate,
bancorCode,
bancorNetworkAddress
} = require("../constant");


Expand Down Expand Up @@ -76,18 +79,25 @@ module.exports = async function (deployer) {

AuctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);

txHash3 = await whiteListInstance.addNewWallet(ownerWallet,byPassCode, 10, {
await whiteListInstance.addNewWallet(ownerWallet,byPassCode, 10, {
from: whiteListSecondary,
});

txHash3 = await whiteListInstance.addNewWallet(escrow,byPassCode, 10, {
await whiteListInstance.addNewWallet(escrow,byPassCode, 10, {
from: whiteListSecondary,
});

txHash3 = await whiteListInstance.addNewWallet(realEstate,byPassCode, 10, {
await whiteListInstance.addNewWallet(realEstate,byPassCode, 10, {
from: whiteListSecondary,
});

await whiteListInstance.addNewWallet(gateWay,byPassCode, 10, {
from: whiteListSecondary,
});

await whiteListInstance.addNewWallet(bancorNetworkAddress,bancorCode, 10, {
from: whiteListSecondary,
});


await AuctionRegistyInstance.registerContractAddress(
WhiteListCode,
Expand Down
2 changes: 1 addition & 1 deletion migrations/8_Auction_Liquadity.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = async function (deployer) {

LiquadityInstance = await Liquadity.at(LiquadityProxyAddress);

txHash10 = await whiteListInstance.addNewWallet(LiquadityProxyAddress, byPassCode, 0, {
await whiteListInstance.addNewWallet(LiquadityProxyAddress, byPassCode, 0, {
from: whiteListSecondary,
});

Expand Down

0 comments on commit c36cc9d

Please sign in to comment.