@gearbox-protocol/sdk 14.12.0-next.2 → 14.12.0-next.4

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 (46) hide show
  1. package/dist/cjs/preview/parse/index.js +2 -0
  2. package/dist/cjs/preview/parse/parseOperationCalldata.js +8 -0
  3. package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +108 -0
  4. package/dist/cjs/preview/parse/types-rwa.js +16 -0
  5. package/dist/cjs/preview/parse/types.js +9 -2
  6. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +13 -13
  7. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +13 -13
  8. package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +66 -0
  9. package/dist/cjs/preview/prerequisites/buildPrerequisites.js +77 -5
  10. package/dist/cjs/preview/prerequisites/index.js +2 -0
  11. package/dist/cjs/preview/simulate/index.js +5 -2
  12. package/dist/cjs/preview/simulate/simulateOperation.js +4 -0
  13. package/dist/cjs/preview/simulate/simulateRWAOperation.js +30 -0
  14. package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +30 -0
  15. package/dist/cjs/sdk/market/rwa/types.js +5 -2
  16. package/dist/esm/preview/parse/index.js +1 -0
  17. package/dist/esm/preview/parse/parseOperationCalldata.js +9 -0
  18. package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +89 -0
  19. package/dist/esm/preview/parse/types-rwa.js +0 -0
  20. package/dist/esm/preview/parse/types.js +6 -1
  21. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +13 -13
  22. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +13 -13
  23. package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +42 -0
  24. package/dist/esm/preview/prerequisites/buildPrerequisites.js +79 -5
  25. package/dist/esm/preview/prerequisites/index.js +1 -0
  26. package/dist/esm/preview/simulate/index.js +3 -1
  27. package/dist/esm/preview/simulate/simulateOperation.js +8 -1
  28. package/dist/esm/preview/simulate/simulateRWAOperation.js +6 -0
  29. package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +33 -1
  30. package/dist/esm/sdk/market/rwa/types.js +5 -2
  31. package/dist/types/preview/parse/classifyInnerOperations.d.ts +0 -2
  32. package/dist/types/preview/parse/index.d.ts +1 -0
  33. package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +22 -0
  34. package/dist/types/preview/parse/types-rwa.d.ts +60 -0
  35. package/dist/types/preview/parse/types.d.ts +11 -6
  36. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +1 -3
  37. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +1 -3
  38. package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +36 -0
  39. package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +1 -1
  40. package/dist/types/preview/prerequisites/index.d.ts +1 -0
  41. package/dist/types/preview/prerequisites/types.d.ts +10 -8
  42. package/dist/types/preview/simulate/index.d.ts +2 -0
  43. package/dist/types/preview/simulate/simulateRWAOperation.d.ts +25 -0
  44. package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +6 -1
  45. package/dist/types/sdk/market/rwa/types.d.ts +13 -5
  46. package/package.json +1 -1
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  CreditFacadeV310Contract,
3
+ isRWAFactory,
3
4
  PoolV310Contract,
4
5
  ZapperContract
5
6
  } from "../../sdk/index.js";
6
7
  import { UnsupportedTargetError } from "./errors.js";
7
8
  import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
8
9
  import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
10
+ import { parseRWAFactoryOperationCalldata } from "./parseRWAFactoryOperationCalldata.js";
9
11
  function parseOperationCalldata(input) {
10
12
  const { sdk, to, calldata, value, sender } = input;
11
13
  const contract = sdk.getContract(to);
@@ -48,6 +50,13 @@ function parseOperationCalldata(input) {
48
50
  calldata
49
51
  });
50
52
  }
53
+ if (contract && isRWAFactory(contract)) {
54
+ return parseRWAFactoryOperationCalldata({
55
+ sdk,
56
+ factory: contract,
57
+ calldata
58
+ });
59
+ }
51
60
  throw new UnsupportedTargetError(to);
52
61
  }
