@safe-global/safe-deployments 1.37.1 → 1.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -10
- package/dist/accessors.d.ts +14 -1
- package/dist/accessors.js +19 -9
- package/dist/assets/v1.0.0/gnosis_safe.json +5 -3
- package/dist/assets/v1.0.0/proxy_factory.json +5 -3
- package/dist/assets/v1.1.1/default_callback_handler.json +5 -3
- package/dist/assets/v1.1.1/gnosis_safe.json +5 -3
- package/dist/assets/v1.1.1/multi_send.json +5 -3
- package/dist/assets/v1.1.1/proxy_factory.json +5 -3
- package/dist/assets/v1.2.0/gnosis_safe.json +5 -3
- package/dist/assets/v1.3.0/compatibility_fallback_handler.json +17 -5
- package/dist/assets/v1.3.0/create_call.json +17 -5
- package/dist/assets/v1.3.0/gnosis_safe.json +17 -5
- package/dist/assets/v1.3.0/gnosis_safe_l2.json +17 -5
- package/dist/assets/v1.3.0/multi_send.json +17 -5
- package/dist/assets/v1.3.0/multi_send_call_only.json +17 -5
- package/dist/assets/v1.3.0/proxy_factory.json +17 -5
- package/dist/assets/v1.3.0/sign_message_lib.json +17 -5
- package/dist/assets/v1.3.0/simulate_tx_accessor.json +17 -5
- package/dist/assets/v1.4.1/compatibility_fallback_handler.json +8 -3
- package/dist/assets/v1.4.1/create_call.json +8 -3
- package/dist/assets/v1.4.1/multi_send.json +8 -3
- package/dist/assets/v1.4.1/multi_send_call_only.json +8 -3
- package/dist/assets/v1.4.1/safe.json +8 -3
- package/dist/assets/v1.4.1/safe_l2.json +8 -3
- package/dist/assets/v1.4.1/safe_proxy_factory.json +8 -3
- package/dist/assets/v1.4.1/sign_message_lib.json +8 -3
- package/dist/assets/v1.4.1/simulate_tx_accessor.json +8 -3
- package/dist/deployments.d.ts +12 -0
- package/dist/deployments.js +71 -0
- package/dist/factories.d.ts +12 -1
- package/dist/factories.js +17 -16
- package/dist/handler.d.ts +29 -1
- package/dist/handler.js +55 -25
- package/dist/libs.d.ts +45 -1
- package/dist/libs.js +62 -24
- package/dist/safes.d.ts +23 -3
- package/dist/safes.js +32 -23
- package/dist/types.d.ts +21 -12
- package/dist/types.js +0 -11
- package/dist/utils.d.ts +5 -2
- package/dist/utils.js +34 -11
- package/package.json +6 -5
- package/src/__tests__/assets/v1/v1.0.0/gnosis_safe.json +5 -3
- package/src/__tests__/assets/v1/v1.0.0/proxy_factory.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/create_and_add_modules.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/create_call.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/default_callback_handler.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/gnosis_safe.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/multi_send.json +5 -3
- package/src/__tests__/assets/v1/v1.1.1/proxy_factory.json +5 -3
- package/src/__tests__/assets/v1/v1.2.0/gnosis_safe.json +5 -3
- package/src/__tests__/assets/v1/v1.3.0/compatibility_fallback_handler.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/create_call.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/gnosis_safe.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/gnosis_safe_l2.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/multi_send.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/multi_send_call_only.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/proxy_factory.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/sign_message_lib.json +13 -5
- package/src/__tests__/assets/v1/v1.3.0/simulate_tx_accessor.json +13 -5
- package/src/__tests__/assets/v1/v1.4.1/compatibility_fallback_handler.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/create_call.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/multi_send.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/multi_send_call_only.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/safe.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/safe_l2.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/safe_proxy_factory.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/sign_message_lib.json +5 -3
- package/src/__tests__/assets/v1/v1.4.1/simulate_tx_accessor.json +5 -3
- package/src/__tests__/assets.test.ts +7 -7
- package/src/__tests__/utils.test.ts +386 -236
- package/src/accessors.ts +19 -8
- package/src/assets/v1.0.0/gnosis_safe.json +5 -3
- package/src/assets/v1.0.0/proxy_factory.json +5 -3
- package/src/assets/v1.1.1/create_and_add_modules.json +5 -3
- package/src/assets/v1.1.1/create_call.json +5 -3
- package/src/assets/v1.1.1/default_callback_handler.json +5 -3
- package/src/assets/v1.1.1/gnosis_safe.json +5 -3
- package/src/assets/v1.1.1/multi_send.json +5 -3
- package/src/assets/v1.1.1/proxy_factory.json +5 -3
- package/src/assets/v1.2.0/gnosis_safe.json +5 -3
- package/src/assets/v1.3.0/compatibility_fallback_handler.json +17 -5
- package/src/assets/v1.3.0/create_call.json +17 -5
- package/src/assets/v1.3.0/gnosis_safe.json +17 -5
- package/src/assets/v1.3.0/gnosis_safe_l2.json +17 -5
- package/src/assets/v1.3.0/multi_send.json +17 -5
- package/src/assets/v1.3.0/multi_send_call_only.json +17 -5
- package/src/assets/v1.3.0/proxy_factory.json +17 -5
- package/src/assets/v1.3.0/sign_message_lib.json +17 -5
- package/src/assets/v1.3.0/simulate_tx_accessor.json +17 -5
- package/src/assets/v1.4.1/compatibility_fallback_handler.json +8 -3
- package/src/assets/v1.4.1/create_call.json +8 -3
- package/src/assets/v1.4.1/multi_send.json +8 -3
- package/src/assets/v1.4.1/multi_send_call_only.json +8 -3
- package/src/assets/v1.4.1/safe.json +8 -3
- package/src/assets/v1.4.1/safe_l2.json +8 -3
- package/src/assets/v1.4.1/safe_proxy_factory.json +8 -3
- package/src/assets/v1.4.1/sign_message_lib.json +8 -3
- package/src/assets/v1.4.1/simulate_tx_accessor.json +8 -3
- package/src/deployments.ts +90 -0
- package/src/factories.ts +17 -15
- package/src/handler.ts +56 -23
- package/src/libs.ts +64 -22
- package/src/safes.ts +31 -21
- package/src/types.ts +27 -25
- package/src/utils.ts +63 -8
package/src/libs.ts
CHANGED
|
@@ -1,38 +1,80 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import SignMessageLib130 from './assets/v1.3.0/sign_message_lib.json';
|
|
9
|
-
import SignMessageLib141 from './assets/v1.4.1/sign_message_lib.json';
|
|
10
|
-
import { DeploymentFilter, SingletonDeployment, SingletonDeploymentJSON } from './types';
|
|
1
|
+
import {
|
|
2
|
+
_CREATE_CALL_DEPLOYMENTS,
|
|
3
|
+
_MULTI_SEND_CALL_ONLY_DEPLOYMENTS,
|
|
4
|
+
_MULTI_SEND_DEPLOYMENTS,
|
|
5
|
+
_SIGN_MESSAGE_LIB_DEPLOYMENTS,
|
|
6
|
+
} from './deployments';
|
|
7
|
+
import { DeploymentFilter, DeploymentFormats, SingletonDeployment, SingletonDeploymentV2 } from './types';
|
|
11
8
|
import { findDeployment } from './utils';
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Get the MultiSend deployment based on the provided filter.
|
|
12
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployment.
|
|
13
|
+
* @returns {SingletonDeployment | undefined} - The matched deployment or undefined if not found.
|
|
14
|
+
*/
|
|
16
15
|
export const getMultiSendDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
17
|
-
return findDeployment(filter,
|
|
16
|
+
return findDeployment(filter, _MULTI_SEND_DEPLOYMENTS);
|
|
18
17
|
};
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Get all MultiSend deployments based on the provided filter.
|
|
21
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployments.
|
|
22
|
+
* @returns {SingletonDeploymentV2 | undefined} - The matched deployments or undefined if not found.
|
|
23
|
+
*/
|
|
24
|
+
export const getMultiSendDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
25
|
+
return findDeployment(filter, _MULTI_SEND_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
26
|
+
};
|
|
22
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Get the MultiSendCallOnly deployment based on the provided filter.
|
|
30
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployment.
|
|
31
|
+
* @returns {SingletonDeployment | undefined} - The matched deployment or undefined if not found.
|
|
32
|
+
*/
|
|
23
33
|
export const getMultiSendCallOnlyDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
24
|
-
return findDeployment(filter,
|
|
34
|
+
return findDeployment(filter, _MULTI_SEND_CALL_ONLY_DEPLOYMENTS);
|
|
25
35
|
};
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Get all MultiSendCallOnly deployments based on the provided filter.
|
|
39
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployments.
|
|
40
|
+
* @returns {SingletonDeploymentV2 | undefined} - The matched deployments or undefined if not found.
|
|
41
|
+
*/
|
|
42
|
+
export const getMultiSendCallOnlyDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
43
|
+
return findDeployment(filter, _MULTI_SEND_CALL_ONLY_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
44
|
+
};
|
|
29
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Get the CreateCall deployment based on the provided filter.
|
|
48
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployment.
|
|
49
|
+
* @returns {SingletonDeployment | undefined} - The matched deployment or undefined if not found.
|
|
50
|
+
*/
|
|
30
51
|
export const getCreateCallDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
31
|
-
return findDeployment(filter,
|
|
52
|
+
return findDeployment(filter, _CREATE_CALL_DEPLOYMENTS);
|
|
32
53
|
};
|
|
33
54
|
|
|
34
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Get all CreateCall deployments based on the provided filter.
|
|
57
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployments.
|
|
58
|
+
* @returns {SingletonDeploymentV2 | undefined} - The matched deployments or undefined if not found.
|
|
59
|
+
*/
|
|
60
|
+
export const getCreateCallDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
61
|
+
return findDeployment(filter, _CREATE_CALL_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
62
|
+
};
|
|
35
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Get the SignMessageLib deployment based on the provided filter.
|
|
66
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployment.
|
|
67
|
+
* @returns {SingletonDeployment | undefined} - The matched deployment or undefined if not found.
|
|
68
|
+
*/
|
|
36
69
|
export const getSignMessageLibDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
37
|
-
return findDeployment(filter,
|
|
70
|
+
return findDeployment(filter, _SIGN_MESSAGE_LIB_DEPLOYMENTS);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get all SignMessageLib deployments based on the provided filter.
|
|
75
|
+
* @param {DeploymentFilter} [filter] - The filter criteria for the deployments.
|
|
76
|
+
* @returns {SingletonDeploymentV2 | undefined} - The matched deployments or undefined if not found.
|
|
77
|
+
*/
|
|
78
|
+
export const getSignMessageLibDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
79
|
+
return findDeployment(filter, _SIGN_MESSAGE_LIB_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
38
80
|
};
|
package/src/safes.ts
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import GnosisSafeL2130 from './assets/v1.3.0/gnosis_safe_l2.json';
|
|
4
|
-
import GnosisSafe130 from './assets/v1.3.0/gnosis_safe.json';
|
|
5
|
-
import GnosisSafe120 from './assets/v1.2.0/gnosis_safe.json';
|
|
6
|
-
import GnosisSafe111 from './assets/v1.1.1/gnosis_safe.json';
|
|
7
|
-
import GnosisSafe100 from './assets/v1.0.0/gnosis_safe.json';
|
|
8
|
-
import { DeploymentFilter, SingletonDeployment, SingletonDeploymentJSON } from './types';
|
|
1
|
+
import { _SAFE_DEPLOYMENTS, _SAFE_L2_DEPLOYMENTS } from './deployments';
|
|
2
|
+
import { DeploymentFilter, DeploymentFormats, SingletonDeployment, SingletonDeploymentV2 } from './types';
|
|
9
3
|
import { findDeployment } from './utils';
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
GnosisSafe111,
|
|
17
|
-
GnosisSafe100,
|
|
18
|
-
];
|
|
19
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Finds the latest safe singleton deployment that matches the given filter.
|
|
7
|
+
* @param {DeploymentFilter} [filter] - The filter to apply when searching for the deployment.
|
|
8
|
+
* @returns {SingletonDeployment | undefined} - The found deployment or undefined if no deployment matches the filter.
|
|
9
|
+
*/
|
|
20
10
|
export const getSafeSingletonDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
21
|
-
return findDeployment(filter,
|
|
11
|
+
return findDeployment(filter, _SAFE_DEPLOYMENTS);
|
|
22
12
|
};
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Finds all safe singleton deployments that match the given filter.
|
|
16
|
+
* @param {DeploymentFilter} [filter] - The filter to apply when searching for the deployments.
|
|
17
|
+
* @returns {SingletonDeploymentV2 | undefined} - The found deployments or undefined if no deployments match the filter.
|
|
18
|
+
*/
|
|
19
|
+
export const getSafeSingletonDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
20
|
+
return findDeployment(filter, _SAFE_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
21
|
+
};
|
|
26
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Finds the latest safe L2 singleton deployment that matches the given filter.
|
|
25
|
+
* @param {DeploymentFilter} [filter] - The filter to apply when searching for the deployment.
|
|
26
|
+
* @returns {SingletonDeployment | undefined} - The found deployment or undefined if no deployment matches the filter.
|
|
27
|
+
*/
|
|
27
28
|
export const getSafeL2SingletonDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
28
|
-
return findDeployment(filter,
|
|
29
|
+
return findDeployment(filter, _SAFE_L2_DEPLOYMENTS);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Finds all safe L2 singleton deployments that match the given filter.
|
|
34
|
+
* @param {DeploymentFilter} [filter] - The filter to apply when searching for the deployments.
|
|
35
|
+
* @returns {SingletonDeploymentV2 | undefined} - The found deployments or undefined if no deployments match the filter.
|
|
36
|
+
*/
|
|
37
|
+
export const getSafeL2SingletonDeployments = (filter?: DeploymentFilter): SingletonDeploymentV2 | undefined => {
|
|
38
|
+
return findDeployment(filter, _SAFE_L2_DEPLOYMENTS, DeploymentFormats.MULTIPLE);
|
|
29
39
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
// The original address the contract was deployed on.
|
|
3
|
-
// Starting with 1.4.1, the contracts are deployed with an EIP155-compatible transaction.
|
|
4
|
-
CANONICAL = 'canonical',
|
|
1
|
+
export type AddressType = 'canonical' | 'eip155' | 'zksync';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
// The
|
|
8
|
-
|
|
3
|
+
export const enum DeploymentFormats {
|
|
4
|
+
// The old format that only allows a single address for each network.
|
|
5
|
+
SINGLETON = 'singleton',
|
|
9
6
|
|
|
10
|
-
//
|
|
11
|
-
|
|
7
|
+
// The new format that allows multiple addresses for each network.
|
|
8
|
+
MULTIPLE = 'multiple',
|
|
12
9
|
}
|
|
13
10
|
|
|
11
|
+
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
|
|
12
|
+
|
|
14
13
|
export interface SingletonDeploymentJSON {
|
|
15
14
|
// Indicates if the deployment is released.
|
|
16
15
|
released: boolean;
|
|
@@ -21,20 +20,19 @@ export interface SingletonDeploymentJSON {
|
|
|
21
20
|
// The version of the deployment.
|
|
22
21
|
version: string;
|
|
23
22
|
|
|
24
|
-
// The hash of the contract code.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// A record of network addresses, where the key is the network identifier and the value is either a single address type or an array of address types.
|
|
28
|
-
networkAddresses: Record<string, string | string[]>;
|
|
29
|
-
|
|
30
|
-
// A record of addresses, where the key is the address type and the value is the address.
|
|
23
|
+
// The address & hash of the contract code, where the key is the deployment type.
|
|
24
|
+
// There could be multiple deployment types: canonical, eip155, zksync
|
|
31
25
|
// Possible addresses per version:
|
|
32
26
|
// 1.0.0: canonical
|
|
33
27
|
// 1.1.1: canonical
|
|
34
28
|
// 1.2.0: canonical
|
|
35
29
|
// 1.3.0: canonical, eip155, zksync
|
|
36
30
|
// 1.4.1: canonical, zksync
|
|
37
|
-
|
|
31
|
+
// Ex: deployments: { "canonical": { "codeHash": "0x1234", "address": "0x5678"}}
|
|
32
|
+
deployments: AtLeastOne<Record<AddressType, { address: string; codeHash: string }>>;
|
|
33
|
+
|
|
34
|
+
// A record of network addresses, where the key is the network identifier and the value is either a single address type or an array of address types.
|
|
35
|
+
networkAddresses: Record<string, AddressType | AddressType[]>;
|
|
38
36
|
|
|
39
37
|
// The ABI (Application Binary Interface) of the contract.
|
|
40
38
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
@@ -56,11 +54,16 @@ export interface SingletonDeployment {
|
|
|
56
54
|
// The version of the deployment.
|
|
57
55
|
version: string;
|
|
58
56
|
|
|
59
|
-
// The hash of the contract code.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
57
|
+
// The address & hash of the contract code, where the key is the deployment type.
|
|
58
|
+
// There could be multiple deployment types: canonical, eip155, zksync
|
|
59
|
+
// Possible addresses per version:
|
|
60
|
+
// 1.0.0: canonical
|
|
61
|
+
// 1.1.1: canonical
|
|
62
|
+
// 1.2.0: canonical
|
|
63
|
+
// 1.3.0: canonical, eip155, zksync
|
|
64
|
+
// 1.4.1: canonical, zksync
|
|
65
|
+
// Ex: deployments: { "canonical": { "codeHash": "0x1234", "address": "0x5678"}}
|
|
66
|
+
deployments: AtLeastOne<Record<AddressType, { address: string; codeHash: string }>>;
|
|
64
67
|
|
|
65
68
|
// A record of network addresses, where the key is the network identifier and the value is the address.
|
|
66
69
|
networkAddresses: Record<string, string>;
|
|
@@ -74,11 +77,10 @@ export interface SingletonDeploymentV2 {
|
|
|
74
77
|
released: boolean;
|
|
75
78
|
contractName: string;
|
|
76
79
|
version: string;
|
|
77
|
-
codeHash: string
|
|
80
|
+
deployments: AtLeastOne<Record<AddressType, { address: string; codeHash: string }>>;
|
|
78
81
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
79
82
|
abi: any[];
|
|
80
|
-
networkAddresses: Record<string,
|
|
81
|
-
addresses: Partial<Record<AddressType, string>>;
|
|
83
|
+
networkAddresses: Record<string, string | string[]>;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export interface DeploymentFilter {
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DeploymentFilter,
|
|
3
|
+
SingletonDeployment,
|
|
4
|
+
SingletonDeploymentJSON,
|
|
5
|
+
DeploymentFormats,
|
|
6
|
+
SingletonDeploymentV2,
|
|
7
|
+
AddressType,
|
|
8
|
+
} from './types';
|
|
2
9
|
import semverSatisfies from 'semver/functions/satisfies';
|
|
3
10
|
|
|
4
11
|
const DEFAULT_FILTER: DeploymentFilter = { released: true };
|
|
@@ -18,28 +25,68 @@ const mapJsonToDeploymentsFormatV1 = (deployment: SingletonDeploymentJSON): Sing
|
|
|
18
25
|
const defaultAddressType = Array.isArray(deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID])
|
|
19
26
|
? deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID][0]
|
|
20
27
|
: deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID];
|
|
21
|
-
|
|
28
|
+
// The usage of non-null assertion below is safe, because we validate that the asset files are properly formed in tests
|
|
29
|
+
const defaultAddress = deployment.deployments[defaultAddressType]!.address;
|
|
22
30
|
const networkAddresses = Object.fromEntries(
|
|
23
31
|
Object.entries(deployment.networkAddresses).map(([chainId, addressTypes]) => [
|
|
24
32
|
chainId,
|
|
25
|
-
Array.isArray(addressTypes)
|
|
33
|
+
Array.isArray(addressTypes)
|
|
34
|
+
? deployment.deployments[addressTypes[0]]!.address
|
|
35
|
+
: deployment.deployments[addressTypes]!.address,
|
|
26
36
|
]),
|
|
27
37
|
);
|
|
28
38
|
|
|
29
39
|
return { ...deployment, defaultAddress, networkAddresses };
|
|
30
40
|
};
|
|
31
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Maps a SingletonDeploymentJSON object to a SingletonDeploymentV2 object.
|
|
44
|
+
*
|
|
45
|
+
* This function transforms the `networkAddresses` field of the deployment JSON object.
|
|
46
|
+
* It converts each entry in `networkAddresses` to an array of addresses, using the `addresses` field
|
|
47
|
+
* to resolve each address type.
|
|
48
|
+
*
|
|
49
|
+
* @param {SingletonDeploymentJSON} deployment - The deployment JSON object to map.
|
|
50
|
+
* @returns {SingletonDeploymentV2} - The mapped deployment object in V2 format.
|
|
51
|
+
*/
|
|
52
|
+
const mapJsonToDeploymentsFormatV2 = (deployment: SingletonDeploymentJSON): SingletonDeploymentV2 => {
|
|
53
|
+
const newJson = { ...deployment };
|
|
54
|
+
newJson.networkAddresses = Object.fromEntries(
|
|
55
|
+
Object.entries(deployment.networkAddresses).map(([chainId, addressTypes]) => [
|
|
56
|
+
chainId,
|
|
57
|
+
(Array.isArray(addressTypes)
|
|
58
|
+
? // The usage of non-null assertion below is safe, because we validate that the asset files are properly formed in tests
|
|
59
|
+
(addressTypes.map((addressType) => deployment.deployments[addressType]!.address) as AddressType[])
|
|
60
|
+
: deployment.deployments[addressTypes]!.address) as AddressType,
|
|
61
|
+
]),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return newJson;
|
|
65
|
+
};
|
|
66
|
+
|
|
32
67
|
/**
|
|
33
68
|
* Finds a deployment that matches the given criteria.
|
|
69
|
+
* This function is implemented as a regular function to allow for overloading: https://github.com/microsoft/TypeScript/issues/33482
|
|
34
70
|
*
|
|
35
71
|
* @param {DeploymentFilter} [criteria=DEFAULT_FILTER] - The filter criteria to match deployments.
|
|
36
72
|
* @param {SingletonDeploymentJSON[]} deployments - The list of deployment JSON objects to search.
|
|
37
73
|
* @returns {SingletonDeployment | undefined} - The found deployment object or undefined if no match is found.
|
|
38
74
|
*/
|
|
39
|
-
|
|
40
|
-
criteria: DeploymentFilter
|
|
75
|
+
function findDeployment(
|
|
76
|
+
criteria: DeploymentFilter | undefined,
|
|
77
|
+
deployments: SingletonDeploymentJSON[],
|
|
78
|
+
format?: DeploymentFormats.SINGLETON,
|
|
79
|
+
): SingletonDeployment | undefined;
|
|
80
|
+
function findDeployment(
|
|
81
|
+
criteria: DeploymentFilter | undefined,
|
|
41
82
|
deployments: SingletonDeploymentJSON[],
|
|
42
|
-
|
|
83
|
+
format: DeploymentFormats.MULTIPLE,
|
|
84
|
+
): SingletonDeploymentV2 | undefined;
|
|
85
|
+
function findDeployment(
|
|
86
|
+
criteria = DEFAULT_FILTER,
|
|
87
|
+
deployments: SingletonDeploymentJSON[],
|
|
88
|
+
format: DeploymentFormats = DeploymentFormats.SINGLETON,
|
|
89
|
+
): SingletonDeployment | SingletonDeploymentV2 | undefined {
|
|
43
90
|
const { version, released, network } = { ...DEFAULT_FILTER, ...criteria };
|
|
44
91
|
|
|
45
92
|
const deploymentJson = deployments.find((deployment) => {
|
|
@@ -50,5 +97,13 @@ export const findDeployment = (
|
|
|
50
97
|
return true;
|
|
51
98
|
});
|
|
52
99
|
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
if (!deploymentJson) return undefined;
|
|
101
|
+
|
|
102
|
+
if (format === DeploymentFormats.MULTIPLE) {
|
|
103
|
+
return mapJsonToDeploymentsFormatV2(deploymentJson);
|
|
104
|
+
} else {
|
|
105
|
+
return mapJsonToDeploymentsFormatV1(deploymentJson);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { findDeployment };
|