Last active
July 9, 2022 17:26
-
-
Save z0r0z/bd21de838999f09ab15641f69c88620d to your computer and use it in GitHub Desktop.
Subsidized transactions for smart contracts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: AGPL-3.0-only | |
pragma solidity >=0.8.4; | |
import {SafeTransferLib} from "https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol"; | |
/// @notice Subsidized transactions for smart contracts. | |
/// @author z0r0z.eth | |
abstract contract Subsidized { | |
using SafeTransferLib for address; | |
modifier subsidized() virtual { | |
uint256 startGas = gasleft(); | |
_; | |
unchecked { | |
tx.origin.safeTransferETH( | |
( | |
startGas - gasleft() | |
) | |
* tx.gasprice | |
); | |
} | |
} | |
} | |
contract SubsidizedTester is Subsidized { | |
uint256 public counter; | |
receive() external payable virtual {} | |
function testCounter() public subsidized virtual { | |
unchecked { | |
++counter; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment