mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	added basic connector: avalanche
This commit is contained in:
		
							parent
							
								
									a7cd775056
								
							
						
					
					
						commit
						18ed3cbd92
					
				
							
								
								
									
										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";
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user