├── .gitignore
├── README.md
├── constant.js
├── contracts
├── Auction
│ ├── Auction.sol
│ ├── AuctionProxy.sol
│ └── AuctionStorage.sol
├── InterFaces
│ ├── IAuction.sol
│ ├── IAuctionLiquidity.sol
│ ├── IAuctionProtection.sol
│ ├── IAuctionRegistery.sol
│ ├── IBEP20Token.sol
│ ├── IContributionTrigger.sol
│ ├── ICurrencyPrices.sol
│ ├── IEscrow.sol
│ ├── IToken.sol
│ ├── ITokenVault.sol
│ └── IWhiteList.sol
├── Liquidity
│ ├── AuctionLiquidity.sol
│ ├── LiquidityProxy.sol
│ └── LiquidityStorage.sol
├── Migrations.sol
├── Pricing
│ ├── CurrencyPrice.sol
│ └── PriceTracker.sol
├── Protection
│ ├── AuctionProtection.sol
│ ├── ProtectionProxy.sol
│ └── ProtectionStorage.sol
├── Proxy
│ ├── IRegistry.sol
│ ├── Proxy.sol
│ ├── UpgradeabilityProxy.sol
│ ├── UpgradeabilityStorage.sol
│ └── Upgradeable.sol
├── TokenVault
│ ├── TokenVault.sol
│ ├── TokenVaultProxy.sol
│ └── TokenVaultStorage.sol
├── Tokens
│ ├── EtnToken.sol
│ ├── Exchangeable.sol
│ ├── IBEP20.sol
│ ├── MainToken.sol
│ ├── StandardToken.sol
│ ├── StockToken.sol
│ └── TokenUtils.sol
├── WhiteList
│ ├── README.md
│ ├── WhiteList.sol
│ ├── WhiteListProxy.sol
│ └── WhiteListStorage.sol
├── auctionContracts
│ └── AuctionRegistery.sol
├── common
│ ├── Constant.sol
│ ├── MultiSigGovernance.sol
│ ├── Ownable.sol
│ ├── ProxyOwnable.sol
│ ├── SafeMath.sol
│ └── TokenTransfer.sol
├── contributionTrigger
│ ├── ContributionTrigger.sol
│ └── ContributionTriggerProxy.sol
└── test
│ ├── TestAuction.sol
│ ├── TestAuctionRegistery.sol
│ ├── TestCurrencyPrices.sol
│ ├── TestEscrow.sol
│ └── TestIBEP20Token.sol
├── latestContract.json
├── migrations
├── 10_auction_protection.js
├── 11_update_code.js
├── 12_transfer_onwerShip.js
├── 1_initial_migration.js
├── 2_Auction_Registery.js
├── 3_Currency_price.js
├── 4_Whitelist.js
├── 5_MainToken.js
├── 6_Token_Vault.js
├── 7_Tag_Along.js
├── 8_Auction_Liquadity.js
└── 9_Auction.js
├── package-lock.json
├── package.json
└── test
├── AuctionTagAlongTests.js
├── AuctionTests.js
├── LiquidityTests.js
├── OwnableTest.js
├── ProtectionTests.js
├── TokenVaultTests.js
├── TokensSpecificTest.js
├── WhitelistTests.js
├── bancorArtifacts
├── BancorConverter.json
├── BancorConverterFactory.json
├── BancorConverterRegistry.json
├── BancorConverterRegistryData.json
├── BancorConverterUpgrader.json
├── BancorFormula.json
├── BancorGasPriceLimit.json
├── BancorNetwork.json
├── BancorNetworkPathFinder.json
├── BancorPriceFloor.json
├── BancorX.json
├── ContractFeatures.json
├── ContractRegistry.json
├── ContractRegistryClient.json
├── CrowdsaleController.json
├── ERC20Token.json
├── EtherToken.json
├── FeatureIds.json
├── IBancorConverter.json
├── IBancorConverterExtended.json
├── IBancorConverterFactory.json
├── IBancorConverterRegistry.json
├── IBancorConverterRegistryData.json
├── IBancorConverterUpgrader.json
├── IBancorFormula.json
├── IBancorNetwork.json
├── IBancorX.json
├── IBancorXUpgrader.json
├── IContractFeatures.json
├── IContractRegistry.json
├── IERC20Token.json
├── IEtherToken.json
├── INonStandardERC20.json
├── IOwned.json
├── ISmartToken.json
├── ISmartTokenController.json
├── ITokenHolder.json
├── IWhitelist.json
├── Migrations.json
├── NewBancorConverter.json
├── NonStandardERC20Token.json
├── NonStandardSmartToken.json
├── OldBancorConverter.json
├── Owned.json
├── SafeMath.json
├── SmartToken.json
├── SmartTokenController.json
├── TestBancorFormula.json
├── TestBancorNetwork.json
├── TestCrowdsaleController.json
├── TestFeatures.json
├── TestNonStandardERC20Token.json
├── TestSafeMath.json
├── TokenHolder.json
├── Utils.json
├── Whitelist.json
└── XTransferRerouter.json
├── deployBancor.js
├── multiSigTest.js
└── utils.js
/.gitignore:
--------------------------------------------------------------------------------
1 | build/contracts
2 | node_modules
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Jointer is a decentralized financial (DeFi) and property technology (PropTech) based on Decentralized Autonomous Organization (DAO) established in 2017 in Silicon Valley, CA and expanded to include Tel Aviv, Israel. Jointer has invested talent, resources, and funds to build an alternative to Commercial Real Estate syndication, scaling the needs of investors and owners in a complete and independent end-to-end blockchain syndication and investment solution.
2 | Jointer is a multi-award winning company, including:
3 | - A $1,000,000 “Best Startup in the World” prize in 2018 during a worldwide competition between 4,000 startups and 196 countries
4 | - Winner of the Disruptive Startup Award at Stanford University in 2019 by a panel of Google, SoftBank, Bain Capital, Thomson Reuters, Stanford Angels, BMW, Andreessen, NEA, and other top VC Funds,
5 | - First place for the Disruptor Daily “Blockchain in Real Estate” Disruptor Award,
6 | - Most promising venture from the Carnegie Mellon University US-China Innovation and Entrepreneurship Association
7 |
8 | In addition to Draper Venture Network inclusion, Jointer’s prestigious advisory group includes Nobel Prize Winners, the previous Chairman of the SEC, the previous Vice Chairman of the NASDAQ, founder of Visa, the previous Chief Economist of the U.S. Department of State, founder of LA Blockchain Summit (CIS), the CFO of Yahoo, the co-creator of Bitcoin’s prototype, and other luminaries.
9 |
10 | Through years of work, Jointer has created a decentralized fund of funds syndication economy utilizing the blockchain while providing uncorrelated returns, diversification, and unlimited liquidity. The syndication economy is powered by a world’s first patent-pending multilayer system that helps to increase the company’s valuation daily while preventing a value decrease, regardless of market volatility or manipulation. This syndication economy system can be applied to a multitude of industries, including insurance, venture capital, and many more. Jointer’s first use case will be commercial real estate.
11 |
--------------------------------------------------------------------------------
/constant.js:
--------------------------------------------------------------------------------
1 |
2 | //tesnet Adderss
3 | // const ownerWallet = "0xC3BdAF7a7740bF1cCA06eB5ed479EBFF1153773B"; // wallet #1
4 | // const auctionSecondary = "0x58f06b0eA4F92750999e024e75D13dA7A06ab079"; // wallet #2
5 | // const otherSecondary = "0xb511de8f9A4B1A66D1d63125089A55bD299f0c0a"; // wallet #3
6 | // const whiteListSecondary = "0x68bC87e4Ac145b33D917f6CEAB7AdcF398F90771"; // white list wallet
7 |
8 |
9 |
10 | //have to chanage according
11 | const ownerWallet = "0xD99634a54e2295f23d4DBD5B004f73D4ed0474F5"; // wallet #1
12 | const auctionSecondary = "0xc56975a27B5cBfbc31eDAcbf0ffd9d0c9b3A77c4"; // wallet #2
13 | const otherSecondary = "0x04a88313d287ABfd1ef62C8561dDFde09510b9Ca"; // wallet #3
14 | const whiteListSecondary = "0x82c2935d9b3F800fb80A167070C38aA835041B98"; // white list wallet
15 |
16 | // for bep20
17 | const mainTokenOwner = "0x154A7eD86F3CceECfb54fD03034b3311D102399e";
18 |
19 |
20 | // {
21 | // "Escrow": "0x72dC50F76c5982004e311086F44f80d9f325C5A1",
22 | // "EscrowedGovernance": "0x338a0dC9A3693D5d007db1CBbDadEE88828fc2F8",
23 | // "EscrowedGovernanceProxy": "0x2662Bb4cF85B0be7e151072ee404033DAcBbc746",
24 | // "Governance": "0xD4618DF62d8e1a179385cD68fB13214e4251835d",
25 | // "GovernanceProxy": "0x756D25558130dcaAaD42e4e73F91A4Ed9ed30bb8",
26 | // "Gateway": "0x7AD320b5EFe4e5287c84e5b46ba66b0Fbf77B7d4",
27 | // "RealEstate": "0xfB3497CD9ef268e1364593D7496f67B7B1e06B7c"
28 | // }
29 | const realEstate = "0xfB3497CD9ef268e1364593D7496f67B7B1e06B7c";
30 | const governance = "0x756D25558130dcaAaD42e4e73F91A4Ed9ed30bb8"; // GovernanceProxy address is here dynamic
31 | const escrow = "0x72dC50F76c5982004e311086F44f80d9f325C5A1"; // dynamic
32 | const gateWay = "0x7AD320b5EFe4e5287c84e5b46ba66b0Fbf77B7d4"; // dynamic
33 |
34 | // pool address
35 | const factoryAddress = "0x0Ff8C7a97A2ec6cCfb472Cf6F13271512C1d791E";
36 | const baseTokenAddress = "0x0000000000000000000000000000000000000001";// dynamic
37 | const poolAddress = "0x65C29F0C82Ab7e3b30c819c86eD1f00Cd42b201D";// dynamic
38 |
39 | //0x3fD4D76105E03851328Df84918cF6eF916F88f6A factory
40 |
41 |
42 | const baseLinePrice = "28400000000"; // dynamic
43 | const mainTokenHoldBack = 0; // threre is no holdback days
44 | const etnTokenHoldBack = 0;
45 | const stockTokenHoldBack = 0;
46 | const mainMaturityDays = 0; // threre is no maturityDays
47 | const etnMaturityDays = 0;
48 | const stockMaturityDays = 0;
49 |
50 | const mainTokenName = "Jointer";
51 | const mainTokenSymbol = "JNTR";
52 |
53 | const preMintAddress = [escrow,ownerWallet];
54 |
55 | const preMintAmount = ["11927121908469559000000000000","100000000000000000000000"];
56 |
57 | const byPassCode = 20483;
58 | const poolCode = 8195;
59 |
60 | const starTime = 1602936000;
61 | const minAuctionTime = 82800;
62 | const intervalTime = 86400;
63 | const mainTokenCheckDay = 58;
64 |
65 | module.exports = {
66 | governance:governance,
67 | ownerWallet:ownerWallet,
68 | otherSecondary:otherSecondary,
69 | whiteListSecondary:whiteListSecondary,
70 | auctionSecondary:auctionSecondary,
71 | mainTokenHoldBack:mainTokenHoldBack,
72 | etnTokenHoldBack:etnTokenHoldBack,
73 | stockTokenHoldBack:stockTokenHoldBack,
74 | mainMaturityDays:mainMaturityDays,
75 | etnMaturityDays:etnMaturityDays,
76 | stockMaturityDays:stockMaturityDays,
77 | byPassCode:byPassCode,
78 | poolCode:poolCode,
79 | mainTokenName:mainTokenName,
80 | mainTokenSymbol:mainTokenSymbol,
81 | preMintAddress:preMintAddress,
82 | preMintAmount:preMintAmount,
83 | baseTokenAddress:baseTokenAddress,
84 | poolAddress:poolAddress,
85 | escrow:escrow,
86 | mainTokenCheckDay:mainTokenCheckDay,
87 | starTime : starTime,
88 | minAuctionTime:minAuctionTime,
89 | intervalTime:intervalTime,
90 | baseLinePrice:baseLinePrice,
91 | realEstate:realEstate,
92 | gateWay:gateWay,
93 | mainTokenOwner:mainTokenOwner,
94 | factoryAddress:factoryAddress
95 | }
--------------------------------------------------------------------------------
/contracts/Auction/AuctionProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../Proxy/IRegistry.sol";
4 | import "../common/Ownable.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 | import "../InterFaces/IBEP20Token.sol";
7 |
8 | interface AuctionProxyInitializeInterface {
9 | function initialize(
10 | uint256 _startTime,
11 | uint256 _minAuctionTime,
12 | uint256 _interval,
13 | uint256 _mainTokenCheckDay,
14 | address _primaryOwner,
15 | address _systemAddress,
16 | address _multisigAddress,
17 | address _registryaddress
18 | ) external;
19 | }
20 |
21 | /**
22 | * @title Registry
23 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
24 | */
25 | contract AuctionProxyRegistry is Ownable, IRegistry {
26 | // Mapping of versions to implementations of different functions
27 | mapping(uint256 => address) internal versions;
28 |
29 | uint256 public currentVersion;
30 |
31 | address payable public proxyAddress;
32 |
33 | //@dev constructor
34 | //@param _systemAddress address of the system Owner
35 | constructor(address _systemAddress, address _multisigAddress)
36 | public
37 | Ownable(_systemAddress, _multisigAddress)
38 | {}
39 |
40 | /**
41 | * @dev Registers a new version with its implementation address
42 | * @param version representing the version name of the new implementation to be registered
43 | * @param implementation representing the address of the new implementation to be registered
44 | */
45 | function addVersion(uint256 version, address implementation)
46 | public
47 | onlyOneOfOnwer()
48 | notZeroAddress(implementation)
49 | {
50 | require(
51 | versions[version] == address(0),
52 | "This version has implementation attached"
53 | );
54 | versions[version] = implementation;
55 | emit VersionAdded(version, implementation);
56 | }
57 |
58 | /**
59 | * @dev Tells the address of the implementation for a given version
60 | * @param version to query the implementation of
61 | * @return address of the implementation registered for the given version
62 | */
63 | function getVersion(uint256 version) public view returns (address) {
64 | return versions[version];
65 | }
66 |
67 | /**
68 | * @dev Creates an upgradeable proxy
69 | * @param version representing the first version to be set for the proxy
70 | * @return address of the new proxy created
71 | */
72 | function createProxy(
73 | uint256 version,
74 | uint256 _startTime,
75 | uint256 _minAuctionTime,
76 | uint256 _interval,
77 | uint256 _mainTokenCheckDay,
78 | address _primaryOwner,
79 | address _systemAddress,
80 | address _multisigAddress,
81 | address _registryaddress
82 | ) external onlyOneOfOnwer() returns (address) {
83 | require(proxyAddress == address(0), "ERR_PROXY_ALREADY_CREATED");
84 |
85 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
86 |
87 | AuctionProxyInitializeInterface(address(proxy)).initialize(
88 | _startTime,
89 | _minAuctionTime,
90 | _interval,
91 | _mainTokenCheckDay,
92 | _primaryOwner,
93 | _systemAddress,
94 | _multisigAddress,
95 | _registryaddress
96 | );
97 |
98 | currentVersion = version;
99 | proxyAddress = address(proxy);
100 | emit ProxyCreated(address(proxy));
101 | return address(proxy);
102 | }
103 |
104 | /**
105 | * @dev Upgrades the implementation to the requested version
106 | * @param version representing the version name of the new implementation to be set
107 | */
108 |
109 | function upgradeTo(uint256 version) public onlyAuthorized() returns (bool) {
110 | require(
111 | versions[version] != address(0),
112 | "ERR_ZERO_ADDDRESS"
113 | );
114 | currentVersion = version;
115 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
116 | return true;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/contracts/Auction/AuctionStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "../InterFaces/IAuctionRegistery.sol";
3 |
4 | contract AuctionStorage {
5 | IAuctionRegistery public contractsRegistry;
6 |
7 | address payable public whiteListAddress;
8 | address payable public smartSwapAddress;
9 | address payable public currencyPricesAddress;
10 | address payable public vaultAddress;
11 | address payable public mainTokenAddress;
12 | address payable public liquidityAddress;
13 | address payable public companyFundWalletAddress;
14 | address payable public escrowAddress;
15 | address payable public auctionProtectionAddress;
16 |
17 | uint256 public constant PRICE_NOMINATOR = 10**9;
18 |
19 | uint256 public constant DECIMAL_NOMINATOR = 10**18;
20 |
21 | uint256 public constant PERCENT_NOMINATOR = 10**6;
22 |
23 | // allowed contarct limit the contribution
24 | uint256 public maxContributionAllowed;
25 | // managment fee to run auction cut from basesupply
26 | uint256 public managementFee;
27 | // staking percentage
28 | uint256 public staking;
29 | // fund that will be locked in contacrt
30 | uint256 public downSideProtectionRatio;
31 | // Fund goes to companyWallet
32 | uint256 public fundWalletRatio;
33 | // if contribution reach above yesterdayContribution groupBonus multiplyer
34 | uint256 public groupBonusRatio;
35 | // user neeed this amount of mainToken to contribute
36 | uint256 public mainTokenRatio;
37 |
38 | //from which day mainTokenCheck start
39 | uint256 public mainTokencheckDay;
40 | // current auctionday
41 | uint256 public auctionDay;
42 | // current totalContribution
43 | uint256 public totalContribution;
44 | // today total contributiton
45 | uint256 public todayContribution;
46 | // yesterday's contribution
47 | uint256 public yesterdayContribution;
48 | // allowed max contribution in a day
49 | uint256 public allowMaxContribution;
50 | // yesterday token Supply
51 | uint256 public yesterdaySupply;
52 | // today token supply
53 | uint256 public todaySupply;
54 |
55 | uint256 public averageDay;
56 |
57 | bool public directPushToLiquidity;
58 |
59 | // address how much invested by them in auciton till date
60 | mapping(address => uint256) public userTotalFund;
61 |
62 | // how much token recived by address in auciton till date
63 | mapping(address => uint256) public userTotalReturnToken;
64 |
65 | // day wise supply (groupBounus+coreSupply)
66 | mapping(uint256 => uint256) public dayWiseSupply;
67 |
68 | // day wise coreSupply
69 | mapping(uint256 => uint256) public dayWiseSupplyCore;
70 |
71 | // day wise bonusSupply
72 | mapping(uint256 => uint256) public dayWiseSupplyBonus;
73 |
74 | // daywise contribution
75 | mapping(uint256 => uint256) public dayWiseContribution;
76 |
77 | // daywise markertPrice
78 | mapping(uint256 => uint256) public dayWiseMarketPrice;
79 |
80 | // dayWise downsideProtection Ratio
81 | mapping(uint256 => uint256) public dayWiseDownSideProtectionRatio;
82 |
83 | // address wise contribution each day
84 | mapping(uint256 => mapping(address => uint256))
85 | public walletDayWiseContribution;
86 |
87 | // daywise contribution
88 | mapping(uint256 => mapping(address => uint256))
89 | public mainTokenCheckDayWise;
90 |
91 | // return index of user for bonus
92 | mapping(uint256 => uint256) public indexReturn;
93 |
94 | // day wiser five top contributor
95 | mapping(uint256 => mapping(uint256 => address)) public topFiveContributor;
96 |
97 | //contributor Index
98 | mapping(uint256 => mapping(address => uint256)) public topContributorIndex;
99 |
100 | // check if daywise token disturbuted
101 | mapping(uint256 => mapping(address => bool)) public returnToken;
102 |
103 | uint256 public MIN_AUCTION_END_TIME; //epoch
104 |
105 | uint256 public LAST_AUCTION_START;
106 |
107 | uint256 public INTERVAL;
108 |
109 | uint256 public currentMarketPrice;
110 |
111 | event FundAdded(
112 | uint256 indexed _auctionDayId,
113 | uint256 _todayContribution,
114 | address indexed _fundBy,
115 | address indexed _fundToken,
116 | uint256 _fundAmount,
117 | uint256 _fundValue,
118 | uint256 _totalFund,
119 | uint256 _marketPrice
120 | );
121 |
122 | event FundAddedBehalf(address indexed _caller, address indexed _recipient);
123 |
124 | event AuctionEnded(
125 | uint256 indexed _auctionDayId,
126 | uint256 _todaySupply,
127 | uint256 _yesterdaySupply,
128 | uint256 _todayContribution,
129 | uint256 _yesterdayContribution,
130 | uint256 _totalContribution,
131 | uint256 _maxContributionAllowed,
132 | uint256 _tokenPrice,
133 | uint256 _tokenMarketPrice
134 | );
135 |
136 | event FundDeposited(address _token, address indexed _from, uint256 _amount);
137 |
138 | event TokenDistrubuted(
139 | address indexed _whom,
140 | uint256 indexed dayId,
141 | uint256 _totalToken,
142 | uint256 lockedToken,
143 | uint256 _userToken
144 | );
145 |
146 | }
--------------------------------------------------------------------------------
/contracts/InterFaces/IAuction.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface IAuction {
4 |
5 | function dayWiseMarketPrice(uint256 dayId) external view returns(uint256);
6 |
7 | function dayWiseContribution(uint256 dayId) external view returns(uint256);
8 |
9 | function auctionDay() external returns(uint256);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IAuctionLiquidity.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "./IBEP20Token.sol";
3 |
4 | interface IAuctionLiquidity {
5 | function contributeWithEther() external payable returns (uint256);
6 |
7 | function auctionEnded() external returns (bool);
8 |
9 | function contributeTowardMainReserve() external returns (uint256);
10 | }
11 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IAuctionProtection.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./IBEP20Token.sol";
4 |
5 | interface IAuctionProtection {
6 | function lockEther(uint256 _auctionDay,address _which)
7 | external
8 | payable
9 | returns (bool);
10 |
11 | function stackFund(uint256 _amount)
12 | external
13 | returns (bool);
14 |
15 | function depositToken(
16 | uint256 _auctionDay,
17 | address _which,
18 | uint256 _amount
19 | ) external returns (bool);
20 |
21 | function unLockTokens() external returns (bool);
22 | }
--------------------------------------------------------------------------------
/contracts/InterFaces/IAuctionRegistery.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | contract AuctionRegisteryContracts {
4 | bytes32 internal constant MAIN_TOKEN = "MAIN_TOKEN";
5 | bytes32 internal constant ETN_TOKEN = "ETN_TOKEN";
6 | bytes32 internal constant STOCK_TOKEN = "STOCK_TOKEN";
7 | bytes32 internal constant WHITE_LIST = "WHITE_LIST";
8 | bytes32 internal constant AUCTION = "AUCTION";
9 | bytes32 internal constant AUCTION_PROTECTION = "AUCTION_PROTECTION";
10 | bytes32 internal constant LIQUIDITY = "LIQUIDITY";
11 | bytes32 internal constant CURRENCY = "CURRENCY";
12 | bytes32 internal constant VAULT = "VAULT";
13 | bytes32 internal constant CONTRIBUTION_TRIGGER = "CONTRIBUTION_TRIGGER";
14 | bytes32 internal constant COMPANY_FUND_WALLET = "COMPANY_FUND_WALLET";
15 | bytes32 internal constant SMART_SWAP = "SMART_SWAP";
16 | bytes32 internal constant SMART_SWAP_P2P = "SMART_SWAP_P2P";
17 | bytes32 internal constant ESCROW = "ESCROW";
18 | }
19 |
20 | interface IAuctionRegistery {
21 | function getAddressOf(bytes32 _contractName)
22 | external
23 | view
24 | returns (address payable);
25 | }
26 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IBEP20Token.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 |
4 | interface IBEP20Token {
5 | function name() external view returns (string memory);
6 |
7 | function symbol() external view returns (string memory);
8 |
9 | function decimals() external view returns (uint8);
10 |
11 | function totalSupply() external view returns (uint256);
12 |
13 | function balanceOf(address _owner) external view returns (uint256);
14 |
15 | function allowance(address _owner, address _spender)
16 | external
17 | view
18 | returns (uint256);
19 |
20 | function transfer(address _to, uint256 _value) external returns (bool);
21 |
22 | function transferFrom(
23 | address _from,
24 | address _to,
25 | uint256 _value
26 | ) external returns (bool);
27 |
28 | function approve(address _spender, uint256 _value) external returns (bool);
29 | }
30 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IContributionTrigger.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./IBEP20Token.sol";
4 |
5 | interface IContributionTrigger {
6 | function depositeToken(
7 | IBEP20Token _token,
8 | address _from,
9 | uint256 _amount
10 | ) external returns (bool);
11 |
12 | function contributeTowardLiquidity(uint256 _amount)
13 | external
14 | returns (uint256);
15 |
16 | function transferTokenLiquidity(
17 | IBEP20Token _token,
18 | address _reciver,
19 | uint256 _amount
20 | ) external returns (bool);
21 | }
22 |
--------------------------------------------------------------------------------
/contracts/InterFaces/ICurrencyPrices.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface ICurrencyPrices {
4 | function getCurrencyPrice(address _which) external view returns (uint256);
5 | }
6 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IEscrow.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface IEscrow {
4 | function depositFee(uint256 value) external returns (bool);
5 | }
6 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface IToken {
4 | function mintTokens(uint256 _amount) external returns (bool);
5 |
6 | function buyTokens(address _fromToken, uint256 _amount)
7 | external
8 | returns (uint256);
9 |
10 | function burn(uint256 _value) external returns (bool);
11 |
12 | function lockToken(
13 | address _which,
14 | uint256 _amount,
15 | uint256 _locktime
16 | ) external returns (bool);
17 | }
18 |
--------------------------------------------------------------------------------
/contracts/InterFaces/ITokenVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./IBEP20Token.sol";
4 |
5 | interface ITokenVault {
6 | function depositeToken(
7 | IBEP20Token _token,
8 | address _from,
9 | uint256 _amount
10 | ) external returns (bool);
11 |
12 | function directTransfer(
13 | address _token,
14 | address _to,
15 | uint256 amount
16 | ) external returns (bool);
17 |
18 | function transferEther(address payable _to, uint256 amount)
19 | external
20 | returns (bool);
21 | }
22 |
--------------------------------------------------------------------------------
/contracts/InterFaces/IWhiteList.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface IWhiteList {
4 | function address_belongs(address _who) external view returns (address);
5 |
6 | function isWhiteListed(address _who) external view returns (bool);
7 |
8 | function isAllowedInAuction(address _which) external view returns (bool);
9 |
10 | function isAddressByPassed(address _which) external view returns (bool);
11 |
12 | function isExchangeAddress(address _which) external view returns (bool);
13 |
14 | function main_isTransferAllowed(
15 | address _msgSender,
16 | address _from,
17 | address _to
18 | ) external returns (bool);
19 |
20 | function etn_isTransferAllowed(
21 | address _msgSender,
22 | address _from,
23 | address _to
24 | ) external returns (bool);
25 |
26 | function stock_isTransferAllowed(
27 | address _msgSender,
28 | address _from,
29 | address _to
30 | ) external returns (bool);
31 |
32 | function addWalletBehalfExchange(address _mainWallet, address _subWallet)
33 | external
34 | returns (bool);
35 |
36 | function main_isReceiveAllowed(address user) external view returns (bool);
37 |
38 | function etn_isReceiveAllowed(address user) external view returns (bool);
39 |
40 | function stock_isReceiveAllowed(address user) external view returns (bool);
41 |
42 | /**@dev checks if address is allowed in auction or not */
43 | function checkRule(address _which, uint256 _condition) external view returns (bool);
44 | }
45 |
--------------------------------------------------------------------------------
/contracts/Liquidity/LiquidityProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../Proxy/IRegistry.sol";
4 | import "../common/Ownable.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 | import "../InterFaces/IBEP20Token.sol";
7 |
8 | interface InitializeInterface {
9 | function initialize(
10 | address payable _converter,
11 | address payable _factory,
12 | address _baseToken,
13 | address _mainToken,
14 | address _primaryOwner,
15 | address _systemAddress,
16 | address _authorityAddress,
17 | address _registeryAddress,
18 | uint256 _baseLinePrice
19 | ) external;
20 | }
21 |
22 |
23 | /**
24 | * @title Registry
25 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
26 | */
27 | contract LiquidityRegistery is Ownable, IRegistry {
28 | // Mapping of versions to implementations of different functions
29 | mapping(uint256 => address) internal versions;
30 |
31 | uint256 public currentVersion;
32 |
33 | address payable public proxyAddress;
34 |
35 | //@dev constructor
36 | //@param _systemAddress address of the system Owner
37 | constructor(address _systemAddress, address _multisigAddress)
38 | public
39 | Ownable(_systemAddress, _multisigAddress)
40 | {}
41 |
42 | /**
43 | * @dev Registers a new version with its implementation address
44 | * @param version representing the version name of the new implementation to be registered
45 | * @param implementation representing the address of the new implementation to be registered
46 | */
47 | function addVersion(uint256 version, address implementation)
48 | public
49 | onlyOneOfOnwer()
50 | notZeroAddress(implementation)
51 | {
52 | require(
53 | versions[version] == address(0),
54 | "This version has implementation attached"
55 | );
56 | versions[version] = implementation;
57 | emit VersionAdded(version, implementation);
58 | }
59 |
60 | /**
61 | * @dev Tells the address of the implementation for a given version
62 | * @param version to query the implementation of
63 | * @return address of the implementation registered for the given version
64 | */
65 | function getVersion(uint256 version) public view returns (address) {
66 | return versions[version];
67 | }
68 |
69 | /**
70 | * @dev Creates an upgradeable proxy
71 | * @param version representing the first version to be set for the proxy
72 | * @return address of the new proxy created
73 | */
74 | function createProxy(
75 | uint256 version,
76 | address payable _converter,
77 | address payable _factory,
78 | address _baseToken,
79 | address _mainToken,
80 | address _primaryOwner,
81 | address _systemAddress,
82 | address _authorityAddress,
83 | address _registeryAddress,
84 | uint256 _baseLinePrice
85 |
86 | ) external onlyOneOfOnwer() returns (address) {
87 |
88 | require(proxyAddress == address(0),"ERR_PROXY_ALREADY_CREATED");
89 |
90 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
91 |
92 | InitializeInterface(address(proxy)).initialize(
93 | _converter,
94 | _factory,
95 | _baseToken,
96 | _mainToken,
97 | _primaryOwner,
98 | _systemAddress,
99 | _authorityAddress,
100 | _registeryAddress,
101 | _baseLinePrice
102 | );
103 |
104 | currentVersion = version;
105 | proxyAddress = address(proxy);
106 | emit ProxyCreated(address(proxy));
107 | return address(proxy);
108 | }
109 |
110 |
111 | /**
112 | * @dev Upgrades the implementation to the requested version
113 | * @param version representing the version name of the new implementation to be set
114 | */
115 |
116 | function upgradeTo(uint256 version) public onlyAuthorized() returns(bool) {
117 | require(
118 | versions[version] != address(0),
119 | "ERR_ZERO_ADDDRESS"
120 | );
121 | currentVersion = version;
122 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
123 | return true;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/contracts/Liquidity/LiquidityStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "../InterFaces/IBEP20Token.sol";
3 | import "../InterFaces/IAuctionRegistery.sol";
4 |
5 | contract LiquidityStorage {
6 | bytes32 internal constant BANCOR_FORMULA = "BancorFormula";
7 | bytes32 internal constant BANCOR_NETWORK = "BancorNetwork";
8 | uint256 public constant BIG_NOMINATOR = 10**24;
9 | uint256 public constant DECIMAL_NOMINATOR = 10**18;
10 | uint256 public constant PRICE_NOMINATOR = 10**9;
11 |
12 | address payable public converter;
13 | address payable public factory;
14 |
15 | address public baseToken; // basetoken
16 |
17 | address public mainToken; // maintoken
18 |
19 |
20 | // registery of all contacrt
21 | IAuctionRegistery public contractsRegistry;
22 |
23 | address payable public whiteListAddress;
24 | address payable public vaultAddress;
25 | address payable public auctionAddress;
26 | address payable public triggerAddress;
27 | address payable public currencyPricesAddress;
28 | address payable public escrowAddress;
29 |
30 |
31 |
32 | // side reserve ratio split between bancor and side reserve
33 | uint256 public sideReseverRatio;
34 |
35 | // 1:1 investment ratio
36 | uint256 public tagAlongRatio;
37 |
38 | // token price increase from yesterday limit 120%
39 | uint256 public appreciationLimit;
40 |
41 | // token price increase in decimal place
42 | uint256 public appreciationLimitWithDecimal;
43 |
44 | // contribution reduction start day
45 | uint256 public reductionStartDay;
46 |
47 | // basetoken price change ratio
48 | uint256 public baseTokenVolatiltyRatio;
49 |
50 | // reduction limit
51 | uint256 public virtualReserverDivisor;
52 |
53 | // previous day contribution in bancor
54 | uint256 public previousMainReserveContribution;
55 |
56 | // current day contribution in bancor
57 | uint256 public todayMainReserveContribution;
58 |
59 | // auction end day price of token
60 | uint256 public tokenAuctionEndPrice;
61 |
62 | // last reserve balance in bancor
63 | uint256 public lastReserveBalance;
64 |
65 | // basetoken starting price
66 | uint256 public baseLinePrice;
67 |
68 | // maxIteration for finding root
69 | uint256 public maxIteration;
70 |
71 | // check if today token price reach certain level
72 | bool public isAppreciationLimitReached;
73 |
74 | bool public isBuyBackOpen;
75 |
76 | uint256 public relayPercent;
77 |
78 | // mapping for where user last reddeem
79 | mapping(address => uint256) public lastReedeemDay;
80 |
81 | event Contribution(address _token, uint256 _amount, uint256 returnAmount);
82 | event RecoverPrice(uint256 _oldPrice, uint256 _newPrice);
83 | event Redemption(address _token, uint256 _amount, uint256 returnAmount);
84 | event FundDeposited(address _token, address indexed _from, uint256 _amount);
85 |
86 | uint256 public redemptionDayRelay;
87 | }
88 |
--------------------------------------------------------------------------------
/contracts/Migrations.sol:
--------------------------------------------------------------------------------
1 | pragma solidity >=0.4.21 <0.7.0;
2 |
3 | contract Migrations {
4 | address public owner;
5 | uint public last_completed_migration;
6 |
7 | constructor() public {
8 | owner = msg.sender;
9 | }
10 |
11 | modifier restricted() {
12 | if (msg.sender == owner) _;
13 | }
14 |
15 | function setCompleted(uint completed) public restricted {
16 | last_completed_migration = completed;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/contracts/Pricing/CurrencyPrice.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../common/Ownable.sol";
4 |
5 | interface IPrice {
6 | function getCurrencyPrice() external view returns (uint256);
7 | }
8 |
9 | contract CurrencyPrices is Ownable {
10 | mapping(address => address) public currencyContract;
11 |
12 | constructor(address _systemAddress, address _multisigAddress)
13 | public
14 | Ownable(_systemAddress, _multisigAddress)
15 | {}
16 |
17 | function setCurrencyPriceContract(address _currency, address _priceFeed)
18 | external
19 | onlySystem()
20 | returns (bool)
21 | {
22 | require(currencyContract[_currency] == address(0),"ERR_ADDRESS_IS_SET");
23 | currencyContract[_currency] = _priceFeed;
24 | return true;
25 | }
26 |
27 | function updateCurrencyPriceContract(address _currency, address _priceFeed)
28 | external
29 | onlyAuthorized()
30 | returns (bool)
31 | {
32 | currencyContract[_currency] = _priceFeed;
33 | return true;
34 | }
35 |
36 | function getCurrencyPrice(address _which) public view returns (uint256) {
37 | return IPrice(currencyContract[_which]).getCurrencyPrice();
38 | }
39 | }
--------------------------------------------------------------------------------
/contracts/Pricing/PriceTracker.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | pragma experimental ABIEncoderV2;
3 |
4 |
5 | interface IStdReference {
6 | /// A structure returned whenever someone requests for standard reference data.
7 | struct ReferenceData {
8 | uint256 rate; // base/quote exchange rate, multiplied by 1e18.
9 | uint256 lastUpdatedBase; // UNIX epoch of the last time when base price gets updated.
10 | uint256 lastUpdatedQuote; // UNIX epoch of the last time when quote price gets updated.
11 | }
12 |
13 | /// Returns the price data for the given base/quote pair. Revert if not available.
14 | function getReferenceData(string calldata _base, string calldata _quote)
15 | external
16 | view
17 | returns (ReferenceData memory);
18 |
19 | }
20 |
21 | contract CurrencyPriceTicker {
22 |
23 | IStdReference public ref;
24 |
25 | string public baseCurrency;
26 |
27 | string public vsCurrency;
28 |
29 | uint256 public constant PRICE_NOMINATOR = 10**9;
30 |
31 | constructor(IStdReference _ref,string memory _baseCurrency,string memory _vsCurrency) public {
32 | baseCurrency = _baseCurrency;
33 | vsCurrency = _vsCurrency;
34 | ref = _ref;
35 | }
36 |
37 |
38 | function getCurrencyPrice() external view returns (uint256){
39 | IStdReference.ReferenceData memory data = ref.getReferenceData(baseCurrency,vsCurrency);
40 | return data.rate/PRICE_NOMINATOR;
41 | }
42 |
43 |
44 | }
--------------------------------------------------------------------------------
/contracts/Protection/ProtectionProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../Proxy/IRegistry.sol";
4 | import "../common/Ownable.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 |
7 | interface ProtectionProxyInitializeInterface {
8 | function initialize(
9 | address _primaryOwner,
10 | address _systemAddress,
11 | address _authorityAddress,
12 | address _registeryAddress
13 | ) external;
14 | }
15 |
16 | /**
17 | * @title Registry
18 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
19 | */
20 | contract ProtectionRegistry is Ownable, IRegistry {
21 | // Mapping of versions to implementations of different functions
22 | mapping(uint256 => address) internal versions;
23 |
24 | uint256 public currentVersion;
25 |
26 | address payable public proxyAddress;
27 |
28 | //@dev constructor
29 | //@param _systemAddress address of the system Owner
30 | constructor(address _systemAddress, address _multisigAddress)
31 | public
32 | Ownable(_systemAddress, _multisigAddress)
33 | {}
34 |
35 | /**
36 | * @dev Registers a new version with its implementation address
37 | * @param version representing the version name of the new implementation to be registered
38 | * @param implementation representing the address of the new implementation to be registered
39 | */
40 | function addVersion(uint256 version, address implementation)
41 | public
42 | onlyOneOfOnwer()
43 | notZeroAddress(implementation)
44 | {
45 | require(
46 | versions[version] == address(0),
47 | "This version has implementation attached"
48 | );
49 | versions[version] = implementation;
50 | emit VersionAdded(version, implementation);
51 | }
52 |
53 | /**
54 | * @dev Tells the address of the implementation for a given version
55 | * @param version to query the implementation of
56 | * @return address of the implementation registered for the given version
57 | */
58 | function getVersion(uint256 version) public view returns (address) {
59 | return versions[version];
60 | }
61 |
62 | /**
63 | * @dev Creates an upgradeable proxy
64 | * @param version representing the first version to be set for the proxy
65 | * @return address of the new proxy created
66 | */
67 | function createProxy(
68 | uint256 version,
69 | address _primaryOwner,
70 | address _systemAddress,
71 | address _authorityAddress,
72 | address _registeryAddress
73 | ) public onlyOneOfOnwer() returns (address) {
74 |
75 | require(proxyAddress == address(0),"ERR_PROXY_ALREADY_CREATED");
76 |
77 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
78 |
79 | ProtectionProxyInitializeInterface(address(proxy)).initialize(
80 | _primaryOwner,
81 | _systemAddress,
82 | _authorityAddress,
83 | _registeryAddress
84 | );
85 |
86 | currentVersion = version;
87 | proxyAddress = address(proxy);
88 | emit ProxyCreated(address(proxy));
89 | return address(proxy);
90 | }
91 |
92 |
93 | /**
94 | * @dev Upgrades the implementation to the requested version
95 | * @param version representing the version name of the new implementation to be set
96 | */
97 |
98 | function upgradeTo(uint256 version) public onlyAuthorized() returns(bool) {
99 | currentVersion = version;
100 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
101 | return true;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/contracts/Protection/ProtectionStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "../InterFaces/IAuctionRegistery.sol";
3 |
4 | contract ProtectionStorage {
5 |
6 | IAuctionRegistery public contractsRegistry;
7 |
8 | address payable public vaultAddress;
9 | address payable public auctionAddress;
10 | address payable public liquidityAddress;
11 | address payable public mainTokenAddress;
12 | address payable public companyFundWalletAddress;
13 | address payable public whiteListAddress;
14 |
15 | // timestamp for address where first lock happen
16 | mapping(address => uint256) public lockedOn;
17 |
18 | mapping(address => mapping(address => uint256)) public lockedFunds;
19 |
20 | mapping(address => mapping(uint256 => mapping(address => uint256))) public currentLockedFunds;
21 |
22 | mapping(address => uint256) public lockedTokens;
23 |
24 |
25 | event TokenUnLocked(address indexed _from, uint256 _tokenAmount);
26 |
27 | event InvestMentCancelled(address indexed _from, uint256 _tokenAmount);
28 |
29 | event FundLocked(address _token, address indexed _which, uint256 _amount);
30 |
31 | event FundTransfer(address indexed _to, address _token, uint256 _amount);
32 |
33 | // We track Token only transfer by auction or downside
34 | // Reason for tracking this bcz someone can send token direclty
35 |
36 | uint256 public constant PERCENT_NOMINATOR = 10**6;
37 |
38 | uint256 public constant DECIMAL_NOMINATOR = 10**18;
39 |
40 | uint256 public totalTokenAmount;
41 |
42 | uint256 public stackRoundId;
43 |
44 | mapping(uint256 => uint256) dayWiseRatio;
45 |
46 | mapping(address => uint256) lastRound;
47 |
48 | mapping(address => mapping(uint256 => uint256)) roundWiseToken;
49 |
50 | mapping(address => uint256) stackBalance;
51 |
52 | uint256 public tokenLockDuration;
53 |
54 | mapping(address => bool) public unLockBlock;
55 |
56 | uint256 public vaultRatio;
57 |
58 | event StackAdded(
59 | uint256 indexed _roundId,
60 | address indexed _whom,
61 | uint256 _amount
62 | );
63 |
64 | event StackRemoved(
65 | uint256 indexed _roundId,
66 | address indexed _whom,
67 | uint256 _amount
68 | );
69 | }
--------------------------------------------------------------------------------
/contracts/Proxy/IRegistry.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | /**
4 | * @title IRegistry
5 | * @dev This contract represents the interface of a registry contract
6 | */
7 | interface IRegistry {
8 | /**
9 | * @dev This event will be emitted every time a new proxy is created
10 | * @param proxy representing the address of the proxy created
11 | */
12 | event ProxyCreated(address proxy);
13 |
14 | /**
15 | * @dev This event will be emitted every time a new implementation is registered
16 | * @param version representing the version name of the registered implementation
17 | * @param implementation representing the address of the registered implementation
18 | */
19 | event VersionAdded(uint256 version, address implementation);
20 |
21 | /**
22 | * @dev Registers a new version with its implementation address
23 | * @param version representing the version name of the new implementation to be registered
24 | * @param implementation representing the address of the new implementation to be registered
25 | */
26 | function addVersion(uint256 version, address implementation)
27 | external;
28 |
29 | /**
30 | * @dev Tells the address of the implementation for a given version
31 | * @param version to query the implementation of
32 | * @return address of the implementation registered for the given version
33 | */
34 | function getVersion(uint256 version)
35 | external
36 | view
37 | returns (address);
38 | }
39 |
40 |
41 |
--------------------------------------------------------------------------------
/contracts/Proxy/Proxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | /**
4 | * @title Proxy
5 | * @dev Gives the possibility to delegate any call to a foreign implementation.
6 | */
7 | contract Proxy {
8 | /**
9 | * @dev Tells the address of the implementation where every call will be delegated.
10 | * @return address of the implementation to which it will be delegated
11 | */
12 | function implementation() public view returns (address);
13 |
14 | /**
15 | * @dev Fallback function allowing to perform a delegatecall to the given implementation.
16 | * This function will return whatever the implementation call returns
17 | */
18 |
19 | function() external payable {
20 | address _impl = implementation();
21 | require(_impl != address(0),"ERR_IMPLEMENTEION_ZERO");
22 |
23 | assembly {
24 | let ptr := mload(0x40)
25 | calldatacopy(ptr, 0, calldatasize())
26 | let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
27 | let size := returndatasize()
28 | returndatacopy(ptr, 0, size)
29 |
30 | switch result
31 | case 0 {
32 | revert(ptr, size)
33 | }
34 | default {
35 | return(ptr, size)
36 | }
37 | }
38 | }
39 |
40 |
41 |
42 |
43 | }
--------------------------------------------------------------------------------
/contracts/Proxy/UpgradeabilityProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import './IRegistry.sol';
4 | import './UpgradeabilityStorage.sol';
5 |
6 | /**
7 | * @title UpgradeabilityProxy
8 | * @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded
9 | */
10 | contract UpgradeabilityProxy is UpgradeabilityStorage {
11 | /**
12 | * @dev Constructor function
13 | */
14 | constructor(uint256 _version) public {
15 | registry = IRegistry(msg.sender);
16 | upgradeTo(_version);
17 | }
18 |
19 | /**
20 | * @dev Upgrades the implementation to the requested version
21 | * @param _version representing the version name of the new implementation to be set
22 | */
23 | function upgradeTo(uint256 _version) public {
24 | require(msg.sender == address(registry),"ERR_ONLY_REGISTRERY_CAN_CALL");
25 | _implementation = registry.getVersion(_version);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/contracts/Proxy/UpgradeabilityStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import './IRegistry.sol';
4 | import './Proxy.sol';
5 |
6 | /**
7 | * @title UpgradeabilityStorage
8 | * @dev This contract holds all the necessary state variables to support the upgrade functionality
9 | */
10 | contract UpgradeabilityStorage is Proxy {
11 | // Versions registry
12 | IRegistry public registry;
13 |
14 | // Address of the current implementation
15 | address internal _implementation;
16 |
17 | /**
18 | * @dev Tells the address of the current implementation
19 | * @return address of the current implementation
20 | */
21 | function implementation() public view returns (address) {
22 | return _implementation;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/contracts/Proxy/Upgradeable.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import './UpgradeabilityStorage.sol';
4 |
5 |
6 | /**
7 | * @title Upgradeable
8 | * @dev This contract holds all the minimum required functionality for a behavior to be upgradeable.
9 | * This means, required state variables for owned upgradeability purpose and simple initialization validation.
10 | */
11 | contract Upgradeable is UpgradeabilityStorage {
12 | /**
13 | * @dev Validates the caller is the versions registry.
14 | * THIS FUNCTION SHOULD BE OVERRIDDEN CALLING SUPER
15 | */
16 | function initialize() public view {
17 | require(msg.sender == address(registry),"ERR_ONLY_REGISTRERY_CAN_CALL");
18 | }
19 | }
--------------------------------------------------------------------------------
/contracts/TokenVault/TokenVault.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./TokenVaultStorage.sol";
4 | import "../common/ProxyOwnable.sol";
5 | import "../common/SafeMath.sol";
6 | import "../common/TokenTransfer.sol";
7 | import "../Proxy/Upgradeable.sol";
8 | import "../InterFaces/IAuctionRegistery.sol";
9 | import "../InterFaces/IBEP20Token.sol";
10 | import "../InterFaces/IAuctionProtection.sol";
11 |
12 |
13 | interface InitializeInterfaceVault {
14 | function initialize(
15 | address _primaryOwner,
16 | address _systemAddress,
17 | address _authorityAddress,
18 | address _registryaddress
19 | ) external;
20 | }
21 |
22 | contract TokenRegistery is ProxyOwnable,TokenVaultStorage, AuctionRegisteryContracts {
23 |
24 |
25 | function updateRegistery(address _address)
26 | external
27 | onlyAuthorized()
28 | notZeroAddress(_address)
29 | returns (bool)
30 | {
31 |
32 | contractsRegistry = IAuctionRegistery(_address);
33 | _updateAddresses();
34 | return true;
35 | }
36 |
37 | function getAddressOf(bytes32 _contractName)
38 | internal
39 | view
40 | returns (address payable)
41 | {
42 | return contractsRegistry.getAddressOf(_contractName);
43 | }
44 |
45 | /**@dev updates all the address from the registry contract
46 | this decision was made to save gas that occurs from calling an external view function */
47 |
48 | function _updateAddresses() internal {
49 | auctionProtectionAddress = getAddressOf(AUCTION_PROTECTION);
50 | }
51 |
52 | function updateAddresses() external returns (bool) {
53 | _updateAddresses();
54 | }
55 | }
56 |
57 | contract TokenSpenders is TokenRegistery,SafeMath {
58 |
59 |
60 | modifier onlySpender() {
61 | require(isSpender[msg.sender],ERR_AUTHORIZED_ADDRESS_ONLY);
62 | _;
63 | }
64 |
65 | // once all spender from set give authority to govenranacne
66 | function addSpender(address _which) external onlyOwner() returns(bool){
67 | require(isSpender[_which] == false,ERR_AUTHORIZED_ADDRESS_ONLY);
68 | isSpender[_which] = true;
69 | spenderIndex[_which] = spenders.length;
70 | spenders.push(_which);
71 | emit TokenSpenderAdded(_which);
72 | return true;
73 |
74 | }
75 |
76 | function removeSpender(address _which) external onlyAuthorized() returns(bool){
77 | require(isSpender[_which],ERR_AUTHORIZED_ADDRESS_ONLY);
78 | uint256 _spenderIndex = spenderIndex[_which];
79 | address _lastAdress = spenders[safeSub(spenders.length, 1)];
80 | spenders[_spenderIndex] = _lastAdress;
81 | spenderIndex[_lastAdress] = _spenderIndex;
82 | delete isSpender[_which];
83 | spenders.pop();
84 | emit TokenSpenderRemoved(_which);
85 | return true;
86 |
87 | }
88 | }
89 |
90 |
91 | contract TokenVault is
92 | Upgradeable,
93 | TokenSpenders,
94 | InitializeInterfaceVault,
95 | TokenTransfer
96 | {
97 |
98 |
99 |
100 | function initialize(
101 | address _primaryOwner,
102 | address _systemAddress,
103 | address _authorityAddress,
104 | address _registryaddress
105 | ) public {
106 | super.initialize();
107 | contractsRegistry = IAuctionRegistery(_registryaddress);
108 | _updateAddresses();
109 | initializeOwner(
110 | _primaryOwner,
111 | _systemAddress,
112 | _authorityAddress
113 | );
114 |
115 | }
116 |
117 |
118 | function() external payable{
119 | emit FundDeposited(address(0), msg.sender, msg.value);
120 | }
121 |
122 | function depositeToken(IBEP20Token _token, address _from, uint256 _amount)
123 | external
124 | returns (bool)
125 | {
126 | ensureTransferFrom(_token, _from, address(this), _amount);
127 | emit FundDeposited(address(_token), _from, _amount);
128 | return true;
129 | }
130 |
131 |
132 | function directTransfer(address _token,address _to,uint256 amount) external onlySpender() returns (bool){
133 | ensureTransferFrom(IBEP20Token(_token),address(this),_to,amount);
134 | emit FundTransfer(msg.sender,_to,_token,amount);
135 | return true;
136 | }
137 |
138 | function transferEther(address payable _to,uint256 amount) external onlySpender() returns (bool){
139 | _to.transfer(amount);
140 | emit FundTransfer(msg.sender,_to,address(0),amount);
141 | return true;
142 | }
143 |
144 |
145 | // This method is auction protection methods called from here
146 | // vault address set when contribution is 0
147 | function unLockTokens() external onlySystem() returns (bool){
148 | return IAuctionProtection(auctionProtectionAddress).unLockTokens();
149 | }
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/contracts/TokenVault/TokenVaultProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../common/Ownable.sol";
4 | import "../Proxy/IRegistry.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 |
7 |
8 | interface VaultProxyInitializeInterface {
9 | function initialize(
10 | address _primaryOwner,
11 | address _systemAddress,
12 | address _authorityAddress,
13 | address _registryaddress
14 | ) external;
15 | }
16 |
17 |
18 | /**
19 | * @title Registry
20 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
21 | */
22 | contract TokenVaultRegistery is Ownable, IRegistry {
23 | // Mapping of versions to implementations of different functions
24 | mapping(uint256 => address) internal versions;
25 |
26 | uint256 public currentVersion;
27 |
28 | address payable public proxyAddress;
29 |
30 | //@dev constructor
31 | //@param _systemAddress address of the system Owner
32 | constructor(address _systemAddress, address _multisigAddress)
33 | public
34 | Ownable(_systemAddress, _multisigAddress)
35 | {}
36 |
37 | /**
38 | * @dev Registers a new version with its implementation address
39 | * @param version representing the version name of the new implementation to be registered
40 | * @param implementation representing the address of the new implementation to be registered
41 | */
42 | function addVersion(uint256 version, address implementation)
43 | public
44 | onlyOneOfOnwer()
45 | notZeroAddress(implementation)
46 | {
47 | require(
48 | versions[version] == address(0),
49 | "This version has implementation attached"
50 | );
51 | versions[version] = implementation;
52 | emit VersionAdded(version, implementation);
53 | }
54 |
55 | /**
56 | * @dev Tells the address of the implementation for a given version
57 | * @param version to query the implementation of
58 | * @return address of the implementation registered for the given version
59 | */
60 | function getVersion(uint256 version) public view returns (address) {
61 | return versions[version];
62 | }
63 |
64 | /**
65 | * @dev Creates an upgradeable proxy
66 | * @param version representing the first version to be set for the proxy
67 | * @return address of the new proxy created
68 | */
69 | function createProxy(
70 | uint256 version,
71 | address _primaryOwner,
72 | address _systemAddress,
73 | address _authorityAddress,
74 | address _registryaddress
75 | ) public onlyOneOfOnwer() returns (address) {
76 | require(proxyAddress == address(0), "ERR_PROXY_ALREADY_CREATED");
77 |
78 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
79 |
80 | VaultProxyInitializeInterface(address(proxy)).initialize(
81 | _primaryOwner,
82 | _systemAddress,
83 | _authorityAddress,
84 | _registryaddress
85 | );
86 |
87 | currentVersion = version;
88 | proxyAddress = address(proxy);
89 | emit ProxyCreated(address(proxy));
90 | return address(proxy);
91 | }
92 |
93 | /**
94 | * @dev Upgrades the implementation to the requested version
95 | * @param version representing the version name of the new implementation to be set
96 | */
97 |
98 | function upgradeTo(uint256 version) public onlyAuthorized() returns (bool) {
99 | require(
100 | versions[version] != address(0),
101 | "ERR_ZERO_ADDDRESS"
102 | );
103 | currentVersion = version;
104 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
105 | return true;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/contracts/TokenVault/TokenVaultStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "../InterFaces/IAuctionRegistery.sol";
3 |
4 |
5 | contract TokenVaultStorage {
6 |
7 | IAuctionRegistery public contractsRegistry;
8 |
9 | address payable public auctionProtectionAddress;
10 |
11 | mapping(address=>bool) public isSpender;
12 |
13 | mapping(address => uint256) public spenderIndex;
14 |
15 | address[] public spenders;
16 |
17 | event TokenSpenderAdded(address indexed _which);
18 |
19 | event TokenSpenderRemoved(address indexed _which);
20 |
21 | event FundTransfer(address indexed _by,address _to,address _token,uint256 amount);
22 |
23 | event FundDeposited(address _token, address _from, uint256 _amount);
24 |
25 | }
--------------------------------------------------------------------------------
/contracts/Tokens/EtnToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./Exchangeable.sol";
4 | import "../InterFaces/IWhiteList.sol";
5 |
6 |
7 | contract EtnToken is Exchangeable {
8 | /**
9 | *@dev constructs contract and premints tokens
10 | *@param _name name of the token
11 | *@param _symbol symbol of the token
12 | *@param _systemAddress address that acts as an admin of the system
13 | *@param _authorityAddress address that can change the systemAddress
14 | *@param _registeryAddress address of the registry contract the keeps track of all the contract Addresses
15 | *@param _returnToken address of the token user gets back when system forces them to convert(maintoken)
16 | **/
17 | constructor(
18 | string memory _name,
19 | string memory _symbol,
20 | address _systemAddress,
21 | address _authorityAddress,
22 | address _registeryAddress,
23 | address _returnToken
24 | )
25 | public
26 | TokenUtils(
27 | _name,
28 | _symbol,
29 | _systemAddress,
30 | _authorityAddress,
31 | _registeryAddress
32 | )
33 | ForceSwap(_returnToken)
34 | {}
35 |
36 | /**
37 | *@dev checks before every transfer that takes place(except minting)
38 | *@param _from address from which tokens are being transferred
39 | *@param _to address to which tokens are being transfferred
40 | */
41 | function checkBeforeTransfer(address _from, address _to)
42 | internal
43 | returns (bool)
44 | {
45 | require(
46 | IWhiteList(whiteListAddress).etn_isTransferAllowed(
47 | msg.sender,
48 | _from,
49 | _to
50 | ),
51 | "ERR_NOT_HAVE_PERMISSION_TO_TRANSFER"
52 | );
53 |
54 | return true;
55 | }
56 |
57 | /** @dev Allows users to buy tokens from other accepteble tokens prices as per prices in currencyPrices contract
58 | *@param _fromToken the token user wants buy from
59 | *@param _amount amount of token users wants buy with. It assumes that contract has been approved atleast _amount buy msg.sender
60 | */
61 | function buyTokens(address _fromToken, uint256 _amount)
62 | external
63 | isConversionAllowed(_fromToken)
64 | returns (uint256)
65 | {
66 | //check if msg.sender is allowed
67 |
68 | require(
69 | IWhiteList(whiteListAddress).etn_isReceiveAllowed(msg.sender),
70 | "ERR_CANNOT_RECIEVE"
71 | );
72 |
73 | ICurrencyPrices currencyPrice = ICurrencyPrices(currencyPricesAddress);
74 |
75 | uint256 fromTokenPrice = currencyPrice.getCurrencyPrice(_fromToken);
76 |
77 | require(fromTokenPrice > 0, "ERR_TOKEN_PRICE_NOT_SET");
78 |
79 | uint256 currentTokenPrice = currencyPrice.getCurrencyPrice(
80 | address(this)
81 | );
82 |
83 | uint256 _assignToken = safeDiv(
84 | safeMul(_amount, fromTokenPrice),
85 | currentTokenPrice
86 | );
87 |
88 | if (_fromToken == returnToken) {
89 | IBEP20(_fromToken).transferFrom(msg.sender, vaultAddress, _amount);
90 | } else {
91 | IBEP20(_fromToken).transferFrom(msg.sender, address(this), _amount);
92 | IToken(_fromToken).burn(_amount);
93 | }
94 |
95 | _mint(msg.sender, _assignToken);
96 |
97 | return _assignToken;
98 | }
99 |
100 | function transfer(address _to, uint256 _value) external returns (bool ok) {
101 | require(checkBeforeTransfer(msg.sender, _to));
102 | return _transfer(msg.sender, _to, _value);
103 | }
104 |
105 | function transferFrom(
106 | address _from,
107 | address _to,
108 | uint256 _value
109 | ) external returns (bool) {
110 | require(checkBeforeTransfer(_from, _to));
111 | return _transferFrom(_from, _to, _value);
112 | }
113 |
114 | function() external payable {
115 | revert("ERR_CAN'T_FORCE_ETH");
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/contracts/Tokens/Exchangeable.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 |
4 | import "./StandardToken.sol";
5 | import "../InterFaces/ICurrencyPrices.sol";
6 | import "../InterFaces/ITokenVault.sol";
7 | import "../InterFaces/IToken.sol";
8 | import "./TokenUtils.sol";
9 | import "../InterFaces/IWhiteList.sol";
10 |
11 |
12 | /**
13 | @dev ForeceSwap contains functionality for system to be able to convert tokens of anyone into returnToken at setted price
14 | */
15 | contract ForceSwap is TokenUtils {
16 | // here returnToken means with mainToken
17 | address public returnToken;
18 |
19 | constructor(address _returnToken) public notZeroAddress(_returnToken) {
20 | returnToken = _returnToken;
21 | }
22 |
23 | /**
24 | @dev converts _which's _amount of tokens into returnTokens as per the price
25 | @param _which address which tokens are being converted
26 | @param _amount amount of tokens being converted */
27 | function _forceSwap(address _which, uint256 _amount)
28 | internal
29 | returns (bool)
30 | {
31 | require(returnToken != address(0), "ERR_ACTION_NOT_ALLOWED");
32 |
33 | _burn(_which, _amount);
34 |
35 | ICurrencyPrices currencyPrice = ICurrencyPrices(currencyPricesAddress);
36 |
37 |
38 | ITokenVault tokenVault = ITokenVault(vaultAddress);
39 |
40 | uint256 retunTokenPrice = currencyPrice.getCurrencyPrice(returnToken);
41 |
42 | require(retunTokenPrice > 0, "ERR_TOKEN_PRICE_NOT_SET");
43 |
44 | uint256 currentTokenPrice = currencyPrice.getCurrencyPrice(
45 | address(this)
46 | );
47 |
48 | uint256 _assignToken = safeDiv(
49 | safeMul(_amount, currentTokenPrice),
50 | retunTokenPrice
51 | );
52 |
53 | return tokenVault.directTransfer(returnToken, msg.sender, _assignToken);
54 | }
55 |
56 | /**
57 | @dev converts _which's _amount of tokens into returnTokens as per the price, can be called only by the system
58 | @param _which address which tokens are being converted
59 | @param _amount amount of tokens being converted */
60 | function forceSwap(address _which, uint256 _amount)
61 | external
62 | onlySystem()
63 | returns (bool)
64 | {
65 | return _forceSwap(_which, _amount);
66 | }
67 | }
68 |
69 |
70 | /**@dev Exchangeble keeps track of token with which users are allowed to buy 'this' token from*/
71 | contract Exchangeable is ForceSwap {
72 | //address of the token with which user can buy 'this' token from
73 | address public exchangeableToken;
74 |
75 | /**@dev sets the address of the token with which user can buy 'this' token from by system only */
76 | function setExchangeableToken(address _which)
77 | external
78 | onlySystem()
79 | returns (bool)
80 | {
81 | require(exchangeableToken == address(0), "ERR_ACTION_NOT_ALLOWED");
82 | exchangeableToken = _which;
83 | }
84 |
85 | modifier isConversionAllowed(address _which) {
86 | require(
87 | _which == exchangeableToken || _which == returnToken,
88 | "ERR_TOKEN_IS_NOT_IN_LIST"
89 | );
90 | _;
91 | }
92 |
93 | /**@dev allows user to convert tokens into returnTokens at setted price
94 | @param _amount amount of token being converted
95 | */
96 | function swapTokens(uint256 _amount) external returns (bool) {
97 | return _forceSwap(msg.sender, _amount);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/contracts/Tokens/IBEP20.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | interface IBEP20 {
4 | /**
5 | * @dev Returns the amount of tokens in existence.
6 | */
7 | function totalSupply() external view returns (uint256);
8 |
9 | /**
10 | * @dev Returns the token decimals.
11 | */
12 | function decimals() external view returns (uint8);
13 |
14 | /**
15 | * @dev Returns the token symbol.
16 | */
17 | function symbol() external view returns (string memory);
18 |
19 | /**
20 | * @dev Returns the token name.
21 | */
22 | function name() external view returns (string memory);
23 |
24 | /**
25 | * @dev Returns the bep token owner.
26 | */
27 | function getOwner() external view returns (address);
28 |
29 | /**
30 | * @dev Returns the amount of tokens owned by `account`.
31 | */
32 | function balanceOf(address account) external view returns (uint256);
33 |
34 | /**
35 | * @dev Moves `amount` tokens from the caller's account to `recipient`.
36 | *
37 | * Returns a boolean value indicating whether the operation succeeded.
38 | *
39 | * Emits a {Transfer} event.
40 | */
41 | function transfer(address recipient, uint256 amount) external returns (bool);
42 |
43 | /**
44 | * @dev Returns the remaining number of tokens that `spender` will be
45 | * allowed to spend on behalf of `owner` through {transferFrom}. This is
46 | * zero by default.
47 | *
48 | * This value changes when {approve} or {transferFrom} are called.
49 | */
50 | function allowance(address _owner, address spender) external view returns (uint256);
51 |
52 | /**
53 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
54 | *
55 | * Returns a boolean value indicating whether the operation succeeded.
56 | *
57 | * IMPORTANT: Beware that changing an allowance with this method brings the risk
58 | * that someone may use both the old and the new allowance by unfortunate
59 | * transaction ordering. One possible solution to mitigate this race
60 | * condition is to first reduce the spender's allowance to 0 and set the
61 | * desired value afterwards:
62 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
63 | *
64 | * Emits an {Approval} event.
65 | */
66 | function approve(address spender, uint256 amount) external returns (bool);
67 |
68 | /**
69 | * @dev Moves `amount` tokens from `sender` to `recipient` using the
70 | * allowance mechanism. `amount` is then deducted from the caller's
71 | * allowance.
72 | *
73 | * Returns a boolean value indicating whether the operation succeeded.
74 | *
75 | * Emits a {Transfer} event.
76 | */
77 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
78 |
79 | /**
80 | * @dev Emitted when `value` tokens are moved from one account (`from`) to
81 | * another (`to`).
82 | *
83 | * Note that `value` may be zero.
84 | */
85 | event Transfer(address indexed from, address indexed to, uint256 value);
86 |
87 | /**
88 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by
89 | * a call to {approve}. `value` is the new allowance.
90 | */
91 | event Approval(address indexed owner, address indexed spender, uint256 value);
92 | }
--------------------------------------------------------------------------------
/contracts/Tokens/MainToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../InterFaces/IWhiteList.sol";
4 | import "./TokenUtils.sol";
5 |
6 |
7 |
8 | contract TokenMinter is TokenUtils {
9 | modifier onlyAuthorizedAddress() {
10 | require(msg.sender == auctionAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
11 | _;
12 | }
13 |
14 | function mintTokens(uint256 _amount)
15 | external
16 | onlyAuthorizedAddress()
17 | returns (bool)
18 | {
19 | return _mint(msg.sender, _amount);
20 | }
21 | }
22 |
23 |
24 | contract MainToken is TokenMinter {
25 | mapping(address => uint256) public lockedToken;
26 | mapping(address => uint256) public lastLock;
27 |
28 | /**
29 | *@dev constructs contract and premints tokens
30 | *@param _name name of the token
31 | *@param _symbol symbol of the token
32 | *@param _systemAddress address that acts as an admin of the system
33 | *@param _authorityAddress address that can change the systemAddress
34 | *@param _registeryAddress address of the registry contract the keeps track of all the contract Addresses
35 | *@param _which array of address to mint tokens to
36 | *@param _amount array of corresponding amount getting minted
37 | **/
38 | constructor(
39 | string memory _name,
40 | string memory _symbol,
41 | address _systemAddress,
42 | address _authorityAddress,
43 | address _registeryAddress,
44 | address[] memory _which,
45 | uint256[] memory _amount
46 | )
47 | public
48 | TokenUtils(
49 | _name,
50 | _symbol,
51 | _systemAddress,
52 | _authorityAddress,
53 | _registeryAddress
54 | )
55 | {
56 | require(_which.length == _amount.length, "ERR_NOT_SAME_LENGTH");
57 |
58 | for (uint256 tempX = 0; tempX < _which.length; tempX++) {
59 | require(
60 | IWhiteList(whiteListAddress).isWhiteListed(_which[tempX]),
61 | "ERR_TRANSFER_CHECK_WHITELIST"
62 | );
63 | _mint(_which[tempX], _amount[tempX]);
64 | }
65 | }
66 |
67 | function checkBeforeTransfer(address _from, address _to)
68 | internal
69 | returns (bool)
70 | {
71 | require(
72 | IWhiteList(whiteListAddress).main_isTransferAllowed(
73 | msg.sender,
74 | _from,
75 | _to
76 | ),
77 | "ERR_NOT_HAVE_PERMISSION_TO_TRANSFER"
78 | );
79 |
80 | return true;
81 | }
82 |
83 | function transfer(address _to, uint256 _value) external returns (bool ok) {
84 | uint256 senderBalance = safeSub(
85 | balances[msg.sender],
86 | lockedToken[msg.sender]
87 | );
88 | require(senderBalance >= _value, "ERR_NOT_ENOUGH_BALANCE");
89 | require(checkBeforeTransfer(msg.sender, _to));
90 | return _transfer(msg.sender, _to, _value);
91 | }
92 |
93 | function transferFrom(
94 | address _from,
95 | address _to,
96 | uint256 _value
97 | ) external returns (bool) {
98 |
99 | uint256 senderBalance = safeSub(balances[_from], lockedToken[_from]);
100 | require(senderBalance >= _value, "ERR_NOT_ENOUGH_BALANCE");
101 |
102 | require(checkBeforeTransfer(_from, _to));
103 | return _transferFrom(_from, _to, _value);
104 | }
105 |
106 | // we need lock time
107 | // becuse we can check if user invest after new auction start
108 | // if user invest before token distrubution we dont change anything
109 | // ex -> user invest at 11:35 and token distrubution happened at 11:40
110 | // if in between user invest we dont unlock user token we keep as it as
111 | // to unlock token set _amount = 0
112 | function lockToken(
113 | address _which,
114 | uint256 _amount,
115 | uint256 _locktime
116 | ) external returns (bool) {
117 | require(msg.sender == auctionAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
118 | if (_locktime > lastLock[_which]) {
119 | lockedToken[_which] = _amount;
120 | lastLock[_which] = _locktime;
121 | }
122 | return true;
123 | }
124 |
125 | // user can unlock their token after 1 day of locking
126 | // user dont need to call this function as auction set 0 after token distrubution
127 | // It is failsafe function for user that their token not locked all the time if AUCTION distrubution dont happened
128 | function unlockToken() external returns (bool) {
129 | require(
130 | safeAdd(lastLock[msg.sender], 86400) > now,
131 | "ERR_TOKEN_UNLCOK_AFTER_DAY"
132 | );
133 | lockedToken[msg.sender] = 0;
134 | return true;
135 | }
136 |
137 | function() external payable {
138 | revert("ERR_CAN'T_FORCE_ETH");
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/contracts/Tokens/StandardToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./IBEP20.sol";
4 | import "../common/SafeMath.sol";
5 | import "../common/Ownable.sol";
6 |
7 |
8 | contract StandardToken is IBEP20, SafeMath, Ownable {
9 |
10 | uint256 public totalSupply;
11 |
12 | string public name;
13 |
14 | string public symbol;
15 |
16 | uint256 public constant decimals = 18;
17 |
18 | mapping(address => uint256) balances;
19 |
20 | mapping(address => mapping(address => uint256)) allowed;
21 |
22 | constructor(string memory _name,
23 | string memory _symbol,
24 | address _systemAddress,
25 | address _authorityAddress) public Ownable(_systemAddress,_authorityAddress) {
26 |
27 | require(bytes(_name).length > 0 && bytes(_symbol).length > 0);
28 | name = _name;
29 | symbol = _symbol;
30 | }
31 |
32 | event Mint(address indexed _to, uint256 value);
33 | event Burn(address indexed from, uint256 value);
34 | event TransferFrom(
35 | address indexed spender,
36 | address indexed _from,
37 | address indexed _to
38 | );
39 |
40 |
41 | /**
42 | * @dev transfer token for a specified address
43 | * @param _from The address from token transfer.
44 | * @param _to The address to transfer to.
45 | * @param _value The amount to be transferred.
46 | */
47 | function _transfer(address _from, address _to, uint256 _value)
48 | internal
49 | returns (bool)
50 | {
51 | uint256 senderBalance = balances[_from];
52 | require(senderBalance >= _value, "ERR_NOT_ENOUGH_BALANCE");
53 | senderBalance = safeSub(senderBalance, _value);
54 | balances[_from] = senderBalance;
55 | balances[_to] = safeAdd(balances[_to], _value);
56 | emit Transfer(_from, _to, _value);
57 | return true;
58 | }
59 |
60 | /**
61 | * @dev Transfer tokens from one address to another
62 | * @param _from address The address which you want to send tokens from
63 | * @param _to address The address which you want to transfer tokens
64 | * @param _value uint256 the amount of tokens to be transferred
65 | */
66 | function _transferFrom(address _from, address _to, uint256 _value)
67 | internal
68 | notThisAddress(_to)
69 | notZeroAddress(_to)
70 | returns (bool)
71 | {
72 | require(allowed[_from][msg.sender] >= _value, "ERR_NOT_ENOUGH_BALANCE");
73 | require(_transfer(_from, _to, _value));
74 | allowed[_from][msg.sender] = safeSub(
75 | allowed[_from][msg.sender],
76 | _value
77 | );
78 | emit TransferFrom(msg.sender, _from, _to);
79 | return true;
80 | }
81 |
82 | function _approve(address owner, address spender, uint256 amount) internal notZeroAddress(spender) {
83 |
84 | allowed[owner][spender] = amount;
85 | emit Approval(owner, spender, amount);
86 | }
87 |
88 | function _burn(address _from, uint256 _value) internal returns (bool) {
89 | uint256 senderBalance = balances[_from];
90 | require(senderBalance >= _value, "ERR_NOT_ENOUGH_BALANCE");
91 | senderBalance = safeSub(senderBalance, _value);
92 | balances[_from] = senderBalance;
93 | totalSupply = safeSub(totalSupply, _value);
94 | emit Burn(_from, _value);
95 | emit Transfer(_from, address(0), _value);
96 | return true;
97 | }
98 |
99 | function _mint(address _to, uint256 _value) internal returns (bool) {
100 | balances[_to] = safeAdd(balances[_to], _value);
101 | totalSupply = safeAdd(totalSupply, _value);
102 | emit Mint(_to, _value);
103 | emit Transfer(address(0), _to, _value);
104 | return true;
105 | }
106 |
107 |
108 |
109 | /**
110 | * @dev Gets the balance of the specified address.
111 | * @param _who The address to query the the balance of.
112 | * @return balance An uint256 representing the amount owned by the passed address.
113 | */
114 | function balanceOf(address _who) public view returns (uint256 balance) {
115 | return balances[_who];
116 | }
117 |
118 |
119 | /**
120 | * @dev `msg.sender` approves `spender` to spend `value` tokens
121 | * @param _spender The address of the account able to transfer the tokens
122 | * @param _value The amount of wei to be approved for transfer
123 | * @return ok Whether the approval was successful or not
124 | */
125 | function approve(address _spender, uint256 _value)
126 | external
127 | notZeroAddress(_spender)
128 | returns (bool ok)
129 | {
130 | _approve(msg.sender, _spender, _value);
131 | return true;
132 | }
133 |
134 | /**
135 | * @dev `msg.sender` approves `spender` to increase spend `value` tokens
136 | * @param _spender The address of the account able to transfer the tokens
137 | * @param _value The amount of wei to be approved for transfer
138 | * @return Whether the approval was successful or not
139 | */
140 | function increaseAllowance(address _spender, uint256 _value) external returns (bool) {
141 | uint256 currentAllowed = allowed[msg.sender][_spender];
142 | _approve(msg.sender, _spender, safeAdd(currentAllowed,_value));
143 | return true;
144 |
145 | }
146 |
147 | /**
148 | * @dev `msg.sender` approves `spender` to decrease spend `value` tokens
149 | * @param _spender The address of the account able to transfer the tokens
150 | * @param _value The amount of wei to be approved for transfer
151 | * @return Whether the approval was successful or not
152 | */
153 | function decreaseAllowance(address _spender, uint256 _value) external returns (bool) {
154 | uint256 currentAllowed = allowed[msg.sender][_spender];
155 | require(currentAllowed >= _value,"ERR_ALLOWENCE");
156 | _approve(msg.sender, _spender, safeSub(currentAllowed,_value));
157 | return true;
158 | }
159 |
160 |
161 |
162 | /**
163 | * @dev to check allowed token for transferFrom
164 | * @param _owner The address of the account owning tokens
165 | * @param _spender The address of the account able to transfer the tokens
166 | * @return Amount of remaining tokens allowed to spent
167 | */
168 | function allowance(address _owner, address _spender)
169 | external
170 | view
171 | returns (uint256)
172 | {
173 | return allowed[_owner][_spender];
174 | }
175 |
176 |
177 |
178 | /**
179 | * @dev burn token from this address
180 | * @param _value uint256 the amount of tokens to be burned
181 | */
182 | function burn(uint256 _value) external returns (bool) {
183 | return _burn(msg.sender, _value);
184 | }
185 |
186 | /**
187 | * @dev Returns the bep token owner.
188 | */
189 | function getOwner() external view returns (address) {
190 | return systemAddress;
191 | }
192 |
193 | }
--------------------------------------------------------------------------------
/contracts/Tokens/StockToken.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./Exchangeable.sol";
4 | import "../InterFaces/IWhiteList.sol";
5 |
6 |
7 | contract StockToken is Exchangeable {
8 |
9 | /**
10 | *@dev constructs contract and premints tokens
11 | *@param _name name of the token
12 | *@param _symbol symbol of the token
13 | *@param _systemAddress address that acts as an admin of the system
14 | *@param _authorityAddress address that can change the systemAddress
15 | *@param _registeryAddress address of the registry contract the keeps track of all the contract Addresses
16 | *@param _returnToken address of the token user gets back when system forces them to convert(maintoken)
17 | *@param _which array of address to mint tokens to
18 | *@param _amount array of corresponding amount getting minted
19 | **/
20 | constructor(
21 | string memory _name,
22 | string memory _symbol,
23 | address _systemAddress,
24 | address _authorityAddress,
25 | address _registeryAddress,
26 | address _returnToken,
27 | address[] memory _which,
28 | uint256[] memory _amount
29 | )
30 | public
31 | TokenUtils(
32 | _name,
33 | _symbol,
34 | _systemAddress,
35 | _authorityAddress,
36 | _registeryAddress
37 | )
38 | ForceSwap(_returnToken)
39 | {
40 | require(_which.length == _amount.length, "ERR_NOT_SAME_LENGTH");
41 | for (uint256 tempX = 0; tempX < _which.length; tempX++) {
42 | require(
43 | IWhiteList(whiteListAddress).isWhiteListed(_which[tempX]),
44 | "ERR_TRANSFER_CHECK_WHITELIST"
45 | );
46 | _mint(_which[tempX], _amount[tempX]);
47 | }
48 | }
49 |
50 | /**
51 | *@dev checks before every transfer that takes place(except minting)
52 | *@param _from address from which tokens are being transferred
53 | *@param _to address to which tokens are being transfferred
54 | */
55 | function checkBeforeTransfer(address _from, address _to)
56 | internal
57 | returns (bool)
58 | {
59 | require(
60 | IWhiteList(whiteListAddress).stock_isTransferAllowed(
61 | msg.sender,
62 | _from,
63 | _to
64 | ),
65 | "ERR_NOT_HAVE_PERMISSION_TO_TRANSFER"
66 | );
67 |
68 | return true;
69 | }
70 |
71 | /** @dev Allows users to buy tokens from other accepteble tokens prices as per prices in currencyPrices contract
72 | *@param _fromToken the token user wants buy from
73 | *@param _amount amount of token users wants buy with. It assumes that contract has been approved atleast _amount buy msg.sender
74 | */
75 | function buyTokens(address _fromToken, uint256 _amount)
76 | external
77 | isConversionAllowed(_fromToken)
78 | returns (uint256)
79 | {
80 | //check if msg.sender is allowed
81 |
82 | require(
83 | IWhiteList(whiteListAddress).stock_isReceiveAllowed(msg.sender),
84 | "ERR_CANNOT_RECIEVE"
85 | );
86 |
87 | ICurrencyPrices currencyPrice = ICurrencyPrices(currencyPricesAddress);
88 |
89 | uint256 fromTokenPrice = currencyPrice.getCurrencyPrice(_fromToken);
90 |
91 | require(fromTokenPrice > 0, "ERR_TOKEN_PRICE_NOT_SET");
92 |
93 | uint256 currentTokenPrice = currencyPrice.getCurrencyPrice(
94 | address(this)
95 | );
96 |
97 | uint256 _assignToken = safeDiv(
98 | safeMul(_amount, fromTokenPrice),
99 | currentTokenPrice
100 | );
101 |
102 | if (_fromToken == returnToken) {
103 | IBEP20(_fromToken).transferFrom(msg.sender, vaultAddress, _amount);
104 | } else {
105 | IBEP20(_fromToken).transferFrom(msg.sender, address(this), _amount);
106 | IToken(_fromToken).burn(_amount);
107 | }
108 |
109 | _mint(msg.sender, _assignToken);
110 |
111 | return _assignToken;
112 | }
113 |
114 | function transfer(address _to, uint256 _value) external returns (bool ok) {
115 | require(checkBeforeTransfer(msg.sender, _to));
116 | return _transfer(msg.sender, _to, _value);
117 | }
118 |
119 | function transferFrom(
120 | address _from,
121 | address _to,
122 | uint256 _value
123 | ) external returns (bool) {
124 | require(checkBeforeTransfer(_from, _to));
125 | return _transferFrom(_from, _to, _value);
126 | }
127 |
128 | function() external payable {
129 | revert("ERR_CAN'T_FORCE_ETH");
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/contracts/Tokens/TokenUtils.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./StandardToken.sol";
4 | import "../common/SafeMath.sol";
5 | import "../common/Ownable.sol";
6 | import "../InterFaces/IAuctionRegistery.sol";
7 |
8 |
9 | /**@dev keeps track of registry contract at which all the addresses of the wholes system's contracts are stored */
10 | contract AuctionRegistery is AuctionRegisteryContracts, Ownable {
11 |
12 | IAuctionRegistery public contractsRegistry;
13 |
14 | address public whiteListAddress;
15 | address public smartSwapAddress;
16 | address public currencyPricesAddress;
17 | address public vaultAddress;
18 | address public auctionAddress;
19 |
20 | /**@dev sets the initial registry address */
21 | constructor(address _registeryAddress)
22 | public
23 | notZeroAddress(_registeryAddress)
24 | {
25 | contractsRegistry = IAuctionRegistery(_registeryAddress);
26 | _updateAddresses();
27 | }
28 |
29 | /**@dev updates the address of the registry, called only by the system */
30 | function updateRegistery(address _address)
31 | external
32 | onlyAuthorized()
33 | notZeroAddress(_address)
34 | returns (bool)
35 | {
36 | contractsRegistry = IAuctionRegistery(_address);
37 | _updateAddresses();
38 | return true;
39 | }
40 |
41 | /**@dev returns address of the asked contract got from registry contract at the registryAddress
42 | @param _contractName name of the contract */
43 | function getAddressOf(bytes32 _contractName)
44 | internal
45 | view
46 | returns (address)
47 | {
48 | return contractsRegistry.getAddressOf(_contractName);
49 | }
50 |
51 | /**@dev updates all the address from the registry contract
52 | this decision was made to save gas that occurs from calling an external view function */
53 | function _updateAddresses() internal {
54 | whiteListAddress = getAddressOf(WHITE_LIST);
55 | smartSwapAddress = getAddressOf(SMART_SWAP);
56 | currencyPricesAddress = getAddressOf(CURRENCY);
57 | vaultAddress = getAddressOf(VAULT);
58 | auctionAddress = getAddressOf(AUCTION);
59 | }
60 |
61 | function updateAddresses() external returns (bool) {
62 | _updateAddresses();
63 | }
64 | }
65 |
66 |
67 | /**@dev Also is a standard IBEP20 token*/
68 | contract TokenUtils is StandardToken, AuctionRegistery {
69 |
70 | /**
71 | *@dev contructs standard IBEP20 token and auction registry
72 | *@param _name name of the token
73 | *@param _symbol symbol of the token
74 | *@param _systemAddress address that acts as an admin of the system
75 | *@param _authorityAddress address that can change the systemAddress
76 | *@param _registeryAddress address of the registry contract the keeps track of all the contract Addresses
77 | **/
78 | constructor(
79 | string memory _name,
80 | string memory _symbol,
81 | address _systemAddress,
82 | address _authorityAddress,
83 | address _registeryAddress
84 | )
85 | public
86 | StandardToken(_name, _symbol, _systemAddress, _authorityAddress)
87 | AuctionRegistery(_registeryAddress)
88 | {
89 | _updateAddresses();
90 | }
91 |
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/contracts/WhiteList/README.md:
--------------------------------------------------------------------------------
1 | # Used flags
2 |
3 | KYC = 1 << 0; //0x01;
4 | AML = 1 << 1; //0x02;
5 | ACCREDIATED_INVESTOR = 1 << 2;
6 | QUALIFIED_INVESTOR = 1 << 3;
7 | RETAIL_INVESTOR = 1 << 4;
8 | DECENTRALIZE_EXCHANGE = 1 << 5
9 | CENTRALIZE_EXCHANGE = 1 << 6;
10 | IS_ALLOWED_ETN = 1 << 7;
11 | IS_ALLOWED_STOCK = 1 << 8;
12 | FROM_USA = 1 << 9;
13 | FROM_CHINA = 1 << 10;
14 | FROM_EU = 1 << 11;
15 | IS_BYPASSED = 1 << 12;
16 | POOL_ADDRESS = 1 << 13;
17 | IS_ALLOWED_AUCTION = 1 << 14;
18 | IS_ALLOWED_CENTRALIZE_EXCHANGE = 1 << 15;
19 | IS_STAKE = 1 << 16;
20 | IS_SMARTSWAP = 1 << 17;
21 |
--------------------------------------------------------------------------------
/contracts/WhiteList/WhiteListProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../common/Ownable.sol";
4 | import "../Proxy/IRegistry.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 |
7 | interface InitializeInterface {
8 | function initialize(
9 | address _primaryOwner,
10 | address _systemAddress,
11 | address _authorityAddress,
12 | uint256 _mainHoldBackDays,
13 | uint256 _etnHoldBackDays,
14 | uint256 _stockHoldBackDays,
15 | uint256 _mainMaturityDays,
16 | uint256 _etnMaturityDays,
17 | uint256 _stockMaturityDays,
18 | address _registryaddress
19 | ) external;
20 | }
21 |
22 | /**
23 | * @title Registry
24 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
25 | */
26 | contract WhiteListRegistery is Ownable, IRegistry {
27 | // Mapping of versions to implementations of different functions
28 | mapping(uint256 => address) internal versions;
29 |
30 | uint256 public currentVersion;
31 |
32 | address payable public proxyAddress;
33 |
34 | //@dev constructor
35 | //@param _systemAddress address of the system Owner
36 | constructor(address _systemAddress, address _multisigAddress)
37 | public
38 | Ownable(_systemAddress, _multisigAddress)
39 | {}
40 |
41 | /**
42 | * @dev Registers a new version with its implementation address
43 | * @param version representing the version name of the new implementation to be registered
44 | * @param implementation representing the address of the new implementation to be registered
45 | */
46 | function addVersion(uint256 version, address implementation)
47 | public
48 | onlyOneOfOnwer()
49 | notZeroAddress(implementation)
50 | {
51 | require(
52 | versions[version] == address(0),
53 | "This version has implementation attached"
54 | );
55 | versions[version] = implementation;
56 | emit VersionAdded(version, implementation);
57 | }
58 |
59 | /**
60 | * @dev Tells the address of the implementation for a given version
61 | * @param version to query the implementation of
62 | * @return address of the implementation registered for the given version
63 | */
64 | function getVersion(uint256 version) public view returns (address) {
65 | return versions[version];
66 | }
67 |
68 | /**
69 | * @dev Creates an upgradeable proxy
70 | * @param version representing the first version to be set for the proxy
71 | * @return address of the new proxy created
72 | */
73 | function createProxy(
74 | uint256 version,
75 | address _primaryOwner,
76 | address _systemAddress,
77 | address _authorityAddress,
78 | uint256 _mainHoldBackDays,
79 | uint256 _etnHoldBackDays,
80 | uint256 _stockHoldBackDays,
81 | uint256 _mainMaturityDays,
82 | uint256 _etnMaturityDays,
83 | uint256 _stockMaturityDays,
84 | address _registryaddress
85 | ) public onlyOneOfOnwer() returns (address) {
86 | require(proxyAddress == address(0), "ERR_PROXY_ALREADY_CREATED");
87 |
88 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
89 |
90 | InitializeInterface(address(proxy)).initialize(
91 | _primaryOwner,
92 | _systemAddress,
93 | _authorityAddress,
94 | _mainHoldBackDays,
95 | _etnHoldBackDays,
96 | _stockHoldBackDays,
97 | _mainMaturityDays,
98 | _etnMaturityDays,
99 | _stockMaturityDays,
100 | _registryaddress
101 | );
102 |
103 | currentVersion = version;
104 | proxyAddress = address(proxy);
105 | emit ProxyCreated(address(proxy));
106 | return address(proxy);
107 | }
108 |
109 | /**
110 | * @dev Upgrades the implementation to the requested version
111 | * @param version representing the version name of the new implementation to be set
112 | */
113 |
114 | function upgradeTo(uint256 version) public onlyAuthorized() returns (bool) {
115 | require(
116 | versions[version] != address(0),
117 | "ERR_ZERO_ADDDRESS"
118 | );
119 | currentVersion = version;
120 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
121 | return true;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/contracts/WhiteList/WhiteListStorage.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 | import "../InterFaces/IAuctionRegistery.sol";
3 |
4 | contract WhiteListStorage {
5 |
6 | IAuctionRegistery public contractsRegistry;
7 |
8 | address payable public auctionAddress;
9 |
10 |
11 | struct UserDetails {
12 | uint256 flags; // bitmap, where each bit correspondent to some properties (additional flags can be added in future).
13 | uint256 maxWallets;
14 | address[] wallets;
15 | }
16 |
17 | // Whitelist rules
18 | struct ReceivingRule {
19 | uint256 mask; // bit-mask to select bits which will be checked by this rule
20 | uint256 condition; // bit-sets which indicate the require bit status.
21 | // for example, if rule require that the 1 and 4 bits should be '1' and 2 bit should be '0', then mask = 0x16 (10110 binary) and condition = 0x12 (10010 binary). I.e. '1' is set for bit which should be '1' and '0' - for bit which should be '0'
22 | }
23 |
24 | // Restriction rules
25 | struct TransferringRule {
26 | uint256 from_mask; // bit-mask to select bits which will be checked by this rule
27 | uint256 from_condition; // bit-sets which indicate the require bit status.
28 | uint256 to_mask; // bit-mask to select bits which will be checked by this rule
29 | uint256 to_condition; // bit-sets which indicate the require bit status.
30 | // if rule 'from' return 'true' and rule 'to' is true - the transfer disallowed.
31 | // if rule 'from' return 'false' then don't check rule 'to'.
32 | }
33 |
34 | mapping(address => address) public address_belongs;
35 | mapping(address => UserDetails) public user_details;
36 |
37 | //Made this decision so that we can reuse the code
38 |
39 | //0:main
40 | //1:etn
41 | //2:stock
42 | mapping(uint8 => ReceivingRule) public tokenToReceivingRule;
43 | mapping(uint8 => TransferringRule[]) public tokenToTransferringRuleArray;
44 |
45 | //timestamp when hold back days are over
46 | mapping(uint8 => uint256) public tokenToHoldBackDaysTimeStamp;
47 | //timestamp when token matures
48 | mapping(uint8 => uint256) public tokenToMaturityDaysTimeStamp;
49 |
50 |
51 | uint256 public constant KYC = 1 << 0; //0x01
52 | uint256 public constant AML = 1 << 1; //0x02
53 | uint256 public constant ACCREDIATED_INVESTOR = 1 << 2;
54 | uint256 public constant QUALIFIED_INVESTOR = 1 << 3;
55 | uint256 public constant RETAIL_INVESTOR = 1 << 4;
56 | uint256 public constant DECENTRALIZE_EXCHANGE = 1 << 5; // wallet of decentralize exchanges
57 | uint256 public constant CENTRALIZE_EXCHANGE = 1 << 6; // wallet of centralize exchanges
58 | uint256 public constant IS_ALLOWED_ETN = 1 << 7;
59 | uint256 public constant IS_ALLOWED_STOCK = 1 << 8;
60 | uint256 public constant FROM_USA = 1 << 9;
61 | uint256 public constant FROM_CHINA = 1 << 10;
62 | uint256 public constant FROM_EU = 1 << 11;
63 | uint256 public constant IS_BYPASSED = 1 << 12;
64 | uint256 public constant POOL_ADDRESS = 1 << 13;
65 | uint256 public constant IS_ALLOWED_AUCTION = 1 << 14;
66 |
67 | event AccountWhiteListed(address indexed which, uint256 flags);
68 | event WalletAdded(address indexed from, address indexed which);
69 | event WalletRemoved(address indexed from, address indexed which);
70 | event FlagsChanged(address indexed which, uint256 flags);
71 |
72 | mapping (address => uint256) public blockedWallet;
73 |
74 | address payable public vaultAddress;
75 | address payable public liquidityAddress;
76 |
77 | }
--------------------------------------------------------------------------------
/contracts/auctionContracts/AuctionRegistery.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../common/Ownable.sol";
4 | import "../common/SafeMath.sol";
5 |
6 | interface Icontract {
7 | function updateAddresses() external returns (bool);
8 | }
9 |
10 | contract AuctionRegistery is Ownable, SafeMath {
11 | // store all contract address with bytes32 representation
12 | mapping(bytes32 => address payable) private contractAddress;
13 |
14 | // store contractIndex
15 | mapping(bytes32 => uint256) public contractIndex;
16 |
17 | // store all contract Name
18 | string[] public contracts;
19 |
20 | event ContractAddressUpdated(
21 | bytes32 indexed _contractName,
22 | address _contractAddressFrom,
23 | address _contractAddressTo
24 | );
25 |
26 | constructor(address _systemAddess, address _multisig)
27 | public
28 | Ownable(_systemAddess, _multisig)
29 | {}
30 |
31 | function totalContracts() external view returns (uint256) {
32 | return contracts.length;
33 | }
34 |
35 | function getAddressOf(bytes32 _contractName)
36 | external
37 | view
38 | returns (address payable)
39 | {
40 | return contractAddress[_contractName];
41 | }
42 |
43 | /**
44 | * @dev add new contarct address to the registery
45 | * @return bool
46 | */
47 | function registerContractAddress(
48 | bytes32 _contractName,
49 | address payable _contractAddress
50 | )
51 | external
52 | onlyOneOfOnwer()
53 | notZeroValue(_contractName.length)
54 | notZeroAddress(_contractAddress)
55 | returns (bool)
56 | {
57 | require(contractAddress[_contractName] == address(0), ERR_SAME_ADDRESS);
58 |
59 | contractAddress[_contractName] = _contractAddress;
60 |
61 | contractIndex[_contractName] = contracts.length;
62 |
63 | contracts.push(bytes32ToString(_contractName));
64 |
65 | emit ContractAddressUpdated(
66 | _contractName,
67 | address(0),
68 | _contractAddress
69 | );
70 |
71 | return true;
72 | }
73 |
74 | /**
75 | * @dev update contarct address to the registery
76 | * note that we dont need to update contractAddress index we just update contract addres only
77 | * @return bool
78 | */
79 | function updateContractAddress(
80 | bytes32 _contractName,
81 | address payable _contractAddress
82 | )
83 | external
84 | onlyOwner()
85 | notZeroValue(_contractName.length)
86 | notZeroAddress(_contractAddress)
87 | notZeroAddress(contractAddress[_contractName])
88 | returns (bool)
89 | {
90 | emit ContractAddressUpdated(
91 | _contractName,
92 | contractAddress[_contractName],
93 | _contractAddress
94 | );
95 | contractAddress[_contractName] = _contractAddress;
96 |
97 | return true;
98 | }
99 |
100 | /**
101 | * @dev remove contarct address to the registery
102 | * @return bool
103 | */
104 | function removeContractAddress(bytes32 _contractName)
105 | external
106 | onlyAuthorized()
107 | notZeroValue(_contractName.length)
108 | notZeroAddress(contractAddress[_contractName])
109 | returns (bool)
110 | {
111 | uint256 _contractIndex = contractIndex[_contractName];
112 |
113 | string memory lastContract = contracts[safeSub(contracts.length, 1)];
114 |
115 | bytes32 lastContractBytes = stringToBytes32(lastContract);
116 |
117 | contracts[_contractIndex] = lastContract;
118 |
119 | contractIndex[lastContractBytes] = _contractIndex;
120 |
121 | emit ContractAddressUpdated(
122 | _contractName,
123 | contractAddress[_contractName],
124 | address(0)
125 | );
126 |
127 | delete contractAddress[_contractName];
128 |
129 | delete contractIndex[_contractName];
130 |
131 | contracts.pop();
132 |
133 | return true;
134 | }
135 |
136 | /**
137 | * @dev utility, converts bytes32 to a string
138 | * note that the bytes32 argument is assumed to be UTF8 encoded ASCII string
139 | *
140 | * @return string representation of the given bytes32 argument
141 | */
142 | function bytes32ToString(bytes32 _bytes)
143 | public
144 | pure
145 | returns (string memory)
146 | {
147 | bytes memory byteArray = new bytes(32);
148 | for (uint256 i; i < 32; i++) {
149 | byteArray[i] = _bytes[i];
150 | }
151 |
152 | return string(byteArray);
153 | }
154 |
155 | /**
156 | * @dev utility, converts string to bytes32
157 | * note that the bytes32 argument is assumed to be UTF8 encoded ASCII string
158 | *
159 | * @return string representation of the given bytes32 argument
160 | */
161 | function stringToBytes32(string memory _string)
162 | public
163 | pure
164 | returns (bytes32)
165 | {
166 | bytes32 result;
167 | assembly {
168 | result := mload(add(_string, 32))
169 | }
170 | return result;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/contracts/common/Constant.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | contract Constant {
4 | string constant ERR_CONTRACT_SELF_ADDRESS = "ERR_CONTRACT_SELF_ADDRESS";
5 |
6 | string constant ERR_ZERO_ADDRESS = "ERR_ZERO_ADDRESS";
7 |
8 | string constant ERR_NOT_OWN_ADDRESS = "ERR_NOT_OWN_ADDRESS";
9 |
10 | string constant ERR_VALUE_IS_ZERO = "ERR_VALUE_IS_ZERO";
11 |
12 | string constant ERR_SAME_ADDRESS = "ERR_SAME_ADDRESS";
13 |
14 | string constant ERR_AUTHORIZED_ADDRESS_ONLY = "ERR_AUTHORIZED_ADDRESS_ONLY";
15 |
16 | modifier notOwnAddress(address _which) {
17 | require(msg.sender != _which, ERR_NOT_OWN_ADDRESS);
18 | _;
19 | }
20 |
21 | // validates an address is not zero
22 | modifier notZeroAddress(address _which) {
23 | require(_which != address(0), ERR_ZERO_ADDRESS);
24 | _;
25 | }
26 |
27 | // verifies that the address is different than this contract address
28 | modifier notThisAddress(address _which) {
29 | require(_which != address(this), ERR_CONTRACT_SELF_ADDRESS);
30 | _;
31 | }
32 |
33 | modifier notZeroValue(uint256 _value) {
34 | require(_value > 0, ERR_VALUE_IS_ZERO);
35 | _;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/contracts/common/MultiSigGovernance.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./SafeMath.sol";
4 |
5 | contract MultiSigConstant {
6 | string constant ERR_SAME_ADDRESS = "ERR_SAME_ADDRESS";
7 |
8 | string constant ERR_CONTRACT_SELF_ADDRESS = "ERR_CONTRACT_SELF_ADDRESS";
9 |
10 | string constant ERR_ZERO_ADDRESS = "ERR_ZERO_ADDRESS";
11 |
12 | string constant ERR_ZERO_VALUE = "ERR_ZERO_VALUE";
13 |
14 | string constant ERR_AUTHORIZED_ADDRESS_ONLY = "ERR_AUTHORIZED_ADDRESS_ONLY";
15 |
16 | string constant ERR_OWNER_MAXIMUM_LIMIT = "ERR_OWNER_MAXIMUM_LIMIT";
17 |
18 | string constant ERR_OWNER_MINIMUM_LIMIT = "ERR_OWNER_MINIMUM_LIMIT";
19 |
20 | string constant ERR_CONFIRMATION_LIMIT = "ERR_CONFIRMATION_LIMIT";
21 |
22 | string constant ERR_TRAN_NOT_AVILABLE = "ERR_TRAN_NOT_AVILABLE";
23 |
24 | string constant ERR_TRAN_ALREADY_EXUCATED = "ERR_TRAN_ALREADY_EXUCATED";
25 |
26 | string constant ERR_TRAN_ALREADY_SIGNED = "ERR_TRAN_ALREADY_SIGNED";
27 |
28 | string constant ERR_TRAN_NOT_SIGNED = "ERR_TRAN_NOT_SIGNED";
29 |
30 | // validates an address is not zero
31 | modifier notZeroAddress(address _which) {
32 | require(_which != address(0), ERR_ZERO_ADDRESS);
33 | _;
34 | }
35 | }
36 |
37 | contract MultiSigOwnable is MultiSigConstant, SafeMath {
38 | uint256 public constant MAX_OWNERS_ALLOWED = 30;
39 |
40 | mapping(address => bool) public isOwner;
41 |
42 | mapping(address => uint256) public ownerIndex;
43 |
44 | address[] public multiSigOwners;
45 |
46 | uint256 public minConfirmationsRequired;
47 |
48 | modifier onlyAuthorized() {
49 | require(msg.sender == address(this), ERR_AUTHORIZED_ADDRESS_ONLY);
50 | _;
51 | }
52 |
53 | modifier notOwner(address _which) {
54 | require(!isOwner[_which], ERR_SAME_ADDRESS);
55 | _;
56 | }
57 |
58 | modifier shoudBeOwner(address _which) {
59 | require(isOwner[_which], ERR_AUTHORIZED_ADDRESS_ONLY);
60 | _;
61 | }
62 |
63 | event OwnerAdded(address indexed owner);
64 | event OwnerRemoved(address indexed owner);
65 |
66 | function addNewOwner(address _owner)
67 | external
68 | onlyAuthorized()
69 | notZeroAddress(_owner)
70 | notOwner(_owner)
71 | returns (bool)
72 | {
73 | require(
74 | safeAdd(multiSigOwners.length, 1) <= MAX_OWNERS_ALLOWED,
75 | ERR_OWNER_MAXIMUM_LIMIT
76 | );
77 |
78 | ownerIndex[_owner] = multiSigOwners.length;
79 | isOwner[_owner] = true;
80 | multiSigOwners.push(_owner);
81 | emit OwnerAdded(_owner);
82 | return true;
83 | }
84 |
85 | function removeOwner(address _owner)
86 | external
87 | onlyAuthorized()
88 | notZeroAddress(_owner)
89 | shoudBeOwner(_owner)
90 | returns (bool)
91 | {
92 | require(
93 | safeSub(multiSigOwners.length, 1) >= 1,
94 | ERR_OWNER_MINIMUM_LIMIT
95 | );
96 |
97 | isOwner[_owner] = false;
98 |
99 | uint256 _ownerIndex = ownerIndex[_owner];
100 |
101 | address _lastAdress = multiSigOwners[safeSub(multiSigOwners.length, 1)];
102 |
103 | multiSigOwners[_ownerIndex] = _lastAdress;
104 |
105 | ownerIndex[_lastAdress] = _ownerIndex;
106 |
107 | multiSigOwners.pop();
108 |
109 | if (minConfirmationsRequired > multiSigOwners.length)
110 | minConfirmationsRequired = multiSigOwners.length;
111 |
112 | emit OwnerRemoved(_owner);
113 | return true;
114 | }
115 |
116 | function changeMinConfirmationsRequired(uint256 _minConfirmationsRequired)
117 | external
118 | onlyAuthorized()
119 | returns (bool)
120 | {
121 | require(
122 | multiSigOwners.length >= _minConfirmationsRequired,
123 | ERR_CONFIRMATION_LIMIT
124 | );
125 | minConfirmationsRequired = _minConfirmationsRequired;
126 | return true;
127 | }
128 | }
129 |
130 | contract MultiSigGovernance is MultiSigOwnable {
131 | struct Transaction {
132 | address destination;
133 | uint256 value;
134 | bytes data;
135 | bool executed;
136 | uint256 confirmationsRequired;
137 | }
138 |
139 | mapping(uint256 => Transaction) public transactions;
140 |
141 | mapping(uint256 => uint256) public confirmationsCount;
142 |
143 | mapping(uint256 => mapping(address => bool)) public confirmations;
144 |
145 | uint256 public transactionCount;
146 |
147 | event NewTransactionAdded(uint256 indexed transactionId, address owner);
148 | event TransactionConfirmed(uint256 indexed transactionId, address owner);
149 | event TransactionConfirmationRevoked(
150 | uint256 indexed transactionId,
151 | address owner
152 | );
153 | event TransactionExecuted(uint256 indexed transactionId, bool isSuccess);
154 |
155 | modifier notExecuted(uint256 transactionId) {
156 | require(
157 | transactions[transactionId].destination != address(0),
158 | ERR_TRAN_NOT_AVILABLE
159 | );
160 | require(
161 | transactions[transactionId].executed == false,
162 | ERR_TRAN_ALREADY_EXUCATED
163 | );
164 | _;
165 | }
166 |
167 | constructor(
168 | address[] memory _multiSigOwners,
169 | uint256 _minConfirmationsRequired
170 | ) public {
171 | require(
172 | _multiSigOwners.length >= _minConfirmationsRequired,
173 | ERR_CONFIRMATION_LIMIT
174 | );
175 |
176 | for (uint256 i = 0; i < _multiSigOwners.length; i++) {
177 | require(
178 | isOwner[_multiSigOwners[i]] == false &&
179 | _multiSigOwners[i] != address(0),
180 | ERR_SAME_ADDRESS
181 | );
182 | isOwner[_multiSigOwners[i]] = true;
183 | ownerIndex[_multiSigOwners[i]] = i;
184 | }
185 | multiSigOwners = _multiSigOwners;
186 | minConfirmationsRequired = _minConfirmationsRequired;
187 | }
188 |
189 | function external_call(
190 | address destination,
191 | uint256 value,
192 | uint256 dataLength,
193 | bytes memory data
194 | ) private returns (bool) {
195 | bool result;
196 | assembly {
197 | let x := mload(0x40)
198 | let d := add(data, 32)
199 | result := call(gas(), destination, value, d, dataLength, x, 0)
200 | }
201 | return result;
202 | }
203 |
204 | function addTransaction(
205 | address destination,
206 | uint256 value,
207 | bytes calldata data,
208 | uint256 _confirmationsRequired
209 | )
210 | external
211 | shoudBeOwner(msg.sender)
212 | notZeroAddress(destination)
213 | returns (uint256 transactionId)
214 | {
215 | require(
216 | _confirmationsRequired >= minConfirmationsRequired,
217 | ERR_CONFIRMATION_LIMIT
218 | );
219 |
220 | require(
221 | multiSigOwners.length >= _confirmationsRequired,
222 | ERR_OWNER_MAXIMUM_LIMIT
223 | );
224 |
225 | transactionId = transactionCount;
226 |
227 | transactions[transactionId] = Transaction({
228 | destination: destination,
229 | value: value,
230 | data: data,
231 | executed: false,
232 | confirmationsRequired: _confirmationsRequired
233 | });
234 | emit NewTransactionAdded(transactionCount, msg.sender);
235 | transactionCount = safeAdd(transactionCount, 1);
236 | confirmTransaction(transactionId);
237 | return transactionId;
238 | }
239 |
240 | function confirmTransaction(uint256 transactionId)
241 | public
242 | shoudBeOwner(msg.sender)
243 | notExecuted(transactionId)
244 | returns (bool)
245 | {
246 | require(
247 | !confirmations[transactionId][msg.sender],
248 | ERR_TRAN_ALREADY_SIGNED
249 | );
250 | confirmations[transactionId][msg.sender] = true;
251 |
252 | confirmationsCount[transactionId] = safeAdd(
253 | confirmationsCount[transactionId],
254 | 1
255 | );
256 |
257 | emit TransactionConfirmed(transactionId, msg.sender);
258 | executeTransaction(transactionId);
259 | return true;
260 | }
261 |
262 | function revokeConfirmation(uint256 transactionId)
263 | public
264 | shoudBeOwner(msg.sender)
265 | notExecuted(transactionId)
266 | returns (bool)
267 | {
268 | require(confirmations[transactionId][msg.sender], ERR_TRAN_NOT_SIGNED);
269 | confirmations[transactionId][msg.sender] = false;
270 | confirmationsCount[transactionId] = safeSub(
271 | confirmationsCount[transactionId],
272 | 1
273 | );
274 | emit TransactionConfirmationRevoked(transactionId, msg.sender);
275 | return true;
276 | }
277 |
278 | function executeTransaction(uint256 transactionId)
279 | public
280 | shoudBeOwner(msg.sender)
281 | notExecuted(transactionId)
282 | returns (bool)
283 | {
284 | if (
285 | confirmationsCount[transactionId] >=
286 | transactions[transactionId].confirmationsRequired
287 | ) {
288 | Transaction storage txn = transactions[transactionId];
289 | bool result = external_call(
290 | txn.destination,
291 | txn.value,
292 | txn.data.length,
293 | txn.data
294 | );
295 | txn.executed = result;
296 | emit TransactionExecuted(transactionId, result);
297 | }
298 | return true;
299 | }
300 |
301 | function withDrawEth(uint256 balance, address payable _address)
302 | external
303 | onlyAuthorized()
304 | notZeroAddress(_address)
305 | returns (bool)
306 | {
307 | require(address(this).balance >= balance, ERR_TRAN_NOT_AVILABLE);
308 | _address.transfer(balance);
309 | return true;
310 | }
311 |
312 | function() external payable {}
313 | }
314 |
--------------------------------------------------------------------------------
/contracts/common/Ownable.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./Constant.sol";
4 |
5 | contract Ownable is Constant {
6 | address public primaryOwner = address(0);
7 |
8 | address public authorityAddress = address(0);
9 |
10 | address public systemAddress = address(0);
11 |
12 | address public newAuthorityAddress = address(0);
13 |
14 | event OwnershipTransferred(
15 | string ownerType,
16 | address indexed previousOwner,
17 | address indexed newOwner
18 | );
19 | event AuthorityAddressChnageCall(
20 | address indexed previousOwner,
21 | address indexed newOwner
22 | );
23 |
24 | /**
25 | * @dev The Ownable constructor sets the `primaryOwner` and `systemAddress` and '_multisigAddress'
26 | * account.
27 | */
28 | constructor(address _systemAddress, address _authorityAddress)
29 | public
30 | notZeroAddress(_systemAddress)
31 | {
32 | require(msg.sender != _systemAddress, ERR_SAME_ADDRESS);
33 |
34 | require(_systemAddress != _authorityAddress, ERR_SAME_ADDRESS);
35 |
36 | require(msg.sender != _authorityAddress, ERR_SAME_ADDRESS);
37 |
38 | primaryOwner = msg.sender;
39 |
40 | systemAddress = _systemAddress;
41 |
42 | authorityAddress = _authorityAddress;
43 | }
44 |
45 | modifier onlyOwner() {
46 | require(msg.sender == primaryOwner, ERR_AUTHORIZED_ADDRESS_ONLY);
47 | _;
48 | }
49 |
50 | modifier onlySystem() {
51 | require(msg.sender == systemAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
52 | _;
53 | }
54 |
55 | modifier onlyOneOfOnwer() {
56 | require(
57 | msg.sender == primaryOwner || msg.sender == systemAddress,
58 | ERR_AUTHORIZED_ADDRESS_ONLY
59 | );
60 | _;
61 | }
62 |
63 | modifier onlyAuthorized() {
64 | require(msg.sender == authorityAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
65 | _;
66 | }
67 |
68 | /**
69 | * @dev change primary ownership governance
70 | */
71 | function changePrimaryOwner()
72 | public
73 | onlyOwner()
74 | returns (bool)
75 | {
76 | emit OwnershipTransferred("PRIMARY_OWNER", primaryOwner, authorityAddress);
77 | primaryOwner = authorityAddress;
78 | return true;
79 | }
80 |
81 | /**
82 | * @dev change system address
83 | * @param _which The address to which is new system address
84 | */
85 | function changeSystemAddress(address _which)
86 | public
87 | onlyAuthorized()
88 | notThisAddress(_which)
89 | notZeroAddress(_which)
90 | returns (bool)
91 | {
92 | require(
93 | _which != systemAddress &&
94 | _which != authorityAddress &&
95 | _which != primaryOwner,
96 | ERR_SAME_ADDRESS
97 | );
98 | emit OwnershipTransferred("SYSTEM_ADDRESS", systemAddress, _which);
99 | systemAddress = _which;
100 | return true;
101 | }
102 |
103 | /**
104 | * @dev change system address
105 | * @param _which The address to which is new Authority address
106 | */
107 | function changeAuthorityAddress(address _which)
108 | public
109 | onlyAuthorized()
110 | notZeroAddress(_which)
111 | returns (bool)
112 | {
113 | require(
114 | _which != systemAddress &&
115 | _which != authorityAddress &&
116 | _which != primaryOwner,
117 | ERR_SAME_ADDRESS
118 | );
119 | newAuthorityAddress = _which;
120 | return true;
121 | }
122 |
123 | function acceptAuthorityAddress() public returns (bool) {
124 | require(msg.sender == newAuthorityAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
125 | emit OwnershipTransferred(
126 | "AUTHORITY_ADDRESS",
127 | authorityAddress,
128 | newAuthorityAddress
129 | );
130 | authorityAddress = newAuthorityAddress;
131 | newAuthorityAddress = address(0);
132 | return true;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/contracts/common/ProxyOwnable.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "./Constant.sol";
4 |
5 |
6 | contract ProxyOwnable is Constant {
7 |
8 | address public primaryOwner;
9 |
10 | address public authorityAddress;
11 |
12 | address public newAuthorityAddress;
13 |
14 | address public systemAddress;
15 |
16 | bool public isOwnerInitialize = false;
17 |
18 | event OwnershipTransferred(
19 | string ownerType,
20 | address indexed previousOwner,
21 | address indexed newOwner
22 | );
23 |
24 | event AuthorityAddressChnageCall(
25 | address indexed previousOwner,
26 | address indexed newOwner
27 | );
28 |
29 | /**
30 | * @dev The Ownable constructor sets the `primaryOwner` and `systemAddress` and '_multisigAddress'
31 | * account.
32 | */
33 |
34 | function initializeOwner(
35 | address _primaryOwner,
36 | address _systemAddress,
37 | address _authorityAddress
38 | ) internal notZeroAddress(_primaryOwner) notZeroAddress(_systemAddress) notZeroAddress(_authorityAddress) {
39 |
40 | require(!isOwnerInitialize,"ERR_OWNER_INTIALIZED_ALREADY");
41 |
42 | require(_primaryOwner != _systemAddress, ERR_SAME_ADDRESS);
43 |
44 | require(_systemAddress != _authorityAddress, ERR_SAME_ADDRESS);
45 |
46 | require(_primaryOwner != _authorityAddress, ERR_SAME_ADDRESS);
47 |
48 | primaryOwner = _primaryOwner;
49 | systemAddress = _systemAddress;
50 | authorityAddress = _authorityAddress;
51 | isOwnerInitialize = true;
52 | }
53 |
54 | modifier onlyOwner() {
55 | require(msg.sender == primaryOwner, ERR_AUTHORIZED_ADDRESS_ONLY);
56 | _;
57 | }
58 |
59 | modifier onlySystem() {
60 | require(msg.sender == systemAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
61 | _;
62 | }
63 |
64 | modifier onlyOneOfOnwer() {
65 | require(
66 | msg.sender == primaryOwner || msg.sender == systemAddress,
67 | ERR_AUTHORIZED_ADDRESS_ONLY
68 | );
69 | _;
70 | }
71 |
72 | modifier onlyAuthorized() {
73 | require(msg.sender == authorityAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
74 | _;
75 | }
76 |
77 | /**
78 | * @dev change primary ownership governance
79 | */
80 | function changePrimaryOwner()
81 | public
82 | onlyOwner()
83 | returns (bool)
84 | {
85 | emit OwnershipTransferred("PRIMARY_OWNER", primaryOwner, authorityAddress);
86 | primaryOwner = authorityAddress;
87 | return true;
88 | }
89 |
90 | /**
91 | * @dev change system address
92 | * @param _which The address to which is new system address
93 | */
94 | function changeSystemAddress(address _which)
95 | public
96 | onlyAuthorized()
97 | notThisAddress(_which)
98 | notZeroAddress(_which)
99 | returns (bool)
100 | {
101 | require(
102 | _which != systemAddress &&
103 | _which != authorityAddress &&
104 | _which != primaryOwner,
105 | ERR_SAME_ADDRESS
106 | );
107 | emit OwnershipTransferred("SYSTEM_ADDRESS", systemAddress, _which);
108 | systemAddress = _which;
109 | return true;
110 | }
111 |
112 | /**
113 | * @dev change system address
114 | * @param _which The address to which is new Authority address
115 | */
116 | function changeAuthorityAddress(address _which)
117 | public
118 | onlyAuthorized()
119 | notZeroAddress(_which)
120 | returns (bool)
121 | {
122 | require(
123 | _which != systemAddress &&
124 | _which != authorityAddress,
125 | ERR_SAME_ADDRESS
126 | );
127 | newAuthorityAddress = _which;
128 | return true;
129 | }
130 |
131 | function acceptAuthorityAddress() public returns (bool) {
132 | require(msg.sender == newAuthorityAddress, ERR_AUTHORIZED_ADDRESS_ONLY);
133 | emit OwnershipTransferred(
134 | "AUTHORITY_ADDRESS",
135 | authorityAddress,
136 | newAuthorityAddress
137 | );
138 | authorityAddress = newAuthorityAddress;
139 | newAuthorityAddress = address(0);
140 | return true;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/contracts/common/SafeMath.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | contract SafeMath {
4 | function safeMul(uint256 a, uint256 b) internal pure returns (uint256) {
5 | if (a == 0) {
6 | return 0;
7 | }
8 | uint256 c = a * b;
9 | assert(c / a == b);
10 | return c;
11 | }
12 |
13 | function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) {
14 | uint256 c = a / b;
15 | return c;
16 | }
17 |
18 | function safeSub(uint256 a, uint256 b) internal pure returns (uint256) {
19 | assert(b <= a);
20 | return a - b;
21 | }
22 |
23 | function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) {
24 | uint256 c = a + b;
25 | assert(c >= a);
26 | return c;
27 | }
28 |
29 | function safeExponent(uint256 a, uint256 b)
30 | internal
31 | pure
32 | returns (uint256)
33 | {
34 | uint256 result;
35 | assembly {
36 | result := exp(a, b)
37 | }
38 | return result;
39 | }
40 |
41 | // calculates a^(1/n) to dp decimal places
42 | // maxIts bounds the number of iterations performed
43 | function nthRoot(
44 | uint256 _a,
45 | uint256 _n,
46 | uint256 _dp,
47 | uint256 _maxIts
48 | ) internal pure returns (uint256) {
49 | assert(_n > 1);
50 |
51 | // The scale factor is a crude way to turn everything into integer calcs.
52 | // Actually do (a * (10 ^ ((dp + 1) * n))) ^ (1/n)
53 | // We calculate to one extra dp and round at the end
54 | uint256 one = 10**(1 + _dp);
55 | uint256 a0 = one**_n * _a;
56 |
57 | // Initial guess: 1.0
58 | uint256 xNew = one;
59 | uint256 x;
60 |
61 | uint256 iter = 0;
62 | while (xNew != x && iter < _maxIts) {
63 | x = xNew;
64 | uint256 t0 = x**(_n - 1);
65 | if (x * t0 > a0) {
66 | xNew = x - (x - a0 / t0) / _n;
67 | } else {
68 | xNew = x + (a0 / t0 - x) / _n;
69 | }
70 | ++iter;
71 | }
72 |
73 | // Round to nearest in the last dp.
74 | return (xNew + 5) / 10;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/contracts/common/TokenTransfer.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../InterFaces/IBEP20Token.sol";
4 |
5 | contract TokenTransfer {
6 | function ensureTransferFrom(
7 | IBEP20Token _token,
8 | address _from,
9 | address _to,
10 | uint256 _amount
11 | ) internal {
12 | if (_from == address(this))
13 | require(_token.transfer(_to, _amount), "ERR_TOKEN_TRANSFER_FAIL");
14 | else
15 | require(
16 | _token.transferFrom(_from, _to, _amount),
17 | "ERR_TOKEN_TRANSFER_FAIL"
18 | );
19 | }
20 |
21 | function approveTransferFrom(
22 | IBEP20Token _token,
23 | address _spender,
24 | uint256 _amount
25 | ) internal {
26 | require(_token.approve(_spender, _amount), "ERR_TOKEN_APPROVAL_FAIL");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/contracts/contributionTrigger/ContributionTrigger.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../common/SafeMath.sol";
4 | import "../common/ProxyOwnable.sol";
5 | import "../Proxy/Upgradeable.sol";
6 | import "../common/TokenTransfer.sol";
7 | import "../InterFaces/IAuctionRegistery.sol";
8 | import "../InterFaces/ICurrencyPrices.sol";
9 | import "../InterFaces/IBEP20Token.sol";
10 | import "../InterFaces/IAuctionLiquidity.sol";
11 | import "../InterFaces/IAuction.sol";
12 | import "../InterFaces/ITokenVault.sol";
13 |
14 | interface ContributionTriggerInitializeInterface {
15 | function initialize(
16 | address _primaryOwner,
17 | address _systemAddress,
18 | address _multisigAdress,
19 | address _registryaddress
20 | ) external;
21 | }
22 |
23 | contract RegisteryContributionTrigger is ProxyOwnable, AuctionRegisteryContracts {
24 | IAuctionRegistery public contractsRegistry;
25 | address payable public liquidityAddress;
26 |
27 | event FundDeposited(address _token, address _from, uint256 _amount);
28 |
29 | function initilizeRegistry(
30 | address _primaryOwner,
31 | address _systemAddress,
32 | address _multisigAdress,
33 | address _registryaddress
34 | ) internal {
35 | initializeOwner(_primaryOwner, _systemAddress, _multisigAdress);
36 | contractsRegistry = IAuctionRegistery(_registryaddress);
37 | _updateAddresses();
38 | }
39 |
40 | function updateRegistery(address _address)
41 | external
42 | onlyAuthorized()
43 | notZeroAddress(_address)
44 | returns (bool)
45 | {
46 | contractsRegistry = IAuctionRegistery(_address);
47 | _updateAddresses();
48 | return true;
49 | }
50 |
51 | function getAddressOf(bytes32 _contractName)
52 | internal
53 | view
54 | returns (address payable)
55 | {
56 | return contractsRegistry.getAddressOf(_contractName);
57 | }
58 |
59 | /**@dev updates all the address from the registry contract
60 | this decision was made to save gas that occurs from calling an external view function */
61 |
62 | function _updateAddresses() internal {
63 | liquidityAddress = getAddressOf(LIQUIDITY);
64 | }
65 |
66 | function updateAddresses() external returns (bool) {
67 | _updateAddresses();
68 | return true;
69 | }
70 | }
71 |
72 | contract ContributionTrigger is
73 | Upgradeable,
74 | RegisteryContributionTrigger,
75 | TokenTransfer,
76 | ContributionTriggerInitializeInterface
77 | {
78 | function initialize(
79 | address _primaryOwner,
80 | address _systemAddress,
81 | address _multisigAdress,
82 | address _registryaddress
83 | ) external {
84 | super.initialize();
85 | initilizeRegistry(
86 | _primaryOwner,
87 | _systemAddress,
88 | _multisigAdress,
89 | _registryaddress
90 | );
91 | }
92 |
93 | function contributeTowardLiquidity(uint256 _amount)
94 | external
95 | returns (uint256)
96 | {
97 | require(msg.sender == liquidityAddress, "ERR_ONLY_Liquidity_ALLOWED");
98 |
99 | if (_amount > address(this).balance) {
100 | uint256 _newamount = address(this).balance;
101 | msg.sender.transfer(_newamount);
102 | return _newamount;
103 | }
104 | msg.sender.transfer(_amount);
105 | return _amount;
106 | }
107 |
108 | // relay token and bnt token
109 | function transferTokenLiquidity(
110 | IBEP20Token _token,
111 | address _reciver,
112 | uint256 _amount
113 | ) external returns (bool) {
114 | require(msg.sender == liquidityAddress, "ERR_ONLY_Liquidity_ALLOWED");
115 | ensureTransferFrom(_token, address(this), _reciver, _amount);
116 | return true;
117 | }
118 |
119 | function depositeToken(
120 | IBEP20Token _token,
121 | address _from,
122 | uint256 _amount
123 | ) external returns (bool) {
124 | ensureTransferFrom(_token, _from, address(this), _amount);
125 | emit FundDeposited(address(_token), _from, _amount);
126 | return true;
127 | }
128 |
129 | function() external payable {}
130 | }
131 |
--------------------------------------------------------------------------------
/contracts/contributionTrigger/ContributionTriggerProxy.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | import "../Proxy/IRegistry.sol";
4 | import "../common/Ownable.sol";
5 | import "../Proxy/UpgradeabilityProxy.sol";
6 | import "../InterFaces/IBEP20Token.sol";
7 |
8 | interface ContributionTriggerProxyInitializeInterface {
9 | function initialize(
10 | address _primaryOwner,
11 | address _systemAddress,
12 | address _multisigAdress,
13 | address _registryaddress
14 | ) external;
15 | }
16 |
17 | /**
18 | * @title Registry
19 | * @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
20 | */
21 | contract ContributionTriggerRegistry is Ownable, IRegistry {
22 | // Mapping of versions to implementations of different functions
23 | mapping(uint256 => address) internal versions;
24 |
25 | uint256 public currentVersion;
26 |
27 | address payable public proxyAddress;
28 |
29 | //@dev constructor
30 | //@param _systemAddress address of the system Owner
31 | constructor(address _systemAddress, address _multisigAddress)
32 | public
33 | Ownable(_systemAddress, _multisigAddress)
34 | {}
35 |
36 | /**
37 | * @dev Registers a new version with its implementation address
38 | * @param version representing the version name of the new implementation to be registered
39 | * @param implementation representing the address of the new implementation to be registered
40 | */
41 | function addVersion(uint256 version, address implementation)
42 | public
43 | onlyOneOfOnwer()
44 | notZeroAddress(implementation)
45 | {
46 | require(
47 | versions[version] == address(0),
48 | "This version has implementation attached"
49 | );
50 | versions[version] = implementation;
51 | emit VersionAdded(version, implementation);
52 | }
53 |
54 | /**
55 | * @dev Tells the address of the implementation for a given version
56 | * @param version to query the implementation of
57 | * @return address of the implementation registered for the given version
58 | */
59 | function getVersion(uint256 version) public view returns (address) {
60 | return versions[version];
61 | }
62 |
63 | /**
64 | * @dev Creates an upgradeable proxy
65 | * @param version representing the first version to be set for the proxy
66 | * @return address of the new proxy created
67 | */
68 | function createProxy(
69 | uint256 version,
70 | address _primaryOwner,
71 | address _systemAddress,
72 | address _multisigAdress,
73 | address _registryaddress
74 | ) external onlyOneOfOnwer() returns (address) {
75 | require(proxyAddress == address(0), "ERR_PROXY_ALREADY_CREATED");
76 |
77 | UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);
78 |
79 | ContributionTriggerProxyInitializeInterface(address(proxy)).initialize(
80 | _primaryOwner,
81 | _systemAddress,
82 | _multisigAdress,
83 | _registryaddress
84 | );
85 |
86 | currentVersion = version;
87 | proxyAddress = address(proxy);
88 | emit ProxyCreated(address(proxy));
89 | return address(proxy);
90 | }
91 |
92 | /**
93 | * @dev Upgrades the implementation to the requested version
94 | * @param version representing the version name of the new implementation to be set
95 | */
96 |
97 | function upgradeTo(uint256 version) public onlyAuthorized() returns (bool) {
98 | currentVersion = version;
99 | UpgradeabilityProxy(proxyAddress).upgradeTo(version);
100 | return true;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/contracts/test/TestAuction.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | //This contract is made to just test the redemption functionality in liquity and protection
4 | //All the other functionlity that requires auction in Liquidity contract is done with the original auction in
5 | //the auctionTests.js itself
6 |
7 |
8 | import "../InterFaces/IBEP20Token.sol";
9 |
10 | contract TestAuction {
11 | // uint256 public auctionDay = 1;
12 |
13 | // address protectionAddress;
14 |
15 | // constructor(address _protectionAddress) public {
16 | // protectionAddress = _protectionAddress;
17 | // }
18 |
19 | // function changeAuctionDay(uint256 _auctionDay) public {
20 | // auctionDay = _auctionDay;
21 | // }
22 |
23 | // function depositToken(
24 | // address _from,
25 | // address _which,
26 | // uint256 _amount
27 | // ) external returns (bool) {
28 | // return
29 | // IAuctionProtection(protectionAddress).depositToken(
30 | // _from,
31 | // _which,
32 | // _amount
33 | // );
34 | // }
35 |
36 | // function lockEther(address _which) external payable returns (bool) {
37 | // return
38 | // IAuctionProtection(protectionAddress).lockEther.value(msg.value)(
39 | // _which
40 | // );
41 | // }
42 |
43 | // function stackFund(uint256 _amount) external returns (bool) {
44 | // return IAuctionProtection(protectionAddress).stackFund(_amount);
45 | // }
46 |
47 | // //IBEP20 stuff
48 | // function approve(
49 | // IBEP20Token _token,
50 | // address _spender,
51 | // uint256 _value
52 | // ) external returns (bool) {
53 | // return _token.approve(_spender, _value);
54 | // }
55 |
56 | // function() external payable {}
57 | }
58 |
--------------------------------------------------------------------------------
/contracts/test/TestAuctionRegistery.sol:
--------------------------------------------------------------------------------
1 | //Added this becuse there may be a potential naming conflict
2 |
3 | pragma solidity ^0.5.9;
4 |
5 | import "../common/Ownable.sol";
6 | import "../common/SafeMath.sol";
7 |
8 |
9 | contract TestAuctionRegistery is Ownable, SafeMath {
10 | mapping(bytes32 => address payable) private contractAddress;
11 |
12 | mapping(bytes32 => uint256) public contractIndex;
13 |
14 | string[] public contracts;
15 |
16 | event ContractAddressUpdated(
17 | bytes32 indexed _contractName,
18 | address _contractAddressFrom,
19 | address _contractAddressTo
20 | );
21 |
22 | constructor(address _systemAddess, address _multisig)
23 | public
24 | Ownable(_systemAddess, _multisig)
25 | {}
26 |
27 | function contractsCount() external view returns (uint256) {
28 | return contracts.length;
29 | }
30 |
31 | function getAddressOf(bytes32 _contractName)
32 | external
33 | view
34 | returns (address payable)
35 | {
36 | return contractAddress[_contractName];
37 | }
38 |
39 | /**
40 | * @dev add new contarct address to the registery
41 | * @return bool
42 | */
43 | function registerContractAddress(
44 | bytes32 _contractName,
45 | address payable _contractAddress
46 | )
47 | external
48 | onlyOneOfOnwer()
49 | notZeroValue(_contractName.length)
50 | notZeroAddress(_contractAddress)
51 | returns (bool)
52 | {
53 | require(contractAddress[_contractName] == address(0), ERR_SAME_ADDRESS);
54 |
55 | contractAddress[_contractName] = _contractAddress;
56 |
57 | contractIndex[_contractName] = contracts.length;
58 |
59 | contracts.push(bytes32ToString(_contractName));
60 |
61 | emit ContractAddressUpdated(
62 | _contractName,
63 | address(0),
64 | _contractAddress
65 | );
66 |
67 | return true;
68 | }
69 |
70 | /**
71 | * @dev update contarct address to the registery
72 | * note that we dont need to update contractAddress index we just update contract addres only
73 | * @return bool
74 | */
75 | function updateContractAddress(
76 | bytes32 _contractName,
77 | address payable _contractAddress
78 | )
79 | external
80 | onlyAuthorized()
81 | notZeroValue(_contractName.length)
82 | notZeroAddress(_contractAddress)
83 | notZeroAddress(contractAddress[_contractName])
84 | returns (bool)
85 | {
86 | emit ContractAddressUpdated(
87 | _contractName,
88 | contractAddress[_contractName],
89 | _contractAddress
90 | );
91 | contractAddress[_contractName] = _contractAddress;
92 | return true;
93 | }
94 |
95 | /**
96 | * @dev remove contarct address to the registery
97 | * @return bool
98 | */
99 | function removeContractAddress(bytes32 _contractName)
100 | external
101 | onlyAuthorized()
102 | notZeroValue(_contractName.length)
103 | notZeroAddress(contractAddress[_contractName])
104 | returns (bool)
105 | {
106 | uint256 _contractIndex = contractIndex[_contractName];
107 |
108 | string memory lastContract = contracts[safeSub(contracts.length, 1)];
109 |
110 | bytes32 lastContractBytes = stringToBytes32(lastContract);
111 |
112 | contracts[_contractIndex] = lastContract;
113 |
114 | contractIndex[lastContractBytes] = _contractIndex;
115 |
116 | emit ContractAddressUpdated(
117 | _contractName,
118 | contractAddress[_contractName],
119 | address(0)
120 | );
121 |
122 | delete contractAddress[_contractName];
123 |
124 | delete contractIndex[_contractName];
125 |
126 | delete contracts[safeSub(contracts.length, 1)];
127 |
128 | return true;
129 | }
130 |
131 | /**
132 | * @dev utility, converts bytes32 to a string
133 | * note that the bytes32 argument is assumed to be UTF8 encoded ASCII string
134 | *
135 | * @return string representation of the given bytes32 argument
136 | */
137 | function bytes32ToString(bytes32 _bytes)
138 | public
139 | pure
140 | returns (string memory)
141 | {
142 | bytes memory byteArray = new bytes(32);
143 | for (uint256 i; i < 32; i++) {
144 | byteArray[i] = _bytes[i];
145 | }
146 |
147 | return string(byteArray);
148 | }
149 |
150 | /**
151 | * @dev utility, converts string to bytes32
152 | * note that the bytes32 argument is assumed to be UTF8 encoded ASCII string
153 | *
154 | * @return string representation of the given bytes32 argument
155 | */
156 | function stringToBytes32(string memory _string)
157 | public
158 | pure
159 | returns (bytes32)
160 | {
161 | bytes32 result;
162 | assembly {
163 | result := mload(add(_string, 32))
164 | }
165 | return result;
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/contracts/test/TestCurrencyPrices.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 |
4 | contract OwnableTemp {
5 | address public owner;
6 |
7 | event OwnershipTransferred(
8 | address indexed previousOwner,
9 | address indexed newOwner
10 | );
11 |
12 | /**
13 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender
14 | * account.
15 | */
16 | constructor(address _systemAddress) public {
17 | owner = _systemAddress;
18 | }
19 |
20 | /**
21 | * @dev Throws if called by any account other than the owner.
22 | */
23 | modifier onlyOwner() {
24 | require(msg.sender == owner);
25 | _;
26 | }
27 |
28 | /**
29 | * @dev Allows the current owner to transfer control of the contract to a newOwner.
30 | * @param newOwner The address to transfer ownership to.
31 | */
32 | function transferOwnership(address newOwner) public onlyOwner {
33 | require(newOwner != address(0));
34 | emit OwnershipTransferred(owner, newOwner);
35 | owner = newOwner;
36 | }
37 | }
38 |
39 |
40 | contract TestCurrencyPrices is OwnableTemp {
41 | mapping(address => uint256) public currencyPrices;
42 |
43 | constructor(address _systemAddress, address _multisigAddress)
44 | public
45 | OwnableTemp(_systemAddress)
46 | {}
47 |
48 | //Owner can Set Currency price
49 | //@ param _price Current price of currency.
50 | // currency Price set in 6 decimal
51 | function setCurrencyPriceUSD(
52 | address[] memory currency,
53 | uint256[] memory price
54 | ) public onlyOwner {
55 | for (uint8 i = 0; i < currency.length; i++) {
56 | require(price[i] != 0);
57 | currencyPrices[currency[i]] = price[i];
58 | }
59 | }
60 |
61 | function getCurrencyPrice(address _which) public view returns (uint256) {
62 | return currencyPrices[_which];
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/contracts/test/TestEscrow.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 | //the auctionTests.js itself
4 |
5 | import "../common/TokenTransfer.sol";
6 | import "../InterFaces/IBEP20Token.sol";
7 |
8 | contract TestEscrow is TokenTransfer{
9 |
10 | IBEP20Token mainToken ;
11 | constructor(IBEP20Token _mainToken) public {
12 | mainToken = _mainToken;
13 | }
14 |
15 | function depositFee(uint256 value) external returns(bool){
16 | ensureTransferFrom(mainToken,msg.sender,address(this),value);
17 | return true;
18 | }
19 |
20 |
21 | }
--------------------------------------------------------------------------------
/contracts/test/TestIBEP20Token.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.5.9;
2 |
3 |
4 | // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
5 |
6 | library SafeMath {
7 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
8 | require((z = x + y) >= x, "ds-math-add-overflow");
9 | }
10 |
11 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
12 | require((z = x - y) <= x, "ds-math-sub-underflow");
13 | }
14 |
15 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
16 | require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow");
17 | }
18 | }
19 |
20 |
21 | interface IBEP20 {
22 | event Approval(
23 | address indexed owner,
24 | address indexed spender,
25 | uint256 value
26 | );
27 | event Transfer(address indexed from, address indexed to, uint256 value);
28 |
29 | function name() external view returns (string memory);
30 |
31 | function symbol() external view returns (string memory);
32 |
33 | function decimals() external view returns (uint8);
34 |
35 | function totalSupply() external view returns (uint256);
36 |
37 | function balanceOf(address owner) external view returns (uint256);
38 |
39 | function allowance(address owner, address spender)
40 | external
41 | view
42 | returns (uint256);
43 |
44 | function approve(address spender, uint256 value) external returns (bool);
45 |
46 | function transfer(address to, uint256 value) external returns (bool);
47 |
48 | function transferFrom(
49 | address from,
50 | address to,
51 | uint256 value
52 | ) external returns (bool);
53 | }
54 |
55 |
56 | contract CustomIBEP20 is IBEP20 {
57 | using SafeMath for uint256;
58 |
59 | string public name;
60 | string public symbol;
61 | uint8 public constant decimals = 18;
62 | uint256 public totalSupply;
63 | mapping(address => uint256) public balanceOf;
64 | mapping(address => mapping(address => uint256)) public allowance;
65 |
66 | bytes32 public DOMAIN_SEPARATOR;
67 | // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
68 | bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
69 | mapping(address => uint256) public nonces;
70 |
71 | event Approval(
72 | address indexed owner,
73 | address indexed spender,
74 | uint256 value
75 | );
76 | event Transfer(address indexed from, address indexed to, uint256 value);
77 |
78 | constructor(
79 | string memory _name,
80 | string memory _symbol,
81 | uint256 _totalSupply,
82 | uint256 _chainId
83 | ) public {
84 | name = _name;
85 | symbol = _symbol;
86 | _mint(msg.sender, _totalSupply);
87 |
88 | uint256 chainId = _chainId;
89 |
90 | // assembly {
91 | // chainId := chainid
92 | // }
93 | DOMAIN_SEPARATOR = keccak256(
94 | abi.encode(
95 | keccak256(
96 | "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
97 | ),
98 | keccak256(bytes(name)),
99 | keccak256(bytes("1")),
100 | chainId,
101 | address(this)
102 | )
103 | );
104 | }
105 |
106 | function _mint(address to, uint256 value) internal {
107 | totalSupply = totalSupply.add(value);
108 | balanceOf[to] = balanceOf[to].add(value);
109 | emit Transfer(address(0), to, value);
110 | }
111 |
112 | function _burn(address from, uint256 value) internal {
113 | balanceOf[from] = balanceOf[from].sub(value);
114 | totalSupply = totalSupply.sub(value);
115 | emit Transfer(from, address(0), value);
116 | }
117 |
118 | function _approve(
119 | address owner,
120 | address spender,
121 | uint256 value
122 | ) private {
123 | allowance[owner][spender] = value;
124 | emit Approval(owner, spender, value);
125 | }
126 |
127 | function _transfer(
128 | address from,
129 | address to,
130 | uint256 value
131 | ) private {
132 | balanceOf[from] = balanceOf[from].sub(value);
133 | balanceOf[to] = balanceOf[to].add(value);
134 | emit Transfer(from, to, value);
135 | }
136 |
137 | function approve(address spender, uint256 value) external returns (bool) {
138 | _approve(msg.sender, spender, value);
139 | return true;
140 | }
141 |
142 | function transfer(address to, uint256 value) external returns (bool) {
143 | _transfer(msg.sender, to, value);
144 | return true;
145 | }
146 |
147 | function transferFrom(
148 | address from,
149 | address to,
150 | uint256 value
151 | ) external returns (bool) {
152 | if (allowance[from][msg.sender] != uint256(-1)) {
153 | allowance[from][msg.sender] = allowance[from][msg.sender].sub(
154 | value
155 | );
156 | }
157 | _transfer(from, to, value);
158 | return true;
159 | }
160 |
161 | function permit(
162 | address owner,
163 | address spender,
164 | uint256 value,
165 | uint256 deadline,
166 | uint8 v,
167 | bytes32 r,
168 | bytes32 s
169 | ) external {
170 | require(deadline >= block.timestamp, "UniswapV2: EXPIRED");
171 | bytes32 digest = keccak256(
172 | abi.encodePacked(
173 | "\x19\x01",
174 | DOMAIN_SEPARATOR,
175 | keccak256(
176 | abi.encode(
177 | PERMIT_TYPEHASH,
178 | owner,
179 | spender,
180 | value,
181 | nonces[owner]++,
182 | deadline
183 | )
184 | )
185 | )
186 | );
187 | address recoveredAddress = ecrecover(digest, v, r, s);
188 | require(
189 | recoveredAddress != address(0) && recoveredAddress == owner,
190 | "UniswapV2: INVALID_SIGNATURE"
191 | );
192 | _approve(owner, spender, value);
193 | }
194 | }
195 |
196 |
197 | contract TestIBEP20 is CustomIBEP20 {
198 | constructor() public CustomIBEP20("mDAI", "mDAI", 0, 0) {}
199 |
200 | function mint(address who, uint256 amount) public {
201 | _mint(who, amount);
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/latestContract.json:
--------------------------------------------------------------------------------
1 | {
2 | "AuctionRegistery": "0x79170906ea32Cf81d9Ae0A66050fD0c1D554863F",
3 | "CurrencyPrices": "0x90609EE9c8b71A14f36dE903899A8b904D58C2ca",
4 | "WhiteListRegistery": "0xFb01190D3a1e33BA389fC04E346B637bBF2FdBF1",
5 | "WhiteList": "0x444cD50db0A915E5f58C70d6542C2bCfA92D5348",
6 | "MainToken": "0xA64b3f0cdF3374E71279C6b8CF1596CB68870fE1",
7 | "TokenVaultRegistery": "0x9245648E58269b72bE42Ee1ef1d1FbB649643D1A",
8 | "TokenVault": "0x5012D9DEC79C4AfdABD5008814F37d50589f9fCe",
9 | "TagAlongRegistry": "0x0289973f6207b410DAe761E3c215764004c9Ee0E",
10 | "TagAlong": "0x6c600dde2D21862Ca6B1f62715463F6367f8a88B",
11 | "LiquadityRegistery": "0xc9DC31e7848421aBec560B6298B9514F1Aa636f2",
12 | "Liquadity": "0xed087c14b86B77A6D96DB9Dd60a54bb90a3182E0",
13 | "AuctionProxyRegistry": "0x03146986dd433C8Dd356505F82cd54Adc84b9B96",
14 | "Auction": "0x38bc71C38b5A378cd52C2Ca839afdD741B452d03",
15 | "ProtectionRegistry": "0xD35Abe7758E3822E53601bC7035d970E03ac5187",
16 | "AuctionProtection": "0x5C7d4b9D589f93Cb2004FdfD20AEA88CA5a877A4"
17 | }
--------------------------------------------------------------------------------
/migrations/10_auction_protection.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const { promisify } = require('util')
3 | const readFileAsync = promisify(fs.readFile);
4 | const writeFileAsync = promisify(fs.writeFile);
5 | var path = require('path');
6 |
7 | const AuctionRegistery = artifacts.require("AuctionRegistery");
8 | const WhiteList = artifacts.require("WhiteList");
9 |
10 |
11 | const ProtectionRegistry = artifacts.require("ProtectionRegistry");
12 | const AuctionProtection = artifacts.require("AuctionProtection");
13 |
14 | const {
15 | ownerWallet,
16 | whiteListSecondary,
17 | otherSecondary,
18 | governance,
19 | byPassCode,
20 | } = require("../constant");
21 |
22 | const protectionCode =
23 | "0x41554354494f4e5f50524f54454354494f4e0000000000000000000000000000";
24 |
25 | module.exports = async function (deployer) {
26 |
27 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
28 | currentdata = JSON.parse(currentdata);
29 |
30 | auctionRegistery = currentdata.AuctionRegistery;
31 | whiteList = currentdata.WhiteList;
32 |
33 | whiteListInstance = await WhiteList.at(whiteList);
34 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
35 |
36 | await deployer.deploy(
37 | ProtectionRegistry,
38 | otherSecondary,
39 | governance,{
40 | from: ownerWallet,
41 | }
42 | );
43 |
44 | protectionRegistryInstance = await ProtectionRegistry.deployed();
45 |
46 | await deployer.deploy(AuctionProtection, {
47 | from: ownerWallet,
48 | });
49 |
50 | txHash1 = await protectionRegistryInstance.addVersion(1, AuctionProtection.address, {
51 | from: ownerWallet,
52 | });
53 |
54 | txHash2 = await protectionRegistryInstance.createProxy(
55 | 1,
56 | ownerWallet,
57 | otherSecondary,
58 | governance,
59 | auctionRegistery, {
60 | from: ownerWallet,
61 | }
62 | );
63 |
64 | protectionProxyAddress = await protectionRegistryInstance.proxyAddress();
65 |
66 | protectionInstance = await AuctionProtection.at(protectionProxyAddress);
67 |
68 | txHash3 = await whiteListInstance.addNewWallet(protectionProxyAddress, byPassCode, 0, {
69 | from: whiteListSecondary,
70 | });
71 |
72 | txHash4 = await auctionRegistyInstance.registerContractAddress(
73 | protectionCode,
74 | protectionProxyAddress, {
75 | from: otherSecondary
76 | }
77 | );
78 | currentdata["ProtectionRegistry"] = ProtectionRegistry.address;
79 | currentdata["AuctionProtection"] = protectionProxyAddress;
80 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
81 |
82 |
83 |
84 | }
--------------------------------------------------------------------------------
/migrations/11_update_code.js:
--------------------------------------------------------------------------------
1 |
2 | const fs = require("fs");
3 | const { promisify } = require('util')
4 | const readFileAsync = promisify(fs.readFile);
5 | const writeFileAsync = promisify(fs.writeFile);
6 | var path = require('path');
7 |
8 | const AuctionRegistery = artifacts.require("AuctionRegistery");
9 |
10 | const WhiteListRegistery = artifacts.require("WhiteListRegistery");
11 | const WhiteList = artifacts.require("WhiteList");
12 |
13 | const MainToken = artifacts.require("MainToken");
14 | const CurrencyPrices = artifacts.require("CurrencyPrices");
15 |
16 | const TokenVaultRegistery = artifacts.require("TokenVaultRegistery");
17 | const TokenVault = artifacts.require("TokenVault");
18 |
19 | const TagAlongRegistry = artifacts.require("ContributionTriggerRegistry");
20 | const TagAlong = artifacts.require("ContributionTrigger");
21 |
22 | const LiquadityRegistery = artifacts.require("LiquidityRegistery");
23 | const Liquadity = artifacts.require("Liquidity");
24 |
25 | const AuctionProxyRegistry = artifacts.require("AuctionProxyRegistry");
26 | const Auction = artifacts.require("Auction");
27 |
28 | const ProtectionRegistry = artifacts.require("ProtectionRegistry");
29 | const AuctionProtection = artifacts.require("AuctionProtection");
30 |
31 | const { ownerWallet , otherSecondary } = require('../constant');
32 | module.exports = async function (deployer) {
33 |
34 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
35 | currentdata = JSON.parse(currentdata);
36 |
37 |
38 | whiteList = currentdata.WhiteList;
39 | mainToken = currentdata.MainToken;
40 | currencyPrice = currentdata.CurrencyPrices;
41 | tokenVault = currentdata.TokenVault;
42 | tagAlong = currentdata.TagAlong;
43 | liquadity = currentdata.Liquadity;
44 | auction = currentdata.Auction;
45 |
46 | currencyPricesInstnace = await CurrencyPrices.at(currencyPrice);
47 | whiteListInstance = await WhiteList.at(whiteList);
48 | maintTokenInstance = await MainToken.at(mainToken);
49 | tokenVaultInstance = await TokenVault.at(tokenVault);
50 | tagAlongInstance = await TagAlong.at(tagAlong);
51 | liquadityInstance = await Liquadity.at(liquadity);
52 | auctionInstance = await Auction.at(auction);
53 |
54 | await currencyPricesInstnace.setCurrencyPriceContract(mainToken,liquadity,{
55 | from: otherSecondary
56 | });
57 |
58 | await tokenVault.addSpender(liquadity,{
59 | from: ownerWallet
60 | });
61 |
62 | await whiteListInstance.updateAddresses({from: ownerWallet})
63 | await maintTokenInstance.updateAddresses({from: ownerWallet})
64 | await tokenVaultInstance.updateAddresses({from: ownerWallet})
65 | await tagAlongInstance.updateAddresses({from: ownerWallet})
66 | await liquadityInstance.updateAddresses({from: ownerWallet})
67 | await auctionInstance.updateAddresses({from: ownerWallet})
68 |
69 | // no need to update auciton protection as we deploy it last it has alredy latest address
70 |
71 |
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/migrations/12_transfer_onwerShip.js:
--------------------------------------------------------------------------------
1 |
2 | const fs = require("fs");
3 | const { promisify } = require('util')
4 | const readFileAsync = promisify(fs.readFile);
5 | const writeFileAsync = promisify(fs.writeFile);
6 | var path = require('path');
7 |
8 | const AuctionRegistery = artifacts.require("AuctionRegistery");
9 |
10 | const WhiteListRegistery = artifacts.require("WhiteListRegistery");
11 | const WhiteList = artifacts.require("WhiteList");
12 |
13 | const MainToken = artifacts.require("MainToken");
14 | const CurrencyPrices = artifacts.require("CurrencyPrices");
15 |
16 | const TokenVaultRegistery = artifacts.require("TokenVaultRegistery");
17 | const TokenVault = artifacts.require("TokenVault");
18 |
19 | const TagAlongRegistry = artifacts.require("ContributionTriggerRegistry");
20 | const TagAlong = artifacts.require("ContributionTrigger");
21 |
22 | const LiquadityRegistery = artifacts.require("LiquidityRegistery");
23 | const Liquadity = artifacts.require("Liquidity");
24 |
25 | const AuctionProxyRegistry = artifacts.require("AuctionProxyRegistry");
26 | const Auction = artifacts.require("Auction");
27 |
28 | const ProtectionRegistry = artifacts.require("ProtectionRegistry");
29 | const AuctionProtection = artifacts.require("AuctionProtection");
30 |
31 |
32 | const { ownerWallet , otherSecondary } = require('../constant');
33 | module.exports = async function (deployer) {
34 |
35 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
36 | currentdata = JSON.parse(currentdata);
37 |
38 | auctionRegistery = currentdata.AuctionRegistery;
39 |
40 | whiteList = currentdata.WhiteList;
41 | whiteListRegistery = currentdata.WhiteListRegistery;
42 | mainToken = currentdata.MainToken;
43 | currencyPrice = currentdata.CurrencyPrices;
44 |
45 | tokenVault = currentdata.TokenVault;
46 | tokenVaultRegistery = currentdata.TokenVaultRegistery;
47 |
48 | tagAlong = currentdata.TagAlong;
49 | tagAlongRegistry = currentdata.TagAlongRegistry;
50 |
51 | liquadity = currentdata.Liquadity;
52 | liquadityRegistery = currentdata.LiquadityRegistery;
53 |
54 | auction = currentdata.Auction;
55 | auctionProxyRegistry = currentdata.AuctionProxyRegistry;
56 |
57 | auctionProtection = currentdata.AuctionProtection;
58 | protectionRegistry = currentdata.ProtectionRegistry;
59 |
60 |
61 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
62 | currencyPricesInstnace = await CurrencyPrices.at(currencyPrice);
63 | maintTokenInstance = await MainToken.at(mainToken);
64 |
65 | whiteListInstance = await WhiteList.at(whiteList);
66 | whiteListRegisteryInstance = await WhiteListRegistery.at(whiteListRegistery);
67 |
68 | tokenVaultInstance = await TokenVault.at(tokenVault);
69 | tokenVaultRegisteryInstance = await TokenVaultRegistery.at(tokenVaultRegistery);
70 |
71 | tagAlongInstance = await TagAlong.at(tagAlong);
72 | tagAlongRegistryInstance = await TagAlongRegistry.at(tagAlongRegistry);
73 |
74 | liquadityInstance = await Liquadity.at(liquadity);
75 | liquadityRegisteryInstance = await LiquadityRegistery.at(liquadityRegistery);
76 |
77 | auctionInstance = await Auction.at(auction);
78 | auctionProxyRegistryInstance = await AuctionProxyRegistry.at(auctionProxyRegistry);
79 |
80 | protectionInstance = await AuctionProtection.at(auctionProtection);
81 | protectionInstanceInstance = await ProtectionRegistry.at(auctionProxyRegistry);
82 |
83 | await auctionRegistyInstance.changePrimaryOwner({from: ownerWallet});
84 | await whiteListInstance.changePrimaryOwner({from: ownerWallet});
85 | await maintTokenInstance.changePrimaryOwner({from: ownerWallet});
86 | await tokenVaultInstance.changePrimaryOwner({from: ownerWallet});
87 | await tagAlongInstance.changePrimaryOwner({from: ownerWallet});
88 | await liquadityInstance.changePrimaryOwner({from: ownerWallet});
89 | await auctionInstance.changePrimaryOwner({from: ownerWallet});
90 |
91 | await whiteListRegisteryInstance.changePrimaryOwner({from: ownerWallet});
92 | await tokenVaultRegisteryInstance.changePrimaryOwner({from: ownerWallet});
93 | await liquadityRegisteryInstance.changePrimaryOwner({from: ownerWallet});
94 | await auctionProxyRegistryInstance.changePrimaryOwner({from: ownerWallet});
95 | await protectionInstanceInstance.changePrimaryOwner({from: ownerWallet});
96 |
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/migrations/1_initial_migration.js:
--------------------------------------------------------------------------------
1 | const Migrations = artifacts.require("Migrations");
2 |
3 | const WhiteList = artifacts.require("WhiteList");
4 | const Auction = artifacts.require("Auction");
5 |
6 | const { ownerWallet , otherSecondary , governance } = require('../constant');
7 |
8 | module.exports = async function(deployer) {
9 | // deployer.deploy(Migrations);
10 | };
11 |
--------------------------------------------------------------------------------
/migrations/2_Auction_Registery.js:
--------------------------------------------------------------------------------
1 |
2 | const fs = require("fs");
3 | const { promisify } = require('util')
4 | const readFileAsync = promisify(fs.readFile);
5 | const writeFileAsync = promisify(fs.writeFile);
6 | var path = require('path');
7 |
8 | const AuctionRegistery = artifacts.require("AuctionRegistery");
9 |
10 | const { ownerWallet , otherSecondary , governance } = require('../constant');
11 |
12 |
13 | module.exports = async function (deployer) {
14 |
15 | await deployer.deploy(
16 | AuctionRegistery,
17 | otherSecondary,
18 | governance, {
19 | from: ownerWallet
20 | }
21 | );
22 |
23 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
24 | currentdata = JSON.parse(currentdata);
25 | currentdata["AuctionRegistery"] = AuctionRegistery.address;
26 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
27 |
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/migrations/3_Currency_price.js:
--------------------------------------------------------------------------------
1 |
2 | const fs = require("fs");
3 | const { promisify } = require('util')
4 | const readFileAsync = promisify(fs.readFile);
5 | const writeFileAsync = promisify(fs.writeFile);
6 | var path = require('path');
7 | const CurrencyPrices = artifacts.require("CurrencyPrices");
8 | const CurrencyPriceTicker = artifacts.require("CurrencyPriceTicker");
9 | const AuctionRegistery = artifacts.require("AuctionRegistery");
10 |
11 | const { ownerWallet , otherSecondary , governance , baseTokenAddress } = require('../constant');
12 |
13 |
14 |
15 | const bandProtocol = "0xDA7a001b254CD22e46d3eAB04d937489c93174C3";
16 |
17 | const currencyCode =
18 | "0x43555252454e4359000000000000000000000000000000000000000000000000";
19 |
20 |
21 | module.exports = async function (deployer) {
22 |
23 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
24 | currentdata = JSON.parse(currentdata);
25 |
26 | auctionRegistery = currentdata.AuctionRegistery;
27 | AuctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
28 |
29 | await deployer.deploy(
30 | CurrencyPrices,
31 | otherSecondary,
32 | governance, {
33 | from: ownerWallet
34 | }
35 | );
36 |
37 | CurrencyPricesInstnace = await CurrencyPrices.deployed();
38 |
39 | await deployer.deploy(
40 | CurrencyPriceTicker,
41 | bandProtocol,
42 | "BNB",
43 | "USD",
44 | {
45 | from: ownerWallet
46 | }
47 | );
48 |
49 | await CurrencyPricesInstnace.setCurrencyPriceContract(baseTokenAddress,CurrencyPriceTicker.address,{
50 | from: otherSecondary
51 | });
52 |
53 | await CurrencyPricesInstnace.setCurrencyPriceContract("0x0000000000000000000000000000000000000000",CurrencyPriceTicker.address,{
54 | from: otherSecondary
55 | });
56 |
57 | // await AuctionRegistyInstance.registerContractAddress(
58 | // currencyCode,
59 | // CurrencyPrices.address, {
60 | // from: otherSecondary
61 | // }
62 | // );
63 |
64 | // currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
65 | // currentdata = JSON.parse(currentdata);
66 | // currentdata["CurrencyPrices"] = CurrencyPrices.address;//CurrencyPrices.address;
67 | // await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
68 |
69 |
70 |
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/migrations/4_Whitelist.js:
--------------------------------------------------------------------------------
1 |
2 | const fs = require("fs");
3 | const { promisify } = require('util')
4 | const readFileAsync = promisify(fs.readFile);
5 | const writeFileAsync = promisify(fs.writeFile);
6 | var path = require('path');
7 | const WhiteListRegistery = artifacts.require("WhiteListRegistery");
8 | const WhiteList = artifacts.require("WhiteList");
9 | const AuctionRegistery = artifacts.require("AuctionRegistery");
10 | const {
11 | ownerWallet,
12 | whiteListSecondary,
13 | otherSecondary,
14 | governance,
15 | mainTokenHoldBack,
16 | etnTokenHoldBack,
17 | stockTokenHoldBack,
18 | mainMaturityDays,
19 | etnMaturityDays,
20 | stockMaturityDays,
21 | byPassCode,
22 | escrow,
23 | gateWay,
24 | realEstate
25 | } = require("../constant");
26 |
27 |
28 | const WhiteListCode =
29 | "0x57484954455f4c49535400000000000000000000000000000000000000000000";
30 |
31 | const escrowCode =
32 | "0x455343524f570000000000000000000000000000000000000000000000000000";
33 |
34 | const realEstateCode = "0x434f4d50414e595f46554e445f57414c4c455400000000000000000000000000";
35 |
36 | module.exports = async function (deployer) {
37 |
38 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
39 | currentdata = JSON.parse(currentdata);
40 | auctionRegistery = currentdata.AuctionRegistery;
41 |
42 | await deployer.deploy(WhiteListRegistery, whiteListSecondary, governance, {
43 | from: ownerWallet,
44 | });
45 |
46 | whiteListRegisteryInstance = await WhiteListRegistery.deployed();
47 |
48 | await deployer.deploy(WhiteList, {
49 | from: ownerWallet,
50 | });
51 |
52 | txHash1 = await whiteListRegisteryInstance.addVersion(1, WhiteList.address, {
53 | from: ownerWallet,
54 | });
55 |
56 | txHash2 = await whiteListRegisteryInstance.createProxy(
57 | 1,
58 | ownerWallet,
59 | whiteListSecondary,
60 | governance,
61 | mainTokenHoldBack,
62 | etnTokenHoldBack,
63 | stockTokenHoldBack,
64 | mainMaturityDays,
65 | etnMaturityDays,
66 | stockMaturityDays,
67 | auctionRegistery,
68 | {
69 | from: ownerWallet,
70 | }
71 | );
72 |
73 | whiteListProxyAdress = await whiteListRegisteryInstance.proxyAddress();
74 | whiteListInstance = await WhiteList.at(whiteListProxyAdress);
75 |
76 | AuctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
77 |
78 | await whiteListInstance.addNewWallet(ownerWallet,byPassCode, 10, {
79 | from: whiteListSecondary,
80 | });
81 |
82 | await whiteListInstance.addNewWallet(escrow,byPassCode, 10, {
83 | from: whiteListSecondary,
84 | });
85 |
86 | await whiteListInstance.addNewWallet(realEstate,byPassCode, 10, {
87 | from: whiteListSecondary,
88 | });
89 |
90 | await whiteListInstance.addNewWallet(gateWay,byPassCode, 10, {
91 | from: whiteListSecondary,
92 | });
93 |
94 | await AuctionRegistyInstance.registerContractAddress(
95 | WhiteListCode,
96 | whiteListProxyAdress, {
97 | from: otherSecondary
98 | }
99 | );
100 |
101 | await AuctionRegistyInstance.registerContractAddress(
102 | escrowCode,
103 | escrow, {
104 | from: otherSecondary
105 | }
106 | );
107 |
108 | await AuctionRegistyInstance.registerContractAddress(
109 | realEstateCode,
110 | realEstate, {
111 | from: otherSecondary
112 | }
113 | );
114 |
115 | currentdata["WhiteListRegistery"] = WhiteListRegistery.address;
116 | currentdata["WhiteList"] = whiteListProxyAdress;
117 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
118 |
119 | };
120 |
--------------------------------------------------------------------------------
/migrations/5_MainToken.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const { promisify } = require('util')
3 | const readFileAsync = promisify(fs.readFile);
4 | const writeFileAsync = promisify(fs.writeFile);
5 | var path = require('path');
6 | const AuctionRegistery = artifacts.require("AuctionRegistery");
7 |
8 | const WhiteList = artifacts.require("WhiteList");
9 |
10 | const MainToken = artifacts.require("MainToken");
11 |
12 | const {
13 | ownerWallet,
14 | otherSecondary,
15 | governance,
16 | mainTokenName,
17 | mainTokenSymbol,
18 | preMintAddress,
19 | preMintAmount,
20 | mainTokenOwner
21 | } = require("../constant");
22 |
23 |
24 |
25 | const mainTokenCode =
26 | "0x4d41494e5f544f4b454e00000000000000000000000000000000000000000000";
27 |
28 | module.exports = async function (deployer) {
29 |
30 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
31 | currentdata = JSON.parse(currentdata);
32 |
33 | auctionRegistery = currentdata.AuctionRegistery;
34 | whiteList = currentdata.WhiteList;
35 |
36 | whiteListInstance = await WhiteList.at(whiteList);
37 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
38 |
39 | await deployer.deploy(
40 | MainToken,
41 | mainTokenName,
42 | mainTokenSymbol,
43 | mainTokenOwner,
44 | governance,
45 | auctionRegistery,
46 | preMintAddress,
47 | preMintAmount, {
48 | from: ownerWallet,
49 | }
50 | );
51 |
52 | txHash1 = await auctionRegistyInstance.registerContractAddress(
53 | mainTokenCode,
54 | MainToken.address, {
55 | from: otherSecondary
56 | }
57 | );
58 |
59 | currentdata["MainToken"] = MainToken.address;
60 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
61 |
62 |
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/migrations/6_Token_Vault.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const { promisify } = require('util')
3 | const readFileAsync = promisify(fs.readFile);
4 | const writeFileAsync = promisify(fs.writeFile);
5 | var path = require('path');
6 |
7 | const AuctionRegistery = artifacts.require("AuctionRegistery");
8 | const WhiteList = artifacts.require("WhiteList");
9 |
10 | const TokenVaultRegistery = artifacts.require("TokenVaultRegistery");
11 | const TokenVault = artifacts.require("TokenVault");
12 |
13 | const {
14 | ownerWallet,
15 | whiteListSecondary,
16 | otherSecondary,
17 | governance,
18 | byPassCode,
19 | } = require("../constant");
20 |
21 | const vaultCode =
22 | "0x5641554c54000000000000000000000000000000000000000000000000000000";
23 |
24 | module.exports = async function (deployer) {
25 |
26 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
27 | currentdata = JSON.parse(currentdata);
28 |
29 | auctionRegistery = currentdata.AuctionRegistery;
30 | whiteList = currentdata.WhiteList;
31 |
32 | whiteListInstance = await WhiteList.at(whiteList);
33 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
34 |
35 | await deployer.deploy(
36 | TokenVaultRegistery,
37 | otherSecondary,
38 | governance, {
39 | from: ownerWallet,
40 | }
41 | );
42 |
43 | tokenVaultRegisteryInstance = await TokenVaultRegistery.deployed();
44 | await deployer.deploy(TokenVault, {
45 | from: ownerWallet,
46 | });
47 |
48 | txHash1 = await tokenVaultRegisteryInstance.addVersion(1, TokenVault.address, {
49 | from: ownerWallet,
50 | });
51 |
52 | txHash2 = await tokenVaultRegisteryInstance.createProxy(
53 | 1,
54 | ownerWallet,
55 | otherSecondary,
56 | governance,
57 | auctionRegistery, {
58 | from: ownerWallet,
59 | }
60 | );
61 |
62 | tokenVaultProxyAdress = await tokenVaultRegisteryInstance.proxyAddress();
63 | tokenVaultInstance = await TokenVault.at(tokenVaultProxyAdress);
64 |
65 | txHash3 = await whiteListInstance.addNewWallet(tokenVaultProxyAdress, byPassCode, 0, {
66 | from: whiteListSecondary,
67 | });
68 |
69 | txHash4 = await auctionRegistyInstance.registerContractAddress(
70 | vaultCode,
71 | tokenVaultProxyAdress, {
72 | from: otherSecondary
73 | }
74 | );
75 |
76 |
77 | currentdata["TokenVaultRegistery"] = TokenVaultRegistery.address;
78 | currentdata["TokenVault"] = tokenVaultProxyAdress;
79 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
80 |
81 | }
82 |
83 |
--------------------------------------------------------------------------------
/migrations/7_Tag_Along.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const { promisify } = require('util')
3 | const readFileAsync = promisify(fs.readFile);
4 | const writeFileAsync = promisify(fs.writeFile);
5 | var path = require('path');
6 |
7 | const AuctionRegistery = artifacts.require("AuctionRegistery");
8 | const WhiteList = artifacts.require("WhiteList");
9 |
10 |
11 | const TagAlongRegistry = artifacts.require("ContributionTriggerRegistry");
12 | const TagAlong = artifacts.require("ContributionTrigger");
13 |
14 | const {
15 | ownerWallet,
16 | whiteListSecondary,
17 | otherSecondary,
18 | governance,
19 | byPassCode,
20 | } = require("../constant");
21 |
22 | const tagAlongCode =
23 | "0x434f4e545249425554494f4e5f54524947474552000000000000000000000000";
24 |
25 | module.exports = async function (deployer) {
26 |
27 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
28 | currentdata = JSON.parse(currentdata);
29 |
30 | auctionRegistery = currentdata.AuctionRegistery;
31 | whiteList = currentdata.WhiteList;
32 |
33 | whiteListInstance = await WhiteList.at(whiteList);
34 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
35 |
36 | await deployer.deploy(
37 | TagAlongRegistry,
38 | otherSecondary,
39 | governance,{
40 | from: ownerWallet,
41 | }
42 | );
43 |
44 | tagAlongRegistryInstance = await TagAlongRegistry.deployed();
45 |
46 | await deployer.deploy(TagAlong, {
47 | from: ownerWallet,
48 | });
49 |
50 | txHash1 = await tagAlongRegistryInstance.addVersion(1, TagAlong.address, {
51 | from: ownerWallet,
52 | });
53 |
54 | txHash2 = await tagAlongRegistryInstance.createProxy(
55 | 1,
56 | ownerWallet,
57 | otherSecondary,
58 | governance,
59 | auctionRegistery, {
60 | from: ownerWallet,
61 | }
62 | );
63 |
64 | tagAlongProxyAddress = await tagAlongRegistryInstance.proxyAddress();
65 |
66 | tagAlongInstance = await TagAlong.at(tagAlongProxyAddress);
67 |
68 | txHash3 = await whiteListInstance.addNewWallet(tagAlongProxyAddress, byPassCode,10, {
69 | from: whiteListSecondary,
70 | });
71 |
72 | txHash4 = await auctionRegistyInstance.registerContractAddress(
73 | tagAlongCode,
74 | tagAlongProxyAddress, {
75 | from: otherSecondary
76 | }
77 | );
78 |
79 | currentdata["TagAlongRegistry"] = TagAlongRegistry.address;
80 | currentdata["TagAlong"] = tagAlongProxyAddress;
81 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata,undefined,2));
82 |
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/migrations/8_Auction_Liquadity.js:
--------------------------------------------------------------------------------
1 | const TruffleContract = require("@truffle/contract");
2 | const fs = require("fs");
3 | const {
4 | promisify
5 | } = require('util')
6 | const readFileAsync = promisify(fs.readFile);
7 | const writeFileAsync = promisify(fs.writeFile);
8 | var path = require('path');
9 |
10 | const AuctionRegistery = artifacts.require("AuctionRegistery");
11 | const WhiteList = artifacts.require("WhiteList");
12 |
13 | const MainToken = artifacts.require("MainToken");
14 |
15 | const LiquadityRegistery = artifacts.require("LiquidityRegistery");
16 | const Liquadity = artifacts.require("Liquidity");
17 |
18 | const {
19 | ownerWallet,
20 | whiteListSecondary,
21 | baseTokenAddress,
22 | otherSecondary,
23 | governance,
24 | byPassCode,
25 | poolAddress,
26 | baseLinePrice,
27 | factoryAddress
28 | } = require("../constant");
29 |
30 | const liquadityCode = "0x4c49515549444954590000000000000000000000000000000000000000000000";
31 |
32 | module.exports = async function (deployer) {
33 |
34 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
35 | currentdata = JSON.parse(currentdata);
36 |
37 | auctionRegistery = currentdata.AuctionRegistery;
38 | whiteList = currentdata.WhiteList;
39 | mainToken = currentdata.MainToken;
40 |
41 | whiteListInstance = await WhiteList.at(whiteList);
42 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
43 |
44 |
45 | await deployer.deploy(
46 | LiquadityRegistery,
47 | otherSecondary,
48 | governance, {
49 | from: ownerWallet,
50 | }
51 | );
52 |
53 |
54 | LiquadityRegisteryInstance = await LiquadityRegistery.deployed();
55 |
56 | await deployer.deploy(Liquadity, {
57 | from: ownerWallet,
58 | });
59 |
60 | txHash8 = await LiquadityRegisteryInstance.addVersion(1, Liquadity.address, {
61 | from: ownerWallet,
62 | });
63 |
64 | txHash9 = await LiquadityRegisteryInstance.createProxy(
65 | 1,
66 | poolAddress,
67 | factoryAddress,
68 | baseTokenAddress,
69 | mainToken,
70 | ownerWallet,
71 | otherSecondary,
72 | governance,
73 | auctionRegistery,
74 | baseLinePrice, {
75 | from: ownerWallet,
76 | }
77 | );
78 |
79 | LiquadityProxyAddress = await LiquadityRegisteryInstance.proxyAddress();
80 |
81 | LiquadityInstance = await Liquadity.at(LiquadityProxyAddress);
82 |
83 | await whiteListInstance.addNewWallet(LiquadityProxyAddress, byPassCode, 0, {
84 | from: whiteListSecondary,
85 | });
86 |
87 | txHash11 = await auctionRegistyInstance.registerContractAddress(
88 | liquadityCode,
89 | LiquadityProxyAddress, {
90 | from: otherSecondary
91 | }
92 | );
93 |
94 | await whiteListInstance.changeFlags(ownerWallet,0,{
95 | from: whiteListSecondary,
96 | });
97 |
98 |
99 | currentdata["LiquadityRegistery"] = LiquadityRegistery.address;
100 | currentdata["Liquadity"] = LiquadityProxyAddress;
101 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata, undefined, 2));
102 |
103 |
104 |
105 | }
--------------------------------------------------------------------------------
/migrations/9_Auction.js:
--------------------------------------------------------------------------------
1 | const TruffleContract = require("@truffle/contract");
2 | const fs = require("fs");
3 | const {
4 | promisify
5 | } = require('util')
6 | const readFileAsync = promisify(fs.readFile);
7 | const writeFileAsync = promisify(fs.writeFile);
8 | var path = require('path');
9 |
10 | const AuctionRegistery = artifacts.require("AuctionRegistery");
11 | const WhiteList = artifacts.require("WhiteList");
12 |
13 | const MainToken = artifacts.require("MainToken");
14 |
15 | const AuctionProxyRegistry = artifacts.require("AuctionProxyRegistry");
16 | const Auction = artifacts.require("Auction");
17 |
18 | const {
19 | ownerWallet,
20 | auctionSecondary,
21 | whiteListSecondary,
22 | otherSecondary,
23 | governance,
24 | byPassCode,
25 | starTime,
26 | minAuctionTime,
27 | mainTokenCheckDay,
28 | intervalTime
29 |
30 | } = require("../constant");
31 |
32 | const auctionCode = "0x41554354494f4e00000000000000000000000000000000000000000000000000";
33 |
34 | module.exports = async function (deployer) {
35 |
36 | currentdata = await readFileAsync(path.resolve(__dirname, '../latestContract.json'));
37 | currentdata = JSON.parse(currentdata);
38 |
39 | auctionRegistery = currentdata.AuctionRegistery;
40 | whiteList = currentdata.WhiteList;
41 | mainToken = currentdata.MainToken;
42 |
43 | whiteListInstance = await WhiteList.at(whiteList);
44 | auctionRegistyInstance = await AuctionRegistery.at(auctionRegistery);
45 |
46 | await deployer.deploy(
47 | AuctionProxyRegistry,
48 | auctionSecondary,
49 | governance, {
50 | from: ownerWallet,
51 | }
52 | );
53 |
54 | AuctionProxyRegistryInstance = await AuctionProxyRegistry.deployed();
55 |
56 | await deployer.deploy(Auction, {
57 | from: ownerWallet,
58 | });
59 |
60 | await AuctionProxyRegistryInstance.addVersion(1, Auction.address, {
61 | from: ownerWallet,
62 | });
63 |
64 | await AuctionProxyRegistryInstance.createProxy(
65 | 1,
66 | starTime,
67 | minAuctionTime,
68 | intervalTime,
69 | mainTokenCheckDay,
70 | ownerWallet,
71 | auctionSecondary,
72 | governance,
73 | auctionRegistery,
74 | {
75 | from: ownerWallet,
76 | }
77 | );
78 | auctionProxyAddress = await AuctionProxyRegistryInstance.proxyAddress();
79 |
80 | auctionInstance = await Auction.at(auctionProxyAddress);
81 |
82 | await whiteListInstance.addNewWallet(auctionProxyAddress, byPassCode, 0, {
83 | from: whiteListSecondary,
84 | });
85 |
86 | await auctionRegistyInstance.registerContractAddress(
87 | auctionCode,
88 | auctionProxyAddress, {
89 | from: otherSecondary
90 | }
91 | );
92 |
93 | currentdata["AuctionProxyRegistry"] = AuctionProxyRegistry.address;
94 | currentdata["Auction"] = auctionProxyAddress;
95 | await writeFileAsync(path.resolve(__dirname, '../latestContract.json'), JSON.stringify(currentdata, undefined, 2));
96 |
97 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jointer-token",
3 | "version": "1.0.0",
4 | "description": "A NEW WAY TO INVEST IN COMMERCIAL REAL ESTATE",
5 | "main": "truffle-config.js",
6 | "directories": {
7 | "test": "test"
8 | },
9 | "dependencies": {
10 | "lodash": "^4.17.19"
11 | },
12 | "devDependencies": {
13 | "@openzeppelin/test-helpers": "^0.5.6",
14 | "@truffle/hdwallet-provider": "^1.0.39",
15 | "buidler-gas-reporter": "^0.1.3"
16 | },
17 | "scripts": {
18 | "test": "truffle test"
19 | },
20 | "repository": {
21 | "type": "git",
22 | "url": "git+https://github.com/jointerinc/jointer-token.git"
23 | },
24 | "author": "minddeft",
25 | "license": "ISC",
26 | "bugs": {
27 | "url": "https://github.com/jointerinc/jointer-token/issues"
28 | },
29 | "homepage": "https://github.com/jointerinc/jointer-token#readme"
30 | }
31 |
--------------------------------------------------------------------------------
/test/AuctionTagAlongTests.js:
--------------------------------------------------------------------------------
1 | const {
2 | constants,
3 | expectEvent,
4 | expectRevert,
5 | BN,
6 | } = require("@openzeppelin/test-helpers");
7 | const { ZERO_ADDRESS } = constants;
8 |
9 | const { expect } = require("chai");
10 |
11 | const TagAlong = artifacts.require("AuctionTagAlong");
12 | const TagAlongRegistry = artifacts.require("TagAlongRegistry");
13 | const AuctionRegisty = artifacts.require("TestAuctionRegistery");
14 | const ERC20 = artifacts.require("TestERC20");
15 |
16 | contract("~auction tag Along works", function (accounts) {
17 | const [
18 | other1,
19 | primaryOwner,
20 | systemAddress,
21 | multiSigPlaceHolder,
22 | liquidityPlaceHolder,
23 | contributer1,
24 | ] = accounts;
25 | const contributeAmount = new BN(1000);
26 | beforeEach(async function () {
27 | //contract that has address of all the contracts
28 | this.auctionRegistry = await AuctionRegisty.new(
29 | systemAddress,
30 | multiSigPlaceHolder,
31 | { from: primaryOwner }
32 | );
33 | await this.auctionRegistry.registerContractAddress(
34 | web3.utils.fromAscii("LIQUADITY"),
35 | liquidityPlaceHolder,
36 | { from: primaryOwner }
37 | );
38 |
39 | var tagAlongRegistry = await TagAlongRegistry.new(
40 | systemAddress,
41 | multiSigPlaceHolder,
42 | { from: primaryOwner }
43 | );
44 | let tempTagAlong = await TagAlong.new({ from: primaryOwner });
45 | await tagAlongRegistry.addVersion(1, tempTagAlong.address, {
46 | from: primaryOwner,
47 | });
48 | await tagAlongRegistry.createProxy(
49 | 1,
50 | primaryOwner,
51 | systemAddress,
52 | multiSigPlaceHolder,
53 | this.auctionRegistry.address,
54 | { from: primaryOwner }
55 | );
56 | proxyAddress = await tagAlongRegistry.proxyAddress();
57 | this.tagAlong = await TagAlong.at(proxyAddress);
58 |
59 | this.erc20 = await ERC20.new({ from: other1 });
60 | this.erc20.mint(contributer1, contributeAmount, { from: contributer1 });
61 | });
62 | it("should initialize correctly", async function () {
63 | expect(await this.tagAlong.systemAddress()).to.equal(systemAddress);
64 | expect(await this.tagAlong.primaryOwner()).to.equal(primaryOwner);
65 | expect(await this.tagAlong.authorityAddress()).to.equal(
66 | multiSigPlaceHolder
67 | );
68 | expect(await this.tagAlong.contractsRegistry()).to.equal(
69 | this.auctionRegistry.address
70 | );
71 | expect(await this.tagAlong.liquadityAddress()).to.equal(
72 | liquidityPlaceHolder
73 | );
74 | // expect(await this.tagAlong.liquadityRatio()).to.be.bignumber.equal("100");
75 | // expect(await this.tagAlong.contributionRatio()).to.be.bignumber.equal(
76 | // "100"
77 | // );
78 | });
79 | describe("All the functions", async function () {
80 | //maybe first test the depositToken and then other functions
81 | it("should deposite token correctly", async function () {
82 | await this.erc20.approve(this.tagAlong.address, contributeAmount, {
83 | from: contributer1,
84 | });
85 | let reciept = await this.tagAlong.depositeToken(
86 | this.erc20.address,
87 | contributer1,
88 | contributeAmount,
89 | {
90 | from: contributer1,
91 | }
92 | );
93 | expectEvent(reciept, "FundDeposited", {
94 | _token: this.erc20.address,
95 | _from: contributer1,
96 | _amount: contributeAmount,
97 | });
98 | });
99 | it("contribute Toward Liquadity should work", async function () {
100 | //this function is incomplete
101 | let initialBalance = new BN(1000000);
102 | let receipt = await this.tagAlong.sendTransaction({
103 | from: other1,
104 | value: initialBalance,
105 | });
106 | let amount = new BN(1000);
107 | await expectRevert(
108 | this.tagAlong.contributeTowardLiquadity(amount, { from: other1 }),
109 | "ERR_ONLY_LIQUADITY_ALLWOED"
110 | );
111 |
112 | await this.tagAlong.contributeTowardLiquadity(amount, {
113 | from: liquidityPlaceHolder,
114 | });
115 |
116 | expect(
117 | await web3.eth.getBalance(this.tagAlong.address)
118 | ).to.be.bignumber.equal(initialBalance.sub(amount));
119 | });
120 | it("should tranfer token liquidity", async function () {
121 | await this.erc20.approve(this.tagAlong.address, contributeAmount, {
122 | from: contributer1,
123 | });
124 | await this.tagAlong.depositeToken(
125 | this.erc20.address,
126 | contributer1,
127 | contributeAmount,
128 | {
129 | from: contributer1,
130 | }
131 | );
132 | expectRevert(
133 | this.tagAlong.transferTokenLiquadity(
134 | this.erc20.address,
135 | other1,
136 | contributeAmount,
137 | { from: other1 }
138 | ),
139 | "ERR_ONLY_LIQUADITY_ALLWOED"
140 | );
141 | let reciept = await this.tagAlong.transferTokenLiquadity(
142 | this.erc20.address,
143 | other1,
144 | contributeAmount,
145 | { from: liquidityPlaceHolder }
146 | );
147 | });
148 | });
149 | });
150 |
--------------------------------------------------------------------------------
/test/OwnableTest.js:
--------------------------------------------------------------------------------
1 | const {
2 | constants,
3 | expectEvent,
4 | expectRevert,
5 | } = require("@openzeppelin/test-helpers");
6 | const {ZERO_ADDRESS} = constants;
7 |
8 | const {expect} = require("chai");
9 |
10 | const Ownable = artifacts.require("Ownable");
11 |
12 | contract("~Ownable works", function (accounts) {
13 | const [
14 | primaryOwner,
15 | authorityAddress,
16 | systemAddress,
17 | newAuthorityAddress,
18 | other,
19 | other1,
20 | ] = accounts;
21 |
22 | beforeEach(async function () {
23 | this.ownable = await Ownable.new(systemAddress, authorityAddress, {
24 | from: primaryOwner,
25 | });
26 | });
27 |
28 | it("should set the values correctly", async function () {
29 | expect(await this.ownable.primaryOwner()).to.equal(primaryOwner);
30 | expect(await this.ownable.authorityAddress()).to.equal(authorityAddress);
31 | expect(await this.ownable.systemAddress()).to.equal(systemAddress);
32 | });
33 |
34 | it("changes PrimaryOwner only by authority", async function () {
35 | const receipt = await this.ownable.changePrimaryOwner(other, {
36 | from: authorityAddress,
37 | });
38 | expectEvent(receipt, "OwnershipTransferred", {
39 | ownerType: "PRIMARY_OWNER",
40 | previousOwner: primaryOwner,
41 | newOwner: other,
42 | });
43 |
44 | await expectRevert(
45 | this.ownable.changePrimaryOwner(other, {
46 | from: other1,
47 | }),
48 | "ERR_AUTHORIZED_ADDRESS_ONLY"
49 | );
50 | expect(await this.ownable.primaryOwner()).to.equal(other);
51 | });
52 |
53 | it("changes system only by authority", async function () {
54 | const receipt = await this.ownable.changeSystemAddress(other, {
55 | from: authorityAddress,
56 | });
57 | expectEvent(receipt, "OwnershipTransferred", {
58 | ownerType: "SYSTEM_ADDRESS",
59 | previousOwner: systemAddress,
60 | newOwner: other,
61 | });
62 |
63 | await expectRevert(
64 | this.ownable.changeSystemAddress(other, {
65 | from: other1,
66 | }),
67 | "ERR_AUTHORIZED_ADDRESS_ONLY"
68 | );
69 | expect(await this.ownable.systemAddress()).to.equal(other);
70 | });
71 |
72 | it("changes Authority address only by authority", async function () {
73 | await this.ownable.changeAuthorityAddress(other, {
74 | from: authorityAddress,
75 | });
76 | expect(await this.ownable.newAuthorityAddress()).to.equal(other);
77 | await expectRevert(
78 | this.ownable.changeAuthorityAddress(other, {
79 | from: other1,
80 | }),
81 | "ERR_AUTHORIZED_ADDRESS_ONLY"
82 | );
83 | });
84 | it("new authority accepts correctly", async function () {
85 | await this.ownable.changeAuthorityAddress(other, {
86 | from: authorityAddress,
87 | });
88 | expectRevert(
89 | this.ownable.acceptAuthorityAddress({from: other1}),
90 | "ERR_AUTHORIZED_ADDRESS_ONLY"
91 | );
92 | let receipt = await this.ownable.acceptAuthorityAddress({from: other});
93 | expectEvent(receipt, "OwnershipTransferred", {
94 | ownerType: "AUTHORITY_ADDRESS",
95 | previousOwner: authorityAddress,
96 | newOwner: other,
97 | });
98 | expect(await this.ownable.authorityAddress()).to.equal(other);
99 | });
100 | });
101 |
--------------------------------------------------------------------------------
/test/TokenVaultTests.js:
--------------------------------------------------------------------------------
1 | const {
2 | constants,
3 | expectEvent,
4 | expectRevert,
5 | BN,
6 | } = require("@openzeppelin/test-helpers");
7 |
8 | const {ZERO_ADDRESS} = constants;
9 |
10 | const {expect} = require("chai");
11 |
12 | const TokenVault = artifacts.require("TokenVault");
13 | const TokenVaultRegistry = artifacts.require("TokenVaultRegistery");
14 | const AuctionRegisty = artifacts.require("TestAuctionRegistery");
15 | const TestERC20 = artifacts.require("TestERC20");
16 |
17 | contract("~Token vault works", function (accounts) {
18 | const [
19 | primaryOwner,
20 | systemAddress,
21 | testTokenHolder,
22 | multiSigPlaceHolder,
23 | auctionProtectionPlaceHolder,
24 | spender,
25 | other1,
26 | ] = accounts;
27 |
28 | const startingAmount = new BN(20);
29 | const transferringAmount = new BN(10);
30 |
31 | beforeEach(async function () {
32 |
33 | this.auctionRegistry = await AuctionRegisty.new(
34 | systemAddress,
35 | multiSigPlaceHolder,
36 | {from: primaryOwner}
37 | );
38 |
39 | await this.auctionRegistry.registerContractAddress(
40 | web3.utils.fromAscii("AUCTION_PROTECTION"),
41 | auctionProtectionPlaceHolder,
42 | {
43 | from: primaryOwner,
44 | }
45 | );
46 |
47 | var tokenVaultRegistry = await TokenVaultRegistry.new(
48 | systemAddress,
49 | multiSigPlaceHolder,
50 | {from: primaryOwner}
51 | );
52 |
53 | let tempTokenVault = await TokenVault.new();
54 | await tokenVaultRegistry.addVersion(1, tempTokenVault.address);
55 |
56 | await tokenVaultRegistry.createProxy(
57 | 1,
58 | primaryOwner,
59 | systemAddress,
60 | multiSigPlaceHolder,
61 | this.auctionRegistry.address,
62 | {from: primaryOwner}
63 | );
64 |
65 | let proxyAddress = await tokenVaultRegistry.proxyAddress();
66 | this.tokenVault = await TokenVault.at(proxyAddress);
67 |
68 | this.erc20 = await TestERC20.new();
69 | await this.erc20.mint(testTokenHolder, startingAmount, {
70 | from: testTokenHolder,
71 | });
72 | });
73 | it("should initialize correctly", async function () {
74 |
75 | expect(await this.tokenVault.systemAddress()).to.equal(systemAddress);
76 |
77 | expect(await this.tokenVault.primaryOwner()).to.equal(primaryOwner);
78 |
79 | expect(await this.tokenVault.authorityAddress()).to.equal(
80 | multiSigPlaceHolder
81 | );
82 |
83 | expect(await this.tokenVault.contractsRegistry()).to.equal(
84 | this.auctionRegistry.address
85 | );
86 |
87 | expect(await this.tokenVault.auctionProtectionAddress()).to.equal(
88 | auctionProtectionPlaceHolder
89 | );
90 |
91 | });
92 |
93 | it("should accept eth correctly", async function () {
94 | let receipt = await this.tokenVault.sendTransaction({
95 | from: other1,
96 | value: transferringAmount,
97 | });
98 | expectEvent(receipt, "FundDeposited", {
99 | _token: ZERO_ADDRESS,
100 | _from: other1,
101 | _amount: transferringAmount,
102 | });
103 | });
104 | it("should deposit token correctly", async function () {
105 | //should throw if tokens were not approved
106 | //unsoecified becuase it is likely that error would of underflow from testERC20 and not from ensureTransferFrom
107 | await expectRevert.unspecified(
108 | this.tokenVault.depositeToken(
109 | this.erc20.address,
110 | testTokenHolder,
111 | transferringAmount,
112 | {from: testTokenHolder}
113 | )
114 | );
115 |
116 | await this.erc20.approve(this.tokenVault.address, transferringAmount, {
117 | from: testTokenHolder,
118 | });
119 |
120 | let receipt = await this.tokenVault.depositeToken(
121 | this.erc20.address,
122 | testTokenHolder,
123 | transferringAmount,
124 | {from: testTokenHolder}
125 | );
126 | expectEvent(receipt, "FundDeposited", {
127 | _token: this.erc20.address,
128 | _from: testTokenHolder,
129 | _amount: transferringAmount,
130 | });
131 | });
132 | it("should add spender correctly", async function () {
133 | await expectRevert(
134 | this.tokenVault.addSpender(spender, {from: other1}),
135 | "ERR_AUTHORIZED_ADDRESS_ONLY"
136 | );
137 | let receipt = await this.tokenVault.addSpender(spender, {
138 | from: multiSigPlaceHolder,
139 | });
140 | expectEvent(receipt, "TokenSpenderAdded", {_which: spender});
141 |
142 | expect(await this.tokenVault.isSpender(spender)).to.be.equal(true);
143 | await expectRevert(
144 | this.tokenVault.addSpender(spender, {from: multiSigPlaceHolder}),
145 | "ERR_AUTHORIZED_ADDRESS_ONLY"
146 | );
147 | });
148 | it("should remove spender correctly", async function () {
149 | await this.tokenVault.addSpender(spender, {
150 | from: multiSigPlaceHolder,
151 | });
152 | //if called by other1
153 | await expectRevert(
154 | this.tokenVault.removeSpender(spender, {from: other1}),
155 | "ERR_AUTHORIZED_ADDRESS_ONLY"
156 | );
157 | //if not a spender already
158 | await expectRevert(
159 | this.tokenVault.removeSpender(other1, {from: multiSigPlaceHolder}),
160 | "ERR_AUTHORIZED_ADDRESS_ONLY"
161 | );
162 | let receipt = await this.tokenVault.removeSpender(spender, {
163 | from: multiSigPlaceHolder,
164 | });
165 | expectEvent(receipt, "TokenSpenderRemoved", {_which: spender});
166 |
167 | expect(await this.tokenVault.isSpender(spender)).to.be.equal(false);
168 | });
169 | it("should transfer tokens correctly", async function () {
170 | await this.tokenVault.addSpender(spender, {
171 | from: multiSigPlaceHolder,
172 | });
173 | //throw if insufficient funds
174 | await expectRevert.unspecified(
175 | this.tokenVault.directTransfer(
176 | this.erc20.address,
177 | other1,
178 | transferringAmount,
179 | {from: spender}
180 | )
181 | );
182 | await this.erc20.transfer(this.tokenVault.address, transferringAmount, {
183 | from: testTokenHolder,
184 | });
185 | //throw if not one of spenders address
186 | await expectRevert(
187 | this.tokenVault.directTransfer(
188 | this.erc20.address,
189 | other1,
190 | transferringAmount,
191 | {from: other1}
192 | ),
193 | "ERR_AUTHORIZED_ADDRESS_ONLY"
194 | );
195 |
196 | let receipt = await this.tokenVault.directTransfer(
197 | this.erc20.address,
198 | other1,
199 | transferringAmount,
200 | {from: spender}
201 | );
202 | expectEvent(receipt, "FundTransfer", {
203 | _by: spender,
204 | _to: other1,
205 | _token: this.erc20.address,
206 | amount: transferringAmount,
207 | });
208 | });
209 | it("should transfer eth correctly", async function () {
210 | await this.tokenVault.addSpender(spender, {
211 | from: multiSigPlaceHolder,
212 | });
213 | //throw if insufficient funds
214 | await expectRevert.unspecified(
215 | this.tokenVault.transferEther(other1, transferringAmount, {from: spender})
216 | );
217 | await this.tokenVault.sendTransaction({
218 | from: other1,
219 | value: transferringAmount,
220 | });
221 | //throw if not one of spenders address
222 | await expectRevert(
223 | this.tokenVault.transferEther(other1, transferringAmount, {from: other1}),
224 | "ERR_AUTHORIZED_ADDRESS_ONLY"
225 | );
226 |
227 | let receipt = await this.tokenVault.transferEther(
228 | other1,
229 | transferringAmount,
230 | {from: spender}
231 | );
232 | expectEvent(receipt, "FundTransfer", {
233 | _by: spender,
234 | _to: other1,
235 | _token: ZERO_ADDRESS,
236 | amount: transferringAmount,
237 | });
238 | });
239 | //choosing to not test remaining one line methods
240 | });
241 |
--------------------------------------------------------------------------------
/test/bancorArtifacts/IWhitelist.json:
--------------------------------------------------------------------------------
1 | {
2 | "contractName": "IWhitelist",
3 | "abi": [
4 | {
5 | "constant": true,
6 | "inputs": [
7 | {
8 | "name": "_address",
9 | "type": "address"
10 | }
11 | ],
12 | "name": "isWhitelisted",
13 | "outputs": [
14 | {
15 | "name": "",
16 | "type": "bool"
17 | }
18 | ],
19 | "payable": false,
20 | "stateMutability": "view",
21 | "type": "function"
22 | }
23 | ],
24 | "metadata": "",
25 | "bytecode": "0x",
26 | "deployedBytecode": "0x",
27 | "sourceMap": "",
28 | "deployedSourceMap": "",
29 | "source": "pragma solidity 0.4.26;\n\n/*\n Whitelist interface\n*/\ncontract IWhitelist {\n function isWhitelisted(address _address) public view returns (bool);\n}\n",
30 | "sourcePath": "/home/safu/minddeft/jointerInc/bancorTry/temp/contracts/solidity/contracts/utility/interfaces/IWhitelist.sol",
31 | "ast": {
32 | "absolutePath": "/home/safu/minddeft/jointerInc/bancorTry/temp/contracts/solidity/contracts/utility/interfaces/IWhitelist.sol",
33 | "exportedSymbols": {
34 | "IWhitelist": [
35 | 14174
36 | ]
37 | },
38 | "id": 14175,
39 | "nodeType": "SourceUnit",
40 | "nodes": [
41 | {
42 | "id": 14166,
43 | "literals": [
44 | "solidity",
45 | "0.4",
46 | ".26"
47 | ],
48 | "nodeType": "PragmaDirective",
49 | "src": "0:23:53"
50 | },
51 | {
52 | "baseContracts": [],
53 | "contractDependencies": [],
54 | "contractKind": "contract",
55 | "documentation": null,
56 | "fullyImplemented": false,
57 | "id": 14174,
58 | "linearizedBaseContracts": [
59 | 14174
60 | ],
61 | "name": "IWhitelist",
62 | "nodeType": "ContractDefinition",
63 | "nodes": [
64 | {
65 | "body": null,
66 | "documentation": null,
67 | "id": 14173,
68 | "implemented": false,
69 | "isConstructor": false,
70 | "isDeclaredConst": true,
71 | "modifiers": [],
72 | "name": "isWhitelisted",
73 | "nodeType": "FunctionDefinition",
74 | "parameters": {
75 | "id": 14169,
76 | "nodeType": "ParameterList",
77 | "parameters": [
78 | {
79 | "constant": false,
80 | "id": 14168,
81 | "name": "_address",
82 | "nodeType": "VariableDeclaration",
83 | "scope": 14173,
84 | "src": "104:16:53",
85 | "stateVariable": false,
86 | "storageLocation": "default",
87 | "typeDescriptions": {
88 | "typeIdentifier": "t_address",
89 | "typeString": "address"
90 | },
91 | "typeName": {
92 | "id": 14167,
93 | "name": "address",
94 | "nodeType": "ElementaryTypeName",
95 | "src": "104:7:53",
96 | "typeDescriptions": {
97 | "typeIdentifier": "t_address",
98 | "typeString": "address"
99 | }
100 | },
101 | "value": null,
102 | "visibility": "internal"
103 | }
104 | ],
105 | "src": "103:18:53"
106 | },
107 | "payable": false,
108 | "returnParameters": {
109 | "id": 14172,
110 | "nodeType": "ParameterList",
111 | "parameters": [
112 | {
113 | "constant": false,
114 | "id": 14171,
115 | "name": "",
116 | "nodeType": "VariableDeclaration",
117 | "scope": 14173,
118 | "src": "143:4:53",
119 | "stateVariable": false,
120 | "storageLocation": "default",
121 | "typeDescriptions": {
122 | "typeIdentifier": "t_bool",
123 | "typeString": "bool"
124 | },
125 | "typeName": {
126 | "id": 14170,
127 | "name": "bool",
128 | "nodeType": "ElementaryTypeName",
129 | "src": "143:4:53",
130 | "typeDescriptions": {
131 | "typeIdentifier": "t_bool",
132 | "typeString": "bool"
133 | }
134 | },
135 | "value": null,
136 | "visibility": "internal"
137 | }
138 | ],
139 | "src": "142:6:53"
140 | },
141 | "scope": 14174,
142 | "src": "81:68:53",
143 | "stateMutability": "view",
144 | "superFunction": null,
145 | "visibility": "public"
146 | }
147 | ],
148 | "scope": 14175,
149 | "src": "55:96:53"
150 | }
151 | ],
152 | "src": "0:152:53"
153 | },
154 | "legacyAST": {
155 | "absolutePath": "/home/safu/minddeft/jointerInc/bancorTry/temp/contracts/solidity/contracts/utility/interfaces/IWhitelist.sol",
156 | "exportedSymbols": {
157 | "IWhitelist": [
158 | 14174
159 | ]
160 | },
161 | "id": 14175,
162 | "nodeType": "SourceUnit",
163 | "nodes": [
164 | {
165 | "id": 14166,
166 | "literals": [
167 | "solidity",
168 | "0.4",
169 | ".26"
170 | ],
171 | "nodeType": "PragmaDirective",
172 | "src": "0:23:53"
173 | },
174 | {
175 | "baseContracts": [],
176 | "contractDependencies": [],
177 | "contractKind": "contract",
178 | "documentation": null,
179 | "fullyImplemented": false,
180 | "id": 14174,
181 | "linearizedBaseContracts": [
182 | 14174
183 | ],
184 | "name": "IWhitelist",
185 | "nodeType": "ContractDefinition",
186 | "nodes": [
187 | {
188 | "body": null,
189 | "documentation": null,
190 | "id": 14173,
191 | "implemented": false,
192 | "isConstructor": false,
193 | "isDeclaredConst": true,
194 | "modifiers": [],
195 | "name": "isWhitelisted",
196 | "nodeType": "FunctionDefinition",
197 | "parameters": {
198 | "id": 14169,
199 | "nodeType": "ParameterList",
200 | "parameters": [
201 | {
202 | "constant": false,
203 | "id": 14168,
204 | "name": "_address",
205 | "nodeType": "VariableDeclaration",
206 | "scope": 14173,
207 | "src": "104:16:53",
208 | "stateVariable": false,
209 | "storageLocation": "default",
210 | "typeDescriptions": {
211 | "typeIdentifier": "t_address",
212 | "typeString": "address"
213 | },
214 | "typeName": {
215 | "id": 14167,
216 | "name": "address",
217 | "nodeType": "ElementaryTypeName",
218 | "src": "104:7:53",
219 | "typeDescriptions": {
220 | "typeIdentifier": "t_address",
221 | "typeString": "address"
222 | }
223 | },
224 | "value": null,
225 | "visibility": "internal"
226 | }
227 | ],
228 | "src": "103:18:53"
229 | },
230 | "payable": false,
231 | "returnParameters": {
232 | "id": 14172,
233 | "nodeType": "ParameterList",
234 | "parameters": [
235 | {
236 | "constant": false,
237 | "id": 14171,
238 | "name": "",
239 | "nodeType": "VariableDeclaration",
240 | "scope": 14173,
241 | "src": "143:4:53",
242 | "stateVariable": false,
243 | "storageLocation": "default",
244 | "typeDescriptions": {
245 | "typeIdentifier": "t_bool",
246 | "typeString": "bool"
247 | },
248 | "typeName": {
249 | "id": 14170,
250 | "name": "bool",
251 | "nodeType": "ElementaryTypeName",
252 | "src": "143:4:53",
253 | "typeDescriptions": {
254 | "typeIdentifier": "t_bool",
255 | "typeString": "bool"
256 | }
257 | },
258 | "value": null,
259 | "visibility": "internal"
260 | }
261 | ],
262 | "src": "142:6:53"
263 | },
264 | "scope": 14174,
265 | "src": "81:68:53",
266 | "stateMutability": "view",
267 | "superFunction": null,
268 | "visibility": "public"
269 | }
270 | ],
271 | "scope": 14175,
272 | "src": "55:96:53"
273 | }
274 | ],
275 | "src": "0:152:53"
276 | },
277 | "compiler": {
278 | "name": "solc",
279 | "version": "0.4.26+commit.4563c3fc.Emscripten.clang"
280 | },
281 | "networks": {},
282 | "schemaVersion": "3.1.0",
283 | "updatedAt": "2020-06-10T14:32:18.878Z",
284 | "devdoc": {
285 | "methods": {}
286 | },
287 | "userdoc": {
288 | "methods": {}
289 | }
290 | }
--------------------------------------------------------------------------------
/test/multiSigTest.js:
--------------------------------------------------------------------------------
1 | const {
2 | constants,
3 | expectEvent,
4 | expectRevert,
5 | } = require("@openzeppelin/test-helpers");
6 | const {ZERO_ADDRESS} = constants;
7 |
8 | const {expect} = require("chai");
9 | function getParamFromTxEvent(
10 | transaction,
11 | paramName,
12 | contractFactory,
13 | eventName
14 | ) {
15 | assert.isObject(transaction);
16 | let logs = transaction.logs;
17 | if (eventName != null) {
18 | logs = logs.filter((l) => l.event === eventName);
19 | }
20 | assert.equal(logs.length, 1, "too many logs found!");
21 | let param = logs[0].args[paramName];
22 | if (contractFactory != null) {
23 | let contract = contractFactory.at(param);
24 | assert.isObject(contract, `getting ${paramName} failed for ${param}`);
25 | return contract;
26 | } else {
27 | return param;
28 | }
29 | }
30 |
31 | const AuctionMultiSig = artifacts.require("MultiSigGovernance");
32 | const ERC20 = artifacts.require("TestERC20");
33 | contract("~Multisig works", function (accounts) {
34 | const args = {
35 | _bigAmount: 99999999999999,
36 | _smallAmount: 200,
37 | _biggerSmallAmount: 300,
38 | _zero: 0,
39 | };
40 | var multiSigIntstance;
41 | var owners = [accounts[0], accounts[1], accounts[3], accounts[4]];
42 | const minConfirmationsRequired = 2;
43 |
44 | var data = "0x00";
45 | let value = 100;
46 | let destination = accounts[8];
47 | //console.log(data);
48 |
49 | beforeEach(async function () {
50 | multiSigIntstance = await AuctionMultiSig.new(
51 | owners,
52 | minConfirmationsRequired
53 | );
54 | await web3.eth.sendTransaction({
55 | from: accounts[0],
56 | to: multiSigIntstance.address,
57 | value: 1000000,
58 | });
59 | let chainId = await web3.eth.net.getId();
60 |
61 | var ERC20Instance = await ERC20.new();
62 | await ERC20Instance.mint(multiSigIntstance.address, 10000000);
63 |
64 | data = ERC20Instance.contract.methods
65 | .transfer(accounts[8], 10000)
66 | .encodeABI();
67 | value = 0;
68 | destination = ERC20Instance.address;
69 | });
70 |
71 | describe("~Multisig works", async function () {
72 | it("Should return the right public variables", async function () {
73 | // let owner0 = await multiauthSigIntstance.multiSigOwners(0);
74 | // assert.equal(owners[0], owner0, "value set correctly");
75 |
76 | // let owner1 = await multiSigIntstance.multiSigOwners(1);
77 | // assert.equal(owners[1], owner1, "value set correctly");
78 |
79 | let _minConfirmationsRequired = await multiSigIntstance.minConfirmationsRequired();
80 | assert.equal(
81 | minConfirmationsRequired,
82 | _minConfirmationsRequired,
83 | "value set correctly"
84 | );
85 |
86 | for (var i = 0; i < owners.length; i++) {
87 | let owner = owners[i];
88 |
89 | let _owner = await multiSigIntstance.multiSigOwners(i);
90 | assert.equal(owner, _owner, "value set correctly");
91 |
92 | let _isOwner = await multiSigIntstance.isOwner(owner);
93 | assert.equal(_isOwner, true, "value set correctly");
94 |
95 | let ownerIndex = await multiSigIntstance.ownerIndex(owner);
96 | assert.equal(ownerIndex, i, "value set correctly");
97 | }
98 | });
99 | });
100 | it("addTransaction should work", async function () {
101 | // let _transactionCount = await multiSigIntstance.transactionCount();
102 | let _transactionCount;
103 | for (var i = 0; i < owners.length; i++) {
104 | _transactionCount = await multiSigIntstance.transactionCount();
105 | let addTransaction = await multiSigIntstance.addTransaction(
106 | destination,
107 | value,
108 | data,
109 | minConfirmationsRequired,
110 | {from: owners[i]}
111 | );
112 |
113 | expectEvent(addTransaction, "NewTransactionAdded", {
114 | transactionId: _transactionCount,
115 | owner: owners[i],
116 | });
117 |
118 | let transactionObj = await multiSigIntstance.transactions(
119 | _transactionCount
120 | );
121 |
122 | assert.equal(
123 | transactionObj.destination,
124 | destination,
125 | "value set correctly"
126 | );
127 | assert.equal(transactionObj.value, value, "value set correctly");
128 | assert.equal(transactionObj.data, data, "value set correctly");
129 | assert.equal(transactionObj.executed, false, "value set correctly");
130 | }
131 | });
132 |
133 | it("confirmTransaction should work", async function () {
134 | let _transactionCount = await multiSigIntstance.transactionCount();
135 | await multiSigIntstance.addTransaction(
136 | destination,
137 | value,
138 | data,
139 | minConfirmationsRequired,
140 | {
141 | from: owners[0],
142 | }
143 | );
144 | let transactionId = _transactionCount;
145 | for (var i = 1; i < owners.length; i++) {
146 | let confirmationsCount = await multiSigIntstance.confirmationsCount(
147 | transactionId
148 | );
149 |
150 | if (i + 1 > minConfirmationsRequired) {
151 | await expectRevert(
152 | multiSigIntstance.confirmTransaction(transactionId, {
153 | from: owners[i],
154 | }),
155 | "ERR_TRAN_ALREADY_EXUCATED"
156 | );
157 | continue;
158 | }
159 | let confirmTransaction = await multiSigIntstance.confirmTransaction(
160 | transactionId,
161 | {from: owners[i]}
162 | );
163 | confirmationsCount = await multiSigIntstance.confirmationsCount(
164 | transactionId
165 | );
166 |
167 | assert.equal(confirmationsCount, i + 1, "value set correctly");
168 |
169 | expectEvent(confirmTransaction, "TransactionConfirmed", {
170 | transactionId: transactionId,
171 | owner: owners[i],
172 | });
173 |
174 | if (minConfirmationsRequired == confirmationsCount) {
175 | expectEvent(confirmTransaction, "TransactionExecuted", {
176 | transactionId: transactionId,
177 | isSuccess: true,
178 | });
179 | }
180 | }
181 | });
182 | it("revoke conifrmation should work", async function () {
183 | let _transactionCount = await multiSigIntstance.transactionCount();
184 |
185 | let addTransaction = await multiSigIntstance.addTransaction(
186 | destination,
187 | value,
188 | data,
189 | minConfirmationsRequired,
190 | {
191 | from: owners[0],
192 | }
193 | );
194 | let transactionId = _transactionCount;
195 | for (var i = 1; i < minConfirmationsRequired - 1; i++) {
196 | let confirmTransaction = await multiSigIntstance.confirmTransaction(
197 | transactionId,
198 | {from: owners[i]}
199 | );
200 | let confirmationsCount = await multiSigIntstance.confirmationsCount(
201 | transactionId
202 | );
203 | }
204 |
205 | for (var i = minConfirmationsRequired - 2; i > -1; i--) {
206 | let revokeTransaction = await multiSigIntstance.revokeConfirmation(
207 | transactionId,
208 | {from: owners[i]}
209 | );
210 | let bool = await multiSigIntstance.confirmations(
211 | transactionId,
212 | owners[i]
213 | );
214 | assert.equal(bool, false, "confirmation revoked value set correcty");
215 | expectEvent(revokeTransaction, "TransactionConfirmationRevoked", {
216 | transactionId: transactionId,
217 | owner: owners[i],
218 | });
219 | }
220 | });
221 | it("withdrawEth should work", async function () {
222 | let amountToWithdraw = 1;
223 | let oldContractBalance = await web3.eth.getBalance(
224 | multiSigIntstance.address
225 | );
226 | data = multiSigIntstance.contract.methods
227 | .withDrawEth(amountToWithdraw, owners[0])
228 | .encodeABI();
229 | value = 0;
230 | destination = multiSigIntstance.address;
231 |
232 | let addTransaction = await multiSigIntstance.addTransaction(
233 | destination,
234 | value,
235 | data,
236 | minConfirmationsRequired,
237 | {
238 | from: owners[0],
239 | }
240 | );
241 |
242 | let transactionId = getParamFromTxEvent(
243 | addTransaction,
244 | "transactionId",
245 | null,
246 | "NewTransactionAdded"
247 | );
248 | for (var i = 1; i < owners.length; i++) {
249 | let confirmTransaction = await multiSigIntstance.confirmTransaction(
250 | transactionId,
251 | {from: owners[i]}
252 | );
253 | let confirmationsCount = await multiSigIntstance.confirmationsCount(
254 | transactionId
255 | );
256 |
257 | if (minConfirmationsRequired <= confirmationsCount) {
258 | var _isSuccess = getParamFromTxEvent(
259 | confirmTransaction,
260 | "isSuccess",
261 | null,
262 | "TransactionExecuted"
263 | );
264 |
265 | assert.equal(_isSuccess, true, "Transaction executed successfully");
266 |
267 | break;
268 | }
269 | }
270 | let newContractBalance = await web3.eth.getBalance(
271 | multiSigIntstance.address
272 | );
273 |
274 | assert.equal(
275 | amountToWithdraw,
276 | oldContractBalance - newContractBalance,
277 | "withdrawed suceessfully"
278 | );
279 | });
280 | });
281 |
--------------------------------------------------------------------------------
/test/utils.js:
--------------------------------------------------------------------------------
1 | const advanceTime = (time) => {
2 | return new Promise((resolve, reject) => {
3 | web3.currentProvider.send(
4 | {
5 | jsonrpc: "2.0",
6 | method: "evm_increaseTime",
7 | params: [time],
8 | id: new Date().getTime(),
9 | },
10 | (err, result) => {
11 | if (err) {
12 | return reject(err);
13 | }
14 | return resolve(result);
15 | }
16 | );
17 | });
18 | };
19 |
20 | const advanceBlock = () => {
21 | return new Promise((resolve, reject) => {
22 | web3.currentProvider.send(
23 | {
24 | jsonrpc: "2.0",
25 | method: "evm_mine",
26 | id: new Date().getTime(),
27 | },
28 | (err, result) => {
29 | if (err) {
30 | return reject(err);
31 | }
32 | const newBlockHash = web3.eth.getBlock("latest").hash;
33 |
34 | return resolve(newBlockHash);
35 | }
36 | );
37 | });
38 | };
39 |
40 | const takeSnapshot = () => {
41 | return new Promise((resolve, reject) => {
42 | web3.currentProvider.send(
43 | {
44 | jsonrpc: "2.0",
45 | method: "evm_snapshot",
46 | id: new Date().getTime(),
47 | },
48 | (err, snapshotId) => {
49 | if (err) {
50 | return reject(err);
51 | }
52 | return resolve(snapshotId);
53 | }
54 | );
55 | });
56 | };
57 |
58 | const revertToSnapshot = (id) => {
59 | return new Promise((resolve, reject) => {
60 | web3.currentProvider.send(
61 | {
62 | jsonrpc: "2.0",
63 | method: "evm_revert",
64 | params: [id],
65 | id: new Date().getTime(),
66 | },
67 | (err, result) => {
68 | if (err) {
69 | return reject(err);
70 | }
71 | return resolve(result);
72 | }
73 | );
74 | });
75 | };
76 |
77 | const advanceTimeAndBlock = async (time) => {
78 | await advanceTime(time);
79 | await advanceBlock();
80 | return Promise.resolve(web3.eth.getBlock("latest"));
81 | };
82 |
83 | module.exports = {
84 | advanceTime,
85 | advanceBlock,
86 | advanceTimeAndBlock,
87 | takeSnapshot,
88 | revertToSnapshot,
89 | };
90 |
--------------------------------------------------------------------------------