mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	Merge pull request #117 from Instadapp/fantom-connectors-deployment
Fantom connectors deployment
This commit is contained in:
		
						commit
						6ed8d1a6ec
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -63,4 +63,5 @@ build/contracts | ||||||
| # buidler | # buidler | ||||||
| artifacts | artifacts | ||||||
| cache | cache | ||||||
| typechain | typechain | ||||||
|  | 
 | ||||||
|  |  | ||||||
							
								
								
									
										54
									
								
								contracts/fantom/common/basic.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								contracts/fantom/common/basic.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,54 @@ | ||||||
|  | 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) == ftmAddr ? address(this).balance : token.balanceOf(address(this)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) { | ||||||
|  |         buyDec = address(buyAddr) == ftmAddr ?  18 : buyAddr.decimals(); | ||||||
|  |         sellDec = address(sellAddr) == ftmAddr ?  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 changeftmAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){ | ||||||
|  |         _buy = buy == ftmAddr ? TokenInterface(wftmAddr) : TokenInterface(buy); | ||||||
|  |         _sell = sell == ftmAddr ? TokenInterface(wftmAddr) : TokenInterface(sell); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | }  | ||||||
							
								
								
									
										22
									
								
								contracts/fantom/common/interfaces.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								contracts/fantom/common/interfaces.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | ||||||
|  | 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); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 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); | ||||||
|  | } | ||||||
							
								
								
									
										50
									
								
								contracts/fantom/common/math.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								contracts/fantom/common/math.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | ||||||
