@gearbox-protocol/sdk 14.12.0-next.4 → 14.12.0-next.6
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 -2
- 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 -1
- 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 -1
- 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,26 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
-
import type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
|
|
4
|
-
/** Reads a watched holder's "before" balance of a token. */
|
|
5
|
-
export type BalanceLookup = (token: Address, holder: Address) => bigint;
|
|
1
|
+
import type { OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput } from "./types.js";
|
|
6
2
|
/**
|
|
7
3
|
* Simulates a pool deposit/mint/withdraw/redeem (direct or zapper-routed) and
|
|
8
|
-
* returns the resulting
|
|
4
|
+
* returns the resulting token amounts going in and out, or a decoded failure.
|
|
9
5
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* {@link computePoolOpBalanceChanges}. It works on every network the SDK
|
|
15
|
-
* supports.
|
|
6
|
+
* Performs the matching preview read (the pool's ERC4626
|
|
7
|
+
* `previewDeposit`/`previewMint`/`previewWithdraw`/`previewRedeem`, or the
|
|
8
|
+
* zapper's `previewDeposit`/`previewRedeem`) to convert the calldata-known
|
|
9
|
+
* amount into its counterpart. It works on every network the SDK supports.
|
|
16
10
|
*
|
|
17
11
|
* It does not execute the calldata, so it ignores balance/allowance
|
|
18
12
|
* prerequisites (preview reads succeed regardless).
|
|
19
13
|
*/
|
|
20
14
|
export declare function simulatePoolOperation(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulation>;
|
|
21
|
-
/**
|
|
22
|
-
* Pure computation of {@link AddressBalanceChanges} for a pool operation from
|
|
23
|
-
* its preview result and the watched holders' "before" balances. Legs sharing
|
|
24
|
-
* the same address are grouped together.
|
|
25
|
-
*/
|
|
26
|
-
export declare function computePoolOpBalanceChanges(operation: PoolOperation, wallet: Address, previewAmount: bigint, before: BalanceLookup): AddressBalanceChanges[];
|
|
@@ -11,8 +11,6 @@ export interface SimulateRWAOperationInput {
|
|
|
11
11
|
to: Address;
|
|
12
12
|
/** Raw RWA-factory 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 an RWA-factory operation.
|
|
@@ -3,25 +3,6 @@ import type { OnchainSDK } from "../../sdk/index.js";
|
|
|
3
3
|
import type { ILogger } from "../../sdk/types/logger.js";
|
|
4
4
|
import type { PoolOperation } from "../parse/index.js";
|
|
5
5
|
import type { PreviewSimulationError } from "./errors.js";
|
|
6
|
-
/**
|
|
7
|
-
* Change in an address's balance of a single token over the simulated call.
|
|
8
|
-
* `delta` is `after - before` (negative when the address spent the token).
|
|
9
|
-
*/
|
|
10
|
-
export interface TokenBalanceChange {
|
|
11
|
-
token: Address;
|
|
12
|
-
before: bigint;
|
|
13
|
-
after: bigint;
|
|
14
|
-
delta: bigint;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Balance changes for a single watched address (e.g. the wallet or the
|
|
18
|
-
* operation recipient). Keyed purely by address; UI labeling is resolved
|
|
19
|
-
* separately by the presentation layer.
|
|
20
|
-
*/
|
|
21
|
-
export interface AddressBalanceChanges {
|
|
22
|
-
address: Address;
|
|
23
|
-
changes: TokenBalanceChange[];
|
|
24
|
-
}
|
|
25
6
|
export interface PoolOperationSimulationInput {
|
|
26
7
|
/** Only `client`/`networkType` are used, so any OnchainSDK works. */
|
|
27
8
|
sdk: OnchainSDK;
|
|
@@ -31,8 +12,6 @@ export interface PoolOperationSimulationInput {
|
|
|
31
12
|
to: Address;
|
|
32
13
|
/** Raw deposit/mint/withdraw/redeem calldata to simulate. */
|
|
33
14
|
calldata: Hex;
|
|
34
|
-
/** Wallet whose balance changes and transfers we track. */
|
|
35
|
-
wallet: Address;
|
|
36
15
|
}
|
|
37
16
|
export interface OperationSimulationOptions {
|
|
38
17
|
/** Block to simulate at; defaults to latest. */
|
|
@@ -43,15 +22,22 @@ export interface OperationSimulationOptions {
|
|
|
43
22
|
logger?: ILogger;
|
|
44
23
|
}
|
|
45
24
|
/**
|
|
46
|
-
* Successful simulation of a pool operation: the
|
|
47
|
-
*
|
|
48
|
-
* {@link PoolOperationSimulation}
|
|
25
|
+
* Successful simulation of a pool operation: the amounts of tokens going in
|
|
26
|
+
* and out. One side comes from calldata, the other from the matching ERC4626
|
|
27
|
+
* preview read. This is the success payload of {@link PoolOperationSimulation}
|
|
28
|
+
* without the `status` discriminant.
|
|
49
29
|
*/
|
|
50
30
|
export interface PoolOperationSimulationResult {
|
|
51
31
|
/**
|
|
52
|
-
*
|
|
32
|
+
* Amount of tokens going from the user to the pool (underlying or zapper
|
|
33
|
+
* input token for deposit/mint, pool shares for withdraw/redeem).
|
|
34
|
+
**/
|
|
35
|
+
amountIn: bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Amount of tokens going from the pool to the user (pool shares or zapper
|
|
38
|
+
* output token for deposit/mint, underlying for withdraw/redeem).
|
|
53
39
|
**/
|
|
54
|
-
|
|
40
|
+
amountOut: bigint;
|
|
55
41
|
}
|
|
56
42
|
/**
|
|
57
43
|
* Outcome of simulating a pool operation. On success it carries a
|
|
@@ -12,10 +12,8 @@ export interface ParsedZapperDeposit {
|
|
|
12
12
|
/** Zapper contract the call is sent to. */
|
|
13
13
|
zapper: Address;
|
|
14
14
|
receiver: Address;
|
|
15
|
-
/** Amount of `
|
|
15
|
+
/** Amount of `tokenIn` supplied to the zapper. */
|
|
16
16
|
assets: bigint;
|
|
17
|
-
/** Token actually deposited into the zapper (the zapper's `tokenIn`). */
|
|
18
|
-
token: Address;
|
|
19
17
|
/** Underlying token of the destination pool. */
|
|
20
18
|
underlying: Address;
|
|
21
19
|
/** Referral code, present only for `depositWithReferral(...)` calls. */
|
|
@@ -32,10 +30,12 @@ export interface ParsedZapperRedeem {
|
|
|
32
30
|
/** Zapper contract the call is sent to. */
|
|
33
31
|
zapper: Address;
|
|
34
32
|
receiver: Address;
|
|
35
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Amount of the zapper's `tokenOut` burned. This is the pool's diesel token
|
|
35
|
+
* only when the zapper's `tokenOut` is the pool itself; for farmed/staked
|
|
36
|
+
* wrappers it's denominated in the wrapper token.
|
|
37
|
+
*/
|
|
36
38
|
shares: bigint;
|
|
37
|
-
/** Token returned to the receiver (the zapper's `tokenIn`). */
|
|
38
|
-
token: Address;
|
|
39
39
|
/** Underlying token of the source pool. */
|
|
40
40
|
underlying: Address;
|
|
41
41
|
}
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AddressSet } from "../../sdk/index.js";
|
|
2
|
-
function sourceHolder(operation, wallet) {
|
|
3
|
-
switch (operation.operation) {
|
|
4
|
-
case "Deposit":
|
|
5
|
-
case "Mint":
|
|
6
|
-
return wallet;
|
|
7
|
-
case "Withdraw":
|
|
8
|
-
case "Redeem":
|
|
9
|
-
return operation.owner;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function watchedHolders(operation, wallet) {
|
|
13
|
-
const holders = new AddressSet([
|
|
14
|
-
sourceHolder(operation, wallet),
|
|
15
|
-
operation.receiver
|
|
16
|
-
]);
|
|
17
|
-
return holders.asArray();
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
watchedHolders
|
|
21
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Distinct addresses whose balances change during the operation: the funds
|
|
5
|
-
* source (payer or share owner) and the receiver.
|
|
6
|
-
*/
|
|
7
|
-
export declare function watchedHolders(operation: PoolOperation, wallet: Address): Address[];
|