@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.
Files changed (112) hide show
  1. package/README.md +150 -31
  2. package/dist/accessors.d.ts +14 -1
  3. package/dist/accessors.js +19 -11
  4. package/dist/assets/v1.0.0/gnosis_safe.json +479 -103
  5. package/dist/assets/v1.0.0/proxy_factory.json +11 -6
  6. package/dist/assets/v1.1.1/default_callback_handler.json +14 -9
  7. package/dist/assets/v1.1.1/gnosis_safe.json +14 -9
  8. package/dist/assets/v1.1.1/multi_send.json +14 -9
  9. package/dist/assets/v1.1.1/proxy_factory.json +14 -9
  10. package/dist/assets/v1.2.0/gnosis_safe.json +14 -9
  11. package/dist/assets/v1.3.0/compatibility_fallback_handler.json +259 -235
  12. package/dist/assets/v1.3.0/create_call.json +259 -235
  13. package/dist/assets/v1.3.0/gnosis_safe.json +259 -235
  14. package/dist/assets/v1.3.0/gnosis_safe_l2.json +259 -235
  15. package/dist/assets/v1.3.0/multi_send.json +259 -235
  16. package/dist/assets/v1.3.0/multi_send_call_only.json +259 -235
  17. package/dist/assets/v1.3.0/proxy_factory.json +259 -235
  18. package/dist/assets/v1.3.0/sign_message_lib.json +260 -236
  19. package/dist/assets/v1.3.0/simulate_tx_accessor.json +259 -235
  20. package/dist/assets/v1.4.1/compatibility_fallback_handler.json +119 -108
  21. package/dist/assets/v1.4.1/create_call.json +119 -108
  22. package/dist/assets/v1.4.1/multi_send.json +119 -108
  23. package/dist/assets/v1.4.1/multi_send_call_only.json +119 -108
  24. package/dist/assets/v1.4.1/safe.json +119 -108
  25. package/dist/assets/v1.4.1/safe_l2.json +119 -108
  26. package/dist/assets/v1.4.1/safe_proxy_factory.json +120 -109
  27. package/dist/assets/v1.4.1/sign_message_lib.json +120 -109
  28. package/dist/assets/v1.4.1/simulate_tx_accessor.json +119 -108
  29. package/dist/deployments.d.ts +12 -0
  30. package/dist/deployments.js +71 -0
  31. package/dist/factories.d.ts +12 -1
  32. package/dist/factories.js +17 -13
  33. package/dist/handler.d.ts +29 -1
  34. package/dist/handler.js +55 -24
  35. package/dist/libs.d.ts +45 -1
  36. package/dist/libs.js +62 -32
  37. package/dist/safes.d.ts +23 -3
  38. package/dist/safes.js +32 -21
  39. package/dist/types.d.ts +37 -2
  40. package/dist/utils.d.ts +12 -2
  41. package/dist/utils.js +61 -9
  42. package/package.json +18 -19
  43. package/src/__tests__/assets/v1/v1.0.0/gnosis_safe.json +796 -0
  44. package/src/__tests__/assets/v1/v1.0.0/proxy_factory.json +111 -0
  45. package/src/__tests__/assets/v1/v1.1.1/create_and_add_modules.json +59 -0
  46. package/src/__tests__/assets/v1/v1.1.1/create_call.json +90 -0
  47. package/src/__tests__/assets/v1/v1.1.1/default_callback_handler.json +212 -0
  48. package/src/__tests__/assets/v1/v1.1.1/gnosis_safe.json +1001 -0
  49. package/src/__tests__/assets/v1/v1.1.1/multi_send.json +45 -0
  50. package/src/__tests__/assets/v1/v1.1.1/proxy_factory.json +191 -0
  51. package/src/__tests__/assets/v1/v1.2.0/gnosis_safe.json +1022 -0
  52. package/src/__tests__/assets/v1/v1.3.0/compatibility_fallback_handler.json +588 -0
  53. package/src/__tests__/assets/v1/v1.3.0/create_call.json +331 -0
  54. package/src/__tests__/assets/v1/v1.3.0/gnosis_safe.json +1296 -0
  55. package/src/__tests__/assets/v1/v1.3.0/gnosis_safe_l2.json +1401 -0
  56. package/src/__tests__/assets/v1/v1.3.0/multi_send.json +283 -0
  57. package/src/__tests__/assets/v1/v1.3.0/multi_send_call_only.json +278 -0
  58. package/src/__tests__/assets/v1/v1.3.0/proxy_factory.json +426 -0
  59. package/src/__tests__/assets/v1/v1.3.0/sign_message_lib.json +310 -0
  60. package/src/__tests__/assets/v1/v1.3.0/simulate_tx_accessor.json +314 -0
  61. package/src/__tests__/assets/v1/v1.4.1/compatibility_fallback_handler.json +447 -0
  62. package/src/__tests__/assets/v1/v1.4.1/create_call.json +192 -0
  63. package/src/__tests__/assets/v1/v1.4.1/multi_send.json +144 -0
  64. package/src/__tests__/assets/v1/v1.4.1/multi_send_call_only.json +139 -0
  65. package/src/__tests__/assets/v1/v1.4.1/safe.json +1123 -0
  66. package/src/__tests__/assets/v1/v1.4.1/safe_l2.json +1228 -0
  67. package/src/__tests__/assets/v1/v1.4.1/safe_proxy_factory.json +263 -0
  68. package/src/__tests__/assets/v1/v1.4.1/sign_message_lib.json +171 -0
  69. package/src/__tests__/assets/v1/v1.4.1/simulate_tx_accessor.json +175 -0
  70. package/src/__tests__/assets.test.ts +101 -38
  71. package/src/__tests__/factories.test.ts +3 -3
  72. package/src/__tests__/handler.test.ts +5 -5
  73. package/src/__tests__/libs.test.ts +9 -9
  74. package/src/__tests__/safes.test.ts +9 -12
  75. package/src/__tests__/utils.test.ts +421 -0
  76. package/src/accessors.ts +21 -12
  77. package/src/assets/v1.0.0/gnosis_safe.json +479 -103
  78. package/src/assets/v1.0.0/proxy_factory.json +11 -6
  79. package/src/assets/v1.1.1/create_and_add_modules.json +19 -10
  80. package/src/assets/v1.1.1/create_call.json +14 -9
  81. package/src/assets/v1.1.1/default_callback_handler.json +14 -9
  82. package/src/assets/v1.1.1/gnosis_safe.json +14 -9
  83. package/src/assets/v1.1.1/multi_send.json +14 -9
  84. package/src/assets/v1.1.1/proxy_factory.json +14 -9
  85. package/src/assets/v1.2.0/gnosis_safe.json +14 -9
  86. package/src/assets/v1.3.0/compatibility_fallback_handler.json +259 -235
  87. package/src/assets/v1.3.0/create_call.json +259 -235
  88. package/src/assets/v1.3.0/gnosis_safe.json +259 -235
  89. package/src/assets/v1.3.0/gnosis_safe_l2.json +259 -235
  90. package/src/assets/v1.3.0/multi_send.json +259 -235
  91. package/src/assets/v1.3.0/multi_send_call_only.json +259 -235
  92. package/src/assets/v1.3.0/proxy_factory.json +259 -235
  93. package/src/assets/v1.3.0/sign_message_lib.json +260 -236
  94. package/src/assets/v1.3.0/simulate_tx_accessor.json +259 -235
  95. package/src/assets/v1.4.1/compatibility_fallback_handler.json +119 -108
  96. package/src/assets/v1.4.1/create_call.json +119 -108
  97. package/src/assets/v1.4.1/multi_send.json +119 -108
  98. package/src/assets/v1.4.1/multi_send_call_only.json +119 -108
  99. package/src/assets/v1.4.1/safe.json +119 -108
  100. package/src/assets/v1.4.1/safe_l2.json +119 -108
  101. package/src/assets/v1.4.1/safe_proxy_factory.json +120 -109
  102. package/src/assets/v1.4.1/sign_message_lib.json +120 -109
  103. package/src/assets/v1.4.1/simulate_tx_accessor.json +119 -108
  104. package/src/deployments.ts +90 -0
  105. package/src/factories.ts +19 -14
  106. package/src/handler.ts +62 -26
  107. package/src/index.ts +6 -6
  108. package/src/libs.ts +69 -35
  109. package/src/safes.ts +34 -22
  110. package/src/types.ts +86 -10
  111. package/src/utils.ts +105 -12
  112. package/src/__tests__/utilts.test.ts +0 -385