53
62
  export {
@@ -0,0 +1,89 @@
1
+ import { AbstractAdapterContract } from "../../plugins/adapters/index.js";
2
+ import {
3
+ CreditFacadeV310Contract,
4
+ hexEq,
5
+ isRWAFactory,
6
+ RWA_FACTORY_SECURITIZE
7
+ } from "../../sdk/index.js";
8
+ import { classifyInnerOperations } from "./classifyInnerOperations.js";
9
+ import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
10
+ function parseRWAFactoryOperationCalldata(props) {
11
+ const { contractType, address } = props.factory;
12
+ if (isRWAFactory(props.factory, RWA_FACTORY_SECURITIZE)) {
13
+ return parseSecuritizeOperationCalldata(props);
14
+ }
15
+ throw new Error(
16
+ `unsupported RWA factory type "${contractType}" on ${address}`
17
+ );
18
+ }
19
+ function parseSecuritizeOperationCalldata(props) {
20
+ const { sdk, factory, calldata } = props;
21
+ const parsed = sdk.parseFunctionDataV2(factory.address, calldata);
22
+ const functionName = parsed.functionName.split("(")[0];
23
+ const { rawArgs } = parsed;
24
+ const innerCalls = rawArgs.calls ?? [];
25
+ const tokensToRegister = [
26
+ ...rawArgs.tokensToRegister ?? []
27
+ ];
28
+ const signaturesToCache = [
29
+ ...rawArgs.signaturesToCache ?? []
30
+ ];
31
+ const suite = functionName === "openCreditAccount" ? sdk.marketRegister.findCreditManager(rawArgs.creditManager) : resolveSuiteForMulticall(sdk, factory, innerCalls);
32
+ const metadata = {
33
+ factory: factory.address,
34
+ creditManager: suite.creditManager.address,
35
+ creditFacade: suite.creditFacade.address
36
+ };
37
+ const multicall = classifyInnerOperations(innerCalls, {
38
+ sdk,
39
+ underlying: suite.underlying
40
+ });
41
+ const expectedBalanceChanges = extractExpectedBalanceChanges(innerCalls);
42
+ switch (functionName) {
43
+ case "openCreditAccount":
44
+ return {
45
+ ...metadata,
46
+ operation: "SecuritizeOpenCreditAccount",
47
+ multicall,
48
+ expectedBalanceChanges,
49
+ tokensToRegister,
50
+ signaturesToCache
51
+ };
52
+ case "multicall":
53
+ return {
54
+ ...metadata,
55
+ operation: "SecuritizeMulticall",
56
+ creditAccount: rawArgs.creditAccount,
57
+ multicall,
58
+ expectedBalanceChanges,
59
+ tokensToRegister,
60
+ signaturesToCache
61
+ };
62
+ default:
63
+ throw new Error(
64
+ `unsupported RWA factory function "${parsed.functionName}" on ${factory.address}`
65
+ );
66
+ }
67
+ }
68
+ function resolveSuiteForMulticall(sdk, factory, innerCalls) {
69
+ for (const call of innerCalls) {
70
+ const contract = sdk.getContract(call.target);
71
+ if (contract instanceof CreditFacadeV310Contract) {
72
+ const suite = sdk.marketRegister.creditManagers.find(
73
+ (cm) => hexEq(cm.creditFacade.address, call.target)
74
+ );
75
+ if (suite) {
76
+ return suite;
77
+ }
78
+ }
79
+ if (contract instanceof AbstractAdapterContract) {
80
+ return sdk.marketRegister.findCreditManager(contract.creditManager);
81
+ }
82
+ }
83
+ throw new Error(
84
+ `cannot resolve credit manager for RWA factory multicall on ${factory.address}`
85
+ );
86
+ }
87
+ export {
88
+ parseRWAFactoryOperationCalldata
89
+ };
File without changes
@@ -1,9 +1,14 @@
1
1
  export * from "./types-adapters.js";
2
2
  export * from "./types-facades.js";
3
3
  export * from "./types-pools.js";
4
+ export * from "./types-rwa.js";
4
5
  function isPoolOperation(tx) {
5
6
  return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
6
7
  }
8
+ function isRWAOperation(tx) {
9
+ return tx.operation === "SecuritizeOpenCreditAccount" || tx.operation === "SecuritizeMulticall";
10
+ }
7
11
  export {
8
- isPoolOperation
12
+ isPoolOperation,
13
+ isRWAOperation
9
14
  };
@@ -4,14 +4,14 @@ import {
4
4
  toPrerequisiteError
5
5
  } from "./Prerequisite.js";
6
6
  class AllowancePrerequisite extends Prerequisite {
7
- _id;
8
- _title;
9
- _detail;
7
+ #id;
8
+ #title;
9
+ #detail;
10
10
  constructor(props) {
11
11
  super();
12
- this._id = props.id ?? `allowance:${props.token}:${props.owner}:${props.spender}`;
13
- this._title = props.title ?? "Token approval";
14
- this._detail = {
12
+ this.#id = props.id ?? `allowance:${props.token}:${props.owner}:${props.spender}`;
13
+ this.#title = props.title ?? "Token approval";
14
+ this.#detail = {
15
15
  token: props.token,
16
16
  owner: props.owner,
17
17
  spender: props.spender,
@@ -19,24 +19,24 @@ class AllowancePrerequisite extends Prerequisite {
19
19
  };
20
20
  }
21
21
  get id() {
22
- return this._id;
22
+ return this.#id;
23
23
  }
24
24
  get kind() {
25
25
  return "allowance";
26
26
  }
27
27
  get title() {
28
- return this._title;
28
+ return this.#title;
29
29
  }
30
30
  get detail() {
31
- return this._detail;
31
+ return this.#detail;
32
32
  }
33
33
  calls() {
34
34
  return [
35
35
  {
36
- address: this._detail.token,
36
+ address: this.#detail.token,
37
37
  abi: erc20Abi,
38
38
  functionName: "allowance",
39
- args: [this._detail.owner, this._detail.spender]
39
+ args: [this.#detail.owner, this.#detail.spender]
40
40
  }
41
41
  ];
42
42
  }
@@ -46,8 +46,8 @@ class AllowancePrerequisite extends Prerequisite {
46
46
  return this.errorResult(toPrerequisiteError(res?.error));
47
47
  }
48
48
  const actual = res.result;
49
- return this.satisfiedResult(actual >= this._detail.required, {
50
- ...this._detail,
49
+ return this.satisfiedResult(actual >= this.#detail.required, {
50
+ ...this.#detail,
51
51
  actual
52
52
  });
53
53
  }
@@ -4,38 +4,38 @@ import {
4
4
  toPrerequisiteError
5
5
  } from "./Prerequisite.js";
6
6
  class BalancePrerequisite extends Prerequisite {
7
- _id;
8
- _title;
9
- _detail;
7
+ #id;
8
+ #title;
9
+ #detail;
10
10
  constructor(props) {
11
11
  super();
12
- this._id = props.id ?? `balance:${props.token}:${props.owner}`;
13
- this._title = props.title ?? "Sufficient balance";
14
- this._detail = {
12
+ this.#id = props.id ?? `balance:${props.token}:${props.owner}`;
13
+ this.#title = props.title ?? "Sufficient balance";
14
+ this.#detail = {
15
15
  token: props.token,
16
16
  owner: props.owner,
17
17
  required: props.required
18
18
  };
19
19
  }
20
20
  get id() {
21
- return this._id;
21
+ return this.#id;
22
22
  }
23
23
  get kind() {
24
24
  return "balance";
25
25
  }
26
26
  get title() {
27
- return this._title;
27
+ return this.#title;
28
28
  }
29
29
  get detail() {
30
- return this._detail;
30
+ return this.#detail;
31
31
  }
32
32
  calls() {
33
33
  return [
34
34
  {
35
- address: this._detail.token,
35
+ address: this.#detail.token,
36
36
  abi: erc20Abi,
37
37
  functionName: "balanceOf",
38
- args: [this._detail.owner]
38
+ args: [this.#detail.owner]
39
39
  }
40
40
  ];
41
41
  }
@@ -45,8 +45,8 @@ class BalancePrerequisite extends Prerequisite {
45
45
  return this.errorResult(toPrerequisiteError(res?.error));
46
46
  }
47
47
  const actual = res.result;
48
- return this.satisfiedResult(actual >= this._detail.required, {
49
- ...this._detail,
48
+ return this.satisfiedResult(actual >= this.#detail.required, {
49
+ ...this.#detail,
50
50
  actual
51
51
  });
52
52
  }
@@ -0,0 +1,42 @@
1
+ import { Prerequisite } from "./Prerequisite.js";
2
+ class RWAOpenRequirementsPrerequisite extends Prerequisite {
3
+ #id;
4
+ #title;
5
+ #detail;
6
+ constructor(props) {
7
+ super();
8
+ this.#id = props.id ?? `rwaOpenRequirements:${props.factory}:${props.token}`;
9
+ this.#title = props.title ?? "RWA account requirements fulfilled";
10
+ this.#detail = props.requirements;
11
+ }
12
+ get id() {
13
+ return this.#id;
14
+ }
15
+ get kind() {
16
+ return "rwaOpenRequirements";
17
+ }
18
+ get title() {
19
+ return this.#title;
20
+ }
21
+ get detail() {
22
+ return this.#detail;
23
+ }
24
+ /** Pre-resolved: no on-chain reads to contribute. */
25
+ calls() {
26
+ return [];
27
+ }
28
+ resolve() {
29
+ return this.satisfiedResult(this.#satisfied(), this.#detail);
30
+ }
31
+ /**
32
+ * Satisfied when the borrower has nothing left to do: no tokens pending
33
+ * issuer-side registration and no messages left to sign.
34
+ */
35
+ #satisfied() {
36
+ const { securitizeTokensToRegister, requiredSignatures } = this.#detail;
37
+ return securitizeTokensToRegister.length === 0 && requiredSignatures.length === 0;
38
+ }
39
+ }
40
+ export {
41
+ RWAOpenRequirementsPrerequisite
42
+ };
@@ -1,7 +1,11 @@
1
1
  import { isAddressEqual } from "viem";
2
+ import {
3
+ AddressSet
4
+ } from "../../sdk/index.js";
2
5
  import { AllowancePrerequisite } from "./AllowancePrerequisite.js";
3
6
  import { BalancePrerequisite } from "./BalancePrerequisite.js";
4
- function buildPrerequisites(tx, ctx) {
7
+ import { RWAOpenRequirementsPrerequisite } from "./RWAOpenRequirementsPrerequisite.js";
8
+ async function buildPrerequisites(tx, ctx) {
5
9
  const { wallet } = ctx;
6
10
  switch (tx.operation) {
7
11
  // Deposit and Mint both pull the underlying from the caller into the pool;
@@ -127,7 +131,37 @@ function buildPrerequisites(tx, ctx) {
127
131
  case "OpenCreditAccount":
128
132
  case "CloseCreditAccount":
129
133
  case "LiquidateCreditAccount":
130
- return collateralPrerequisites(tx.multicall, tx.creditManager, wallet);
134
+ return collateralPrerequisites(
135
+ tx.operation === "OpenCreditAccount" ? { creditManager: tx.creditManager, borrower: wallet } : {
136
+ creditManager: tx.creditManager,
137
+ creditAccount: tx.creditAccount
138
+ },
139
+ tx.multicall,
140
+ ctx
141
+ );
142
+ // RWA-factory operations: same collateral checks as facade operations,
143
+ // plus (for opening) the factory's open-account requirements. The parsed
144
+ // operation carries template (empty) `tokensToRegister`/`signaturesToCache`;
145
+ // the prerequisite detail provides the real values.
146
+ case "SecuritizeOpenCreditAccount":
147
+ return [
148
+ ...await collateralPrerequisites(
149
+ { creditManager: tx.creditManager, borrower: wallet },
150
+ tx.multicall,
151
+ ctx
152
+ ),
153
+ ...await rwaOpenRequirementsPrerequisites(
154
+ tx.multicall,
155
+ tx.creditManager,
156
+ ctx
157
+ )
158
+ ];
159
+ case "SecuritizeMulticall":
160
+ return collateralPrerequisites(
161
+ { creditManager: tx.creditManager, creditAccount: tx.creditAccount },
162
+ tx.multicall,
163
+ ctx
164
+ );
131
165
  case "PartiallyLiquidateCreditAccount": {
132
166
  const underlying = underlyingOf(ctx.sdk, tx.creditManager);
133
167
  if (!underlying || tx.repaidAmount === 0n) {
@@ -153,7 +187,8 @@ function buildPrerequisites(tx, ctx) {
153
187
  return [];
154
188
  }
155
189
  }
156
- function collateralPrerequisites(multicall, creditManager, wallet) {
190
+ async function collateralPrerequisites(spenderOptions, multicall, ctx) {
191
+ const { sdk, wallet } = ctx;
157
192
  const required = /* @__PURE__ */ new Map();
158
193
  for (const op of multicall) {
159
194
  if (op.operation !== "AddCollateral" || op.amount === 0n) {
@@ -166,15 +201,19 @@ function collateralPrerequisites(multicall, creditManager, wallet) {
166
201
  amount: (existing?.amount ?? 0n) + op.amount
167
202
  });
168
203
  }
204
+ if (required.size === 0) {
205
+ return [];
206
+ }
207
+ const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
169
208
  const prereqs = [];
170
209
  for (const { token, amount } of required.values()) {
171
210
  prereqs.push(
172
211
  new AllowancePrerequisite({
173
212
  token,
174
213
  owner: wallet,
175
- spender: creditManager,
214
+ spender,
176
215
  required: amount,
177
- title: "Collateral approved to credit manager"
216
+ title: "Collateral approved"
178
217
  }),
179
218
  new BalancePrerequisite({
180
219
  token,
@@ -186,6 +225,41 @@ function collateralPrerequisites(multicall, creditManager, wallet) {
186
225
  }
187
226
  return prereqs;
188
227
  }
228
+ async function rwaOpenRequirementsPrerequisites(multicall, creditManager, ctx) {
229
+ const { sdk, wallet } = ctx;
230
+ const { rwaFactory } = sdk.marketRegister.findByCreditManager(creditManager);
231
+ if (!rwaFactory) {
232
+ return [];
233
+ }
234
+ const rwaTokens = new AddressSet(rwaFactory.getTokens());
235
+ const candidates = new AddressSet();
236
+ for (const op of multicall) {
237
+ if (op.operation === "AddCollateral" || op.operation === "UpdateQuota") {
238
+ candidates.add(op.token);
239
+ }
240
+ }
241
+ const prereqs = [];
242
+ for (const token of candidates) {
243
+ if (!rwaTokens.has(token)) {
244
+ continue;
245
+ }
246
+ const requirements = await sdk.accounts.getOpenAccountRequirements(
247
+ wallet,
248
+ creditManager,
249
+ { tokenOutAddress: token }
250
+ );
251
+ if (requirements) {
252
+ prereqs.push(
253
+ new RWAOpenRequirementsPrerequisite({
254
+ requirements,
255
+ token,
256
+ factory: rwaFactory.address
257
+ })
258
+ );
259
+ }
260
+ }
261
+ return prereqs;
262
+ }
189
263
  function underlyingOf(sdk, creditManager) {
190
264
  const suite = sdk.marketRegister.creditManagers.find(
191
265
  (cm) => isAddressEqual(cm.creditManager.address, creditManager)
@@ -3,5 +3,6 @@ export * from "./BalancePrerequisite.js";
3
3
  export * from "./buildPrerequisites.js";
4
4
  export * from "./Prerequisite.js";
5
5
  export * from "./prepareAction.js";
6
+ export * from "./RWAOpenRequirementsPrerequisite.js";
6
7
  export * from "./runPrerequisites.js";
7
8
  export * from "./types.js";
@@ -2,9 +2,11 @@ import { PreviewSimulationError } from "./errors.js";
2
2
  import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
3
3
  import { simulateOperation } from "./simulateOperation.js";
4
4
  import { simulatePoolOperation } from "./simulatePoolOperation.js";
5
+ import { simulateRWAOperation } from "./simulateRWAOperation.js";
5
6
  export {
6
7
  PreviewSimulationError,
7
8
  simulateFacadeOperation,
8
9
  simulateOperation,
9
- simulatePoolOperation
10
+ simulatePoolOperation,
11
+ simulateRWAOperation
10
12
  };
@@ -1,11 +1,18 @@
1
- import { isPoolOperation } from "../parse/index.js";
1
+ import {
2
+ isPoolOperation,
3
+ isRWAOperation
4
+ } from "../parse/index.js";
2
5
  import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
3
6
  import { simulatePoolOperation } from "./simulatePoolOperation.js";
7
+ import { simulateRWAOperation } from "./simulateRWAOperation.js";
4
8
  async function simulateOperation(input, options) {
5
9
  const { operation } = input;
6
10
  if (isPoolOperation(operation)) {
7
11
  return simulatePoolOperation({ ...input, operation }, options);
8
12
  }
13
+ if (isRWAOperation(operation)) {
14
+ return simulateRWAOperation({ ...input, operation }, options);
15
+ }
9
16
  return simulateFacadeOperation({ ...input, operation }, options);
10
17
  }
11
18
  export {
@@ -0,0 +1,6 @@
1
+ async function simulateRWAOperation(_input, _options) {
2
+ throw new Error("not yet implemented");
3
+ }
4
+ export {
5
+ simulateRWAOperation
6
+ };
@@ -1,4 +1,6 @@
1
- import { decodeAbiParameters } from "viem";
1
+ import {
2
+ decodeAbiParameters
3
+ } from "viem";
2
4
  import { iSecuritizeRWAFactoryAbi } from "../../../../abi/rwa/iSecuritizeRWAFactory.js";
3
5
  import { BaseContract } from "../../../base/index.js";
4
6
  import { AddressMap, AddressSet } from "../../../utils/index.js";
@@ -49,6 +51,30 @@ class SecuritizeRWAFactory extends BaseContract {
49
51
  operators: [...t.operators]
50
52
  }));
51
53
  }
54
+ parseFunctionParamsV2(params, strict) {
55
+ switch (params.functionName) {
56
+ case "openCreditAccount": {
57
+ const [creditManager, calls, tokensToRegister, signaturesToCache] = params.args;
58
+ return {
59
+ creditManager,
60
+ calls: this.register.parseMultiCallV2([...calls], strict),
61
+ tokensToRegister,
62
+ signaturesToCache
63
+ };
64
+ }
65
+ case "multicall": {
66
+ const [creditAccount, calls, tokensToRegister, signaturesToCache] = params.args;
67
+ return {
68
+ creditAccount,
69
+ calls: this.register.parseMultiCallV2([...calls], strict),
70
+ tokensToRegister,
71
+ signaturesToCache
72
+ };
73
+ }
74
+ default:
75
+ return super.parseFunctionParamsV2(params, strict);
76
+ }
77
+ }
52
78
  /**
53
79
  * {@inheritDoc IRWAFactory.decodeInvestorData}
54
80
  */
@@ -104,6 +130,12 @@ class SecuritizeRWAFactory extends BaseContract {
104
130
  })
105
131
  };
106
132
  }
133
+ /**
134
+ * {@inheritDoc IRWAFactory.getTokens}
135
+ */
136
+ getTokens() {
137
+ return this.dsTokens.map((t) => t.address);
138
+ }
107
139
  /**
108
140
  * {@inheritDoc IRWAFactory.getInvestor}
109
141
  */
@@ -1,7 +1,10 @@
1
1
  import { RWA_FACTORY_SECURITIZE } from "./securitize/index.js";
2
2
  const RWA_FACTORY_TYPES = [RWA_FACTORY_SECURITIZE];
3
- function isRWAFactory(factory, type) {
4
- return factory.contractType === type;
3
+ function isRWAFactory(contract, type) {
4
+ if (type) {
5
+ return contract.contractType === type;
6
+ }
7
+ return contract.contractType.startsWith("RWA_FACTORY::");
5
8
  }
6
9
  export {
7
10
  RWA_FACTORY_TYPES,
@@ -7,8 +7,6 @@ export interface ClassifyInnerOperationsProps {
7
7
  underlying: Address;
8
8
  }
9
9
  /**
10
- * Calldata-only counterpart of the SDK's `classifyMulticallOperations`.
11
- *
12
10
  * Maps each inner multicall entry to an {@link InnerOperation}:
13
11
  * - adapter and unknown targets become a pure-descriptor `Execute`
14
12
  * {@link AdapterOperation};
@@ -4,4 +4,5 @@ export * from "./extractExpectedBalanceChanges.js";
4
4
  export * from "./parseFacadeOperationCalldata.js";
5
5
  export * from "./parseOperationCalldata.js";
6
6
  export * from "./parsePoolOperationCalldata.js";
7
+ export * from "./parseRWAFactoryOperationCalldata.js";
7
8
  export * from "./types.js";
@@ -0,0 +1,22 @@
1
+ import type { Hex } from "viem";
2
+ import { type IRWAFactory, type OnchainSDK } from "../../sdk/index.js";
3
+ import type { RWAOperation } from "./types-rwa.js";
4
+ export interface ParseRWAFactoryOperationCalldataProps {
5
+ sdk: OnchainSDK;
6
+ /** Resolved RWA factory contract for the transaction target. */
7
+ factory: IRWAFactory;
8
+ calldata: Hex;
9
+ }
10
+ /**
11
+ * Decodes a RWA-factory entry-point call into the matching
12
+ * {@link RWAOperation}.
13
+ *
14
+ * RWA credit accounts are opened and managed through the market's RWA factory
15
+ * (see `CreditAccountsServiceV310`) rather than the credit facade, but the
16
+ * inner `calls` share the credit-facade multicall shape, so classification is
17
+ * identical to {@link parseFacadeOperationCalldata}.
18
+ *
19
+ * Dispatches on the factory's contract type; supporting a new factory type
20
+ * requires a new branch here plus new operation types in `types-rwa.ts`.
21
+ */
22
+ export declare function parseRWAFactoryOperationCalldata(props: ParseRWAFactoryOperationCalldataProps): RWAOperation;
@@ -0,0 +1,60 @@
1
+ import type { Address } from "viem";
2
+ import type { SecuritizeRegisterMessage } from "../../sdk/index.js";
3
+ import type { ExpectedBalanceChange, InnerOperation } from "./types-facades.js";
4
+ /**
5
+ * Metadata shared by all RWA factory operations. RWA credit accounts are
6
+ * opened and managed through the market's RWA factory rather than the credit
7
+ * facade, but the inner `calls` still target the facade/adapters, so the
8
+ * credit suite is known.
9
+ */
10
+ export interface RWAOperationMetadata {
11
+ /** RWA factory contract the transaction is sent to. */
12
+ factory: Address;
13
+ creditManager: Address;
14
+ creditFacade: Address;
15
+ }
16
+ export interface SecuritizeOpenCreditAccountOperation<Ext extends object = {}> extends RWAOperationMetadata {
17
+ operation: "SecuritizeOpenCreditAccount";
18
+ multicall: InnerOperation<Ext>[];
19
+ /**
20
+ * Potential balance changes declared by a router-generated
21
+ * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
22
+ * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
23
+ */
24
+ expectedBalanceChanges?: ExpectedBalanceChange[];
25
+ /**
26
+ * DSToken addresses to register, decoded from calldata. Empty in the
27
+ * template flow, where the real value comes from the factory's open-account
28
+ * requirements.
29
+ */
30
+ tokensToRegister: Address[];
31
+ /**
32
+ * EIP-712 registration signatures to store on-chain, decoded from calldata.
33
+ * Empty in the template flow.
34
+ */
35
+ signaturesToCache: SecuritizeRegisterMessage[];
36
+ }
37
+ /**
38
+ * `SecuritizeRWAFactory.multicall` call: like the facade's `multicall`, plus
39
+ * the factory-specific registration args.
40
+ */
41
+ export interface SecuritizeMulticallOperation<Ext extends object = {}> extends RWAOperationMetadata {
42
+ operation: "SecuritizeMulticall";
43
+ creditAccount: Address;
44
+ multicall: InnerOperation<Ext>[];
45
+ /**
46
+ * Potential balance changes declared by a router-generated
47
+ * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
48
+ * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
49
+ */
50
+ expectedBalanceChanges?: ExpectedBalanceChange[];
51
+ /** DSToken addresses to register, decoded from calldata. */
52
+ tokensToRegister: Address[];
53
+ /** EIP-712 registration signatures to store on-chain, decoded from calldata. */
54
+ signaturesToCache: SecuritizeRegisterMessage[];
55
+ }
56
+ /**
57
+ * Discriminated union of all RWA factory operation types. Extend it when
58
+ * adding support for a new RWA factory type.
59
+ */
60
+ export type RWAOperation<Ext extends object = {}> = SecuritizeOpenCreditAccountOperation<Ext> | SecuritizeMulticallOperation<Ext>;