@gearbox-protocol/sdk 14.12.0-next.3 → 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 +6 -4
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +4 -0
- package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +22 -10
- package/dist/cjs/preview/parse/types-rwa.js +16 -0
- package/dist/cjs/preview/parse/types.js +9 -2
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +13 -13
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +32 -14
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +66 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +95 -27
- package/dist/cjs/preview/prerequisites/index.js +2 -0
- 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/index.js +5 -2
- package/dist/cjs/preview/simulate/simulateOperation.js +4 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +20 -116
- package/dist/cjs/preview/simulate/simulateRWAOperation.js +30 -0
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
- package/dist/cjs/sdk/market/rwa/types.js +5 -2
- 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 +7 -5
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +4 -0
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +25 -11
- package/dist/esm/preview/parse/types-rwa.js +0 -0
- package/dist/esm/preview/parse/types.js +6 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +13 -13
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +32 -14
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +42 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +100 -27
- package/dist/esm/preview/prerequisites/index.js +1 -0
- 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/index.js +3 -1
- package/dist/esm/preview/simulate/simulateOperation.js +8 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +21 -120
- package/dist/esm/preview/simulate/simulateRWAOperation.js +6 -0
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +14 -4
- package/dist/esm/sdk/market/rwa/types.js +5 -2
- 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/parseRWAFactoryOperationCalldata.d.ts +10 -11
- 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 +48 -0
- package/dist/types/preview/parse/types.d.ts +11 -6
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +1 -3
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +9 -6
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +36 -0
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +15 -6
- package/dist/types/preview/prerequisites/index.d.ts +1 -0
- package/dist/types/preview/prerequisites/types.d.ts +10 -8
- 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 +3 -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 +23 -0
- package/dist/types/preview/simulate/types.d.ts +12 -26
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -0
- package/dist/types/sdk/market/rwa/types.d.ts +13 -5
- 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
|
@@ -20,6 +20,7 @@ __reExport(prerequisites_exports, require("./BalancePrerequisite.js"), module.ex
|
|
|
20
20
|
__reExport(prerequisites_exports, require("./buildPrerequisites.js"), module.exports);
|
|
21
21
|
__reExport(prerequisites_exports, require("./Prerequisite.js"), module.exports);
|
|
22
22
|
__reExport(prerequisites_exports, require("./prepareAction.js"), module.exports);
|
|
23
|
+
__reExport(prerequisites_exports, require("./RWAOpenRequirementsPrerequisite.js"), module.exports);
|
|
23
24
|
__reExport(prerequisites_exports, require("./runPrerequisites.js"), module.exports);
|
|
24
25
|
__reExport(prerequisites_exports, require("./types.js"), module.exports);
|
|
25
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -29,6 +30,7 @@ __reExport(prerequisites_exports, require("./types.js"), module.exports);
|
|
|
29
30
|
...require("./buildPrerequisites.js"),
|
|
30
31
|
...require("./Prerequisite.js"),
|
|
31
32
|
...require("./prepareAction.js"),
|
|
33
|
+
...require("./RWAOpenRequirementsPrerequisite.js"),
|
|
32
34
|
...require("./runPrerequisites.js"),
|
|
33
35
|
...require("./types.js")
|
|
34
36
|
});
|
|
@@ -16,30 +16,21 @@ 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(
|
|
21
|
-
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
UnsupportedOperationError: () => UnsupportedOperationError
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case "Redeem":
|
|
32
|
-
return operation.owner;
|
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
|
+
class UnsupportedOperationError extends Error {
|
|
25
|
+
/** The parsed operation kind (the `operation` discriminant). */
|
|
26
|
+
operation;
|
|
27
|
+
constructor(operation) {
|
|
28
|
+
super(`operation "${operation}" is not supported by previewOperation`);
|
|
29
|
+
this.name = "UnsupportedOperationError";
|
|
30
|
+
this.operation = operation;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
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
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
34
|
0 && (module.exports = {
|
|
44
|
-
|
|
35
|
+
UnsupportedOperationError
|
|
45
36
|
});
|
|
@@ -37,7 +37,7 @@ function extractExpectedBalanceChanges(innerCalls) {
|
|
|
37
37
|
if (!balanceDeltas) {
|
|
38
38
|
return void 0;
|
|
39
39
|
}
|
|
40
|
-
return balanceDeltas.map(({ token, amount }) => ({ token,
|
|
40
|
+
return balanceDeltas.map(({ token, amount }) => ({ token, balance: amount }));
|
|
41
41
|
}
|
|
42
42
|
function functionName(call) {
|
|
43
43
|
return call.functionName.split("(")[0];
|
|
@@ -0,0 +1,26 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var preview_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(preview_exports);
|
|
18
|
+
__reExport(preview_exports, require("./errors.js"), module.exports);
|
|
19
|
+
__reExport(preview_exports, require("./previewOperation.js"), module.exports);
|
|
20
|
+
__reExport(preview_exports, require("./types.js"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./errors.js"),
|
|
24
|
+
...require("./previewOperation.js"),
|
|
25
|
+
...require("./types.js")
|
|
26
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
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 previewOpenCreditAccount_exports = {};
|
|
20
|
+
__export(previewOpenCreditAccount_exports, {
|
|
21
|
+
previewOpenCreditAccount: () => previewOpenCreditAccount
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(previewOpenCreditAccount_exports);
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
var import_extractExpectedBalanceChanges = require("./extractExpectedBalanceChanges.js");
|
|
26
|
+
function previewOpenCreditAccount(input, operation) {
|
|
27
|
+
const { sdk, to, calldata } = input;
|
|
28
|
+
const market = sdk.marketRegister.findByCreditManager(
|
|
29
|
+
operation.creditManager
|
|
30
|
+
);
|
|
31
|
+
const collateralByToken = new import_sdk.AddressMap();
|
|
32
|
+
const balances = new import_sdk.AddressMap();
|
|
33
|
+
const addBalance = (token, amount) => {
|
|
34
|
+
balances.upsert(token, (balances.get(token) ?? 0n) + amount);
|
|
35
|
+
};
|
|
36
|
+
let debt = 0n;
|
|
37
|
+
const quotas = [];
|
|
38
|
+
for (const op of operation.multicall) {
|
|
39
|
+
switch (op.operation) {
|
|
40
|
+
case "AddCollateral": {
|
|
41
|
+
const balance = collateralByToken.get(op.token)?.balance ?? 0n;
|
|
42
|
+
collateralByToken.upsert(op.token, {
|
|
43
|
+
token: op.token,
|
|
44
|
+
balance: balance + op.amount
|
|
45
|
+
});
|
|
46
|
+
addBalance(op.token, op.amount);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case "WithdrawCollateral":
|
|
50
|
+
addBalance(op.token, -op.amount);
|
|
51
|
+
break;
|
|
52
|
+
case "IncreaseBorrowedAmount":
|
|
53
|
+
debt += op.amount;
|
|
54
|
+
addBalance(op.token, op.amount);
|
|
55
|
+
break;
|
|
56
|
+
case "DecreaseBorrowedAmount":
|
|
57
|
+
debt -= op.amount;
|
|
58
|
+
addBalance(op.token, -op.amount);
|
|
59
|
+
break;
|
|
60
|
+
case "UpdateQuota":
|
|
61
|
+
quotas.push({ token: op.token, balance: op.change });
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const collateral = collateralByToken.values();
|
|
66
|
+
const collateralValue = collateral.reduce(
|
|
67
|
+
(acc, { token, balance }) => acc + market.priceOracle.convert(token, market.underlying, balance),
|
|
68
|
+
0n
|
|
69
|
+
);
|
|
70
|
+
const parsed = sdk.parseFunctionDataV2(to, calldata);
|
|
71
|
+
const innerCalls = parsed.rawArgs.calls ?? [];
|
|
72
|
+
const deltas = (0, import_extractExpectedBalanceChanges.extractExpectedBalanceChanges)(innerCalls) ?? [];
|
|
73
|
+
for (const { token, balance } of deltas) {
|
|
74
|
+
addBalance(token, balance);
|
|
75
|
+
}
|
|
76
|
+
const assets = balances.entries().filter(([, balance]) => balance > 1n).map(([token, balance]) => ({ token, balance }));
|
|
77
|
+
return {
|
|
78
|
+
operation: operation.operation,
|
|
79
|
+
target: inferTargetAsset(operation.multicall, balances),
|
|
80
|
+
collateral,
|
|
81
|
+
collateralValue,
|
|
82
|
+
debt,
|
|
83
|
+
quotas,
|
|
84
|
+
assets
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function inferTargetAsset(multicall, balances) {
|
|
88
|
+
for (const op of multicall) {
|
|
89
|
+
if (op.operation === "UpdateQuota" && op.change > 0n) {
|
|
90
|
+
const balance = balances.get(op.token);
|
|
91
|
+
return balance ? { token: op.token, balance } : void 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
previewOpenCreditAccount
|
|
99
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 previewOperation_exports = {};
|
|
20
|
+
__export(previewOperation_exports, {
|
|
21
|
+
previewOperation: () => previewOperation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(previewOperation_exports);
|
|
24
|
+
var import_parse = require("../parse/index.js");
|
|
25
|
+
var import_errors = require("./errors.js");
|
|
26
|
+
var import_previewOpenCreditAccount = require("./previewOpenCreditAccount.js");
|
|
27
|
+
var import_previewPoolOperation = require("./previewPoolOperation.js");
|
|
28
|
+
async function previewOperation(input, options) {
|
|
29
|
+
const operation = (0, import_parse.parseOperationCalldata)(input);
|
|
30
|
+
if ((0, import_parse.isPoolOperation)(operation)) {
|
|
31
|
+
return (0, import_previewPoolOperation.previewPoolOperation)(input, operation, options);
|
|
32
|
+
}
|
|
33
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "SecuritizeOpenCreditAccount") {
|
|
34
|
+
return (0, import_previewOpenCreditAccount.previewOpenCreditAccount)(input, operation);
|
|
35
|
+
}
|
|
36
|
+
throw new import_errors.UnsupportedOperationError(operation.operation);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
previewOperation
|
|
41
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 previewPoolOperation_exports = {};
|
|
20
|
+
__export(previewPoolOperation_exports, {
|
|
21
|
+
previewPoolOperation: () => previewPoolOperation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(previewPoolOperation_exports);
|
|
24
|
+
var import_simulate = require("../simulate/index.js");
|
|
25
|
+
async function previewPoolOperation(input, operation, options) {
|
|
26
|
+
const { sdk, to, calldata } = input;
|
|
27
|
+
const { tokenIn, tokenOut } = operation;
|
|
28
|
+
const sim = await (0, import_simulate.simulatePoolOperation)(
|
|
29
|
+
{ sdk, operation, to, calldata },
|
|
30
|
+
options
|
|
31
|
+
);
|
|
32
|
+
if (sim.status === "success") {
|
|
33
|
+
return {
|
|
34
|
+
operation: operation.operation,
|
|
35
|
+
pool: operation.pool,
|
|
36
|
+
tokenIn: { token: tokenIn, balance: sim.amountIn },
|
|
37
|
+
tokenOut: { token: tokenOut, balance: sim.amountOut }
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const { error } = sim;
|
|
41
|
+
switch (operation.operation) {
|
|
42
|
+
case "Deposit":
|
|
43
|
+
return {
|
|
44
|
+
operation: "Deposit",
|
|
45
|
+
pool: operation.pool,
|
|
46
|
+
tokenIn: { token: tokenIn, balance: operation.assets },
|
|
47
|
+
tokenOut: { token: tokenOut, error }
|
|
48
|
+
};
|
|
49
|
+
case "Mint":
|
|
50
|
+
return {
|
|
51
|
+
operation: "Mint",
|
|
52
|
+
pool: operation.pool,
|
|
53
|
+
tokenIn: { token: tokenIn, error },
|
|
54
|
+
tokenOut: { token: tokenOut, balance: operation.shares }
|
|
55
|
+
};
|
|
56
|
+
case "Withdraw":
|
|
57
|
+
return {
|
|
58
|
+
operation: "Withdraw",
|
|
59
|
+
pool: operation.pool,
|
|
60
|
+
tokenIn: { token: tokenIn, error },
|
|
61
|
+
tokenOut: { token: tokenOut, balance: operation.assets }
|
|
62
|
+
};
|
|
63
|
+
case "Redeem":
|
|
64
|
+
return {
|
|
65
|
+
operation: "Redeem",
|
|
66
|
+
pool: operation.pool,
|
|
67
|
+
tokenIn: { token: tokenIn, balance: operation.shares },
|
|
68
|
+
tokenOut: { token: tokenOut, error }
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
previewPoolOperation
|
|
75
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -21,17 +21,20 @@ __export(simulate_exports, {
|
|
|
21
21
|
PreviewSimulationError: () => import_errors.PreviewSimulationError,
|
|
22
22
|
simulateFacadeOperation: () => import_simulateFacadeOperation.simulateFacadeOperation,
|
|
23
23
|
simulateOperation: () => import_simulateOperation.simulateOperation,
|
|
24
|
-
simulatePoolOperation: () => import_simulatePoolOperation.simulatePoolOperation
|
|
24
|
+
simulatePoolOperation: () => import_simulatePoolOperation.simulatePoolOperation,
|
|
25
|
+
simulateRWAOperation: () => import_simulateRWAOperation.simulateRWAOperation
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(simulate_exports);
|
|
27
28
|
var import_errors = require("./errors.js");
|
|
28
29
|
var import_simulateFacadeOperation = require("./simulateFacadeOperation.js");
|
|
29
30
|
var import_simulateOperation = require("./simulateOperation.js");
|
|
30
31
|
var import_simulatePoolOperation = require("./simulatePoolOperation.js");
|
|
32
|
+
var import_simulateRWAOperation = require("./simulateRWAOperation.js");
|
|
31
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
34
|
0 && (module.exports = {
|
|
33
35
|
PreviewSimulationError,
|
|
34
36
|
simulateFacadeOperation,
|
|
35
37
|
simulateOperation,
|
|
36
|
-
simulatePoolOperation
|
|
38
|
+
simulatePoolOperation,
|
|
39
|
+
simulateRWAOperation
|
|
37
40
|
});
|
|
@@ -24,11 +24,15 @@ 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
|
+
var import_simulateRWAOperation = require("./simulateRWAOperation.js");
|
|
27
28
|
async function simulateOperation(input, options) {
|
|
28
29
|
const { operation } = input;
|
|
29
30
|
if ((0, import_parse.isPoolOperation)(operation)) {
|
|
30
31
|
return (0, import_simulatePoolOperation.simulatePoolOperation)({ ...input, operation }, options);
|
|
31
32
|
}
|
|
33
|
+
if ((0, import_parse.isRWAOperation)(operation)) {
|
|
34
|
+
return (0, import_simulateRWAOperation.simulateRWAOperation)({ ...input, operation }, options);
|
|
35
|
+
}
|
|
32
36
|
return (0, import_simulateFacadeOperation.simulateFacadeOperation)({ ...input, operation }, options);
|
|
33
37
|
}
|
|
34
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -18,16 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var simulatePoolOperation_exports = {};
|
|
20
20
|
__export(simulatePoolOperation_exports, {
|
|
21
|
-
computePoolOpBalanceChanges: () => computePoolOpBalanceChanges,
|
|
22
21
|
simulatePoolOperation: () => simulatePoolOperation
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(simulatePoolOperation_exports);
|
|
25
24
|
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
-
var import_iERC20 = require("../../abi/iERC20.js");
|
|
27
25
|
var import_iZapper = require("../../abi/iZapper.js");
|
|
28
|
-
var import_sdk = require("../../sdk/index.js");
|
|
29
26
|
var import_errors = require("./errors.js");
|
|
30
|
-
var import_holders = require("./holders.js");
|
|
31
27
|
function previewRead(operation) {
|
|
32
28
|
switch (operation.operation) {
|
|
33
29
|
case "Deposit":
|
|
@@ -40,16 +36,6 @@ function previewRead(operation) {
|
|
|
40
36
|
return { functionName: "previewRedeem", amount: operation.shares };
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
|
-
function outsideToken(operation) {
|
|
44
|
-
switch (operation.operation) {
|
|
45
|
-
case "Deposit":
|
|
46
|
-
case "Mint":
|
|
47
|
-
return operation.tokenIn;
|
|
48
|
-
case "Withdraw":
|
|
49
|
-
case "Redeem":
|
|
50
|
-
return operation.tokenOut;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
39
|
function previewContract(operation) {
|
|
54
40
|
const { functionName, amount } = previewRead(operation);
|
|
55
41
|
if (operation.zapper) {
|
|
@@ -67,60 +53,31 @@ function previewContract(operation) {
|
|
|
67
53
|
args: [amount]
|
|
68
54
|
};
|
|
69
55
|
}
|
|
56
|
+
function amountsInOut(operation, previewAmount) {
|
|
57
|
+
switch (operation.operation) {
|
|
58
|
+
case "Deposit":
|
|
59
|
+
return { amountIn: operation.assets, amountOut: previewAmount };
|
|
60
|
+
case "Mint":
|
|
61
|
+
return { amountIn: previewAmount, amountOut: operation.shares };
|
|
62
|
+
case "Withdraw":
|
|
63
|
+
return { amountIn: previewAmount, amountOut: operation.assets };
|
|
64
|
+
case "Redeem":
|
|
65
|
+
return { amountIn: operation.shares, amountOut: previewAmount };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
70
68
|
async function simulatePoolOperation(input, options = {}) {
|
|
71
|
-
const { sdk, operation
|
|
69
|
+
const { sdk, operation } = input;
|
|
72
70
|
const { blockNumber, logger } = options;
|
|
73
|
-
const { pool } = operation;
|
|
74
71
|
try {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
({ holder, token }) => ({
|
|
82
|
-
address: token,
|
|
83
|
-
abi: import_iERC20.ierc20Abi,
|
|
84
|
-
functionName: "balanceOf",
|
|
85
|
-
args: [holder]
|
|
86
|
-
})
|
|
87
|
-
);
|
|
88
|
-
const preview = previewContract(operation);
|
|
89
|
-
let results;
|
|
90
|
-
try {
|
|
91
|
-
results = await sdk.client.multicall({
|
|
92
|
-
allowFailure: false,
|
|
93
|
-
// `undefined` lets viem read at `latest`; `blockNumber` is only set for
|
|
94
|
-
// testnet forks pinned to a specific block.
|
|
95
|
-
blockNumber,
|
|
96
|
-
contracts: [...balanceContracts, preview]
|
|
97
|
-
});
|
|
98
|
-
} catch (cause) {
|
|
99
|
-
throw new import_errors.PreviewSimulationError([
|
|
100
|
-
{
|
|
101
|
-
source: "multicall",
|
|
102
|
-
detail: (0, import_errors.decodeSimulationError)({
|
|
103
|
-
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
const previewAmount = results[balanceContracts.length];
|
|
109
|
-
const balances = new import_sdk.AddressMap();
|
|
110
|
-
for (const [i, { holder, token }] of balanceCalls.entries()) {
|
|
111
|
-
const tokenBalances = balances.get(holder) ?? new import_sdk.AddressMap();
|
|
112
|
-
tokenBalances.upsert(token, results[i]);
|
|
113
|
-
balances.upsert(holder, tokenBalances);
|
|
114
|
-
}
|
|
115
|
-
const before = (token, holder) => balances.get(holder)?.get(token) ?? 0n;
|
|
72
|
+
const previewAmount = await sdk.client.readContract({
|
|
73
|
+
// `undefined` lets viem read at `latest`; `blockNumber` is only set for
|
|
74
|
+
// testnet forks pinned to a specific block.
|
|
75
|
+
blockNumber,
|
|
76
|
+
...previewContract(operation)
|
|
77
|
+
});
|
|
116
78
|
return {
|
|
117
79
|
status: "success",
|
|
118
|
-
|
|
119
|
-
operation,
|
|
120
|
-
wallet,
|
|
121
|
-
previewAmount,
|
|
122
|
-
before
|
|
123
|
-
)
|
|
80
|
+
...amountsInOut(operation, previewAmount)
|
|
124
81
|
};
|
|
125
82
|
} catch (cause) {
|
|
126
83
|
const error = (0, import_errors.asPreviewSimulationError)(cause, "multicall");
|
|
@@ -128,60 +85,7 @@ async function simulatePoolOperation(input, options = {}) {
|
|
|
128
85
|
return { status: "failure", error };
|
|
129
86
|
}
|
|
130
87
|
}
|
|
131
|
-
function balanceLegs(operation, wallet, previewAmount) {
|
|
132
|
-
const { pool, receiver } = operation;
|
|
133
|
-
switch (operation.operation) {
|
|
134
|
-
case "Deposit":
|
|
135
|
-
return [
|
|
136
|
-
{ address: wallet, token: operation.tokenIn, delta: -operation.assets },
|
|
137
|
-
{ address: receiver, token: pool, delta: previewAmount }
|
|
138
|
-
];
|
|
139
|
-
case "Mint":
|
|
140
|
-
return [
|
|
141
|
-
{ address: wallet, token: operation.tokenIn, delta: -previewAmount },
|
|
142
|
-
{ address: receiver, token: pool, delta: operation.shares }
|
|
143
|
-
];
|
|
144
|
-
case "Withdraw":
|
|
145
|
-
return [
|
|
146
|
-
{ address: operation.owner, token: pool, delta: -previewAmount },
|
|
147
|
-
{
|
|
148
|
-
address: receiver,
|
|
149
|
-
token: operation.tokenOut,
|
|
150
|
-
delta: operation.assets
|
|
151
|
-
}
|
|
152
|
-
];
|
|
153
|
-
case "Redeem":
|
|
154
|
-
return [
|
|
155
|
-
{ address: operation.owner, token: pool, delta: -operation.shares },
|
|
156
|
-
{ address: receiver, token: operation.tokenOut, delta: previewAmount }
|
|
157
|
-
];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function computePoolOpBalanceChanges(operation, wallet, previewAmount, before) {
|
|
161
|
-
const byAddress = new import_sdk.AddressMap();
|
|
162
|
-
for (const { address, token, delta } of balanceLegs(
|
|
163
|
-
operation,
|
|
164
|
-
wallet,
|
|
165
|
-
previewAmount
|
|
166
|
-
)) {
|
|
167
|
-
const beforeBalance = before(token, address);
|
|
168
|
-
const change = {
|
|
169
|
-
token,
|
|
170
|
-
before: beforeBalance,
|
|
171
|
-
after: beforeBalance + delta,
|
|
172
|
-
delta
|
|
173
|
-
};
|
|
174
|
-
const existing = byAddress.get(address);
|
|
175
|
-
if (existing) {
|
|
176
|
-
existing.changes.push(change);
|
|
177
|
-
} else {
|
|
178
|
-
byAddress.upsert(address, { address, changes: [change] });
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return byAddress.values();
|
|
182
|
-
}
|
|
183
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
184
89
|
0 && (module.exports = {
|
|
185
|
-
computePoolOpBalanceChanges,
|
|
186
90
|
simulatePoolOperation
|
|
187
91
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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 simulateRWAOperation_exports = {};
|
|
20
|
+
__export(simulateRWAOperation_exports, {
|
|
21
|
+
simulateRWAOperation: () => simulateRWAOperation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(simulateRWAOperation_exports);
|
|
24
|
+
async function simulateRWAOperation(_input, _options) {
|
|
25
|
+
throw new Error("not yet implemented");
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
simulateRWAOperation
|
|
30
|
+
});
|
|
@@ -73,17 +73,21 @@ class SecuritizeRWAFactory extends import_base.BaseContract {
|
|
|
73
73
|
parseFunctionParamsV2(params, strict) {
|
|
74
74
|
switch (params.functionName) {
|
|
75
75
|
case "openCreditAccount": {
|
|
76
|
-
const [creditManager, calls] = params.args;
|
|
76
|
+
const [creditManager, calls, tokensToRegister, signaturesToCache] = params.args;
|
|
77
77
|
return {
|
|
78
78
|
creditManager,
|
|
79
|
-
calls: this.register.parseMultiCallV2([...calls], strict)
|
|
79
|
+
calls: this.register.parseMultiCallV2([...calls], strict),
|
|
80
|
+
tokensToRegister,
|
|
81
|
+
signaturesToCache
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
case "multicall": {
|
|
83
|
-
const [creditAccount, calls] = params.args;
|
|
85
|
+
const [creditAccount, calls, tokensToRegister, signaturesToCache] = params.args;
|
|
84
86
|
return {
|
|
85
87
|
creditAccount,
|
|
86
|
-
calls: this.register.parseMultiCallV2([...calls], strict)
|
|
88
|
+
calls: this.register.parseMultiCallV2([...calls], strict),
|
|
89
|
+
tokensToRegister,
|
|
90
|
+
signaturesToCache
|
|
87
91
|
};
|
|
88
92
|
}
|
|
89
93
|
default:
|
|
@@ -145,6 +149,12 @@ class SecuritizeRWAFactory extends import_base.BaseContract {
|
|
|
145
149
|
})
|
|
146
150
|
};
|
|
147
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* {@inheritDoc IRWAFactory.getTokens}
|
|
154
|
+
*/
|
|
155
|
+
getTokens() {
|
|
156
|
+
return this.dsTokens.map((t) => t.address);
|
|
157
|
+
}
|
|
148
158
|
/**
|
|
149
159
|
* {@inheritDoc IRWAFactory.getInvestor}
|
|
150
160
|
*/
|
|
@@ -24,8 +24,11 @@ __export(types_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(types_exports);
|
|
25
25
|
var import_securitize = require("./securitize/index.js");
|
|
26
26
|
const RWA_FACTORY_TYPES = [import_securitize.RWA_FACTORY_SECURITIZE];
|
|
27
|
-
function isRWAFactory(
|
|
28
|
-
|
|
27
|
+
function isRWAFactory(contract, type) {
|
|
28
|
+
if (type) {
|
|
29
|
+
return contract.contractType === type;
|
|
30
|
+
}
|
|
31
|
+
return contract.contractType.startsWith("RWA_FACTORY::");
|
|
29
32
|
}
|
|
30
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
34
|
0 && (module.exports = {
|
|
@@ -55,7 +55,6 @@ class ZapperContract extends import_base.BaseContract {
|
|
|
55
55
|
const { rawArgs } = parsed;
|
|
56
56
|
const pool = this.pool;
|
|
57
57
|
const zapper = this.address;
|
|
58
|
-
const token = this.tokenIn.addr;
|
|
59
58
|
const underlying = this.sdk.marketRegister.findByPool(pool).underlying;
|
|
60
59
|
const receiver = rawArgs.receiver;
|
|
61
60
|
if (parsed.functionName.startsWith("deposit")) {
|
|
@@ -65,7 +64,6 @@ class ZapperContract extends import_base.BaseContract {
|
|
|
65
64
|
zapper,
|
|
66
65
|
receiver,
|
|
67
66
|
assets: rawArgs.tokenInAmount ?? value ?? 0n,
|
|
68
|
-
token,
|
|
69
67
|
underlying,
|
|
70
68
|
referralCode: rawArgs.referralCode
|
|
71
69
|
};
|
|
@@ -77,7 +75,6 @@ class ZapperContract extends import_base.BaseContract {
|
|
|
77
75
|
zapper,
|
|
78
76
|
receiver,
|
|
79
77
|
shares: rawArgs.tokenOutAmount,
|
|
80
|
-
token,
|
|
81
78
|
underlying
|
|
82
79
|
};
|
|
83
80
|
}
|
|
@@ -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";
|