Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- ERC1155Adapter
- Optimization enabled
- true
- Compiler version
- v0.8.23+commit.f704f362
- Optimization runs
- 999999
- EVM Version
- paris
- Verified at
- 2024-04-16T10:29:34.005154Z
contracts/adapters/ERC1155Adapter.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "../interfaces/IAdapter.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
contract ERC1155Adapter is IAdapter {
/**
* @notice Indicates the ERC165 interfaceId supported by this adapter
*/
bytes4 public constant interfaceId = 0xd9b67a26;
/**
* @notice Checks allowance on an ERC1155
* @param party Party params to check
* @dev Use call: "msg.sender" is Swap contract
*/
function hasAllowance(Party calldata party) external view returns (bool) {
return
IERC1155(party.token).isApprovedForAll(party.wallet, address(msg.sender));
}
/**
* @notice Checks balance on an ERC1155
* @param party Party params to check
*/
function hasBalance(Party calldata party) external view returns (bool) {
return
IERC1155(party.token).balanceOf(party.wallet, party.id) >= party.amount;
}
/**
* @notice Checks params for transfer
* @param party Party params to check
*/
function hasValidParams(Party calldata party) external pure returns (bool) {
return (party.amount != 0);
}
/**
* @notice Function to wrap safeTransferFrom for ERC1155
* @param from address Wallet address to transfer from
* @param to address Wallet address to transfer to
* @param amount uint256 Amount for ERC-1155
* @param id uint256 token ID for ERC-1155
* @param token address Contract address of token
* @dev Use delegatecall: "this" is Swap contract
*/
function transfer(
address from,
address to,
uint256 amount,
uint256 id,
address token
) external {
if (amount == 0) revert AmountOrIDInvalid("amount");
IERC1155(token).safeTransferFrom(from, to, id, amount, "0x00");
}
}
@openzeppelin/contracts/token/ERC1155/IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
contracts/interfaces/IAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
struct Party {
address wallet; // Wallet address of the party
address token; // Contract address of the token
bytes4 kind; // Interface ID of the token
uint256 id; // ID for ERC-721 or ERC-1155
uint256 amount; // Amount for ERC-20 or ERC-1155
}
/**
* @title IAdapter: Adapter for various token kinds
*/
interface IAdapter {
/**
* @notice Revert if provided an invalid transfer argument
*/
error AmountOrIDInvalid(string);
/**
* @notice Return the ERC165 interfaceId this adapter supports
*/
function interfaceId() external view returns (bytes4);
/**
* @notice Checks allowance on a token
* @param party Party params to check
*/
function hasAllowance(Party calldata party) external view returns (bool);
/**
* @notice Checks balance on a token
* @param party Party params to check
*/
function hasBalance(Party calldata party) external view returns (bool);
/**
* @notice Checks params for transfer
* @param party Party params to check
*/
function hasValidParams(Party calldata party) external view returns (bool);
/**
* @notice Function to wrap token transfer for different token types
* @param from address Wallet address to transfer from
* @param to address Wallet address to transfer to
* @param amount uint256 Amount for ERC-20
* @param id token ID for ERC-721
* @param token address Contract address of token
*/
function transfer(
address from,
address to,
uint256 amount,
uint256 id,
address token
) external;
}
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":999999,"enabled":true},"libraries":{},"evmVersion":"paris"}
Contract ABI
[{"type":"error","name":"AmountOrIDInvalid","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasAllowance","inputs":[{"type":"tuple","name":"party","internalType":"struct Party","components":[{"type":"address","name":"wallet","internalType":"address"},{"type":"address","name":"token","internalType":"address"},{"type":"bytes4","name":"kind","internalType":"bytes4"},{"type":"uint256","name":"id","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasBalance","inputs":[{"type":"tuple","name":"party","internalType":"struct Party","components":[{"type":"address","name":"wallet","internalType":"address"},{"type":"address","name":"token","internalType":"address"},{"type":"bytes4","name":"kind","internalType":"bytes4"},{"type":"uint256","name":"id","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasValidParams","inputs":[{"type":"tuple","name":"party","internalType":"struct Party","components":[{"type":"address","name":"wallet","internalType":"address"},{"type":"address","name":"token","internalType":"address"},{"type":"bytes4","name":"kind","internalType":"bytes4"},{"type":"uint256","name":"id","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"interfaceId","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transfer","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"id","internalType":"uint256"},{"type":"address","name":"token","internalType":"address"}]}]
Contract Creation Code
0x608060405234801561001057600080fd5b50610548806100206000396000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c806347338bc31161005057806347338bc3146100ab578063a64d0cd4146100c0578063d1190df91461011857600080fd5b80633170f63d1461006c57806340944de914610094575b600080fd5b61007f61007a36600461041d565b61012b565b60405190151581526020015b60405180910390f35b61007f6100a236600461041d565b60800135151590565b6100be6100b936600461045e565b6101fe565b005b6100e77fd9b67a260000000000000000000000000000000000000000000000000000000081565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161008b565b61007f61012636600461041d565b610340565b600061013d60408301602084016104b5565b73ffffffffffffffffffffffffffffffffffffffff1663e985e9c561016560208501856104b5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152336024820152604401602060405180830381865afa1580156101d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f891906104d7565b92915050565b8260000361026c576040517f94d40be700000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f616d6f756e740000000000000000000000000000000000000000000000000000604482015260640160405180910390fd5b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004808401919091528682166024840152604483018590526064830186905260a0608484015260a48301527f307830300000000000000000000000000000000000000000000000000000000060c483015282169063f242432a9060e401600060405180830381600087803b15801561032157600080fd5b505af1158015610335573d6000803e3d6000fd5b505050505050505050565b6000608082013561035760408401602085016104b5565b73ffffffffffffffffffffffffffffffffffffffff1662fdd58e61037e60208601866104b5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff909116600482015260608601356024820152604401602060405180830381865afa1580156103f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041591906104f9565b101592915050565b600060a0828403121561042f57600080fd5b50919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461045957600080fd5b919050565b600080600080600060a0868803121561047657600080fd5b61047f86610435565b945061048d60208701610435565b935060408601359250606086013591506104a960808701610435565b90509295509295909350565b6000602082840312156104c757600080fd5b6104d082610435565b9392505050565b6000602082840312156104e957600080fd5b815180151581146104d057600080fd5b60006020828403121561050b57600080fd5b505191905056fea26469706673582212201766a0cf2da0cad9a04f5dad3cd74e63b6a20d7a791b15fed915f4b60a8f997a64736f6c63430008170033
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100675760003560e01c806347338bc31161005057806347338bc3146100ab578063a64d0cd4146100c0578063d1190df91461011857600080fd5b80633170f63d1461006c57806340944de914610094575b600080fd5b61007f61007a36600461041d565b61012b565b60405190151581526020015b60405180910390f35b61007f6100a236600461041d565b60800135151590565b6100be6100b936600461045e565b6101fe565b005b6100e77fd9b67a260000000000000000000000000000000000000000000000000000000081565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161008b565b61007f61012636600461041d565b610340565b600061013d60408301602084016104b5565b73ffffffffffffffffffffffffffffffffffffffff1663e985e9c561016560208501856104b5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff9091166004820152336024820152604401602060405180830381865afa1580156101d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f891906104d7565b92915050565b8260000361026c576040517f94d40be700000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f616d6f756e740000000000000000000000000000000000000000000000000000604482015260640160405180910390fd5b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004808401919091528682166024840152604483018590526064830186905260a0608484015260a48301527f307830300000000000000000000000000000000000000000000000000000000060c483015282169063f242432a9060e401600060405180830381600087803b15801561032157600080fd5b505af1158015610335573d6000803e3d6000fd5b505050505050505050565b6000608082013561035760408401602085016104b5565b73ffffffffffffffffffffffffffffffffffffffff1662fdd58e61037e60208601866104b5565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16815273ffffffffffffffffffffffffffffffffffffffff909116600482015260608601356024820152604401602060405180830381865afa1580156103f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061041591906104f9565b101592915050565b600060a0828403121561042f57600080fd5b50919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461045957600080fd5b919050565b600080600080600060a0868803121561047657600080fd5b61047f86610435565b945061048d60208701610435565b935060408601359250606086013591506104a960808701610435565b90509295509295909350565b6000602082840312156104c757600080fd5b6104d082610435565b9392505050565b6000602082840312156104e957600080fd5b815180151581146104d057600080fd5b60006020828403121561050b57600080fd5b505191905056fea26469706673582212201766a0cf2da0cad9a04f5dad3cd74e63b6a20d7a791b15fed915f4b60a8f997a64736f6c63430008170033