@safe-global/safe-deployments 1.37.0 → 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 +150 -31
- package/dist/accessors.d.ts +14 -1
- package/dist/accessors.js +19 -11
- package/dist/assets/v1.0.0/gnosis_safe.json +479 -103
- package/dist/assets/v1.0.0/proxy_factory.json +11 -6
- package/dist/assets/v1.1.1/default_callback_handler.json +14 -9
- package/dist/assets/v1.1.1/gnosis_safe.json +14 -9
- package/dist/assets/v1.1.1/multi_send.json +14 -9
- package/dist/assets/v1.1.1/proxy_factory.json +14 -9
- package/dist/assets/v1.2.0/gnosis_safe.json +14 -9
- package/dist/assets/v1.3.0/compatibility_fallback_handler.json +259 -235
- package/dist/assets/v1.3.0/create_call.json +259 -235
- package/dist/assets/v1.3.0/gnosis_safe.json +259 -235
- package/dist/assets/v1.3.0/gnosis_safe_l2.json +259 -235
- package/dist/assets/v1.3.0/multi_send.json +259 -235
- package/dist/assets/v1.3.0/multi_send_call_only.json +259 -235
- package/dist/assets/v1.3.0/proxy_factory.json +259 -235
- package/dist/assets/v1.3.0/sign_message_lib.json +260 -236
- package/dist/assets/v1.3.0/simulate_tx_accessor.json +259 -235
- package/dist/assets/v1.4.1/compatibility_fallback_handler.json +119 -108
- package/dist/assets/v1.4.1/create_call.json +119 -108
- package/dist/assets/v1.4.1/multi_send.json +119 -108
- package/dist/assets/v1.4.1/multi_send_call_only.json +119 -108
- package/dist/assets/v1.4.1/safe.json +119 -108
- package/dist/assets/v1.4.1/safe_l2.json +119 -108
- package/dist/assets/v1.4.1/safe_proxy_factory.json +120 -109
- package/dist/assets/v1.4.1/sign_message_lib.json +120 -109
- package/dist/assets/v1.4.1/simulate_tx_accessor.json +119 -108
- 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 -13
- package/dist/handler.d.ts +29 -1
- package/dist/handler.js +55 -24
- package/dist/libs.d.ts +45 -1
- package/dist/libs.js +62 -32
- package/dist/safes.d.ts +23 -3
- package/dist/safes.js +32 -21
- package/dist/types.d.ts +37 -2
- package/dist/utils.d.ts +12 -2
- package/dist/utils.js +61 -9
- package/package.json +18 -19
- package/src/__tests__/assets/v1/v1.0.0/gnosis_safe.json +796 -0
- package/src/__tests__/assets/v1/v1.0.0/proxy_factory.json +111 -0
- package/src/__tests__/assets/v1/v1.1.1/create_and_add_modules.json +59 -0
- package/src/__tests__/assets/v1/v1.1.1/create_call.json +90 -0
- package/src/__tests__/assets/v1/v1.1.1/default_callback_handler.json +212 -0
- package/src/__tests__/assets/v1/v1.1.1/gnosis_safe.json +1001 -0
- package/src/__tests__/assets/v1/v1.1.1/multi_send.json +45 -0
- package/src/__tests__/assets/v1/v1.1.1/proxy_factory.json +191 -0
- package/src/__tests__/assets/v1/v1.2.0/gnosis_safe.json +1022 -0
- package/src/__tests__/assets/v1/v1.3.0/compatibility_fallback_handler.json +588 -0
- package/src/__tests__/assets/v1/v1.3.0/create_call.json +331 -0
- package/src/__tests__/assets/v1/v1.3.0/gnosis_safe.json +1296 -0
- package/src/__tests__/assets/v1/v1.3.0/gnosis_safe_l2.json +1401 -0
- package/src/__tests__/assets/v1/v1.3.0/multi_send.json +283 -0
- package/src/__tests__/assets/v1/v1.3.0/multi_send_call_only.json +278 -0
- package/src/__tests__/assets/v1/v1.3.0/proxy_factory.json +426 -0
- package/src/__tests__/assets/v1/v1.3.0/sign_message_lib.json +310 -0
- package/src/__tests__/assets/v1/v1.3.0/simulate_tx_accessor.json +314 -0
- package/src/__tests__/assets/v1/v1.4.1/compatibility_fallback_handler.json +447 -0
- package/src/__tests__/assets/v1/v1.4.1/create_call.json +192 -0
- package/src/__tests__/assets/v1/v1.4.1/multi_send.json +144 -0
- package/src/__tests__/assets/v1/v1.4.1/multi_send_call_only.json +139 -0
- package/src/__tests__/assets/v1/v1.4.1/safe.json +1123 -0
- package/src/__tests__/assets/v1/v1.4.1/safe_l2.json +1228 -0
- package/src/__tests__/assets/v1/v1.4.1/safe_proxy_factory.json +263 -0
- package/src/__tests__/assets/v1/v1.4.1/sign_message_lib.json +171 -0
- package/src/__tests__/assets/v1/v1.4.1/simulate_tx_accessor.json +175 -0
- package/src/__tests__/assets.test.ts +101 -38
- package/src/__tests__/factories.test.ts +3 -3
- package/src/__tests__/handler.test.ts +5 -5
- package/src/__tests__/libs.test.ts +9 -9
- package/src/__tests__/safes.test.ts +9 -12
- package/src/__tests__/utils.test.ts +421 -0
- package/src/accessors.ts +21 -12
- package/src/assets/v1.0.0/gnosis_safe.json +479 -103
- package/src/assets/v1.0.0/proxy_factory.json +11 -6
- package/src/assets/v1.1.1/create_and_add_modules.json +19 -10
- package/src/assets/v1.1.1/create_call.json +14 -9
- package/src/assets/v1.1.1/default_callback_handler.json +14 -9
- package/src/assets/v1.1.1/gnosis_safe.json +14 -9
- package/src/assets/v1.1.1/multi_send.json +14 -9
- package/src/assets/v1.1.1/proxy_factory.json +14 -9
- package/src/assets/v1.2.0/gnosis_safe.json +14 -9
- package/src/assets/v1.3.0/compatibility_fallback_handler.json +259 -235
- package/src/assets/v1.3.0/create_call.json +259 -235
- package/src/assets/v1.3.0/gnosis_safe.json +259 -235
- package/src/assets/v1.3.0/gnosis_safe_l2.json +259 -235
- package/src/assets/v1.3.0/multi_send.json +259 -235
- package/src/assets/v1.3.0/multi_send_call_only.json +259 -235
- package/src/assets/v1.3.0/proxy_factory.json +259 -235
- package/src/assets/v1.3.0/sign_message_lib.json +260 -236
- package/src/assets/v1.3.0/simulate_tx_accessor.json +259 -235
- package/src/assets/v1.4.1/compatibility_fallback_handler.json +119 -108
- package/src/assets/v1.4.1/create_call.json +119 -108
- package/src/assets/v1.4.1/multi_send.json +119 -108
- package/src/assets/v1.4.1/multi_send_call_only.json +119 -108
- package/src/assets/v1.4.1/safe.json +119 -108
- package/src/assets/v1.4.1/safe_l2.json +119 -108
- package/src/assets/v1.4.1/safe_proxy_factory.json +120 -109
- package/src/assets/v1.4.1/sign_message_lib.json +120 -109
- package/src/assets/v1.4.1/simulate_tx_accessor.json +119 -108
- package/src/deployments.ts +90 -0
- package/src/factories.ts +19 -14
- package/src/handler.ts +62 -26
- package/src/index.ts +6 -6
- package/src/libs.ts +69 -35
- package/src/safes.ts +34 -22
- package/src/types.ts +86 -10
- package/src/utils.ts +105 -12
- package/src/__tests__/utilts.test.ts +0 -385
package/src/safes.ts
CHANGED
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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 } from './types'
|
|
9
|
-
import { findDeployment } from './utils'
|
|
10
|
-
|
|
11
|
-
// This is a sorted array (newest to oldest), exported for tests
|
|
12
|
-
export const _safeDeployments: SingletonDeployment[] = [
|
|
13
|
-
Safe141, GnosisSafe130, GnosisSafe120, GnosisSafe111, GnosisSafe100
|
|
14
|
-
]
|
|
1
|
+
import { _SAFE_DEPLOYMENTS, _SAFE_L2_DEPLOYMENTS } from './deployments';
|
|
2
|
+
import { DeploymentFilter, DeploymentFormats, SingletonDeployment, SingletonDeploymentV2 } from './types';
|
|
3
|
+
import { findDeployment } from './utils';
|
|
15
4
|
|
|
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
|
+
*/
|
|
16
10
|
export const getSafeSingletonDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
17
|
-
|
|
18
|
-
}
|
|
11
|
+
return findDeployment(filter, _SAFE_DEPLOYMENTS);
|
|
12
|
+
};
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
};
|
|
24
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
|
+
*/
|
|
25
28
|
export const getSafeL2SingletonDeployment = (filter?: DeploymentFilter): SingletonDeployment | undefined => {
|
|
26
|
-
|
|
27
|
-
}
|
|
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);
|
|
39
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,14 +1,90 @@
|
|
|
1
|
+
export type AddressType = 'canonical' | 'eip155' | 'zksync';
|
|
2
|
+
|
|
3
|
+
export const enum DeploymentFormats {
|
|
4
|
+
// The old format that only allows a single address for each network.
|
|
5
|
+
SINGLETON = 'singleton',
|
|
6
|
+
|
|
7
|
+
// The new format that allows multiple addresses for each network.
|
|
8
|
+
MULTIPLE = 'multiple',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
|
|
12
|
+
|
|
13
|
+
export interface SingletonDeploymentJSON {
|
|
14
|
+
// Indicates if the deployment is released.
|
|
15
|
+
released: boolean;
|
|
16
|
+
|
|
17
|
+
// The name of the contract.
|
|
18
|
+
contractName: string;
|
|
19
|
+
|
|
20
|
+
// The version of the deployment.
|
|
21
|
+
version: string;
|
|
22
|
+
|
|
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
|
|
25
|
+
// Possible addresses per version:
|
|
26
|
+
// 1.0.0: canonical
|
|
27
|
+
// 1.1.1: canonical
|
|
28
|
+
// 1.2.0: canonical
|
|
29
|
+
// 1.3.0: canonical, eip155, zksync
|
|
30
|
+
// 1.4.1: canonical, zksync
|
|
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[]>;
|
|
36
|
+
|
|
37
|
+
// The ABI (Application Binary Interface) of the contract.
|
|
38
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
39
|
+
abi: any[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// This is the old type that only allows a single address for each network.
|
|
43
|
+
// It is still used for backwards compatibility.
|
|
1
44
|
export interface SingletonDeployment {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
45
|
+
// The default address of the deployment.
|
|
46
|
+
defaultAddress: string;
|
|
47
|
+
|
|
48
|
+
// Indicates if the deployment is released.
|
|
49
|
+
released: boolean;
|
|
50
|
+
|
|
51
|
+
// The name of the contract.
|
|
52
|
+
contractName: string;
|
|
53
|
+
|
|
54
|
+
// The version of the deployment.
|
|
55
|
+
version: string;
|
|
56
|
+
|
|
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 }>>;
|
|
67
|
+
|
|
68
|
+
// A record of network addresses, where the key is the network identifier and the value is the address.
|
|
69
|
+
networkAddresses: Record<string, string>;
|
|
70
|
+
|
|
71
|
+
// The ABI (Application Binary Interface) of the contract.
|
|
72
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
73
|
+
abi: any[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface SingletonDeploymentV2 {
|
|
77
|
+
released: boolean;
|
|
78
|
+
contractName: string;
|
|
79
|
+
version: string;
|
|
80
|
+
deployments: AtLeastOne<Record<AddressType, { address: string; codeHash: string }>>;
|
|
81
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
82
|
+
abi: any[];
|
|
83
|
+
networkAddresses: Record<string, string | string[]>;
|
|
8
84
|
}
|
|
9
85
|
|
|
10
86
|
export interface DeploymentFilter {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
87
|
+
version?: string;
|
|
88
|
+
released?: boolean;
|
|
89
|
+
network?: string;
|
|
90
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,16 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
DeploymentFilter,
|
|
3
|
+
SingletonDeployment,
|
|
4
|
+
SingletonDeploymentJSON,
|
|
5
|
+
DeploymentFormats,
|
|
6
|
+
SingletonDeploymentV2,
|
|
7
|
+
AddressType,
|
|
8
|
+
} from './types';
|
|
9
|
+
import semverSatisfies from 'semver/functions/satisfies';
|
|
3
10
|
|
|
4
|
-
const DEFAULT_FILTER: DeploymentFilter = { released: true }
|
|
11
|
+
const DEFAULT_FILTER: DeploymentFilter = { released: true };
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
// The older JSON format had a `defaultAddress` field, which became obsolete due to EIP-155 enforcement and non-EVM compatible chains.
|
|
14
|
+
// This led to multiple "default" addresses, sometimes on the same chain ID. To maintain backwards compatibility, we map `defaultAddress`
|
|
15
|
+
// to the address deployed on a chosen default network.
|
|
16
|
+
const DEFAULT_NETWORK_CHAIN_ID = '1';
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Maps a SingletonDeploymentJSON object to a SingletonDeployment object.
|
|
20
|
+
*
|
|
21
|
+
* @param {SingletonDeploymentJSON} deployment - The deployment JSON object to map.
|
|
22
|
+
* @returns {SingletonDeployment} - The mapped deployment object.
|
|
23
|
+
*/
|
|
24
|
+
const mapJsonToDeploymentsFormatV1 = (deployment: SingletonDeploymentJSON): SingletonDeployment => {
|
|
25
|
+
const defaultAddressType = Array.isArray(deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID])
|
|
26
|
+
? deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID][0]
|
|
27
|
+
: deployment.networkAddresses[DEFAULT_NETWORK_CHAIN_ID];
|
|
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;
|
|
30
|
+
const networkAddresses = Object.fromEntries(
|
|
31
|
+
Object.entries(deployment.networkAddresses).map(([chainId, addressTypes]) => [
|
|
32
|
+
chainId,
|
|
33
|
+
Array.isArray(addressTypes)
|
|
34
|
+
? deployment.deployments[addressTypes[0]]!.address
|
|
35
|
+
: deployment.deployments[addressTypes]!.address,
|
|
36
|
+
]),
|
|
37
|
+
);
|
|
13
38
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
39
|
+
return { ...deployment, defaultAddress, networkAddresses };
|
|
40
|
+
};
|
|
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
|
+
|
|
67
|
+
/**
|
|
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
|
|
70
|
+
*
|
|
71
|
+
* @param {DeploymentFilter} [criteria=DEFAULT_FILTER] - The filter criteria to match deployments.
|
|
72
|
+
* @param {SingletonDeploymentJSON[]} deployments - The list of deployment JSON objects to search.
|
|
73
|
+
* @returns {SingletonDeployment | undefined} - The found deployment object or undefined if no match is found.
|
|
74
|
+
*/
|
|
75
|
+
function findDeployment(
|
|
76
|
+
criteria: DeploymentFilter | undefined,
|
|
77
|
+
deployments: SingletonDeploymentJSON[],
|
|
78
|
+
format?: DeploymentFormats.SINGLETON,
|
|
79
|
+
): SingletonDeployment | undefined;
|
|
80
|
+
function findDeployment(
|
|
81
|
+
criteria: DeploymentFilter | undefined,
|
|
82
|
+
deployments: SingletonDeploymentJSON[],
|
|
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 {
|
|
90
|
+
const { version, released, network } = { ...DEFAULT_FILTER, ...criteria };
|
|
91
|
+
|
|
92
|
+
const deploymentJson = deployments.find((deployment) => {
|
|
93
|
+
if (version && !semverSatisfies(deployment.version, version)) return false;
|
|
94
|
+
if (typeof released === 'boolean' && deployment.released !== released) return false;
|
|
95
|
+
if (network && !deployment.networkAddresses[network]) return false;
|
|
96
|
+
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
|
|
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 };
|
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
import SafeL2141 from '../assets/v1.4.1/safe_l2.json';
|
|
2
|
-
import Safe141 from '../assets/v1.4.1/safe.json';
|
|
3
|
-
|
|
4
|
-
import GnosisSafeL2130 from '../assets/v1.3.0/gnosis_safe_l2.json';
|
|
5
|
-
import GnosisSafe130 from '../assets/v1.3.0/gnosis_safe.json';
|
|
6
|
-
import GnosisSafe120 from '../assets/v1.2.0/gnosis_safe.json';
|
|
7
|
-
import GnosisSafe111 from '../assets/v1.1.1/gnosis_safe.json';
|
|
8
|
-
import GnosisSafe100 from '../assets/v1.0.0/gnosis_safe.json';
|
|
9
|
-
import { findDeployment } from '../utils';
|
|
10
|
-
import { _safeDeployments, _safeL2Deployments } from '../safes';
|
|
11
|
-
import { SingletonDeployment } from '../types';
|
|
12
|
-
|
|
13
|
-
const _safeDeploymentsReverse = [..._safeDeployments].reverse();
|
|
14
|
-
|
|
15
|
-
describe('utils.ts', () => {
|
|
16
|
-
describe('findDeployment', () => {
|
|
17
|
-
it('should filter by released by default', () => {
|
|
18
|
-
const testUnreleasedDeployment: SingletonDeployment = {
|
|
19
|
-
defaultAddress: '',
|
|
20
|
-
version: '',
|
|
21
|
-
abi: [],
|
|
22
|
-
networkAddresses: { "1": "0xbeef" },
|
|
23
|
-
contractName: '',
|
|
24
|
-
released: false,
|
|
25
|
-
};
|
|
26
|
-
const testReleasedDeployment: SingletonDeployment = {
|
|
27
|
-
defaultAddress: '',
|
|
28
|
-
version: '',
|
|
29
|
-
abi: [],
|
|
30
|
-
networkAddresses: { "1": "0xbeef" },
|
|
31
|
-
contractName: '',
|
|
32
|
-
released: true, // Default filter value
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const testDeployments = [
|
|
36
|
-
testUnreleasedDeployment,
|
|
37
|
-
testUnreleasedDeployment,
|
|
38
|
-
testReleasedDeployment,
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
expect(findDeployment(undefined, testDeployments)).toBe(
|
|
42
|
-
testReleasedDeployment
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
// should preserve the released flag even if its not explicitly passed
|
|
46
|
-
expect(findDeployment({ network: '1' }, testDeployments)).toBe(
|
|
47
|
-
testReleasedDeployment
|
|
48
|
-
)
|
|
49
|
-
});
|
|
50
|
-
it('should return the correct deployment (filtered by version)', () => {
|
|
51
|
-
// Chronological deployments
|
|
52
|
-
expect(findDeployment({ version: '1.3.0' }, _safeDeployments)).toBe(
|
|
53
|
-
GnosisSafe130
|
|
54
|
-
);
|
|
55
|
-
expect(findDeployment({ version: '1.2.0' }, _safeDeployments)).toBe(
|
|
56
|
-
GnosisSafe120
|
|
57
|
-
);
|
|
58
|
-
expect(findDeployment({ version: '1.1.1' }, _safeDeployments)).toBe(
|
|
59
|
-
GnosisSafe111
|
|
60
|
-
);
|
|
61
|
-
expect(findDeployment({ version: '1.0.0' }, _safeDeployments)).toBe(
|
|
62
|
-
GnosisSafe100
|
|
63
|
-
);
|
|
64
|
-
// Incorrect filter:
|
|
65
|
-
expect(
|
|
66
|
-
findDeployment({ version: '2.0.0' }, _safeDeployments)
|
|
67
|
-
).toBeUndefined();
|
|
68
|
-
|
|
69
|
-
// L2 deployments
|
|
70
|
-
expect(findDeployment({ version: '1.3.0+L2' }, _safeL2Deployments)).toBe(
|
|
71
|
-
GnosisSafeL2130
|
|
72
|
-
);
|
|
73
|
-
// Incorrect filter:
|
|
74
|
-
expect(
|
|
75
|
-
findDeployment({ version: '2.0.0+L2' }, _safeL2Deployments)
|
|
76
|
-
).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
it('should return the correct deployment (filtered by released flag)', () => {
|
|
79
|
-
const testUnreleasedDeployment: SingletonDeployment = {
|
|
80
|
-
defaultAddress: '',
|
|
81
|
-
version: '',
|
|
82
|
-
abi: [],
|
|
83
|
-
networkAddresses: { "1": "0xbeef" },
|
|
84
|
-
contractName: '',
|
|
85
|
-
released: false,
|
|
86
|
-
};
|
|
87
|
-
const testReleasedDeployment: SingletonDeployment = {
|
|
88
|
-
defaultAddress: '',
|
|
89
|
-
version: '',
|
|
90
|
-
abi: [],
|
|
91
|
-
networkAddresses: { "1": "0xbeef" },
|
|
92
|
-
contractName: '',
|
|
93
|
-
released: true, // Default filter value
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const testDeployments = [
|
|
97
|
-
testUnreleasedDeployment,
|
|
98
|
-
testReleasedDeployment,
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// Chronological deployments
|
|
103
|
-
expect(findDeployment({ released: true }, _safeDeployments)).toBe(
|
|
104
|
-
Safe141
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
// Reverse chronological deployments
|
|
108
|
-
expect(findDeployment({ released: true }, _safeDeploymentsReverse)).toBe(
|
|
109
|
-
GnosisSafe100
|
|
110
|
-
);
|
|
111
|
-
// Released flag set to false:
|
|
112
|
-
expect(
|
|
113
|
-
findDeployment({ released: false }, testDeployments)
|
|
114
|
-
).toBe(testUnreleasedDeployment);
|
|
115
|
-
|
|
116
|
-
// L2 deployments
|
|
117
|
-
expect(findDeployment({ released: true }, _safeL2Deployments)).toBe(
|
|
118
|
-
SafeL2141
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should return the correct deployment (filtered by network)', () => {
|
|
123
|
-
// Reverse chronological deployments
|
|
124
|
-
expect(findDeployment({ network: '1' }, _safeDeploymentsReverse)).toBe(
|
|
125
|
-
GnosisSafe100
|
|
126
|
-
);
|
|
127
|
-
expect(
|
|
128
|
-
findDeployment({ network: '73799' }, _safeDeploymentsReverse)
|
|
129
|
-
).toBe(GnosisSafe111);
|
|
130
|
-
expect(
|
|
131
|
-
findDeployment({ network: '11297108109' }, _safeDeploymentsReverse)
|
|
132
|
-
).toBe(GnosisSafe130);
|
|
133
|
-
// Incorrect filter:
|
|
134
|
-
expect(
|
|
135
|
-
findDeployment({ network: '0' }, _safeDeploymentsReverse)
|
|
136
|
-
).toBeUndefined();
|
|
137
|
-
|
|
138
|
-
// L2 deployments
|
|
139
|
-
expect(findDeployment({ network: '100' }, _safeL2Deployments)).toBe(
|
|
140
|
-
SafeL2141
|
|
141
|
-
);
|
|
142
|
-
// Incorrect filter:
|
|
143
|
-
expect(
|
|
144
|
-
findDeployment({ network: '0' }, _safeL2Deployments)
|
|
145
|
-
).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
it('should return the correct deployment (filtered by version and released)', () => {
|
|
148
|
-
// Chronological deployments
|
|
149
|
-
expect(
|
|
150
|
-
findDeployment({ version: '1.3.0', released: true }, _safeDeployments)
|
|
151
|
-
).toBe(GnosisSafe130);
|
|
152
|
-
expect(
|
|
153
|
-
findDeployment({ version: '1.2.0', released: true }, _safeDeployments)
|
|
154
|
-
).toBe(GnosisSafe120);
|
|
155
|
-
expect(
|
|
156
|
-
findDeployment({ version: '1.1.1', released: true }, _safeDeployments)
|
|
157
|
-
).toBe(GnosisSafe111);
|
|
158
|
-
expect(
|
|
159
|
-
findDeployment({ version: '1.0.0', released: true }, _safeDeployments)
|
|
160
|
-
).toBe(GnosisSafe100);
|
|
161
|
-
// Incorrect filter:
|
|
162
|
-
expect(
|
|
163
|
-
findDeployment({ version: '1.0.0', released: false }, _safeDeployments)
|
|
164
|
-
).toBeUndefined();
|
|
165
|
-
|
|
166
|
-
// L2 deployments
|
|
167
|
-
expect(
|
|
168
|
-
findDeployment({ version: '1.3.0', released: true }, _safeL2Deployments)
|
|
169
|
-
).toBe(GnosisSafeL2130);
|
|
170
|
-
expect(
|
|
171
|
-
findDeployment(
|
|
172
|
-
{ version: '1.3.0+L2', released: true },
|
|
173
|
-
_safeL2Deployments
|
|
174
|
-
)
|
|
175
|
-
).toBe(GnosisSafeL2130);
|
|
176
|
-
// Incorrect filter:
|
|
177
|
-
expect(
|
|
178
|
-
findDeployment(
|
|
179
|
-
{ version: '1.3.0+L2', released: false },
|
|
180
|
-
_safeL2Deployments
|
|
181
|
-
)
|
|
182
|
-
).toBeUndefined();
|
|
183
|
-
});
|
|
184
|
-
it('should return the correct deployment (filtered by version and network)', () => {
|
|
185
|
-
// Reverse chronological deployments
|
|
186
|
-
expect(
|
|
187
|
-
findDeployment(
|
|
188
|
-
{ version: '1.0.0', network: '1' },
|
|
189
|
-
_safeDeploymentsReverse
|
|
190
|
-
)
|
|
191
|
-
).toBe(GnosisSafe100);
|
|
192
|
-
expect(
|
|
193
|
-
findDeployment(
|
|
194
|
-
{ version: '1.1.1', network: '1' },
|
|
195
|
-
_safeDeploymentsReverse
|
|
196
|
-
)
|
|
197
|
-
).toBe(GnosisSafe111);
|
|
198
|
-
expect(
|
|
199
|
-
findDeployment(
|
|
200
|
-
{ version: '1.2.0', network: '1' },
|
|
201
|
-
_safeDeploymentsReverse
|
|
202
|
-
)
|
|
203
|
-
).toBe(GnosisSafe120);
|
|
204
|
-
expect(
|
|
205
|
-
findDeployment(
|
|
206
|
-
{ version: '1.3.0', network: '1' },
|
|
207
|
-
_safeDeploymentsReverse
|
|
208
|
-
)
|
|
209
|
-
).toBe(GnosisSafe130);
|
|
210
|
-
// Incorrect filter:
|
|
211
|
-
expect(
|
|
212
|
-
findDeployment(
|
|
213
|
-
{ version: '1.3.0', network: '0' },
|
|
214
|
-
_safeDeploymentsReverse
|
|
215
|
-
)
|
|
216
|
-
).toBeUndefined();
|
|
217
|
-
|
|
218
|
-
// L2 deployments
|
|
219
|
-
expect(
|
|
220
|
-
findDeployment({ version: '1.3.0', network: '100' }, _safeL2Deployments)
|
|
221
|
-
).toBe(GnosisSafeL2130);
|
|
222
|
-
expect(
|
|
223
|
-
findDeployment(
|
|
224
|
-
{ version: '1.3.0+L2', network: '100' },
|
|
225
|
-
_safeL2Deployments
|
|
226
|
-
)
|
|
227
|
-
).toBe(GnosisSafeL2130);
|
|
228
|
-
// Incorrect filter:
|
|
229
|
-
expect(
|
|
230
|
-
findDeployment(
|
|
231
|
-
{ version: '1.3.0+L2', network: '0' },
|
|
232
|
-
_safeL2Deployments
|
|
233
|
-
)
|
|
234
|
-
).toBeUndefined();
|
|
235
|
-
});
|
|
236
|
-
it('should return the correct deployment (filtered by released and network)', () => {
|
|
237
|
-
const testUnreleasedDeployment: SingletonDeployment = {
|
|
238
|
-
defaultAddress: '',
|
|
239
|
-
version: '',
|
|
240
|
-
abi: [],
|
|
241
|
-
networkAddresses: { "1": "0xbeef" },
|
|
242
|
-
contractName: '',
|
|
243
|
-
released: false,
|
|
244
|
-
};
|
|
245
|
-
const testReleasedDeployment: SingletonDeployment = {
|
|
246
|
-
defaultAddress: '',
|
|
247
|
-
version: '',
|
|
248
|
-
abi: [],
|
|
249
|
-
networkAddresses: { "1": "0xbeef" },
|
|
250
|
-
contractName: '',
|
|
251
|
-
released: true, // Default filter value
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const testDeployments = [
|
|
255
|
-
testUnreleasedDeployment,
|
|
256
|
-
testUnreleasedDeployment,
|
|
257
|
-
testReleasedDeployment,
|
|
258
|
-
];
|
|
259
|
-
|
|
260
|
-
// Reverse chronological deployments
|
|
261
|
-
expect(
|
|
262
|
-
findDeployment(
|
|
263
|
-
{ released: true, network: '1' },
|
|
264
|
-
_safeDeploymentsReverse
|
|
265
|
-
)
|
|
266
|
-
).toBe(GnosisSafe100);
|
|
267
|
-
expect(
|
|
268
|
-
findDeployment(
|
|
269
|
-
{ released: true, network: '246' },
|
|
270
|
-
_safeDeploymentsReverse
|
|
271
|
-
)
|
|
272
|
-
).toBe(GnosisSafe111);
|
|
273
|
-
expect(
|
|
274
|
-
findDeployment(
|
|
275
|
-
{ released: true, network: '11297108109' },
|
|
276
|
-
_safeDeploymentsReverse
|
|
277
|
-
)
|
|
278
|
-
).toBe(GnosisSafe130);
|
|
279
|
-
// Incorrect filter:
|
|
280
|
-
expect(
|
|
281
|
-
findDeployment(
|
|
282
|
-
{ released: true, network: '0' },
|
|
283
|
-
_safeDeploymentsReverse
|
|
284
|
-
)
|
|
285
|
-
).toBeUndefined();
|
|
286
|
-
expect(
|
|
287
|
-
findDeployment(
|
|
288
|
-
{ released: false, network: '1' },
|
|
289
|
-
testDeployments
|
|
290
|
-
)
|
|
291
|
-
).toBe(testUnreleasedDeployment);
|
|
292
|
-
|
|
293
|
-
// L2 deployments
|
|
294
|
-
expect(
|
|
295
|
-
findDeployment({ released: true, network: '100' }, _safeL2Deployments)
|
|
296
|
-
).toBe(SafeL2141);
|
|
297
|
-
// Incorrect filter:
|
|
298
|
-
expect(
|
|
299
|
-
findDeployment({ released: true, network: '0' }, _safeL2Deployments)
|
|
300
|
-
).toBeUndefined();
|
|
301
|
-
expect(
|
|
302
|
-
findDeployment({ released: false, network: '100' }, testDeployments)
|
|
303
|
-
).toBeUndefined();
|
|
304
|
-
});
|
|
305
|
-
it('should return the correct deployment (filtered by version, released and network)', () => {
|
|
306
|
-
// Reverse chronological deployments
|
|
307
|
-
expect(
|
|
308
|
-
findDeployment(
|
|
309
|
-
{ version: '1.0.0', released: true, network: '1' },
|
|
310
|
-
_safeDeploymentsReverse
|
|
311
|
-
)
|
|
312
|
-
).toBe(GnosisSafe100);
|
|
313
|
-
expect(
|
|
314
|
-
findDeployment(
|
|
315
|
-
{ version: '1.1.1', released: true, network: '246' },
|
|
316
|
-
_safeDeploymentsReverse
|
|
317
|
-
)
|
|
318
|
-
).toBe(GnosisSafe111);
|
|
319
|
-
expect(
|
|
320
|
-
findDeployment(
|
|
321
|
-
{ version: '1.2.0', released: true, network: '73799' },
|
|
322
|
-
_safeDeploymentsReverse
|
|
323
|
-
)
|
|
324
|
-
).toBe(GnosisSafe120);
|
|
325
|
-
expect(
|
|
326
|
-
findDeployment(
|
|
327
|
-
{ version: '1.3.0', released: true, network: '11297108109' },
|
|
328
|
-
_safeDeploymentsReverse
|
|
329
|
-
)
|
|
330
|
-
).toBe(GnosisSafe130);
|
|
331
|
-
// Incorrect filter:
|
|
332
|
-
expect(
|
|
333
|
-
findDeployment(
|
|
334
|
-
{ version: '1.3.0', released: false, network: '11297108109' },
|
|
335
|
-
_safeDeploymentsReverse
|
|
336
|
-
)
|
|
337
|
-
).toBeUndefined();
|
|
338
|
-
expect(
|
|
339
|
-
findDeployment(
|
|
340
|
-
{ version: '1.3.0', released: true, network: '0' },
|
|
341
|
-
_safeDeploymentsReverse
|
|
342
|
-
)
|
|
343
|
-
).toBeUndefined();
|
|
344
|
-
expect(
|
|
345
|
-
findDeployment(
|
|
346
|
-
{ version: '2.0.0', released: true, network: '11297108109' },
|
|
347
|
-
_safeDeploymentsReverse
|
|
348
|
-
)
|
|
349
|
-
).toBeUndefined();
|
|
350
|
-
|
|
351
|
-
// L2 deployments
|
|
352
|
-
expect(
|
|
353
|
-
findDeployment(
|
|
354
|
-
{ version: '1.3.0', released: true, network: '100' },
|
|
355
|
-
_safeL2Deployments
|
|
356
|
-
)
|
|
357
|
-
).toBe(GnosisSafeL2130);
|
|
358
|
-
expect(
|
|
359
|
-
findDeployment(
|
|
360
|
-
{ version: '1.3.0+L2', released: true, network: '100' },
|
|
361
|
-
_safeL2Deployments
|
|
362
|
-
)
|
|
363
|
-
).toBe(GnosisSafeL2130);
|
|
364
|
-
// Incorrect filter:
|
|
365
|
-
expect(
|
|
366
|
-
findDeployment(
|
|
367
|
-
{ version: '1.3.0+L2', released: false, network: '100' },
|
|
368
|
-
_safeL2Deployments
|
|
369
|
-
)
|
|
370
|
-
).toBeUndefined();
|
|
371
|
-
expect(
|
|
372
|
-
findDeployment(
|
|
373
|
-
{ version: '1.3.0+L2', released: true, network: '0' },
|
|
374
|
-
_safeL2Deployments
|
|
375
|
-
)
|
|
376
|
-
).toBeUndefined();
|
|
377
|
-
expect(
|
|
378
|
-
findDeployment(
|
|
379
|
-
{ version: '2.0.0+L2', released: true, network: '100' },
|
|
380
|
-
_safeL2Deployments
|
|
381
|
-
)
|
|
382
|
-
).toBeUndefined();
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|