|
| 1 | +import { getSelfArg } from './common-options'; |
| 2 | +import type { ContractBuilder } from './contract'; |
| 3 | +import type { Access } from './set-access-control'; |
| 4 | +import { requireAccessControl } from './set-access-control'; |
| 5 | +import { defineFunctions } from './utils/define-functions'; |
| 6 | + |
| 7 | +export function addPausable(c: ContractBuilder, access: Access) { |
| 8 | + c.addUseClause('openzeppelin_pausable', 'self', { alias: 'pausable' }); |
| 9 | + c.addUseClause('openzeppelin_pausable', 'Pausable'); |
| 10 | + |
| 11 | + const pausableTrait = { |
| 12 | + name: 'Pausable', |
| 13 | + for: c.name, |
| 14 | + tags: ['contractimpl'], |
| 15 | + section: 'Utils', |
| 16 | + }; |
| 17 | + |
| 18 | + c.addFunction(pausableTrait, functions.paused); |
| 19 | + c.addFunction(pausableTrait, functions.pause); |
| 20 | + c.addFunction(pausableTrait, functions.unpause); |
| 21 | + |
| 22 | + requireAccessControl(c, pausableTrait, functions.pause, access, 'caller'); |
| 23 | + requireAccessControl(c, pausableTrait, functions.unpause, access, 'caller'); |
| 24 | +} |
| 25 | + |
| 26 | +const functions = defineFunctions({ |
| 27 | + paused: { |
| 28 | + args: [getSelfArg()], |
| 29 | + returns: 'bool', |
| 30 | + code: ['pausable::paused(e)'], |
| 31 | + }, |
| 32 | + pause: { |
| 33 | + args: [getSelfArg(), { name: 'caller', type: 'Address' }], |
| 34 | + code: ['pausable::pause(e, &caller)'], |
| 35 | + }, |
| 36 | + unpause: { |
| 37 | + args: [getSelfArg(), { name: 'caller', type: 'Address' }], |
| 38 | + code: ['pausable::unpause(e, &caller)'], |
| 39 | + }, |
| 40 | +}); |
0 commit comments