@@ -1,8 +1,11 @@
1
- import fs from "fs";
2
- import path from "path";
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { SingletonDeploymentJSON, AddressType } from '../types';
4
+
5
+ const KNOWN_ADDRESS_TYPES: AddressType[] = ['canonical', 'eip155', 'zksync'];
3
6
 
4
7
  function assetPath(...paths: string[]) {
5
- return path.join(__dirname, "..", "assets", ...paths);
8
+ return path.join(__dirname, '..', 'assets', ...paths);
6
9
  }
7
10
 
8
11
  function versions() {
@@ -16,67 +19,93 @@ function versionFiles(version: string) {
16
19
  }
17
20
 
18
21
  async function readAsset(version: string, file: string) {
19
- return await fs.promises.readFile(assetPath(version, file), "utf-8");
22
+ return await fs.promises.readFile(assetPath(version, file), 'utf-8');
20
23
  }
21
24
 
22
- async function readAssetJSON(version: string, file: string) {
25
+ async function readAssetJSON(version: string, file: string): Promise<SingletonDeploymentJSON | undefined> {
23
26
  return JSON.parse(await readAsset(version, file));
24
27
  }
25
28
 
26
- describe("assets/", () => {
29
+ describe('assets/', () => {
27
30
  for (const version of versions()) {
28
31
  describe(version, () => {
29
32
  for (const file of versionFiles(version)) {
30
33
  describe(file, () => {
31
- describe("networkAddresses", () => {
32
- it("should be sorted by chain ID", async () => {
34
+ describe('networkAddresses', () => {
35
+ it('should be sorted by chain ID', async () => {
33
36
  // We manually parse the JSON here, since ECMA `JSON.parse` will
34
37
  // always order fields with numeric keys.
35
38
  const json = await readAsset(version, file);
36
- const networkAddresses = json
37
- .replace(
38
- /^[\s\S]*"networkAddresses" *: *\{([^}]*)\}[\s\S]*$/,
39
- "$1"
40
- )
41
- .trim();
42
- const keys = networkAddresses.split(",").map((pair) => {
43
- const [key] = pair.split(":");
44
- return parseInt(key.trim().replace(/^"(.*)"$/, "$1"));
39
+ const networkAddresses = json.replace(/^[\s\S]*"networkAddresses" *: *\{([^}]*)\}[\s\S]*$/, '$1').trim();
40
+ const keys = networkAddresses.split(',').map((pair) => {
41
+ const [key] = pair.split(':');
42
+ return parseInt(key.trim().replace(/^"(.*)"$/, '$1'));
45
43
  });
46
44
  const sorted = [...keys].sort((a, b) => a - b);
47
45
  expect(keys).toEqual(sorted);
48
46
  });
49
47
 
50
- it("should only contain canonical addresses", async () => {
51
- const { networkAddresses } = await readAssetJSON(version, file);
52
- const canonicalAddresses = [
53
- // Ethereum Mainnet address
54
- networkAddresses[1],
55
- // For v1.3.0, support alternate address with different
56
- // `CREATE2` deployer, notably used for Optimism Mainnet
57
- ...(version === "v1.3.0" ? [networkAddresses[10]] : []),
58
- // zkSync Mainnet address
59
- networkAddresses[324],
60
- ].filter((address) => address !== undefined);
61
-
62
- for (const [network, address] of Object.entries(
63
- networkAddresses
64
- )) {
65
- expect(
66
- canonicalAddresses.map((address) => [network, address])
67
- ).toContainEqual([network, address]);
48
+ it('networks should only contain known address types', async () => {
49
+ const deploymentJson = await readAssetJSON(version, file);
50
+ if (!deploymentJson) {
51
+ throw new Error(`Failed to read asset ${version}/${file}`);
52
+ }
53
+
54
+ const { networkAddresses, deployments } = deploymentJson;
55
+ const canonicalAddressTypes = Object.keys(deployments);
56
+
57
+ for (const addressType of Object.values(networkAddresses)) {
58
+ if (Array.isArray(addressType)) {
59
+ for (const type of addressType) {
60
+ expect(canonicalAddressTypes).toContain(type);
61
+ }
62
+ } else {
63
+ expect(canonicalAddressTypes).toContain(addressType);
64
+ }
68
65
  }
69
66
  });
70
67
  });
68
+
69
+ it('should only contain known address types', async () => {
70
+ const deploymentJson = await readAssetJSON(version, file);
71
+ if (!deploymentJson) {
72
+ throw new Error(`Failed to read asset ${version}/${file}`);
73
+ }
74
+ const { deployments } = deploymentJson;
75
+
76
+ for (const addressType of Object.keys(deployments)) {
77
+ expect(KNOWN_ADDRESS_TYPES).toContain(addressType);
78
+ }
79
+ });
80
+
81
+ it('no network can contain zksync address together with other address types', async () => {
82
+ const deploymentJson = await readAssetJSON(version, file);
83
+ if (!deploymentJson) {
84
+ throw new Error(`Failed to read asset ${version}/${file}`);
85
+ }
86
+ const { networkAddresses } = deploymentJson;
87
+
88
+ for (const network of Object.keys(networkAddresses)) {
89
+ const addressTypes = networkAddresses[network];
90
+
91
+ if (Array.isArray(addressTypes)) {
92
+ expect(addressTypes).not.toContain('zksync');
93
+ }
94
+ }
95
+ });
71
96
  });
72
97
  }
73
98
 
74
- describe("networkAddresses", () => {
75
- it("should contain the same networks in all files", async () => {
99
+ describe('networkAddresses', () => {
100
+ it('should contain the same networks in all files', async () => {
76
101
  const files = versionFiles(version);
77
102
  const networkCounts: Record<string, number> = {};
78
103
  for (const file of files) {
79
- const { networkAddresses } = await readAssetJSON(version, file);
104
+ const deploymentJson = await readAssetJSON(version, file);
105
+ if (!deploymentJson) {
106
+ throw new Error(`Failed to read asset ${version}/${file}`);
107
+ }
108
+ const { networkAddresses } = deploymentJson;
80
109
  for (const network of Object.keys(networkAddresses)) {
81
110
  networkCounts[network] = (networkCounts[network] ?? 0) + 1;
82
111
  }
@@ -85,6 +114,40 @@ describe("assets/", () => {
85
114
  expect([network, count]).toEqual([network, files.length]);
86
115
  }
87
116
  });
117
+
118
+ it('the address types for a network should be the same in all files', async () => {
119
+ const files = versionFiles(version);
120
+ const networkAddressMap: Record<string, string | string[]> = {};
121
+
122
+ for (const file of files) {
123
+ const deploymentJson = await readAssetJSON(version, file);
124
+ if (!deploymentJson) {
125
+ throw new Error(`Failed to read asset ${version}/${file}`);
126
+ }
127
+ const { networkAddresses } = deploymentJson;
128
+
129
+ for (const [network, addressTypes] of Object.entries(networkAddresses)) {
130
+ if (!networkAddressMap[network]) {
131
+ networkAddressMap[network] = addressTypes;
132
+ } else {
133
+ // We use try/catch here to make the error message more readable.
134
+ // Without it the error message looks like:
135
+ // Expected: "canonical"
136
+ // Actual: ["canonical", "eip155"]
137
+ try {
138
+ expect(addressTypes).toEqual(networkAddressMap[network]);
139
+ } catch (e) {
140
+ console.log(`
141
+ Discrepancy in network ${network}
142
+ Expected: ${networkAddressMap[network]}
143
+ Actual: ${addressTypes}
144
+ `);
145
+ throw e;
146
+ }
147
+ }
148
+ }
149
+ }
150
+ });
88
151
  });
89
152
  });
90
153
  }
@@ -1,12 +1,12 @@
1
- import ProxyFactory130 from '../assets/v1.3.0/proxy_factory.json';
2
- import ProxyFactory141 from '../assets/v1.4.1/safe_proxy_factory.json';
1
+ import ProxyFactory130 from './assets/v1/v1.3.0/proxy_factory.json';
2
+ import ProxyFactory141 from './assets/v1/v1.4.1/safe_proxy_factory.json';
3
3
  import { getProxyFactoryDeployment } from '../factories';
4
4
 
5
5
  describe('factories.ts', () => {
6
6
  describe('getProxyFactoryDeployment', () => {
7
7
  it('should find the latest deployment first', () => {
8
8
  const result = getProxyFactoryDeployment();
9
- expect(result).toBe(ProxyFactory141);
9
+ expect(result).toMatchObject(ProxyFactory141);
10
10
  expect(result).not.toBe(ProxyFactory130);
11
11
  });
12
12
  });
@@ -1,5 +1,5 @@
1
- import DefaultCallbackHandler130 from '../assets/v1.1.1/default_callback_handler.json';
2
- import CompatibilityFallbackHandler141 from '../assets/v1.4.1/compatibility_fallback_handler.json';
1
+ import DefaultCallbackHandler130 from './assets/v1/v1.1.1/default_callback_handler.json';
2
+ import CompatibilityFallbackHandler141 from './assets/v1/v1.4.1/compatibility_fallback_handler.json';
3
3
  import {
4
4
  getDefaultCallbackHandlerDeployment,
5
5
  getCompatibilityFallbackHandlerDeployment,
@@ -10,21 +10,21 @@ describe('handler.ts', () => {
10
10
  describe('getDefaultCallbackHandlerDeployment', () => {
11
11
  it('should find the preferred deployment first', () => {
12
12
  const result = getDefaultCallbackHandlerDeployment();
13
- expect(result).toBe(DefaultCallbackHandler130);
13
+ expect(result).toMatchObject(DefaultCallbackHandler130);
14
14
  });
15
15
  });
16
16
 
17
17
  describe('getCompatibilityFallbackHandlerDeployment', () => {
18
18
  it('should find the preferred deployment first', () => {
19
19
  const result = getCompatibilityFallbackHandlerDeployment();
20
- expect(result).toBe(CompatibilityFallbackHandler141);
20
+ expect(result).toMatchObject(CompatibilityFallbackHandler141);
21
21
  });
22
22
  });
23
23
 
24
24
  describe('getFallbackHandlerDeployment', () => {
25
25
  it('should find the preferred deployment first', () => {
26
26
  const result = getFallbackHandlerDeployment();
27
- expect(result).toBe(CompatibilityFallbackHandler141);
27
+ expect(result).toMatchObject(CompatibilityFallbackHandler141);
28
28
  expect(result).not.toBe(DefaultCallbackHandler130);
29
29
  });
30
30
  });
@@ -1,8 +1,8 @@
1
- import CreateCall141 from '../assets/v1.4.1/create_call.json';
2
- import MultiSend111 from '../assets/v1.1.1/multi_send.json';
3
- import MultiSend141 from '../assets/v1.4.1/multi_send.json';
4
- import MultiSendCallOnly141 from '../assets/v1.4.1/multi_send_call_only.json';
5
- import SignMessageLib141 from '../assets/v1.4.1/sign_message_lib.json';
1
+ import CreateCall141 from './assets/v1/v1.4.1/create_call.json';
2
+ import MultiSend111 from './assets/v1/v1.1.1/multi_send.json';
3
+ import MultiSend141 from './assets/v1/v1.4.1/multi_send.json';
4
+ import MultiSendCallOnly141 from './assets/v1/v1.4.1/multi_send_call_only.json';
5
+ import SignMessageLib141 from './assets/v1/v1.4.1/sign_message_lib.json';
6
6
  import {
7
7
  getMultiSendDeployment,
8
8
  getMultiSendCallOnlyDeployment,
@@ -14,26 +14,26 @@ describe('libs.ts', () => {
14
14
  describe('getMultiSendDeployment', () => {
15
15
  it('should find the preferred deployment first', () => {
16
16
  const result = getMultiSendDeployment();
17
- expect(result).toBe(MultiSend141);
17
+ expect(result).toMatchObject(MultiSend141);
18
18
  expect(result).not.toBe(MultiSend111);
19
19
  });
20
20
  });
21
21
  describe('getMultiSendCallOnlyDeployment', () => {
22
22
  it('should find the preferred deployment first', () => {
23
23
  const result = getMultiSendCallOnlyDeployment();
24
- expect(result).toBe(MultiSendCallOnly141);
24
+ expect(result).toMatchObject(MultiSendCallOnly141);
25
25
  });
26
26
  });
27
27
  describe('getCreateCallDeployment', () => {
28
28
  it('should find the preferred deployment first', () => {
29
29
  const result = getCreateCallDeployment();
30
- expect(result).toBe(CreateCall141);
30
+ expect(result).toMatchObject(CreateCall141);
31
31
  });
32
32
  });
33
33
  describe('getSignMessageLibDeployment', () => {
34
34
  it('should find the preferred deployment first', () => {
35
35
  const result = getSignMessageLibDeployment();
36
- expect(result).toBe(SignMessageLib141);
36
+ expect(result).toMatchObject(SignMessageLib141);
37
37
  });
38
38
  });
39
39
  });
@@ -1,19 +1,16 @@
1
- import SafeL2141 from '../assets/v1.4.1/safe_l2.json';
2
- import Safe141 from '../assets/v1.4.1/safe.json';
3
- import GnosisSafe130 from '../assets/v1.3.0/gnosis_safe.json';
4
- import GnosisSafe120 from '../assets/v1.2.0/gnosis_safe.json';
5
- import GnosisSafe111 from '../assets/v1.1.1/gnosis_safe.json';
6
- import GnosisSafe100 from '../assets/v1.0.0/gnosis_safe.json';
7
- import {
8
- getSafeSingletonDeployment,
9
- getSafeL2SingletonDeployment,
10
- } from '../safes';
1
+ import SafeL2141 from './assets/v1/v1.4.1/safe_l2.json';
2
+ import Safe141 from './assets/v1/v1.4.1/safe.json';
3
+ import GnosisSafe130 from './assets/v1/v1.3.0/gnosis_safe.json';
4
+ import GnosisSafe120 from './assets/v1/v1.2.0/gnosis_safe.json';
5
+ import GnosisSafe111 from './assets/v1/v1.1.1/gnosis_safe.json';
6
+ import GnosisSafe100 from './assets/v1/v1.0.0/gnosis_safe.json';
7
+ import { getSafeSingletonDeployment, getSafeL2SingletonDeployment } from '../safes';
11
8
 
12
9
  describe('safes.ts', () => {
13
10
  describe('getSafeSingletonDeployment', () => {
14
11
  it('should find the latest deployment first', () => {
15
12
  const result = getSafeSingletonDeployment();
16
- expect(result).toBe(Safe141);
13
+ expect(result).toMatchObject(Safe141);
17
14
  [GnosisSafe130, GnosisSafe120, GnosisSafe111, GnosisSafe100].forEach((version) => {
18
15
  expect(result).not.toBe(version);
19
16
  });
@@ -22,7 +19,7 @@ describe('safes.ts', () => {
22
19
  describe('getSafeL2SingletonDeployment', () => {
23
20
  it('should find the latest deployment first', () => {
24
21
  const result = getSafeL2SingletonDeployment();
25
- expect(result).toBe(SafeL2141);
22
+ expect(result).toMatchObject(SafeL2141);
26
23
  });
27
24
  });
28
25
  });