-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update documentation #214
Update documentation #214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good improvements!
docs/Account.md
Outdated
- `max_fee` is the maximum fee a user will pay | ||
- `version` is a fixed number which is used to invalidate old transactions | ||
|
||
This `MultiCall` message is consumed by the `__execute__` method, which acts as a single entrypoint for all user interaction with any contract, including managing the account contract itself. That's why if you want to change the public key controlling the Account, you would send a transaction targeting the very Account contract: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that __execute__
doesn't take a MultiCall
but it builds one (until starknet allows for pointers on struct arrays)! It expects this instead:
call_array_len: felt,
call_array: AccountCallArray*,
calldata_len: felt,
calldata: felt*,
nonce: felt
I think it's worth documenting the actual interface
docs/Account.md
Outdated
@@ -265,11 +300,13 @@ response: felt* | |||
|
|||
Certain contracts like ERC721 require a means to differentiate between account contracts and non-account contracts. For a contract to declare itself as an account, it should implement [ERC165](https://eips.ethereum.org/EIPS/eip-165) as proposed in [#100](https://github.com/OpenZeppelin/cairo-contracts/discussions/100). To be in compliance with ERC165 specifications, the idea is to calculate the XOR of `IAccount`'s EVM selectors (not StarkNet selectors). The resulting magic value of `IAccount` is 0x50b70dcb. | |||
|
|||
Our ERC165 integration on StarkNet is inspired by OpenZeppelin's Solidity implementation of [ERC165Storage](https://docs.openzeppelin.com/contracts/4.x/api/utils#ERC165Storage) which stores the interfaces that the implementing contract supports. In the case of account contracts, querying `supportsInterface` of an account's address with the `IAccount` magic value should return true (meaning `1` in Cairo). | |||
Our ERC165 integration on StarkNet is inspired by OpenZeppelin's Solidity implementation of [ERC165Storage](https://docs.openzeppelin.com/contracts/4.x/api/utils#ERC165Storage) which stores the interfaces that the implementing contract supports. In the case of account contracts, querying `supportsInterface` of an account's address with the `IAccount` magic value should return `TRUE`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a link to our constants' doc, someone might think there's such a native value in Cairo
docs/Account.md
Outdated
There's no clear contract extensibility pattern for Cairo smart contracts yet. In the meantime the best way to extend our contracts is copypasting and modifying them at your own risk. Since `execute` relies on it, we suggest changing how `is_valid_signature` works to explore different signature validation schemes such as multisig, or some guardian logic like in [Argent's account](https://github.com/argentlabs/argent-contracts-starknet/blob/de5654555309fa76160ba3d7393d32d2b12e7349/contracts/ArgentAccount.cairo). | ||
Account contracts can be extended by following the [extensibility pattern](../docs/Extensibility.md#the-pattern). The basic idea behind integrating the pattern is to import the requisite methods from the Account library and incorporate the extended logic thereafter. The Account library is constructed to accomodate the current validation scheme; however, new schemes may require amending or adding methods in the library. | ||
|
||
Since `__execute__` relies on it, we suggest changing how `is_valid_signature` works to explore different signature validation schemes such as multisig, some guardian logic like in [Argent's account](https://github.com/argentlabs/argent-contracts-starknet/blob/de5654555309fa76160ba3d7393d32d2b12e7349/contracts/ArgentAccount.cairo), or even [Ethereum signatures](https://github.com/OpenZeppelin/cairo-contracts/issues/161). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the case anymore since (except for the above paragraph) we don't suggest changing the libraries but using them, and/or changing the presets. I'd say the Account library is not yet ready for extensibility, or at least I'm under that impression until we experiment a bit more with it. Not sure what to do about this section in the meantime, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was having trouble with writing this section, as we'll need to refactor some of the library's methods to allow for new schemes. That's how it looks to me with is_valid_signature
, anyway. For now, I suppose we can keep it simple and just say something like: "Account extensibility is not yet available." Maybe make an issue and leave a link here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we should write it taking that into account, maybe making an easy-to-replace paragraph when we make the changes. I wouldn't say it's not available either, just maybe mentioning that there's a single library/preset and we're looking for feedback/new presets.
docs/ERC20.md
Outdated
@@ -124,13 +127,47 @@ await signer.send_transaction(account, erc20.contract_address, 'transfer', [reci | |||
|
|||
## Extensibility | |||
|
|||
There's no clear contract extensibility pattern for Cairo smart contracts yet. In the meantime the best way to extend our contracts is copypasting and modifying them at your own risk. | |||
ERC20 contracts can be extended by following the [extensibility pattern](../docs/Extensibility.md#the-pattern). The basic idea behind integrating the pattern is to import the requisite ERC20 methods from the ERC20 library and incorporate the extended logic thereafter. For example, let's say you wanted to implement a pausing mechanism. The contract should first import the ERC20 methods (and the extended logic if it's in a separate contract). Next, the contract should expose the methods with the extended logic therein like this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and the extended logic if it's in a separate contract)
I didn't get that part, what do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I meant library, not contract. I was trying to convey an example like how ERC20_Pausable
combines functions from two libraries (ERC20
and pausable
) into the exposed functions—as opposed to importing from just one library and having the extended behavior coded in the contract itself. I don't think I phrased this well :) I'll edit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely! I would try to convey that extensibility can be custom as well, not just library-based.
docs/ERC20.md
Outdated
### ERC20 (basic) | ||
|
||
The `ERC20` preset offers a quick and easy setup for deploying a basic ERC20 token. | ||
|
||
### ERC20_Mintable | ||
|
||
The `ERC20_Mintable` preset allows the contract owner to mint new tokens. | ||
|
||
### ERC20_Pausable | ||
|
||
The `ERC20_Pausable` preset allows the contract owner to pause/unpause all state-modifying methods i.e. `transfer`, `approve`, etc. This preset proves useful for scenarios such as preventing trades until the end of an evaluation period and having an emergency switch for freezing all token transfers in the event of a large bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe adding links to the presets for inspection?
This PR updates ERC20, Extensibility, and Account docs.
In the ERC20 docs, this PR:
Extensibility
section to include the extensibility patternPresets
sectionIn the Extensibility docs, this PR:
Presets
In the Account docs, this PR:
__execute__
and its params)Extensibility
sectionThis resolves #206.