|  | 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); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										37
									
								
								contracts/fantom/common/stores.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								contracts/fantom/common/stores.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | import { MemoryInterface } from "./interfaces.sol"; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | abstract contract Stores { | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * @dev Return FTM address | ||||||
|  |    */ | ||||||
|  |   address constant internal ftmAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * @dev Return Wrapped FTM address | ||||||
|  |    */ | ||||||
|  |   address constant internal wftmAddr = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83; | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * @dev Return memory variable address | ||||||
|  |    */ | ||||||
|  |   MemoryInterface constant internal instaMemory = MemoryInterface(0x56439117379A53bE3CC2C55217251e2481B7a1C8); | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * @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); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								contracts/fantom/connectors/authority/events.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								contracts/fantom/connectors/authority/events.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | contract Events { | ||||||
|  |     event LogAddAuth(address indexed _msgSender, address indexed _authority); | ||||||
|  |     event LogRemoveAuth(address indexed _msgSender, address indexed _authority); | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								contracts/fantom/connectors/authority/helpers.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								contracts/fantom/connectors/authority/helpers.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | pragma experimental ABIEncoderV2; | ||||||
|  | 
 | ||||||
|  | import { DSMath } from "../../common/math.sol"; | ||||||
|  | import { Basic } from "../../common/basic.sol"; | ||||||
|  | import { ListInterface } from "./interface.sol"; | ||||||
|  | 
 | ||||||
|  | abstract contract Helpers is DSMath, Basic { | ||||||
|  |     ListInterface internal constant listContract = ListInterface(0x3565F6057b7fFE36984779A507fC87b31EFb0f09); | ||||||
|  | 
 | ||||||
|  |     function checkAuthCount() internal view returns (uint count) { | ||||||
|  |         uint64 accountId = listContract.accountID(address(this)); | ||||||
|  |         count = listContract.accountLink(accountId).count; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								contracts/fantom/connectors/authority/interface.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								contracts/fantom/connectors/authority/interface.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | pragma experimental ABIEncoderV2; | ||||||
|  | 
 | ||||||
|  | interface ListInterface { | ||||||
|  |     struct AccountLink { | ||||||
|  |         address first; | ||||||
|  |         address last; | ||||||
|  |         uint64 count; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     function accountID(address) external view returns (uint64); | ||||||
|  |     function accountLink(uint64) external view returns (AccountLink memory); | ||||||
|  | } | ||||||
							
								
								
									
										45
									
								
								contracts/fantom/connectors/authority/main.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								contracts/fantom/connectors/authority/main.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @title Authority. | ||||||
|  |  * @dev Manage Authorities to DSA. | ||||||
|  |  */ | ||||||
|  |   | ||||||
|  | import { AccountInterface } from "../../common/interfaces.sol"; | ||||||
|  | import { Helpers } from "./helpers.sol"; | ||||||
|  | import { Events } from "./events.sol"; | ||||||
|  | 
 | ||||||
|  | abstract contract AuthorityResolver is Events, Helpers { | ||||||
|  |     /** | ||||||
|  |      * @dev Add New authority | ||||||
|  |      * @notice Add an address as account authority | ||||||
|  |      * @param authority The authority Address. | ||||||
|  |      */ | ||||||
|  |     function add( | ||||||
|  |         address authority | ||||||
|  |     ) external payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         AccountInterface(address(this)).enable(authority); | ||||||
|  | 
 | ||||||
|  |         _eventName = "LogAddAuth(address,address)"; | ||||||
|  |         _eventParam = abi.encode(msg.sender, authority); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @dev Remove authority | ||||||
|  |      * @notice Remove an address as account authority | ||||||
|  |      * @param authority The authority Address. | ||||||
|  |      */ | ||||||
|  |     function remove( | ||||||
|  |         address authority | ||||||
|  |     ) external payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         require(checkAuthCount() > 1, "Removing-all-authorities"); | ||||||
|  |         AccountInterface(address(this)).disable(authority); | ||||||
|  | 
 | ||||||
|  |         _eventName = "LogRemoveAuth(address,address)"; | ||||||
|  |         _eventParam = abi.encode(msg.sender, authority); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | contract ConnectV2AuthFantom is AuthorityResolver { | ||||||
|  |     string public constant name = "Auth-v1"; | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								contracts/fantom/connectors/basic-ERC1155/events.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								contracts/fantom/connectors/basic-ERC1155/events.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | ||||||
|  | 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 | ||||||
|  |     ); | ||||||
|  | } | ||||||
							
								
								
									
										93
									
								
								contracts/fantom/connectors/basic-ERC1155/main.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								contracts/fantom/connectors/basic-ERC1155/main.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,93 @@ | ||||||
|  | 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 ConnectV2BasicERC1155Fantom is BasicResolver { | ||||||
|  |     string public constant name = "BASIC-ERC1155-v1.0"; | ||||||
|  | } | ||||||
							
								
								
									
										18
									
								
								contracts/fantom/connectors/basic-ERC721/events.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								contracts/fantom/connectors/basic-ERC721/events.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | ||||||
|  | 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 | ||||||
|  |     ); | ||||||
|  | } | ||||||
							
								
								
									
										76
									
								
								contracts/fantom/connectors/basic-ERC721/main.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								contracts/fantom/connectors/basic-ERC721/main.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,76 @@ | ||||||
|  | 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 ConnectV2BasicERC721Fantom is BasicResolver { | ||||||
|  |     string public constant name = "BASIC-ERC721-v1.0"; | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								contracts/fantom/connectors/basic/events.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								contracts/fantom/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); | ||||||
|  | } | ||||||
							
								
								
									
										82
									
								
								contracts/fantom/connectors/basic/main.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								contracts/fantom/connectors/basic/main.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,82 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @title Basic. | ||||||
|  |  * @dev Deposit & Withdraw from DSA. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 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. | ||||||
|  |      * @notice Deposit a token to DSA | ||||||
|  |      * @param token The address of the token to deposit. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||||
|  |      * @param amt The amount of tokens to deposit. (For max: `uint256(-1)` (Not valid for MATIC)) | ||||||
|  |      * @param getId ID to retrieve amt. | ||||||
|  |      * @param setId ID stores the amount of tokens deposited. | ||||||
|  |      */ | ||||||
|  |     function deposit( | ||||||
|  |         address token, | ||||||
|  |         uint256 amt, | ||||||
|  |         uint256 getId, | ||||||
|  |         uint256 setId | ||||||
|  |     ) public payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         uint _amt = getUint(getId, amt); | ||||||
|  |         if (token != ftmAddr) { | ||||||
|  |             IERC20 tokenContract = IERC20(token); | ||||||
|  |             _amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt; | ||||||
|  |             tokenContract.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(token, _amt, getId, setId); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @dev Withdraw Assets from Smart  Account | ||||||
|  |      * @notice Withdraw a token from DSA | ||||||
|  |      * @param token The address of the token to withdraw. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) | ||||||
|  |      * @param amt The amount of tokens to withdraw. (For max: `uint256(-1)`) | ||||||
|  |      * @param to The address to receive the token upon withdrawal | ||||||
|  |      * @param getId ID to retrieve amt. | ||||||
|  |      * @param setId ID stores the amount of tokens withdrawn. | ||||||
|  |      */ | ||||||
|  |     function withdraw( | ||||||
|  |         address token, | ||||||
|  |         uint amt, | ||||||
|  |         address payable to, | ||||||
|  |         uint getId, | ||||||
|  |         uint setId | ||||||
|  |     ) public payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         uint _amt = getUint(getId, amt); | ||||||
|  |         if (token == ftmAddr) { | ||||||
|  |             _amt = _amt == uint(-1) ? address(this).balance : _amt; | ||||||
|  |             to.call{value: _amt}(""); | ||||||
|  |         } else { | ||||||
|  |             IERC20 tokenContract = IERC20(token); | ||||||
|  |             _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; | ||||||
|  |             tokenContract.safeTransfer(to, _amt); | ||||||
|  |         } | ||||||
|  |         setUint(setId, _amt); | ||||||
|  | 
 | ||||||
|  |         _eventName = "LogWithdraw(address,uint256,address,uint256,uint256)"; | ||||||
|  |         _eventParam = abi.encode(token, _amt, to, getId, setId); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | contract ConnectV2BasicFantom is BasicResolver { | ||||||
|  |     string constant public name = "Basic-v1"; | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								contracts/fantom/connectors/wftm/events.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								contracts/fantom/connectors/wftm/events.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | contract Events { | ||||||
|  |     event LogDeposit(uint256 tokenAmt, uint256 getId, uint256 setId); | ||||||
|  |     event LogWithdraw(uint256 tokenAmt, uint256 getId, uint256 setId); | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								contracts/fantom/connectors/wftm/helpers.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								contracts/fantom/connectors/wftm/helpers.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | import { TokenInterface } from "../../common/interfaces.sol"; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | abstract contract Helpers  { | ||||||
|  |     TokenInterface constant internal wftmContract = TokenInterface(0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83); | ||||||
|  | } | ||||||
							
								
								
									
										65
									
								
								contracts/fantom/connectors/wftm/main.sol
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								contracts/fantom/connectors/wftm/main.sol
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,65 @@ | ||||||
|  | pragma solidity ^0.7.0; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * @title WFTM. | ||||||
|  |  * @dev Wrap and Unwrap WFTM. | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | import { DSMath } from "../../common/math.sol"; | ||||||
|  | import { Basic } from "../../common/basic.sol"; | ||||||
|  | import { Events } from "./events.sol"; | ||||||
|  | import { Helpers } from "./helpers.sol"; | ||||||
|  | 
 | ||||||
|  | abstract contract Resolver is Events, DSMath, Basic, Helpers { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @dev Deposit FTM into WFTM. | ||||||
|  |      * @notice Wrap FTM into WFTM | ||||||
|  |      * @param amt The amount of FTM to deposit. (For max: `uint256(-1)`) | ||||||
|  |      * @param getId ID to retrieve amt. | ||||||
|  |      * @param setId ID stores the amount of FTM deposited. | ||||||
|  |      */ | ||||||
|  |     function deposit( | ||||||
|  |         uint256 amt, | ||||||
|  |         uint256 getId, | ||||||
|  |         uint256 setId | ||||||
|  |     ) public payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         uint _amt = getUint(getId, amt); | ||||||
|  | 
 | ||||||
|  |         _amt = _amt == uint(-1) ? address(this).balance : _amt; | ||||||
|  |         wftmContract.deposit{value: _amt}(); | ||||||
|  |          | ||||||
|  |         setUint(setId, _amt); | ||||||
|  | 
 | ||||||
|  |         _eventName = "LogDeposit(uint256,uint256,uint256)"; | ||||||
|  |         _eventParam = abi.encode(_amt, getId, setId); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @dev Withdraw FTM from WFTM from Smart  Account | ||||||
|  |      * @notice Unwrap FTM from WFTM | ||||||
|  |      * @param amt The amount of wFTM to withdraw. (For max: `uint256(-1)`) | ||||||
|  |      * @param getId ID to retrieve amt. | ||||||
|  |      * @param setId ID stores the amount of FTM withdrawn. | ||||||
|  |      */ | ||||||
|  |     function withdraw( | ||||||
|  |         uint amt, | ||||||
|  |         uint getId, | ||||||
|  |         uint setId | ||||||
|  |     ) public payable returns (string memory _eventName, bytes memory _eventParam) { | ||||||
|  |         uint _amt = getUint(getId, amt); | ||||||
|  | 
 | ||||||
|  |         _amt = _amt == uint(-1) ? wftmContract.balanceOf(address(this)) : _amt; | ||||||
|  |         approve(wftmContract, wftmAddr, _amt); | ||||||
|  |         wftmContract.withdraw(_amt); | ||||||
|  | 
 | ||||||
|  |         setUint(setId, _amt); | ||||||
|  | 
 | ||||||
|  |         _eventName = "LogWithdraw(uint256,uint256,uint256)"; | ||||||
|  |         _eventParam = abi.encode(_amt, getId, setId); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | contract ConnectV2WFTMFantom is Resolver { | ||||||
|  |     string constant public name = "WFTM-v1.0"; | ||||||
|  | } | ||||||
|  | @ -49,6 +49,12 @@ | ||||||
|       "UNISWAP-V3-A": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2", |       "UNISWAP-V3-A": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2", | ||||||
|       "1INCH-A": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB", |       "1INCH-A": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB", | ||||||
|       "WETH-A": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD" |       "WETH-A": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD" | ||||||
|  |     }, | ||||||
|  |     "fantom" : { | ||||||
|  |       "AUTHORITY-A": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", | ||||||
|  |       "BASIC-A": "0x9926955e0dd681dc303370c52f4ad0a4dd061687", | ||||||
|  |       "BASIC-B": "0x8dA60dee0815a08d16C066b07814b10722fA9306", | ||||||
|  |       "BASIC-C": "0x2EadEecf1aB9283a9F76D219CF17eeD4932B8811" | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "mappings": { |   "mappings": { | ||||||
|  |  | ||||||
|  | @ -24,7 +24,8 @@ const chainIds = { | ||||||
|   avalanche: 43114, |   avalanche: 43114, | ||||||
|   polygon: 137, |   polygon: 137, | ||||||
|   arbitrum: 42161, |   arbitrum: 42161, | ||||||
|   optimism: 10 |   optimism: 10, | ||||||
|  |   fantom:250 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const alchemyApiKey = process.env.ALCHEMY_API_KEY; | const alchemyApiKey = process.env.ALCHEMY_API_KEY; | ||||||
|  | @ -38,6 +39,7 @@ const POLYGONSCAN_API = process.env.POLYGON_API_KEY; | ||||||
| const ARBISCAN_API = process.env.ARBISCAN_API_KEY; | const ARBISCAN_API = process.env.ARBISCAN_API_KEY; | ||||||
| const OPTIMISM_API = process.env.OPTIMISM_API_KEY; | const OPTIMISM_API = process.env.OPTIMISM_API_KEY; | ||||||
| const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY; | const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY; | ||||||
|  | const FANTOMSCAN_API = process.env.FANTOM_API_KEY; | ||||||
| const mnemonic = | const mnemonic = | ||||||
|   process.env.MNEMONIC ?? |   process.env.MNEMONIC ?? | ||||||
|   "test test test test test test test test test test test junk"; |   "test test test test test test test test test test test junk"; | ||||||
|  | @ -66,6 +68,8 @@ function getNetworkUrl(networkType: string) { | ||||||
|     return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; |     return `https://arb-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; | ||||||
|   else if (networkType === "optimism") |   else if (networkType === "optimism") | ||||||
|     return `https://opt-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; |     return `https://opt-mainnet.g.alchemy.com/v2/${alchemyApiKey}`; | ||||||
|  |   else if(networkType === "fantom") | ||||||
|  |     return `https://rpc.ftm.tools/` | ||||||
|   else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`; |   else return `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -73,6 +77,7 @@ function getScanApiKey(networkType: string) { | ||||||
|   if (networkType === "avalanche") return SNOWTRACE_API; |   if (networkType === "avalanche") return SNOWTRACE_API; | ||||||
|   else if (networkType === "polygon") return POLYGONSCAN_API; |   else if (networkType === "polygon") return POLYGONSCAN_API; | ||||||
|   else if (networkType === "arbitrum") return ARBISCAN_API; |   else if (networkType === "arbitrum") return ARBISCAN_API; | ||||||
|  |   else if(networkType === "fantom") return FANTOMSCAN_API; | ||||||
|   else if (networkType === "optimism") return OPTIMISM_API; |   else if (networkType === "optimism") return OPTIMISM_API; | ||||||
|   else return ETHERSCAN_API; |   else return ETHERSCAN_API; | ||||||
| } | } | ||||||
|  | @ -118,6 +123,7 @@ const config: HardhatUserConfig = { | ||||||
|     avalanche: createConfig("avalanche"), |     avalanche: createConfig("avalanche"), | ||||||
|     arbitrum: createConfig("arbitrum"), |     arbitrum: createConfig("arbitrum"), | ||||||
|     optimism: createConfig("optimism"), |     optimism: createConfig("optimism"), | ||||||
|  |     fantom: createConfig("fantom"), | ||||||
|   }, |   }, | ||||||
|   paths: { |   paths: { | ||||||
|     artifacts: "./artifacts", |     artifacts: "./artifacts", | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 0xPradyuman
						0xPradyuman