mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #156 from Instadapp/basic-connectors
BASIC-B and BASIC-C
This commit is contained in:
commit
7913581a55
21
contracts/avalanche/connectors/basic-ERC1155/events.sol
Normal file
21
contracts/avalanche/connectors/basic-ERC1155/events.sol
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogDepositERC1155(
|
||||||
|
address indexed erc1155,
|
||||||
|
address from,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
event LogWithdrawERC1155(
|
||||||
|
address indexed erc1155,
|
||||||
|
uint256 tokenId,
|
||||||
|
address indexed to,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
}
|
94
contracts/avalanche/connectors/basic-ERC1155/main.sol
Normal file
94
contracts/avalanche/connectors/basic-ERC1155/main.sol
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Basic.
|
||||||
|
* @dev Deposit & Withdraw from ERC1155 DSA.
|
||||||
|
*/
|
||||||
|
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.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 ERC1155 token to DSA
|
||||||
|
* @param token Address of token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param amount Amount to deposit.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setId ID stores the amount.
|
||||||
|
*/
|
||||||
|
function depositERC1155(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amount = getUint(getId, amount);
|
||||||
|
|
||||||
|
IERC1155 tokenContract = IERC1155(token);
|
||||||
|
tokenContract.safeTransferFrom(
|
||||||
|
msg.sender,
|
||||||
|
address(this),
|
||||||
|
tokenId,
|
||||||
|
_amount,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
setUint(setId, _amount);
|
||||||
|
|
||||||
|
_eventName = "LogDepositERC1155(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
token,
|
||||||
|
msg.sender,
|
||||||
|
tokenId,
|
||||||
|
_amount,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Assets To Smart Account.
|
||||||
|
* @notice Withdraw a ERC1155 token from DSA
|
||||||
|
* @param token Address of the token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param to The address to receive the token upon withdrawal
|
||||||
|
* @param amount Amount to withdraw.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setId ID stores the amount.
|
||||||
|
*/
|
||||||
|
function withdrawERC1155(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
address payable to,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amount = getUint(getId, amount);
|
||||||
|
IERC1155 tokenContract = IERC1155(token);
|
||||||
|
tokenContract.safeTransferFrom(address(this), to, tokenId, _amount, "");
|
||||||
|
|
||||||
|
setUint(setId, _amount);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawERC1155(address,uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, tokenId, to, _amount, getId, setId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectV2BasicERC1155Avalanche is BasicResolver {
|
||||||
|
string public constant name = "BASIC-ERC1155-v1.0";
|
||||||
|
}
|
19
contracts/avalanche/connectors/basic-ERC721/events.sol
Normal file
19
contracts/avalanche/connectors/basic-ERC721/events.sol
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogDepositERC721(
|
||||||
|
address indexed erc721,
|
||||||
|
address from,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
event LogWithdrawERC721(
|
||||||
|
address indexed erc721,
|
||||||
|
uint256 tokenId,
|
||||||
|
address indexed to,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
}
|
77
contracts/avalanche/connectors/basic-ERC721/main.sol
Normal file
77
contracts/avalanche/connectors/basic-ERC721/main.sol
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Basic.
|
||||||
|
* @dev Deposit & Withdraw ERC721 from DSA.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
* @param token Address of token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param getId ID to retrieve tokenId.
|
||||||
|
* @param setId ID stores the tokenId.
|
||||||
|
*/
|
||||||
|
function depositERC721(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _tokenId = getUint(getId, tokenId);
|
||||||
|
|
||||||
|
IERC721 tokenContract = IERC721(token);
|
||||||
|
tokenContract.safeTransferFrom(msg.sender, address(this), _tokenId);
|
||||||
|
|
||||||
|
setUint(setId, _tokenId);
|
||||||
|
|
||||||
|
_eventName = "LogDepositERC721(address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, msg.sender, _tokenId, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Assets To Smart Account.
|
||||||
|
* @notice Withdraw a ERC721 token from DSA
|
||||||
|
* @param token Address of the token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param to The address to receive the token upon withdrawal
|
||||||
|
* @param getId ID to retrieve tokenId.
|
||||||
|
* @param setId ID stores the tokenId.
|
||||||
|
*/
|
||||||
|
function withdrawERC721(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
address payable to,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _tokenId = getUint(getId, tokenId);
|
||||||
|
IERC721 tokenContract = IERC721(token);
|
||||||
|
tokenContract.safeTransferFrom(address(this), to, _tokenId);
|
||||||
|
|
||||||
|
setUint(setId, _tokenId);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawERC721(address,uint256,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, _tokenId, to, getId, setId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectV2BasicERC721Avalanche is BasicResolver {
|
||||||
|
string public constant name = "BASIC-ERC721-v1.0";
|
||||||
|
}
|
58
contracts/optimism/common/basic.sol
Normal file
58
contracts/optimism/common/basic.sol
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { TokenInterface } from "./interfaces.sol";
|
||||||
|
import { Stores } from "./stores.sol";
|
||||||
|
import { DSMath } from "./math.sol";
|
||||||
|
|
||||||
|
abstract contract Basic is DSMath, Stores {
|
||||||
|
|
||||||
|
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||||||
|
amt = (_amt / 10 ** (18 - _dec));
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) {
|
||||||
|
amt = mul(_amt, 10 ** (18 - _dec));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTokenBal(TokenInterface token) internal view returns(uint _amt) {
|
||||||
|
_amt = address(token) == ethAddr ? address(this).balance : token.balanceOf(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) {
|
||||||
|
buyDec = address(buyAddr) == ethAddr ? 18 : buyAddr.decimals();
|
||||||
|
sellDec = address(sellAddr) == ethAddr ? 18 : sellAddr.decimals();
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeEvent(string memory eventName, bytes memory eventParam) internal pure returns (bytes memory) {
|
||||||
|
return abi.encode(eventName, eventParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
function approve(TokenInterface token, address spender, uint256 amount) internal {
|
||||||
|
try token.approve(spender, amount) {
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
token.approve(spender, 0);
|
||||||
|
token.approve(spender, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeEthAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){
|
||||||
|
_buy = buy == ethAddr ? TokenInterface(wethAddr) : TokenInterface(buy);
|
||||||
|
_sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeEthAddrToWethAddr(address token) internal pure returns(address tokenAddr){
|
||||||
|
tokenAddr = token == ethAddr ? wethAddr : token;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
|
||||||
|
if(isEth) token.deposit{value: amount}();
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal {
|
||||||
|
if(isEth) {
|
||||||
|
approve(token, address(token), amount);
|
||||||
|
token.withdraw(amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
contracts/optimism/common/interfaces.sol
Normal file
24
contracts/optimism/common/interfaces.sol
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
interface TokenInterface {
|
||||||
|
function approve(address, uint256) external;
|
||||||
|
function transfer(address, uint) external;
|
||||||
|
function transferFrom(address, address, uint) external;
|
||||||
|
function deposit() external payable;
|
||||||
|
function withdraw(uint) external;
|
||||||
|
function balanceOf(address) external view returns (uint);
|
||||||
|
function decimals() external view returns (uint);
|
||||||
|
function totalSupply() external view returns (uint);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MemoryInterface {
|
||||||
|
function getUint(uint id) external returns (uint num);
|
||||||
|
function setUint(uint id, uint val) external;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface AccountInterface {
|
||||||
|
function enable(address) external;
|
||||||
|
function disable(address) external;
|
||||||
|
function isAuth(address) external view returns (bool);
|
||||||
|
}
|
49
contracts/optimism/common/math.sol
Normal file
49
contracts/optimism/common/math.sol
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
|
||||||
|
|
||||||
|
contract DSMath {
|
||||||
|
uint constant WAD = 10 ** 18;
|
||||||
|
uint constant RAY = 10 ** 27;
|
||||||
|
|
||||||
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.add(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub(uint x, uint y) internal virtual pure returns (uint z) {
|
||||||
|
z = SafeMath.sub(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.mul(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function div(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.div(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wmul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rdiv(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rmul(uint x, uint y) internal pure returns (uint z) {
|
||||||
|
z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toInt(uint x) internal pure returns (int y) {
|
||||||
|
y = int(x);
|
||||||
|
require(y >= 0, "int-overflow");
|
||||||
|
}
|
||||||
|
|
||||||
|
function toRad(uint wad) internal pure returns (uint rad) {
|
||||||
|
rad = mul(wad, 10 ** 27);
|
||||||
|
}
|
||||||
|
}
|
35
contracts/optimism/common/stores.sol
Normal file
35
contracts/optimism/common/stores.sol
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
import { MemoryInterface } from "./interfaces.sol";
|
||||||
|
|
||||||
|
abstract contract Stores {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return ethereum address
|
||||||
|
*/
|
||||||
|
address constant internal ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return Wrapped ETH address
|
||||||
|
*/
|
||||||
|
address constant internal wethAddr = 0x4200000000000000000000000000000000000006;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return memory variable address
|
||||||
|
*/
|
||||||
|
MemoryInterface constant internal instaMemory = MemoryInterface(0x3254Ce8f5b1c82431B8f21Df01918342215825C2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Get Uint value from InstaMemory Contract.
|
||||||
|
*/
|
||||||
|
function getUint(uint getId, uint val) internal returns (uint returnVal) {
|
||||||
|
returnVal = getId == 0 ? val : instaMemory.getUint(getId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Set Uint value in InstaMemory Contract.
|
||||||
|
*/
|
||||||
|
function setUint(uint setId, uint val) virtual internal {
|
||||||
|
if (setId != 0) instaMemory.setUint(setId, val);
|
||||||
|
}
|
||||||
|
}
|
21
contracts/optimism/connectors/basic-ERC1155/events.sol
Normal file
21
contracts/optimism/connectors/basic-ERC1155/events.sol
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogDepositERC1155(
|
||||||
|
address indexed erc1155,
|
||||||
|
address from,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
event LogWithdrawERC1155(
|
||||||
|
address indexed erc1155,
|
||||||
|
uint256 tokenId,
|
||||||
|
address indexed to,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
}
|
94
contracts/optimism/connectors/basic-ERC1155/main.sol
Normal file
94
contracts/optimism/connectors/basic-ERC1155/main.sol
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Basic.
|
||||||
|
* @dev Deposit & Withdraw from ERC1155 DSA.
|
||||||
|
*/
|
||||||
|
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.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 ERC1155 token to DSA
|
||||||
|
* @param token Address of token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param amount Amount to deposit.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setId ID stores the amount.
|
||||||
|
*/
|
||||||
|
function depositERC1155(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amount = getUint(getId, amount);
|
||||||
|
|
||||||
|
IERC1155 tokenContract = IERC1155(token);
|
||||||
|
tokenContract.safeTransferFrom(
|
||||||
|
msg.sender,
|
||||||
|
address(this),
|
||||||
|
tokenId,
|
||||||
|
_amount,
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
setUint(setId, _amount);
|
||||||
|
|
||||||
|
_eventName = "LogDepositERC1155(address,address,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
token,
|
||||||
|
msg.sender,
|
||||||
|
tokenId,
|
||||||
|
_amount,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Assets To Smart Account.
|
||||||
|
* @notice Withdraw a ERC1155 token from DSA
|
||||||
|
* @param token Address of the token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param to The address to receive the token upon withdrawal
|
||||||
|
* @param amount Amount to withdraw.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setId ID stores the amount.
|
||||||
|
*/
|
||||||
|
function withdrawERC1155(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
address payable to,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amount = getUint(getId, amount);
|
||||||
|
IERC1155 tokenContract = IERC1155(token);
|
||||||
|
tokenContract.safeTransferFrom(address(this), to, tokenId, _amount, "");
|
||||||
|
|
||||||
|
setUint(setId, _amount);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawERC1155(address,uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, tokenId, to, _amount, getId, setId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectV2BasicERC1155Optimism is BasicResolver {
|
||||||
|
string public constant name = "BASIC-ERC1155-v1.0";
|
||||||
|
}
|
19
contracts/optimism/connectors/basic-ERC721/events.sol
Normal file
19
contracts/optimism/connectors/basic-ERC721/events.sol
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogDepositERC721(
|
||||||
|
address indexed erc721,
|
||||||
|
address from,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
event LogWithdrawERC721(
|
||||||
|
address indexed erc721,
|
||||||
|
uint256 tokenId,
|
||||||
|
address indexed to,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
}
|
77
contracts/optimism/connectors/basic-ERC721/main.sol
Normal file
77
contracts/optimism/connectors/basic-ERC721/main.sol
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Basic.
|
||||||
|
* @dev Deposit & Withdraw ERC721 from DSA.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
* @param token Address of token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param getId ID to retrieve tokenId.
|
||||||
|
* @param setId ID stores the tokenId.
|
||||||
|
*/
|
||||||
|
function depositERC721(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _tokenId = getUint(getId, tokenId);
|
||||||
|
|
||||||
|
IERC721 tokenContract = IERC721(token);
|
||||||
|
tokenContract.safeTransferFrom(msg.sender, address(this), _tokenId);
|
||||||
|
|
||||||
|
setUint(setId, _tokenId);
|
||||||
|
|
||||||
|
_eventName = "LogDepositERC721(address,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, msg.sender, _tokenId, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Assets To Smart Account.
|
||||||
|
* @notice Withdraw a ERC721 token from DSA
|
||||||
|
* @param token Address of the token.
|
||||||
|
* @param tokenId ID of token.
|
||||||
|
* @param to The address to receive the token upon withdrawal
|
||||||
|
* @param getId ID to retrieve tokenId.
|
||||||
|
* @param setId ID stores the tokenId.
|
||||||
|
*/
|
||||||
|
function withdrawERC721(
|
||||||
|
address token,
|
||||||
|
uint256 tokenId,
|
||||||
|
address payable to,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _tokenId = getUint(getId, tokenId);
|
||||||
|
IERC721 tokenContract = IERC721(token);
|
||||||
|
tokenContract.safeTransferFrom(address(this), to, _tokenId);
|
||||||
|
|
||||||
|
setUint(setId, _tokenId);
|
||||||
|
|
||||||
|
_eventName = "LogWithdrawERC721(address,uint256,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(token, _tokenId, to, getId, setId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectV2BasicERC721Optimism is BasicResolver {
|
||||||
|
string public constant name = "BASIC-ERC721-v1.0";
|
||||||
|
}
|
|
@ -25,7 +25,7 @@
|
||||||
"REFINANCE-A": "0x6f22931423e8ffC8d51f6E5aF73118fC64b27856",
|
"REFINANCE-A": "0x6f22931423e8ffC8d51f6E5aF73118fC64b27856",
|
||||||
"INST-A": "0x52C2C4a0db049255fF345EB9D3Fb1f555b7a924A",
|
"INST-A": "0x52C2C4a0db049255fF345EB9D3Fb1f555b7a924A",
|
||||||
"REFLEXER-A": "0xaC6dc28a6251F49Bbe5755E630107Dccde9ae2C8",
|
"REFLEXER-A": "0xaC6dc28a6251F49Bbe5755E630107Dccde9ae2C8",
|
||||||
"GELATO-AAVE-A: "0x825832a5A589ed9500CaEE2aa2D2c3117218D6A9"
|
"GELATO-AAVE-A": "0x825832a5A589ed9500CaEE2aa2D2c3117218D6A9",
|
||||||
"LIQUITY-A": "0x3643bA40B8e2bd8F77233BDB6abe38c218f31bFe",
|
"LIQUITY-A": "0x3643bA40B8e2bd8F77233BDB6abe38c218f31bFe",
|
||||||
"UNISWAP-V3-A": "0x25B0c76dE86C3457b9B8b9ee3775F5a7b8D4c475",
|
"UNISWAP-V3-A": "0x25B0c76dE86C3457b9B8b9ee3775F5a7b8D4c475",
|
||||||
"B-COMPOUND-A": "0xa3EeFDc2de9DFA59968bEcff3E15b53E6162460f",
|
"B-COMPOUND-A": "0xa3EeFDc2de9DFA59968bEcff3E15b53E6162460f",
|
||||||
|
@ -40,7 +40,6 @@
|
||||||
"AAVE-CLAIM-A": "0xC7Cb1dE2721BFC0E0DA1b9D526bCdC54eF1C0eFC",
|
"AAVE-CLAIM-A": "0xC7Cb1dE2721BFC0E0DA1b9D526bCdC54eF1C0eFC",
|
||||||
"PARASWAP-A": "0xFb3a1D56eD56F046721B9aCa749895100754578b",
|
"PARASWAP-A": "0xFb3a1D56eD56F046721B9aCa749895100754578b",
|
||||||
"GELATO-AAAVE-A": "0x177Bd89A1D8643C9525D2DF131C1a6C513869299"
|
"GELATO-AAAVE-A": "0x177Bd89A1D8643C9525D2DF131C1a6C513869299"
|
||||||
"PARASWAP-A": "0xFb3a1D56eD56F046721B9aCa749895100754578b"
|
|
||||||
},
|
},
|
||||||
"arbitrum" : {
|
"arbitrum" : {
|
||||||
"AUTHORITY-A": "0x6ce3e607c808b4f4c26b7f6adaeb619e49cabb25",
|
"AUTHORITY-A": "0x6ce3e607c808b4f4c26b7f6adaeb619e49cabb25",
|
||||||
|
|
|
@ -23,6 +23,7 @@ const chainIds = {
|
||||||
avalanche: 43114,
|
avalanche: 43114,
|
||||||
polygon: 137,
|
polygon: 137,
|
||||||
arbitrum: 42161,
|
arbitrum: 42161,
|
||||||
|
optimism: 10
|
||||||
};
|
};
|
||||||
|
|
||||||
const alchemyApiKey = process.env.ALCHEMY_API_KEY;
|
const alchemyApiKey = process.env.ALCHEMY_API_KEY;
|
||||||
|
@ -50,6 +51,7 @@ function createConfig(network: string) {
|
||||||
return {
|
return {
|
||||||
url: getNetworkUrl(network),
|
url: getNetworkUrl(network),
|
||||||
accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic },
|
accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic },
|
||||||
|
// gasPrice: 1000000, // 0.0001 GWEI
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +62,8 @@ function getNetworkUrl(networkType: string) {
|
||||||
return `https://polygon-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
|
return `https://polygon-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
|
||||||
else if (networkType === "arbitrum")
|
else if (networkType === "arbitrum")
|
||||||
return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
|
return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
|
||||||
|
else if (networkType === "optimism")
|
||||||
|
return `https://opt-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
|
||||||
else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`;
|
else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +115,7 @@ const config: HardhatUserConfig = {
|
||||||
polygon: createConfig("polygon"),
|
polygon: createConfig("polygon"),
|
||||||
avalanche: createConfig("avalanche"),
|
avalanche: createConfig("avalanche"),
|
||||||
arbitrum: createConfig("arbitrum"),
|
arbitrum: createConfig("arbitrum"),
|
||||||
|
optimism: createConfig("optimism"),
|
||||||
},
|
},
|
||||||
paths: {
|
paths: {
|
||||||
artifacts: "./artifacts",
|
artifacts: "./artifacts",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user