From 556e920ee822398b2c1b76b8c60acf5c66680d5a Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 16 Dec 2020 20:04:24 +0530 Subject: [PATCH 1/3] added fee connector --- contracts/connectors/fee.sol | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 contracts/connectors/fee.sol diff --git a/contracts/connectors/fee.sol b/contracts/connectors/fee.sol new file mode 100644 index 0000000..c5dd31e --- /dev/null +++ b/contracts/connectors/fee.sol @@ -0,0 +1,78 @@ +pragma solidity ^0.6.0; +pragma experimental ABIEncoderV2; + +interface MemoryInterface { + function getUint(uint _id) external returns (uint _num); + function setUint(uint _id, uint _val) external; +} + +contract DSMath { + uint256 constant WAD = 10 ** 18; + + function add(uint x, uint y) internal pure returns (uint z) { + require((z = x + y) >= x, "math-not-safe"); + } + + function mul(uint x, uint y) internal pure returns (uint z) { + require(y == 0 || (z = x * y) / y == x, "math-not-safe"); + } + + function wmul(uint x, uint y) internal pure returns (uint z) { + z = add(mul(x, y), WAD / 2) / WAD; + } +} + +contract Setup is DSMath { + + /** + * @dev Return InstAaMemory Address. + */ + function getMemoryAddr() internal pure returns (address) { + return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; + } + + /** + * @dev Get Uint value from InstaMemory Contract. + */ + function getUint(uint getId, uint val) internal returns (uint returnVal) { + returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId); + } + + /** + * @dev Set Uint value in InstaMemory Contract. + */ + function setUint(uint setId, uint val) internal { + if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val); + } + + /** + * @dev Connector ID and Type. TODO: change. + */ + function connectorID() public pure returns(uint _type, uint _id) { + (_type, _id) = (1, 37); + } + +} + + +contract FeeResolver is Setup { + + /** + * @dev Calculate fee + */ + function calculateFee(uint amount, uint fee, uint getId, uint setId) external payable { + require(fee <= 5 * 10 ** 16, "Fee-more-than-5%"); // TODO: change + uint _amt = getUint(getId, amount); + + uint feeAmt = wmul(_amt, fee); + + uint totalAmt = add(_amt, feeAmt); + + setUint(setId, totalAmt); + } +} + + +contract ConnectFee is FeeResolver { + string public constant name = "Fee-v1"; +} \ No newline at end of file From 52b7e1be41a831af98d07ff77a4760bfd65d2eb7 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 16 Dec 2020 20:26:02 +0530 Subject: [PATCH 2/3] added setIdFee --- contracts/connectors/fee.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/connectors/fee.sol b/contracts/connectors/fee.sol index c5dd31e..b9ed6e1 100644 --- a/contracts/connectors/fee.sol +++ b/contracts/connectors/fee.sol @@ -60,8 +60,7 @@ contract FeeResolver is Setup { /** * @dev Calculate fee */ - function calculateFee(uint amount, uint fee, uint getId, uint setId) external payable { - require(fee <= 5 * 10 ** 16, "Fee-more-than-5%"); // TODO: change + function calculateFee(uint amount, uint fee, uint getId, uint setId, uint setIdFee) external payable { uint _amt = getUint(getId, amount); uint feeAmt = wmul(_amt, fee); @@ -69,6 +68,7 @@ contract FeeResolver is Setup { uint totalAmt = add(_amt, feeAmt); setUint(setId, totalAmt); + setUint(setIdFee, feeAmt); } } From 14982f759471ca1bc30f7cc94703b82220981709 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 16 Dec 2020 20:26:37 +0530 Subject: [PATCH 3/3] removed auth check while withdrawing --- contracts/connectors/basic.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/connectors/basic.sol b/contracts/connectors/basic.sol index 0ca4672..650ab9e 100644 --- a/contracts/connectors/basic.sol +++ b/contracts/connectors/basic.sol @@ -63,7 +63,7 @@ contract BasicResolver is Stores { uint getId, uint setId ) public payable { - require(AccountInterface(address(this)).isAuth(to), "invalid-to-address"); + // require(AccountInterface(address(this)).isAuth(to), "invalid-to-address"); uint amt = getUint(getId, tokenAmt); if (erc20 == getEthAddr()) { amt = amt == uint(-1) ? address(this).balance : amt;