@gearbox-protocol/sdk 14.12.0-next.51 → 14.12.0-next.52

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.
@@ -40,9 +40,32 @@ async function writeAndWait(anvil, params) {
40
40
  });
41
41
  return hash;
42
42
  }
43
+ async function useSecuritizeAdmin(props) {
44
+ const { anvil, adminPrivateKey, admin, logger } = props;
45
+ if (adminPrivateKey) {
46
+ return {
47
+ account: (0, import_accounts.privateKeyToAccount)(adminPrivateKey),
48
+ release: async () => {
49
+ }
50
+ };
51
+ }
52
+ if (!admin) {
53
+ throw new Error(
54
+ "securitize: either adminPrivateKey or admin address is required"
55
+ );
56
+ }
57
+ await anvil.impersonateAccount({ address: admin });
58
+ await anvil.setBalance({ address: admin, value: (0, import_viem.parseEther)("100") });
59
+ logger?.debug(`securitize: impersonating registry admin ${admin}`);
60
+ return {
61
+ account: admin,
62
+ release: async () => {
63
+ await anvil.stopImpersonatingAccount({ address: admin });
64
+ }
65
+ };
66
+ }
43
67
  async function registerSecuritizeInvestor(props) {
44
- const { investor, anvil, token, adminPrivateKey, logger } = props;
45
- const account = (0, import_accounts.privateKeyToAccount)(adminPrivateKey);
68
+ const { investor, anvil, token, logger } = props;
46
69
  const registryServiceId = await anvil.readContract({
47
70
  address: token,
48
71
  abi: import_iDSToken.iDSTokenAbi,
@@ -89,53 +112,58 @@ async function registerSecuritizeInvestor(props) {
89
112
  functionName: "isInvestor",
90
113
  args: [investorId]
91
114
  });
92
- if (!investorExists) {
93
- await writeAndWait(anvil, {
94
- account,
95
- chain: anvil.chain,
96
- address: registryService,
97
- abi: import_iDSRegistryService.iDSRegistryServiceAbi,
98
- functionName: "registerInvestor",
99
- args: [investorId, investorId]
100
- });
101
- logger?.debug(`Registered investor "${investorId}"`);
102
- }
103
- await writeAndWait(anvil, {
104
- account,
105
- chain: anvil.chain,
106
- address: registryService,
107
- abi: import_iDSRegistryService.iDSRegistryServiceAbi,
108
- functionName: "addWallet",
109
- args: [investor, investorId]
110
- });
111
- logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
115
+ const { account, release } = await useSecuritizeAdmin(props);
112
116
  try {
117
+ if (!investorExists) {
118
+ await writeAndWait(anvil, {
119
+ account,
120
+ chain: anvil.chain,
121
+ address: registryService,
122
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
123
+ functionName: "registerInvestor",
124
+ args: [investorId, investorId]
125
+ });
126
+ logger?.debug(`Registered investor "${investorId}"`);
127
+ }
113
128
  await writeAndWait(anvil, {
114
129
  account,
115
130
  chain: anvil.chain,
116
131
  address: registryService,
117
132
  abi: import_iDSRegistryService.iDSRegistryServiceAbi,
118
- functionName: "setCountry",
119
- args: [investorId, "US"]
120
- });
121
- logger?.debug(`Set country for investor "${investorId}" to "US"`);
122
- await writeAndWait(anvil, {
123
- account,
124
- chain: anvil.chain,
125
- address: registryService,
126
- abi: import_iDSRegistryService.iDSRegistryServiceAbi,
127
- functionName: "setAttribute",
128
- args: [
129
- investorId,
130
- ACCREDITED,
131
- BigInt(APPROVED),
132
- import_sdk.MAX_UINT256,
133
- "fake proof"
134
- ]
133
+ functionName: "addWallet",
134
+ args: [investor, investorId]
135
135
  });
136
- logger?.debug(`Set attributes for investor "${investorId}"`);
137
- } catch (e) {
138
- logger?.error(e);
136
+ logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
137
+ try {
138
+ await writeAndWait(anvil, {
139
+ account,
140
+ chain: anvil.chain,
141
+ address: registryService,
142
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
143
+ functionName: "setCountry",
144
+ args: [investorId, "US"]
145
+ });
146
+ logger?.debug(`Set country for investor "${investorId}" to "US"`);
147
+ await writeAndWait(anvil, {
148
+ account,
149
+ chain: anvil.chain,
150
+ address: registryService,
151
+ abi: import_iDSRegistryService.iDSRegistryServiceAbi,
152
+ functionName: "setAttribute",
153
+ args: [
154
+ investorId,
155
+ ACCREDITED,
156
+ BigInt(APPROVED),
157
+ import_sdk.MAX_UINT256,
158
+ "fake proof"
159
+ ]
160
+ });
161
+ logger?.debug(`Set attributes for investor "${investorId}"`);
162
+ } catch (e) {
163
+ logger?.error(e);
164
+ }
165
+ } finally {
166
+ await release();
139
167
  }
140
168
  } else {
141
169
  logger?.debug(`Investor ${investor} is already a registered wallet`);
@@ -284,20 +312,29 @@ function collectMidasGateways(sdk) {
284
312
  return gateways.asArray();
285
313
  }
286
314
  async function registerRWAInvestor(props) {
287
- const { anvil, sdk, investor, adminPrivateKey, midasAdmin, logger } = props;
315
+ const {
316
+ anvil,
317
+ sdk,
318
+ investor,
319
+ adminPrivateKey,
320
+ securitizeAdmin,
321
+ midasAdmin,
322
+ logger
323
+ } = props;
288
324
  const securitizeTokens = [];
289
325
  const midasGateways = [];
290
326
  const failed = [];
291
327
  const dsTokens = new import_sdk.AddressSet(
292
328
  sdk.rwa.factories.flatMap((factory) => factory.getTokens())
293
329
  );
294
- if (adminPrivateKey) {
330
+ if (adminPrivateKey || securitizeAdmin) {
295
331
  for (const token of dsTokens) {
296
332
  try {
297
333
  await registerSecuritizeInvestor({
298
334
  anvil,
299
335
  investor,
300
336
  adminPrivateKey,
337
+ admin: securitizeAdmin,
301
338
  token,
302
339
  logger
303
340
  });
@@ -310,7 +347,7 @@ async function registerRWAInvestor(props) {
310
347
  }
311
348
  } else if (dsTokens.size > 0) {
312
349
  logger?.warn(
313
- `securitize: no admin private key, skipping ${dsTokens.size} DSToken(s)`
350
+ `securitize: no registry admin, skipping ${dsTokens.size} DSToken(s)`
314
351
  );
315
352
  }
316
353
  const gateways = collectMidasGateways(sdk);
@@ -22,9 +22,32 @@ async function writeAndWait(anvil, params) {
22
22
  });
23
23
  return hash;
24
24
  }
25
+ async function useSecuritizeAdmin(props) {
26
+ const { anvil, adminPrivateKey, admin, logger } = props;
27
+ if (adminPrivateKey) {
28
+ return {
29
+ account: privateKeyToAccount(adminPrivateKey),
30
+ release: async () => {
31
+ }
32
+ };
33
+ }
34
+ if (!admin) {
35
+ throw new Error(
36
+ "securitize: either adminPrivateKey or admin address is required"
37
+ );
38
+ }
39
+ await anvil.impersonateAccount({ address: admin });
40
+ await anvil.setBalance({ address: admin, value: parseEther("100") });
41
+ logger?.debug(`securitize: impersonating registry admin ${admin}`);
42
+ return {
43
+ account: admin,
44
+ release: async () => {
45
+ await anvil.stopImpersonatingAccount({ address: admin });
46
+ }
47
+ };
48
+ }
25
49
  async function registerSecuritizeInvestor(props) {
26
- const { investor, anvil, token, adminPrivateKey, logger } = props;
27
- const account = privateKeyToAccount(adminPrivateKey);
50
+ const { investor, anvil, token, logger } = props;
28
51
  const registryServiceId = await anvil.readContract({
29
52
  address: token,
30
53
  abi: iDSTokenAbi,
@@ -71,53 +94,58 @@ async function registerSecuritizeInvestor(props) {
71
94
  functionName: "isInvestor",
72
95
  args: [investorId]
73
96
  });
74
- if (!investorExists) {
75
- await writeAndWait(anvil, {
76
- account,
77
- chain: anvil.chain,
78
- address: registryService,
79
- abi: iDSRegistryServiceAbi,
80
- functionName: "registerInvestor",
81
- args: [investorId, investorId]
82
- });
83
- logger?.debug(`Registered investor "${investorId}"`);
84
- }
85
- await writeAndWait(anvil, {
86
- account,
87
- chain: anvil.chain,
88
- address: registryService,
89
- abi: iDSRegistryServiceAbi,
90
- functionName: "addWallet",
91
- args: [investor, investorId]
92
- });
93
- logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
97
+ const { account, release } = await useSecuritizeAdmin(props);
94
98
  try {
99
+ if (!investorExists) {
100
+ await writeAndWait(anvil, {
101
+ account,
102
+ chain: anvil.chain,
103
+ address: registryService,
104
+ abi: iDSRegistryServiceAbi,
105
+ functionName: "registerInvestor",
106
+ args: [investorId, investorId]
107
+ });
108
+ logger?.debug(`Registered investor "${investorId}"`);
109
+ }
95
110
  await writeAndWait(anvil, {
96
111
  account,
97
112
  chain: anvil.chain,
98
113
  address: registryService,
99
114
  abi: iDSRegistryServiceAbi,
100
- functionName: "setCountry",
101
- args: [investorId, "US"]
102
- });
103
- logger?.debug(`Set country for investor "${investorId}" to "US"`);
104
- await writeAndWait(anvil, {
105
- account,
106
- chain: anvil.chain,
107
- address: registryService,
108
- abi: iDSRegistryServiceAbi,
109
- functionName: "setAttribute",
110
- args: [
111
- investorId,
112
- ACCREDITED,
113
- BigInt(APPROVED),
114
- MAX_UINT256,
115
- "fake proof"
116
- ]
115
+ functionName: "addWallet",
116
+ args: [investor, investorId]
117
117
  });
118
- logger?.debug(`Set attributes for investor "${investorId}"`);
119
- } catch (e) {
120
- logger?.error(e);
118
+ logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
119
+ try {
120
+ await writeAndWait(anvil, {
121
+ account,
122
+ chain: anvil.chain,
123
+ address: registryService,
124
+ abi: iDSRegistryServiceAbi,
125
+ functionName: "setCountry",
126
+ args: [investorId, "US"]
127
+ });
128
+ logger?.debug(`Set country for investor "${investorId}" to "US"`);
129
+ await writeAndWait(anvil, {
130
+ account,
131
+ chain: anvil.chain,
132
+ address: registryService,
133
+ abi: iDSRegistryServiceAbi,
134
+ functionName: "setAttribute",
135
+ args: [
136
+ investorId,
137
+ ACCREDITED,
138
+ BigInt(APPROVED),
139
+ MAX_UINT256,
140
+ "fake proof"
141
+ ]
142
+ });
143
+ logger?.debug(`Set attributes for investor "${investorId}"`);
144
+ } catch (e) {
145
+ logger?.error(e);
146
+ }
147
+ } finally {
148
+ await release();
121
149
  }
122
150
  } else {
123
151
  logger?.debug(`Investor ${investor} is already a registered wallet`);
@@ -266,20 +294,29 @@ function collectMidasGateways(sdk) {
266
294
  return gateways.asArray();
267
295
  }
268
296
  async function registerRWAInvestor(props) {
269
- const { anvil, sdk, investor, adminPrivateKey, midasAdmin, logger } = props;
297
+ const {
298
+ anvil,
299
+ sdk,
300
+ investor,
301
+ adminPrivateKey,
302
+ securitizeAdmin,
303
+ midasAdmin,
304
+ logger
305
+ } = props;
270
306
  const securitizeTokens = [];
271
307
  const midasGateways = [];
272
308
  const failed = [];
273
309
  const dsTokens = new AddressSet(
274
310
  sdk.rwa.factories.flatMap((factory) => factory.getTokens())
275
311
  );
276
- if (adminPrivateKey) {
312
+ if (adminPrivateKey || securitizeAdmin) {
277
313
  for (const token of dsTokens) {
278
314
  try {
279
315
  await registerSecuritizeInvestor({
280
316
  anvil,
281
317
  investor,
282
318
  adminPrivateKey,
319
+ admin: securitizeAdmin,
283
320
  token,
284
321
  logger
285
322
  });
@@ -292,7 +329,7 @@ async function registerRWAInvestor(props) {
292
329
  }
293
330
  } else if (dsTokens.size > 0) {
294
331
  logger?.warn(
295
- `securitize: no admin private key, skipping ${dsTokens.size} DSToken(s)`
332
+ `securitize: no registry admin, skipping ${dsTokens.size} DSToken(s)`
296
333
  );
297
334
  }
298
335
  const gateways = collectMidasGateways(sdk);
@@ -11,7 +11,14 @@ export interface RegisterSecuritizeInvestorProps {
11
11
  * Wallet to register in the Securitize DS registry
12
12
  */
13
13
  investor: Address;
14
- adminPrivateKey: Hex;
14
+ /**
15
+ * Private key of the DS registry admin, signs the registry writes
16
+ */
17
+ adminPrivateKey?: Hex;
18
+ /**
19
+ * DS registry admin, impersonated on the fork when no private key is given
20
+ */
21
+ admin?: Address;
15
22
  /**
16
23
  * DSToken address
17
24
  */
@@ -87,9 +94,14 @@ export interface RegisterRWAInvestorProps {
87
94
  */
88
95
  investor: Address;
89
96
  /**
90
- * Securitize registry admin, DSTokens are skipped when omitted
97
+ * Private key of the Securitize registry admin, DSTokens are skipped when
98
+ * neither this nor `securitizeAdmin` is set
91
99
  */
92
100
  adminPrivateKey?: Hex;
101
+ /**
102
+ * Securitize registry admin, impersonated on the fork
103
+ */
104
+ securitizeAdmin?: Address;
93
105
  /**
94
106
  * Midas access control admin, Midas gateways are skipped when omitted
95
107
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.12.0-next.51",
3
+ "version": "14.12.0-next.52",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {