TransientSlotMock.js 804 B

1234567891011121314151617181920212223242526272829303132333435
  1. const format = require('../format-lines');
  2. const { TYPES } = require('./Slot.opts');
  3. const header = `\
  4. pragma solidity ^0.8.24;
  5. import {Multicall} from "../utils/Multicall.sol";
  6. import {TransientSlot} from "../utils/TransientSlot.sol";
  7. `;
  8. const transient = ({ type, name }) => `\
  9. event ${name}Value(bytes32 slot, ${type} value);
  10. function tload${name}(bytes32 slot) public {
  11. emit ${name}Value(slot, slot.as${name}().tload());
  12. }
  13. function tstore(bytes32 slot, ${type} value) public {
  14. slot.as${name}().tstore(value);
  15. }
  16. `;
  17. // GENERATE
  18. module.exports = format(
  19. header,
  20. 'contract TransientSlotMock is Multicall {',
  21. format(
  22. [].concat(
  23. 'using TransientSlot for *;',
  24. '',
  25. TYPES.filter(type => type.isValueType).map(type => transient(type)),
  26. ),
  27. ).trimEnd(),
  28. '}',
  29. );