GalaTreasureChestClaimFee
Deploy on AlchemyContract Information
The following smart contract is called GalaTreasureChestClaimFee and it is used for executing payments. It imports the MessageValidator contract and inherits its functions. The pay function takes in a reference ID, amount, block signed, and a signature. It then validates the message and transfers the payment to the signer address. An event is emitted after the payment is executed.
More Info
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import './MessageValidator.sol';
contract GalaTreasureChestClaimFee is MessageValidator {
event PaymentExecuted(string refId, uint256 amount, uint256 blockSigned);
constructor(address _signer) {
setSignerAddress(_signer);
}
function pay(
string memory refId,
uint256 amount,
uint256 blockSigned,
bytes memory sig
)
public
payable
isValidMessage(refId, amount, blockSigned, sig, msg.value)
{
payable(address(signerAddress)).transfer(msg.value);
emit PaymentExecuted(refId, msg.value, blockSigned);
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import '@openzeppelin/contracts/access/Ownable.sol';
contract MessageValidator is Ownable {
address public signerAddress;
uint256 public blockMaxThreshold = 10;
function setSignerAddress(address _signer) public onlyOwner {
signerAddress = _signer;
}
modifier isValidMessage(
string memory refId,
uint256 amount,
uint256 blockSigned,
bytes memory sig,
uint256 value
) {
bytes32 message = keccak256(
abi.encodePacked(refId, amount, blockSigned)
);
require(
recoverSigner(message, sig) == signerAddress,
'Invalid signature'
);
require(
(block.number - blockSigned) <= blockMaxThreshold,
'Signature expired'
);
require(value >= amount, 'Invalid amount');
_;
}
function recoverSigner(bytes32 message, bytes memory sig)
internal
pure
returns (address)
{
uint8 v;
bytes32 r;
bytes32 s;
(v, r, s) = splitSignature(sig);
return ecrecover(message, v, r, s);
}
function splitSignature(bytes memory sig)
internal
pure
returns (
uint8,
bytes32,
bytes32
)
{
require(sig.length == 65, 'Signature must be 65 bytes long');
bytes32 r;
bytes32 s;
uint8 v;
assembly {
// first 32 bytes, after the length prefix
r := mload(add(sig, 32))
// second 32 bytes
s := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes)
v := byte(0, mload(add(sig, 96)))
}
return (v, r, s);
}
function setBlockMaxThreshold(uint256 _blockThreshold) public onlyOwner {
blockMaxThreshold = _blockThreshold;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
[{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"refId","type":"string"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockSigned","type":"uint256"}],"name":"PaymentExecuted","type":"event"},{"inputs":[],"name":"blockMaxThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"refId","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"blockSigned","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"pay","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_blockThreshold","type":"uint256"}],"name":"setBlockMaxThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"setSignerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
[{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"refId","type":"string"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"blockSigned","type":"uint256"}],"name":"PaymentExecuted","type":"event"},{"inputs":[],"name":"blockMaxThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"refId","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"blockSigned","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"pay","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_blockThreshold","type":"uint256"}],"name":"setBlockMaxThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"setSignerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
6080604052600a60025534801561001557600080fd5b5060405161096538038061096583398101604081905261003491610126565b61003d3361004c565b6100468161009c565b50610156565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6100a46100c6565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146101245760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640160405180910390fd5b565b60006020828403121561013857600080fd5b81516001600160a01b038116811461014f57600080fd5b9392505050565b610800806101656000396000f3fe60806040526004361061007b5760003560e01c8063715018a61161004e578063715018a6146101165780638b6bbb621461012b5780638da5cb5b1461014b578063f2fde38b1461016957600080fd5b8063046dc1661461008057806321be1fca146100a2578063478d3267146100cb5780635b7633d0146100de575b600080fd5b34801561008c57600080fd5b506100a061009b366004610595565b610189565b005b3480156100ae57600080fd5b506100b860025481565b6040519081526020015b60405180910390f35b6100a06100d9366004610651565b6101b3565b3480156100ea57600080fd5b506001546100fe906001600160a01b031681565b6040516001600160a01b0390911681526020016100c2565b34801561012257600080fd5b506100a0610360565b34801561013757600080fd5b506100a06101463660046106f3565b610374565b34801561015757600080fd5b506000546001600160a01b03166100fe565b34801561017557600080fd5b506100a0610184366004610595565b610381565b6101916103fa565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b838383833460008585856040516020016101cf9392919061073c565b60408051601f1981840301815291905280516020909101206001549091506001600160a01b03166102008285610454565b6001600160a01b03161461024f5760405162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b60448201526064015b60405180910390fd5b60025461025c8543610763565b111561029e5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b6044820152606401610246565b848210156102df5760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a5908185b5bdd5b9d60921b6044820152606401610246565b6001546040516001600160a01b03909116903480156108fc02916000818181858888f19350505050158015610318573d6000803e3d6000fd5b507fe56ca6e9a81874e5a0d13f616127ff156f98b8c2546e7810b271bdfac7cadfb18a348a60405161034c93929190610788565b60405180910390a150505050505050505050565b6103686103fa565b61037260006104d3565b565b61037c6103fa565b600255565b6103896103fa565b6001600160a01b0381166103ee5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610246565b6103f7816104d3565b50565b6000546001600160a01b031633146103725760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610246565b60008060008061046385610523565b6040805160008152602081018083528b905260ff8516918101919091526060810183905260808101829052929550909350915060019060a0016020604051602081039080840390855afa1580156104be573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600083516041146105795760405162461bcd60e51b815260206004820152601f60248201527f5369676e6174757265206d757374206265203635206279746573206c6f6e67006044820152606401610246565b5050506020810151604082015160609092015160001a92909190565b6000602082840312156105a757600080fd5b81356001600160a01b03811681146105be57600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff808411156105f6576105f66105c5565b604051601f8501601f19908116603f0116810190828211818310171561061e5761061e6105c5565b8160405280935085815286868601111561063757600080fd5b858560208301376000602087830101525050509392505050565b6000806000806080858703121561066757600080fd5b843567ffffffffffffffff8082111561067f57600080fd5b818701915087601f83011261069357600080fd5b6106a2888335602085016105db565b9550602087013594506040870135935060608701359150808211156106c657600080fd5b508501601f810187136106d857600080fd5b6106e7878235602084016105db565b91505092959194509250565b60006020828403121561070557600080fd5b5035919050565b60005b8381101561072757818101518382015260200161070f565b83811115610736576000848401525b50505050565b6000845161074e81846020890161070c565b91909101928352506020820152604001919050565b60008282101561078357634e487b7160e01b600052601160045260246000fd5b500390565b60608152600084518060608401526107a781608085016020890161070c565b60208301949094525060408101919091526080601f909201601f1916010191905056fea2646970667358221220e489ef4c921a632d3ea4baa8f56abaf756dfdcf2f46b735b996a1881a3034bc064736f6c634300080b0033000000000000000000000000ea985e309d82b653f2e36151462f8908133c7573
6080604052600a60025534801561001557600080fd5b5060405161096538038061096583398101604081905261003491610126565b61003d3361004c565b6100468161009c565b50610156565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6100a46100c6565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146101245760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640160405180910390fd5b565b60006020828403121561013857600080fd5b81516001600160a01b038116811461014f57600080fd5b9392505050565b610800806101656000396000f3fe60806040526004361061007b5760003560e01c8063715018a61161004e578063715018a6146101165780638b6bbb621461012b5780638da5cb5b1461014b578063f2fde38b1461016957600080fd5b8063046dc1661461008057806321be1fca146100a2578063478d3267146100cb5780635b7633d0146100de575b600080fd5b34801561008c57600080fd5b506100a061009b366004610595565b610189565b005b3480156100ae57600080fd5b506100b860025481565b6040519081526020015b60405180910390f35b6100a06100d9366004610651565b6101b3565b3480156100ea57600080fd5b506001546100fe906001600160a01b031681565b6040516001600160a01b0390911681526020016100c2565b34801561012257600080fd5b506100a0610360565b34801561013757600080fd5b506100a06101463660046106f3565b610374565b34801561015757600080fd5b506000546001600160a01b03166100fe565b34801561017557600080fd5b506100a0610184366004610595565b610381565b6101916103fa565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b838383833460008585856040516020016101cf9392919061073c565b60408051601f1981840301815291905280516020909101206001549091506001600160a01b03166102008285610454565b6001600160a01b03161461024f5760405162461bcd60e51b8152602060048201526011602482015270496e76616c6964207369676e617475726560781b60448201526064015b60405180910390fd5b60025461025c8543610763565b111561029e5760405162461bcd60e51b815260206004820152601160248201527014da59db985d1d5c9948195e1c1a5c9959607a1b6044820152606401610246565b848210156102df5760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a5908185b5bdd5b9d60921b6044820152606401610246565b6001546040516001600160a01b03909116903480156108fc02916000818181858888f19350505050158015610318573d6000803e3d6000fd5b507fe56ca6e9a81874e5a0d13f616127ff156f98b8c2546e7810b271bdfac7cadfb18a348a60405161034c93929190610788565b60405180910390a150505050505050505050565b6103686103fa565b61037260006104d3565b565b61037c6103fa565b600255565b6103896103fa565b6001600160a01b0381166103ee5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610246565b6103f7816104d3565b50565b6000546001600160a01b031633146103725760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610246565b60008060008061046385610523565b6040805160008152602081018083528b905260ff8516918101919091526060810183905260808101829052929550909350915060019060a0016020604051602081039080840390855afa1580156104be573d6000803e3d6000fd5b5050604051601f190151979650505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600083516041146105795760405162461bcd60e51b815260206004820152601f60248201527f5369676e6174757265206d757374206265203635206279746573206c6f6e67006044820152606401610246565b5050506020810151604082015160609092015160001a92909190565b6000602082840312156105a757600080fd5b81356001600160a01b03811681146105be57600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff808411156105f6576105f66105c5565b604051601f8501601f19908116603f0116810190828211818310171561061e5761061e6105c5565b8160405280935085815286868601111561063757600080fd5b858560208301376000602087830101525050509392505050565b6000806000806080858703121561066757600080fd5b843567ffffffffffffffff8082111561067f57600080fd5b818701915087601f83011261069357600080fd5b6106a2888335602085016105db565b9550602087013594506040870135935060608701359150808211156106c657600080fd5b508501601f810187136106d857600080fd5b6106e7878235602084016105db565b91505092959194509250565b60006020828403121561070557600080fd5b5035919050565b60005b8381101561072757818101518382015260200161070f565b83811115610736576000848401525b50505050565b6000845161074e81846020890161070c565b91909101928352506020820152604001919050565b60008282101561078357634e487b7160e01b600052601160045260246000fd5b500390565b60608152600084518060608401526107a781608085016020890161070c565b60208301949094525060408101919091526080601f909201601f1916010191905056fea2646970667358221220e489ef4c921a632d3ea4baa8f56abaf756dfdcf2f46b735b996a1881a3034bc064736f6c634300080b0033000000000000000000000000ea985e309d82b653f2e36151462f8908133c7573