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

Implement New Accessor Functions for Deploments with Multiple Addresses #685

Closed
nlordell opened this issue Jul 5, 2024 · 0 comments · Fixed by #684
Closed

Implement New Accessor Functions for Deploments with Multiple Addresses #685

nlordell opened this issue Jul 5, 2024 · 0 comments · Fixed by #684
Assignees

Comments

@nlordell
Copy link
Collaborator

nlordell commented Jul 5, 2024

Now that the JSON has been updated to allow for multiple addresses per network, new accessor functions for fetching deployments including multiple addresses need to be added to the repository.

Work has already begun in #684

@mmv08 mmv08 linked a pull request Jul 8, 2024 that will close this issue
mmv08 added a commit that referenced this issue Jul 12, 2024
This PR is a new API proposal for the functions that support the updated
JSON format, which supports multiple deployments per network. Implements
#685

The complexity of supporting multiple formats is handled by the utility
function `findDeployments`, which contains a function overload with the
deployment format parameter.

The new functions are added alongside the [existing
API](https://github.com/safe-global/safe-deployments?tab=readme-ov-file#usage)
functions but with plural `deployments` at the end of the function name.

**Example function:**
```
export const getProxyFactoryDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
  return findDeployment(filter, factoryDeployments, DeploymentFormats.MULTIPLE);
};
```

**My reason for going with this approach**:
All the complexity is kept within the internal `findDeployment`
function. Developers do not have to import and understand which format
means what and don't have to import the additional `DeploymentFilter`
enum. Type shenanigans are kept to a minimum. Also, the alternative
approach below would require refactoring package functions to be defined
via the `function` keyword because arrow functions do not support
function overloads properly:
https://www.perplexity.ai/search/typescript-arrow-function-over-tit1.0R8Rracx_PAUr1nVw#0

**Alternative approach:**
Add function overloads to the existing functions like this:
```
export const getSafeSingletonDeployment = (filter?: DeploymentFilter, format = DeploymentFormats.SINGLETON) => {
  return findDeployment(filter, _safeDeployments, format);
};
```

---------

Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants