@gearbox-protocol/sdk 14.12.0-next.4 → 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.
- package/dist/cjs/preview/index.js +2 -4
- package/dist/cjs/preview/parse/index.js +0 -2
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +5 -12
- package/dist/cjs/preview/parse/parseOperationCalldata.js +5 -3
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +4 -0
- package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +0 -4
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +19 -1
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +24 -15
- package/dist/cjs/preview/{simulate/holders.js → preview/errors.js} +12 -21
- package/dist/cjs/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
- package/dist/cjs/preview/preview/index.js +26 -0
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +99 -0
- package/dist/cjs/preview/preview/previewOperation.js +41 -0
- package/dist/cjs/preview/preview/previewPoolOperation.js +75 -0
- package/dist/cjs/preview/preview/types.js +16 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +20 -116
- package/dist/cjs/sdk/market/zapper/ZapperContract.js +0 -3
- package/dist/esm/preview/index.js +1 -2
- package/dist/esm/preview/parse/index.js +0 -1
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +5 -12
- package/dist/esm/preview/parse/parseOperationCalldata.js +5 -3
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +4 -0
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +0 -4
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +19 -1
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +28 -16
- package/dist/esm/preview/preview/errors.js +12 -0
- package/dist/esm/preview/{parse → preview}/extractExpectedBalanceChanges.js +1 -1
- package/dist/esm/preview/preview/index.js +3 -0
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +77 -0
- package/dist/esm/preview/preview/previewOperation.js +17 -0
- package/dist/esm/preview/preview/previewPoolOperation.js +53 -0
- package/dist/esm/preview/preview/types.js +0 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +21 -120
- package/dist/esm/sdk/market/zapper/ZapperContract.js +0 -3
- package/dist/types/history/types.d.ts +4 -4
- package/dist/types/preview/index.d.ts +1 -2
- package/dist/types/preview/parse/index.d.ts +0 -1
- package/dist/types/preview/parse/types-facades.d.ts +0 -33
- package/dist/types/preview/parse/types-pools.d.ts +29 -1
- package/dist/types/preview/parse/types-rwa.d.ts +1 -13
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +8 -3
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +15 -6
- package/dist/types/preview/preview/errors.d.ts +9 -0
- package/dist/types/preview/{parse → preview}/extractExpectedBalanceChanges.d.ts +4 -5
- package/dist/types/preview/preview/index.d.ts +3 -0
- package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +4 -0
- package/dist/types/preview/preview/previewOperation.d.ts +8 -0
- package/dist/types/preview/preview/previewPoolOperation.d.ts +5 -0
- package/dist/types/preview/preview/types.d.ts +103 -0
- package/dist/types/preview/simulate/index.d.ts +1 -1
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -2
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -2
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +6 -18
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +0 -2
- package/dist/types/preview/simulate/types.d.ts +12 -26
- package/dist/types/sdk/market/zapper/types.d.ts +6 -6
- package/package.json +1 -1
- package/dist/esm/preview/simulate/holders.js +0 -21
- package/dist/types/preview/simulate/holders.d.ts +0 -7
|
@@ -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 {
|
|
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
|
|
46
|
+
const { sdk, operation } = input;
|
|
52
47
|
const { blockNumber, logger } = options;
|
|
53
|
-
const { pool } = operation;
|
|
54
48
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
};
|
|
@@ -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 =
|
|
22
|
-
export type OpenCreditAccountOperation =
|
|
23
|
-
export type CloseCreditAccountOperation =
|
|
24
|
-
export type LiquidateCreditAccountOperation =
|
|
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,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";
|
|
@@ -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
|
-
/**
|
|
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"];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
import type { SecuritizeRegisterMessage } from "../../sdk/index.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { InnerOperation } from "./types-facades.js";
|
|
4
4
|
/**
|
|
5
5
|
* Metadata shared by all RWA factory operations. RWA credit accounts are
|
|
6
6
|
* opened and managed through the market's RWA factory rather than the credit
|
|
@@ -16,12 +16,6 @@ export interface RWAOperationMetadata {
|
|
|
16
16
|
export interface SecuritizeOpenCreditAccountOperation<Ext extends object = {}> extends RWAOperationMetadata {
|
|
17
17
|
operation: "SecuritizeOpenCreditAccount";
|
|
18
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
19
|
/**
|
|
26
20
|
* DSToken addresses to register, decoded from calldata. Empty in the
|
|
27
21
|
* template flow, where the real value comes from the factory's open-account
|
|
@@ -42,12 +36,6 @@ export interface SecuritizeMulticallOperation<Ext extends object = {}> extends R
|
|
|
42
36
|
operation: "SecuritizeMulticall";
|
|
43
37
|
creditAccount: Address;
|
|
44
38
|
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
39
|
/** DSToken addresses to register, decoded from calldata. */
|
|
52
40
|
tokensToRegister: Address[];
|
|
53
41
|
/** EIP-712 registration signatures to store on-chain, decoded from calldata. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Address, type ContractFunctionParameters } from "viem";
|
|
2
2
|
import { type MulticallCallResult, Prerequisite } from "./Prerequisite.js";
|
|
3
|
-
import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
|
|
3
|
+
import type { PrerequisiteContext, PrerequisiteDetail, PrerequisiteResult } from "./types.js";
|
|
4
4
|
export interface BalancePrerequisiteProps {
|
|
5
5
|
token: Address;
|
|
6
6
|
owner: Address;
|
|
@@ -8,7 +8,12 @@ export interface BalancePrerequisiteProps {
|
|
|
8
8
|
title?: string;
|
|
9
9
|
id?: string;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Checks that `owner` holds a token balance >= `required`. The token is read
|
|
13
|
+
* as an ERC-20, except for the native pseudo-address ({@link NATIVE_ADDRESS},
|
|
14
|
+
* e.g. ETH-zapper deposits) whose balance is read via multicall3's
|
|
15
|
+
* `getEthBalance`.
|
|
16
|
+
*/
|
|
12
17
|
export declare class BalancePrerequisite extends Prerequisite<"balance"> {
|
|
13
18
|
#private;
|
|
14
19
|
constructor(props: BalancePrerequisiteProps);
|
|
@@ -16,6 +21,6 @@ export declare class BalancePrerequisite extends Prerequisite<"balance"> {
|
|
|
16
21
|
get kind(): "balance";
|
|
17
22
|
get title(): string;
|
|
18
23
|
get detail(): PrerequisiteDetail<"balance">;
|
|
19
|
-
calls(): ContractFunctionParameters[];
|
|
24
|
+
calls(ctx: PrerequisiteContext): ContractFunctionParameters[];
|
|
20
25
|
resolve(slice: MulticallCallResult[]): PrerequisiteResult<"balance">;
|
|
21
26
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PluginsMap } from "../../sdk/index.js";
|
|
2
|
+
import { type ParseOperationCalldataInput } from "../parse/parseOperationCalldata.js";
|
|
2
3
|
import type { AnyPrerequisite } from "./Prerequisite.js";
|
|
3
|
-
import type { PrerequisiteContext } from "./types.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
5
|
+
* Input of {@link buildPrerequisites}: the same raw-calldata input as the
|
|
6
|
+
* internal calldata parser, plus an optional block to read at.
|
|
7
|
+
*/
|
|
8
|
+
export type BuildPrerequisitesInput<P extends PluginsMap = PluginsMap> = ParseOperationCalldataInput<P> & {
|
|
9
|
+
/** Block to read at; defaults to latest. Only set for testnet forks. */
|
|
10
|
+
blockNumber?: bigint;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Derives the on-chain prerequisites for an operation given its raw calldata:
|
|
14
|
+
* the conditions that must hold for the call not to revert and that we can
|
|
15
|
+
* verify with the SDK (token approvals, wallet balances). The calldata is
|
|
16
|
+
* decoded internally via `parseOperationCalldata`.
|
|
8
17
|
*
|
|
9
18
|
* Only *sender-actionable* prerequisites belong here: conditions the LP
|
|
10
19
|
* provider or borrower can fix themselves before retrying (e.g. approve a
|
|
@@ -13,4 +22,4 @@ import type { PrerequisiteContext } from "./types.js";
|
|
|
13
22
|
* bot permissions) is intentionally out of scope, since the user cannot
|
|
14
23
|
* resolve it. New {@link AnyPrerequisite} subclasses must follow the same rule.
|
|
15
24
|
*/
|
|
16
|
-
export declare function buildPrerequisites
|
|
25
|
+
export declare function buildPrerequisites<P extends PluginsMap>(input: BuildPrerequisitesInput<P>): Promise<AnyPrerequisite[]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown by `previewOperation` for parsed operations it cannot preview yet.
|
|
3
|
+
* Currently only pool operations and credit account opening are supported.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnsupportedOperationError extends Error {
|
|
6
|
+
/** The parsed operation kind (the `operation` discriminant). */
|
|
7
|
+
readonly operation: string;
|
|
8
|
+
constructor(operation: string);
|
|
9
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ParsedCallV2 } from "../../sdk/index.js";
|
|
2
|
-
import type { ExpectedBalanceChange } from "./types.js";
|
|
1
|
+
import type { Asset, ParsedCallV2 } from "../../sdk/index.js";
|
|
3
2
|
/**
|
|
4
3
|
* Recovers the potential balance changes declared by a router-generated
|
|
5
4
|
* `storeExpectedBalances`/`compareBalances` pair inside a credit-facade
|
|
@@ -13,10 +12,10 @@ import type { ExpectedBalanceChange } from "./types.js";
|
|
|
13
12
|
*
|
|
14
13
|
* When the multicall does not match this shape, `undefined` is returned. On a
|
|
15
14
|
* match, the `BalanceDelta[]` argument of `storeExpectedBalances` is decoded
|
|
16
|
-
* into {@link
|
|
17
|
-
*
|
|
15
|
+
* into {@link Asset}[] (the `balance` is the signed `int256` delta and may be
|
|
16
|
+
* negative).
|
|
18
17
|
*
|
|
19
18
|
* @param innerCalls - Raw (already-decoded) inner multicall calls.
|
|
20
19
|
* @returns The declared balance changes, or `undefined` when not router-shaped.
|
|
21
20
|
*/
|
|
22
|
-
export declare function extractExpectedBalanceChanges(innerCalls: ParsedCallV2[]):
|
|
21
|
+
export declare function extractExpectedBalanceChanges(innerCalls: ParsedCallV2[]): Asset[] | undefined;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PluginsMap } from "../../sdk/index.js";
|
|
2
|
+
import type { OpenCreditAccountOperation, SecuritizeOpenCreditAccountOperation } from "../parse/index.js";
|
|
3
|
+
import type { OpenCreditAccountPreview, PreviewOperationInput } from "./types.js";
|
|
4
|
+
export declare function previewOpenCreditAccount<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: OpenCreditAccountOperation | SecuritizeOpenCreditAccountOperation): OpenCreditAccountPreview;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PluginsMap } from "../../sdk/index.js";
|
|
2
|
+
import type { OperationSimulationOptions } from "../simulate/index.js";
|
|
3
|
+
import type { OperationPreview, PreviewOperationInput } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
6
|
+
* assembles an operation-specific, human-displayable preview.
|
|
7
|
+
*/
|
|
8
|
+
export declare function previewOperation<P extends PluginsMap = PluginsMap>(input: PreviewOperationInput<P>, options?: OperationSimulationOptions): Promise<OperationPreview>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PluginsMap } from "../../sdk/index.js";
|
|
2
|
+
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
+
import { type OperationSimulationOptions } from "../simulate/index.js";
|
|
4
|
+
import type { PoolOperationPreview, PreviewOperationInput } from "./types.js";
|
|
5
|
+
export declare function previewPoolOperation<P extends PluginsMap>(input: PreviewOperationInput<P>, operation: PoolOperation, options?: OperationSimulationOptions): Promise<PoolOperationPreview>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { Asset, PluginsMap } from "../../sdk/index.js";
|
|
3
|
+
import type { PoolOperationType, SdkWithAdapters } from "../parse/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Input of {@link previewOperation}: the raw operation calldata plus the
|
|
6
|
+
* already-attached SDK
|
|
7
|
+
*/
|
|
8
|
+
export interface PreviewOperationInput<P extends PluginsMap = PluginsMap> {
|
|
9
|
+
/**
|
|
10
|
+
* Already-attached SDK; chain, RPC and block are baked in at attach time.
|
|
11
|
+
* Must be created with the adapters plugin (enforced at compile time) so
|
|
12
|
+
* adapter contracts resolve during multicall classification.
|
|
13
|
+
*/
|
|
14
|
+
sdk: SdkWithAdapters<P>;
|
|
15
|
+
/**
|
|
16
|
+
* Contract address that was called
|
|
17
|
+
*/
|
|
18
|
+
to: Address;
|
|
19
|
+
/**
|
|
20
|
+
* Raw calldata of the operation
|
|
21
|
+
*/
|
|
22
|
+
calldata: Hex;
|
|
23
|
+
/**
|
|
24
|
+
* Transaction sender
|
|
25
|
+
*/
|
|
26
|
+
sender: Address;
|
|
27
|
+
/**
|
|
28
|
+
* Transaction `msg.value`
|
|
29
|
+
**/
|
|
30
|
+
value?: bigint;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A token amount that may require an additional async call (e.g. an ERC4626
|
|
34
|
+
* preview read) to determine. When that call fails, only the token address and
|
|
35
|
+
* the error are returned.
|
|
36
|
+
*/
|
|
37
|
+
export type PreviewedAsset = Asset | {
|
|
38
|
+
token: Address;
|
|
39
|
+
error: Error;
|
|
40
|
+
};
|
|
41
|
+
export interface PoolOperationPreview {
|
|
42
|
+
operation: PoolOperationType;
|
|
43
|
+
/**
|
|
44
|
+
* Pool address
|
|
45
|
+
*/
|
|
46
|
+
pool: Address;
|
|
47
|
+
/**
|
|
48
|
+
* Token that goes from user to pool
|
|
49
|
+
* In case of deposit, underlying for direct deposit, zapper input for zapper-routed deposit
|
|
50
|
+
* In case of withdraw, pool shares (diesel token) for direct withdraw or zapper token out
|
|
51
|
+
*
|
|
52
|
+
* For mint/withdraw the amount of tokenIn cannot be determined from
|
|
53
|
+
* transaction calldata alone and requires an additional async call
|
|
54
|
+
* (previewMint/previewWithdraw). In case of error only the token address is
|
|
55
|
+
* returned.
|
|
56
|
+
*/
|
|
57
|
+
tokenIn: PreviewedAsset;
|
|
58
|
+
/**
|
|
59
|
+
* Token that goes from pool to user
|
|
60
|
+
* In case of deposit, pool shares (diesel token) for direct deposit or zapper token out
|
|
61
|
+
* In case of withdraw, underlying for direct withdraw or zapper token in
|
|
62
|
+
*
|
|
63
|
+
* For deposit/redeem the amount of tokenOut cannot be determined from
|
|
64
|
+
* transaction calldata alone and requires an additional async call
|
|
65
|
+
* (previewDeposit/previewRedeem). In case of error only the token address is
|
|
66
|
+
* returned.
|
|
67
|
+
*/
|
|
68
|
+
tokenOut: PreviewedAsset;
|
|
69
|
+
}
|
|
70
|
+
export interface OpenCreditAccountPreview {
|
|
71
|
+
operation: "OpenCreditAccount" | "SecuritizeOpenCreditAccount";
|
|
72
|
+
/**
|
|
73
|
+
* Target token of strategy: the first quoted token, with its balance taken
|
|
74
|
+
* from `assets`. Undefined when nothing is quoted.
|
|
75
|
+
*/
|
|
76
|
+
target?: Asset;
|
|
77
|
+
/**
|
|
78
|
+
* Tokens that were added as collateral during account opening
|
|
79
|
+
*/
|
|
80
|
+
collateral: Asset[];
|
|
81
|
+
/**
|
|
82
|
+
* Sum of collateral tokens in underlying
|
|
83
|
+
*/
|
|
84
|
+
collateralValue: bigint;
|
|
85
|
+
/**
|
|
86
|
+
* Borrowed amount in underlying
|
|
87
|
+
*/
|
|
88
|
+
debt: bigint;
|
|
89
|
+
/**
|
|
90
|
+
* Desired quotas
|
|
91
|
+
*/
|
|
92
|
+
quotas: Asset[];
|
|
93
|
+
/**
|
|
94
|
+
* Minimum amount of assets on credit account after it's opened,
|
|
95
|
+
* as estimated by router
|
|
96
|
+
*/
|
|
97
|
+
assets: Asset[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Result of previewing a raw operation calldata: currently pool operations and
|
|
101
|
+
* credit account opening are supported.
|
|
102
|
+
*/
|
|
103
|
+
export type OperationPreview = PoolOperationPreview | OpenCreditAccountPreview;
|
|
@@ -7,4 +7,4 @@ export { simulateOperation } from "./simulateOperation.js";
|
|
|
7
7
|
export { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
8
8
|
export type { SimulateRWAOperationInput } from "./simulateRWAOperation.js";
|
|
9
9
|
export { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
10
|
-
export type {
|
|
10
|
+
export type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, } from "./types.js";
|
|
@@ -11,8 +11,6 @@ export interface SimulateFacadeOperationInput {
|
|
|
11
11
|
to: Address;
|
|
12
12
|
/** Raw credit-facade calldata to simulate. */
|
|
13
13
|
calldata: Hex;
|
|
14
|
-
/** Wallet whose balance changes and transfers we track. */
|
|
15
|
-
wallet: Address;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Simulates a credit-facade operation.
|
|
@@ -11,8 +11,6 @@ export interface SimulateOperationInput {
|
|
|
11
11
|
to: Address;
|
|
12
12
|
/** Raw operation calldata to simulate. */
|
|
13
13
|
calldata: Hex;
|
|
14
|
-
/** Wallet whose balance changes and transfers we track. */
|
|
15
|
-
wallet: Address;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Simulates a parsed pool or credit account operation {@link Operation}
|