@gearbox-protocol/sdk 14.12.0-next.1 → 14.12.0-next.3
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/abi/iZapper.js +62 -24
- package/dist/cjs/preview/parse/errors.js +5 -2
- package/dist/cjs/preview/parse/index.js +2 -0
- package/dist/cjs/preview/parse/parseOperationCalldata.js +38 -1
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +92 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +57 -10
- package/dist/cjs/preview/simulate/errors.js +0 -7
- package/dist/cjs/preview/simulate/index.js +0 -3
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +154 -29
- package/dist/cjs/sdk/MultichainSDK.js +1 -0
- package/dist/cjs/sdk/OnchainSDK.js +7 -3
- package/dist/cjs/sdk/market/MarketRegister.js +10 -5
- package/dist/cjs/sdk/market/ZapperRegister.js +54 -0
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +20 -0
- package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/ZapperContract.js +109 -0
- package/dist/cjs/sdk/market/zapper/createZapper.js +12 -4
- package/dist/cjs/{preview/simulate/constants.js → sdk/market/zapper/errors.js} +15 -6
- package/dist/cjs/sdk/market/zapper/index.js +6 -2
- package/dist/cjs/sdk/market/zapper/types.js +16 -0
- package/dist/cjs/sdk/options.js +41 -17
- package/dist/esm/abi/iZapper.js +62 -24
- package/dist/esm/preview/parse/errors.js +3 -1
- package/dist/esm/preview/parse/index.js +1 -0
- package/dist/esm/preview/parse/parseOperationCalldata.js +41 -2
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +71 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +57 -10
- package/dist/esm/preview/simulate/errors.js +0 -6
- package/dist/esm/preview/simulate/index.js +0 -2
- package/dist/esm/preview/simulate/simulatePoolOperation.js +155 -30
- package/dist/esm/sdk/MultichainSDK.js +1 -0
- package/dist/esm/sdk/OnchainSDK.js +7 -3
- package/dist/esm/sdk/market/MarketRegister.js +10 -5
- package/dist/esm/sdk/market/ZapperRegister.js +54 -0
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +23 -1
- package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/ZapperContract.js +85 -0
- package/dist/esm/sdk/market/zapper/createZapper.js +12 -4
- package/dist/esm/sdk/market/zapper/errors.js +13 -0
- package/dist/esm/sdk/market/zapper/index.js +3 -1
- package/dist/esm/sdk/market/zapper/types.js +0 -0
- package/dist/esm/sdk/options.js +39 -15
- package/dist/types/abi/iERC20Zapper.d.ts +91 -23
- package/dist/types/abi/iETHZapper.d.ts +91 -23
- package/dist/types/abi/iZapper.d.ts +91 -23
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +0 -2
- package/dist/types/preview/parse/errors.d.ts +1 -0
- package/dist/types/preview/parse/index.d.ts +1 -0
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +3 -3
- package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +23 -0
- package/dist/types/preview/parse/types-pools.d.ts +61 -1
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +1 -1
- package/dist/types/preview/simulate/errors.d.ts +6 -12
- package/dist/types/preview/simulate/index.d.ts +0 -1
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +22 -4
- package/dist/types/preview/simulate/types.d.ts +3 -16
- package/dist/types/sdk/MultichainSDK.d.ts +5 -0
- package/dist/types/sdk/OnchainSDK.d.ts +4 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +15 -6
- package/dist/types/sdk/market/ZapperRegister.d.ts +25 -4
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -1
- package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/ZapperContract.d.ts +35 -0
- package/dist/types/sdk/market/zapper/createZapper.d.ts +2 -4
- package/dist/types/sdk/market/zapper/errors.d.ts +10 -0
- package/dist/types/sdk/market/zapper/index.d.ts +3 -1
- package/dist/types/sdk/market/zapper/types.d.ts +64 -0
- package/dist/types/sdk/options.d.ts +10 -5
- package/dist/types/sdk/pools/types.d.ts +3 -3
- package/dist/types/sdk/types/state-human.d.ts +9 -0
- package/dist/types/sdk/types/state.d.ts +7 -0
- package/package.json +3 -3
- package/dist/cjs/preview/simulate/extractERC20Transfers.js +0 -47
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +0 -155
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +0 -106
- package/dist/cjs/sdk/market/zapper/Zapper.js +0 -47
- package/dist/esm/preview/simulate/constants.js +0 -4
- package/dist/esm/preview/simulate/extractERC20Transfers.js +0 -23
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +0 -130
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +0 -82
- package/dist/esm/sdk/market/zapper/Zapper.js +0 -23
- package/dist/types/preview/simulate/constants.d.ts +0 -6
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +0 -11
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +0 -28
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +0 -14
- package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -13
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { simulateCalls } from "viem/actions";
|
|
2
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
-
import { decodeSimulationError, PreviewSimulationError } from "./errors.js";
|
|
4
|
-
import { extractERC20Transfers } from "./extractERC20Transfers.js";
|
|
5
|
-
import { watchedHolders } from "./holders.js";
|
|
6
|
-
async function simulatePoolOpV1(input, options = {}) {
|
|
7
|
-
const { sdk, operation, to, calldata, wallet } = input;
|
|
8
|
-
const { blockNumber } = options;
|
|
9
|
-
const { underlying, pool } = operation;
|
|
10
|
-
const holders = watchedHolders(operation, wallet);
|
|
11
|
-
const tokens = [underlying, pool];
|
|
12
|
-
const balanceOf = (token, holder) => ({
|
|
13
|
-
to: token,
|
|
14
|
-
abi: ierc20Abi,
|
|
15
|
-
functionName: "balanceOf",
|
|
16
|
-
args: [holder]
|
|
17
|
-
});
|
|
18
|
-
const balanceCalls = holders.flatMap(
|
|
19
|
-
(holder) => tokens.map((token) => balanceOf(token, holder))
|
|
20
|
-
);
|
|
21
|
-
let results;
|
|
22
|
-
try {
|
|
23
|
-
({ results } = await simulateCalls(sdk.client, {
|
|
24
|
-
account: wallet,
|
|
25
|
-
// `undefined` lets viem simulate at `latest`; `blockNumber` is only set
|
|
26
|
-
// for testnet forks pinned to a specific block.
|
|
27
|
-
blockNumber,
|
|
28
|
-
calls: [...balanceCalls, { to, data: calldata }, ...balanceCalls]
|
|
29
|
-
}));
|
|
30
|
-
} catch (cause) {
|
|
31
|
-
throw new PreviewSimulationError([
|
|
32
|
-
{
|
|
33
|
-
source: "eth_simulateV1",
|
|
34
|
-
detail: decodeSimulationError({
|
|
35
|
-
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
|
-
const sim = results;
|
|
41
|
-
const txIndex = balanceCalls.length;
|
|
42
|
-
const afterOffset = txIndex + 1;
|
|
43
|
-
const txResult = sim[txIndex];
|
|
44
|
-
if (!txResult || txResult.status === "failure") {
|
|
45
|
-
throw new PreviewSimulationError([
|
|
46
|
-
{
|
|
47
|
-
source: "eth_simulateV1",
|
|
48
|
-
detail: decodeSimulationError({
|
|
49
|
-
error: txResult?.error,
|
|
50
|
-
data: txResult?.data
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
]);
|
|
54
|
-
}
|
|
55
|
-
const balanceChanges = [];
|
|
56
|
-
for (const [holderIndex, address] of holders.entries()) {
|
|
57
|
-
const changes = [];
|
|
58
|
-
for (const [tokenIndex, token] of tokens.entries()) {
|
|
59
|
-
const slot = holderIndex * tokens.length + tokenIndex;
|
|
60
|
-
const before = readBalance(sim[slot]);
|
|
61
|
-
const after = readBalance(sim[afterOffset + slot]);
|
|
62
|
-
const delta = after - before;
|
|
63
|
-
const magnitude = delta >= 0n ? delta : -delta;
|
|
64
|
-
if (magnitude > 1n) {
|
|
65
|
-
changes.push({ token, before, after, delta });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (changes.length > 0) {
|
|
69
|
-
balanceChanges.push({ address, changes });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
transfers: extractERC20Transfers(txResult.logs ?? [], holders),
|
|
74
|
-
balanceChanges
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function readBalance(result) {
|
|
78
|
-
return result?.status === "success" ? result.result : 0n;
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
simulatePoolOpV1
|
|
82
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { bytes32ToString } from "../../utils/index.js";
|
|
2
|
-
class Zapper {
|
|
3
|
-
pool;
|
|
4
|
-
type;
|
|
5
|
-
baseParams;
|
|
6
|
-
tokenIn;
|
|
7
|
-
tokenOut;
|
|
8
|
-
contractType;
|
|
9
|
-
constructor(data) {
|
|
10
|
-
this.pool = data.pool;
|
|
11
|
-
this.type = data.type;
|
|
12
|
-
this.baseParams = data.baseParams;
|
|
13
|
-
this.tokenIn = data.tokenIn;
|
|
14
|
-
this.tokenOut = data.tokenOut;
|
|
15
|
-
this.contractType = Zapper.contractType(data.baseParams);
|
|
16
|
-
}
|
|
17
|
-
static contractType(baseParams) {
|
|
18
|
-
return bytes32ToString(baseParams.contractType);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
Zapper
|
|
23
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { NetworkType } from "../../sdk/chain/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Networks where the `eth_simulateV1` JSON-RPC method is available and usable
|
|
4
|
-
* for pool or credit account operation simulation.
|
|
5
|
-
**/
|
|
6
|
-
export declare const ETH_SIMULATE_V1_NETWORKS: ReadonlySet<NetworkType>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Address, type Log } from "viem";
|
|
2
|
-
import type { TokenTransfer } from "../parse/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Parses ERC-20 `Transfer` logs and keeps only those involving one of the
|
|
5
|
-
* watched addresses (as sender or receiver). A log that touches several watched
|
|
6
|
-
* addresses is still emitted once.
|
|
7
|
-
*
|
|
8
|
-
* @param logs - raw logs from the simulated call
|
|
9
|
-
* @param watch - addresses whose transfers we care about (e.g. wallet + recipient)
|
|
10
|
-
*/
|
|
11
|
-
export declare function extractERC20Transfers(logs: Log[], watch: Address[]): TokenTransfer[];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { PoolOperation } from "../parse/index.js";
|
|
3
|
-
import type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulationInput, PoolOperationSimulationResult } from "./types.js";
|
|
4
|
-
/** Reads a watched holder's "before" balance of a token. */
|
|
5
|
-
export type BalanceLookup = (token: Address, holder: Address) => bigint;
|
|
6
|
-
/**
|
|
7
|
-
* Multicall pool-operation flow, used where `eth_simulateV1` is unavailable or
|
|
8
|
-
* as a fallback alongside it.
|
|
9
|
-
*
|
|
10
|
-
* Reads the watched holders' "before" balances together with the matching
|
|
11
|
-
* ERC4626 preview (`previewDeposit`/`previewMint`/`previewWithdraw`/
|
|
12
|
-
* `previewRedeem`) in a single multicall, then computes the theoretical balance
|
|
13
|
-
* changes via {@link computePoolOpBalanceChanges}.
|
|
14
|
-
*
|
|
15
|
-
* Unlike the `eth_simulateV1` flow it does not execute the calldata, so it
|
|
16
|
-
* cannot recover ERC-20 transfers (`transfers` is always `undefined`) and it
|
|
17
|
-
* ignores balance/allowance prerequisites (preview reads succeed regardless).
|
|
18
|
-
*
|
|
19
|
-
* @throws {@link PreviewSimulationError} when the multicall round-trip throws or
|
|
20
|
-
* any call (a balance read or the preview read) reverts.
|
|
21
|
-
*/
|
|
22
|
-
export declare function simulatePoolOpMulticall(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulationResult>;
|
|
23
|
-
/**
|
|
24
|
-
* Pure computation of {@link AddressBalanceChanges} for a pool operation from
|
|
25
|
-
* its ERC4626 preview result and the watched holders' "before" balances. Legs
|
|
26
|
-
* sharing the same address are grouped together.
|
|
27
|
-
*/
|
|
28
|
-
export declare function computePoolOpBalanceChanges(operation: PoolOperation, wallet: Address, previewAmount: bigint, before: BalanceLookup): AddressBalanceChanges[];
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { OperationSimulationOptions, PoolOperationSimulationInput, PoolOperationSimulationResult } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* `eth_simulateV1` pool-operation flow.
|
|
4
|
-
*
|
|
5
|
-
* Sandwiches the raw calldata between `balanceOf` reads of the underlying and
|
|
6
|
-
* pool (share) tokens for every watched holder, then derives the balance changes
|
|
7
|
-
* from the before/after diff and the wallet-relevant ERC-20 transfers from the
|
|
8
|
-
* emitted logs. Simulation runs against real chain state (no overrides), so an
|
|
9
|
-
* unmet prerequisite surfaces here as a revert.
|
|
10
|
-
*
|
|
11
|
-
* @throws {@link PreviewSimulationError} when the round-trip throws or the
|
|
12
|
-
* simulated transaction reverts.
|
|
13
|
-
*/
|
|
14
|
-
export declare function simulatePoolOpV1(input: PoolOperationSimulationInput, options?: OperationSimulationOptions): Promise<PoolOperationSimulationResult>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { BaseParams } from "../../base/types.js";
|
|
3
|
-
import type { ZapperData } from "../types.js";
|
|
4
|
-
export declare class Zapper implements ZapperData {
|
|
5
|
-
readonly pool: Address;
|
|
6
|
-
readonly type: "migration" | "rwa" | "base";
|
|
7
|
-
readonly baseParams: ZapperData["baseParams"];
|
|
8
|
-
readonly tokenIn: ZapperData["tokenIn"];
|
|
9
|
-
readonly tokenOut: ZapperData["tokenOut"];
|
|
10
|
-
readonly contractType: string;
|
|
11
|
-
constructor(data: ZapperData);
|
|
12
|
-
static contractType(baseParams: BaseParams): string;
|
|
13
|
-
}
|