@gearbox-protocol/sdk 14.12.0-next.3 → 14.12.0-next.5

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 (87) hide show
  1. package/dist/cjs/preview/index.js +2 -4
  2. package/dist/cjs/preview/parse/index.js +0 -2
  3. package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +5 -12
  4. package/dist/cjs/preview/parse/parseOperationCalldata.js +6 -4
  5. package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +4 -0
  6. package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +22 -10
  7. package/dist/cjs/preview/parse/types-rwa.js +16 -0
  8. package/dist/cjs/preview/parse/types.js +9 -2
  9. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +13 -13
  10. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +32 -14
  11. package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +66 -0
  12. package/dist/cjs/preview/prerequisites/buildPrerequisites.js +95 -27
  13. package/dist/cjs/preview/prerequisites/index.js +2 -0
  14. package/dist/cjs/preview/{simulate/holders.js → preview/errors.js} +12 -21
  15. package/dist/cjs/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
  16. package/dist/cjs/preview/preview/index.js +26 -0
  17. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +99 -0
  18. package/dist/cjs/preview/preview/previewOperation.js +41 -0
  19. package/dist/cjs/preview/preview/previewPoolOperation.js +75 -0
  20. package/dist/cjs/preview/preview/types.js +16 -0
  21. package/dist/cjs/preview/simulate/index.js +5 -2
  22. package/dist/cjs/preview/simulate/simulateOperation.js +4 -0
  23. package/dist/cjs/preview/simulate/simulatePoolOperation.js +20 -116
  24. package/dist/cjs/preview/simulate/simulateRWAOperation.js +30 -0
  25. package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
  26. package/dist/cjs/sdk/market/rwa/types.js +5 -2
  27. package/dist/cjs/sdk/market/zapper/ZapperContract.js +0 -3
  28. package/dist/esm/preview/index.js +1 -2
  29. package/dist/esm/preview/parse/index.js +0 -1
  30. package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +5 -12
  31. package/dist/esm/preview/parse/parseOperationCalldata.js +7 -5
  32. package/dist/esm/preview/parse/parsePoolOperationCalldata.js +4 -0
  33. package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +25 -11
  34. package/dist/esm/preview/parse/types-rwa.js +0 -0
  35. package/dist/esm/preview/parse/types.js +6 -1
  36. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +13 -13
  37. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +32 -14
  38. package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +42 -0
  39. package/dist/esm/preview/prerequisites/buildPrerequisites.js +100 -27
  40. package/dist/esm/preview/prerequisites/index.js +1 -0
  41. package/dist/esm/preview/preview/errors.js +12 -0
  42. package/dist/esm/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
  43. package/dist/esm/preview/preview/index.js +3 -0
  44. package/dist/esm/preview/preview/previewOpenCreditAccount.js +77 -0
  45. package/dist/esm/preview/preview/previewOperation.js +17 -0
  46. package/dist/esm/preview/preview/previewPoolOperation.js +53 -0
  47. package/dist/esm/preview/preview/types.js +0 -0
  48. package/dist/esm/preview/simulate/index.js +3 -1
  49. package/dist/esm/preview/simulate/simulateOperation.js +8 -1
  50. package/dist/esm/preview/simulate/simulatePoolOperation.js +21 -120
  51. package/dist/esm/preview/simulate/simulateRWAOperation.js +6 -0
  52. package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
  53. package/dist/esm/sdk/market/rwa/types.js +5 -2
  54. package/dist/esm/sdk/market/zapper/ZapperContract.js +0 -3
  55. package/dist/types/history/types.d.ts +4 -4
  56. package/dist/types/preview/index.d.ts +1 -2
  57. package/dist/types/preview/parse/index.d.ts +0 -1
  58. package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +10 -11
  59. package/dist/types/preview/parse/types-facades.d.ts +0 -33
  60. package/dist/types/preview/parse/types-pools.d.ts +29 -1
  61. package/dist/types/preview/parse/types-rwa.d.ts +48 -0
  62. package/dist/types/preview/parse/types.d.ts +11 -6
  63. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +1 -3
  64. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +9 -6
  65. package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +36 -0
  66. package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +15 -6
  67. package/dist/types/preview/prerequisites/index.d.ts +1 -0
  68. package/dist/types/preview/prerequisites/types.d.ts +10 -8
  69. package/dist/types/preview/preview/errors.d.ts +9 -0
  70. package/dist/types/preview/{parse → preview}/extractExpectedBalanceChanges.d.ts +4 -5
  71. package/dist/types/preview/preview/index.d.ts +3 -0
  72. package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +4 -0
  73. package/dist/types/preview/preview/previewOperation.d.ts +8 -0
  74. package/dist/types/preview/preview/previewPoolOperation.d.ts +5 -0
  75. package/dist/types/preview/preview/types.d.ts +103 -0
  76. package/dist/types/preview/simulate/index.d.ts +3 -1
  77. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -2
  78. package/dist/types/preview/simulate/simulateOperation.d.ts +0 -2
  79. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +6 -18
  80. package/dist/types/preview/simulate/simulateRWAOperation.d.ts +23 -0
  81. package/dist/types/preview/simulate/types.d.ts +12 -26
  82. package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -0
  83. package/dist/types/sdk/market/rwa/types.d.ts +13 -5
  84. package/dist/types/sdk/market/zapper/types.d.ts +6 -6
  85. package/package.json +1 -1
  86. package/dist/esm/preview/simulate/holders.js +0 -21
  87. package/dist/types/preview/simulate/holders.d.ts +0 -7
