// SPDX-License-Identifier: --🦉--
pragma solidity =0.7.0;
contract RefundSponsor {
address public refundSponsor;
address public sponsoredContract;
bool public isPaused;
uint256 public flushNonce;
uint256 public payoutPercent;
mapping (bytes32 => uint256) public refundAmount;
mapping (address => uint256) public sponsoredAmount;
event RefundIssued(
address refundedTo,
uint256 amount
);
event SponsoredContribution(
address sponsor,
uint256 amount
);
modifier onlySponsor() {
require(
msg.sender == refundSponsor,
'RefundSponsor: not a sponsor'
);
_;
}
receive()
external
payable
{
sponsoredAmount[msg.sender] += msg.value;
emit SponsoredContribution(
msg.sender,
msg.value
);
}
constructor() {
refundSponsor = msg.sender;
payoutPercent = 70;
}
function changePayoutPercent(
uint256 _newPauoutPercent
)
external
onlySponsor
{
payoutPercent = _newPauoutPercent;
}
function setSponsoredContract(address _s)
onlySponsor
external
{
sponsoredContract = _s;
}
function addGasRefund(address _a, uint256 _g)
external
{
if (msg.sender == sponsoredContract && isPaused == false) {
refundAmount[getHash(_a)] += _g;
}
}
function setGasRefund(address _a, uint256 _g)
external
onlySponsor
{
refundAmount[getHash(_a)] = _g;
}
function requestGasRefund()
external
{
require(
isPaused == false,
'RefundSponsor: refunds paused'
);
bytes32 sender = getHash(msg.sender);
require(
refundAmount[sender] > 0,
'RefundSponsor: nothing to refund'
);
uint256 amount = getRefundAmount(msg.sender);
refundAmount[sender] = 0;
msg.sender.transfer(amount);
emit RefundIssued(
msg.sender,
amount
);
}
function myRefundAmount()
external
view
returns (uint256)
{
return getRefundAmount(msg.sender) * payoutPercent / 100;
}
function getRefundAmount(address x)
public
view
returns (uint256)
{
return refundAmount[getHash(x)] * payoutPercent / 100;
}
function getHash(address x)
public
view
returns (bytes32)
{
return keccak256(
abi.encodePacked(x, flushNonce)
);
}
function pause()
external
onlySponsor
{
isPaused = true;
}
function resume()
external
onlySponsor
{
isPaused = false;
}
function flush()
external
onlySponsor
{
flushNonce += 1;
}
}
{
"compilationTarget": {
"RefundSponsor.sol": "RefundSponsor"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"refundedTo","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RefundIssued","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sponsor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SponsoredContribution","type":"event"},{"inputs":[{"internalType":"address","name":"_a","type":"address"},{"internalType":"uint256","name":"_g","type":"uint256"}],"name":"addGasRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newPauoutPercent","type":"uint256"}],"name":"changePayoutPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"flush","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"flushNonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"x","type":"address"}],"name":"getHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"x","type":"address"}],"name":"getRefundAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"myRefundAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"payoutPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"refundAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refundSponsor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"requestGasRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resume","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_a","type":"address"},{"internalType":"uint256","name":"_g","type":"uint256"}],"name":"setGasRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_s","type":"address"}],"name":"setSponsoredContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"sponsoredAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sponsoredContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]