-
Notifications
You must be signed in to change notification settings - Fork 298
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
Feature: Multiple deployments functions #684
Conversation
6eb41fe
to
354b3c6
Compare
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.
LGTM.
I put this on pause because of a conflict with #683. I'll let @remedcu make the final changes to the JSON file structure. Also, in the meantime, we can wait for feedback from @gjeanmart and @katspaugh |
src/__tests__/libs.test.ts
Outdated
|
||
describe('libs.ts', () => { | ||
describe('getMultiSendDeployment', () => { | ||
it('should find the preferred deployment first', () => { | ||
const result = getMultiSendDeployment(); | ||
expect(result).toMatchObject(MultiSend141); | ||
expect(result).not.toBe(MultiSend111); |
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 removed this because it seemed redundant. The same reasoning for other similar removals
src/__tests__/safes.test.ts
Outdated
// @ts-expect-error The function is conditionally exported only if the process.env.NODE_ENV is 'test'. TypeScript will not be able to figure it out. | ||
import { mapJsonToDeploymentsFormatV2 } from '../utils'; |
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.
uber-nit: To abstract this away, you could have a src/__tests__/utils.ts
file that re-exports this symbol, so you only have to work around and document this TS issue in a single plance, and all tests import from:
// @ts-expect-error The function is conditionally exported only if the process.env.NODE_ENV is 'test'. TypeScript will not be able to figure it out. | |
import { mapJsonToDeploymentsFormatV2 } from '../utils'; | |
import { mapJsonToDeploymentsFormatV2 } from './utils'; |
export const getDefaultCallbackHandlerDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => { | ||
return findDeployment(filter, defaultCallbackHandlerDeployments); | ||
}; | ||
|
||
export const getDefaultCallbackHandlerDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => { |
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.
Should this also have a NatSpec function (saw you adding them in other places)?
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.
added
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.
LGTM. 2 small things, but approving to reduce back-and-forth:
- One suggestion to avoid the long
@ts-expect-error
explanation in multiple places (but feel free to merge without this suggestion if you don't agree) - One missing function documentation
…1-multiple-deployments-function
9410461
to
1979fde
Compare
1979fde
to
94cf3a1
Compare
// We use some specific types (like `AddressType`) in the `SingletonDeploymentJSON` type, but the TypeScript cannot infer that from the JSON files. | ||
// So we need to cast them to `SingletonDeploymentJSON` manually. The casting is valid because we have a test in `__tests__/assets.test.ts` that checks that the JSON files are valid. | ||
// The arrays are sorted by preference, which at the moment means from the most recent version to the oldest. | ||
// The arrays are prefixed with an underscore because they are not meant to be imported directly. |
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 shouldn't affect a bundler's ability to tree-shake right?
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.
Well, that's a very complex question. We do not export an ESM
bundle with the best tree shaking support.
https://webpack.js.org/guides/tree-shaking/
We also do not support tree shaking with commonjs by adding helper options. I don't know how this affects tree shaking or whether the lib was previously tree-shakeable.
const _SIGN_MESSAGE_LIB_DEPLOYMENTS = [SignMessageLib141, SignMessageLib130] as SingletonDeploymentJSON[]; | ||
|
||
export { | ||
_ACCESSOR_DEPLOYMENTS, |
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.
Why _
prefixes?
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.
// The arrays are prefixed with an underscore because they are not meant to be imported directly.
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.
LGTM, one suggestion for types (I find the object notation easier to understand than the Record
type).
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
8f70103
to
7634cfc
Compare
I have just realised that I'm an idiot and I forgot to add documentation 🤦 |
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 functions but with plural
deployments
at the end of the function name.Example function:
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 additionalDeploymentFilter
enum. Type shenanigans are kept to a minimum. Also, the alternative approach below would require refactoring package functions to be defined via thefunction
keyword because arrow functions do not support function overloads properly: https://www.perplexity.ai/search/typescript-arrow-function-over-tit1.0R8Rracx_PAUr1nVw#0Alternative approach:
Add function overloads to the existing functions like this: