mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
added addition connector
This commit is contained in:
parent
ad76f705d7
commit
358f313931
78
contracts/connectors/addition.sol
Normal file
78
contracts/connectors/addition.sol
Normal file
|
@ -0,0 +1,78 @@
|
|||
pragma solidity ^0.6.0;
|
||||
|
||||
interface MemoryInterface {
|
||||
function getUint(uint _id) external returns (uint _num);
|
||||
function setUint(uint _id, uint _val) external;
|
||||
}
|
||||
|
||||
contract DSMath {
|
||||
|
||||
function add(uint x, uint y) internal pure returns (uint z) {
|
||||
require((z = x + y) >= x, "math-not-safe");
|
||||
}
|
||||
|
||||
function sub(uint x, uint y) internal pure returns (uint z) {
|
||||
require((z = x - y) <= x, "ds-math-sub-underflow");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract Helpers is DSMath {
|
||||
/**
|
||||
* @dev Return Memory Variable Address
|
||||
*/
|
||||
function getMemoryAddr() internal pure returns (address) {
|
||||
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, 47);
|
||||
}
|
||||
}
|
||||
|
||||
contract BasicResolver is Helpers {
|
||||
|
||||
/**
|
||||
* @dev Add getIds
|
||||
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function addIds(uint[] calldata getIds, uint setId) external payable {
|
||||
uint amt;
|
||||
for (uint i = 0; i < getIds.length; i++) {
|
||||
amt = add(amt, getUint(getIds[i], 0));
|
||||
}
|
||||
|
||||
setUint(setId, amt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sub getIds
|
||||
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
||||
*/
|
||||
function subIds(uint getIdOne, uint getIdTwo, uint setId) external payable {
|
||||
uint amt = add(getUint(getIdOne, 0), getUint(getIdTwo, 0));
|
||||
|
||||
setUint(setId, amt);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectAddition is BasicResolver {
|
||||
string public name = "Addition-v1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user