Skip to content
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

Handle write contract functions #19

Merged
merged 26 commits into from
Apr 23, 2021
Merged

Handle write contract functions #19

merged 26 commits into from
Apr 23, 2021

Conversation

germartinez
Copy link
Member

@germartinez germartinez commented Apr 12, 2021

Check #9

  • Add/remove Safe modules
  • Change threshold
  • Add/remove/replace Safe owners
  • Prevent contract errors with input validation in the SDK
  • Tests

@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

README.md Outdated
Comment on lines 291 to 303
const tx = await safeSdk.buildContractCall({
method: SafeSettings.ENABLE_MODULE,
moduleAddress
})
```

#### Transaction to disable a Safe module.

```js
const tx = await safeSdk.buildContractCall({
method: SafeSettings.DISABLE_MODULE,
moduleAddress
})
Copy link
Member

@mmv08 mmv08 Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why you chose the approach of having one generic method to perform safe contract calls.

IMO It feels too "raw" or low-level. I think it's handier to have a method responsible for the call (enableModule, disableModule, etc). This buildContractCall could be used in the internal realization. You can find an example here: https://github.com/gnosis/safe-apps-sdk/blob/master/packages/safe-apps-sdk/src/eth/index.ts#L84 Probably, not the best one 🙈 I also found that in web3.js repo, they also use that approach to build methods for rpc calls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good comment :)

I had it implemented that way before refactoring to just just have one generic method. You can check here the commit and the methods I had previously:
35c0aa1#diff-9d1172cb852904ea345f63e4470d48e4b305c14b39b6ef97202c28c356e58676L25

So it is this:

getEnableModuleTx(moduleAddress: string): Promise<SafeTransaction>
getDisableModuleTx(moduleAddress: string): Promise<SafeTransaction>
getAddOwnerTx(ownerAddress: string, threshold?: number): Promise<SafeTransaction>
getRemoveOwnerTx(ownerAddress: string, threshold?: number): Promise<SafeTransaction>
getSwapOwnerTx(oldOwnerAddress: string, newOwnerAddress: string): Promise<SafeTransaction>
getChangeThresholdTx(threshold: number): Promise<SafeTransaction>

vs. this:

buildContractCall(params: ContractCallParams): Promise<SafeTransaction>

I don't really have a strong opinion on this. I unified them because I thought the logic/concept (not the implementation) was almost the same: to get the encoding of a contract call data. So why not using just one function passing the contract method name as an argument?

Does this look too low-level? It may be.
What do you think @rmeissner? Do you also agree that is easier for the devs to have one independent method for each contract call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I also don't have a strong opinion. Ethers allows you to do both approaches, right? Not sure what is best. Probably the one where autocomplete works the best :P

@germartinez germartinez linked an issue Apr 12, 2021 that may be closed by this pull request
@germartinez germartinez requested a review from mmv08 April 22, 2021 17:16
@@ -0,0 +1,49 @@
export enum SafeSettings {
Copy link
Member

@mmv08 mmv08 Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see an import in index.ts for this file:

import { ContractCallParams, SafeSettings } from './managers/types'

I couldn't find any other ones, so seems not all types are used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove them. They are not used with the Specific methods for each contract call.

to: this.getAddress(),
value: '0',
data: await this.#moduleManager.encodeEnableModuleData(moduleAddress),
nonce: (await this.#contract.nonce()).toNumber()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I can see at some time in the future a feature request for a way to set a custom nonce. No need to address it now but better to keep it in mind when designing the project.

Copy link
Member Author

@germartinez germartinez Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was implemented in the other PR with some other improvements. (Not pushed yet) :)

Comment on lines 24 to 26
if (!isValidAddress || moduleAddress === zeroAddress || moduleAddress === SENTINEL_MODULES) {
throw new Error('Invalid module address provided')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be possibly extracted to a function for reusability and readability (as it will have a meaningful name)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also used in ownerManager

@germartinez germartinez merged commit 53f27fa into main Apr 23, 2021
@germartinez germartinez deleted the write-methods branch April 23, 2021 12:46
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle write contract functions
3 participants