diff --git a/abiniser/deployments/4/Exchange_DEPLOYS.json b/abiniser/deployments/4/Exchange_DEPLOYS.json index e6f4666b..861e9189 100644 --- a/abiniser/deployments/4/Exchange_DEPLOYS.json +++ b/abiniser/deployments/4/Exchange_DEPLOYS.json @@ -50,7 +50,7 @@ } }, "3c157a5256a2093da587f166d4dbd537": { - "latestDeployedAddress": "0xa2ed50765110b695816c658d5d6d1d32bcd03866", + "latestDeployedAddress": "0xc5b604f8e046dff26642ca544c9eb3064e02ecd9", "deployments": { "0xa2ed50765110b695816c658d5d6d1d32bcd03866": { "generatedAt": "2018-05-03T22:05:03.992Z", @@ -64,6 +64,19 @@ "deployedBytecodeHash": "2c390a9b03f57a87af44432fc6444647", "sourceHash": "6e27bdbdc64d0d9cf52de1abc46c4cf7", "source": "/* Augmint's Internal Exchange\n\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/exchangeFlow.png\n\n TODO:\n - change to wihtdrawal pattern, see: https://github.com/Augmint/augmint-contracts/issues/17\n - deduct fee\n - consider take funcs (frequent rate changes with takeBuyToken? send more and send back remainder?)\n - use Rates interface?\n*/\npragma solidity ^0.4.23;\n\nimport \"./generic/SafeMath.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./Rates.sol\";\n\n\ncontract Exchange is Restricted {\n using SafeMath for uint256;\n\n AugmintTokenInterface public augmintToken;\n Rates public rates;\n\n uint public constant CHUNK_SIZE = 100;\n\n struct Order {\n uint64 index;\n address maker;\n\n // % of published current peggedSymbol/ETH rates published by Rates contract. Stored as parts per million\n // I.e. 1,000,000 = 100% (parity), 990,000 = 1% below parity\n uint32 price;\n\n // buy order: amount in wei\n // sell order: token amount\n uint amount;\n }\n\n uint64 public orderCount;\n mapping(uint64 => Order) public buyTokenOrders;\n mapping(uint64 => Order) public sellTokenOrders;\n\n uint64[] private activeBuyOrders;\n uint64[] private activeSellOrders;\n\n /* used to stop executing matchMultiple when running out of gas.\n actual is much less, just leaving enough matchMultipleOrders() to finish TODO: fine tune & test it*/\n uint32 private constant ORDER_MATCH_WORST_GAS = 100000;\n\n event NewOrder(uint64 indexed orderId, address indexed maker, uint32 price, uint tokenAmount, uint weiAmount);\n\n event OrderFill(address indexed tokenBuyer, address indexed tokenSeller, uint64 buyTokenOrderId,\n uint64 sellTokenOrderId, uint publishedRate, uint32 price, uint fillRate, uint weiAmount, uint tokenAmount);\n\n event CancelledOrder(uint64 indexed orderId, address indexed maker, uint tokenAmount, uint weiAmount);\n\n event RatesContractChanged(Rates newRatesContract);\n\n constructor(AugmintTokenInterface _augmintToken, Rates _rates) public {\n augmintToken = _augmintToken;\n rates = _rates;\n }\n\n /* to allow upgrade of Rates contract */\n function setRatesContract(Rates newRatesContract)\n external restrict(\"MonetaryBoard\") {\n rates = newRatesContract;\n emit RatesContractChanged(newRatesContract);\n }\n\n function placeBuyTokenOrder(uint32 price) external payable returns (uint64 orderId) {\n require(price > 0, \"price must be > 0\");\n require(msg.value > 0, \"msg.value must be > 0\");\n\n orderId = ++orderCount;\n buyTokenOrders[orderId] = Order(uint64(activeBuyOrders.length), msg.sender, price, msg.value);\n activeBuyOrders.push(orderId);\n\n emit NewOrder(orderId, msg.sender, price, 0, msg.value);\n }\n\n /* this function requires previous approval to transfer tokens */\n function placeSellTokenOrder(uint32 price, uint tokenAmount) external returns (uint orderId) {\n augmintToken.transferFrom(msg.sender, this, tokenAmount);\n return _placeSellTokenOrder(msg.sender, price, tokenAmount);\n }\n\n /* place sell token order called from AugmintToken's transferAndNotify\n Flow:\n 1) user calls token contract's transferAndNotify price passed in data arg\n 2) transferAndNotify transfers tokens to the Exchange contract\n 3) transferAndNotify calls Exchange.transferNotification with lockProductId\n */\n function transferNotification(address maker, uint tokenAmount, uint price) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n _placeSellTokenOrder(maker, uint32(price), tokenAmount);\n }\n\n function cancelBuyTokenOrder(uint64 buyTokenId) external {\n Order storage order = buyTokenOrders[buyTokenId];\n require(order.maker == msg.sender, \"msg.sender must be order.maker\");\n\n uint amount = order.amount;\n order.amount = 0;\n _removeBuyOrder(order);\n\n msg.sender.transfer(amount);\n\n emit CancelledOrder(buyTokenId, msg.sender, 0, amount);\n }\n\n function cancelSellTokenOrder(uint64 sellTokenId) external {\n Order storage order = sellTokenOrders[sellTokenId];\n require(order.maker == msg.sender, \"msg.sender must be order.maker\");\n\n uint amount = order.amount;\n order.amount = 0;\n _removeSellOrder(order);\n\n augmintToken.transferWithNarrative(msg.sender, amount, \"Sell token order cancelled\");\n\n emit CancelledOrder(sellTokenId, msg.sender, amount, 0);\n }\n\n /* matches any two orders if the sell price >= buy price\n trade price meets in the middle\n reverts if any of the orders have been removed\n */\n function matchOrders(uint64 buyTokenId, uint64 sellTokenId) external {\n _fillOrder(buyTokenId, sellTokenId);\n }\n\n /* matches as many orders as possible from the passed orders\n Runs as long as gas is available for the call.\n Stops if any match is invalid (case when any of the orders removed after client generated the match list sent)\n */\n function matchMultipleOrders(uint64[] buyTokenIds, uint64[] sellTokenIds) external returns(uint matchCount) {\n uint len = buyTokenIds.length;\n require(len == sellTokenIds.length, \"buyTokenIds and sellTokenIds lengths must be equal\");\n\n for (uint i = 0; i < len && gasleft() > ORDER_MATCH_WORST_GAS; i++) {\n _fillOrder(buyTokenIds[i], sellTokenIds[i]);\n matchCount++;\n }\n }\n\n function getActiveOrderCounts() external view returns(uint buyTokenOrderCount, uint sellTokenOrderCount) {\n return(activeBuyOrders.length, activeSellOrders.length);\n }\n\n // returns CHUNK_SIZE orders starting from offset\n // orders are encoded as [id, maker, price, amount]\n function getActiveBuyOrders(uint offset) external view returns (uint[4][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE && i + offset < activeBuyOrders.length; i++) {\n uint64 orderId = activeBuyOrders[offset + i];\n Order storage order = buyTokenOrders[orderId];\n response[i] = [orderId, uint(order.maker), order.price, order.amount];\n }\n }\n\n function getActiveSellOrders(uint offset) external view returns (uint[4][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE && i + offset < activeSellOrders.length; i++) {\n uint64 orderId = activeSellOrders[offset + i];\n Order storage order = sellTokenOrders[orderId];\n response[i] = [orderId, uint(order.maker), order.price, order.amount];\n }\n }\n\n function _fillOrder(uint64 buyTokenId, uint64 sellTokenId) private {\n Order storage buy = buyTokenOrders[buyTokenId];\n Order storage sell = sellTokenOrders[sellTokenId];\n\n require(buy.price >= sell.price, \"buy price must be >= sell price\");\n\n // pick maker's price (whoever placed order sooner considered as maker)\n uint32 price = buyTokenId > sellTokenId ? sell.price : buy.price;\n\n uint publishedRate;\n (publishedRate, ) = rates.rates(augmintToken.peggedSymbol());\n uint fillRate = publishedRate.mul(price).roundedDiv(1000000);\n\n uint sellWei = sell.amount.mul(1 ether).roundedDiv(fillRate);\n\n uint tradedWei;\n uint tradedTokens;\n if (sellWei <= buy.amount) {\n tradedWei = sellWei;\n tradedTokens = sell.amount;\n } else {\n tradedWei = buy.amount;\n tradedTokens = buy.amount.mul(fillRate).roundedDiv(1 ether);\n }\n\n buy.amount = buy.amount.sub(tradedWei);\n if (buy.amount == 0) {\n _removeBuyOrder(buy);\n }\n\n sell.amount = sell.amount.sub(tradedTokens);\n if (sell.amount == 0) {\n _removeSellOrder(sell);\n }\n\n augmintToken.transferWithNarrative(buy.maker, tradedTokens, \"Buy token order fill\");\n sell.maker.transfer(tradedWei);\n\n emit OrderFill(buy.maker, sell.maker, buyTokenId,\n sellTokenId, publishedRate, price, fillRate, tradedWei, tradedTokens);\n }\n\n function _placeSellTokenOrder(address maker, uint32 price, uint tokenAmount)\n private returns (uint64 orderId) {\n require(price > 0, \"price must be > 0\");\n require(tokenAmount > 0, \"tokenAmount must be > 0\");\n\n orderId = ++orderCount;\n sellTokenOrders[orderId] = Order(uint64(activeSellOrders.length), maker, price, tokenAmount);\n activeSellOrders.push(orderId);\n\n emit NewOrder(orderId, maker, price, tokenAmount, 0);\n }\n\n function _removeBuyOrder(Order storage order) private {\n _removeOrder(activeBuyOrders, order.index);\n }\n\n function _removeSellOrder(Order storage order) private {\n _removeOrder(activeSellOrders, order.index);\n }\n\n function _removeOrder(uint64[] storage orders, uint64 index) private {\n if (index < orders.length - 1) {\n orders[index] = orders[orders.length - 1];\n }\n orders.length--;\n }\n\n}\n" + }, + "0xc5b604f8e046dff26642ca544c9eb3064e02ecd9": { + "generatedAt": "2018-05-12T01:34:38.557Z", + "truffleContractFileUpdatedAt": "2018-05-12T01:30:50.090Z", + "deployTransactionHash": "0x7f022b010da30ab1c76d7c976a0b8f19ac6d7eab34ba46d19fcbfad1695fcb21", + "compiler": { + "name": "solc", + "version": "0.4.23+commit.124ca40d.Emscripten.clang" + }, + "bytecodeHash": "0c3aae2a1e26a2cc4f1800e62fa873ee", + "deployedBytecodeHash": "4c6ad15993389d8d7326c731b2b92d63", + "sourceHash": "6e27bdbdc64d0d9cf52de1abc46c4cf7", + "source": "/* Augmint's Internal Exchange\n\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/exchangeFlow.png\n\n TODO:\n - change to wihtdrawal pattern, see: https://github.com/Augmint/augmint-contracts/issues/17\n - deduct fee\n - consider take funcs (frequent rate changes with takeBuyToken? send more and send back remainder?)\n - use Rates interface?\n*/\npragma solidity ^0.4.23;\n\nimport \"./generic/SafeMath.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./Rates.sol\";\n\n\ncontract Exchange is Restricted {\n using SafeMath for uint256;\n\n AugmintTokenInterface public augmintToken;\n Rates public rates;\n\n uint public constant CHUNK_SIZE = 100;\n\n struct Order {\n uint64 index;\n address maker;\n\n // % of published current peggedSymbol/ETH rates published by Rates contract. Stored as parts per million\n // I.e. 1,000,000 = 100% (parity), 990,000 = 1% below parity\n uint32 price;\n\n // buy order: amount in wei\n // sell order: token amount\n uint amount;\n }\n\n uint64 public orderCount;\n mapping(uint64 => Order) public buyTokenOrders;\n mapping(uint64 => Order) public sellTokenOrders;\n\n uint64[] private activeBuyOrders;\n uint64[] private activeSellOrders;\n\n /* used to stop executing matchMultiple when running out of gas.\n actual is much less, just leaving enough matchMultipleOrders() to finish TODO: fine tune & test it*/\n uint32 private constant ORDER_MATCH_WORST_GAS = 100000;\n\n event NewOrder(uint64 indexed orderId, address indexed maker, uint32 price, uint tokenAmount, uint weiAmount);\n\n event OrderFill(address indexed tokenBuyer, address indexed tokenSeller, uint64 buyTokenOrderId,\n uint64 sellTokenOrderId, uint publishedRate, uint32 price, uint fillRate, uint weiAmount, uint tokenAmount);\n\n event CancelledOrder(uint64 indexed orderId, address indexed maker, uint tokenAmount, uint weiAmount);\n\n event RatesContractChanged(Rates newRatesContract);\n\n constructor(AugmintTokenInterface _augmintToken, Rates _rates) public {\n augmintToken = _augmintToken;\n rates = _rates;\n }\n\n /* to allow upgrade of Rates contract */\n function setRatesContract(Rates newRatesContract)\n external restrict(\"MonetaryBoard\") {\n rates = newRatesContract;\n emit RatesContractChanged(newRatesContract);\n }\n\n function placeBuyTokenOrder(uint32 price) external payable returns (uint64 orderId) {\n require(price > 0, \"price must be > 0\");\n require(msg.value > 0, \"msg.value must be > 0\");\n\n orderId = ++orderCount;\n buyTokenOrders[orderId] = Order(uint64(activeBuyOrders.length), msg.sender, price, msg.value);\n activeBuyOrders.push(orderId);\n\n emit NewOrder(orderId, msg.sender, price, 0, msg.value);\n }\n\n /* this function requires previous approval to transfer tokens */\n function placeSellTokenOrder(uint32 price, uint tokenAmount) external returns (uint orderId) {\n augmintToken.transferFrom(msg.sender, this, tokenAmount);\n return _placeSellTokenOrder(msg.sender, price, tokenAmount);\n }\n\n /* place sell token order called from AugmintToken's transferAndNotify\n Flow:\n 1) user calls token contract's transferAndNotify price passed in data arg\n 2) transferAndNotify transfers tokens to the Exchange contract\n 3) transferAndNotify calls Exchange.transferNotification with lockProductId\n */\n function transferNotification(address maker, uint tokenAmount, uint price) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n _placeSellTokenOrder(maker, uint32(price), tokenAmount);\n }\n\n function cancelBuyTokenOrder(uint64 buyTokenId) external {\n Order storage order = buyTokenOrders[buyTokenId];\n require(order.maker == msg.sender, \"msg.sender must be order.maker\");\n\n uint amount = order.amount;\n order.amount = 0;\n _removeBuyOrder(order);\n\n msg.sender.transfer(amount);\n\n emit CancelledOrder(buyTokenId, msg.sender, 0, amount);\n }\n\n function cancelSellTokenOrder(uint64 sellTokenId) external {\n Order storage order = sellTokenOrders[sellTokenId];\n require(order.maker == msg.sender, \"msg.sender must be order.maker\");\n\n uint amount = order.amount;\n order.amount = 0;\n _removeSellOrder(order);\n\n augmintToken.transferWithNarrative(msg.sender, amount, \"Sell token order cancelled\");\n\n emit CancelledOrder(sellTokenId, msg.sender, amount, 0);\n }\n\n /* matches any two orders if the sell price >= buy price\n trade price meets in the middle\n reverts if any of the orders have been removed\n */\n function matchOrders(uint64 buyTokenId, uint64 sellTokenId) external {\n _fillOrder(buyTokenId, sellTokenId);\n }\n\n /* matches as many orders as possible from the passed orders\n Runs as long as gas is available for the call.\n Stops if any match is invalid (case when any of the orders removed after client generated the match list sent)\n */\n function matchMultipleOrders(uint64[] buyTokenIds, uint64[] sellTokenIds) external returns(uint matchCount) {\n uint len = buyTokenIds.length;\n require(len == sellTokenIds.length, \"buyTokenIds and sellTokenIds lengths must be equal\");\n\n for (uint i = 0; i < len && gasleft() > ORDER_MATCH_WORST_GAS; i++) {\n _fillOrder(buyTokenIds[i], sellTokenIds[i]);\n matchCount++;\n }\n }\n\n function getActiveOrderCounts() external view returns(uint buyTokenOrderCount, uint sellTokenOrderCount) {\n return(activeBuyOrders.length, activeSellOrders.length);\n }\n\n // returns CHUNK_SIZE orders starting from offset\n // orders are encoded as [id, maker, price, amount]\n function getActiveBuyOrders(uint offset) external view returns (uint[4][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE && i + offset < activeBuyOrders.length; i++) {\n uint64 orderId = activeBuyOrders[offset + i];\n Order storage order = buyTokenOrders[orderId];\n response[i] = [orderId, uint(order.maker), order.price, order.amount];\n }\n }\n\n function getActiveSellOrders(uint offset) external view returns (uint[4][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE && i + offset < activeSellOrders.length; i++) {\n uint64 orderId = activeSellOrders[offset + i];\n Order storage order = sellTokenOrders[orderId];\n response[i] = [orderId, uint(order.maker), order.price, order.amount];\n }\n }\n\n function _fillOrder(uint64 buyTokenId, uint64 sellTokenId) private {\n Order storage buy = buyTokenOrders[buyTokenId];\n Order storage sell = sellTokenOrders[sellTokenId];\n\n require(buy.price >= sell.price, \"buy price must be >= sell price\");\n\n // pick maker's price (whoever placed order sooner considered as maker)\n uint32 price = buyTokenId > sellTokenId ? sell.price : buy.price;\n\n uint publishedRate;\n (publishedRate, ) = rates.rates(augmintToken.peggedSymbol());\n uint fillRate = publishedRate.mul(price).roundedDiv(1000000);\n\n uint sellWei = sell.amount.mul(1 ether).roundedDiv(fillRate);\n\n uint tradedWei;\n uint tradedTokens;\n if (sellWei <= buy.amount) {\n tradedWei = sellWei;\n tradedTokens = sell.amount;\n } else {\n tradedWei = buy.amount;\n tradedTokens = buy.amount.mul(fillRate).roundedDiv(1 ether);\n }\n\n buy.amount = buy.amount.sub(tradedWei);\n if (buy.amount == 0) {\n _removeBuyOrder(buy);\n }\n\n sell.amount = sell.amount.sub(tradedTokens);\n if (sell.amount == 0) {\n _removeSellOrder(sell);\n }\n\n augmintToken.transferWithNarrative(buy.maker, tradedTokens, \"Buy token order fill\");\n sell.maker.transfer(tradedWei);\n\n emit OrderFill(buy.maker, sell.maker, buyTokenId,\n sellTokenId, publishedRate, price, fillRate, tradedWei, tradedTokens);\n }\n\n function _placeSellTokenOrder(address maker, uint32 price, uint tokenAmount)\n private returns (uint64 orderId) {\n require(price > 0, \"price must be > 0\");\n require(tokenAmount > 0, \"tokenAmount must be > 0\");\n\n orderId = ++orderCount;\n sellTokenOrders[orderId] = Order(uint64(activeSellOrders.length), maker, price, tokenAmount);\n activeSellOrders.push(orderId);\n\n emit NewOrder(orderId, maker, price, tokenAmount, 0);\n }\n\n function _removeBuyOrder(Order storage order) private {\n _removeOrder(activeBuyOrders, order.index);\n }\n\n function _removeSellOrder(Order storage order) private {\n _removeOrder(activeSellOrders, order.index);\n }\n\n function _removeOrder(uint64[] storage orders, uint64 index) private {\n if (index < orders.length - 1) {\n orders[index] = orders[orders.length - 1];\n }\n orders.length--;\n }\n\n}\n" } } } diff --git a/abiniser/deployments/4/LoanManager_DEPLOYS.json b/abiniser/deployments/4/LoanManager_DEPLOYS.json index 0d49d1cb..c23b02f0 100644 --- a/abiniser/deployments/4/LoanManager_DEPLOYS.json +++ b/abiniser/deployments/4/LoanManager_DEPLOYS.json @@ -37,7 +37,7 @@ } }, "291572b8d2ffe95dca1733ebc1472e08": { - "latestDeployedAddress": "0xbdb02f82d7ad574f9f549895caf41e23a8981b07", + "latestDeployedAddress": "0x214919abe3f2b7ca7a43a799c4fc7132bbf78e8a", "deployments": { "0xbdb02f82d7ad574f9f549895caf41e23a8981b07": { "generatedAt": "2018-04-25T12:31:29.206Z", @@ -51,6 +51,19 @@ "deployedBytecodeHash": "7b195ed87405ef49bec0955ea58bb0ea", "sourceHash": "9d5f96db98b6d336c18b8c6df5c7cd92", "source": "/*\n Contract to manage Augmint token loan contracts backed by ETH\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/loanFlow.png\n\n TODO:\n - create MonetarySupervisor interface and use it instead?\n - make data arg generic bytes?\n - make collect() run as long as gas provided allows\n*/\npragma solidity ^0.4.23;\n\nimport \"./Rates.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./generic/SafeMath.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./MonetarySupervisor.sol\";\n\n\ncontract LoanManager is Restricted {\n using SafeMath for uint256;\n\n uint16 public constant CHUNK_SIZE = 100;\n\n enum LoanState { Open, Repaid, Defaulted, Collected } // NB: Defaulted state is not stored, only getters calculate\n\n struct LoanProduct {\n uint minDisbursedAmount; // 0: with decimals set in AugmintToken.decimals\n uint32 term; // 1\n uint32 discountRate; // 2: discountRate in parts per million , ie. 10,000 = 1%\n uint32 collateralRatio; // 3: loan token amount / colleteral pegged ccy value\n // in parts per million , ie. 10,000 = 1%\n uint32 defaultingFeePt; // 4: % of collateral in parts per million , ie. 50,000 = 5%\n bool isActive; // 5\n }\n\n /* NB: we don't need to store loan parameters because loan products can't be altered (only disabled/enabled) */\n struct LoanData {\n uint collateralAmount; // 0\n uint repaymentAmount; // 1\n address borrower; // 2\n uint32 productId; // 3\n LoanState state; // 4\n uint40 maturity; // 5\n }\n\n LoanProduct[] public products;\n\n LoanData[] public loans;\n mapping(address => uint[]) public accountLoans; // owner account address => array of loan Ids\n\n Rates public rates; // instance of ETH/pegged currency rate provider contract\n AugmintTokenInterface public augmintToken; // instance of token contract\n MonetarySupervisor public monetarySupervisor;\n\n event NewLoan(uint32 productId, uint loanId, address indexed borrower, uint collateralAmount, uint loanAmount,\n uint repaymentAmount, uint40 maturity);\n\n event LoanProductActiveStateChanged(uint32 productId, bool newState);\n\n event LoanProductAdded(uint32 productId);\n\n event LoanRepayed(uint loanId, address borrower);\n\n event LoanCollected(uint loanId, address indexed borrower, uint collectedCollateral,\n uint releasedCollateral, uint defaultingFee);\n\n event SystemContractsChanged(Rates newRatesContract, MonetarySupervisor newMonetarySupervisor);\n\n constructor(AugmintTokenInterface _augmintToken, MonetarySupervisor _monetarySupervisor, Rates _rates)\n public {\n augmintToken = _augmintToken;\n monetarySupervisor = _monetarySupervisor;\n rates = _rates;\n }\n\n function addLoanProduct(uint32 term, uint32 discountRate, uint32 collateralRatio, uint minDisbursedAmount,\n uint32 defaultingFeePt, bool isActive)\n external restrict(\"MonetaryBoard\") {\n\n uint _newProductId = products.push(\n LoanProduct(minDisbursedAmount, term, discountRate, collateralRatio, defaultingFeePt, isActive)\n ) - 1;\n\n uint32 newProductId = uint32(_newProductId);\n require(newProductId == _newProductId, \"productId overflow\");\n\n emit LoanProductAdded(newProductId);\n }\n\n function setLoanProductActiveState(uint32 productId, bool newState)\n external restrict (\"MonetaryBoard\") {\n require(productId < products.length, \"invalid productId\"); // next line would revert but require to emit reason\n products[productId].isActive = false;\n emit LoanProductActiveStateChanged(productId, newState);\n }\n\n function newEthBackedLoan(uint32 productId) external payable {\n require(productId < products.length, \"invalid productId\"); // next line would revert but require to emit reason\n LoanProduct storage product = products[productId];\n require(product.isActive, \"product must be in active state\"); // valid product\n\n\n // calculate loan values based on ETH sent in with Tx\n uint tokenValue = rates.convertFromWei(augmintToken.peggedSymbol(), msg.value);\n uint repaymentAmount = tokenValue.mul(product.collateralRatio).div(1000000);\n\n uint loanAmount;\n (loanAmount, ) = calculateLoanValues(product, repaymentAmount);\n\n require(loanAmount >= product.minDisbursedAmount, \"loanAmount must be >= minDisbursedAmount\");\n\n uint expiration = now.add(product.term);\n uint40 maturity = uint40(expiration);\n require(maturity == expiration, \"maturity overflow\");\n\n // Create new loan\n uint loanId = loans.push(LoanData(msg.value, repaymentAmount, msg.sender,\n productId, LoanState.Open, maturity)) - 1;\n\n // Store ref to new loan\n accountLoans[msg.sender].push(loanId);\n\n // Issue tokens and send to borrower\n monetarySupervisor.issueLoan(msg.sender, loanAmount);\n\n emit NewLoan(productId, loanId, msg.sender, msg.value, loanAmount, repaymentAmount, maturity);\n }\n\n /* repay loan, called from AugmintToken's transferAndNotify\n Flow for repaying loan:\n 1) user calls token contract's transferAndNotify loanId passed in data arg\n 2) transferAndNotify transfers tokens to the Lender contract\n 3) transferAndNotify calls Lender.transferNotification with lockProductId\n */\n // from arg is not used as we allow anyone to repay a loan:\n function transferNotification(address, uint repaymentAmount, uint loanId) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n\n _repayLoan(loanId, repaymentAmount);\n }\n\n function collect(uint[] loanIds) external {\n /* when there are a lots of loans to be collected then\n the client need to call it in batches to make sure tx won't exceed block gas limit.\n Anyone can call it - can't cause harm as it only allows to collect loans which they are defaulted\n TODO: optimise defaulting fee calculations\n */\n uint totalLoanAmountCollected;\n uint totalCollateralToCollect;\n uint totalDefaultingFee;\n for (uint i = 0; i < loanIds.length; i++) {\n require(i < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanIds[i]];\n require(loan.state == LoanState.Open, \"loan state must be Open\");\n require(now >= loan.maturity, \"current time must be later than maturity\");\n LoanProduct storage product = products[loan.productId];\n\n uint loanAmount;\n (loanAmount, ) = calculateLoanValues(product, loan.repaymentAmount);\n\n totalLoanAmountCollected = totalLoanAmountCollected.add(loanAmount);\n\n loan.state = LoanState.Collected;\n\n // send ETH collateral to augmintToken reserve\n uint defaultingFeeInToken = loan.repaymentAmount.mul(product.defaultingFeePt).div(1000000);\n uint defaultingFee = rates.convertToWei(augmintToken.peggedSymbol(), defaultingFeeInToken);\n uint targetCollection = rates.convertToWei(augmintToken.peggedSymbol(),\n loan.repaymentAmount).add(defaultingFee);\n\n uint releasedCollateral;\n if (targetCollection < loan.collateralAmount) {\n releasedCollateral = loan.collateralAmount.sub(targetCollection);\n loan.borrower.transfer(releasedCollateral);\n }\n uint collateralToCollect = loan.collateralAmount.sub(releasedCollateral);\n if (defaultingFee >= collateralToCollect) {\n defaultingFee = collateralToCollect;\n collateralToCollect = 0;\n } else {\n collateralToCollect = collateralToCollect.sub(defaultingFee);\n }\n totalDefaultingFee = totalDefaultingFee.add(defaultingFee);\n\n totalCollateralToCollect = totalCollateralToCollect.add(collateralToCollect);\n\n emit LoanCollected(loanIds[i], loan.borrower, collateralToCollect.add(defaultingFee), releasedCollateral, defaultingFee);\n }\n\n if (totalCollateralToCollect > 0) {\n address(monetarySupervisor.augmintReserves()).transfer(totalCollateralToCollect);\n }\n\n if (totalDefaultingFee > 0){\n address(augmintToken.feeAccount()).transfer(totalDefaultingFee);\n }\n\n monetarySupervisor.loanCollectionNotification(totalLoanAmountCollected);// update KPIs\n\n }\n\n /* to allow upgrade of Rates and MonetarySupervisor contracts */\n function setSystemContracts(Rates newRatesContract, MonetarySupervisor newMonetarySupervisor)\n external restrict(\"MonetaryBoard\") {\n rates = newRatesContract;\n monetarySupervisor = newMonetarySupervisor;\n emit SystemContractsChanged(newRatesContract, newMonetarySupervisor);\n }\n\n function getProductCount() external view returns (uint ct) {\n return products.length;\n }\n\n // returns CHUNK_SIZE loan products starting from some offset:\n // [ productId, minDisbursedAmount, term, discountRate, collateralRatio, defaultingFeePt, maxLoanAmount, isActive ]\n function getProducts(uint offset) external view returns (uint[8][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= products.length) { break; }\n\n LoanProduct storage product = products[offset + i];\n\n response[i] = [offset + i, product.minDisbursedAmount, product.term, product.discountRate,\n product.collateralRatio, product.defaultingFeePt,\n monetarySupervisor.getMaxLoanAmount(product.minDisbursedAmount), product.isActive ? 1 : 0 ];\n }\n }\n\n function getLoanCount() external view returns (uint ct) {\n return loans.length;\n }\n\n /* returns CHUNK_SIZE loans starting from some offset. Loans data encoded as:\n [loanId, collateralAmount, repaymentAmount, borrower, productId, state, maturity, disbursementTime,\n loanAmount, interestAmount ] */\n function getLoans(uint offset) external view returns (uint[10][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= loans.length) { break; }\n\n response[i] = getLoanTuple(offset + i);\n }\n }\n\n function getLoanCountForAddress(address borrower) external view returns (uint) {\n return accountLoans[borrower].length;\n }\n\n /* returns CHUNK_SIZE loans of a given account, starting from some offset. Loans data encoded as:\n [loanId, collateralAmount, repaymentAmount, borrower, productId, state, maturity, disbursementTime,\n loanAmount, interestAmount ] */\n function getLoansForAddress(address borrower, uint offset) external view returns (uint[10][CHUNK_SIZE] response) {\n\n uint[] storage loansForAddress = accountLoans[borrower];\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= loansForAddress.length) { break; }\n\n response[i] = getLoanTuple(loansForAddress[offset + i]);\n }\n }\n\n function getLoanTuple(uint loanId) public view returns (uint[10] result) {\n require(loanId < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanId];\n LoanProduct storage product = products[loan.productId];\n\n uint loanAmount;\n uint interestAmount;\n (loanAmount, interestAmount) = calculateLoanValues(product, loan.repaymentAmount);\n uint disbursementTime = loan.maturity - product.term;\n\n LoanState loanState =\n loan.state == LoanState.Open && now >= loan.maturity ? LoanState.Defaulted : loan.state;\n\n result = [loanId, loan.collateralAmount, loan.repaymentAmount, uint(loan.borrower),\n loan.productId, uint(loanState), loan.maturity, disbursementTime, loanAmount, interestAmount];\n }\n\n function calculateLoanValues(LoanProduct storage product, uint repaymentAmount)\n internal view returns (uint loanAmount, uint interestAmount) {\n // calculate loan values based on repayment amount\n loanAmount = repaymentAmount.mul(product.discountRate).div(1000000);\n interestAmount = loanAmount > repaymentAmount ? 0 : repaymentAmount.sub(loanAmount);\n }\n\n /* internal function, assuming repayment amount already transfered */\n function _repayLoan(uint loanId, uint repaymentAmount) internal {\n require(loanId < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanId];\n require(loan.state == LoanState.Open, \"loan state must be Open\");\n require(repaymentAmount == loan.repaymentAmount, \"repaymentAmount must be equal to tokens sent\");\n require(now <= loan.maturity, \"current time must be earlier than maturity\");\n\n LoanProduct storage product = products[loan.productId];\n uint loanAmount;\n uint interestAmount;\n (loanAmount, interestAmount) = calculateLoanValues(product, loan.repaymentAmount);\n\n loans[loanId].state = LoanState.Repaid;\n\n if (interestAmount > 0) {\n augmintToken.transfer(monetarySupervisor.interestEarnedAccount(), interestAmount);\n augmintToken.burn(loanAmount);\n } else {\n // negative or zero interest (i.e. discountRate >= 0)\n augmintToken.burn(repaymentAmount);\n }\n\n monetarySupervisor.loanRepaymentNotification(loanAmount); // update KPIs\n\n loan.borrower.transfer(loan.collateralAmount); // send back ETH collateral\n\n emit LoanRepayed(loanId, loan.borrower);\n }\n\n}\n" + }, + "0x214919abe3f2b7ca7a43a799c4fc7132bbf78e8a": { + "generatedAt": "2018-05-12T01:34:38.508Z", + "truffleContractFileUpdatedAt": "2018-05-12T01:30:50.403Z", + "deployTransactionHash": "0x809f88d01aa3ddef9c215492f1e6dcf18db2efecc925469af77b49a2c4df3b93", + "compiler": { + "name": "solc", + "version": "0.4.23+commit.124ca40d.Emscripten.clang" + }, + "bytecodeHash": "feef104fe0b04cf9bde178c2f8ee4c04", + "deployedBytecodeHash": "d16030995b358f9fd29dafc6df7e6d35", + "sourceHash": "9d5f96db98b6d336c18b8c6df5c7cd92", + "source": "/*\n Contract to manage Augmint token loan contracts backed by ETH\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/loanFlow.png\n\n TODO:\n - create MonetarySupervisor interface and use it instead?\n - make data arg generic bytes?\n - make collect() run as long as gas provided allows\n*/\npragma solidity ^0.4.23;\n\nimport \"./Rates.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./generic/SafeMath.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./MonetarySupervisor.sol\";\n\n\ncontract LoanManager is Restricted {\n using SafeMath for uint256;\n\n uint16 public constant CHUNK_SIZE = 100;\n\n enum LoanState { Open, Repaid, Defaulted, Collected } // NB: Defaulted state is not stored, only getters calculate\n\n struct LoanProduct {\n uint minDisbursedAmount; // 0: with decimals set in AugmintToken.decimals\n uint32 term; // 1\n uint32 discountRate; // 2: discountRate in parts per million , ie. 10,000 = 1%\n uint32 collateralRatio; // 3: loan token amount / colleteral pegged ccy value\n // in parts per million , ie. 10,000 = 1%\n uint32 defaultingFeePt; // 4: % of collateral in parts per million , ie. 50,000 = 5%\n bool isActive; // 5\n }\n\n /* NB: we don't need to store loan parameters because loan products can't be altered (only disabled/enabled) */\n struct LoanData {\n uint collateralAmount; // 0\n uint repaymentAmount; // 1\n address borrower; // 2\n uint32 productId; // 3\n LoanState state; // 4\n uint40 maturity; // 5\n }\n\n LoanProduct[] public products;\n\n LoanData[] public loans;\n mapping(address => uint[]) public accountLoans; // owner account address => array of loan Ids\n\n Rates public rates; // instance of ETH/pegged currency rate provider contract\n AugmintTokenInterface public augmintToken; // instance of token contract\n MonetarySupervisor public monetarySupervisor;\n\n event NewLoan(uint32 productId, uint loanId, address indexed borrower, uint collateralAmount, uint loanAmount,\n uint repaymentAmount, uint40 maturity);\n\n event LoanProductActiveStateChanged(uint32 productId, bool newState);\n\n event LoanProductAdded(uint32 productId);\n\n event LoanRepayed(uint loanId, address borrower);\n\n event LoanCollected(uint loanId, address indexed borrower, uint collectedCollateral,\n uint releasedCollateral, uint defaultingFee);\n\n event SystemContractsChanged(Rates newRatesContract, MonetarySupervisor newMonetarySupervisor);\n\n constructor(AugmintTokenInterface _augmintToken, MonetarySupervisor _monetarySupervisor, Rates _rates)\n public {\n augmintToken = _augmintToken;\n monetarySupervisor = _monetarySupervisor;\n rates = _rates;\n }\n\n function addLoanProduct(uint32 term, uint32 discountRate, uint32 collateralRatio, uint minDisbursedAmount,\n uint32 defaultingFeePt, bool isActive)\n external restrict(\"MonetaryBoard\") {\n\n uint _newProductId = products.push(\n LoanProduct(minDisbursedAmount, term, discountRate, collateralRatio, defaultingFeePt, isActive)\n ) - 1;\n\n uint32 newProductId = uint32(_newProductId);\n require(newProductId == _newProductId, \"productId overflow\");\n\n emit LoanProductAdded(newProductId);\n }\n\n function setLoanProductActiveState(uint32 productId, bool newState)\n external restrict (\"MonetaryBoard\") {\n require(productId < products.length, \"invalid productId\"); // next line would revert but require to emit reason\n products[productId].isActive = false;\n emit LoanProductActiveStateChanged(productId, newState);\n }\n\n function newEthBackedLoan(uint32 productId) external payable {\n require(productId < products.length, \"invalid productId\"); // next line would revert but require to emit reason\n LoanProduct storage product = products[productId];\n require(product.isActive, \"product must be in active state\"); // valid product\n\n\n // calculate loan values based on ETH sent in with Tx\n uint tokenValue = rates.convertFromWei(augmintToken.peggedSymbol(), msg.value);\n uint repaymentAmount = tokenValue.mul(product.collateralRatio).div(1000000);\n\n uint loanAmount;\n (loanAmount, ) = calculateLoanValues(product, repaymentAmount);\n\n require(loanAmount >= product.minDisbursedAmount, \"loanAmount must be >= minDisbursedAmount\");\n\n uint expiration = now.add(product.term);\n uint40 maturity = uint40(expiration);\n require(maturity == expiration, \"maturity overflow\");\n\n // Create new loan\n uint loanId = loans.push(LoanData(msg.value, repaymentAmount, msg.sender,\n productId, LoanState.Open, maturity)) - 1;\n\n // Store ref to new loan\n accountLoans[msg.sender].push(loanId);\n\n // Issue tokens and send to borrower\n monetarySupervisor.issueLoan(msg.sender, loanAmount);\n\n emit NewLoan(productId, loanId, msg.sender, msg.value, loanAmount, repaymentAmount, maturity);\n }\n\n /* repay loan, called from AugmintToken's transferAndNotify\n Flow for repaying loan:\n 1) user calls token contract's transferAndNotify loanId passed in data arg\n 2) transferAndNotify transfers tokens to the Lender contract\n 3) transferAndNotify calls Lender.transferNotification with lockProductId\n */\n // from arg is not used as we allow anyone to repay a loan:\n function transferNotification(address, uint repaymentAmount, uint loanId) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n\n _repayLoan(loanId, repaymentAmount);\n }\n\n function collect(uint[] loanIds) external {\n /* when there are a lots of loans to be collected then\n the client need to call it in batches to make sure tx won't exceed block gas limit.\n Anyone can call it - can't cause harm as it only allows to collect loans which they are defaulted\n TODO: optimise defaulting fee calculations\n */\n uint totalLoanAmountCollected;\n uint totalCollateralToCollect;\n uint totalDefaultingFee;\n for (uint i = 0; i < loanIds.length; i++) {\n require(i < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanIds[i]];\n require(loan.state == LoanState.Open, \"loan state must be Open\");\n require(now >= loan.maturity, \"current time must be later than maturity\");\n LoanProduct storage product = products[loan.productId];\n\n uint loanAmount;\n (loanAmount, ) = calculateLoanValues(product, loan.repaymentAmount);\n\n totalLoanAmountCollected = totalLoanAmountCollected.add(loanAmount);\n\n loan.state = LoanState.Collected;\n\n // send ETH collateral to augmintToken reserve\n uint defaultingFeeInToken = loan.repaymentAmount.mul(product.defaultingFeePt).div(1000000);\n uint defaultingFee = rates.convertToWei(augmintToken.peggedSymbol(), defaultingFeeInToken);\n uint targetCollection = rates.convertToWei(augmintToken.peggedSymbol(),\n loan.repaymentAmount).add(defaultingFee);\n\n uint releasedCollateral;\n if (targetCollection < loan.collateralAmount) {\n releasedCollateral = loan.collateralAmount.sub(targetCollection);\n loan.borrower.transfer(releasedCollateral);\n }\n uint collateralToCollect = loan.collateralAmount.sub(releasedCollateral);\n if (defaultingFee >= collateralToCollect) {\n defaultingFee = collateralToCollect;\n collateralToCollect = 0;\n } else {\n collateralToCollect = collateralToCollect.sub(defaultingFee);\n }\n totalDefaultingFee = totalDefaultingFee.add(defaultingFee);\n\n totalCollateralToCollect = totalCollateralToCollect.add(collateralToCollect);\n\n emit LoanCollected(loanIds[i], loan.borrower, collateralToCollect.add(defaultingFee), releasedCollateral, defaultingFee);\n }\n\n if (totalCollateralToCollect > 0) {\n address(monetarySupervisor.augmintReserves()).transfer(totalCollateralToCollect);\n }\n\n if (totalDefaultingFee > 0){\n address(augmintToken.feeAccount()).transfer(totalDefaultingFee);\n }\n\n monetarySupervisor.loanCollectionNotification(totalLoanAmountCollected);// update KPIs\n\n }\n\n /* to allow upgrade of Rates and MonetarySupervisor contracts */\n function setSystemContracts(Rates newRatesContract, MonetarySupervisor newMonetarySupervisor)\n external restrict(\"MonetaryBoard\") {\n rates = newRatesContract;\n monetarySupervisor = newMonetarySupervisor;\n emit SystemContractsChanged(newRatesContract, newMonetarySupervisor);\n }\n\n function getProductCount() external view returns (uint ct) {\n return products.length;\n }\n\n // returns CHUNK_SIZE loan products starting from some offset:\n // [ productId, minDisbursedAmount, term, discountRate, collateralRatio, defaultingFeePt, maxLoanAmount, isActive ]\n function getProducts(uint offset) external view returns (uint[8][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= products.length) { break; }\n\n LoanProduct storage product = products[offset + i];\n\n response[i] = [offset + i, product.minDisbursedAmount, product.term, product.discountRate,\n product.collateralRatio, product.defaultingFeePt,\n monetarySupervisor.getMaxLoanAmount(product.minDisbursedAmount), product.isActive ? 1 : 0 ];\n }\n }\n\n function getLoanCount() external view returns (uint ct) {\n return loans.length;\n }\n\n /* returns CHUNK_SIZE loans starting from some offset. Loans data encoded as:\n [loanId, collateralAmount, repaymentAmount, borrower, productId, state, maturity, disbursementTime,\n loanAmount, interestAmount ] */\n function getLoans(uint offset) external view returns (uint[10][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= loans.length) { break; }\n\n response[i] = getLoanTuple(offset + i);\n }\n }\n\n function getLoanCountForAddress(address borrower) external view returns (uint) {\n return accountLoans[borrower].length;\n }\n\n /* returns CHUNK_SIZE loans of a given account, starting from some offset. Loans data encoded as:\n [loanId, collateralAmount, repaymentAmount, borrower, productId, state, maturity, disbursementTime,\n loanAmount, interestAmount ] */\n function getLoansForAddress(address borrower, uint offset) external view returns (uint[10][CHUNK_SIZE] response) {\n\n uint[] storage loansForAddress = accountLoans[borrower];\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= loansForAddress.length) { break; }\n\n response[i] = getLoanTuple(loansForAddress[offset + i]);\n }\n }\n\n function getLoanTuple(uint loanId) public view returns (uint[10] result) {\n require(loanId < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanId];\n LoanProduct storage product = products[loan.productId];\n\n uint loanAmount;\n uint interestAmount;\n (loanAmount, interestAmount) = calculateLoanValues(product, loan.repaymentAmount);\n uint disbursementTime = loan.maturity - product.term;\n\n LoanState loanState =\n loan.state == LoanState.Open && now >= loan.maturity ? LoanState.Defaulted : loan.state;\n\n result = [loanId, loan.collateralAmount, loan.repaymentAmount, uint(loan.borrower),\n loan.productId, uint(loanState), loan.maturity, disbursementTime, loanAmount, interestAmount];\n }\n\n function calculateLoanValues(LoanProduct storage product, uint repaymentAmount)\n internal view returns (uint loanAmount, uint interestAmount) {\n // calculate loan values based on repayment amount\n loanAmount = repaymentAmount.mul(product.discountRate).div(1000000);\n interestAmount = loanAmount > repaymentAmount ? 0 : repaymentAmount.sub(loanAmount);\n }\n\n /* internal function, assuming repayment amount already transfered */\n function _repayLoan(uint loanId, uint repaymentAmount) internal {\n require(loanId < loans.length, \"invalid loanId\"); // next line would revert but require to emit reason\n LoanData storage loan = loans[loanId];\n require(loan.state == LoanState.Open, \"loan state must be Open\");\n require(repaymentAmount == loan.repaymentAmount, \"repaymentAmount must be equal to tokens sent\");\n require(now <= loan.maturity, \"current time must be earlier than maturity\");\n\n LoanProduct storage product = products[loan.productId];\n uint loanAmount;\n uint interestAmount;\n (loanAmount, interestAmount) = calculateLoanValues(product, loan.repaymentAmount);\n\n loans[loanId].state = LoanState.Repaid;\n\n if (interestAmount > 0) {\n augmintToken.transfer(monetarySupervisor.interestEarnedAccount(), interestAmount);\n augmintToken.burn(loanAmount);\n } else {\n // negative or zero interest (i.e. discountRate >= 0)\n augmintToken.burn(repaymentAmount);\n }\n\n monetarySupervisor.loanRepaymentNotification(loanAmount); // update KPIs\n\n loan.borrower.transfer(loan.collateralAmount); // send back ETH collateral\n\n emit LoanRepayed(loanId, loan.borrower);\n }\n\n}\n" } } } diff --git a/abiniser/deployments/4/Locker_DEPLOYS.json b/abiniser/deployments/4/Locker_DEPLOYS.json index f79cdd6b..4b58877e 100644 --- a/abiniser/deployments/4/Locker_DEPLOYS.json +++ b/abiniser/deployments/4/Locker_DEPLOYS.json @@ -37,7 +37,7 @@ } }, "66e3e89133d9bbd91baac5552f21f7e1": { - "latestDeployedAddress": "0xf98ae1fb568b267a7632bf54579a153c892e2ec2", + "latestDeployedAddress": "0xd0b6136c2e35c288a903e836feb9535954e4a9e9", "deployments": { "0xf98ae1fb568b267a7632bf54579a153c892e2ec2": { "generatedAt": "2018-04-25T12:31:29.231Z", @@ -51,6 +51,19 @@ "deployedBytecodeHash": "c88454f70e3cc7b363b425ef66ef47ca", "sourceHash": "7ffe14f90465530802dc1f5762e0217f", "source": "/* contract for tracking locked funds\n\n requirements\n -> lock funds\n -> unlock funds\n -> index locks by address\n\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/lockFlow.png\n\n TODO / think about:\n -> self-destruct function?\n\n*/\n\npragma solidity ^0.4.23;\n\nimport \"./generic/Restricted.sol\";\nimport \"./generic/SafeMath.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./MonetarySupervisor.sol\";\nimport \"./interfaces/TokenReceiver.sol\";\n\n\ncontract Locker is Restricted, TokenReceiver {\n\n using SafeMath for uint256;\n\n uint public constant CHUNK_SIZE = 100;\n\n event NewLockProduct(uint32 indexed lockProductId, uint32 perTermInterest, uint32 durationInSecs,\n uint32 minimumLockAmount, bool isActive);\n\n event LockProductActiveChange(uint32 indexed lockProductId, bool newActiveState);\n\n // NB: amountLocked includes the original amount, plus interest\n event NewLock(address indexed lockOwner, uint lockId, uint amountLocked, uint interestEarned,\n uint40 lockedUntil, uint32 perTermInterest, uint32 durationInSecs);\n\n event LockReleased(address indexed lockOwner, uint lockId);\n\n event MonetarySupervisorChanged(MonetarySupervisor newMonetarySupervisor);\n\n struct LockProduct {\n // perTermInterest is in millionths (i.e. 1,000,000 = 100%):\n uint32 perTermInterest;\n uint32 durationInSecs;\n uint32 minimumLockAmount;\n bool isActive;\n }\n\n /* NB: we don't need to store lock parameters because lockProducts can't be altered (only disabled/enabled) */\n struct Lock {\n uint amountLocked;\n address owner;\n uint32 productId;\n uint40 lockedUntil;\n bool isActive;\n }\n\n AugmintTokenInterface public augmintToken;\n MonetarySupervisor public monetarySupervisor;\n\n LockProduct[] public lockProducts;\n\n Lock[] public locks;\n\n // lock ids for an account\n mapping(address => uint[]) public accountLocks;\n\n constructor(AugmintTokenInterface _augmintToken, MonetarySupervisor _monetarySupervisor) public {\n\n augmintToken = _augmintToken;\n monetarySupervisor = _monetarySupervisor;\n\n }\n\n function addLockProduct(uint32 perTermInterest, uint32 durationInSecs, uint32 minimumLockAmount, bool isActive)\n external restrict(\"MonetaryBoard\") {\n\n uint _newLockProductId = lockProducts.push(\n LockProduct(perTermInterest, durationInSecs, minimumLockAmount, isActive)) - 1;\n uint32 newLockProductId = uint32(_newLockProductId);\n require(newLockProductId == _newLockProductId, \"lockProduct overflow\");\n emit NewLockProduct(newLockProductId, perTermInterest, durationInSecs, minimumLockAmount, isActive);\n\n }\n\n function setLockProductActiveState(uint32 lockProductId, bool isActive) external restrict(\"MonetaryBoard\") {\n // next line would revert but require to emit reason:\n require(lockProductId < lockProducts.length, \"invalid lockProductId\");\n\n lockProducts[lockProductId].isActive = isActive;\n emit LockProductActiveChange(lockProductId, isActive);\n\n }\n\n /* lock funds, called from AugmintToken's transferAndNotify\n Flow for locking tokens:\n 1) user calls token contract's transferAndNotify lockProductId passed in data arg\n 2) transferAndNotify transfers tokens to the Lock contract\n 3) transferAndNotify calls Lock.transferNotification with lockProductId\n */\n function transferNotification(address from, uint256 amountToLock, uint _lockProductId) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n // next line would revert but require to emit reason:\n require(lockProductId < lockProducts.length, \"invalid lockProductId\");\n uint32 lockProductId = uint32(_lockProductId);\n require(lockProductId == _lockProductId, \"lockProductId overflow\");\n /* TODO: make data arg generic bytes\n uint productId;\n assembly { // solhint-disable-line no-inline-assembly\n productId := mload(data)\n } */\n _createLock(lockProductId, from, amountToLock);\n }\n\n function releaseFunds(uint lockId) external {\n // next line would revert but require to emit reason:\n require(lockId < locks.length, \"invalid lockId\");\n Lock storage lock = locks[lockId];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n require(lock.isActive, \"lock must be in active state\");\n require(now >= lock.lockedUntil, \"current time must be later than lockedUntil\");\n\n lock.isActive = false;\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n monetarySupervisor.releaseFundsNotification(lock.amountLocked); // to maintain totalLockAmount\n augmintToken.transferWithNarrative(lock.owner, lock.amountLocked.add(interestEarned),\n \"Funds released from lock\");\n\n emit LockReleased(lock.owner, lockId);\n }\n\n function setMonetarySupervisor(MonetarySupervisor newMonetarySupervisor) external restrict(\"MonetaryBoard\") {\n monetarySupervisor = newMonetarySupervisor;\n emit MonetarySupervisorChanged(newMonetarySupervisor);\n }\n\n function getLockProductCount() external view returns (uint) {\n\n return lockProducts.length;\n\n }\n\n // returns 20 lock products starting from some offset\n // lock products are encoded as [ perTermInterest, durationInSecs, minimumLockAmount, maxLockAmount, isActive ]\n function getLockProducts(uint offset) external view returns (uint[5][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= lockProducts.length) { break; }\n\n LockProduct storage lockProduct = lockProducts[offset + i];\n\n response[i] = [ lockProduct.perTermInterest, lockProduct.durationInSecs, lockProduct.minimumLockAmount,\n monetarySupervisor.getMaxLockAmount(lockProduct.minimumLockAmount, lockProduct.perTermInterest),\n lockProduct.isActive ? 1 : 0 ];\n }\n }\n\n function getLockCount() external view returns (uint) {\n return locks.length;\n }\n\n function getLockCountForAddress(address lockOwner) external view returns (uint) {\n return accountLocks[lockOwner].length;\n }\n\n // returns CHUNK_SIZE locks starting from some offset\n // lock products are encoded as\n // [lockId, owner, amountLocked, interestEarned, lockedUntil, perTermInterest, durationInSecs, isActive ]\n // NB: perTermInterest is in millionths (i.e. 1,000,000 = 100%):\n function getLocks(uint offset) external view returns (uint[8][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= locks.length) { break; }\n\n Lock storage lock = locks[offset + i];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n response[i] = [uint(offset + i), uint(lock.owner), lock.amountLocked, interestEarned, lock.lockedUntil,\n lockProduct.perTermInterest, lockProduct.durationInSecs, lock.isActive ? 1 : 0];\n }\n }\n\n // returns CHUNK_SIZE locks of a given account, starting from some offset\n // lock products are encoded as\n // [lockId, amountLocked, interestEarned, lockedUntil, perTermInterest, durationInSecs, isActive ]\n function getLocksForAddress(address lockOwner, uint offset) external view returns (uint[7][CHUNK_SIZE] response) {\n\n uint[] storage locksForAddress = accountLocks[lockOwner];\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= locksForAddress.length) { break; }\n\n Lock storage lock = locks[locksForAddress[offset + i]];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n response[i] = [ locksForAddress[offset + i], lock.amountLocked, interestEarned, lock.lockedUntil,\n lockProduct.perTermInterest, lockProduct.durationInSecs, lock.isActive ? 1 : 0 ];\n }\n }\n\n function calculateInterest(uint32 perTermInterest, uint amountToLock) public pure returns (uint interestEarned) {\n interestEarned = amountToLock.mul(perTermInterest).div(1000000);\n }\n\n // Internal function. assumes amountToLock is already transferred to this Lock contract\n function _createLock(uint32 lockProductId, address lockOwner, uint amountToLock) internal returns(uint lockId) {\n LockProduct storage lockProduct = lockProducts[lockProductId];\n require(lockProduct.isActive, \"lockProduct must be in active state\");\n require(amountToLock >= lockProduct.minimumLockAmount, \"amountToLock must be >= minimumLockAmount\");\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, amountToLock);\n uint expiration = now.add(lockProduct.durationInSecs);\n uint40 lockedUntil = uint40(expiration);\n require(lockedUntil == expiration, \"lockedUntil overflow\");\n\n lockId = locks.push(Lock(amountToLock, lockOwner, lockProductId, lockedUntil, true)) - 1;\n accountLocks[lockOwner].push(lockId);\n\n monetarySupervisor.requestInterest(amountToLock, interestEarned); // update KPIs & transfer interest here\n\n emit NewLock(lockOwner, lockId, amountToLock, interestEarned, lockedUntil, lockProduct.perTermInterest,\n lockProduct.durationInSecs);\n }\n\n}\n" + }, + "0xd0b6136c2e35c288a903e836feb9535954e4a9e9": { + "generatedAt": "2018-05-12T01:34:38.533Z", + "truffleContractFileUpdatedAt": "2018-05-12T01:30:50.619Z", + "deployTransactionHash": "0x827346689bfd341aaa1020c44d18f77943fd67afe095aa0a2c2eefe809e78a22", + "compiler": { + "name": "solc", + "version": "0.4.23+commit.124ca40d.Emscripten.clang" + }, + "bytecodeHash": "c6c9a4350153bfd4b81eaf228df169f4", + "deployedBytecodeHash": "878366e51dfa79329645837646563469", + "sourceHash": "7ffe14f90465530802dc1f5762e0217f", + "source": "/* contract for tracking locked funds\n\n requirements\n -> lock funds\n -> unlock funds\n -> index locks by address\n\n For flows see: https://github.com/Augmint/augmint-contracts/blob/master/docs/lockFlow.png\n\n TODO / think about:\n -> self-destruct function?\n\n*/\n\npragma solidity ^0.4.23;\n\nimport \"./generic/Restricted.sol\";\nimport \"./generic/SafeMath.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./MonetarySupervisor.sol\";\nimport \"./interfaces/TokenReceiver.sol\";\n\n\ncontract Locker is Restricted, TokenReceiver {\n\n using SafeMath for uint256;\n\n uint public constant CHUNK_SIZE = 100;\n\n event NewLockProduct(uint32 indexed lockProductId, uint32 perTermInterest, uint32 durationInSecs,\n uint32 minimumLockAmount, bool isActive);\n\n event LockProductActiveChange(uint32 indexed lockProductId, bool newActiveState);\n\n // NB: amountLocked includes the original amount, plus interest\n event NewLock(address indexed lockOwner, uint lockId, uint amountLocked, uint interestEarned,\n uint40 lockedUntil, uint32 perTermInterest, uint32 durationInSecs);\n\n event LockReleased(address indexed lockOwner, uint lockId);\n\n event MonetarySupervisorChanged(MonetarySupervisor newMonetarySupervisor);\n\n struct LockProduct {\n // perTermInterest is in millionths (i.e. 1,000,000 = 100%):\n uint32 perTermInterest;\n uint32 durationInSecs;\n uint32 minimumLockAmount;\n bool isActive;\n }\n\n /* NB: we don't need to store lock parameters because lockProducts can't be altered (only disabled/enabled) */\n struct Lock {\n uint amountLocked;\n address owner;\n uint32 productId;\n uint40 lockedUntil;\n bool isActive;\n }\n\n AugmintTokenInterface public augmintToken;\n MonetarySupervisor public monetarySupervisor;\n\n LockProduct[] public lockProducts;\n\n Lock[] public locks;\n\n // lock ids for an account\n mapping(address => uint[]) public accountLocks;\n\n constructor(AugmintTokenInterface _augmintToken, MonetarySupervisor _monetarySupervisor) public {\n\n augmintToken = _augmintToken;\n monetarySupervisor = _monetarySupervisor;\n\n }\n\n function addLockProduct(uint32 perTermInterest, uint32 durationInSecs, uint32 minimumLockAmount, bool isActive)\n external restrict(\"MonetaryBoard\") {\n\n uint _newLockProductId = lockProducts.push(\n LockProduct(perTermInterest, durationInSecs, minimumLockAmount, isActive)) - 1;\n uint32 newLockProductId = uint32(_newLockProductId);\n require(newLockProductId == _newLockProductId, \"lockProduct overflow\");\n emit NewLockProduct(newLockProductId, perTermInterest, durationInSecs, minimumLockAmount, isActive);\n\n }\n\n function setLockProductActiveState(uint32 lockProductId, bool isActive) external restrict(\"MonetaryBoard\") {\n // next line would revert but require to emit reason:\n require(lockProductId < lockProducts.length, \"invalid lockProductId\");\n\n lockProducts[lockProductId].isActive = isActive;\n emit LockProductActiveChange(lockProductId, isActive);\n\n }\n\n /* lock funds, called from AugmintToken's transferAndNotify\n Flow for locking tokens:\n 1) user calls token contract's transferAndNotify lockProductId passed in data arg\n 2) transferAndNotify transfers tokens to the Lock contract\n 3) transferAndNotify calls Lock.transferNotification with lockProductId\n */\n function transferNotification(address from, uint256 amountToLock, uint _lockProductId) external {\n require(msg.sender == address(augmintToken), \"msg.sender must be augmintToken\");\n // next line would revert but require to emit reason:\n require(lockProductId < lockProducts.length, \"invalid lockProductId\");\n uint32 lockProductId = uint32(_lockProductId);\n require(lockProductId == _lockProductId, \"lockProductId overflow\");\n /* TODO: make data arg generic bytes\n uint productId;\n assembly { // solhint-disable-line no-inline-assembly\n productId := mload(data)\n } */\n _createLock(lockProductId, from, amountToLock);\n }\n\n function releaseFunds(uint lockId) external {\n // next line would revert but require to emit reason:\n require(lockId < locks.length, \"invalid lockId\");\n Lock storage lock = locks[lockId];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n require(lock.isActive, \"lock must be in active state\");\n require(now >= lock.lockedUntil, \"current time must be later than lockedUntil\");\n\n lock.isActive = false;\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n monetarySupervisor.releaseFundsNotification(lock.amountLocked); // to maintain totalLockAmount\n augmintToken.transferWithNarrative(lock.owner, lock.amountLocked.add(interestEarned),\n \"Funds released from lock\");\n\n emit LockReleased(lock.owner, lockId);\n }\n\n function setMonetarySupervisor(MonetarySupervisor newMonetarySupervisor) external restrict(\"MonetaryBoard\") {\n monetarySupervisor = newMonetarySupervisor;\n emit MonetarySupervisorChanged(newMonetarySupervisor);\n }\n\n function getLockProductCount() external view returns (uint) {\n\n return lockProducts.length;\n\n }\n\n // returns 20 lock products starting from some offset\n // lock products are encoded as [ perTermInterest, durationInSecs, minimumLockAmount, maxLockAmount, isActive ]\n function getLockProducts(uint offset) external view returns (uint[5][CHUNK_SIZE] response) {\n for (uint8 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= lockProducts.length) { break; }\n\n LockProduct storage lockProduct = lockProducts[offset + i];\n\n response[i] = [ lockProduct.perTermInterest, lockProduct.durationInSecs, lockProduct.minimumLockAmount,\n monetarySupervisor.getMaxLockAmount(lockProduct.minimumLockAmount, lockProduct.perTermInterest),\n lockProduct.isActive ? 1 : 0 ];\n }\n }\n\n function getLockCount() external view returns (uint) {\n return locks.length;\n }\n\n function getLockCountForAddress(address lockOwner) external view returns (uint) {\n return accountLocks[lockOwner].length;\n }\n\n // returns CHUNK_SIZE locks starting from some offset\n // lock products are encoded as\n // [lockId, owner, amountLocked, interestEarned, lockedUntil, perTermInterest, durationInSecs, isActive ]\n // NB: perTermInterest is in millionths (i.e. 1,000,000 = 100%):\n function getLocks(uint offset) external view returns (uint[8][CHUNK_SIZE] response) {\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= locks.length) { break; }\n\n Lock storage lock = locks[offset + i];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n response[i] = [uint(offset + i), uint(lock.owner), lock.amountLocked, interestEarned, lock.lockedUntil,\n lockProduct.perTermInterest, lockProduct.durationInSecs, lock.isActive ? 1 : 0];\n }\n }\n\n // returns CHUNK_SIZE locks of a given account, starting from some offset\n // lock products are encoded as\n // [lockId, amountLocked, interestEarned, lockedUntil, perTermInterest, durationInSecs, isActive ]\n function getLocksForAddress(address lockOwner, uint offset) external view returns (uint[7][CHUNK_SIZE] response) {\n\n uint[] storage locksForAddress = accountLocks[lockOwner];\n\n for (uint16 i = 0; i < CHUNK_SIZE; i++) {\n\n if (offset + i >= locksForAddress.length) { break; }\n\n Lock storage lock = locks[locksForAddress[offset + i]];\n LockProduct storage lockProduct = lockProducts[lock.productId];\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, lock.amountLocked);\n\n response[i] = [ locksForAddress[offset + i], lock.amountLocked, interestEarned, lock.lockedUntil,\n lockProduct.perTermInterest, lockProduct.durationInSecs, lock.isActive ? 1 : 0 ];\n }\n }\n\n function calculateInterest(uint32 perTermInterest, uint amountToLock) public pure returns (uint interestEarned) {\n interestEarned = amountToLock.mul(perTermInterest).div(1000000);\n }\n\n // Internal function. assumes amountToLock is already transferred to this Lock contract\n function _createLock(uint32 lockProductId, address lockOwner, uint amountToLock) internal returns(uint lockId) {\n LockProduct storage lockProduct = lockProducts[lockProductId];\n require(lockProduct.isActive, \"lockProduct must be in active state\");\n require(amountToLock >= lockProduct.minimumLockAmount, \"amountToLock must be >= minimumLockAmount\");\n\n uint interestEarned = calculateInterest(lockProduct.perTermInterest, amountToLock);\n uint expiration = now.add(lockProduct.durationInSecs);\n uint40 lockedUntil = uint40(expiration);\n require(lockedUntil == expiration, \"lockedUntil overflow\");\n\n lockId = locks.push(Lock(amountToLock, lockOwner, lockProductId, lockedUntil, true)) - 1;\n accountLocks[lockOwner].push(lockId);\n\n monetarySupervisor.requestInterest(amountToLock, interestEarned); // update KPIs & transfer interest here\n\n emit NewLock(lockOwner, lockId, amountToLock, interestEarned, lockedUntil, lockProduct.perTermInterest,\n lockProduct.durationInSecs);\n }\n\n}\n" } } } diff --git a/abiniser/deployments/4/MonetarySupervisor_DEPLOYS.json b/abiniser/deployments/4/MonetarySupervisor_DEPLOYS.json index 01121587..b1e0b4bf 100644 --- a/abiniser/deployments/4/MonetarySupervisor_DEPLOYS.json +++ b/abiniser/deployments/4/MonetarySupervisor_DEPLOYS.json @@ -32,7 +32,7 @@ } }, "a552ee1f90ae83cb91d07311ae8eab1e": { - "latestDeployedAddress": "0xa00a5d1882c3f690e3d0d975ebe378120b70ae87", + "latestDeployedAddress": "0xc19a45f5cbfa93be512ef07177feb3f7b3ae4518", "deployments": { "0x2e8b07a973f8e136aa39922dff21ad187a6e8e7d": { "generatedAt": "2018-04-25T12:31:29.126Z", @@ -59,6 +59,19 @@ "deployedBytecodeHash": "afc07e949d0fc0522760e21001e6442e", "sourceHash": "cbd67b35e74bbbc9ef5a78c3180eb002", "source": "/* MonetarySupervisor\n - maintains system wide KPIs (eg totalLockAmount, totalLoanAmount)\n - holds system wide parameters/limits\n - enforces system wide limits\n - burns and issues to AugmintReserves\n - Send funds from reserve to exchange when intervening (not implemented yet)\n - Converts older versions of AugmintTokens in 1:1 to new\n\n TODO:\n - Mcreate and use MonetarySupervisorInterface?\n - create and use InterestEarnedAccount interface ?\n\n*/\n\npragma solidity ^0.4.23;\nimport \"./generic/SafeMath.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./interfaces/TokenReceiver.sol\";\nimport \"./InterestEarnedAccount.sol\";\nimport \"./AugmintReserves.sol\";\n\n\ncontract MonetarySupervisor is Restricted, TokenReceiver { // solhint-disable-line no-empty-blocks\n using SafeMath for uint256;\n\n uint public constant PERCENT_100 = 1000000;\n\n AugmintTokenInterface public augmintToken;\n InterestEarnedAccount public interestEarnedAccount;\n AugmintReserves public augmintReserves;\n\n uint public issuedByMonetaryBoard; // supply issued manually by monetary board\n\n uint public totalLoanAmount; // total amount of all loans without interest, in token\n uint public totalLockedAmount; // total amount of all locks without premium, in token\n\n /**********\n Parameters to ensure totalLoanAmount or totalLockedAmount difference is within limits and system also works\n when total loan or lock amounts are low.\n for test calculations: https://docs.google.com/spreadsheets/d/1MeWYPYZRIm1n9lzpvbq8kLfQg1hhvk5oJY6NrR401S0\n **********/\n struct LtdParams {\n uint lockDifferenceLimit; /* only allow a new lock if Loan To Deposit ratio would stay above\n (1 - lockDifferenceLimit) with new lock. Stored as parts per million */\n uint loanDifferenceLimit; /* only allow a new loan if Loan To Deposit ratio would stay above\n (1 + loanDifferenceLimit) with new loan. Stored as parts per million */\n /* allowedDifferenceAmount param is to ensure the system is not \"freezing\" when totalLoanAmount or\n totalLockAmount is low.\n It allows a new loan or lock (up to an amount to reach this difference) even if LTD will go below / above\n lockDifferenceLimit / loanDifferenceLimit with the new lock/loan */\n uint allowedDifferenceAmount;\n }\n\n LtdParams public ltdParams;\n\n /* Previously deployed AugmintTokens which are accepted for conversion (see transferNotification() )\n NB: it's not iterable so old version addresses needs to be added for UI manually after each deploy */\n mapping(address => bool) public acceptedLegacyAugmintTokens;\n\n event LtdParamsChanged(uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount);\n\n event AcceptedLegacyAugmintTokenChanged(address augmintTokenAddress, bool newAcceptedState);\n\n event LegacyTokenConverted(address oldTokenAddress, address account, uint amount);\n\n event KPIsAdjusted(uint totalLoanAmountAdjustment, uint totalLockedAmountAdjustment);\n\n event SystemContractsChanged(InterestEarnedAccount newInterestEarnedAccount, AugmintReserves newAugmintReserves);\n\n constructor(AugmintTokenInterface _augmintToken, AugmintReserves _augmintReserves,\n InterestEarnedAccount _interestEarnedAccount,\n uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount) public {\n augmintToken = _augmintToken;\n augmintReserves = _augmintReserves;\n interestEarnedAccount = _interestEarnedAccount;\n\n ltdParams = LtdParams(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n }\n\n function issueToReserve(uint amount) external restrict(\"MonetaryBoard\") {\n issuedByMonetaryBoard = issuedByMonetaryBoard.add(amount);\n augmintToken.issueTo(augmintReserves, amount);\n }\n\n function burnFromReserve(uint amount) external restrict(\"MonetaryBoard\") {\n issuedByMonetaryBoard = issuedByMonetaryBoard.sub(amount);\n augmintReserves.burn(augmintToken, amount);\n }\n\n /* Locker requesting interest when locking funds. Enforcing LTD to stay within range allowed by LTD params\n NB: it does not know about min loan amount, it's the loan contract's responsibility to enforce it */\n function requestInterest(uint amountToLock, uint interestAmount) external {\n // only whitelisted LockerContracts\n require(permissions[msg.sender][\"LockerContracts\"], \"msg.sender must have LockerContracts permission\");\n require(amountToLock <= getMaxLockAmountAllowedByLtd(), \"amountToLock must be <= maxLockAmountAllowedByLtd\");\n\n totalLockedAmount = totalLockedAmount.add(amountToLock);\n // next line would revert but require to emit reason:\n require(augmintToken.balanceOf(address(interestEarnedAccount)) >= interestAmount,\n \"interestEarnedAccount balance must be >= interestAmount\");\n interestEarnedAccount.transferInterest(augmintToken, msg.sender, interestAmount); // transfer interest to Locker\n }\n\n // Locker notifying when releasing funds to update KPIs\n function releaseFundsNotification(uint lockedAmount) external {\n // only whitelisted LockerContracts\n require(permissions[msg.sender][\"LockerContracts\"], \"msg.sender must have LockerContracts permission\");\n totalLockedAmount = totalLockedAmount.sub(lockedAmount);\n }\n\n /* Issue loan if LTD stays within range allowed by LTD params\n NB: it does not know about min loan amount, it's the loan contract's responsibility to enforce it */\n function issueLoan(address borrower, uint loanAmount) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n require(loanAmount <= getMaxLoanAmountAllowedByLtd(), \"loanAmount must be <= maxLoanAmountAllowedByLtd\");\n totalLoanAmount = totalLoanAmount.add(loanAmount);\n augmintToken.issueTo(borrower, loanAmount);\n }\n\n function loanRepaymentNotification(uint loanAmount) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n totalLoanAmount = totalLoanAmount.sub(loanAmount);\n }\n\n // NB: this is called by Lender contract with the sum of all loans collected in batch\n function loanCollectionNotification(uint totalLoanAmountCollected) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n totalLoanAmount = totalLoanAmount.sub(totalLoanAmountCollected);\n }\n\n function setAcceptedLegacyAugmintToken(address legacyAugmintTokenAddress, bool newAcceptedState)\n external restrict(\"MonetaryBoard\") {\n acceptedLegacyAugmintTokens[legacyAugmintTokenAddress] = newAcceptedState;\n emit AcceptedLegacyAugmintTokenChanged(legacyAugmintTokenAddress, newAcceptedState);\n }\n\n function setLtdParams(uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount)\n external restrict(\"MonetaryBoard\") {\n ltdParams = LtdParams(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n\n emit LtdParamsChanged(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n }\n\n /* function to migrate old totalLoanAmount and totalLockedAmount from old monetarySupervisor contract\n when it's upgraded.\n Set new monetarySupervisor contract in all locker and loanManager contracts before executing this */\n function adjustKPIs(uint totalLoanAmountAdjustment, uint totalLockedAmountAdjustment)\n external restrict(\"MonetaryBoard\") {\n totalLoanAmount = totalLoanAmount.add(totalLoanAmountAdjustment);\n totalLockedAmount = totalLockedAmount.add(totalLockedAmountAdjustment);\n\n emit KPIsAdjusted(totalLoanAmountAdjustment, totalLockedAmountAdjustment);\n }\n\n /* to allow upgrades of InterestEarnedAccount and AugmintReserves contracts. */\n function setSystemContracts(InterestEarnedAccount newInterestEarnedAccount, AugmintReserves newAugmintReserves)\n external restrict(\"MonetaryBoard\") {\n interestEarnedAccount = newInterestEarnedAccount;\n augmintReserves = newAugmintReserves;\n emit SystemContractsChanged(newInterestEarnedAccount, newAugmintReserves);\n }\n\n /* User can request to convert their tokens from older AugmintToken versions in 1:1\n transferNotification is called from AugmintToken's transferAndNotify\n Flow for converting old tokens:\n 1) user calls old token contract's transferAndNotify with the amount to convert,\n addressing the new MonetarySupervisor Contract\n 2) transferAndNotify transfers user's old tokens to the current MonetarySupervisor contract's address\n 3) transferAndNotify calls MonetarySupervisor.transferNotification\n 4) MonetarySupervisor checks if old AugmintToken is permitted\n 5) MonetarySupervisor issues new tokens to user's account in current AugmintToken\n 6) MonetarySupervisor burns old tokens from own balance\n */\n function transferNotification(address from, uint amount, uint /* data, not used */ ) external {\n AugmintTokenInterface legacyToken = AugmintTokenInterface(msg.sender);\n require(acceptedLegacyAugmintTokens[legacyToken], \"msg.sender must be allowed in acceptedLegacyAugmintTokens\");\n\n legacyToken.burn(amount);\n augmintToken.issueTo(from, amount);\n emit LegacyTokenConverted(msg.sender, from, amount);\n }\n\n function getLoanToDepositRatio() external view returns (uint loanToDepositRatio) {\n loanToDepositRatio = totalLockedAmount == 0 ? 0 : totalLockedAmount.mul(PERCENT_100).div(totalLoanAmount);\n }\n\n /* Helper function for UI.\n Returns max lock amount based on minLockAmount, interestPt, using LTD params & interestEarnedAccount balance */\n function getMaxLockAmount(uint minLockAmount, uint interestPt) external view returns (uint maxLock) {\n uint allowedByEarning = augmintToken.balanceOf(address(interestEarnedAccount)).mul(PERCENT_100).div(interestPt);\n uint allowedByLtd = getMaxLockAmountAllowedByLtd();\n maxLock = allowedByEarning < allowedByLtd ? allowedByEarning : allowedByLtd;\n maxLock = maxLock < minLockAmount ? 0 : maxLock;\n }\n\n /* Helper function for UI.\n Returns max loan amount based on minLoanAmont using LTD params */\n function getMaxLoanAmount(uint minLoanAmount) external view returns (uint maxLoan) {\n uint allowedByLtd = getMaxLoanAmountAllowedByLtd();\n maxLoan = allowedByLtd < minLoanAmount ? 0 : allowedByLtd;\n }\n\n /* returns maximum lockable token amount allowed by LTD params. */\n function getMaxLockAmountAllowedByLtd() public view returns(uint maxLockByLtd) {\n uint allowedByLtdDifferencePt = totalLoanAmount.mul(PERCENT_100).div(PERCENT_100\n .sub(ltdParams.lockDifferenceLimit));\n allowedByLtdDifferencePt = totalLockedAmount >= allowedByLtdDifferencePt ?\n 0 : allowedByLtdDifferencePt.sub(totalLockedAmount);\n\n uint allowedByLtdDifferenceAmount =\n totalLockedAmount >= totalLoanAmount.add(ltdParams.allowedDifferenceAmount) ?\n 0 : totalLoanAmount.add(ltdParams.allowedDifferenceAmount).sub(totalLockedAmount);\n\n maxLockByLtd = allowedByLtdDifferencePt > allowedByLtdDifferenceAmount ?\n allowedByLtdDifferencePt : allowedByLtdDifferenceAmount;\n }\n\n /* returns maximum borrowable token amount allowed by LTD params */\n function getMaxLoanAmountAllowedByLtd() public view returns(uint maxLoanByLtd) {\n uint allowedByLtdDifferencePt = totalLockedAmount.mul(ltdParams.loanDifferenceLimit.add(PERCENT_100))\n .div(PERCENT_100);\n allowedByLtdDifferencePt = totalLoanAmount >= allowedByLtdDifferencePt ?\n 0 : allowedByLtdDifferencePt.sub(totalLoanAmount);\n\n uint allowedByLtdDifferenceAmount =\n totalLoanAmount >= totalLockedAmount.add(ltdParams.allowedDifferenceAmount) ?\n 0 : totalLockedAmount.add(ltdParams.allowedDifferenceAmount).sub(totalLoanAmount);\n\n maxLoanByLtd = allowedByLtdDifferencePt > allowedByLtdDifferenceAmount ?\n allowedByLtdDifferencePt : allowedByLtdDifferenceAmount;\n }\n\n}\n" + }, + "0xc19a45f5cbfa93be512ef07177feb3f7b3ae4518": { + "generatedAt": "2018-05-12T01:34:38.474Z", + "truffleContractFileUpdatedAt": "2018-05-12T01:30:50.663Z", + "deployTransactionHash": "0x1dc6702b64f4edcba0201b1c4e49c47fbbbbaab7788ed37ee104e6bb3df3b21c", + "compiler": { + "name": "solc", + "version": "0.4.23+commit.124ca40d.Emscripten.clang" + }, + "bytecodeHash": "83f4ac731042d988dad02af18401f3f3", + "deployedBytecodeHash": "6356e4110fb4cbff5b57908614a63219", + "sourceHash": "cbd67b35e74bbbc9ef5a78c3180eb002", + "source": "/* MonetarySupervisor\n - maintains system wide KPIs (eg totalLockAmount, totalLoanAmount)\n - holds system wide parameters/limits\n - enforces system wide limits\n - burns and issues to AugmintReserves\n - Send funds from reserve to exchange when intervening (not implemented yet)\n - Converts older versions of AugmintTokens in 1:1 to new\n\n TODO:\n - Mcreate and use MonetarySupervisorInterface?\n - create and use InterestEarnedAccount interface ?\n\n*/\n\npragma solidity ^0.4.23;\nimport \"./generic/SafeMath.sol\";\nimport \"./generic/Restricted.sol\";\nimport \"./interfaces/AugmintTokenInterface.sol\";\nimport \"./interfaces/TokenReceiver.sol\";\nimport \"./InterestEarnedAccount.sol\";\nimport \"./AugmintReserves.sol\";\n\n\ncontract MonetarySupervisor is Restricted, TokenReceiver { // solhint-disable-line no-empty-blocks\n using SafeMath for uint256;\n\n uint public constant PERCENT_100 = 1000000;\n\n AugmintTokenInterface public augmintToken;\n InterestEarnedAccount public interestEarnedAccount;\n AugmintReserves public augmintReserves;\n\n uint public issuedByMonetaryBoard; // supply issued manually by monetary board\n\n uint public totalLoanAmount; // total amount of all loans without interest, in token\n uint public totalLockedAmount; // total amount of all locks without premium, in token\n\n /**********\n Parameters to ensure totalLoanAmount or totalLockedAmount difference is within limits and system also works\n when total loan or lock amounts are low.\n for test calculations: https://docs.google.com/spreadsheets/d/1MeWYPYZRIm1n9lzpvbq8kLfQg1hhvk5oJY6NrR401S0\n **********/\n struct LtdParams {\n uint lockDifferenceLimit; /* only allow a new lock if Loan To Deposit ratio would stay above\n (1 - lockDifferenceLimit) with new lock. Stored as parts per million */\n uint loanDifferenceLimit; /* only allow a new loan if Loan To Deposit ratio would stay above\n (1 + loanDifferenceLimit) with new loan. Stored as parts per million */\n /* allowedDifferenceAmount param is to ensure the system is not \"freezing\" when totalLoanAmount or\n totalLockAmount is low.\n It allows a new loan or lock (up to an amount to reach this difference) even if LTD will go below / above\n lockDifferenceLimit / loanDifferenceLimit with the new lock/loan */\n uint allowedDifferenceAmount;\n }\n\n LtdParams public ltdParams;\n\n /* Previously deployed AugmintTokens which are accepted for conversion (see transferNotification() )\n NB: it's not iterable so old version addresses needs to be added for UI manually after each deploy */\n mapping(address => bool) public acceptedLegacyAugmintTokens;\n\n event LtdParamsChanged(uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount);\n\n event AcceptedLegacyAugmintTokenChanged(address augmintTokenAddress, bool newAcceptedState);\n\n event LegacyTokenConverted(address oldTokenAddress, address account, uint amount);\n\n event KPIsAdjusted(uint totalLoanAmountAdjustment, uint totalLockedAmountAdjustment);\n\n event SystemContractsChanged(InterestEarnedAccount newInterestEarnedAccount, AugmintReserves newAugmintReserves);\n\n constructor(AugmintTokenInterface _augmintToken, AugmintReserves _augmintReserves,\n InterestEarnedAccount _interestEarnedAccount,\n uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount) public {\n augmintToken = _augmintToken;\n augmintReserves = _augmintReserves;\n interestEarnedAccount = _interestEarnedAccount;\n\n ltdParams = LtdParams(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n }\n\n function issueToReserve(uint amount) external restrict(\"MonetaryBoard\") {\n issuedByMonetaryBoard = issuedByMonetaryBoard.add(amount);\n augmintToken.issueTo(augmintReserves, amount);\n }\n\n function burnFromReserve(uint amount) external restrict(\"MonetaryBoard\") {\n issuedByMonetaryBoard = issuedByMonetaryBoard.sub(amount);\n augmintReserves.burn(augmintToken, amount);\n }\n\n /* Locker requesting interest when locking funds. Enforcing LTD to stay within range allowed by LTD params\n NB: it does not know about min loan amount, it's the loan contract's responsibility to enforce it */\n function requestInterest(uint amountToLock, uint interestAmount) external {\n // only whitelisted LockerContracts\n require(permissions[msg.sender][\"LockerContracts\"], \"msg.sender must have LockerContracts permission\");\n require(amountToLock <= getMaxLockAmountAllowedByLtd(), \"amountToLock must be <= maxLockAmountAllowedByLtd\");\n\n totalLockedAmount = totalLockedAmount.add(amountToLock);\n // next line would revert but require to emit reason:\n require(augmintToken.balanceOf(address(interestEarnedAccount)) >= interestAmount,\n \"interestEarnedAccount balance must be >= interestAmount\");\n interestEarnedAccount.transferInterest(augmintToken, msg.sender, interestAmount); // transfer interest to Locker\n }\n\n // Locker notifying when releasing funds to update KPIs\n function releaseFundsNotification(uint lockedAmount) external {\n // only whitelisted LockerContracts\n require(permissions[msg.sender][\"LockerContracts\"], \"msg.sender must have LockerContracts permission\");\n totalLockedAmount = totalLockedAmount.sub(lockedAmount);\n }\n\n /* Issue loan if LTD stays within range allowed by LTD params\n NB: it does not know about min loan amount, it's the loan contract's responsibility to enforce it */\n function issueLoan(address borrower, uint loanAmount) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n require(loanAmount <= getMaxLoanAmountAllowedByLtd(), \"loanAmount must be <= maxLoanAmountAllowedByLtd\");\n totalLoanAmount = totalLoanAmount.add(loanAmount);\n augmintToken.issueTo(borrower, loanAmount);\n }\n\n function loanRepaymentNotification(uint loanAmount) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n totalLoanAmount = totalLoanAmount.sub(loanAmount);\n }\n\n // NB: this is called by Lender contract with the sum of all loans collected in batch\n function loanCollectionNotification(uint totalLoanAmountCollected) external {\n // only whitelisted LoanManager contracts\n require(permissions[msg.sender][\"LoanManagerContracts\"],\n \"msg.sender must have LoanManagerContracts permission\");\n totalLoanAmount = totalLoanAmount.sub(totalLoanAmountCollected);\n }\n\n function setAcceptedLegacyAugmintToken(address legacyAugmintTokenAddress, bool newAcceptedState)\n external restrict(\"MonetaryBoard\") {\n acceptedLegacyAugmintTokens[legacyAugmintTokenAddress] = newAcceptedState;\n emit AcceptedLegacyAugmintTokenChanged(legacyAugmintTokenAddress, newAcceptedState);\n }\n\n function setLtdParams(uint lockDifferenceLimit, uint loanDifferenceLimit, uint allowedDifferenceAmount)\n external restrict(\"MonetaryBoard\") {\n ltdParams = LtdParams(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n\n emit LtdParamsChanged(lockDifferenceLimit, loanDifferenceLimit, allowedDifferenceAmount);\n }\n\n /* function to migrate old totalLoanAmount and totalLockedAmount from old monetarySupervisor contract\n when it's upgraded.\n Set new monetarySupervisor contract in all locker and loanManager contracts before executing this */\n function adjustKPIs(uint totalLoanAmountAdjustment, uint totalLockedAmountAdjustment)\n external restrict(\"MonetaryBoard\") {\n totalLoanAmount = totalLoanAmount.add(totalLoanAmountAdjustment);\n totalLockedAmount = totalLockedAmount.add(totalLockedAmountAdjustment);\n\n emit KPIsAdjusted(totalLoanAmountAdjustment, totalLockedAmountAdjustment);\n }\n\n /* to allow upgrades of InterestEarnedAccount and AugmintReserves contracts. */\n function setSystemContracts(InterestEarnedAccount newInterestEarnedAccount, AugmintReserves newAugmintReserves)\n external restrict(\"MonetaryBoard\") {\n interestEarnedAccount = newInterestEarnedAccount;\n augmintReserves = newAugmintReserves;\n emit SystemContractsChanged(newInterestEarnedAccount, newAugmintReserves);\n }\n\n /* User can request to convert their tokens from older AugmintToken versions in 1:1\n transferNotification is called from AugmintToken's transferAndNotify\n Flow for converting old tokens:\n 1) user calls old token contract's transferAndNotify with the amount to convert,\n addressing the new MonetarySupervisor Contract\n 2) transferAndNotify transfers user's old tokens to the current MonetarySupervisor contract's address\n 3) transferAndNotify calls MonetarySupervisor.transferNotification\n 4) MonetarySupervisor checks if old AugmintToken is permitted\n 5) MonetarySupervisor issues new tokens to user's account in current AugmintToken\n 6) MonetarySupervisor burns old tokens from own balance\n */\n function transferNotification(address from, uint amount, uint /* data, not used */ ) external {\n AugmintTokenInterface legacyToken = AugmintTokenInterface(msg.sender);\n require(acceptedLegacyAugmintTokens[legacyToken], \"msg.sender must be allowed in acceptedLegacyAugmintTokens\");\n\n legacyToken.burn(amount);\n augmintToken.issueTo(from, amount);\n emit LegacyTokenConverted(msg.sender, from, amount);\n }\n\n function getLoanToDepositRatio() external view returns (uint loanToDepositRatio) {\n loanToDepositRatio = totalLockedAmount == 0 ? 0 : totalLockedAmount.mul(PERCENT_100).div(totalLoanAmount);\n }\n\n /* Helper function for UI.\n Returns max lock amount based on minLockAmount, interestPt, using LTD params & interestEarnedAccount balance */\n function getMaxLockAmount(uint minLockAmount, uint interestPt) external view returns (uint maxLock) {\n uint allowedByEarning = augmintToken.balanceOf(address(interestEarnedAccount)).mul(PERCENT_100).div(interestPt);\n uint allowedByLtd = getMaxLockAmountAllowedByLtd();\n maxLock = allowedByEarning < allowedByLtd ? allowedByEarning : allowedByLtd;\n maxLock = maxLock < minLockAmount ? 0 : maxLock;\n }\n\n /* Helper function for UI.\n Returns max loan amount based on minLoanAmont using LTD params */\n function getMaxLoanAmount(uint minLoanAmount) external view returns (uint maxLoan) {\n uint allowedByLtd = getMaxLoanAmountAllowedByLtd();\n maxLoan = allowedByLtd < minLoanAmount ? 0 : allowedByLtd;\n }\n\n /* returns maximum lockable token amount allowed by LTD params. */\n function getMaxLockAmountAllowedByLtd() public view returns(uint maxLockByLtd) {\n uint allowedByLtdDifferencePt = totalLoanAmount.mul(PERCENT_100).div(PERCENT_100\n .sub(ltdParams.lockDifferenceLimit));\n allowedByLtdDifferencePt = totalLockedAmount >= allowedByLtdDifferencePt ?\n 0 : allowedByLtdDifferencePt.sub(totalLockedAmount);\n\n uint allowedByLtdDifferenceAmount =\n totalLockedAmount >= totalLoanAmount.add(ltdParams.allowedDifferenceAmount) ?\n 0 : totalLoanAmount.add(ltdParams.allowedDifferenceAmount).sub(totalLockedAmount);\n\n maxLockByLtd = allowedByLtdDifferencePt > allowedByLtdDifferenceAmount ?\n allowedByLtdDifferencePt : allowedByLtdDifferenceAmount;\n }\n\n /* returns maximum borrowable token amount allowed by LTD params */\n function getMaxLoanAmountAllowedByLtd() public view returns(uint maxLoanByLtd) {\n uint allowedByLtdDifferencePt = totalLockedAmount.mul(ltdParams.loanDifferenceLimit.add(PERCENT_100))\n .div(PERCENT_100);\n allowedByLtdDifferencePt = totalLoanAmount >= allowedByLtdDifferencePt ?\n 0 : allowedByLtdDifferencePt.sub(totalLoanAmount);\n\n uint allowedByLtdDifferenceAmount =\n totalLoanAmount >= totalLockedAmount.add(ltdParams.allowedDifferenceAmount) ?\n 0 : totalLockedAmount.add(ltdParams.allowedDifferenceAmount).sub(totalLoanAmount);\n\n maxLoanByLtd = allowedByLtdDifferencePt > allowedByLtdDifferenceAmount ?\n allowedByLtdDifferencePt : allowedByLtdDifferenceAmount;\n }\n\n}\n" } } } diff --git a/abiniser/deployments/4/TokenAEur_DEPLOYS.json b/abiniser/deployments/4/TokenAEur_DEPLOYS.json index 32740eee..e71ad477 100644 --- a/abiniser/deployments/4/TokenAEur_DEPLOYS.json +++ b/abiniser/deployments/4/TokenAEur_DEPLOYS.json @@ -1,6 +1,6 @@ { "contractName": "TokenAEur", - "latestAbiHash": "d7dd02520f2d92b2ca237f066cf2488d", + "latestAbiHash": "4b49e7e6d1a9a2de81a4d2d088acbc04", "deployedAbis": { "27721a2c77dc40da7639abd46791c3d7": { "latestDeployedAddress": "0x95aa79d7410eb60f49bfd570b445836d402bd7b1", @@ -53,6 +53,24 @@ "source": "/* Augmint Crypto Euro token (ACE) implementation */\npragma solidity ^0.4.23;\nimport \"./interfaces/TransferFeeInterface.sol\";\nimport \"./generic/AugmintToken.sol\";\n\n\ncontract TokenAEur is AugmintToken {\n constructor(TransferFeeInterface _feeAccount)\n public AugmintToken(\"Augmint Crypto Euro\", \"AEUR\", \"EUR\", 2, _feeAccount)\n {} // solhint-disable-line no-empty-blocks\n\n}\n" } } + }, + "4b49e7e6d1a9a2de81a4d2d088acbc04": { + "latestDeployedAddress": "0x6c90c10d7a33815c2baeed66ee8b848f1d95268e", + "deployments": { + "0x6c90c10d7a33815c2baeed66ee8b848f1d95268e": { + "generatedAt": "2018-05-12T01:34:38.456Z", + "truffleContractFileUpdatedAt": "2018-05-12T01:30:50.031Z", + "deployTransactionHash": "0xf45e9817fca468b5438d7a00a6461fd47e14cf04f1bb4b36ccc7302284ec39c5", + "compiler": { + "name": "solc", + "version": "0.4.23+commit.124ca40d.Emscripten.clang" + }, + "bytecodeHash": "042675fc70cfed8762b1e7de8d15799f", + "deployedBytecodeHash": "03b0c0d8c49d83af34516ac82bc0b2a9", + "sourceHash": "61dded7836f4431e621382340f32670c", + "source": "/* Augmint Crypto Euro token (ACE) implementation */\npragma solidity ^0.4.23;\nimport \"./interfaces/TransferFeeInterface.sol\";\nimport \"./generic/AugmintToken.sol\";\n\n\ncontract TokenAEur is AugmintToken {\n constructor(TransferFeeInterface _feeAccount)\n public AugmintToken(\"Augmint Crypto Euro\", \"AEUR\", \"EUR\", 2, _feeAccount)\n {} // solhint-disable-line no-empty-blocks\n\n}\n" + } + } } } } \ No newline at end of file diff --git a/rinkeby_migrations/17_new_TokenAEur.js b/rinkeby_migrations/17_new_TokenAEur.js new file mode 100644 index 00000000..681abf26 --- /dev/null +++ b/rinkeby_migrations/17_new_TokenAEur.js @@ -0,0 +1,181 @@ +/* deploy new TokenAEur version and all dependent contracts: + - MonetarySupervisor (and switch over to it ) + - Locker + - LoanManager + - Exchange +*/ +const Migrations = artifacts.require("./Migrations.sol"); +const TokenAEur = artifacts.require("./TokenAEur.sol"); +const FeeAccount = artifacts.require("./FeeAccount.sol"); +const Exchange = artifacts.require("./Exchange.sol"); +const MonetarySupervisor = artifacts.require("./MonetarySupervisor.sol"); +const InterestEarnedAccount = artifacts.require("./InterestEarnedAccount.sol"); +const AugmintReserves = artifacts.require("./AugmintReserves.sol"); +const Locker = artifacts.require("./Locker.sol"); +const LoanManager = artifacts.require("./LoanManager.sol"); + +module.exports = function(deployer, network, accounts) { + const ratesAddress = "0xcA8100FCcb479516A5b30f8Bc5dAeA09Fb7a7473"; + const feeAccount = FeeAccount.at("0xc26667132b0B798ab87864f7c29c0819c887aADB"); + const augmintReserves = AugmintReserves.at("0xc70b65e40f877cdC6d8D2ebFd44d63EfBeb7fc6D"); + const interestEarnedAccount = InterestEarnedAccount.at("0x3a414d7636defb9d3dfb7342984fe3f7b5125df6"); + const oldMonetarySupervisor = MonetarySupervisor.at("0xa00a5d1882C3F690E3d0D975ebE378120b70ae87"); + + const oldToken1 = TokenAEur.at("0x95aa79d7410eb60f49bfd570b445836d402bd7b1"); + const oldToken2 = TokenAEur.at("0xa35d9de06895a3a2e7ecae26654b88fe71c179ea"); + const oldToken3 = TokenAEur.at("0x135893F1A6B3037BB45182841f18F69327366992"); + + const oldLocker1 = Locker.at("0xf98AE1fb568B267A7632BF54579A153C892E2ec2"); + const oldLoanManager1 = LoanManager.at("0xBdb02f82d7Ad574f9F549895caf41E23a8981b07"); + + deployer.deploy(TokenAEur, feeAccount.address); + + deployer.then(async () => { + /************************************************************* + * Deploy new TokenAEur + **************************************************************/ + + const newTokenAEur = TokenAEur.at(TokenAEur.address); + + /************************************************************* + * Deploy new Exchange + **************************************************************/ + await deployer.deploy(Exchange, newTokenAEur.address, ratesAddress); + const newExchange = Exchange.at(Exchange.address); + + await feeAccount.grantPermission(newExchange.address, "NoFeeTransferContracts"); + + /************************************************************* + * Deploy new MonetarySupervisor + **************************************************************/ + await deployer.deploy( + MonetarySupervisor, + newTokenAEur.address, + augmintReserves.address, + interestEarnedAccount.address, + 200000 /* ltdLockDifferenceLimit */, + 200000 /* ltdLoanDifferenceLimit*/, + 50000 /* allowedLtdDifferenceAmount */ + ); + + const newMonetarySupervisor = MonetarySupervisor.at(MonetarySupervisor.address); + + /************************************************************* + * Deploy new Locker, setup lock products and permissions + **************************************************************/ + await deployer.deploy(Locker, TokenAEur.address, MonetarySupervisor.address); + const newLocker = Locker.at(Locker.address); + console.log(" Adding test lockProducts."); + await Promise.all([ + feeAccount.grantPermission(newLocker.address, "NoFeeTransferContracts"), + newMonetarySupervisor.grantPermission(newLocker.address, "LockerContracts"), + + // (perTermInterest, durationInSecs, minimumLockAmount, isActive) + newLocker.addLockProduct(14472, 7776000, 1000, false), // 90 days 6% p.a. + newLocker.addLockProduct(4019, 2592000, 1000, true), // 30 days, 5% p.a. + newLocker.addLockProduct(1506, 1209600, 1000, true), // 14 days, 4% p.a. + newLocker.addLockProduct(568, 604800, 1000, true), // 7 days, 3% p.a. + + newLocker.addLockProduct(3, 3600, 2000, true), // 60 minutes for testing, ~2.66% p.a. + newLocker.addLockProduct(1, 60, 3000, true) // 1 minute for testing, ~69.15% p.a. + ]); + + /************************************************************* + * Deploy new LoanManager, setup loan products and permissions + **************************************************************/ + await deployer.deploy(LoanManager, newTokenAEur.address, newMonetarySupervisor.address, ratesAddress); + const newLoanManager = LoanManager.at(LoanManager.address); + console.log(" Adding test loanProducts."); + await Promise.all([ + feeAccount.grantPermission(newLoanManager.address, "NoFeeTransferContracts"), + newMonetarySupervisor.grantPermission(newLoanManager.address, "LoanManagerContracts"), + + // term (in sec), discountRate, loanCoverageRatio, minDisbursedAmount (w/ 4 decimals), defaultingFeePt, isActive + newLoanManager.addLoanProduct(7776000, 971661, 600000, 1000, 50000, false), // 90d, 12%. p.a. + newLoanManager.addLoanProduct(2592000, 990641, 600000, 1000, 50000, true), // 30d, 12% p.a. + newLoanManager.addLoanProduct(1209600, 996337, 600000, 1000, 50000, true), // 14d, 10% p.a. + newLoanManager.addLoanProduct(604800, 998170, 600000, 1000, 50000, true), // 7d, 10% p.a. + + newLoanManager.addLoanProduct(3600, 999989, 980000, 2000, 50000, true), // due in 1hr for testing repayments ? p.a. + newLoanManager.addLoanProduct(1, 999999, 990000, 3000, 50000, true) // defaults in 1 secs for testing ? p.a. + ]); + + /************************************************************* + * Grant MonetaryBoard permissions to accounts on new contracts + **************************************************************/ + console.log(" Granting MonetaryBoard permissions on new contracts "); + const monetaryBoardAccounts = [ + accounts[0], + "0x14A9dc091053fCbA9474c5734078238ff9904364" /* Krosza */, + "0xe71E9636e31B838aF0A3c38B3f3449cdC2b7aa87" /* Phraktle */ + ]; + const grantMonetaryBoardTxs = monetaryBoardAccounts.map(acc => [ + newExchange.grantPermission(acc, "MonetaryBoard"), + newLocker.grantPermission(acc, "MonetaryBoard"), + newTokenAEur.grantPermission(acc, "MonetaryBoard"), + newLoanManager.grantPermission(acc, "MonetaryBoard"), + newMonetarySupervisor.grantPermission(acc, "MonetaryBoard") + ]); + Promise.all(grantMonetaryBoardTxs); + + /************************************************************* + * Switch new MonetarySupervisor to live + **************************************************************/ + console.log(" granting permissions for new MS"); + await Promise.all([ + interestEarnedAccount.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"), + newTokenAEur.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"), + augmintReserves.grantPermission(newMonetarySupervisor.address, "MonetarySupervisorContract"), + feeAccount.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"), + + newMonetarySupervisor.grantPermission(newLocker.address, "LockerContracts"), + newMonetarySupervisor.grantPermission(newLoanManager.address, "LoanManagerContracts"), + newMonetarySupervisor.grantPermission(oldLocker1.address, "LockerContracts"), + newMonetarySupervisor.grantPermission(oldLoanManager1.address, "LoanManagerContracts"), + + newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken1.address, true), + newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken2.address, true), + newMonetarySupervisor.setAcceptedLegacyAugmintToken(oldToken3.address, true), + + // to allow token conversion w/o fee + // NB: NoFeeTransferContracts was set on the token contract in legacy token version. + // For newer versions this permission needs to be set on feeAccount + oldToken1.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"), + oldToken2.grantPermission(newMonetarySupervisor.address, "NoFeeTransferContracts"), + feeAccount.grantPermission(oldToken3.address, "NoFeeTransferContracts") + ]); + + console.log(" switching new MS to live"); + await Promise.all([ + oldLocker1.setMonetarySupervisor(newMonetarySupervisor.address), + oldLoanManager1.setSystemContracts(ratesAddress, newMonetarySupervisor.address) + ]); + + // 3. migrate totals from previous MS (using MS.adjustKPIs) + const [oldTotalLoan, oldTotalLock] = await Promise.all([ + oldMonetarySupervisor.totalLoanAmount(), + oldMonetarySupervisor.totalLockedAmount() + ]); + console.log( + "Migrating KPIs to new MonetarySupervisor contract. totalLoanAmount:", + oldTotalLoan.toString(), + "totalLockedAmount", + oldTotalLock.toString() + ); + await newMonetarySupervisor.adjustKPIs(oldTotalLoan, oldTotalLock); + + console.log("Revoking permission from old MS"); + await Promise.all([ + feeAccount.revokePermission(oldMonetarySupervisor.address, "NoFeeTransferContracts"), + interestEarnedAccount.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"), + oldToken3.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"), + augmintReserves.revokePermission(oldMonetarySupervisor.address, "MonetarySupervisorContract"), + + oldMonetarySupervisor.revokePermission(oldLocker1.address, "LockerContracts"), + oldMonetarySupervisor.revokePermission(oldLoanManager1.address, "LoanManagerContracts") + ]); + + console.log(" Done with all migration steps. Updating truffle Migrations step manually"); + await Migrations.at("0xb96f7e79a6b3faf4162e274ff764ca9de598b0c5").setCompleted(17); + }); +};