mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
added mock connector and todo
This commit is contained in:
parent
c3031849df
commit
e7ee535d96
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
# DeFi Smart Account Connectors
|
# DeFi Smart Account Connectors
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- The contracts should not have `selfdestruct()`.
|
- The contracts should not have `selfdestruct()`.
|
||||||
- The contracts should not have `delegatecall()`.
|
- The contracts should not have `delegatecall()`.
|
||||||
- Use `uint(-1)` for maximum amount everywhere.
|
- Use `uint(-1)` for maximum amount everywhere ([example](/)).
|
||||||
- Import `contracts/common` files.
|
- 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
|
```javascript
|
||||||
contract Sample {
|
contract Sample {
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
pragma solidity ^0.6.0;
|
pragma solidity ^0.6.0;
|
||||||
|
|
||||||
interface MemoryInterface {
|
interface MemoryInterface {
|
||||||
function getUint(uint _id) external returns (uint _num);
|
function getUint(uint id) external returns (uint num);
|
||||||
function setUint(uint _id, uint _val) external;
|
function setUint(uint id, uint val) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EventInterface {
|
||||||
|
function emitEvent(uint connectorType, uint connectorID, bytes32 eventCode, bytes calldata eventData) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Stores {
|
contract Stores {
|
||||||
|
@ -10,12 +14,12 @@ contract Stores {
|
||||||
/**
|
/**
|
||||||
* @dev Return ethereum address
|
* @dev Return ethereum address
|
||||||
*/
|
*/
|
||||||
function getAddressETH() internal pure returns (address) {
|
function getEthAddr() internal pure returns (address) {
|
||||||
return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address
|
return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Return Memory Variable Address
|
* @dev Return memory variable address
|
||||||
*/
|
*/
|
||||||
function getMemoryAddr() internal pure returns (address) {
|
function getMemoryAddr() internal pure returns (address) {
|
||||||
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
|
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
|
||||||
|
@ -30,23 +34,31 @@ contract Stores {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Get Uint value from InstaMemory Contract.
|
* @dev Get Uint value from InstaMemory Contract.
|
||||||
*/
|
*/
|
||||||
function getUint(uint getId, uint val) internal returns (uint returnVal) {
|
function getUint(uint getId, uint val) internal returns (uint returnVal) {
|
||||||
returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId);
|
returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Set Uint value in InstaMemory Contract.
|
* @dev Set Uint value in InstaMemory Contract.
|
||||||
*/
|
*/
|
||||||
function setUint(uint setId, uint val) internal {
|
function setUint(uint setId, uint val) internal {
|
||||||
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
|
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Connector Details
|
* @dev Connector Details
|
||||||
*/
|
*/
|
||||||
function connectorID() public pure returns(uint _type, uint _id) {
|
function connectorID() public pure returns(uint model, uint id) {
|
||||||
(_type, _id) = (1, 3);
|
(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,5 +4,20 @@ import { DSMath } from "../common/math.sol";
|
||||||
import { Stores } from "../common/stores.sol";
|
import { Stores } from "../common/stores.sol";
|
||||||
|
|
||||||
contract MockProtocol is Stores, DSMath {
|
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";
|
||||||
}
|
}
|
5
todo.md
5
todo.md
|
@ -1,2 +1,3 @@
|
||||||
- add the static connectors in "contracts/static" folder
|
- add the static connectors in "contracts/static" folder
|
||||||
- why ^ in ^0.6.0? Do we need it?
|
- why ^ in ^0.6.0? Do we need it?
|
||||||
|
- use the `contract/connectors/mock.sol` structure for yet-to-be-deployed connectors
|
Loading…
Reference in New Issue
Block a user