Add basic & chi

This commit is contained in:
Mubaris NK 2021-02-08 20:48:32 +05:30
parent 8518657e83
commit 7e69631620
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
7 changed files with 136 additions and 0 deletions

View File

@ -32,3 +32,7 @@ abstract contract AuthorityResolver is Events, Helpers {
_eventParam = abi.encode(msg.sender, authority);
}
}
contract ConnectAuth is AuthorityResolver {
string public constant name = "Auth-v1";
}

View File

@ -0,0 +1,6 @@
pragma solidity ^0.7.0;
contract Events {
event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId);
}

View File

@ -0,0 +1,74 @@
pragma solidity ^0.7.0;
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { Events } from "./events.sol";
abstract contract BasicResolver is Events, DSMath, Basic {
using SafeERC20 for IERC20;
/**
* @dev Deposit Assets To Smart Account.
* @param erc20 Token Address.
* @param tokenAmt Token Amount.
* @param getId Get Storage ID.
* @param setId Set Storage ID.
*/
function deposit(
address erc20,
uint tokenAmt,
uint getId,
uint setId
) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint amt = getUint(getId, tokenAmt);
if (erc20 != ethAddr) {
IERC20 token = IERC20(erc20);
amt = amt == uint(-1) ? token.balanceOf(msg.sender) : amt;
token.safeTransferFrom(msg.sender, address(this), amt);
} else {
require(msg.value == amt || amt == uint(-1), "invalid-ether-amount");
amt = msg.value;
}
setUint(setId, amt);
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
_eventParam = abi.encode(erc20, amt, getId, setId);
}
/**
* @dev Withdraw Assets To Smart Account.
* @param erc20 Token Address.
* @param tokenAmt Token Amount.
* @param to Withdraw token address.
* @param getId Get Storage ID.
* @param setId Set Storage ID.
*/
function withdraw(
address erc20,
uint tokenAmt,
address payable to,
uint getId,
uint setId
) public payable returns (string memory _eventName, bytes memory _eventParam) {
uint amt = getUint(getId, tokenAmt);
if (erc20 == ethAddr) {
amt = amt == uint(-1) ? address(this).balance : amt;
to.transfer(amt);
} else {
IERC20 token = IERC20(erc20);
amt = amt == uint(-1) ? token.balanceOf(address(this)) : amt;
token.safeTransfer(to, amt);
}
setUint(setId, amt);
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
_eventParam = abi.encode(erc20, amt, to, getId, setId);
}
}
contract ConnectBasic is BasicResolver {
string public constant name = "Basic-v1.1";
}

View File

@ -0,0 +1,6 @@
pragma solidity ^0.7.0;
contract Events {
event LogMint(uint256 amt);
event LogBurn(uint256 amt);
}

View File

@ -0,0 +1,9 @@
pragma solidity ^0.7.0;
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { CHIInterface } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
CHIInterface constant internal chi = CHIInterface(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c);
}

View File

@ -0,0 +1,8 @@
pragma solidity ^0.7.0;
interface CHIInterface {
function mint(uint256 value) external;
function free(uint256 value) external returns (uint256);
function balanceOf(address) external view returns (uint);
function approve(address, uint256) external;
}

View File

@ -0,0 +1,29 @@
pragma solidity ^0.7.0;
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract ChiResolver is Events, Helpers {
/**
* @dev Mint CHI token.
* @param amt token amount to mint.
*/
function mint(uint amt) public payable {
uint _amt = amt == uint(-1) ? 140 : amt;
require(_amt <= 140, "Max minting is 140 chi");
chi.mint(_amt);
}
/**
* @dev burn CHI token.
* @param amt token amount to burn.
*/
function burn(uint amt) public payable {
uint _amt = amt == uint(-1) ? chi.balanceOf(address(this)) : amt;
chi.approve(address(chi), _amt);
chi.free(_amt);
}
}
contract ConnectCHI is ChiResolver {
string public name = "CHI-v1";
}