mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add basic & chi
This commit is contained in:
parent
8518657e83
commit
7e69631620
|
@ -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";
|
||||
}
|
||||
|
|
6
contracts/connectors/basic/events.sol
Normal file
6
contracts/connectors/basic/events.sol
Normal 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);
|
||||
}
|
74
contracts/connectors/basic/main.sol
Normal file
74
contracts/connectors/basic/main.sol
Normal 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";
|
||||
}
|
6
contracts/connectors/chi/events.sol
Normal file
6
contracts/connectors/chi/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogMint(uint256 amt);
|
||||
event LogBurn(uint256 amt);
|
||||
}
|
9
contracts/connectors/chi/helpers.sol
Normal file
9
contracts/connectors/chi/helpers.sol
Normal 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);
|
||||
}
|
8
contracts/connectors/chi/interface.sol
Normal file
8
contracts/connectors/chi/interface.sol
Normal 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;
|
||||
}
|
29
contracts/connectors/chi/main.sol
Normal file
29
contracts/connectors/chi/main.sol
Normal 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";
|
||||
}
|
Loading…
Reference in New Issue
Block a user