@gearbox-protocol/sdk 14.12.0-next.1 → 14.12.0-next.2
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/parseOperationCalldata.js +30 -1
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +34 -0
- 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/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/parseOperationCalldata.js +32 -2
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +34 -0
- 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/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/errors.d.ts +1 -0
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +3 -3
- package/dist/types/preview/parse/types-pools.d.ts +61 -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/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,5 +1,5 @@
|
|
|
1
1
|
import type { Abi, Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IZapperContract } from "../market/index.js";
|
|
3
3
|
import type { Asset } from "../router/index.js";
|
|
4
4
|
import type { MultiCall, RawTx } from "../types/transactions.js";
|
|
5
5
|
interface PermitResult {
|
|
@@ -62,7 +62,7 @@ export interface DepositMetadata {
|
|
|
62
62
|
/**
|
|
63
63
|
* Zapper that will perform the deposit, undefined in case of direct pool underlying deposit
|
|
64
64
|
*/
|
|
65
|
-
zapper?:
|
|
65
|
+
zapper?: IZapperContract;
|
|
66
66
|
/**
|
|
67
67
|
* Before deposit user will nedd to call approve method on token that he wants to deposit,
|
|
68
68
|
* this is the spender address that will be used to call approve method.
|
|
@@ -82,7 +82,7 @@ export interface WithdrawalMetadata {
|
|
|
82
82
|
/**
|
|
83
83
|
* Zapper that will perform the withdrawal, undefined in case of direct pool underlying withdrawal
|
|
84
84
|
*/
|
|
85
|
-
zapper?:
|
|
85
|
+
zapper?: IZapperContract;
|
|
86
86
|
/**
|
|
87
87
|
* Before withdrawal user will need to call approve method on token that he wants to withdraw (diesel token),
|
|
88
88
|
* this is the spender address that will be used to call approve method.
|
|
@@ -193,6 +193,14 @@ export interface MarketStateHuman {
|
|
|
193
193
|
unpausableAdmins: string[];
|
|
194
194
|
emergencyLiquidators: string[];
|
|
195
195
|
}
|
|
196
|
+
export interface ZapperStateHuman {
|
|
197
|
+
address: string;
|
|
198
|
+
contractType: string;
|
|
199
|
+
type: "migration" | "rwa" | "base";
|
|
200
|
+
pool: string;
|
|
201
|
+
tokenIn: string;
|
|
202
|
+
tokenOut: string;
|
|
203
|
+
}
|
|
196
204
|
export interface GearboxStateHuman {
|
|
197
205
|
network: string;
|
|
198
206
|
block: number;
|
|
@@ -202,6 +210,7 @@ export interface GearboxStateHuman {
|
|
|
202
210
|
plugins: Record<string, unknown>;
|
|
203
211
|
tokens: TokenMetaData[];
|
|
204
212
|
rwa: RWAStateHuman;
|
|
213
|
+
zappers?: ZapperStateHuman[];
|
|
205
214
|
}
|
|
206
215
|
/**
|
|
207
216
|
* Human-readable state for all chains managed by {@link MultichainSDK}.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MarketData } from "../base/index.js";
|
|
2
2
|
import type { NetworkType } from "../chain/chains.js";
|
|
3
3
|
import type { AddressProviderState } from "../core/index.js";
|
|
4
|
+
import type { ZapperData } from "../market/index.js";
|
|
4
5
|
import type { RWAState } from "../market/rwa/index.js";
|
|
5
6
|
import type { PluginStatesMap, PluginsMap } from "../plugins/index.js";
|
|
6
7
|
/**
|
|
@@ -45,6 +46,12 @@ export interface GearboxState<Plugins extends PluginsMap = {}> {
|
|
|
45
46
|
* RWA compressor state snapshot, if RWA factories were loaded.
|
|
46
47
|
**/
|
|
47
48
|
rwa?: RWAState;
|
|
49
|
+
/**
|
|
50
|
+
* All loaded zappers, keyed implicitly by their `pool` field.
|
|
51
|
+
*
|
|
52
|
+
* Present only when zappers were loaded (they are optional)
|
|
53
|
+
**/
|
|
54
|
+
zappers?: ZapperData[];
|
|
48
55
|
/**
|
|
49
56
|
* Per-plugin serialised state.
|
|
50
57
|
**/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "14.12.0-next.
|
|
3
|
+
"version": "14.12.0-next.2",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"clean": "rm -rf dist",
|
|
68
68
|
"build": "tsup",
|
|
69
69
|
"dev": "tsup --watch",
|
|
70
|
-
"example": "tsx
|
|
70
|
+
"example": "tsx scripts/example.ts | pino-pretty",
|
|
71
71
|
"test:watch": "vitest --project unit",
|
|
72
72
|
"test:unit": "vitest run --project unit",
|
|
73
73
|
"test:e2e": "vitest run --project e2e",
|
|
74
74
|
"test:all": "vitest run",
|
|
75
75
|
"test": "vitest run",
|
|
76
|
-
"generate:e2e": "NODE_OPTIONS='--max-old-space-size=8192' tsx
|
|
76
|
+
"generate:e2e": "NODE_OPTIONS='--max-old-space-size=8192' tsx scripts/generate-e2e-fixtures.ts",
|
|
77
77
|
"prepare": "husky",
|
|
78
78
|
"check": "biome check --write",
|
|
79
79
|
"check:ci": "biome check --diagnostic-level=error",
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var extractERC20Transfers_exports = {};
|
|
20
|
-
__export(extractERC20Transfers_exports, {
|
|
21
|
-
extractERC20Transfers: () => extractERC20Transfers
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(extractERC20Transfers_exports);
|
|
24
|
-
var import_viem = require("viem");
|
|
25
|
-
var import_iERC20 = require("../../abi/iERC20.js");
|
|
26
|
-
function extractERC20Transfers(logs, watch) {
|
|
27
|
-
const parsed = (0, import_viem.parseEventLogs)({
|
|
28
|
-
abi: import_iERC20.ierc20Abi,
|
|
29
|
-
eventName: "Transfer",
|
|
30
|
-
logs
|
|
31
|
-
});
|
|
32
|
-
const transfers = [];
|
|
33
|
-
for (const log of parsed) {
|
|
34
|
-
const { from, to, value } = log.args;
|
|
35
|
-
const involved = watch.some(
|
|
36
|
-
(address) => (0, import_viem.isAddressEqual)(from, address) || (0, import_viem.isAddressEqual)(to, address)
|
|
37
|
-
);
|
|
38
|
-
if (involved) {
|
|
39
|
-
transfers.push({ token: log.address, amount: value, from, to });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return transfers;
|
|
43
|
-
}
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {
|
|
46
|
-
extractERC20Transfers
|
|
47
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var simulatePoolOpMulticall_exports = {};
|
|
20
|
-
__export(simulatePoolOpMulticall_exports, {
|
|
21
|
-
computePoolOpBalanceChanges: () => computePoolOpBalanceChanges,
|
|
22
|
-
simulatePoolOpMulticall: () => simulatePoolOpMulticall
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(simulatePoolOpMulticall_exports);
|
|
25
|
-
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
-
var import_iERC20 = require("../../abi/iERC20.js");
|
|
27
|
-
var import_sdk = require("../../sdk/index.js");
|
|
28
|
-
var import_errors = require("./errors.js");
|
|
29
|
-
var import_holders = require("./holders.js");
|
|
30
|
-
function previewRead(operation) {
|
|
31
|
-
switch (operation.operation) {
|
|
32
|
-
case "Deposit":
|
|
33
|
-
return { functionName: "previewDeposit", amount: operation.assets };
|
|
34
|
-
case "Mint":
|
|
35
|
-
return { functionName: "previewMint", amount: operation.shares };
|
|
36
|
-
case "Withdraw":
|
|
37
|
-
return { functionName: "previewWithdraw", amount: operation.assets };
|
|
38
|
-
case "Redeem":
|
|
39
|
-
return { functionName: "previewRedeem", amount: operation.shares };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async function simulatePoolOpMulticall(input, options = {}) {
|
|
43
|
-
const { sdk, operation, wallet } = input;
|
|
44
|
-
const { blockNumber } = options;
|
|
45
|
-
const { underlying, pool } = operation;
|
|
46
|
-
const holders = (0, import_holders.watchedHolders)(operation, wallet);
|
|
47
|
-
const tokens = [underlying, pool];
|
|
48
|
-
const balanceCalls = holders.flatMap(
|
|
49
|
-
(holder) => tokens.map((token) => ({ holder, token }))
|
|
50
|
-
);
|
|
51
|
-
const balanceContracts = balanceCalls.map(
|
|
52
|
-
({ holder, token }) => ({
|
|
53
|
-
address: token,
|
|
54
|
-
abi: import_iERC20.ierc20Abi,
|
|
55
|
-
functionName: "balanceOf",
|
|
56
|
-
args: [holder]
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
const { functionName, amount } = previewRead(operation);
|
|
60
|
-
const previewContract = {
|
|
61
|
-
address: pool,
|
|
62
|
-
abi: import_generated.iPoolV310Abi,
|
|
63
|
-
functionName,
|
|
64
|
-
args: [amount]
|
|
65
|
-
};
|
|
66
|
-
let results;
|
|
67
|
-
try {
|
|
68
|
-
results = await sdk.client.multicall({
|
|
69
|
-
allowFailure: false,
|
|
70
|
-
// `undefined` lets viem read at `latest`; `blockNumber` is only set for
|
|
71
|
-
// testnet forks pinned to a specific block.
|
|
72
|
-
blockNumber,
|
|
73
|
-
contracts: [...balanceContracts, previewContract]
|
|
74
|
-
});
|
|
75
|
-
} catch (cause) {
|
|
76
|
-
throw new import_errors.PreviewSimulationError([
|
|
77
|
-
{
|
|
78
|
-
source: "multicall",
|
|
79
|
-
detail: (0, import_errors.decodeSimulationError)({
|
|
80
|
-
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
const previewAmount = results[balanceContracts.length];
|
|
86
|
-
const balances = new import_sdk.AddressMap();
|
|
87
|
-
for (const [i, { holder, token }] of balanceCalls.entries()) {
|
|
88
|
-
const tokenBalances = balances.get(holder) ?? new import_sdk.AddressMap();
|
|
89
|
-
tokenBalances.upsert(token, results[i]);
|
|
90
|
-
balances.upsert(holder, tokenBalances);
|
|
91
|
-
}
|
|
92
|
-
const before = (token, holder) => balances.get(holder)?.get(token) ?? 0n;
|
|
93
|
-
return {
|
|
94
|
-
balanceChanges: computePoolOpBalanceChanges(
|
|
95
|
-
operation,
|
|
96
|
-
wallet,
|
|
97
|
-
previewAmount,
|
|
98
|
-
before
|
|
99
|
-
),
|
|
100
|
-
transfers: void 0
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function balanceLegs(operation, wallet, previewAmount) {
|
|
104
|
-
const { underlying, pool, receiver } = operation;
|
|
105
|
-
switch (operation.operation) {
|
|
106
|
-
case "Deposit":
|
|
107
|
-
return [
|
|
108
|
-
{ address: wallet, token: underlying, delta: -operation.assets },
|
|
109
|
-
{ address: receiver, token: pool, delta: previewAmount }
|
|
110
|
-
];
|
|
111
|
-
case "Mint":
|
|
112
|
-
return [
|
|
113
|
-
{ address: wallet, token: underlying, delta: -previewAmount },
|
|
114
|
-
{ address: receiver, token: pool, delta: operation.shares }
|
|
115
|
-
];
|
|
116
|
-
case "Withdraw":
|
|
117
|
-
return [
|
|
118
|
-
{ address: operation.owner, token: pool, delta: -previewAmount },
|
|
119
|
-
{ address: receiver, token: underlying, delta: operation.assets }
|
|
120
|
-
];
|
|
121
|
-
case "Redeem":
|
|
122
|
-
return [
|
|
123
|
-
{ address: operation.owner, token: pool, delta: -operation.shares },
|
|
124
|
-
{ address: receiver, token: underlying, delta: previewAmount }
|
|
125
|
-
];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function computePoolOpBalanceChanges(operation, wallet, previewAmount, before) {
|
|
129
|
-
const byAddress = new import_sdk.AddressMap();
|
|
130
|
-
for (const { address, token, delta } of balanceLegs(
|
|
131
|
-
operation,
|
|
132
|
-
wallet,
|
|
133
|
-
previewAmount
|
|
134
|
-
)) {
|
|
135
|
-
const beforeBalance = before(token, address);
|
|
136
|
-
const change = {
|
|
137
|
-
token,
|
|
138
|
-
before: beforeBalance,
|
|
139
|
-
after: beforeBalance + delta,
|
|
140
|
-
delta
|
|
141
|
-
};
|
|
142
|
-
const existing = byAddress.get(address);
|
|
143
|
-
if (existing) {
|
|
144
|
-
existing.changes.push(change);
|
|
145
|
-
} else {
|
|
146
|
-
byAddress.upsert(address, { address, changes: [change] });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return byAddress.values();
|
|
150
|
-
}
|
|
151
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
-
0 && (module.exports = {
|
|
153
|
-
computePoolOpBalanceChanges,
|
|
154
|
-
simulatePoolOpMulticall
|
|
155
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var simulatePoolOpV1_exports = {};
|
|
20
|
-
__export(simulatePoolOpV1_exports, {
|
|
21
|
-
simulatePoolOpV1: () => simulatePoolOpV1
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(simulatePoolOpV1_exports);
|
|
24
|
-
var import_actions = require("viem/actions");
|
|
25
|
-
var import_iERC20 = require("../../abi/iERC20.js");
|
|
26
|
-
var import_errors = require("./errors.js");
|
|
27
|
-
var import_extractERC20Transfers = require("./extractERC20Transfers.js");
|
|
28
|
-
var import_holders = require("./holders.js");
|
|
29
|
-
async function simulatePoolOpV1(input, options = {}) {
|
|
30
|
-
const { sdk, operation, to, calldata, wallet } = input;
|
|
31
|
-
const { blockNumber } = options;
|
|
32
|
-
const { underlying, pool } = operation;
|
|
33
|
-
const holders = (0, import_holders.watchedHolders)(operation, wallet);
|
|
34
|
-
const tokens = [underlying, pool];
|
|
35
|
-
const balanceOf = (token, holder) => ({
|
|
36
|
-
to: token,
|
|
37
|
-
abi: import_iERC20.ierc20Abi,
|
|
38
|
-
functionName: "balanceOf",
|
|
39
|
-
args: [holder]
|
|
40
|
-
});
|
|
41
|
-
const balanceCalls = holders.flatMap(
|
|
42
|
-
(holder) => tokens.map((token) => balanceOf(token, holder))
|
|
43
|
-
);
|
|
44
|
-
let results;
|
|
45
|
-
try {
|
|
46
|
-
({ results } = await (0, import_actions.simulateCalls)(sdk.client, {
|
|
47
|
-
account: wallet,
|
|
48
|
-
// `undefined` lets viem simulate at `latest`; `blockNumber` is only set
|
|
49
|
-
// for testnet forks pinned to a specific block.
|
|
50
|
-
blockNumber,
|
|
51
|
-
calls: [...balanceCalls, { to, data: calldata }, ...balanceCalls]
|
|
52
|
-
}));
|
|
53
|
-
} catch (cause) {
|
|
54
|
-
throw new import_errors.PreviewSimulationError([
|
|
55
|
-
{
|
|
56
|
-
source: "eth_simulateV1",
|
|
57
|
-
detail: (0, import_errors.decodeSimulationError)({
|
|
58
|
-
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
const sim = results;
|
|
64
|
-
const txIndex = balanceCalls.length;
|
|
65
|
-
const afterOffset = txIndex + 1;
|
|
66
|
-
const txResult = sim[txIndex];
|
|
67
|
-
if (!txResult || txResult.status === "failure") {
|
|
68
|
-
throw new import_errors.PreviewSimulationError([
|
|
69
|
-
{
|
|
70
|
-
source: "eth_simulateV1",
|
|
71
|
-
detail: (0, import_errors.decodeSimulationError)({
|
|
72
|
-
error: txResult?.error,
|
|
73
|
-
data: txResult?.data
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
78
|
-
const balanceChanges = [];
|
|
79
|
-
for (const [holderIndex, address] of holders.entries()) {
|
|
80
|
-
const changes = [];
|
|
81
|
-
for (const [tokenIndex, token] of tokens.entries()) {
|
|
82
|
-
const slot = holderIndex * tokens.length + tokenIndex;
|
|
83
|
-
const before = readBalance(sim[slot]);
|
|
84
|
-
const after = readBalance(sim[afterOffset + slot]);
|
|
85
|
-
const delta = after - before;
|
|
86
|
-
const magnitude = delta >= 0n ? delta : -delta;
|
|
87
|
-
if (magnitude > 1n) {
|
|
88
|
-
changes.push({ token, before, after, delta });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (changes.length > 0) {
|
|
92
|
-
balanceChanges.push({ address, changes });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
transfers: (0, import_extractERC20Transfers.extractERC20Transfers)(txResult.logs ?? [], holders),
|
|
97
|
-
balanceChanges
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function readBalance(result) {
|
|
101
|
-
return result?.status === "success" ? result.result : 0n;
|
|
102
|
-
}
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {
|
|
105
|
-
simulatePoolOpV1
|
|
106
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var Zapper_exports = {};
|
|
20
|
-
__export(Zapper_exports, {
|
|
21
|
-
Zapper: () => Zapper
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(Zapper_exports);
|
|
24
|
-
var import_utils = require("../../utils/index.js");
|
|
25
|
-
class Zapper {
|
|
26
|
-
pool;
|
|
27
|
-
type;
|
|
28
|
-
baseParams;
|
|
29
|
-
tokenIn;
|
|
30
|
-
tokenOut;
|
|
31
|
-
contractType;
|
|
32
|
-
constructor(data) {
|
|
33
|
-
this.pool = data.pool;
|
|
34
|
-
this.type = data.type;
|
|
35
|
-
this.baseParams = data.baseParams;
|
|
36
|
-
this.tokenIn = data.tokenIn;
|
|
37
|
-
this.tokenOut = data.tokenOut;
|
|
38
|
-
this.contractType = Zapper.contractType(data.baseParams);
|
|
39
|
-
}
|
|
40
|
-
static contractType(baseParams) {
|
|
41
|
-
return (0, import_utils.bytes32ToString)(baseParams.contractType);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {
|
|
46
|
-
Zapper
|
|
47
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isAddressEqual, parseEventLogs } from "viem";
|
|
2
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
-
function extractERC20Transfers(logs, watch) {
|
|
4
|
-
const parsed = parseEventLogs({
|
|
5
|
-
abi: ierc20Abi,
|
|
6
|
-
eventName: "Transfer",
|
|
7
|
-
logs
|
|
8
|
-
});
|
|
9
|
-
const transfers = [];
|
|
10
|
-
for (const log of parsed) {
|
|
11
|
-
const { from, to, value } = log.args;
|
|
12
|
-
const involved = watch.some(
|
|
13
|
-
(address) => isAddressEqual(from, address) || isAddressEqual(to, address)
|
|
14
|
-
);
|
|
15
|
-
if (involved) {
|
|
16
|
-
transfers.push({ token: log.address, amount: value, from, to });
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return transfers;
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
extractERC20Transfers
|
|
23
|
-
};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
|
-
import { AddressMap } from "../../sdk/index.js";
|
|
4
|
-
import { decodeSimulationError, PreviewSimulationError } from "./errors.js";
|
|
5
|
-
import { watchedHolders } from "./holders.js";
|
|
6
|
-
function previewRead(operation) {
|
|
7
|
-
switch (operation.operation) {
|
|
8
|
-
case "Deposit":
|
|
9
|
-
return { functionName: "previewDeposit", amount: operation.assets };
|
|
10
|
-
case "Mint":
|
|
11
|
-
return { functionName: "previewMint", amount: operation.shares };
|
|
12
|
-
case "Withdraw":
|
|
13
|
-
return { functionName: "previewWithdraw", amount: operation.assets };
|
|
14
|
-
case "Redeem":
|
|
15
|
-
return { functionName: "previewRedeem", amount: operation.shares };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function simulatePoolOpMulticall(input, options = {}) {
|
|
19
|
-
const { sdk, operation, wallet } = input;
|
|
20
|
-
const { blockNumber } = options;
|
|
21
|
-
const { underlying, pool } = operation;
|
|
22
|
-
const holders = watchedHolders(operation, wallet);
|
|
23
|
-
const tokens = [underlying, pool];
|
|
24
|
-
const balanceCalls = holders.flatMap(
|
|
25
|
-
(holder) => tokens.map((token) => ({ holder, token }))
|
|
26
|
-
);
|
|
27
|
-
const balanceContracts = balanceCalls.map(
|
|
28
|
-
({ holder, token }) => ({
|
|
29
|
-
address: token,
|
|
30
|
-
abi: ierc20Abi,
|
|
31
|
-
functionName: "balanceOf",
|
|
32
|
-
args: [holder]
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
const { functionName, amount } = previewRead(operation);
|
|
36
|
-
const previewContract = {
|
|
37
|
-
address: pool,
|
|
38
|
-
abi: iPoolV310Abi,
|
|
39
|
-
functionName,
|
|
40
|
-
args: [amount]
|
|
41
|
-
};
|
|
42
|
-
let results;
|
|
43
|
-
try {
|
|
44
|
-
results = await sdk.client.multicall({
|
|
45
|
-
allowFailure: false,
|
|
46
|
-
// `undefined` lets viem read at `latest`; `blockNumber` is only set for
|
|
47
|
-
// testnet forks pinned to a specific block.
|
|
48
|
-
blockNumber,
|
|
49
|
-
contracts: [...balanceContracts, previewContract]
|
|
50
|
-
});
|
|
51
|
-
} catch (cause) {
|
|
52
|
-
throw new PreviewSimulationError([
|
|
53
|
-
{
|
|
54
|
-
source: "multicall",
|
|
55
|
-
detail: decodeSimulationError({
|
|
56
|
-
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
]);
|
|
60
|
-
}
|
|
61
|
-
const previewAmount = results[balanceContracts.length];
|
|
62
|
-
const balances = new AddressMap();
|
|
63
|
-
for (const [i, { holder, token }] of balanceCalls.entries()) {
|
|
64
|
-
const tokenBalances = balances.get(holder) ?? new AddressMap();
|
|
65
|
-
tokenBalances.upsert(token, results[i]);
|
|
66
|
-
balances.upsert(holder, tokenBalances);
|
|
67
|
-
}
|
|
68
|
-
const before = (token, holder) => balances.get(holder)?.get(token) ?? 0n;
|
|
69
|
-
return {
|
|
70
|
-
balanceChanges: computePoolOpBalanceChanges(
|
|
71
|
-
operation,
|
|
72
|
-
wallet,
|
|
73
|
-
previewAmount,
|
|
74
|
-
before
|
|
75
|
-
),
|
|
76
|
-
transfers: void 0
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function balanceLegs(operation, wallet, previewAmount) {
|
|
80
|
-
const { underlying, pool, receiver } = operation;
|
|
81
|
-
switch (operation.operation) {
|
|
82
|
-
case "Deposit":
|
|
83
|
-
return [
|
|
84
|
-
{ address: wallet, token: underlying, delta: -operation.assets },
|
|
85
|
-
{ address: receiver, token: pool, delta: previewAmount }
|
|
86
|
-
];
|
|
87
|
-
case "Mint":
|
|
88
|
-
return [
|
|
89
|
-
{ address: wallet, token: underlying, delta: -previewAmount },
|
|
90
|
-
{ address: receiver, token: pool, delta: operation.shares }
|
|
91
|
-
];
|
|
92
|
-
case "Withdraw":
|
|
93
|
-
return [
|
|
94
|
-
{ address: operation.owner, token: pool, delta: -previewAmount },
|
|
95
|
-
{ address: receiver, token: underlying, delta: operation.assets }
|
|
96
|
-
];
|
|
97
|
-
case "Redeem":
|
|
98
|
-
return [
|
|
99
|
-
{ address: operation.owner, token: pool, delta: -operation.shares },
|
|
100
|
-
{ address: receiver, token: underlying, delta: previewAmount }
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function computePoolOpBalanceChanges(operation, wallet, previewAmount, before) {
|
|
105
|
-
const byAddress = new AddressMap();
|
|
106
|
-
for (const { address, token, delta } of balanceLegs(
|
|
107
|
-
operation,
|
|
108
|
-
wallet,
|
|
109
|
-
previewAmount
|
|
110
|
-
)) {
|
|
111
|
-
const beforeBalance = before(token, address);
|
|
112
|
-
const change = {
|
|
113
|
-
token,
|
|
114
|
-
before: beforeBalance,
|
|
115
|
-
after: beforeBalance + delta,
|
|
116
|
-
delta
|
|
117
|
-
};
|
|
118
|
-
const existing = byAddress.get(address);
|
|
119
|
-
if (existing) {
|
|
120
|
-
existing.changes.push(change);
|
|
121
|
-
} else {
|
|
122
|
-
byAddress.upsert(address, { address, changes: [change] });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return byAddress.values();
|
|
126
|
-
}
|
|
127
|
-
export {
|
|
128
|
-
computePoolOpBalanceChanges,
|
|
129
|
-
simulatePoolOpMulticall
|
|
130
|
-
};
|