dsa-connectors/contracts/mainnet/connectors/basic-ERC721/main.sol

78 lines
2.3 KiB
Solidity
Raw Normal View History

2022-03-22 15:24:40 +00:00
//SPDX-License-Identifier: MIT
2021-08-25 15:09:52 +00:00
pragma solidity ^0.7.0;
/**
* @title Basic.
2021-09-07 11:14:59 +00:00
* @dev Deposit & Withdraw ERC721 from DSA.
2021-08-25 15:09:52 +00:00
*/
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";
abstract contract BasicResolver is Events, DSMath, Basic {
/**
* @dev Deposit Assets To Smart Account.
* @notice Deposit a ERC721 token to DSA
2021-08-30 08:23:54 +00:00
* @param token Address of token.
* @param tokenId ID of token.
2021-08-25 17:48:08 +00:00
* @param getId ID to retrieve tokenId.
* @param setId ID stores the tokenId.
2021-08-25 15:09:52 +00:00
*/
2021-08-25 16:18:31 +00:00
function depositERC721(
address token,
uint256 tokenId,
uint256 getId,
uint256 setId
)
2021-08-25 15:09:52 +00:00
public
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-25 16:18:31 +00:00
uint256 _tokenId = getUint(getId, tokenId);
2021-08-25 15:09:52 +00:00
IERC721 tokenContract = IERC721(token);
2021-08-25 16:18:31 +00:00
tokenContract.safeTransferFrom(msg.sender, address(this), _tokenId);
setUint(setId, _tokenId);
2021-08-25 15:09:52 +00:00
2021-08-25 16:18:31 +00:00
_eventName = "LogDepositERC721(address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(token, msg.sender, _tokenId, getId, setId);
2021-08-25 15:09:52 +00:00
}
/**
* @dev Withdraw Assets To Smart Account.
* @notice Withdraw a ERC721 token from DSA
2021-08-30 08:23:54 +00:00
* @param token Address of the token.
* @param tokenId ID of token.
2021-08-25 15:09:52 +00:00
* @param to The address to receive the token upon withdrawal
2021-08-25 17:48:08 +00:00
* @param getId ID to retrieve tokenId.
* @param setId ID stores the tokenId.
2021-08-25 15:09:52 +00:00
*/
function withdrawERC721(
address token,
uint256 tokenId,
2021-08-25 16:18:31 +00:00
address payable to,
uint256 getId,
uint256 setId
2021-08-25 15:09:52 +00:00
)
public
payable
returns (string memory _eventName, bytes memory _eventParam)
{
2021-08-25 16:18:31 +00:00
uint256 _tokenId = getUint(getId, tokenId);
2021-08-25 15:09:52 +00:00
IERC721 tokenContract = IERC721(token);
2021-08-25 16:18:31 +00:00
tokenContract.safeTransferFrom(address(this), to, _tokenId);
setUint(setId, _tokenId);
2021-08-25 15:09:52 +00:00
2021-08-25 16:18:31 +00:00
_eventName = "LogWithdrawERC721(address,uint256,address,uint256,uint256)";
_eventParam = abi.encode(token, _tokenId, to, getId, setId);
2021-08-25 15:09:52 +00:00
}
}
2021-08-30 08:23:54 +00:00
contract ConnectV2BasicERC721 is BasicResolver {
2021-08-30 08:25:28 +00:00
string public constant name = "BASIC-ERC721-v1.0";
2021-08-25 15:09:52 +00:00
}