From e7ee535d96bc93684afa0cce03ed5a3306faa6a4 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Sat, 2 May 2020 21:52:06 +1000 Subject: [PATCH] added mock connector and todo --- README.md | 8 +++-- contracts/common/stores.sol | 30 +++++++++++++------ .../connectors/{auth.sol => authority.sol} | 0 contracts/connectors/mock.sol | 17 ++++++++++- todo.md | 5 ++-- 5 files changed, 45 insertions(+), 15 deletions(-) rename contracts/connectors/{auth.sol => authority.sol} (100%) diff --git a/README.md b/README.md index 2fdb671..0526b09 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ - # DeFi Smart Account Connectors ## Requirements - The contracts should not have `selfdestruct()`. - The contracts should not have `delegatecall()`. -- Use `uint(-1)` for maximum amount everywhere. -- Import `contracts/common` files. +- Use `uint(-1)` for maximum amount everywhere ([example](/)). +- Import `contracts/common` files ([example](/)). +- Add `getId` & `setId`, two additional parameter for external public facing functions ([example](/)). +- Use `getUint()` or `setUint()` functions to fetch or store values ([example](/)). +- Use address returned by `getEthAddr()` to denote Ethereum in all Ethereum related operations ([example](/)). ```javascript contract Sample { diff --git a/contracts/common/stores.sol b/contracts/common/stores.sol index cbf0e8d..5e47737 100644 --- a/contracts/common/stores.sol +++ b/contracts/common/stores.sol @@ -1,8 +1,12 @@ pragma solidity ^0.6.0; interface MemoryInterface { - function getUint(uint _id) external returns (uint _num); - function setUint(uint _id, uint _val) external; + function getUint(uint id) external returns (uint num); + function setUint(uint id, uint val) external; +} + +interface EventInterface { + function emitEvent(uint connectorType, uint connectorID, bytes32 eventCode, bytes calldata eventData) external; } contract Stores { @@ -10,12 +14,12 @@ contract Stores { /** * @dev Return ethereum address */ - function getAddressETH() internal pure returns (address) { + function getEthAddr() internal pure returns (address) { return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address } /** - * @dev Return Memory Variable Address + * @dev Return memory variable address */ function getMemoryAddr() internal pure returns (address) { return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address @@ -30,23 +34,31 @@ contract Stores { /** * @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 Details - */ - function connectorID() public pure returns(uint _type, uint _id) { - (_type, _id) = (1, 3); + */ + function connectorID() public pure returns(uint model, uint id) { + (model, id) = (0, 0); + } + + /** + * @dev emit event on event contract + */ + function emitEvent(bytes32 eventCode, bytes memory eventData) internal { + (uint model, uint id) = connectorID(); + EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData); } } \ No newline at end of file diff --git a/contracts/connectors/auth.sol b/contracts/connectors/authority.sol similarity index 100% rename from contracts/connectors/auth.sol rename to contracts/connectors/authority.sol diff --git a/contracts/connectors/mock.sol b/contracts/connectors/mock.sol index b04211d..03a8bc3 100644 --- a/contracts/connectors/mock.sol +++ b/contracts/connectors/mock.sol @@ -4,5 +4,20 @@ import { DSMath } from "../common/math.sol"; import { Stores } from "../common/stores.sol"; contract MockProtocol is Stores, DSMath { - // + + event LogMock(uint mockOne, uint mockTwo, uint getId, uint setId); + + function mockFunction(uint mockNumber, uint getId, uint setId) external payable { + uint mockBalance = mockNumber == uint(-1) ? address(this).balance : mockNumber; + + emit LogMock(mockNumber, mockBalance, getId, setId); + bytes32 eventCode = keccak256("LogMock(uint256,uint256,uint256,uint256)"); + bytes memory eventData = abi.encode(mockNumber, mockBalance, getId, setId); + emitEvent(eventCode, eventData); + } + +} + +contract ConnectMock is MockProtocol { + string public name = "Mock-v1"; } \ No newline at end of file diff --git a/todo.md b/todo.md index dc678c2..9870de6 100644 --- a/todo.md +++ b/todo.md @@ -1,2 +1,3 @@ -- add the static connectors in "contracts/static" folder -- why ^ in ^0.6.0? Do we need it? \ No newline at end of file +- add the static connectors in "contracts/static" folder +- why ^ in ^0.6.0? Do we need it? +- use the `contract/connectors/mock.sol` structure for yet-to-be-deployed connectors \ No newline at end of file