mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
feat/implement ERC721 deposit/withdraw
This commit is contained in:
parent
509d2cf3bd
commit
3adf990b83
|
|
@ -1,6 +1,23 @@
|
|||
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);
|
||||
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
|
||||
);
|
||||
event LogDepositERC721(address indexed erc721, uint256 tokenId);
|
||||
event LogWithdrawERC721(
|
||||
address indexed erc721,
|
||||
uint256 tokenId,
|
||||
address indexed to
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ pragma solidity ^0.7.0;
|
|||
* @dev Deposit & Withdraw from DSA.
|
||||
*/
|
||||
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { Events } from "./events.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;
|
||||
|
|
@ -28,14 +29,23 @@ abstract contract BasicResolver is Events, DSMath, Basic {
|
|||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amt);
|
||||
if (token != ethAddr) {
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt;
|
||||
_amt = _amt == uint256(-1)
|
||||
? tokenContract.balanceOf(msg.sender)
|
||||
: _amt;
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
} else {
|
||||
require(msg.value == _amt || _amt == uint(-1), "invalid-ether-amount");
|
||||
require(
|
||||
msg.value == _amt || _amt == uint256(-1),
|
||||
"invalid-ether-amount"
|
||||
);
|
||||
_amt = msg.value;
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
|
@ -55,18 +65,24 @@ abstract contract BasicResolver is Events, DSMath, Basic {
|
|||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint amt,
|
||||
uint256 amt,
|
||||
address payable to,
|
||||
uint getId,
|
||||
uint setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amt);
|
||||
if (token == ethAddr) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
|
||||
to.call{value: _amt}("");
|
||||
} else {
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
_amt = _amt == uint256(-1)
|
||||
? tokenContract.balanceOf(address(this))
|
||||
: _amt;
|
||||
tokenContract.safeTransfer(to, _amt);
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
|
@ -74,8 +90,49 @@ abstract contract BasicResolver is Events, DSMath, Basic {
|
|||
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, to, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Deposit Assets To Smart Account.
|
||||
* @notice Deposit a ERC721 token to DSA
|
||||
* @param token The address of the token to deposit.
|
||||
* @param tokenId The id of token to deposit.
|
||||
*/
|
||||
function depositERC721(address token, uint256 tokenId)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
IERC721 tokenContract = IERC721(token);
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), tokenId);
|
||||
|
||||
_eventName = "LogDepositERC721(address,uint256,address)";
|
||||
_eventParam = abi.encode(token, tokenId, msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw Assets To Smart Account.
|
||||
* @notice Withdraw a ERC721 token from DSA
|
||||
* @param token The address of the token to deposit.
|
||||
* @param tokenId The id of token to deposit.
|
||||
* @param to The address to receive the token upon withdrawal
|
||||
*/
|
||||
function withdrawERC721(
|
||||
address token,
|
||||
uint256 tokenId,
|
||||
address payable to
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
IERC721 tokenContract = IERC721(token);
|
||||
tokenContract.safeTransferFrom(address(this), to, tokenId);
|
||||
|
||||
_eventName = "LogWithdrawERC721(address,uint256,address)";
|
||||
_eventParam = abi.encode(token, tokenId, to);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2Basic is BasicResolver {
|
||||
string constant public name = "Basic-v1";
|
||||
string public constant name = "Basic-v1";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user