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

Compare all deployment type addresses when relaying #1955

Merged
merged 4 commits into from
Sep 30, 2024

Conversation

iamacook
Copy link
Member

Summary

Resolves #1954

It is possible to get both singular or multiple deployment addresses since safe-global/safe-deployments#668 and, as such, there are respective get*Deployment and get*Deployments functions.

Since this adjustment in the deployments package, we never took this into account in the project. Therefore, if a chain has both canonical and EIP-155 deployments, for example, we would only be retrieving the first address found.

This adjusts all usage of the deployments package, ensuring we retrieve and compare against all deployment type addresses.

Changes

  • Create helpers to retrieve deployments, and add linting rule to ensure usage of them.
  • Modify relaying checks to compare against a list of addresses instead of a singular one.
  • Update tests accordingly.

@iamacook iamacook self-assigned this Sep 24, 2024
@iamacook iamacook requested a review from a team as a code owner September 24, 2024 12:24
@coveralls
Copy link

coveralls commented Sep 24, 2024

Pull Request Test Coverage Report for Build 11106301842

Details

  • 23 of 24 (95.83%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 90.753%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/domain/common/utils/deployments.ts 19 20 95.0%
Totals Coverage Status
Change from base Build 11011895446: -0.01%
Covered Lines: 8331
Relevant Lines: 8804

💛 - Coveralls

/**
* Helper to remap {@link SingletonDeploymentV2} to a list of checksummed addresses.
*
* @param getDeployments - deployment getters from @safe-global/safe-deployments
Copy link
Contributor

Choose a reason for hiding this comment

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

Param types missing

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in 842426e.

return formatDeployments(_getMultiSendDeployments, args);
}

type Filter = {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should either move the type to the top of the file before the functions or another file. My suggestion is to separate concerns as much as possible

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 think separate files for types is quite excessive outside of a class interface. I moved it to the top of the file in 842426e.

args.address || multiSendCallDeployment?.defaultAddress === args.address
);
const multiSendCallDeployments = getMultiSendDeployments(args);
return multiSendCallDeployments.includes(args.address);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: wdyt about simplifying this a bit by:

return (
      getMultiSendCallOnlyDeployments(args).includes(args.address) ||
      getMultiSendDeployments(args).includes(args.address)
    );

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Changed in 79fa30c.

const isL2Singleton =
safeL2Deployment?.networkAddresses[args.chainId] === singleton;
const isL1Singleton = safeL1Deployments.includes(singleton);
const isL2Singleton = safeL2Deployments.includes(singleton);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: in this case, I think it could be also simplified, and optimized (potentially avoiding a second lookup):

return (
      getSafeSingletonDeployments(args).includes(singleton) ||
      getSafeL2SingletonDeployments(args).includes(singleton)
    );

Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Changed in 79fa30c.

multiSendCallDeployment?.networkAddresses[args.chainId] ===
args.address || multiSendCallDeployment?.defaultAddress === args.address
);
return getMultiSendDeployments(args).includes(args.address);
Copy link
Member

@hectorgomezv hectorgomezv Sep 30, 2024

Choose a reason for hiding this comment

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

Nit: we could just

return getMultiSendCallOnlyDeployments(args).includes(args.address) || getMultiSendDeployments(args).includes(args.address);

And therefore get rid of all the variables and the if statement, right? Do you think it would be less readable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Initially it was to avoid getting all deployment addresses. However, it's must simpler. Changed in c5115d5.

@iamacook iamacook enabled auto-merge (squash) September 30, 2024 12:42
@iamacook iamacook merged commit cc1bc18 into main Sep 30, 2024
18 checks passed
@iamacook iamacook deleted the multiple-official-deployments branch September 30, 2024 12:45
PooyaRaki pushed a commit that referenced this pull request Oct 15, 2024
Adjusts all usage of the deployments package, ensuring we retrieve and compare against all deployment type addresses:

- Create helpers to retrieve deployments, and add linting rule to ensure usage of them.
- Modify relaying checks to compare against a list of addresses instead of a singular one.
- Update tests accordingly.
DenSmolonski pushed a commit to Zilliqa/safe-client-gateway that referenced this pull request Oct 24, 2024
Adjusts all usage of the deployments package, ensuring we retrieve and compare against all deployment type addresses:

- Create helpers to retrieve deployments, and add linting rule to ensure usage of them.
- Modify relaying checks to compare against a list of addresses instead of a singular one.
- Update tests accordingly.
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 this pull request may close these issues.

Unable to create Safe with same address on different network via relayer
4 participants