damm-sdk 1.4.36 → 1.4.37

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 (39) hide show
  1. package/dist/index.cjs +32968 -40246
  2. package/dist/index.cjs.map +122 -200
  3. package/dist/index.js +40234 -39832
  4. package/dist/index.js.map +82 -96
  5. package/dist/integrations/index.d.ts +1 -0
  6. package/dist/integrations/index.d.ts.map +1 -1
  7. package/dist/integrations/lagoonV1/delay.proxy.admin.d.ts +208 -0
  8. package/dist/integrations/lagoonV1/delay.proxy.admin.d.ts.map +1 -0
  9. package/dist/integrations/lagoonV1/index.d.ts +1 -0
  10. package/dist/integrations/lagoonV1/index.d.ts.map +1 -1
  11. package/dist/integrations/lagoonV1/lagoon.v1.d.ts +17 -0
  12. package/dist/integrations/lagoonV1/lagoon.v1.d.ts.map +1 -1
  13. package/dist/integrations/lagoonV2/addresses.d.ts +19 -0
  14. package/dist/integrations/lagoonV2/addresses.d.ts.map +1 -0
  15. package/dist/integrations/lagoonV2/factory.abi.d.ts +183 -0
  16. package/dist/integrations/lagoonV2/factory.abi.d.ts.map +1 -0
  17. package/dist/integrations/lagoonV2/index.d.ts +7 -0
  18. package/dist/integrations/lagoonV2/index.d.ts.map +1 -0
  19. package/dist/integrations/lagoonV2/lagoon.v2.d.ts +132 -0
  20. package/dist/integrations/lagoonV2/lagoon.v2.d.ts.map +1 -0
  21. package/dist/integrations/lagoonV2/lagoon.v2.permissions.d.ts +268 -0
  22. package/dist/integrations/lagoonV2/lagoon.v2.permissions.d.ts.map +1 -0
  23. package/dist/integrations/lagoonV2/lagoon.v2.setters.d.ts +293 -0
  24. package/dist/integrations/lagoonV2/lagoon.v2.setters.d.ts.map +1 -0
  25. package/dist/integrations/lagoonV2/vault.abi.d.ts +349 -0
  26. package/dist/integrations/lagoonV2/vault.abi.d.ts.map +1 -0
  27. package/package.json +1 -1
  28. package/src/integrations/index.ts +1 -0
  29. package/src/integrations/lagoonV1/delay.proxy.admin.ts +358 -0
  30. package/src/integrations/lagoonV1/index.ts +1 -0
  31. package/src/integrations/lagoonV1/lagoon.v1.ts +109 -36
  32. package/src/integrations/lagoonV2/addresses.ts +35 -0
  33. package/src/integrations/lagoonV2/factory.abi.ts +110 -0
  34. package/src/integrations/lagoonV2/index.ts +6 -0
  35. package/src/integrations/lagoonV2/lagoon.v2.permissions.ts +578 -0
  36. package/src/integrations/lagoonV2/lagoon.v2.setters.ts +521 -0
  37. package/src/integrations/lagoonV2/lagoon.v2.ts +345 -0
  38. package/src/integrations/lagoonV2/vault.abi.ts +479 -0
  39. package/src/lib/contractsRegistry.json +4 -2
