@gearbox-protocol/sdk 14.11.0-next.6 → 14.11.0-next.7
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/parse/parsePoolOperationCalldata.js +21 -6
- package/dist/cjs/preview/parse/types.js +1 -1
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/cjs/preview/simulate/constants.js +28 -0
- package/dist/cjs/preview/simulate/{decodeSimulationError.js → errors.js} +37 -3
- package/dist/cjs/preview/simulate/holders.js +45 -0
- package/dist/cjs/preview/simulate/index.js +21 -13
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +1 -1
- package/dist/cjs/preview/simulate/simulateOperation.js +3 -3
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +155 -0
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +106 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +27 -62
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +21 -6
- package/dist/esm/preview/parse/types.js +1 -1
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/esm/preview/simulate/constants.js +4 -0
- package/dist/esm/preview/simulate/{decodeSimulationError.js → errors.js} +31 -0
- package/dist/esm/preview/simulate/holders.js +21 -0
- package/dist/esm/preview/simulate/index.js +12 -6
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +1 -1
- package/dist/esm/preview/simulate/simulateOperation.js +3 -3
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +130 -0
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +82 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +30 -62
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +4 -2
- package/dist/types/preview/parse/types-pools.d.ts +29 -16
- package/dist/types/preview/parse/types.d.ts +3 -3
- package/dist/types/preview/simulate/constants.d.ts +6 -0
- package/dist/types/preview/simulate/errors.d.ts +51 -0
- package/dist/types/preview/simulate/holders.d.ts +7 -0
- package/dist/types/preview/simulate/index.d.ts +9 -6
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +3 -5
- package/dist/types/preview/simulate/simulateOperation.d.ts +5 -11
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +28 -0
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +14 -0
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +5 -27
- package/dist/types/preview/simulate/types.d.ts +54 -18
- package/package.json +1 -1
- package/dist/types/preview/simulate/decodeSimulationError.d.ts +0 -18
|
@@ -37,9 +37,26 @@ function parsePoolOperationCalldata(props) {
|
|
|
37
37
|
receiver: rawArgs.receiver,
|
|
38
38
|
assets: rawArgs.assets,
|
|
39
39
|
underlying,
|
|
40
|
-
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
41
|
+
};
|
|
42
|
+
case "mint":
|
|
43
|
+
case "mintWithReferral":
|
|
44
|
+
return {
|
|
45
|
+
operation: "Mint",
|
|
46
|
+
pool: pool.address,
|
|
47
|
+
receiver: rawArgs.receiver,
|
|
48
|
+
shares: rawArgs.shares,
|
|
49
|
+
underlying,
|
|
50
|
+
referralCode: functionName === "mintWithReferral" ? rawArgs.referralCode : void 0
|
|
51
|
+
};
|
|
52
|
+
case "withdraw":
|
|
53
|
+
return {
|
|
54
|
+
operation: "Withdraw",
|
|
55
|
+
pool: pool.address,
|
|
56
|
+
receiver: rawArgs.receiver,
|
|
57
|
+
owner: rawArgs.owner,
|
|
58
|
+
assets: rawArgs.assets,
|
|
59
|
+
underlying
|
|
43
60
|
};
|
|
44
61
|
case "redeem":
|
|
45
62
|
return {
|
|
@@ -48,9 +65,7 @@ function parsePoolOperationCalldata(props) {
|
|
|
48
65
|
receiver: rawArgs.receiver,
|
|
49
66
|
owner: rawArgs.owner,
|
|
50
67
|
shares: rawArgs.shares,
|
|
51
|
-
underlying
|
|
52
|
-
// Calldata-only parse: transfers are recovered later by simulation.
|
|
53
|
-
transfers: []
|
|
68
|
+
underlying
|
|
54
69
|
};
|
|
55
70
|
default:
|
|
56
71
|
throw new import_errors.UnsupportedPoolFunctionError(pool.address, parsed.functionName);
|
|
@@ -26,7 +26,7 @@ __reExport(types_exports, require("./types-adapters.js"), module.exports);
|
|
|
26
26
|
__reExport(types_exports, require("./types-facades.js"), module.exports);
|
|
27
27
|
__reExport(types_exports, require("./types-pools.js"), module.exports);
|
|
28
28
|
function isPoolOperation(tx) {
|
|
29
|
-
return tx.operation === "Deposit" || tx.operation === "Redeem";
|
|
29
|
+
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
30
30
|
}
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
@@ -27,6 +27,12 @@ var import_BalancePrerequisite = require("./BalancePrerequisite.js");
|
|
|
27
27
|
function buildPrerequisites(tx, ctx) {
|
|
28
28
|
const { wallet } = ctx;
|
|
29
29
|
switch (tx.operation) {
|
|
30
|
+
// Deposit and Mint both pull the underlying from the caller into the pool;
|
|
31
|
+
// they only differ in which side (assets vs shares) the caller specifies.
|
|
32
|
+
// The exact underlying amount for Mint is resolved by the pool, so we can
|
|
33
|
+
// only require an allowance/balance against the known specified amount —
|
|
34
|
+
// here we approximate Mint by its shares amount (a lower bound on assets is
|
|
35
|
+
// not knowable from calldata alone).
|
|
30
36
|
case "Deposit":
|
|
31
37
|
return [
|
|
32
38
|
new import_AllowancePrerequisite.AllowancePrerequisite({
|
|
@@ -43,6 +49,24 @@ function buildPrerequisites(tx, ctx) {
|
|
|
43
49
|
title: "Sufficient token balance"
|
|
44
50
|
})
|
|
45
51
|
];
|
|
52
|
+
case "Mint":
|
|
53
|
+
return [
|
|
54
|
+
new import_AllowancePrerequisite.AllowancePrerequisite({
|
|
55
|
+
token: tx.underlying,
|
|
56
|
+
owner: wallet,
|
|
57
|
+
spender: tx.pool,
|
|
58
|
+
required: tx.shares,
|
|
59
|
+
title: "Token approved to pool"
|
|
60
|
+
}),
|
|
61
|
+
new import_BalancePrerequisite.BalancePrerequisite({
|
|
62
|
+
token: tx.underlying,
|
|
63
|
+
owner: wallet,
|
|
64
|
+
required: tx.shares,
|
|
65
|
+
title: "Sufficient token balance"
|
|
66
|
+
})
|
|
67
|
+
];
|
|
68
|
+
// Redeem and Withdraw both burn LP shares from `owner`; they only differ in
|
|
69
|
+
// which side (shares vs assets) the caller specifies.
|
|
46
70
|
case "Redeem": {
|
|
47
71
|
const prereqs = [
|
|
48
72
|
new import_BalancePrerequisite.BalancePrerequisite({
|
|
@@ -65,6 +89,28 @@ function buildPrerequisites(tx, ctx) {
|
|
|
65
89
|
}
|
|
66
90
|
return prereqs;
|
|
67
91
|
}
|
|
92
|
+
case "Withdraw": {
|
|
93
|
+
const prereqs = [
|
|
94
|
+
new import_BalancePrerequisite.BalancePrerequisite({
|
|
95
|
+
token: tx.pool,
|
|
96
|
+
owner: tx.owner,
|
|
97
|
+
required: tx.assets,
|
|
98
|
+
title: "Sufficient LP token balance"
|
|
99
|
+
})
|
|
100
|
+
];
|
|
101
|
+
if (!(0, import_viem.isAddressEqual)(tx.owner, wallet)) {
|
|
102
|
+
prereqs.push(
|
|
103
|
+
new import_AllowancePrerequisite.AllowancePrerequisite({
|
|
104
|
+
token: tx.pool,
|
|
105
|
+
owner: tx.owner,
|
|
106
|
+
spender: wallet,
|
|
107
|
+
required: tx.assets,
|
|
108
|
+
title: "LP token approved to caller"
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return prereqs;
|
|
113
|
+
}
|
|
68
114
|
case "MultiCall":
|
|
69
115
|
case "BotMulticall":
|
|
70
116
|
case "OpenCreditAccount":
|
|
@@ -0,0 +1,28 @@
|
|
|
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 constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
ETH_SIMULATE_V1_NETWORKS: () => ETH_SIMULATE_V1_NETWORKS
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
const ETH_SIMULATE_V1_NETWORKS = /* @__PURE__ */ new Set(["Mainnet", "Plasma", "Somnia"]);
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
ETH_SIMULATE_V1_NETWORKS
|
|
28
|
+
});
|
|
@@ -16,13 +16,44 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
PreviewSimulationError: () => PreviewSimulationError,
|
|
22
|
+
asPreviewSimulationError: () => asPreviewSimulationError,
|
|
23
|
+
combinePreviewSimulationErrors: () => combinePreviewSimulationErrors,
|
|
21
24
|
decodeSimulationError: () => decodeSimulationError
|
|
22
25
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
27
|
var import_viem = require("viem");
|
|
25
28
|
var import_errors = require("../../abi/errors.js");
|
|
29
|
+
class PreviewSimulationError extends import_viem.BaseError {
|
|
30
|
+
name = "PreviewSimulationError";
|
|
31
|
+
/** Per-flow decoded failures behind this error. */
|
|
32
|
+
failures;
|
|
33
|
+
constructor(failures) {
|
|
34
|
+
const shortMessage = failures.length <= 1 ? failures[0]?.detail.reason ?? "simulation failed" : "all simulation flows failed";
|
|
35
|
+
const cause = failures.find((f) => f.detail.cause instanceof Error)?.detail.cause;
|
|
36
|
+
super(shortMessage, {
|
|
37
|
+
metaMessages: failures.map((f) => `[${f.source}] ${f.detail.reason}`),
|
|
38
|
+
cause
|
|
39
|
+
});
|
|
40
|
+
this.failures = failures;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function asPreviewSimulationError(reason, source) {
|
|
44
|
+
if (reason instanceof PreviewSimulationError) {
|
|
45
|
+
return reason;
|
|
46
|
+
}
|
|
47
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
48
|
+
return new PreviewSimulationError([
|
|
49
|
+
{ source, detail: decodeSimulationError({ error }) }
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
function combinePreviewSimulationErrors(...errors) {
|
|
53
|
+
return new PreviewSimulationError(
|
|
54
|
+
errors.filter((e) => e).flatMap((e) => e?.failures ?? [])
|
|
55
|
+
);
|
|
56
|
+
}
|
|
26
57
|
function decodeSimulationError(revert) {
|
|
27
58
|
const { error, data } = revert;
|
|
28
59
|
if (data && data !== "0x") {
|
|
@@ -60,5 +91,8 @@ function formatDecodedError(errorName, args) {
|
|
|
60
91
|
}
|
|
61
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
93
|
0 && (module.exports = {
|
|
94
|
+
PreviewSimulationError,
|
|
95
|
+
asPreviewSimulationError,
|
|
96
|
+
combinePreviewSimulationErrors,
|
|
63
97
|
decodeSimulationError
|
|
64
98
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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 holders_exports = {};
|
|
20
|
+
__export(holders_exports, {
|
|
21
|
+
watchedHolders: () => watchedHolders
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(holders_exports);
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
function sourceHolder(operation, wallet) {
|
|
26
|
+
switch (operation.operation) {
|
|
27
|
+
case "Deposit":
|
|
28
|
+
case "Mint":
|
|
29
|
+
return wallet;
|
|
30
|
+
case "Withdraw":
|
|
31
|
+
case "Redeem":
|
|
32
|
+
return operation.owner;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function watchedHolders(operation, wallet) {
|
|
36
|
+
const holders = new import_sdk.AddressSet([
|
|
37
|
+
sourceHolder(operation, wallet),
|
|
38
|
+
operation.receiver
|
|
39
|
+
]);
|
|
40
|
+
return holders.asArray();
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
watchedHolders
|
|
45
|
+
});
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,22 +15,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
15
|
}
|
|
12
16
|
return to;
|
|
13
17
|
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
19
|
var simulate_exports = {};
|
|
20
|
+
__export(simulate_exports, {
|
|
21
|
+
ETH_SIMULATE_V1_NETWORKS: () => import_constants.ETH_SIMULATE_V1_NETWORKS,
|
|
22
|
+
PreviewSimulationError: () => import_errors.PreviewSimulationError,
|
|
23
|
+
simulateFacadeOperation: () => import_simulateFacadeOperation.simulateFacadeOperation,
|
|
24
|
+
simulateOperation: () => import_simulateOperation.simulateOperation,
|
|
25
|
+
simulatePoolOperation: () => import_simulatePoolOperation.simulatePoolOperation
|
|
26
|
+
});
|
|
17
27
|
module.exports = __toCommonJS(simulate_exports);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
__reExport(simulate_exports, require("./types.js"), module.exports);
|
|
28
|
+
var import_constants = require("./constants.js");
|
|
29
|
+
var import_errors = require("./errors.js");
|
|
30
|
+
var import_simulateFacadeOperation = require("./simulateFacadeOperation.js");
|
|
31
|
+
var import_simulateOperation = require("./simulateOperation.js");
|
|
32
|
+
var import_simulatePoolOperation = require("./simulatePoolOperation.js");
|
|
24
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
34
|
0 && (module.exports = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
...require("./types.js")
|
|
35
|
+
ETH_SIMULATE_V1_NETWORKS,
|
|
36
|
+
PreviewSimulationError,
|
|
37
|
+
simulateFacadeOperation,
|
|
38
|
+
simulateOperation,
|
|
39
|
+
simulatePoolOperation
|
|
32
40
|
});
|
|
@@ -21,7 +21,7 @@ __export(simulateFacadeOperation_exports, {
|
|
|
21
21
|
simulateFacadeOperation: () => simulateFacadeOperation
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(simulateFacadeOperation_exports);
|
|
24
|
-
async function simulateFacadeOperation(_input) {
|
|
24
|
+
async function simulateFacadeOperation(_input, _options) {
|
|
25
25
|
throw new Error("not yet implemented");
|
|
26
26
|
}
|
|
27
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -24,12 +24,12 @@ module.exports = __toCommonJS(simulateOperation_exports);
|
|
|
24
24
|
var import_parse = require("../parse/index.js");
|
|
25
25
|
var import_simulateFacadeOperation = require("./simulateFacadeOperation.js");
|
|
26
26
|
var import_simulatePoolOperation = require("./simulatePoolOperation.js");
|
|
27
|
-
async function simulateOperation(input) {
|
|
27
|
+
async function simulateOperation(input, options) {
|
|
28
28
|
const { operation } = input;
|
|
29
29
|
if ((0, import_parse.isPoolOperation)(operation)) {
|
|
30
|
-
return (0, import_simulatePoolOperation.simulatePoolOperation)({ ...input, operation });
|
|
30
|
+
return (0, import_simulatePoolOperation.simulatePoolOperation)({ ...input, operation }, options);
|
|
31
31
|
}
|
|
32
|
-
return (0, import_simulateFacadeOperation.simulateFacadeOperation)({ ...input, operation });
|
|
32
|
+
return (0, import_simulateFacadeOperation.simulateFacadeOperation)({ ...input, operation }, options);
|
|
33
33
|
}
|
|
34
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
35
|
0 && (module.exports = {
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
});
|