-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Cairo 1+ and OpenZeppelin Contracts for Cairo v0.8.0 (#305)
- Loading branch information
Showing
68 changed files
with
3,422 additions
and
5,685 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,62 @@ | ||
import { withImplicitArgs } from './common-options'; | ||
import type { ContractBuilder, BaseFunction } from './contract'; | ||
import { getSelfArg } from './common-options'; | ||
import type { BaseImplementedTrait, ContractBuilder, ContractFunction } from './contract'; | ||
import { Access, requireAccessControl } from './set-access-control'; | ||
import { defineFunctions } from './utils/define-functions'; | ||
import { defineModules } from './utils/define-modules'; | ||
import { defineComponents } from './utils/define-components'; | ||
import { externalTrait } from './external-trait'; | ||
|
||
export function addPausable(c: ContractBuilder, access: Access, pausableFns: BaseFunction[]) { | ||
c.addModule(modules.Pausable, [], [functions.pause, functions.unpause], false); | ||
export function addPausable(c: ContractBuilder, access: Access) { | ||
c.addComponent(components.PausableComponent, [], false); | ||
|
||
for (const fn of pausableFns) { | ||
setPausable(c, fn); | ||
} | ||
|
||
c.addFunction(functions.paused); | ||
|
||
requireAccessControl(c, functions.pause, access, 'PAUSER'); | ||
requireAccessControl(c, functions.unpause, access, 'PAUSER'); | ||
c.addFunction(externalTrait, functions.pause); | ||
c.addFunction(externalTrait, functions.unpause); | ||
requireAccessControl(c, externalTrait, functions.pause, access, 'PAUSER', 'pauser'); | ||
requireAccessControl(c, externalTrait, functions.unpause, access, 'PAUSER', 'pauser'); | ||
} | ||
|
||
const modules = defineModules( { | ||
Pausable: { | ||
path: 'openzeppelin.security.pausable.library', | ||
useNamespace: true | ||
const components = defineComponents( { | ||
PausableComponent: { | ||
path: 'openzeppelin::security::pausable', | ||
substorage: { | ||
name: 'pausable', | ||
type: 'PausableComponent::Storage', | ||
}, | ||
event: { | ||
name: 'PausableEvent', | ||
type: 'PausableComponent::Event', | ||
}, | ||
impls: [ | ||
{ | ||
name: 'PausableImpl', | ||
value: 'PausableComponent::PausableImpl<ContractState>', | ||
}, | ||
], | ||
internalImpl: { | ||
name: 'PausableInternalImpl', | ||
value: 'PausableComponent::InternalImpl<ContractState>', | ||
}, | ||
}, | ||
}); | ||
|
||
const functions = defineFunctions({ | ||
|
||
paused: { | ||
module: modules.Pausable, | ||
kind: 'view', | ||
implicitArgs: withImplicitArgs(), | ||
args: [], | ||
returns: [{ name: 'paused', type: 'felt' }], | ||
passthrough: true, | ||
parentFunctionName: 'is_paused', | ||
}, | ||
|
||
pause: { | ||
module: modules.Pausable, | ||
kind: 'external', | ||
implicitArgs: withImplicitArgs(), | ||
args: [], | ||
parentFunctionName: '_pause', | ||
args: [ | ||
getSelfArg(), | ||
], | ||
code: [ | ||
'self.pausable._pause()' | ||
] | ||
}, | ||
|
||
unpause: { | ||
module: modules.Pausable, | ||
kind: 'external', | ||
implicitArgs: withImplicitArgs(), | ||
args: [], | ||
parentFunctionName: '_unpause', | ||
}, | ||
|
||
// --- library-only calls --- | ||
|
||
assert_not_paused: { | ||
module: modules.Pausable, | ||
args: [], | ||
args: [ | ||
getSelfArg(), | ||
], | ||
code: [ | ||
'self.pausable._unpause()' | ||
] | ||
}, | ||
|
||
}); | ||
|
||
export function setPausable(c: ContractBuilder, fn: BaseFunction) { | ||
c.addLibraryCall(functions.assert_not_paused, fn); | ||
export function setPausable(c: ContractBuilder, t: BaseImplementedTrait, fn: ContractFunction) { | ||
c.addFunctionCodeBefore(t, fn, 'self.pausable.assert_not_paused()'); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ContractBuilder } from "./contract"; | ||
import { defineComponents } from "./utils/define-components"; | ||
|
||
const components = defineComponents( { | ||
SRC5Component: { | ||
path: 'openzeppelin::introspection::src5', | ||
substorage: { | ||
name: 'src5', | ||
type: 'SRC5Component::Storage', | ||
}, | ||
event: { | ||
name: 'SRC5Event', | ||
type: 'SRC5Component::Event', | ||
}, | ||
impls: [ | ||
{ | ||
name: 'SRC5Impl', | ||
value: 'SRC5Component::SRC5Impl<ContractState>', | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
export function addSRC5Component(c: ContractBuilder) { | ||
c.addComponent(components.SRC5Component, [], false); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.