@@ -0,0 +1,77 @@
1
+ import {
2
+ AddressMap
3
+ } from "../../sdk/index.js";
4
+ import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
5
+ function previewOpenCreditAccount(input, operation) {
6
+ const { sdk, to, calldata } = input;
7
+ const market = sdk.marketRegister.findByCreditManager(
8
+ operation.creditManager
9
+ );
10
+ const collateralByToken = new AddressMap();
11
+ const balances = new AddressMap();
12
+ const addBalance = (token, amount) => {
13
+ balances.upsert(token, (balances.get(token) ?? 0n) + amount);
14
+ };
15
+ let debt = 0n;
16
+ const quotas = [];
17
+ for (const op of operation.multicall) {
18
+ switch (op.operation) {
19
+ case "AddCollateral": {
20
+ const balance = collateralByToken.get(op.token)?.balance ?? 0n;
21
+ collateralByToken.upsert(op.token, {
22
+ token: op.token,
23
+ balance: balance + op.amount
24
+ });
25
+ addBalance(op.token, op.amount);
26
+ break;
27
+ }
28
+ case "WithdrawCollateral":
29
+ addBalance(op.token, -op.amount);
30
+ break;
31
+ case "IncreaseBorrowedAmount":
32
+ debt += op.amount;
33
+ addBalance(op.token, op.amount);
34
+ break;
35
+ case "DecreaseBorrowedAmount":
36
+ debt -= op.amount;
37
+ addBalance(op.token, -op.amount);
38
+ break;
39
+ case "UpdateQuota":
40
+ quotas.push({ token: op.token, balance: op.change });
41
+ break;
42
+ }
43
+ }
44
+ const collateral = collateralByToken.values();
45
+ const collateralValue = collateral.reduce(
46
+ (acc, { token, balance }) => acc + market.priceOracle.convert(token, market.underlying, balance),
47
+ 0n
48
+ );
49
+ const parsed = sdk.parseFunctionDataV2(to, calldata);
50
+ const innerCalls = parsed.rawArgs.calls ?? [];
51
+ const deltas = extractExpectedBalanceChanges(innerCalls) ?? [];
52
+ for (const { token, balance } of deltas) {
53
+ addBalance(token, balance);
54
+ }
55
+ const assets = balances.entries().filter(([, balance]) => balance > 1n).map(([token, balance]) => ({ token, balance }));
56
+ return {
57
+ operation: operation.operation,
58
+ target: inferTargetAsset(operation.multicall, balances),
59
+ collateral,
60
+ collateralValue,
61
+ debt,
62
+ quotas,
63
+ assets
64
+ };
65
+ }
66
+ function inferTargetAsset(multicall, balances) {
67
+ for (const op of multicall) {
68
+ if (op.operation === "UpdateQuota" && op.change > 0n) {
69
+ const balance = balances.get(op.token);
70
+ return balance ? { token: op.token, balance } : void 0;
71
+ }
72
+ }
73
+ return void 0;
74
+ }
75
+ export {
76
+ previewOpenCreditAccount
77
+ };
@@ -0,0 +1,17 @@
1
+ import { isPoolOperation, parseOperationCalldata } from "../parse/index.js";
2
+ import { UnsupportedOperationError } from "./errors.js";
3
+ import { previewOpenCreditAccount } from "./previewOpenCreditAccount.js";
4
+ import { previewPoolOperation } from "./previewPoolOperation.js";
5
+ async function previewOperation(input, options) {
6
+ const operation = parseOperationCalldata(input);
7
+ if (isPoolOperation(operation)) {
8
+ return previewPoolOperation(input, operation, options);
9
+ }
10
+ if (operation.operation === "OpenCreditAccount" || operation.operation === "SecuritizeOpenCreditAccount") {
11
+ return previewOpenCreditAccount(input, operation);
12
+ }
13
+ throw new UnsupportedOperationError(operation.operation);
14
+ }
15
+ export {
16
+ previewOperation
17
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ simulatePoolOperation
3
+ } from "../simulate/index.js";
4
+ async function previewPoolOperation(input, operation, options) {
5
+ const { sdk, to, calldata } = input;
6
+ const { tokenIn, tokenOut } = operation;
7
+ const sim = await simulatePoolOperation(
8
+ { sdk, operation, to, calldata },
9
+ options
10
+ );
11
+ if (sim.status === "success") {
12
+ return {
13
+ operation: operation.operation,
14
+ pool: operation.pool,
15
+ tokenIn: { token: tokenIn, balance: sim.amountIn },
16
+ tokenOut: { token: tokenOut, balance: sim.amountOut }
17
+ };
18
+ }
19
+ const { error } = sim;
20
+ switch (operation.operation) {
21
+ case "Deposit":
22
+ return {
23
+ operation: "Deposit",
24
+ pool: operation.pool,
25
+ tokenIn: { token: tokenIn, balance: operation.assets },
26
+ tokenOut: { token: tokenOut, error }
27
+ };
28
+ case "Mint":
29
+ return {
30
+ operation: "Mint",
31
+ pool: operation.pool,
32
+ tokenIn: { token: tokenIn, error },
33
+ tokenOut: { token: tokenOut, balance: operation.shares }
34
+ };
35
+ case "Withdraw":
36
+ return {
37
+ operation: "Withdraw",
38
+ pool: operation.pool,
39
+ tokenIn: { token: tokenIn, error },
40
+ tokenOut: { token: tokenOut, balance: operation.assets }
41
+ };
42
+ case "Redeem":
43
+ return {
44
+ operation: "Redeem",
45
+ pool: operation.pool,
46
+ tokenIn: { token: tokenIn, balance: operation.shares },
47
+ tokenOut: { token: tokenOut, error }
48
+ };
49
+ }
50
+ }
51
+ export {
52
+ previewPoolOperation
53
+ };
File without changes
@@ -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 {
@@ -1,13 +1,6 @@
1
1
  import { iPoolV310Abi } from "../../abi/310/generated.js";
2
- import { ierc20Abi } from "../../abi/iERC20.js";
3
2
  import { iZapperAbi } from "../../abi/iZapper.js";
4
- import { AddressMap } from "../../sdk/index.js";
5
- import {
6
- asPreviewSimulationError,
7
- decodeSimulationError,
8
- PreviewSimulationError
9
- } from "./errors.js";
10
- import { watchedHolders } from "./holders.js";
3
+ import { asPreviewSimulationError } from "./errors.js";
11
4
  function previewRead(operation) {
12
5
  switch (operation.operation) {
13
6
  case "Deposit":
@@ -20,16 +13,6 @@ function previewRead(operation) {
20
13
  return { functionName: "previewRedeem", amount: operation.shares };
21
14
  }
22
15
  }
23
- function outsideToken(operation) {
24
- switch (operation.operation) {
25
- case "Deposit":
26
- case "Mint":
27
- return operation.tokenIn;
28
- case "Withdraw":
29
- case "Redeem":
30
- return operation.tokenOut;
31
- }
32
- }
33
16
  function previewContract(operation) {
34
17
  const { functionName, amount } = previewRead(operation);
35
18
  if (operation.zapper) {
@@ -47,60 +30,31 @@ function previewContract(operation) {
47
30
  args: [amount]
48
31
  };
49
32
  }
33
+ function amountsInOut(operation, previewAmount) {
34
+ switch (operation.operation) {
35
+ case "Deposit":
36
+ return { amountIn: operation.assets, amountOut: previewAmount };
37
+ case "Mint":
38
+ return { amountIn: previewAmount, amountOut: operation.shares };
39
+ case "Withdraw":
40
+ return { amountIn: previewAmount, amountOut: operation.assets };
41
+ case "Redeem":
42
+ return { amountIn: operation.shares, amountOut: previewAmount };
43
+ }
44
+ }
50
45
  async function simulatePoolOperation(input, options = {}) {
51
- const { sdk, operation, wallet } = input;
46
+ const { sdk, operation } = input;
52
47
  const { blockNumber, logger } = options;
53
- const { pool } = operation;
54
48
  try {
55
- const holders = watchedHolders(operation, wallet);
56
- const tokens = [outsideToken(operation), pool];
57
- const balanceCalls = holders.flatMap(
58
- (holder) => tokens.map((token) => ({ holder, token }))
59
- );
60
- const balanceContracts = balanceCalls.map(
61
- ({ holder, token }) => ({
62
- address: token,
63
- abi: ierc20Abi,
64
- functionName: "balanceOf",
65
- args: [holder]
66
- })
67
- );
68
- const preview = previewContract(operation);
69
- let results;
70
- try {
71
- results = await sdk.client.multicall({
72
- allowFailure: false,
73
- // `undefined` lets viem read at `latest`; `blockNumber` is only set for
74
- // testnet forks pinned to a specific block.
75
- blockNumber,
76
- contracts: [...balanceContracts, preview]
77
- });
78
- } catch (cause) {
79
- throw new PreviewSimulationError([
80
- {
81
- source: "multicall",
82
- detail: decodeSimulationError({
83
- error: cause instanceof Error ? cause : new Error(String(cause))
84
- })
85
- }
86
- ]);
87
- }
88
- const previewAmount = results[balanceContracts.length];
89
- const balances = new AddressMap();
90
- for (const [i, { holder, token }] of balanceCalls.entries()) {
91
- const tokenBalances = balances.get(holder) ?? new AddressMap();
92
- tokenBalances.upsert(token, results[i]);
93
- balances.upsert(holder, tokenBalances);
94
- }
95
- const before = (token, holder) => balances.get(holder)?.get(token) ?? 0n;
49
+ const previewAmount = await sdk.client.readContract({
50
+ // `undefined` lets viem read at `latest`; `blockNumber` is only set for
51
+ // testnet forks pinned to a specific block.
52
+ blockNumber,
53
+ ...previewContract(operation)
54
+ });
96
55
  return {
97
56
  status: "success",
98
- balanceChanges: computePoolOpBalanceChanges(
99
- operation,
100
- wallet,
101
- previewAmount,
102
- before
103
- )
57
+ ...amountsInOut(operation, previewAmount)
104
58
  };
105
59
  } catch (cause) {
106
60
  const error = asPreviewSimulationError(cause, "multicall");
@@ -108,59 +62,6 @@ async function simulatePoolOperation(input, options = {}) {
108
62
  return { status: "failure", error };
109
63
  }
110
64
  }
111
- function balanceLegs(operation, wallet, previewAmount) {
112
- const { pool, receiver } = operation;
113
- switch (operation.operation) {
114
- case "Deposit":
115
- return [
116
- { address: wallet, token: operation.tokenIn, delta: -operation.assets },
117
- { address: receiver, token: pool, delta: previewAmount }
118
- ];
119
- case "Mint":
120
- return [
121
- { address: wallet, token: operation.tokenIn, delta: -previewAmount },
122
- { address: receiver, token: pool, delta: operation.shares }
123
- ];
124
- case "Withdraw":
125
- return [
126
- { address: operation.owner, token: pool, delta: -previewAmount },
127
- {
128
- address: receiver,
129
- token: operation.tokenOut,
130
- delta: operation.assets
131
- }
132
- ];
133
- case "Redeem":
134
- return [
135
- { address: operation.owner, token: pool, delta: -operation.shares },
136
- { address: receiver, token: operation.tokenOut, delta: previewAmount }
137
- ];
138
- }
139
- }
140
- function computePoolOpBalanceChanges(operation, wallet, previewAmount, before) {
141
- const byAddress = new AddressMap();
142
- for (const { address, token, delta } of balanceLegs(
143
- operation,
144
- wallet,
145
- previewAmount
146
- )) {
147
- const beforeBalance = before(token, address);
148
- const change = {
149
- token,
150
- before: beforeBalance,
151
- after: beforeBalance + delta,
152
- delta
153
- };
154
- const existing = byAddress.get(address);
155
- if (existing) {
156
- existing.changes.push(change);
157
- } else {
158
- byAddress.upsert(address, { address, changes: [change] });
159
- }
160
- }
161
- return byAddress.values();
162
- }
163
65
  export {
164
- computePoolOpBalanceChanges,
165
66
  simulatePoolOperation
166
67
  };
@@ -0,0 +1,6 @@
1
+ async function simulateRWAOperation(_input, _options) {
2
+ throw new Error("not yet implemented");
3
+ }
4
+ export {
5
+ simulateRWAOperation
6
+ };
@@ -54,17 +54,21 @@ class SecuritizeRWAFactory extends BaseContract {
54
54
  parseFunctionParamsV2(params, strict) {
55
55
  switch (params.functionName) {
56
56
  case "openCreditAccount": {
57
- const [creditManager, calls] = params.args;
57
+ const [creditManager, calls, tokensToRegister, signaturesToCache] = params.args;
58
58
  return {
59
59
  creditManager,
60
- calls: this.register.parseMultiCallV2([...calls], strict)
60
+ calls: this.register.parseMultiCallV2([...calls], strict),
61
+ tokensToRegister,
62
+ signaturesToCache
61
63
  };
62
64
  }
63
65
  case "multicall": {
64
- const [creditAccount, calls] = params.args;
66
+ const [creditAccount, calls, tokensToRegister, signaturesToCache] = params.args;
65
67
  return {
66
68
  creditAccount,
67
- calls: this.register.parseMultiCallV2([...calls], strict)
69
+ calls: this.register.parseMultiCallV2([...calls], strict),
70
+ tokensToRegister,
71
+ signaturesToCache
68
72
  };
69
73
  }
70
74
  default:
@@ -126,6 +130,12 @@ class SecuritizeRWAFactory extends BaseContract {
126
130
  })
127
131
  };
128
132
  }
133
+ /**
134
+ * {@inheritDoc IRWAFactory.getTokens}
135
+ */
136
+ getTokens() {
137
+ return this.dsTokens.map((t) => t.address);
138
+ }
129
139
  /**
130
140
  * {@inheritDoc IRWAFactory.getInvestor}
131
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,
@@ -32,7 +32,6 @@ class ZapperContract extends BaseContract {
32
32
  const { rawArgs } = parsed;
33
33
  const pool = this.pool;
34
34
  const zapper = this.address;
35
- const token = this.tokenIn.addr;
36
35
  const underlying = this.sdk.marketRegister.findByPool(pool).underlying;
37
36
  const receiver = rawArgs.receiver;
38
37
  if (parsed.functionName.startsWith("deposit")) {
@@ -42,7 +41,6 @@ class ZapperContract extends BaseContract {
42
41
  zapper,
43
42
  receiver,
44
43
  assets: rawArgs.tokenInAmount ?? value ?? 0n,
45
- token,
46
44
  underlying,
47
45
  referralCode: rawArgs.referralCode
48
46
  };
@@ -54,7 +52,6 @@ class ZapperContract extends BaseContract {
54
52
  zapper,
55
53
  receiver,
56
54
  shares: rawArgs.tokenOutAmount,
57
- token,
58
55
  underlying
59
56
  };
60
57
  }
@@ -18,10 +18,10 @@ export type HistoryAdapterExt = TraceAdapterExt & {
18
18
  export type HistoryFacadeMetadata = FacadeOperationMetadata & OperationMetadata;
19
19
  export type AdapterOperation = BaseAdapterOperation<HistoryAdapterExt>;
20
20
  export type InnerOperation = BaseInnerOperation<HistoryAdapterExt>;
21
- export type MulticallOperation = Omit<BaseMulticallOperation<HistoryAdapterExt>, "expectedBalanceChanges"> & OperationMetadata;
22
- export type OpenCreditAccountOperation = Omit<BaseOpenCreditAccountOperation<HistoryAdapterExt>, "expectedBalanceChanges"> & OperationMetadata;
23
- export type CloseCreditAccountOperation = Omit<BaseCloseCreditAccountOperation<HistoryAdapterExt>, "expectedBalanceChanges"> & OperationMetadata;
24
- export type LiquidateCreditAccountOperation = Omit<BaseLiquidateCreditAccountOperation<HistoryAdapterExt>, "expectedBalanceChanges"> & OperationMetadata;
21
+ export type MulticallOperation = BaseMulticallOperation<HistoryAdapterExt> & OperationMetadata;
22
+ export type OpenCreditAccountOperation = BaseOpenCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
23
+ export type CloseCreditAccountOperation = BaseCloseCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
24
+ export type LiquidateCreditAccountOperation = BaseLiquidateCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
25
25
  export type PartialLiquidationOperation = BasePartialLiquidationOperation & OperationMetadata;
26
26
  export type DirectTokenTransferOperation = BaseDirectTokenTransferOperation & OperationMetadata;
27
27
  export type OuterFacadeOperation = MulticallOperation | OpenCreditAccountOperation | CloseCreditAccountOperation | LiquidateCreditAccountOperation | PartialLiquidationOperation;
@@ -1,4 +1,3 @@
1
- export * from "./parse/index.js";
2
1
  export * from "./prerequisites/index.js";
3
- export * from "./simulate/index.js";
2
+ export * from "./preview/index.js";
4
3
  export * from "./trace/index.js";
@@ -1,6 +1,5 @@
1
1
  export * from "./classifyInnerOperations.js";
2
2
  export * from "./errors.js";
3
- export * from "./extractExpectedBalanceChanges.js";
4
3
  export * from "./parseFacadeOperationCalldata.js";
5
4
  export * from "./parseOperationCalldata.js";
6
5
  export * from "./parsePoolOperationCalldata.js";
@@ -1,23 +1,22 @@
1
- import { type Hex } from "viem";
2
- import { type OnchainSDK, type SecuritizeRWAFactory } from "../../sdk/index.js";
3
- import type { OuterFacadeOperation } from "./types.js";
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
4
  export interface ParseRWAFactoryOperationCalldataProps {
5
5
  sdk: OnchainSDK;
6
6
  /** Resolved RWA factory contract for the transaction target. */
7
- factory: SecuritizeRWAFactory;
7
+ factory: IRWAFactory;
8
8
  calldata: Hex;
9
9
  }
10
10
  /**
11
11
  * Decodes a RWA-factory entry-point call into the matching
12
- * {@link OuterFacadeOperation}.
12
+ * {@link RWAOperation}.
13
13
  *
14
14
  * RWA credit accounts are opened and managed through the market's RWA factory
15
- * (see `CreditAccountsServiceV310`) rather than the credit facade, but the inner
16
- * `calls` share the credit-facade multicall shape, so classification is
15
+ * (see `CreditAccountsServiceV310`) rather than the credit facade, but the
16
+ * inner `calls` share the credit-facade multicall shape, so classification is
17
17
  * identical to {@link parseFacadeOperationCalldata}.
18
18
  *
19
- * The RWA factory calldata does not carry `onBehalfOf`, `referralCode` or the
20
- * new account address (all derived on-chain), so those are left as
21
- * `zeroAddress`/`0n`.
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`.
22
21
  */
23
- export declare function parseRWAFactoryOperationCalldata(props: ParseRWAFactoryOperationCalldataProps): OuterFacadeOperation;
22
+ export declare function parseRWAFactoryOperationCalldata(props: ParseRWAFactoryOperationCalldataProps): RWAOperation;
@@ -71,25 +71,10 @@ export interface FacadeOperationMetadata {
71
71
  creditManager: Address;
72
72
  creditFacade: Address;
73
73
  }
74
- /**
75
- * Signed token balance delta recovered from a router-generated
76
- * `storeExpectedBalances` call (the `BalanceDelta` struct). `amount` is the
77
- * signed `int256` delta, so it may be negative.
78
- */
79
- export interface ExpectedBalanceChange {
80
- token: Address;
81
- delta: bigint;
82
- }
83
74
  export interface MulticallOperation<Ext extends object = {}> extends FacadeOperationMetadata {
84
75
  operation: "MultiCall" | "BotMulticall";
85
76
  creditAccount: Address;
86
77
  multicall: InnerOperation<Ext>[];
87
- /**
88
- * Potential balance changes declared by a router-generated
89
- * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
90
- * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
91
- */
92
- expectedBalanceChanges?: ExpectedBalanceChange[];
93
78
  }
94
79
  export interface OpenCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
95
80
  operation: "OpenCreditAccount";
@@ -97,23 +82,11 @@ export interface OpenCreditAccountOperation<Ext extends object = {}> extends Fac
97
82
  onBehalfOf: Address;
98
83
  referralCode: bigint;
99
84
  multicall: InnerOperation<Ext>[];
100
- /**
101
- * Potential balance changes declared by a router-generated
102
- * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
103
- * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
104
- */
105
- expectedBalanceChanges?: ExpectedBalanceChange[];
106
85
  }
107
86
  export interface CloseCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
108
87
  operation: "CloseCreditAccount";
109
88
  creditAccount: Address;
110
89
  multicall: InnerOperation<Ext>[];
111
- /**
112
- * Potential balance changes declared by a router-generated
113
- * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
114
- * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
115
- */
116
- expectedBalanceChanges?: ExpectedBalanceChange[];
117
90
  }
118
91
  export interface LiquidateCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
119
92
  operation: "LiquidateCreditAccount";
@@ -122,12 +95,6 @@ export interface LiquidateCreditAccountOperation<Ext extends object = {}> extend
122
95
  token: Address;
123
96
  remainingFunds: bigint;
124
97
  multicall: InnerOperation<Ext>[];
125
- /**
126
- * Potential balance changes declared by a router-generated
127
- * `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
128
- * multicall is not router-shaped. See {@link ExpectedBalanceChange}.
129
- */
130
- expectedBalanceChanges?: ExpectedBalanceChange[];
131
98
  }
