@gearbox-protocol/sdk 14.12.0-next.12 → 14.12.0-next.13
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/parseRWAFactoryOperationCalldata.js +13 -12
- package/dist/cjs/preview/parse/types.js +1 -1
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +10 -16
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +17 -33
- package/dist/cjs/preview/prerequisites/Prerequisite.js +13 -18
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +36 -15
- package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +57 -0
- package/dist/cjs/preview/prerequisites/{prepareAction.js → buildPartialLiquidationPrerequisites.js} +18 -24
- package/dist/cjs/preview/prerequisites/buildPoolPrerequisites.js +125 -0
- package/dist/cjs/preview/prerequisites/buildRWAPrerequisites.js +57 -0
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +85 -0
- package/dist/cjs/preview/prerequisites/helpers.js +47 -0
- package/dist/cjs/preview/prerequisites/index.js +2 -6
- package/dist/cjs/preview/preview/detectCloseOrRepay.js +51 -0
- package/dist/cjs/preview/preview/index.js +4 -0
- package/dist/cjs/preview/preview/previewCloseOrRepay.js +94 -0
- package/dist/cjs/preview/preview/previewOperation.js +10 -2
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +26 -4
- package/dist/cjs/sdk/utils/AddressSet.js +7 -0
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +13 -12
- package/dist/esm/preview/parse/types.js +1 -1
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +11 -20
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +18 -37
- package/dist/esm/preview/prerequisites/Prerequisite.js +13 -20
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +36 -15
- package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +35 -0
- package/dist/esm/preview/prerequisites/buildPartialLiquidationPrerequisites.js +18 -0
- package/dist/esm/preview/prerequisites/buildPoolPrerequisites.js +101 -0
- package/dist/esm/preview/prerequisites/buildRWAPrerequisites.js +33 -0
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +63 -0
- package/dist/esm/preview/prerequisites/helpers.js +23 -0
- package/dist/esm/preview/prerequisites/index.js +1 -3
- package/dist/esm/preview/preview/detectCloseOrRepay.js +26 -0
- package/dist/esm/preview/preview/index.js +2 -0
- package/dist/esm/preview/preview/previewCloseOrRepay.js +76 -0
- package/dist/esm/preview/preview/previewOperation.js +10 -2
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +26 -4
- package/dist/esm/sdk/utils/AddressSet.js +7 -0
- package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +1 -1
- package/dist/types/preview/parse/types-rwa.d.ts +11 -23
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +4 -5
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +4 -6
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +16 -40
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +22 -16
- package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +14 -0
- package/dist/types/preview/prerequisites/buildPartialLiquidationPrerequisites.d.ts +8 -0
- package/dist/types/preview/prerequisites/buildPoolPrerequisites.d.ts +8 -0
- package/dist/types/preview/prerequisites/buildRWAPrerequisites.d.ts +21 -0
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +27 -0
- package/dist/types/preview/prerequisites/helpers.d.ts +15 -0
- package/dist/types/preview/prerequisites/index.d.ts +1 -3
- package/dist/types/preview/prerequisites/types.d.ts +21 -2
- package/dist/types/preview/preview/detectCloseOrRepay.d.ts +18 -0
- package/dist/types/preview/preview/index.d.ts +2 -0
- package/dist/types/preview/preview/previewAdjustCreditAccount.d.ts +2 -2
- package/dist/types/preview/preview/previewCloseOrRepay.d.ts +10 -0
- package/dist/types/preview/preview/previewOpenCreditAccount.d.ts +2 -2
- package/dist/types/preview/preview/types.d.ts +60 -3
- package/dist/types/sdk/accounts/types.d.ts +3 -3
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +11 -3
- package/dist/types/sdk/market/rwa/securitize/types.d.ts +18 -2
- package/dist/types/sdk/market/rwa/types.d.ts +26 -9
- package/dist/types/sdk/utils/AddressSet.d.ts +1 -0
- package/package.json +1 -1
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +0 -297
- package/dist/cjs/preview/prerequisites/runPrerequisites.js +0 -71
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +0 -279
- package/dist/esm/preview/prerequisites/prepareAction.js +0 -23
- package/dist/esm/preview/prerequisites/runPrerequisites.js +0 -47
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +0 -25
- package/dist/types/preview/prerequisites/prepareAction.d.ts +0 -52
- package/dist/types/preview/prerequisites/runPrerequisites.d.ts +0 -12
|
@@ -0,0 +1,47 @@
|
|
|
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 helpers_exports = {};
|
|
20
|
+
__export(helpers_exports, {
|
|
21
|
+
allowanceAndBalance: () => allowanceAndBalance
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
24
|
+
var import_AllowancePrerequisite = require("./AllowancePrerequisite.js");
|
|
25
|
+
var import_BalancePrerequisite = require("./BalancePrerequisite.js");
|
|
26
|
+
function allowanceAndBalance(props) {
|
|
27
|
+
const { token, owner, spender, required } = props;
|
|
28
|
+
return [
|
|
29
|
+
new import_AllowancePrerequisite.AllowancePrerequisite({
|
|
30
|
+
token,
|
|
31
|
+
owner,
|
|
32
|
+
spender,
|
|
33
|
+
required,
|
|
34
|
+
title: props.allowanceTitle
|
|
35
|
+
}),
|
|
36
|
+
new import_BalancePrerequisite.BalancePrerequisite({
|
|
37
|
+
token,
|
|
38
|
+
owner,
|
|
39
|
+
required,
|
|
40
|
+
title: props.balanceTitle
|
|
41
|
+
})
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
allowanceAndBalance
|
|
47
|
+
});
|
|
@@ -17,20 +17,16 @@ var prerequisites_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(prerequisites_exports);
|
|
18
18
|
__reExport(prerequisites_exports, require("./AllowancePrerequisite.js"), module.exports);
|
|
19
19
|
__reExport(prerequisites_exports, require("./BalancePrerequisite.js"), module.exports);
|
|
20
|
-
__reExport(prerequisites_exports, require("./
|
|
20
|
+
__reExport(prerequisites_exports, require("./checkPrerequisites.js"), module.exports);
|
|
21
21
|
__reExport(prerequisites_exports, require("./Prerequisite.js"), module.exports);
|
|
22
|
-
__reExport(prerequisites_exports, require("./prepareAction.js"), module.exports);
|
|
23
22
|
__reExport(prerequisites_exports, require("./RWAOpenRequirementsPrerequisite.js"), module.exports);
|
|
24
|
-
__reExport(prerequisites_exports, require("./runPrerequisites.js"), module.exports);
|
|
25
23
|
__reExport(prerequisites_exports, require("./types.js"), module.exports);
|
|
26
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
27
25
|
0 && (module.exports = {
|
|
28
26
|
...require("./AllowancePrerequisite.js"),
|
|
29
27
|
...require("./BalancePrerequisite.js"),
|
|
30
|
-
...require("./
|
|
28
|
+
...require("./checkPrerequisites.js"),
|
|
31
29
|
...require("./Prerequisite.js"),
|
|
32
|
-
...require("./prepareAction.js"),
|
|
33
30
|
...require("./RWAOpenRequirementsPrerequisite.js"),
|
|
34
|
-
...require("./runPrerequisites.js"),
|
|
35
31
|
...require("./types.js")
|
|
36
32
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
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 detectCloseOrRepay_exports = {};
|
|
20
|
+
__export(detectCloseOrRepay_exports, {
|
|
21
|
+
classifyCloseOrRepay: () => classifyCloseOrRepay,
|
|
22
|
+
isCloseOrRepay: () => isCloseOrRepay
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(detectCloseOrRepay_exports);
|
|
25
|
+
var import_viem = require("viem");
|
|
26
|
+
var import_sdk = require("../../sdk/index.js");
|
|
27
|
+
function isCloseOrRepay(multicall) {
|
|
28
|
+
const repaysFullDebt = multicall.some(
|
|
29
|
+
(op) => op.operation === "DecreaseBorrowedAmount" && op.amount === import_sdk.MAX_UINT256
|
|
30
|
+
);
|
|
31
|
+
const withdrawsEverything = multicall.some(
|
|
32
|
+
(op) => op.operation === "WithdrawCollateral" && op.amount === import_sdk.MAX_UINT256
|
|
33
|
+
);
|
|
34
|
+
return repaysFullDebt && withdrawsEverything;
|
|
35
|
+
}
|
|
36
|
+
function classifyCloseOrRepay(multicall, underlying) {
|
|
37
|
+
for (const op of multicall) {
|
|
38
|
+
if (op.operation === "AddCollateral") {
|
|
39
|
+
return "repay";
|
|
40
|
+
}
|
|
41
|
+
if (op.operation === "WithdrawCollateral" && !(0, import_viem.isAddressEqual)(op.token, underlying)) {
|
|
42
|
+
return "repay";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return "close";
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
classifyCloseOrRepay,
|
|
50
|
+
isCloseOrRepay
|
|
51
|
+
});
|
|
@@ -16,15 +16,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var preview_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(preview_exports);
|
|
18
18
|
__reExport(preview_exports, require("./applyInnerOperations.js"), module.exports);
|
|
19
|
+
__reExport(preview_exports, require("./detectCloseOrRepay.js"), module.exports);
|
|
19
20
|
__reExport(preview_exports, require("./errors.js"), module.exports);
|
|
20
21
|
__reExport(preview_exports, require("./previewAdjustCreditAccount.js"), module.exports);
|
|
22
|
+
__reExport(preview_exports, require("./previewCloseOrRepay.js"), module.exports);
|
|
21
23
|
__reExport(preview_exports, require("./previewOperation.js"), module.exports);
|
|
22
24
|
__reExport(preview_exports, require("./types.js"), module.exports);
|
|
23
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
24
26
|
0 && (module.exports = {
|
|
25
27
|
...require("./applyInnerOperations.js"),
|
|
28
|
+
...require("./detectCloseOrRepay.js"),
|
|
26
29
|
...require("./errors.js"),
|
|
27
30
|
...require("./previewAdjustCreditAccount.js"),
|
|
31
|
+
...require("./previewCloseOrRepay.js"),
|
|
28
32
|
...require("./previewOperation.js"),
|
|
29
33
|
...require("./types.js")
|
|
30
34
|
});
|
|
@@ -0,0 +1,94 @@
|
|
|
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 previewCloseOrRepay_exports = {};
|
|
20
|
+
__export(previewCloseOrRepay_exports, {
|
|
21
|
+
previewCloseOrRepay: () => previewCloseOrRepay
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(previewCloseOrRepay_exports);
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
var import_applyInnerOperations = require("./applyInnerOperations.js");
|
|
26
|
+
var import_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
27
|
+
var import_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
28
|
+
async function previewCloseOrRepay(input, operation, permanent, options) {
|
|
29
|
+
const { sdk } = input;
|
|
30
|
+
const market = sdk.marketRegister.findByCreditManager(
|
|
31
|
+
operation.creditManager
|
|
32
|
+
);
|
|
33
|
+
const kind = (0, import_detectCloseOrRepay.classifyCloseOrRepay)(operation.multicall, market.underlying);
|
|
34
|
+
return kind === "close" ? previewCloseCreditAccount(input, operation, permanent, options) : previewRepayCreditAccount(input, operation, permanent, options);
|
|
35
|
+
}
|
|
36
|
+
async function previewCloseCreditAccount(input, operation, permanent, options) {
|
|
37
|
+
const { sdk } = input;
|
|
38
|
+
const market = sdk.marketRegister.findByCreditManager(
|
|
39
|
+
operation.creditManager
|
|
40
|
+
);
|
|
41
|
+
const { state } = await replayMulticall(sdk, operation, options);
|
|
42
|
+
return {
|
|
43
|
+
operation: "CloseCreditAccount",
|
|
44
|
+
permanent,
|
|
45
|
+
creditManager: operation.creditManager,
|
|
46
|
+
creditAccount: operation.creditAccount,
|
|
47
|
+
receivedAmount: state.collateralWithdrawn.getOrZero(market.underlying)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function previewRepayCreditAccount(input, operation, permanent, options) {
|
|
51
|
+
const { sdk, value = 0n } = input;
|
|
52
|
+
const { ca, state } = await replayMulticall(sdk, operation, options);
|
|
53
|
+
const collateralAdded = (0, import_unwrapNativeCollateral.unwrapNativeCollateral)(
|
|
54
|
+
state.collateralAdded.toAssets(),
|
|
55
|
+
value,
|
|
56
|
+
sdk.addressProvider.getAddress(import_sdk.AP_WETH_TOKEN, import_sdk.NO_VERSION)
|
|
57
|
+
);
|
|
58
|
+
const initialTotalDebt = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
59
|
+
return {
|
|
60
|
+
operation: "RepayCreditAccount",
|
|
61
|
+
permanent,
|
|
62
|
+
creditManager: operation.creditManager,
|
|
63
|
+
creditAccount: operation.creditAccount,
|
|
64
|
+
collateralAdded,
|
|
65
|
+
debtRepaid: initialTotalDebt - state.totalDebt,
|
|
66
|
+
collateralWithdrawn: state.collateralWithdrawn.toAssets()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async function replayMulticall(sdk, operation, options) {
|
|
70
|
+
let ca = options?.creditAccount;
|
|
71
|
+
if (!ca) {
|
|
72
|
+
ca = await sdk.accounts.getCreditAccountData(
|
|
73
|
+
operation.creditAccount,
|
|
74
|
+
options?.blockNumber
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (!ca) {
|
|
78
|
+
throw new Error(`credit account ${operation.creditAccount} not found`);
|
|
79
|
+
}
|
|
80
|
+
const state = (0, import_applyInnerOperations.makeInnerOperationsState)();
|
|
81
|
+
for (const t of ca.tokens) {
|
|
82
|
+
if (t.balance > 1n) {
|
|
83
|
+
state.balances.upsert(t.token, t.balance);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
state.debt = ca.debt;
|
|
87
|
+
state.totalDebt = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
88
|
+
(0, import_applyInnerOperations.applyInnerOperations)(sdk, operation.multicall, state);
|
|
89
|
+
return { ca, state };
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
previewCloseOrRepay
|
|
94
|
+
});
|
|
@@ -22,8 +22,10 @@ __export(previewOperation_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(previewOperation_exports);
|
|
24
24
|
var import_parse = require("../parse/index.js");
|
|
25
|
+
var import_detectCloseOrRepay = require("./detectCloseOrRepay.js");
|
|
25
26
|
var import_errors = require("./errors.js");
|
|
26
27
|
var import_previewAdjustCreditAccount = require("./previewAdjustCreditAccount.js");
|
|
28
|
+
var import_previewCloseOrRepay = require("./previewCloseOrRepay.js");
|
|
27
29
|
var import_previewOpenCreditAccount = require("./previewOpenCreditAccount.js");
|
|
28
30
|
var import_previewPoolOperation = require("./previewPoolOperation.js");
|
|
29
31
|
async function previewOperation(input, options) {
|
|
@@ -31,10 +33,16 @@ async function previewOperation(input, options) {
|
|
|
31
33
|
if ((0, import_parse.isPoolOperation)(operation)) {
|
|
32
34
|
return (0, import_previewPoolOperation.previewPoolOperation)(input, operation, options);
|
|
33
35
|
}
|
|
34
|
-
if (operation.operation === "OpenCreditAccount" || operation.operation === "
|
|
36
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") {
|
|
35
37
|
return (0, import_previewOpenCreditAccount.previewOpenCreditAccount)(input, operation);
|
|
36
38
|
}
|
|
37
|
-
if (operation.operation === "
|
|
39
|
+
if (operation.operation === "CloseCreditAccount") {
|
|
40
|
+
return (0, import_previewCloseOrRepay.previewCloseOrRepay)(input, operation, true, options);
|
|
41
|
+
}
|
|
42
|
+
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") {
|
|
43
|
+
if ((0, import_detectCloseOrRepay.isCloseOrRepay)(operation.multicall)) {
|
|
44
|
+
return (0, import_previewCloseOrRepay.previewCloseOrRepay)(input, operation, false, options);
|
|
45
|
+
}
|
|
38
46
|
return (0, import_previewAdjustCreditAccount.previewAdjustCreditAccount)(input, operation, options);
|
|
39
47
|
}
|
|
40
48
|
throw new import_errors.UnsupportedOperationError(operation.operation);
|
|
@@ -189,8 +189,8 @@ class SecuritizeRWAFactory extends import_base.BaseContract {
|
|
|
189
189
|
/**
|
|
190
190
|
* {@inheritDoc IRWAFactory.multicall}
|
|
191
191
|
*/
|
|
192
|
-
multicall(creditAccount, calls,
|
|
193
|
-
const { tokensToRegister = [], signaturesToCache = [] } =
|
|
192
|
+
multicall(creditAccount, calls, args) {
|
|
193
|
+
const { tokensToRegister = [], signaturesToCache = [] } = args ?? {};
|
|
194
194
|
return this.createRawTx({
|
|
195
195
|
functionName: "multicall",
|
|
196
196
|
args: [creditAccount, calls, tokensToRegister, signaturesToCache]
|
|
@@ -220,11 +220,33 @@ class SecuritizeRWAFactory extends import_base.BaseContract {
|
|
|
220
220
|
requiredSignatures
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* {@inheritDoc IRWAFactory.getMissingRequirements}
|
|
225
|
+
*
|
|
226
|
+
* A required signature is omitted when `providedArgs.signaturesToCache`
|
|
227
|
+
* already carries a signature for the same token: the transaction caches it
|
|
228
|
+
* on-chain as part of the operation.
|
|
229
|
+
*/
|
|
230
|
+
getMissingRequirements(requirements, providedArgs) {
|
|
231
|
+
const providedTokens = new import_utils.AddressSet(
|
|
232
|
+
(providedArgs?.signaturesToCache ?? []).map((s) => s.token)
|
|
233
|
+
);
|
|
234
|
+
const requiredSignatures = requirements.requiredSignatures.filter(
|
|
235
|
+
(message) => !providedTokens.has(message.message.token)
|
|
236
|
+
);
|
|
237
|
+
if (requiredSignatures.length === 0) {
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
type: import_constants.RWA_FACTORY_SECURITIZE,
|
|
242
|
+
requiredSignatures
|
|
243
|
+
};
|
|
244
|
+
}
|
|
223
245
|
/**
|
|
224
246
|
* {@inheritDoc IRWAFactory.openCreditAccount}
|
|
225
247
|
*/
|
|
226
|
-
openCreditAccount(creditManager, calls,
|
|
227
|
-
const { tokensToRegister = [], signaturesToCache = [] } =
|
|
248
|
+
openCreditAccount(creditManager, calls, args) {
|
|
249
|
+
const { tokensToRegister = [], signaturesToCache = [] } = args ?? {};
|
|
228
250
|
return this.createRawTx({
|
|
229
251
|
functionName: "openCreditAccount",
|
|
230
252
|
args: [creditManager, calls, tokensToRegister, signaturesToCache]
|
|
@@ -38,6 +38,13 @@ class AddressSet extends Set {
|
|
|
38
38
|
has(value) {
|
|
39
39
|
return super.has((0, import_viem.getAddress)(value));
|
|
40
40
|
}
|
|
41
|
+
difference(other) {
|
|
42
|
+
const result = new AddressSet(this.keys());
|
|
43
|
+
for (const key of other) {
|
|
44
|
+
result.delete((0, import_viem.getAddress)(key));
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
41
48
|
/**
|
|
42
49
|
* Returns all addresses as an array.
|
|
43
50
|
**/
|
|
@@ -21,12 +21,15 @@ function parseSecuritizeOperationCalldata(props) {
|
|
|
21
21
|
const functionName = parsed.functionName.split("(")[0];
|
|
22
22
|
const { rawArgs } = parsed;
|
|
23
23
|
const innerCalls = rawArgs.calls ?? [];
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const args = {
|
|
25
|
+
type: RWA_FACTORY_SECURITIZE,
|
|
26
|
+
tokensToRegister: [
|
|
27
|
+
...rawArgs.tokensToRegister ?? []
|
|
28
|
+
],
|
|
29
|
+
signaturesToCache: [
|
|
30
|
+
...rawArgs.signaturesToCache ?? []
|
|
31
|
+
]
|
|
32
|
+
};
|
|
30
33
|
const suite = functionName === "openCreditAccount" ? sdk.marketRegister.findCreditManager(rawArgs.creditManager) : resolveSuiteForMulticall(sdk, factory, innerCalls);
|
|
31
34
|
const metadata = {
|
|
32
35
|
factory: factory.address,
|
|
@@ -41,19 +44,17 @@ function parseSecuritizeOperationCalldata(props) {
|
|
|
41
44
|
case "openCreditAccount":
|
|
42
45
|
return {
|
|
43
46
|
...metadata,
|
|
44
|
-
operation: "
|
|
47
|
+
operation: "RWAOpenCreditAccount",
|
|
45
48
|
multicall,
|
|
46
|
-
|
|
47
|
-
signaturesToCache
|
|
49
|
+
args
|
|
48
50
|
};
|
|
49
51
|
case "multicall":
|
|
50
52
|
return {
|
|
51
53
|
...metadata,
|
|
52
|
-
operation: "
|
|
54
|
+
operation: "RWAMulticall",
|
|
53
55
|
creditAccount: rawArgs.creditAccount,
|
|
54
56
|
multicall,
|
|
55
|
-
|
|
56
|
-
signaturesToCache
|
|
57
|
+
args
|
|
57
58
|
};
|
|
58
59
|
default:
|
|
59
60
|
throw new Error(
|
|
@@ -6,7 +6,7 @@ function isPoolOperation(tx) {
|
|
|
6
6
|
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
7
7
|
}
|
|
8
8
|
function isRWAOperation(tx) {
|
|
9
|
-
return tx.operation === "
|
|
9
|
+
return tx.operation === "RWAOpenCreditAccount" || tx.operation === "RWAMulticall";
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
12
12
|
isPoolOperation,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { erc20Abi } from "viem";
|
|
2
|
-
import {
|
|
3
|
-
Prerequisite,
|
|
4
|
-
toPrerequisiteError
|
|
5
|
-
} from "./Prerequisite.js";
|
|
2
|
+
import { Prerequisite } from "./Prerequisite.js";
|
|
6
3
|
class AllowancePrerequisite extends Prerequisite {
|
|
7
4
|
#id;
|
|
8
5
|
#title;
|
|
@@ -30,22 +27,16 @@ class AllowancePrerequisite extends Prerequisite {
|
|
|
30
27
|
get detail() {
|
|
31
28
|
return this.#detail;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
resolve(slice) {
|
|
44
|
-
const res = slice[0];
|
|
45
|
-
if (!res || res.status === "failure") {
|
|
46
|
-
return this.errorResult(toPrerequisiteError(res?.error));
|
|
47
|
-
}
|
|
48
|
-
const actual = res.result;
|
|
30
|
+
async check(ctx) {
|
|
31
|
+
const actual = await ctx.sdk.client.readContract({
|
|
32
|
+
address: this.#detail.token,
|
|
33
|
+
abi: erc20Abi,
|
|
34
|
+
functionName: "allowance",
|
|
35
|
+
args: [this.#detail.owner, this.#detail.spender],
|
|
36
|
+
// `undefined` lets viem read at `latest`; `blockNumber` is only set for
|
|
37
|
+
// testnet forks pinned to a specific block.
|
|
38
|
+
blockNumber: ctx.blockNumber
|
|
39
|
+
});
|
|
49
40
|
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
50
41
|
...this.#detail,
|
|
51
42
|
actual
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { erc20Abi } from "viem";
|
|
2
|
-
import { iMulticall3Abi } from "../../abi/iMulticall3.js";
|
|
3
2
|
import { hexEq, NATIVE_ADDRESS } from "../../sdk/index.js";
|
|
4
|
-
import {
|
|
5
|
-
Prerequisite,
|
|
6
|
-
toPrerequisiteError
|
|
7
|
-
} from "./Prerequisite.js";
|
|
3
|
+
import { Prerequisite } from "./Prerequisite.js";
|
|
8
4
|
class BalancePrerequisite extends Prerequisite {
|
|
9
5
|
#id;
|
|
10
6
|
#title;
|
|
@@ -31,43 +27,28 @@ class BalancePrerequisite extends Prerequisite {
|
|
|
31
27
|
get detail() {
|
|
32
28
|
return this.#detail;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const multicall3 = ctx.sdk.client.chain.contracts?.multicall3?.address;
|
|
37
|
-
if (!multicall3) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
"multicall3 is not configured for this chain, cannot read native balance"
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return [
|
|
43
|
-
{
|
|
44
|
-
address: multicall3,
|
|
45
|
-
abi: iMulticall3Abi,
|
|
46
|
-
functionName: "getEthBalance",
|
|
47
|
-
args: [this.#detail.owner]
|
|
48
|
-
}
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
return [
|
|
52
|
-
{
|
|
53
|
-
address: this.#detail.token,
|
|
54
|
-
abi: erc20Abi,
|
|
55
|
-
functionName: "balanceOf",
|
|
56
|
-
args: [this.#detail.owner]
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
}
|
|
60
|
-
resolve(slice) {
|
|
61
|
-
const res = slice[0];
|
|
62
|
-
if (!res || res.status === "failure") {
|
|
63
|
-
return this.errorResult(toPrerequisiteError(res?.error));
|
|
64
|
-
}
|
|
65
|
-
const actual = res.result;
|
|
30
|
+
async check(ctx) {
|
|
31
|
+
const actual = await this.#readBalance(ctx);
|
|
66
32
|
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
67
33
|
...this.#detail,
|
|
68
34
|
actual
|
|
69
35
|
});
|
|
70
36
|
}
|
|
37
|
+
async #readBalance(ctx) {
|
|
38
|
+
if (hexEq(this.#detail.token, NATIVE_ADDRESS)) {
|
|
39
|
+
return ctx.sdk.client.getBalance({
|
|
40
|
+
address: this.#detail.owner,
|
|
41
|
+
blockNumber: ctx.blockNumber
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return ctx.sdk.client.readContract({
|
|
45
|
+
address: this.#detail.token,
|
|
46
|
+
abi: erc20Abi,
|
|
47
|
+
functionName: "balanceOf",
|
|
48
|
+
args: [this.#detail.owner],
|
|
49
|
+
blockNumber: ctx.blockNumber
|
|
50
|
+
});
|
|
51
|
+
}
|
|
71
52
|
}
|
|
72
53
|
export {
|
|
73
54
|
BalancePrerequisite
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseError,
|
|
3
|
-
ContractFunctionRevertedError
|
|
4
|
-
} from "viem";
|
|
1
|
+
import { BaseError, ContractFunctionRevertedError } from "viem";
|
|
5
2
|
function toPrerequisiteError(cause) {
|
|
6
3
|
if (cause instanceof BaseError) {
|
|
7
4
|
const reverted = cause.walk(
|
|
@@ -22,19 +19,16 @@ function toPrerequisiteError(cause) {
|
|
|
22
19
|
}
|
|
23
20
|
class Prerequisite {
|
|
24
21
|
/**
|
|
25
|
-
* Verifies this prerequisite
|
|
26
|
-
*
|
|
22
|
+
* Verifies this prerequisite. Never rejects: any error thrown by
|
|
23
|
+
* {@link check} (revert, RPC/network failure, compressor error) is
|
|
24
|
+
* normalized into an `error` result.
|
|
27
25
|
*/
|
|
28
26
|
async verify(ctx) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// testnet forks pinned to a specific block.
|
|
35
|
-
blockNumber: ctx.blockNumber
|
|
36
|
-
});
|
|
37
|
-
return this.resolve(results);
|
|
27
|
+
try {
|
|
28
|
+
return await this.check(ctx);
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
return this.errorResult(cause);
|
|
31
|
+
}
|
|
38
32
|
}
|
|
39
33
|
/** Builds a successful result; `detail` carries the on-chain `actual`. */
|
|
40
34
|
satisfiedResult(satisfied, detail) {
|
|
@@ -46,18 +40,17 @@ class Prerequisite {
|
|
|
46
40
|
satisfied
|
|
47
41
|
};
|
|
48
42
|
}
|
|
49
|
-
/** Builds a failed result from a
|
|
50
|
-
errorResult(
|
|
43
|
+
/** Builds a failed result from a raw read error (normalized internally). */
|
|
44
|
+
errorResult(cause) {
|
|
51
45
|
return {
|
|
52
46
|
id: this.id,
|
|
53
47
|
kind: this.kind,
|
|
54
48
|
title: this.title,
|
|
55
49
|
detail: this.detail,
|
|
56
|
-
error
|
|
50
|
+
error: toPrerequisiteError(cause)
|
|
57
51
|
};
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
54
|
export {
|
|
61
|
-
Prerequisite
|
|
62
|
-
toPrerequisiteError
|
|
55
|
+
Prerequisite
|
|
63
56
|
};
|
|
@@ -3,11 +3,17 @@ class RWAOpenRequirementsPrerequisite extends Prerequisite {
|
|
|
3
3
|
#id;
|
|
4
4
|
#title;
|
|
5
5
|
#detail;
|
|
6
|
+
#providedArgs;
|
|
6
7
|
constructor(props) {
|
|
7
8
|
super();
|
|
8
9
|
this.#id = props.id ?? `rwaOpenRequirements:${props.factory}:${props.token}`;
|
|
9
10
|
this.#title = props.title ?? "RWA account requirements fulfilled";
|
|
10
|
-
this.#detail =
|
|
11
|
+
this.#detail = {
|
|
12
|
+
token: props.token,
|
|
13
|
+
creditManager: props.creditManager,
|
|
14
|
+
factory: props.factory
|
|
15
|
+
};
|
|
16
|
+
this.#providedArgs = props.providedArgs;
|
|
11
17
|
}
|
|
12
18
|
get id() {
|
|
13
19
|
return this.#id;
|
|
@@ -21,20 +27,35 @@ class RWAOpenRequirementsPrerequisite extends Prerequisite {
|
|
|
21
27
|
get detail() {
|
|
22
28
|
return this.#detail;
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
async check(ctx) {
|
|
31
|
+
const requirements = await ctx.sdk.accounts.getOpenAccountRequirements(
|
|
32
|
+
ctx.wallet,
|
|
33
|
+
this.#detail.creditManager,
|
|
34
|
+
{ tokenOutAddress: this.#detail.token }
|
|
35
|
+
);
|
|
36
|
+
if (!requirements) {
|
|
37
|
+
return this.satisfiedResult(true, this.#detail);
|
|
38
|
+
}
|
|
39
|
+
const { rwaFactory } = ctx.sdk.marketRegister.findByCreditManager(
|
|
40
|
+
this.#detail.creditManager
|
|
41
|
+
);
|
|
42
|
+
if (!rwaFactory) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`no RWA factory found for credit manager ${this.#detail.creditManager}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const missing = rwaFactory.getMissingRequirements(
|
|
48
|
+
requirements,
|
|
49
|
+
this.#providedArgs
|
|
50
|
+
);
|
|
51
|
+
return this.satisfiedResult(
|
|
52
|
+
!missing && requirements.securitizeTokensToRegister.length === 0,
|
|
53
|
+
{
|
|
54
|
+
...this.#detail,
|
|
55
|
+
requirements,
|
|
56
|
+
missing
|
|
57
|
+
}
|
|
58
|
+
);
|
|
38
59
|
}
|
|
39
60
|
}
|
|
40
61
|
export {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssetsMap
|
|
3
|
+
} from "../../sdk/index.js";
|
|
4
|
+
import { allowanceAndBalance } from "./helpers.js";
|
|
5
|
+
async function buildCollateralPrerequisites(spenderOptions, multicall, ctx) {
|
|
6
|
+
const { sdk, wallet } = ctx;
|
|
7
|
+
const required = new AssetsMap();
|
|
8
|
+
for (const op of multicall) {
|
|
9
|
+
if (op.operation !== "AddCollateral" || op.amount === 0n) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
required.inc(op.token, op.amount);
|
|
13
|
+
}
|
|
14
|
+
if (required.size === 0) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
|
|
18
|
+
const prereqs = [];
|
|
19
|
+
for (const [token, amount] of required.entries()) {
|
|
20
|
+
prereqs.push(
|
|
21
|
+
...allowanceAndBalance({
|
|
22
|
+
token,
|
|
23
|
+
owner: wallet,
|
|
24
|
+
spender,
|
|
25
|
+
required: amount,
|
|
26
|
+
allowanceTitle: "Collateral approved",
|
|
27
|
+
balanceTitle: "Sufficient collateral balance"
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return prereqs;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
buildCollateralPrerequisites
|
|
35
|
+
};
|