@@ -0,0 +1,345 @@
1
+ import { encodeAbiParameters, encodeFunctionData, getAddress, keccak256, encodePacked } from "viem";
2
+ import type { Address, Hex } from "viem";
3
+ import { createCall, ZERO_ADDRESS, type Call, type HexString, type Unwrapable } from "../..";
4
+ import lagoonV2FactoryAbi from "./factory.abi.ts";
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Types
8
+ // ---------------------------------------------------------------------------
9
+
10
+ /**
11
+ * AccessMode enum for Lagoon v0.6 vault.
12
+ * Blacklist = 0 (default): all addresses permitted unless explicitly blocked.
13
+ * Whitelist = 1: only explicitly whitelisted addresses permitted.
14
+ */
15
+ export const LagoonV2AccessMode = {
16
+ Blacklist: 0,
17
+ Whitelist: 1,
18
+ } as const;
19
+ export type LagoonV2AccessModeValue = (typeof LagoonV2AccessMode)[keyof typeof LagoonV2AccessMode];
20
+
21
+ /**
22
+ * 19-field InitStruct for Lagoon v0.6.
23
+ *
24
+ * Field order matches the Solidity ABI encoding order exactly (required for abi.encode):
25
+ * underlying, name, symbol, safe, whitelistManager, valuationManager, admin,
26
+ * feeReceiver, managementRate, performanceRate, accessMode, entryRate, exitRate,
27
+ * haircutRate, securityCouncil, externalSanctionsList, initialTotalAssets,
28
+ * superOperator, allowHighWaterMarkReset
29
+ *
30
+ * Key differences from v0.5:
31
+ * - `accessMode` (uint8 enum) replaces `enableWhitelist` (bool)
32
+ * - `entryRate`, `exitRate`, `haircutRate` are new fee rate fields (uint16)
33
+ * - `securityCouncil`, `externalSanctionsList`, `superOperator` are new roles (address)
34
+ * - `initialTotalAssets` (uint256) is new
35
+ * - `allowHighWaterMarkReset` (bool) is new
36
+ * - `rateUpdateCooldown` is REMOVED
37
+ * All fields are required — no defaults are applied.
38
+ */
39
+ export type LagoonV2InitStruct = Readonly<{
40
+ underlying: Address;
41
+ name: string;
42
+ symbol: string;
43
+ safe: Address;
44
+ whitelistManager: Address;
45
+ valuationManager: Address;
46
+ admin: Address;
47
+ feeReceiver: Address;
48
+ managementRate: number; // uint16 (0–10_000)
49
+ performanceRate: number; // uint16 (0–10_000)
50
+ accessMode: LagoonV2AccessModeValue; // uint8: 0=Blacklist, 1=Whitelist
51
+ entryRate: number; // uint16 (0–10_000)
52
+ exitRate: number; // uint16 (0–10_000)
53
+ haircutRate: number; // uint16 (0–10_000)
54
+ securityCouncil: Address;
55
+ externalSanctionsList: Address;
56
+ initialTotalAssets: bigint; // uint256
57
+ superOperator: Address;
58
+ allowHighWaterMarkReset: boolean;
59
+ }>;
60
+
61
+ /**
62
+ * Full args for the v0.6 bytes-overload createVaultProxy call.
63
+ * `logic` MUST be the explicit v0.6 vault implementation address — never address(0).
64
+ * Passing address(0) resolves to the registry's v0.5.0 default logic and silently deploys v0.5.
65
+ */
66
+ export type LagoonV2CreateVaultProxyArgs = Readonly<{
67
+ logic: Address;
68
+ initialOwner: Address;
69
+ initialDelay: bigint;
70
+ initStruct: LagoonV2InitStruct;
71
+ /** Registry address (per-chain constant; obtained from factory.registry()). */
72
+ registry: Address;
73
+ /** Wrapped native token address (per-chain constant; obtained from factory.wrappedNativeToken()). */
74
+ wrappedNative: Address;
75
+ salt: HexString;
76
+ }>;
77
+
78
+ // ---------------------------------------------------------------------------
79
+ // ABI parameter types for encoding
80
+ // ---------------------------------------------------------------------------
81
+
82
+ const INIT_STRUCT_ABI_TYPE = {
83
+ type: "tuple",
84
+ components: [
85
+ { name: "underlying", type: "address" },
86
+ { name: "name", type: "string" },
87
+ { name: "symbol", type: "string" },
88
+ { name: "safe", type: "address" },
89
+ { name: "whitelistManager", type: "address" },
90
+ { name: "valuationManager", type: "address" },
91
+ { name: "admin", type: "address" },
92
+ { name: "feeReceiver", type: "address" },
93
+ { name: "managementRate", type: "uint16" },
94
+ { name: "performanceRate", type: "uint16" },
95
+ { name: "accessMode", type: "uint8" },
96
+ { name: "entryRate", type: "uint16" },
97
+ { name: "exitRate", type: "uint16" },
98
+ { name: "haircutRate", type: "uint16" },
99
+ { name: "securityCouncil", type: "address" },
100
+ { name: "externalSanctionsList", type: "address" },
101
+ { name: "initialTotalAssets", type: "uint256" },
102
+ { name: "superOperator", type: "address" },
103
+ { name: "allowHighWaterMarkReset", type: "bool" },
104
+ ],
105
+ } as const;
106
+
107
+ // initialize(bytes _data, address _feeRegistry, address _wrappedNativeToken)
108
+ const INITIALIZE_ABI = [
109
+ {
110
+ name: "initialize",
111
+ type: "function",
112
+ inputs: [
113
+ { name: "_data", type: "bytes" },
114
+ { name: "_feeRegistry", type: "address" },
115
+ { name: "_wrappedNativeToken", type: "address" },
116
+ ],
117
+ outputs: [],
118
+ stateMutability: "nonpayable",
119
+ },
120
+ ] as const;
121
+
122
+ // ---------------------------------------------------------------------------
123
+ // Validation helpers
124
+ // ---------------------------------------------------------------------------
125
+
126
+ function validateRates({
127
+ managementRate,
128
+ performanceRate,
129
+ entryRate,
130
+ exitRate,
131
+ haircutRate,
132
+ }: LagoonV2InitStruct): void {
133
+ const MAX_RATE = 10_000;
134
+ if (performanceRate > MAX_RATE) throw new Error(`performanceRate ${performanceRate} exceeds max ${MAX_RATE}`);
135
+ if (managementRate > MAX_RATE) throw new Error(`managementRate ${managementRate} exceeds max ${MAX_RATE}`);
136
+ if (entryRate > MAX_RATE) throw new Error(`entryRate ${entryRate} exceeds max ${MAX_RATE}`);
137
+ if (exitRate > MAX_RATE) throw new Error(`exitRate ${exitRate} exceeds max ${MAX_RATE}`);
138
+ if (haircutRate > MAX_RATE) throw new Error(`haircutRate ${haircutRate} exceeds max ${MAX_RATE}`);
139
+ }
140
+
141
+ // ---------------------------------------------------------------------------
142
+ // Inner init calldata builder
143
+ // ---------------------------------------------------------------------------
144
+
145
+ /**
146
+ * Builds the `call_data` bytes that the LagoonVaultProxy's initialize function expects.
147
+ *
148
+ * call_data = initialize(abi.encode(<19-field InitStruct tuple>), registry, wrappedNative)
149
+ *
150
+ * This is passed to the bytes-overload createVaultProxy as the `call_data` argument.
151
+ * The factory forwards it verbatim to the proxy's constructor, which delegatecalls it
152
+ * into the vault implementation during initialization.
153
+ */
154
+ export const buildLagoonV2InitCalldata = ({
155
+ initStruct,
156
+ registry,
157
+ wrappedNative,
158
+ }: {
159
+ initStruct: LagoonV2InitStruct;
160
+ registry: Address;
161
+ wrappedNative: Address;
162
+ }): Hex => {
163
+ validateRates(initStruct);
164
+
165
+ // Step 1: ABI-encode the 19-field InitStruct as a tuple (bytes _data parameter)
166
+ const encodedInitStruct = encodeAbiParameters(
167
+ [INIT_STRUCT_ABI_TYPE],
168
+ [
169
+ {
170
+ underlying: initStruct.underlying,
171
+ name: initStruct.name,
172
+ symbol: initStruct.symbol,
173
+ safe: initStruct.safe,
174
+ whitelistManager:
175
+ initStruct.accessMode === LagoonV2AccessMode.Whitelist
176
+ ? initStruct.whitelistManager
177
+ : (ZERO_ADDRESS as Address),
178
+ valuationManager: initStruct.valuationManager,
179
+ admin: initStruct.admin,
180
+ feeReceiver: initStruct.feeReceiver,
181
+ managementRate: initStruct.managementRate,
182
+ performanceRate: initStruct.performanceRate,
183
+ accessMode: initStruct.accessMode,
184
+ entryRate: initStruct.entryRate,
185
+ exitRate: initStruct.exitRate,
186
+ haircutRate: initStruct.haircutRate,
187
+ securityCouncil: initStruct.securityCouncil,
188
+ externalSanctionsList: initStruct.externalSanctionsList,
189
+ initialTotalAssets: initStruct.initialTotalAssets,
190
+ superOperator: initStruct.superOperator,
191
+ allowHighWaterMarkReset: initStruct.allowHighWaterMarkReset,
192
+ },
193
+ ],
194
+ );
195
+
196
+ // Step 2: Encode initialize(bytes,address,address) call
197
+ return encodeFunctionData({
198
+ abi: INITIALIZE_ABI,
199
+ functionName: "initialize",
200
+ args: [encodedInitStruct, registry, wrappedNative],
201
+ });
202
+ };
203
+
204
+ // ---------------------------------------------------------------------------
205
+ // Factory calldata encoder
206
+ // ---------------------------------------------------------------------------
207
+
208
+ /**
209
+ * Encodes the bytes-overload `createVaultProxy` calldata for the v3 Lagoon factory.
210
+ *
211
+ * Uses selector 0x9dfe49f2 = keccak4("createVaultProxy(address,address,uint256,bytes,bytes32)").
212
+ * The `logic` argument MUST be the explicit v0.6 vault implementation — never address(0).
213
+ *
214
+ * @returns ABI-encoded transaction calldata (including 4-byte selector).
215
+ */
216
+ export const CreateLagoonV2VaultProxyCalldata = ({
217
+ logic,
218
+ initialOwner,
219
+ initialDelay,
220
+ initStruct,
221
+ registry,
222
+ wrappedNative,
223
+ salt,
224
+ }: LagoonV2CreateVaultProxyArgs): HexString => {
225
+ if (logic === ZERO_ADDRESS) {
226
+ throw new Error(
227
+ "logic must be the explicit v0.6 vault implementation address. " +
228
+ "address(0) resolves to the registry default (v0.5.0) and silently deploys v0.5.",
229
+ );
230
+ }
231
+
232
+ const callData = buildLagoonV2InitCalldata({ initStruct, registry, wrappedNative });
233
+
234
+ return encodeFunctionData({
235
+ abi: lagoonV2FactoryAbi,
236
+ functionName: "createVaultProxy",
237
+ args: [logic, initialOwner, initialDelay, callData, salt as Hex],
238
+ }) as HexString;
239
+ };
240
+
241
+ /**
242
+ * Wraps CreateLagoonV2VaultProxyCalldata in a Call object suitable for Safe execution.
243
+ */
244
+ export const createLagoonV2VaultProxyTrx = ({
245
+ createVaultProxyParams,
246
+ factory,
247
+ }: {
248
+ createVaultProxyParams: LagoonV2CreateVaultProxyArgs;
249
+ factory: Address;
250
+ }): Unwrapable<Call> => {
251
+ return createCall({
252
+ operation: 0,
253
+ to: factory,
254
+ value: 0n,
255
+ data: CreateLagoonV2VaultProxyCalldata(createVaultProxyParams),
256
+ });
257
+ };
258
+
259
+ // ---------------------------------------------------------------------------
260
+ // CREATE2 deterministic address predictor
261
+ // ---------------------------------------------------------------------------
262
+
263
+ /**
264
+ * LagoonVaultProxy creation bytecode (v0.6).
265
+ *
266
+ * Extracted from the v3 factory implementation at 0xd8c3dfb8e47b153913fe217d6ff4c9ecc4bb5544
267
+ * (Arbitrum mainnet) via CODECOPY analysis: 5580 bytes at factory bytecode offset 0x0aa1.
268
+ * The same factory implementation is deployed on Ethereum mainnet at the same address.
269
+ *
270
+ * Constructor signature: (address logic, address registry, address initialOwner, uint256 initialDelay, bytes call_data)
271
+ * The factory passes: (logic, registry, initialOwner, initialDelay, call_data) where
272
+ * registry is read from factory storage, and call_data is the bytes arg from the factory call.
273
+ *
274
+ * This bytecode is different from v0.5's OptinProxy creation bytecode.
275
+ * Using the wrong creation bytecode produces a mismatched CREATE2 address.
276
+ */
277
+ export const LAGOON_VAULT_PROXY_CREATION_BYTECODE =
278
+ "0x60c06040526040516115cc3803806115cc833981016040819052610022916104b2565b61002c85856100a8565b8161003782826101b8565b5050828260405161004790610454565b6001600160a01b0390921682526020820152604001604051809103905ff080158015610075573d5f803e3d5ffd5b506001600160a01b031660805261009361008e60805190565b610216565b5050506001600160a01b031660a0525061061d565b5f6001600160a01b03831661011e57816001600160a01b03166345f55b3c6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100f3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610117919061059c565b90506101b2565b6001600160a01b03821663f3c665f7610135610262565b856040518363ffffffff1660e01b81526004016101539291906105b5565b602060405180830381865afa15801561016e573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019291906105cf565b6101af5760405163474245d760e11b815260040160405180910390fd5b50815b92915050565b6101c18261027f565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561020a5761020582826102e5565b505050565b610212610358565b5050565b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61023f610379565b8260405161024e9291906105b5565b60405180910390a161025f81610398565b50565b5f61027a5f5f805160206115ac833981519152610389565b905090565b806001600160a01b03163b5f036102b45780604051634c9c8ce360e01b81526004016102ab91906105ee565b60405180910390fd5b805f805160206115ac8339815191525b80546001600160a01b0319166001600160a01b039290921691909117905550565b60605f80846001600160a01b0316846040516103019190610602565b5f60405180830381855af49150503d805f8114610339576040519150601f19603f3d011682016040523d82523d5f602084013e61033e565b606091505b50909250905061034f8583836103d5565b95945050505050565b34156103775760405163b398979f60e01b815260040160405180910390fd5b565b5f5f8051602061158c8339815191525b546001600160a01b0316919050565b6001600160a01b0381166103c1575f604051633173bdd160e11b81526004016102ab91906105ee565b805f8051602061158c8339815191526102c4565b6060826103ea576103e58261042b565b610424565b815115801561040157506001600160a01b0384163b155b156104215783604051639996b31560e01b81526004016102ab91906105ee565b50805b9392505050565b80511561043b5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6109a180610beb83390190565b80516001600160a01b0381168114610477575f80fd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f5b838110156104aa578181015183820152602001610492565b50505f910152565b5f805f805f60a086880312156104c6575f80fd5b6104cf86610461565b94506104dd60208701610461565b93506104eb60408701610461565b6060870151608088015191945092506001600160401b0381111561050d575f80fd5b8601601f8101881361051d575f80fd5b80516001600160401b038111156105365761053661047c565b604051601f8201601f19908116603f011681016001600160401b03811182821017156105645761056461047c565b6040528181528282016020018a101561057b575f80fd5b61058c826020830160208601610490565b8093505050509295509295909350565b5f602082840312156105ac575f80fd5b61042482610461565b6001600160a01b0392831681529116602082015260400190565b5f602082840312156105df575f80fd5b81518015158114610424575f80fd5b6001600160a01b0391909116815260200190565b5f8251610613818460208701610490565b9190910192915050565b60805160a0516105a96106425f395f81816038015260f401525f607201526105a95ff3fe60806040526004361061001d575f3560e01c806306433b1b14610027575b610025610070565b005b348015610032575f80fd5b5061005a7f000000000000000000000000000000000000000000000000000000000000000081565b60405161006791906103eb565b60405180910390f35b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633036101c2575f356001600160e01b03191663278f794360e11b146100d2576040516334ad5dbb60e21b815260040160405180910390fd5b5f806100e136600481846103ff565b8101906100ee919061043a565b915091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f3c665f76101296101cc565b6040516001600160e01b031960e084901b1681526001600160a01b0391821660048201529085166024820152604401602060405180830381865afa158015610173573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101979190610508565b6101b45760405163474245d760e11b815260040160405180910390fd5b6101be82826101f0565b5050565b6101ca61024a565b565b5f6101eb5f80516020610554833981519152546001600160a01b031690565b905090565b6101f98261025a565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a28051156102425761023d82826102bd565b505050565b6101be61032f565b6101ca6102556101cc565b61034e565b806001600160a01b03163b5f0361028f5780604051634c9c8ce360e01b815260040161028691906103eb565b60405180910390fd5b5f8051602061055483398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b0316846040516102d99190610527565b5f60405180830381855af49150503d805f8114610311576040519150601f19603f3d011682016040523d82523d5f602084013e610316565b606091505b509150915061032685838361036c565b95945050505050565b34156101ca5760405163b398979f60e01b815260040160405180910390fd5b365f80375f80365f845af43d5f803e808015610368573d5ff35b3d5ffd5b6060826103815761037c826103c2565b6103bb565b815115801561039857506001600160a01b0384163b155b156103b85783604051639996b31560e01b815260040161028691906103eb565b50805b9392505050565b8051156103d25780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160a01b0391909116815260200190565b5f808585111561040d575f80fd5b83861115610419575f80fd5b5050820193919092039150565b634e487b7160e01b5f52604160045260245ffd5b5f806040838503121561044b575f80fd5b82356001600160a01b0381168114610461575f80fd5b915060208301356001600160401b0381111561047b575f80fd5b8301601f8101851361048b575f80fd5b80356001600160401b038111156104a4576104a4610426565b604051601f8201601f19908116603f011681016001600160401b03811182821017156104d2576104d2610426565b6040528181528282016020018710156104e9575f80fd5b816020840160208301375f602083830101528093505050509250929050565b5f60208284031215610518575f80fd5b815180151581146103bb575f80fd5b5f82515f5b81811015610546576020818601810151858301520161052c565b505f92019182525091905056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca26469706673582212201310de98019309a7eb9fb8d90a862cfb1e8bb0576f4d1ffc2eaf580c61d7e42864736f6c634300081a0033608060405234801561000f575f80fd5b506040516109a13803806109a183398101604081905261002e91610158565b81806001600160a01b03811661005e57604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61006781610109565b5050620151808110156100925760405163013ccc8d60e01b8152620151806004820152602401610055565b62278d008111156100bb57604051630b94129b60e31b815262278d006004820152602401610055565b5f1960018190556003556005819055604080518281525f60208201527fa580b4a9812995ffed1b336481c3f3bfeb3414df9f587a9d73856bab25aa4eee910160405180910390a1505061018f565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f8060408385031215610169575f80fd5b82516001600160a01b038116811461017f575f80fd5b6020939093015192949293505050565b6108058061019c5f395ff3fe6080604052600436106100b7575f3560e01c8063033f8dbc146100bb5780634125ff90146100e3578063432efade146100f9578063554f94db1461011a578063657081b31461012e5780636a42b8f81461014d578063715018a6146101625780638b677b03146101765780638da5cb5b146101a25780639623609d146101b65780639f81aed7146101c9578063a36f141c146101df578063ad3cb1cc146101f4578063f2fde38b14610231578063f6b12cf914610250575b5f80fd5b3480156100c6575f80fd5b506100d060045481565b6040519081526020015b60405180910390f35b3480156100ee575f80fd5b506100d062278d0081565b348015610104575f80fd5b506101186101133660046105e1565b610265565b005b348015610125575f80fd5b50610118610326565b348015610139575f80fd5b5061011861014836600461060c565b6103a8565b348015610158575f80fd5b506100d060055481565b34801561016d575f80fd5b50610118610420565b348015610181575f80fd5b50600254610195906001600160a01b031681565b6040516100da919061062e565b3480156101ad575f80fd5b50610195610433565b6101186101c4366004610656565b610441565b3480156101d4575f80fd5b506100d06201518081565b3480156101ea575f80fd5b506100d060035481565b3480156101ff575f80fd5b50610224604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516100da919061076d565b34801561023c575f80fd5b5061011861024b36600461060c565b610523565b34801561025b575f80fd5b506100d060015481565b61026d610560565b6201518081101561029b5760405163013ccc8d60e01b81526201518060048201526024015b60405180910390fd5b62278d008111156102c457604051630b94129b60e31b815262278d006004820152602401610292565b60048190556005546102d6904261077f565b60038190556005546004546040805192835260208301919091528101919091527fab7d3921ca5710b1f874b995128f2d434b8b28080cc90e5b7ae542d01a41dd6e9060600160405180910390a150565b61032e610560565b60035442101561035157604051634040f3a760e01b815260040160405180910390fd5b7fa580b4a9812995ffed1b336481c3f3bfeb3414df9f587a9d73856bab25aa4eee60045460055460405161038f929190918252602082015260400190565b60405180910390a1600480546005555f90555f19600355565b6103b0610560565b600280546001600160a01b0319166001600160a01b0383161790556005546103d8904261077f565b60018190556002546040519182526001600160a01b0316907fb995d606597d17deae0e0b28f4668c00c67c22d7bed7b95db2a5ac7f1b96aa2b9060200160405180910390a250565b610428610560565b6104315f610592565b565b5f546001600160a01b031690565b610449610560565b60015442101561046c57604051634040f3a760e01b815260040160405180910390fd5b6002546001600160a01b038381169116146104a757600254604051631a160ecd60e11b8152610292916001600160a01b03169060040161062e565b60025460405163278f794360e11b81526001600160a01b0380861692634f1ef2869234926104db92169086906004016107a4565b5f604051808303818588803b1580156104f2575f80fd5b505af1158015610504573d5f803e3d5ffd5b5050600280546001600160a01b031916905550505f1960015550505050565b61052b610560565b6001600160a01b038116610554575f604051631e4fbdf760e01b8152600401610292919061062e565b61055d81610592565b50565b33610569610433565b6001600160a01b031614610431573360405163118cdaa760e01b8152600401610292919061062e565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f602082840312156105f1575f80fd5b5035919050565b6001600160a01b038116811461055d575f80fd5b5f6020828403121561061c575f80fd5b8135610627816105f8565b9392505050565b6001600160a01b0391909116815260200190565b634e487b7160e01b5f52604160045260245ffd5b5f805f60608486031215610668575f80fd5b8335610673816105f8565b92506020840135610683816105f8565b915060408401356001600160401b0381111561069d575f80fd5b8401601f810186136106ad575f80fd5b80356001600160401b038111156106c6576106c6610642565b604051601f8201601f19908116603f011681016001600160401b03811182821017156106f4576106f4610642565b60405281815282820160200188101561070b575f80fd5b816020840160208301375f602083830101528093505050509250925092565b5f81518084525f5b8181101561074e57602081850181015186830182015201610732565b505f602082860101526020601f19601f83011685010191505092915050565b602081525f610627602083018461072a565b8082018082111561079e57634e487b7160e01b5f52601160045260245ffd5b92915050565b6001600160a01b03831681526040602082018190525f906107c79083018461072a565b94935050505056fea264697066735822122036804f99dd8956664ddace0c969782ec219cf2ab51ffe4b46a5fa0641d88cc0c64736f6c634300081a0033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
279
+
280
+ /**
281
+ * Computes the deterministic CREATE2 vault address for a v0.6 Lagoon vault.
282
+ *
283
+ * The factory deploys `new LagoonVaultProxy{salt: salt}(logic, registry, initialOwner, initialDelay, call_data)`.
284
+ * The CREATE2 address is: keccak256(0xff ++ factory ++ salt ++ keccak256(initCode))[-20:]
285
+ * where initCode = LAGOON_VAULT_PROXY_CREATION_BYTECODE + abi.encode(logic, registry, initialOwner, initialDelay, call_data)
286
+ *
287
+ * @returns EIP-55 checksummed address of the vault that would be deployed.
288
+ */
289
+ export const calculateLagoonV2DeterministicVaultAddress = ({
290
+ factoryAddress,
291
+ logic,
292
+ initialOwner,
293
+ initialDelay,
294
+ initStruct,
295
+ registry,
296
+ wrappedNative,
297
+ salt,
298
+ }: {
299
+ factoryAddress: Address;
300
+ logic: Address;
301
+ initialOwner: Address;
302
+ initialDelay: bigint;
303
+ initStruct: LagoonV2InitStruct;
304
+ registry: Address;
305
+ wrappedNative: Address;
306
+ salt: HexString;
307
+ }): Address => {
308
+ if (logic === ZERO_ADDRESS) {
309
+ throw new Error(
310
+ "logic must be the explicit v0.6 vault implementation address. " +
311
+ "address(0) resolves to the registry default (v0.5.0) and silently deploys v0.5.",
312
+ );
313
+ }
314
+
315
+ // Build the call_data (same as what gets passed to the factory bytes overload)
316
+ const callData = buildLagoonV2InitCalldata({ initStruct, registry, wrappedNative });
317
+
318
+ // ABI-encode constructor args: (address logic, address registry, address initialOwner, uint256 initialDelay, bytes call_data)
319
+ const constructorEncoded = encodeAbiParameters(
320
+ [
321
+ { name: "logic", type: "address" },
322
+ { name: "registry", type: "address" },
323
+ { name: "initialOwner", type: "address" },
324
+ { name: "initialDelay", type: "uint256" },
325
+ { name: "call_data", type: "bytes" },
326
+ ],
327
+ [logic, registry, initialOwner, initialDelay, callData],
328
+ );
329
+
330
+ // Full init code = creation bytecode + abi.encode(constructor args)
331
+ const initCode = (LAGOON_VAULT_PROXY_CREATION_BYTECODE + constructorEncoded.slice(2)) as Hex;
332
+ const initCodeHash = keccak256(initCode);
333
+
334
+ // CREATE2: keccak256(0xff ++ factory ++ salt ++ keccak256(initCode))
335
+ // Use encodePacked (solidity-packed, no length/offset padding) for the create2 preimage.
336
+ const create2Input = encodePacked(
337
+ ["bytes1", "address", "bytes32", "bytes32"],
338
+ ["0xff", factoryAddress, salt as Hex, initCodeHash],
339
+ );
340
+
341
+ const hash = keccak256(create2Input);
342
+ // Take the last 20 bytes of the hash as the address
343
+ const addressHex = `0x${hash.slice(-40)}`;
344
+ return getAddress(addressHex) as Address;
345
+ };