132
99
  export interface PartialLiquidationOperation extends FacadeOperationMetadata {
133
100
  operation: "PartiallyLiquidateCreditAccount";
@@ -23,6 +23,12 @@ export interface PoolDepositOperation {
23
23
  * deposits, or the zapper's input token for zapper-routed deposits.
24
24
  */
25
25
  tokenIn: Address;
26
+ /**
27
+ * Token minted to the receiver: the pool's diesel token for direct
28
+ * deposits, or the zapper's output token (e.g. a farmed/staked diesel
29
+ * wrapper) for zapper-routed deposits.
30
+ */
31
+ tokenOut: Address;
26
32
  /** Zapper contract the call is sent to; `undefined` for direct deposits. */
27
33
  zapper?: Address;
28
34
  /** Referral code, present only for `depositWithReferral` calls. */
@@ -48,6 +54,11 @@ export interface PoolMintOperation {
48
54
  * mints, or the zapper's input token for zapper-routed mints.
49
55
  */
50
56
  tokenIn: Address;
57
+ /**
58
+ * Token minted to the receiver: the pool's diesel token for direct mints,
59
+ * or the zapper's output token for zapper-routed mints.
60
+ */
61
+ tokenOut: Address;
51
62
  /** Zapper contract the call is sent to; `undefined` for direct mints. */
52
63
  zapper?: Address;
53
64
  /** Referral code, present only for `mintWithReferral` calls. */
@@ -71,6 +82,12 @@ export interface PoolWithdrawOperation {
71
82
  assets: bigint;
72
83
  /** Underlying token of the source pool. */
73
84
  underlying: Address;
85
+ /**
86
+ * Token burned from `owner`: the pool's diesel token for direct
87
+ * withdrawals, or the zapper's share-side token for zapper-routed
88
+ * withdrawals.
89
+ */
90
+ tokenIn: Address;
74
91
  /**
75
92
  * Token actually returned to the receiver: the pool underlying for direct
76
93
  * withdrawals, or the zapper's output token for zapper-routed withdrawals.
@@ -95,10 +112,20 @@ export interface PoolRedeemOperation {
95
112
  receiver: Address;
96
113
  /** Address whose pool shares are burned. */
97
114
  owner: Address;
98
- /** Pool shares (diesel) burned. */
115
+ /**
116
+ * Amount of {@link PoolRedeemOperation.tokenIn} burned: pool shares
117
+ * (diesel) for direct redeems, or the zapper's share-side token amount for
118
+ * zapper-routed redeems.
119
+ */
99
120
  shares: bigint;
100
121
  /** Underlying token of the source pool. */
101
122
  underlying: Address;
123
+ /**
124
+ * Token burned from `owner`: the pool's diesel token for direct redeems, or
125
+ * the zapper's share-side token (e.g. a farmed/staked diesel wrapper) for
126
+ * zapper-routed redeems.
127
+ */
128
+ tokenIn: Address;
102
129
  /**
103
130
  * Token actually returned to the receiver: the pool underlying for direct
104
131
  * redeems, or the zapper's output token for zapper-routed redeems.
@@ -113,3 +140,4 @@ export interface PoolRedeemOperation {
113
140
  * field).
114
141
  */
115
142
  export type PoolOperation = PoolDepositOperation | PoolMintOperation | PoolWithdrawOperation | PoolRedeemOperation;
143
+ export type PoolOperationType = PoolOperation["operation"];