From b38f3f6e2c06b5337de33e061a43820d4156a00a Mon Sep 17 00:00:00 2001 From: louis-md Date: Thu, 21 Nov 2024 15:04:08 +0100 Subject: [PATCH] docs: Add Safe smart account reference (#624) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Owner and module functions * Remaining events and functions * Add redirections for root folders * Fix vale errors * Implement requested changes (owners) * Fix links * Various fixes * Format files * Minor fix * Implement requested changes (utilities) * Implement requested changes (fallback) * Implement requested changes (guards) * Implement requested changes (modules) * Implement requested changes (signatures) * Implement requested changes (setup) * Implement requested changes (transactions) * Various fixes * Fix vale errors * Fix redirections * Fix missing imports * Implement requested formatting; add and remove white spaces; implement requested indentation; * Implement requested indentation; * Fix indentation * Capitalize module guards * Edit definition for setModuleGuard * Update pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Fix indentation * Edit definition for execTransactionFromModuleReturnData * Update pages/reference-smart-account/modules/execTransactionFromModule.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Update pages/reference-smart-account/modules/execTransactionFromModule.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Update pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Update pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Update pages/reference-smart-account/owners/getThreshold.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Update pages/reference-smart-account/owners/swapOwner.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Edit wording * Fix indentation * Update pages/reference-smart-account/modules/enableModule.mdx Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> * Edit definition for enableModule * Implement requested changes * Update pages/reference-smart-account/transactions/encodeTransactionData.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/signatures/checkNSignatures.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/transactions/execTransaction.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/transactions/execTransaction.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/modules/execTransactionFromModule.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/signatures/checkNSignatures.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/modules/isModuleEnabled.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/modules/getModulesPaginated.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/guards/setGuard.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/guards/setGuard.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/fallback/receive.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/signatures/checkNSignatures.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Update pages/reference-smart-account/signatures/checkNSignatures.mdx Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> * Implement requested changes * Make `prevOwner` definition more detailed * Fix typos * Update pages/reference-smart-account/signatures/checkSignatures.mdx * Add Smart account version to reference index * Factorize callouts * Factorize callouts * Disambiguate `0`, `0x`, `0x...` and `address(0)` --------- Co-authored-by: Germán Martínez <6764315+germartinez@users.noreply.github.com> Co-authored-by: Germán Martínez Co-authored-by: Tanay Pant <7481165+tanay1337@users.noreply.github.com> --- .../config/vocabularies/default/accept.txt | 2 +- components/callouts/ModuleCallout.mdx | 7 + components/callouts/OnlySafeTxCallout.mdx | 5 + pages/_meta.json | 5 + pages/advanced/_meta.json | 4 + pages/reference-smart-account/_meta.json | 23 ++ .../events/AddedOwner.mdx | 7 + .../events/ApproveHash.mdx | 7 + .../events/ChangedFallbackHandler.mdx | 7 + .../events/ChangedGuard.mdx | 7 + .../events/ChangedModuleGuard.mdx | 7 + .../events/ChangedThreshold.mdx | 7 + .../events/DisabledModule.mdx | 7 + .../events/EnabledModule.mdx | 7 + .../events/ExecutionFailure.mdx | 7 + .../events/ExecutionFromModuleFailure.mdx | 7 + .../events/ExecutionFromModuleSuccess.mdx | 7 + .../events/ExecutionSuccess.mdx | 7 + .../events/RemovedOwner.mdx | 7 + .../events/SafeReceived.mdx | 7 + .../events/SafeSetup.mdx | 13 + .../events/SignMsg.mdx | 7 + .../fallback/_meta.json | 5 + .../fallback/fallback.mdx | 32 ++ .../fallback/receive.mdx | 30 ++ .../fallback/setFallbackHandler.mdx | 51 ++++ .../reference-smart-account/guards/_meta.json | 4 + .../guards/setGuard.mdx | 49 +++ .../guards/setModuleGuard.mdx | 52 ++++ .../modules/_meta.json | 8 + .../modules/disableModule.mdx | 63 ++++ .../modules/enableModule.mdx | 49 +++ .../modules/execTransactionFromModule.mdx | 119 ++++++++ .../execTransactionFromModuleReturnData.mdx | 121 ++++++++ .../modules/getModulesPaginated.mdx | 72 +++++ .../modules/isModuleEnabled.mdx | 47 +++ pages/reference-smart-account/overview.mdx | 3 + .../reference-smart-account/owners/_meta.json | 9 + .../owners/addOwnerWithThreshold.mdx | 65 ++++ .../owners/changeThreshold.mdx | 49 +++ .../owners/getOwners.mdx | 35 +++ .../owners/getThreshold.mdx | 35 +++ .../owners/isOwner.mdx | 49 +++ .../owners/removeOwner.mdx | 98 ++++++ .../owners/swapOwner.mdx | 96 ++++++ .../reference-smart-account/setup/_meta.json | 4 + .../setup/domainSeparator.mdx | 33 ++ pages/reference-smart-account/setup/setup.mdx | 68 +++++ .../signatures/_meta.json | 6 + .../signatures/approveHash.mdx | 56 ++++ .../signatures/checkNSignatures.mdx | 109 +++++++ .../signatures/checkSignatures.mdx | 61 ++++ .../signatures/signedMessages.mdx | 46 +++ .../transactions/_meta.json | 6 + .../transactions/encodeTransactionData.mdx | 267 +++++++++++++++++ .../transactions/execTransaction.mdx | 281 ++++++++++++++++++ .../transactions/getTransactionHash.mdx | 265 +++++++++++++++++ .../transactions/simulateAndRevert.mdx | 58 ++++ .../utilities/_meta.json | 3 + .../utilities/getStorageAt.mdx | 58 ++++ 60 files changed, 2625 insertions(+), 1 deletion(-) create mode 100644 components/callouts/ModuleCallout.mdx create mode 100644 components/callouts/OnlySafeTxCallout.mdx create mode 100644 pages/reference-smart-account/_meta.json create mode 100644 pages/reference-smart-account/events/AddedOwner.mdx create mode 100644 pages/reference-smart-account/events/ApproveHash.mdx create mode 100644 pages/reference-smart-account/events/ChangedFallbackHandler.mdx create mode 100644 pages/reference-smart-account/events/ChangedGuard.mdx create mode 100644 pages/reference-smart-account/events/ChangedModuleGuard.mdx create mode 100644 pages/reference-smart-account/events/ChangedThreshold.mdx create mode 100644 pages/reference-smart-account/events/DisabledModule.mdx create mode 100644 pages/reference-smart-account/events/EnabledModule.mdx create mode 100644 pages/reference-smart-account/events/ExecutionFailure.mdx create mode 100644 pages/reference-smart-account/events/ExecutionFromModuleFailure.mdx create mode 100644 pages/reference-smart-account/events/ExecutionFromModuleSuccess.mdx create mode 100644 pages/reference-smart-account/events/ExecutionSuccess.mdx create mode 100644 pages/reference-smart-account/events/RemovedOwner.mdx create mode 100644 pages/reference-smart-account/events/SafeReceived.mdx create mode 100644 pages/reference-smart-account/events/SafeSetup.mdx create mode 100644 pages/reference-smart-account/events/SignMsg.mdx create mode 100644 pages/reference-smart-account/fallback/_meta.json create mode 100644 pages/reference-smart-account/fallback/fallback.mdx create mode 100644 pages/reference-smart-account/fallback/receive.mdx create mode 100644 pages/reference-smart-account/fallback/setFallbackHandler.mdx create mode 100644 pages/reference-smart-account/guards/_meta.json create mode 100644 pages/reference-smart-account/guards/setGuard.mdx create mode 100644 pages/reference-smart-account/guards/setModuleGuard.mdx create mode 100644 pages/reference-smart-account/modules/_meta.json create mode 100644 pages/reference-smart-account/modules/disableModule.mdx create mode 100644 pages/reference-smart-account/modules/enableModule.mdx create mode 100644 pages/reference-smart-account/modules/execTransactionFromModule.mdx create mode 100644 pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx create mode 100644 pages/reference-smart-account/modules/getModulesPaginated.mdx create mode 100644 pages/reference-smart-account/modules/isModuleEnabled.mdx create mode 100644 pages/reference-smart-account/overview.mdx create mode 100644 pages/reference-smart-account/owners/_meta.json create mode 100644 pages/reference-smart-account/owners/addOwnerWithThreshold.mdx create mode 100644 pages/reference-smart-account/owners/changeThreshold.mdx create mode 100644 pages/reference-smart-account/owners/getOwners.mdx create mode 100644 pages/reference-smart-account/owners/getThreshold.mdx create mode 100644 pages/reference-smart-account/owners/isOwner.mdx create mode 100644 pages/reference-smart-account/owners/removeOwner.mdx create mode 100644 pages/reference-smart-account/owners/swapOwner.mdx create mode 100644 pages/reference-smart-account/setup/_meta.json create mode 100644 pages/reference-smart-account/setup/domainSeparator.mdx create mode 100644 pages/reference-smart-account/setup/setup.mdx create mode 100644 pages/reference-smart-account/signatures/_meta.json create mode 100644 pages/reference-smart-account/signatures/approveHash.mdx create mode 100644 pages/reference-smart-account/signatures/checkNSignatures.mdx create mode 100644 pages/reference-smart-account/signatures/checkSignatures.mdx create mode 100644 pages/reference-smart-account/signatures/signedMessages.mdx create mode 100644 pages/reference-smart-account/transactions/_meta.json create mode 100644 pages/reference-smart-account/transactions/encodeTransactionData.mdx create mode 100644 pages/reference-smart-account/transactions/execTransaction.mdx create mode 100644 pages/reference-smart-account/transactions/getTransactionHash.mdx create mode 100644 pages/reference-smart-account/transactions/simulateAndRevert.mdx create mode 100644 pages/reference-smart-account/utilities/_meta.json create mode 100644 pages/reference-smart-account/utilities/getStorageAt.mdx diff --git a/.github/styles/config/vocabularies/default/accept.txt b/.github/styles/config/vocabularies/default/accept.txt index c0f9c846..c30eb78f 100644 --- a/.github/styles/config/vocabularies/default/accept.txt +++ b/.github/styles/config/vocabularies/default/accept.txt @@ -13,6 +13,7 @@ [Bb]inance [Bb]lockchain [Bb]lockchains +[Bb]oolean [Bb]undler [Bb]undlers [Cc]hainlist @@ -252,7 +253,6 @@ Zora address_full_match auditable auth_code -boolean bytestrings checksummed createTransaction diff --git a/components/callouts/ModuleCallout.mdx b/components/callouts/ModuleCallout.mdx new file mode 100644 index 00000000..fa26a545 --- /dev/null +++ b/components/callouts/ModuleCallout.mdx @@ -0,0 +1,7 @@ +import { Callout } from 'nextra/components' + + + Since a guard has the full power to block Safe transaction executions, a + broken guard can cause a denial of service for the Safe. Make sure to + carefully audit the guard code, and design recovery mechanisms. + diff --git a/components/callouts/OnlySafeTxCallout.mdx b/components/callouts/OnlySafeTxCallout.mdx new file mode 100644 index 00000000..c658533c --- /dev/null +++ b/components/callouts/OnlySafeTxCallout.mdx @@ -0,0 +1,5 @@ +import { Callout } from 'nextra/components' + + + This action can only be done via a Safe transaction. + diff --git a/pages/_meta.json b/pages/_meta.json index 101ad313..8eb6f6ee 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -35,6 +35,11 @@ "title": "Advanced", "type": "page" }, + "reference-smart-account": { + "title": "Smart Account Reference", + "type": "page", + "display": "hidden" + }, "resource-hub": { "title": "Resource Hub", "type": "page", diff --git a/pages/advanced/_meta.json b/pages/advanced/_meta.json index 9e539c2c..897bfb75 100644 --- a/pages/advanced/_meta.json +++ b/pages/advanced/_meta.json @@ -19,6 +19,10 @@ }, "smart-account-audits": "Audits", "smart-account-bug-bounty": "Bug Bounty", + "smart-account-reference": { + "title": "Reference", + "href": "/reference-smart-account/overview" + }, "-- Features": { "type": "separator", "title": "Features" diff --git a/pages/reference-smart-account/_meta.json b/pages/reference-smart-account/_meta.json new file mode 100644 index 00000000..8683d752 --- /dev/null +++ b/pages/reference-smart-account/_meta.json @@ -0,0 +1,23 @@ +{ + "home": { + "title": "← Go Back", + "href": "/advanced/smart-account-overview" + }, + "overview": "Overview", + "-- Safe Reference": { + "type": "separator", + "title": "Safe Reference" + }, + "setup": "Setup", + "owners": "Owners", + "transactions": "Transactions", + "modules": "Modules", + "guards": "Guards", + "fallback": "Fallback Handler", + "signatures": "Signatures", + "utilities": "Utilities", + "events": { + "type": "page", + "display": "hidden" + } +} diff --git a/pages/reference-smart-account/events/AddedOwner.mdx b/pages/reference-smart-account/events/AddedOwner.mdx new file mode 100644 index 00000000..9424b027 --- /dev/null +++ b/pages/reference-smart-account/events/AddedOwner.mdx @@ -0,0 +1,7 @@ +### `AddedOwner` + +```solidity +event AddedOwner(address owner); +``` + +Emitted when an owner is added to the Safe. diff --git a/pages/reference-smart-account/events/ApproveHash.mdx b/pages/reference-smart-account/events/ApproveHash.mdx new file mode 100644 index 00000000..58362670 --- /dev/null +++ b/pages/reference-smart-account/events/ApproveHash.mdx @@ -0,0 +1,7 @@ +### `ApproveHash` + +```solidity +event ApproveHash(bytes32 approvedHash, address owner); +``` + +Emitted when a hash is approved by an owner. diff --git a/pages/reference-smart-account/events/ChangedFallbackHandler.mdx b/pages/reference-smart-account/events/ChangedFallbackHandler.mdx new file mode 100644 index 00000000..c7b88341 --- /dev/null +++ b/pages/reference-smart-account/events/ChangedFallbackHandler.mdx @@ -0,0 +1,7 @@ +### `ChangedFallbackHandler` + +```solidity +event ChangedFallbackHandler(address handler); +``` + +Emitted when the Fallback Handler is changed. diff --git a/pages/reference-smart-account/events/ChangedGuard.mdx b/pages/reference-smart-account/events/ChangedGuard.mdx new file mode 100644 index 00000000..70200fb7 --- /dev/null +++ b/pages/reference-smart-account/events/ChangedGuard.mdx @@ -0,0 +1,7 @@ +### `ChangedGuard` + +```solidity +event ChangedGuard(address guard); +``` + +Emitted when a guard is set for the Safe. diff --git a/pages/reference-smart-account/events/ChangedModuleGuard.mdx b/pages/reference-smart-account/events/ChangedModuleGuard.mdx new file mode 100644 index 00000000..09af4a0c --- /dev/null +++ b/pages/reference-smart-account/events/ChangedModuleGuard.mdx @@ -0,0 +1,7 @@ +### `ChangedModuleGuard` + +```solidity +event ChangedModuleGuard(address moduleGuard); +``` + +Emitted when a Module Guard is set for the Safe. diff --git a/pages/reference-smart-account/events/ChangedThreshold.mdx b/pages/reference-smart-account/events/ChangedThreshold.mdx new file mode 100644 index 00000000..25e8719d --- /dev/null +++ b/pages/reference-smart-account/events/ChangedThreshold.mdx @@ -0,0 +1,7 @@ +### `ChangedThreshold` + +```solidity +event ChangedThreshold(uint256 threshold); +``` + +Emitted when the threshold for confirmations is changed. diff --git a/pages/reference-smart-account/events/DisabledModule.mdx b/pages/reference-smart-account/events/DisabledModule.mdx new file mode 100644 index 00000000..691a8b1c --- /dev/null +++ b/pages/reference-smart-account/events/DisabledModule.mdx @@ -0,0 +1,7 @@ +### `DisabledModule` + +```solidity +event DisabledModule(address module); +``` + +Emitted when a module is disabled for the Safe. diff --git a/pages/reference-smart-account/events/EnabledModule.mdx b/pages/reference-smart-account/events/EnabledModule.mdx new file mode 100644 index 00000000..6ba4ef46 --- /dev/null +++ b/pages/reference-smart-account/events/EnabledModule.mdx @@ -0,0 +1,7 @@ +### `EnabledModule` + +```solidity +event EnabledModule(address module); +``` + +Emitted when a module is enabled for the Safe. diff --git a/pages/reference-smart-account/events/ExecutionFailure.mdx b/pages/reference-smart-account/events/ExecutionFailure.mdx new file mode 100644 index 00000000..88b0dcd0 --- /dev/null +++ b/pages/reference-smart-account/events/ExecutionFailure.mdx @@ -0,0 +1,7 @@ +### `ExecutionFailure` + +```solidity +event ExecutionFailure(bytes32 txHash, uint256 payment); +``` + +Emitted when a transaction fails. diff --git a/pages/reference-smart-account/events/ExecutionFromModuleFailure.mdx b/pages/reference-smart-account/events/ExecutionFromModuleFailure.mdx new file mode 100644 index 00000000..47574c4d --- /dev/null +++ b/pages/reference-smart-account/events/ExecutionFromModuleFailure.mdx @@ -0,0 +1,7 @@ +### `ExecutionFromModuleFailure` + +```solidity +event ExecutionFromModuleFailure(address module); +``` + +Emitted when a transaction executed by a module fails. diff --git a/pages/reference-smart-account/events/ExecutionFromModuleSuccess.mdx b/pages/reference-smart-account/events/ExecutionFromModuleSuccess.mdx new file mode 100644 index 00000000..cf078b91 --- /dev/null +++ b/pages/reference-smart-account/events/ExecutionFromModuleSuccess.mdx @@ -0,0 +1,7 @@ +### `ExecutionFromModuleSuccess` + +```solidity +event ExecutionFromModuleSuccess(address to, uint256 value, bytes data); +``` + +Emitted when a transaction executed by a module succeeds. diff --git a/pages/reference-smart-account/events/ExecutionSuccess.mdx b/pages/reference-smart-account/events/ExecutionSuccess.mdx new file mode 100644 index 00000000..00ab62cf --- /dev/null +++ b/pages/reference-smart-account/events/ExecutionSuccess.mdx @@ -0,0 +1,7 @@ +### `ExecutionSuccess` + +```solidity +event ExecutionSuccess(bytes32 txHash, uint256 payment); +``` + +Emitted when a transaction is executed successfully. diff --git a/pages/reference-smart-account/events/RemovedOwner.mdx b/pages/reference-smart-account/events/RemovedOwner.mdx new file mode 100644 index 00000000..7605a218 --- /dev/null +++ b/pages/reference-smart-account/events/RemovedOwner.mdx @@ -0,0 +1,7 @@ +### `RemovedOwner` + +```solidity +event RemovedOwner(address owner); +``` + +Emitted when an owner is removed from the Safe. diff --git a/pages/reference-smart-account/events/SafeReceived.mdx b/pages/reference-smart-account/events/SafeReceived.mdx new file mode 100644 index 00000000..16e0edde --- /dev/null +++ b/pages/reference-smart-account/events/SafeReceived.mdx @@ -0,0 +1,7 @@ +### `SafeReceived` + +```solidity +event SafeReceived(address sender, uint256 value) +``` + +Emitted when the Safe contract receives a payment. diff --git a/pages/reference-smart-account/events/SafeSetup.mdx b/pages/reference-smart-account/events/SafeSetup.mdx new file mode 100644 index 00000000..be00d09a --- /dev/null +++ b/pages/reference-smart-account/events/SafeSetup.mdx @@ -0,0 +1,13 @@ +### `SafeSetup` + +```solidity +event SafeSetup( + address initiator, + address[] owners, + uint256 threshold, + address initializer, + address fallbackHandler +); +``` + +Emitted when the Safe is set up. diff --git a/pages/reference-smart-account/events/SignMsg.mdx b/pages/reference-smart-account/events/SignMsg.mdx new file mode 100644 index 00000000..9b7b26f0 --- /dev/null +++ b/pages/reference-smart-account/events/SignMsg.mdx @@ -0,0 +1,7 @@ +### `SignMsg` + +```solidity +event SignMsg(bytes32 msgHash); +``` + +Emitted when a message is signed by an owner. diff --git a/pages/reference-smart-account/fallback/_meta.json b/pages/reference-smart-account/fallback/_meta.json new file mode 100644 index 00000000..7e500024 --- /dev/null +++ b/pages/reference-smart-account/fallback/_meta.json @@ -0,0 +1,5 @@ +{ + "fallback": "fallback", + "receive": "receive", + "setFallbackHandler": "setFallbackHandler" +} diff --git a/pages/reference-smart-account/fallback/fallback.mdx b/pages/reference-smart-account/fallback/fallback.mdx new file mode 100644 index 00000000..62d1da3f --- /dev/null +++ b/pages/reference-smart-account/fallback/fallback.mdx @@ -0,0 +1,32 @@ +import { Tabs } from 'nextra/components' +import SafeReceived from '../events/SafeReceived.mdx' + +# `fallback` + +This function emits the [`SafeReceived`](./fallback/receive.mdx#safereceived) event when it receives a payment. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + fallback() external; + } + + contract Example { + function example() ... { + (ISafe safe).fallback(); + } + } + ``` + + + +{/* */} + +## Events + + \ No newline at end of file diff --git a/pages/reference-smart-account/fallback/receive.mdx b/pages/reference-smart-account/fallback/receive.mdx new file mode 100644 index 00000000..4251facf --- /dev/null +++ b/pages/reference-smart-account/fallback/receive.mdx @@ -0,0 +1,30 @@ +import { Tabs } from 'nextra/components' +import SafeReceived from '../events/SafeReceived.mdx' + +# `receive` + +Receive function accepts native token transactions. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + receive() external payable; + } + + contract Example { + function example() ... { + (ISafe safe).receive(); + } + } + ``` + + + +## Events + + \ No newline at end of file diff --git a/pages/reference-smart-account/fallback/setFallbackHandler.mdx b/pages/reference-smart-account/fallback/setFallbackHandler.mdx new file mode 100644 index 00000000..59c5aa77 --- /dev/null +++ b/pages/reference-smart-account/fallback/setFallbackHandler.mdx @@ -0,0 +1,51 @@ +import { Tabs, Callout } from 'nextra/components' +import ChangedFallbackHandler from '../events/ChangedFallbackHandler.mdx' + +# `setFallbackHandler` + +Set Fallback Handler to `handler` for the Safe. + + + Only fallback calls without value and with data will be forwarded. This can + only be done via a Safe transaction. Cannot be set to the Safe itself. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function setFallbackHandler(address handler) external; + } + + contract Example { + function example() ... { + (ISafe safe).setFallbackHandler(0x...); + } + } + ``` + + + +{/* */} + +## Parameters + +### `handler` + +- **Type:** `address` + +Contract to handle fallback calls. + +```solidity focus=2 +(ISafe safe).setFallbackHandler( + 0x... +); +``` + +## Events + + diff --git a/pages/reference-smart-account/guards/_meta.json b/pages/reference-smart-account/guards/_meta.json new file mode 100644 index 00000000..dc05975a --- /dev/null +++ b/pages/reference-smart-account/guards/_meta.json @@ -0,0 +1,4 @@ +{ + "setGuard": "setGuard", + "setModuleGuard": "setModuleGuard" +} diff --git a/pages/reference-smart-account/guards/setGuard.mdx b/pages/reference-smart-account/guards/setGuard.mdx new file mode 100644 index 00000000..1c2aa014 --- /dev/null +++ b/pages/reference-smart-account/guards/setGuard.mdx @@ -0,0 +1,49 @@ +import { Tabs, Callout } from 'nextra/components' +import ChangedGuard from '../events/ChangedGuard.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' +import ModuleCallout from '../../../components/callouts/ModuleCallout.mdx' + +# `setGuard` + +Set Transaction Guard `guard` that checks transactions before execution. + + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function setGuard(address guard) external; + } + + contract Example { + function example() ... { + (ISafe safe).setGuard(0x...); + } + } + ``` + + + +## Parameters + +### `guard` + +- **Type:** `address` + +The address of the guard to be used, or `address(0)` to disable the guard. + +```solidity focus=2 +(ISafe safe).setGuard( + 0x... +); +``` + +## Events + + diff --git a/pages/reference-smart-account/guards/setModuleGuard.mdx b/pages/reference-smart-account/guards/setModuleGuard.mdx new file mode 100644 index 00000000..016addc6 --- /dev/null +++ b/pages/reference-smart-account/guards/setModuleGuard.mdx @@ -0,0 +1,52 @@ +import { Tabs, Callout } from 'nextra/components' +import ChangedModuleGuard from '../events/ChangedModuleGuard.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' +import ModuleCallout from '../../../components/callouts/ModuleCallout.mdx' + +# `setModuleGuard` + +Set a Module Guard that checks transactions initiated by the module before +execution. + + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function setModuleGuard(address moduleGuard) external; + } + + contract Example { + function example() ... { + (ISafe safe).setModuleGuard(0x...); + } + } + ``` + + + +{/* */} + +## Parameters + +### `moduleGuard` + +- **Type:** `address` + +The address of the Module Guard to be used, or `address(0)` to disable the Module Guard. + +```solidity focus=2 +(ISafe safe).setModuleGuard( + 0x... +); +``` + +## Events + + diff --git a/pages/reference-smart-account/modules/_meta.json b/pages/reference-smart-account/modules/_meta.json new file mode 100644 index 00000000..763a82d7 --- /dev/null +++ b/pages/reference-smart-account/modules/_meta.json @@ -0,0 +1,8 @@ +{ + "enableModule": "enableModule", + "disableModule": "disableModule", + "execTransactionFromModule": "execTransactionFromModule", + "execTransactionFromModuleReturnData": "execTransactionFromModuleReturnData", + "getModulesPaginated": "getModulesPaginated", + "isModuleEnabled": "isModuleEnabled" +} diff --git a/pages/reference-smart-account/modules/disableModule.mdx b/pages/reference-smart-account/modules/disableModule.mdx new file mode 100644 index 00000000..eedc3e5e --- /dev/null +++ b/pages/reference-smart-account/modules/disableModule.mdx @@ -0,0 +1,63 @@ +import { Tabs, Callout } from 'nextra/components' +import DisabledModule from '../events/DisabledModule.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `disableModule` + +Disables the module `module` for the Safe. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function disableModule(address prevModule, address module) external; + } + + contract Example { + function example() ... { + (ISafe safe).disableModule(0x..., 0x...); + } + } + ``` + + + +{/* */} + +## Parameters + +### `prevModule` + +- **Type:** `address` + +Previous module in the modules linked list. + +```solidity focus=2 +(ISafe safe).disableModule( + 0x..., + 0x... +); +``` + +### `module` + +- **Type:** `address` + +Module to be removed. + +```solidity focus=3 +(ISafe safe).disableModule( + 0x..., + 0x... +); +``` + +## Events + + diff --git a/pages/reference-smart-account/modules/enableModule.mdx b/pages/reference-smart-account/modules/enableModule.mdx new file mode 100644 index 00000000..072ab75c --- /dev/null +++ b/pages/reference-smart-account/modules/enableModule.mdx @@ -0,0 +1,49 @@ +import { Tabs, Callout } from 'nextra/components' +import EnabledModule from '../events/EnabledModule.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `enableModule` + +Enables a new Safe Module in a Safe account. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function enableModule(address module) external; + } + + contract Example { + function example() ... { + (ISafe safe).enableModule(0x...); + } + } + ``` + + + +{/* */} + +## Parameters + +### `module` + +- **Type:** `address` + +Safe Module to be enabled. + +```solidity focus=2 +(ISafe safe).enableModule( + 0x... +); +``` + +## Events + + diff --git a/pages/reference-smart-account/modules/execTransactionFromModule.mdx b/pages/reference-smart-account/modules/execTransactionFromModule.mdx new file mode 100644 index 00000000..e3a4b3ed --- /dev/null +++ b/pages/reference-smart-account/modules/execTransactionFromModule.mdx @@ -0,0 +1,119 @@ +import { Tabs, Callout } from 'nextra/components' +import ExecutionFromModuleSuccess from '../events/ExecutionFromModuleSuccess.mdx' +import ExecutionFromModuleFailure from '../events/ExecutionFromModuleFailure.mdx' + +# `execTransactionFromModule` + +Execute `operation` (0: Call, 1: DelegateCall) to `to` with `value` (native token). + + + Function is virtual to allow overriding for L2 singleton to emit an event for + indexing. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function execTransactionFromModule( + address to, + uint256 value, + bytes data, + enum Enum.Operation operation + ) external returns (bool success); + } + + contract Example { + function example() … { + (ISafe safe).execTransactionFromModule( + 0x..., + 0, + "0x...", + Enum.Operation.Call + ); + } + } + ``` + + + +{/* */} + +## Returns + +### `success` + +- **Type:** `bool` + +Boolean flag indicating if the call succeeded. + +## Parameters + +### `to` + +- **Type:** `address` + +Destination address of module transaction. + +```solidity focus=2 +(ISafe safe).execTransactionFromModule( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `value` + +- **Type:** `uint256` + +The native token value transferred in the Safe Module transaction. + +```solidity focus=3 +(ISafe safe).execTransactionFromModule( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `data` + +- **Type:** `bytes` + +Data payload of the module transaction. + +```solidity focus=4 +(ISafe safe).execTransactionFromModule( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `operation` + +- **Type:** `enum Enum.Operation` + +Operation type of the module transaction. + +```solidity focus=5 +(ISafe safe).execTransactionFromModule( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx b/pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx new file mode 100644 index 00000000..56c5095b --- /dev/null +++ b/pages/reference-smart-account/modules/execTransactionFromModuleReturnData.mdx @@ -0,0 +1,121 @@ +import { Tabs } from 'nextra/components' +import ExecutionFromModuleSuccess from '../events/ExecutionFromModuleSuccess.mdx' +import ExecutionFromModuleFailure from '../events/ExecutionFromModuleFailure.mdx' + +# `execTransactionFromModuleReturnData` + +Executes a transaction from an enabled Safe Module and returns the result data. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function execTransactionFromModuleReturnData( + address to, + uint256 value, + bytes data, + enum Enum.Operation operation + ) external returns (bool success, bytes returnData); + } + + contract Example { + function example() … { + (ISafe safe).execTransactionFromModuleReturnData( + 0x..., + 0, + "0x...", + Enum.Operation.Call + ); + } + } + ``` + + + + +{/* */} + +## Returns + +### `success` + +- **Type:** `bool` + +Boolean flag indicating if the call succeeded. + +### `returnData` + +- **Type:** `bytes` + +Data returned by the call. + +## Parameters + +### `to` + +- **Type:** `address` + +Destination address of the Safe Module transaction. + +```solidity focus=2 +(ISafe safe).execTransactionFromModuleReturnData( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `value` + +- **Type:** `uint256` + +Value of the native token transferred in the module transaction. + +```solidity focus=3 +(ISafe safe).execTransactionFromModuleReturnData( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `data` + +- **Type:** `bytes` + +Data payload of the module transaction. + +```solidity focus=4 +(ISafe safe).execTransactionFromModuleReturnData( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +### `operation` + +- **Type:** `enum Enum.Operation` + +Operation type of the module transaction. + +```solidity focus=5 +(ISafe safe).execTransactionFromModuleReturnData( + 0x..., + 0, + "0x...", + Enum.Operation.Call +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/modules/getModulesPaginated.mdx b/pages/reference-smart-account/modules/getModulesPaginated.mdx new file mode 100644 index 00000000..c23176ef --- /dev/null +++ b/pages/reference-smart-account/modules/getModulesPaginated.mdx @@ -0,0 +1,72 @@ +import { Tabs } from 'nextra/components' + +# `getModulesPaginated` + +Returns an array of modules. If all entries fit into a single page, the next pointer will be `0x1`. If another page is present, next will be the last element of the returned array. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function getModulesPaginated( + address start, + uint256 pageSize + ) external view returns (address[] array, address next); + } + + contract Example { + function example() … { + (ISafe safe).getModulesPaginated(0x..., 1); + } + } + ``` + + + +{/* */} + +## Returns + +### `array` + +- **Type:** `address[]` + +Array of modules. + +### `next` + +- **Type:** `address` + +Start of the next page. + +## Parameters + +### `start` + +- **Type:** `address` + +Start of the page. Has to be a module or start pointer (`0x1` address). + +```solidity focus=2 +(ISafe safe).getModulesPaginated( + 0x..., + 1 +); +``` + +### `pageSize` + +- **Type:** `uint256` + +Maximum number of modules that should be returned. Has to be greater than zero. + +```solidity focus=3 +(ISafe safe).getModulesPaginated( + 0x..., + 1 +); +``` diff --git a/pages/reference-smart-account/modules/isModuleEnabled.mdx b/pages/reference-smart-account/modules/isModuleEnabled.mdx new file mode 100644 index 00000000..63caf11e --- /dev/null +++ b/pages/reference-smart-account/modules/isModuleEnabled.mdx @@ -0,0 +1,47 @@ +import { Tabs } from 'nextra/components' + +# `isModuleEnabled` + +Returns if a module is enabled. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function isModuleEnabled(address module) external view returns (bool); + } + + contract Example { + function example() … { + (ISafe safe).isModuleEnabled(0x...); + } + } + ``` + + + +## Returns + +### `isModuleEnabled` + +- **Type:** `bool` + +Boolean flag indicating if the module is enabled. + +## Parameters + +### `module` + +- **Type:** `address` + +Address of the module. + +```solidity focus=2 +(ISafe safe).isModuleEnabled( + 0x... +); +``` diff --git a/pages/reference-smart-account/overview.mdx b/pages/reference-smart-account/overview.mdx new file mode 100644 index 00000000..4e2a60fd --- /dev/null +++ b/pages/reference-smart-account/overview.mdx @@ -0,0 +1,3 @@ +# Safe Smart Account Reference + +This reference lists all public functions and events of the [Safe Smart Account](../advanced/smart-account-overview.mdx) contracts version `1.4.1`, logically clustered. diff --git a/pages/reference-smart-account/owners/_meta.json b/pages/reference-smart-account/owners/_meta.json new file mode 100644 index 00000000..10e5bc35 --- /dev/null +++ b/pages/reference-smart-account/owners/_meta.json @@ -0,0 +1,9 @@ +{ + "addOwnerWithThreshold": "addOwnerWithThreshold", + "changeThreshold": "changeThreshold", + "getOwners": "getOwners", + "getThreshold": "getThreshold", + "isOwner": "isOwner", + "removeOwner": "removeOwner", + "swapOwner": "swapOwner" +} diff --git a/pages/reference-smart-account/owners/addOwnerWithThreshold.mdx b/pages/reference-smart-account/owners/addOwnerWithThreshold.mdx new file mode 100644 index 00000000..a60be62d --- /dev/null +++ b/pages/reference-smart-account/owners/addOwnerWithThreshold.mdx @@ -0,0 +1,65 @@ +import { Tabs, Callout } from 'nextra/components' +import AddedOwner from '../events/AddedOwner.mdx' +import ChangedThreshold from '../events/ChangedThreshold.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `addOwnerWithThreshold` + +Adds the owner `owner` to the Safe and updates the threshold to `_threshold`. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function addOwnerWithThreshold(address owner, uint256 _threshold) external; + } + + contract Example { + function example() ... { + (ISafe safe).addOwnerWithThreshold(0x..., 1); + } + } + ``` + + + +{/* */} + +## Parameters + +### `owner` + +- **Type:** `address` + +New owner address. + +```solidity focus=2 +(ISafe safe).addOwnerWithThreshold( + 0x..., + 1 +); +``` + +### `_threshold` + +- **Type:** `uint256` + +New threshold. + +```solidity focus=3 +(ISafe safe).addOwnerWithThreshold( + 0x..., + 1 +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/owners/changeThreshold.mdx b/pages/reference-smart-account/owners/changeThreshold.mdx new file mode 100644 index 00000000..a34a304d --- /dev/null +++ b/pages/reference-smart-account/owners/changeThreshold.mdx @@ -0,0 +1,49 @@ +import { Tabs, Callout } from 'nextra/components' +import ChangedThreshold from '../events/ChangedThreshold.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `changeThreshold` + +Changes the threshold of the Safe to `_threshold`. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function changeThreshold(uint256 _threshold) external; + } + + contract Example { + function example() ... { + (ISafe safe).changeThreshold(1); + } + } + ``` + + + +{/* */} + +## Parameters + +### `_threshold` + +- **Type:** `uint256` + +New threshold. + +```solidity focus=2 +(ISafe safe).changeThreshold( + 1 +); +``` + +## Events + + diff --git a/pages/reference-smart-account/owners/getOwners.mdx b/pages/reference-smart-account/owners/getOwners.mdx new file mode 100644 index 00000000..aa6edc86 --- /dev/null +++ b/pages/reference-smart-account/owners/getOwners.mdx @@ -0,0 +1,35 @@ +import { Tabs } from 'nextra/components' + +# `getOwners` + +Returns a list of Safe owners. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function getOwners() external view returns (address[]); + } + + contract Example { + function example() ... { + (ISafe safe).getOwners(); + } + } + ``` + + + +{/* */} + +## Returns + +### `owners` + +- **Type:** `address[]` + +Array of Safe owners. diff --git a/pages/reference-smart-account/owners/getThreshold.mdx b/pages/reference-smart-account/owners/getThreshold.mdx new file mode 100644 index 00000000..686928d3 --- /dev/null +++ b/pages/reference-smart-account/owners/getThreshold.mdx @@ -0,0 +1,35 @@ +import { Tabs } from 'nextra/components' + +# `getThreshold` + +Returns the threshold of the Safe account. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function getThreshold() external view returns (uint256); + } + + contract Example { + function example() ... { + (uint256 threshold) = (ISafe safe).getThreshold(); + } + } + ``` + + + +{/* */} + +## Returns + +### `threshold` + +- **Type:** `uint256` + +Threshold number. diff --git a/pages/reference-smart-account/owners/isOwner.mdx b/pages/reference-smart-account/owners/isOwner.mdx new file mode 100644 index 00000000..6b5b7919 --- /dev/null +++ b/pages/reference-smart-account/owners/isOwner.mdx @@ -0,0 +1,49 @@ +import { Tabs } from 'nextra/components' + +# `isOwner` + +Returns if `owner` is an owner of the Safe. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function isOwner(address owner) external view returns (bool); + } + + contract Example { + function example() … { + (bool isOwner) = (ISafe safe).isOwner(0x...); + } + } + ``` + + + +{/* */} + +## Returns + +### `isOwner` + +- **Type:** `bool` + +Boolean flag indicating if `owner` is an owner of the Safe. + +## Parameters + +### `owner` + +- **Type:** `address` + +Owner address. + +```solidity focus=2 +(ISafe safe).isOwner( + 0x... +); +``` diff --git a/pages/reference-smart-account/owners/removeOwner.mdx b/pages/reference-smart-account/owners/removeOwner.mdx new file mode 100644 index 00000000..0d907241 --- /dev/null +++ b/pages/reference-smart-account/owners/removeOwner.mdx @@ -0,0 +1,98 @@ +import { Tabs, Callout } from 'nextra/components' +import RemovedOwner from '../events/RemovedOwner.mdx' +import ChangedThreshold from '../events/ChangedThreshold.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `removeOwner` + +## Overview + +Removes the owner `owner` from the Safe and updates the threshold to `_threshold`. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function removeOwner( + address prevOwner, + address owner, + uint256 _threshold + ) external; + } + + contract Example { + function example() … { + (ISafe safe).removeOwner( + 0x..., + 0x..., + 1 + ); + } + } + ``` + + + + +{/* */} + +## Parameters + +### `prevOwner` + +- **Type:** `address` + +Owner address that is pointing to the owner to be removed in the contract [linked list](https://github.com/safe-global/safe-smart-account/blob/7f79aaf05c33df71d9cb687f0bc8a73fa39d25d5/contracts/base/OwnerManager.sol#L19). + + + A linked list is a data structure that allows efficient insertion and removal + of elements in a list. Each element in it will point to the next one. In Safe + contracts, the owners are stored in a linked list. + + +```solidity focus=2 +(ISafe safe).removeOwner( + 0x..., + 0x..., + 1 +); +``` + +### `owner` + +- **Type:** `address` + +Owner address to be removed. + +```solidity focus=3 +(ISafe safe).removeOwner( + 0x..., + 0x..., + 1 +); +``` + +### `_threshold` + +- **Type:** `uint256` + +New threshold. + +```solidity focus=4 +(ISafe safe).removeOwner( + 0x..., + 0x..., + 1 +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/owners/swapOwner.mdx b/pages/reference-smart-account/owners/swapOwner.mdx new file mode 100644 index 00000000..2c31eace --- /dev/null +++ b/pages/reference-smart-account/owners/swapOwner.mdx @@ -0,0 +1,96 @@ +import { Tabs, Callout } from 'nextra/components' +import AddedOwner from '../events/AddedOwner.mdx' +import RemovedOwner from '../events/RemovedOwner.mdx' +import OnlySafeTxCallout from '../../../components/callouts/OnlySafeTxCallout.mdx' + +# `swapOwner` + +Replaces the owner `oldOwner` in the Safe with `newOwner`. + + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function swapOwner( + address prevOwner, + address oldOwner, + address newOwner + ) external; + } + + contract Example { + function example() … { + (ISafe safe).swapOwner( + 0x..., + 0x..., + 0x... + ); + } + } + ``` + + + + +{/* */} + +## Parameters + +### `prevOwner` + +- **Type:** `address` + +Owner address that is pointing to the owner to be removed in the contract [linked list](https://github.com/safe-global/safe-smart-account/blob/7f79aaf05c33df71d9cb687f0bc8a73fa39d25d5/contracts/base/OwnerManager.sol#L19). + + + A linked list is a data structure that allows efficient insertion and removal + of elements in a list. Each element in it will point to the next one. In Safe + contracts, the owners are stored in a linked list. + + +```solidity focus=2 +(ISafe safe).swapOwner( + 0x..., + 0x..., + 0x... +); +``` + +### `oldOwner` + +- **Type:** `address` + +Owner address to be replaced. + +```solidity focus=3 +(ISafe safe).swapOwner( + 0x..., + 0x..., + 0x... +); +``` + +### `newOwner` + +- **Type:** `address` + +New owner address. + +```solidity focus=4 +(ISafe safe).swapOwner( + 0x..., + 0x..., + 0x... +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/setup/_meta.json b/pages/reference-smart-account/setup/_meta.json new file mode 100644 index 00000000..6dbd6ca4 --- /dev/null +++ b/pages/reference-smart-account/setup/_meta.json @@ -0,0 +1,4 @@ +{ + "domainSeparator": "domainSeparator", + "setup": "setup" +} \ No newline at end of file diff --git a/pages/reference-smart-account/setup/domainSeparator.mdx b/pages/reference-smart-account/setup/domainSeparator.mdx new file mode 100644 index 00000000..e76947d1 --- /dev/null +++ b/pages/reference-smart-account/setup/domainSeparator.mdx @@ -0,0 +1,33 @@ +import { Tabs } from 'nextra/components' + +# `domainSeparator` + +Returns the domain separator for this contract, as defined in the [EIP-712 standard](../../home/glossary.md#eip-712). + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function domainSeparator() external view returns (bytes32); + } + + contract Example { + function example() … { + (ISafe safe).domainSeparator(); + } + } + ``` + + + +{/* */} + +## Returns + +- **Type:** `bytes32` + +The domain separator hash. diff --git a/pages/reference-smart-account/setup/setup.mdx b/pages/reference-smart-account/setup/setup.mdx new file mode 100644 index 00000000..76da1a31 --- /dev/null +++ b/pages/reference-smart-account/setup/setup.mdx @@ -0,0 +1,68 @@ +import { Tabs, Callout } from 'nextra/components' +import SafeSetup from '../events/SafeSetup.mdx' + +# `setup` + +Sets an initial storage of the Safe contract. + + + This method can only be called once. If a proxy was created without setting + up, anyone can call setup and claim the proxy. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function setup( + address[] _owners, + uint256 _threshold + ) external; + } + + contract Example { + function example() ... { + (ISafe safe).setup([0x..., 0x...], 1); + } + } + ``` + + + +{/* */} + +## Parameters + +### `_owners` + +- **Type:** `address[]` + +List of Safe owners. + +```solidity focus=2 +(ISafe safe).setup( + [0x..., 0x...], + 1 +); +``` + +### `_threshold` + +- **Type:** `uint256` + +Number of required confirmations for a Safe transaction. + +```solidity focus=3 +(ISafe safe).setup( + [0x..., 0x...], + 1 +); +``` + +## Events + + diff --git a/pages/reference-smart-account/signatures/_meta.json b/pages/reference-smart-account/signatures/_meta.json new file mode 100644 index 00000000..6d1df9f5 --- /dev/null +++ b/pages/reference-smart-account/signatures/_meta.json @@ -0,0 +1,6 @@ +{ + "approveHash": "approveHash", + "checkNSignatures": "checkNSignatures", + "checkSignatures": "checkSignatures", + "signedMessages": "signedMessages" +} diff --git a/pages/reference-smart-account/signatures/approveHash.mdx b/pages/reference-smart-account/signatures/approveHash.mdx new file mode 100644 index 00000000..b0fabbb5 --- /dev/null +++ b/pages/reference-smart-account/signatures/approveHash.mdx @@ -0,0 +1,56 @@ +import { Tabs, Callout } from 'nextra/components' +import ApproveHash from '../events/ApproveHash.mdx' + +# `approveHash` + +Marks hash `hashToApprove` as approved. + + + This can be used with a pre-approved hash transaction signature. + + + + The approved hash stays approved forever. There's no revocation mechanism, so + it behaves similarly to ECDSA signatures. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function approveHash(bytes32 hashToApprove) external; + } + + contract Example { + function example() ... { + (ISafe safe).approveHash("0x..."); + } + } + ``` + + + + +{/* */} + +## Parameters + +### `hashToApprove` + +- **Type:** `bytes32` + +The hash to mark as approved for signatures that are verified by this contract. + +```solidity focus=2 +(ISafe safe).approveHash( + "0x..." +); +``` + +## Events + + diff --git a/pages/reference-smart-account/signatures/checkNSignatures.mdx b/pages/reference-smart-account/signatures/checkNSignatures.mdx new file mode 100644 index 00000000..88846595 --- /dev/null +++ b/pages/reference-smart-account/signatures/checkNSignatures.mdx @@ -0,0 +1,109 @@ +import { Tabs, Callout } from 'nextra/components' + +# `checkNSignatures` + +Checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + + + Since the EIP-1271 makes an external call, be mindful of re-entrancy attacks. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function checkNSignatures( + address executor, + bytes32 dataHash, + bytes signatures, + uint256 requiredSignatures + ) external view; + } + + + contract Example { + function example() ... { + (ISafe safe).checkNSignatures( + 0x..., + "0x...", + "0x...", + 1 + ); + } + } + ``` + + + +{/* */} + +## Parameters + +### `executor` + +- **Type:** `address` + +Address executing the transaction. + + + Make sure that the executor address is a legitimate executor. When incorrectly + passed, the executor might reduce the threshold by one signature. + + +```solidity focus=2 +(ISafe safe).checkNSignatures( + 0x..., + "0x...", + "0x...", + 1 +); +``` + +### `dataHash` + +- **Type:** `bytes32` + +Hash of the data (could be either a message hash or transaction hash). + +```solidity focus=3 +(ISafe safe).checkNSignatures( + 0x..., + "0x...", + "0x...", + 1 +); +``` + +### `signatures` + +- **Type:** `bytes` + +Signature data that should be verified. Can be packed ECDSA signature `((bytes32 r)(bytes32 s)(uint8 v))`, contract signature ([EIP-1271](../../home/glossary.md#eip-1271)), or approved hash. + +```solidity focus=4 +(ISafe safe).checkNSignatures( + 0x..., + "0x...", + "0x...", + 1 +); +``` + +### `requiredSignatures` + +- **Type:** `uint256` + +Amount of required valid signatures. + +```solidity focus=5 +(ISafe safe).checkNSignatures( + 0x..., + "0x...", + "0x...", + 1 +); +``` diff --git a/pages/reference-smart-account/signatures/checkSignatures.mdx b/pages/reference-smart-account/signatures/checkSignatures.mdx new file mode 100644 index 00000000..dadfc74a --- /dev/null +++ b/pages/reference-smart-account/signatures/checkSignatures.mdx @@ -0,0 +1,61 @@ +import { Tabs } from 'nextra/components' + +# `checkSignatures` + +Checks whether the signature provided is valid for the provided data and hash. Reverts otherwise. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function checkSignatures( + bytes32 dataHash, + bytes signatures + ) external view; + } + + contract Example { + function example() ... { + (ISafe safe).checkSignatures( + "0x...", + "0x..." + ); + } + } + ``` + + + +{/* */} + +## Parameters + +### `dataHash` + +- **Type:** `bytes32` + +Hash of the data (could be either a message hash or transaction hash). + +```solidity focus=2 +(ISafe safe).checkSignatures( + "0x...", + "0x..." +); +``` + +### `signatures` + +- **Type:** `bytes` + +Signature data that should be verified. Can be packed ECDSA signature `((bytes32 r)(bytes32 s)(uint8 v))`, contract signature ([EIP-1271](../../home/glossary.md#eip-1271)), or approved hash. + +```solidity focus=3 +(ISafe safe).checkSignatures( + "0x...", + "0x..." +); +``` diff --git a/pages/reference-smart-account/signatures/signedMessages.mdx b/pages/reference-smart-account/signatures/signedMessages.mdx new file mode 100644 index 00000000..303f8c14 --- /dev/null +++ b/pages/reference-smart-account/signatures/signedMessages.mdx @@ -0,0 +1,46 @@ +import { Tabs } from 'nextra/components' +import SignMsg from '../events/SignMsg.mdx' + +# `signedMessages` + +Returns a `uint256` if the `messageHash` is signed by the owner. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function signedMessages(bytes32 messageHash) external view returns (uint256); + } + + contract Example { + function example() ... { + (ISafe safe).signedMessages("0x..."); + } + } + ``` + + + +{/* */} + +## Parameters + +### `messageHash` + +- **Type:** `bytes32` + +Hash of message that should be checked. + +## Returns + +- **Type:** `uint256` + +Number denoting if an owner signed the hash. + +## Events + + diff --git a/pages/reference-smart-account/transactions/_meta.json b/pages/reference-smart-account/transactions/_meta.json new file mode 100644 index 00000000..924a03b7 --- /dev/null +++ b/pages/reference-smart-account/transactions/_meta.json @@ -0,0 +1,6 @@ +{ + "encodeTransactionData": "encodeTransactionData", + "execTransaction": "execTransaction", + "getTransactionHash": "getTransactionHash", + "simulateAndRevert": "simulateAndRevert" +} diff --git a/pages/reference-smart-account/transactions/encodeTransactionData.mdx b/pages/reference-smart-account/transactions/encodeTransactionData.mdx new file mode 100644 index 00000000..c48df4f5 --- /dev/null +++ b/pages/reference-smart-account/transactions/encodeTransactionData.mdx @@ -0,0 +1,267 @@ +import { Tabs } from 'nextra/components' + +# `encodeTransactionData` + +Encodes the transaction data for `execTransaction`. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function encodeTransactionData( + address to, + uint256 value, + bytes data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address refundReceiver, + uint256 _nonce + ) external view returns (bytes); + } + + contract Example { + function example() ... { + (ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 + ); + } + } + ``` + + + +{/* */} + +## Returns + +- **Type:** `bytes` + +Encoded transaction data. + +## Parameters + +### `to` + +- **Type:** `address` + +Destination address. + +```solidity focus=2 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `value` + +- **Type:** `uint256` + +Native token value. + +```solidity focus=3 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `data` + +- **Type:** `bytes` + +Data payload. + +```solidity focus=4 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `operation` + +- **Type:** `enum Enum.Operation` + +Operation type. + +```solidity focus=5 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `safeTxGas` + +- **Type:** `uint256` + +Gas that should be used for the Safe transaction. + +```solidity focus=6 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `baseGas` + +- **Type:** `uint256` + +Gas costs for data used to trigger the Safe transaction. + +```solidity focus=7 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `gasPrice` + +- **Type:** `uint256` + +Maximum gas price that should be used for this transaction. + +```solidity focus=8 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `gasToken` + +- **Type:** `address` + +Token address (or `address(0)` if native token) that is used for the payment. + +```solidity focus=9 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `refundReceiver` + +- **Type:** `address` + +Address of receiver of gas payment (or `address(0)` if `tx.origin`). + +```solidity focus=10 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` + +### `_nonce` + +- **Type:** `uint256` + +Transaction nonce. + +```solidity focus=11 +(ISafe safe).encodeTransactionData( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 100000, + 0, + 0, + 0x..., + 0x..., + 1 +); +``` diff --git a/pages/reference-smart-account/transactions/execTransaction.mdx b/pages/reference-smart-account/transactions/execTransaction.mdx new file mode 100644 index 00000000..1b0b3b42 --- /dev/null +++ b/pages/reference-smart-account/transactions/execTransaction.mdx @@ -0,0 +1,281 @@ +import { Tabs, Callout } from 'nextra/components' +import ExecutionSuccess from '../events/ExecutionSuccess.mdx' +import ExecutionFailure from '../events/ExecutionFailure.mdx' + +# `execTransaction` + +Executes a Safe transaction to `to` with `value` (native currency) and pays `gasPrice` \* `gasLimit` in `gasToken` token to `refundReceiver`. + + + The fees are always transferred, even if the user transaction fails. This + method doesn't perform any sanity check of the transaction, such as if the + contract at `to` address has code or not. It is the responsibility of the + caller to perform such checks. + + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function execTransaction( + address to, + uint256 value, + bytes data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address payable refundReceiver, + bytes signatures + ) external payable returns (bool success); + } + + contract Example { + function example() ... { + (ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." + ); + } + } + ``` + + + +{/* */} + +## Returns + +- **Type:** `bool` + +Boolean indicating transaction's success. + +## Parameters + +### `to` + +- **Type:** `address` + +Destination address of Safe transaction. + +```solidity focus=2 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `value` + +- **Type:** `uint256` + +Native token value of Safe transaction. + +```solidity focus=3 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `data` + +- **Type:** `bytes` + +Data payload of Safe transaction. + +```solidity focus=4 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `operation` + +- **Type:** `Enum.Operation` + +Operation type of Safe transaction. + +```solidity focus=5 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `safeTxGas` + +- **Type:** `uint256` + +Gas that should be used for the Safe transaction. + +```solidity focus=6 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `baseGas` + +- **Type:** `uint256` + +Gas costs that are independent of the transaction execution (for example, the base transaction fee, signature check, and refund payment). + +```solidity focus=7 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `gasPrice` + +- **Type:** `uint256` + +Gas price that should be used for the payment calculation. + +```solidity focus=8 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `gasToken` + +- **Type:** `address` + +Token address (or `0x` if native token) that is used for the payment. + +```solidity focus=9 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `refundReceiver` + +- **Type:** `address payable` + +Address of receiver of gas payment (or `0` if `tx.origin`). + +```solidity focus=10 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +### `signatures` + +- **Type:** `bytes` + +Signature data that should be verified. Can be packed ECDSA signature `((bytes32 r)(bytes32 s)(uint8 v))`, contract signature ([EIP-1271](../../home/glossary.md#eip-1271)), or approved hash. + +```solidity focus=11 +(ISafe safe).execTransaction( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + 0x..., + "0x..." +); +``` + +## Events + + + diff --git a/pages/reference-smart-account/transactions/getTransactionHash.mdx b/pages/reference-smart-account/transactions/getTransactionHash.mdx new file mode 100644 index 00000000..cc4788bd --- /dev/null +++ b/pages/reference-smart-account/transactions/getTransactionHash.mdx @@ -0,0 +1,265 @@ +import { Tabs } from 'nextra/components' + +# `getTransactionHash` + +Returns the Safe transaction hash of a Safe transaction that can be signed by the Safe owners. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function getTransactionHash( + address to, + uint256 value, + bytes data, + Enum.Operation operation, + uint256 safeTxGas, + uint256 baseGas, + uint256 gasPrice, + address gasToken, + address refundReceiver, + uint256 _nonce + ) external view returns (bytes32); + } + + contract Example { + function example() ... { + (ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 + ); + } + } + ``` + + + +## Returns + +- **Type:** `bytes32` + +Transaction hash. + +## Parameters + +### `to` + +- **Type:** `address` + +Destination address. + +```solidity focus=2 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `value` + +- **Type:** `uint256` + +Native token value. + +```solidity focus=3 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `data` + +- **Type:** `bytes` + +Data payload. + +```solidity focus=4 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `operation` + +- **Type:** `Enum.Operation` + +Operation type. + +```solidity focus=5 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `safeTxGas` + +- **Type:** `uint256` + +Gas that should be used for the Safe transaction. + +```solidity focus=6 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `baseGas` + +- **Type:** `uint256` + +Gas costs for data used to trigger the Safe transaction. + +```solidity focus=7 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `gasPrice` + +- **Type:** `uint256` + +Maximum gas price that should be used for this transaction. + +```solidity focus=8 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `gasToken` + +- **Type:** `address` + +Token address (or `0x` if native token) that is used for the payment. + +```solidity focus=9 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `refundReceiver` + +- **Type:** `address` + +Address of receiver of gas payment (or `0x` if `tx.origin`). + +```solidity focus=10 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` + +### `_nonce` + +- **Type:** `uint256` + +Transaction nonce. + +```solidity focus=11 +(ISafe safe).getTransactionHash( + 0x..., + 0, + "0x...", + Enum.Operation.Call, + 0, + 0, + 0, + 0x..., + payable(0), + 1 +); +``` diff --git a/pages/reference-smart-account/transactions/simulateAndRevert.mdx b/pages/reference-smart-account/transactions/simulateAndRevert.mdx new file mode 100644 index 00000000..290d276e --- /dev/null +++ b/pages/reference-smart-account/transactions/simulateAndRevert.mdx @@ -0,0 +1,58 @@ +import { Tabs } from 'nextra/components' + +# `simulateAndRevert` + +Performs a `delegatecall` on a `targetContract` in the context of `self`. Internally reverts execution to avoid side effects (making it static). + +This method reverts with data equal to `abi.encode(bool(success), bytes(response))`. Specifically, the `returndata` after a call to this method will be: `success:bool || response.length:uint256 || response:bytes`. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function simulateAndRevert( + address targetContract, + bytes calldata payload + ) external; + } + + contract Example { + function example() ... { + (ISafe safe).simulateAndRevert(0x..., "0x..."); + } + } + ``` + + + +## Parameters + +### `targetContract` + +- **Type:** `address` + +Address of the contract containing the code to execute. + +```solidity focus=2 +(ISafe safe).simulateAndRevert( + 0x..., + "0x..." +); +``` + +### `calldataPayload` + +- **Type:** `bytes` + +Payload to be executed. + +```solidity focus=3 +(ISafe safe).simulateAndRevert( + 0x..., + "0x..." +); +``` diff --git a/pages/reference-smart-account/utilities/_meta.json b/pages/reference-smart-account/utilities/_meta.json new file mode 100644 index 00000000..6dc7b477 --- /dev/null +++ b/pages/reference-smart-account/utilities/_meta.json @@ -0,0 +1,3 @@ +{ + "getStorageAt": "getStorageAt" +} \ No newline at end of file diff --git a/pages/reference-smart-account/utilities/getStorageAt.mdx b/pages/reference-smart-account/utilities/getStorageAt.mdx new file mode 100644 index 00000000..209bf690 --- /dev/null +++ b/pages/reference-smart-account/utilities/getStorageAt.mdx @@ -0,0 +1,58 @@ +import { Tabs } from 'nextra/components' + +# `getStorageAt` + +Reads bytes of storage of length `length` in the current contract, from the position defined by `offset`. + +## Usage + +{/* */} + + + + ```solidity + interface ISafe { + function getStorageAt(uint256 offset, uint256 length) external view returns (bytes); + } + + contract Example { + function example() ... { + (ISafe safe).getStorageAt(0, 1); + } + } + ``` + + + +## Parameters + +### `offset` +- **Type:** `uint256` + +The offset in the current contract's storage in words to start reading from. + +```solidity focus=2 +(ISafe safe).getStorageAt( + 0, + 1 +); +``` + +### `length` + +- **Type:** `uint256` + +The number of words (32 bytes) of data to read. + +```solidity focus=3 +(ISafe safe).getStorageAt( + 0, + 1 +); +``` + +## Returns + +- **Type:** `bytes` + +The bytes that were read.