@gearbox-protocol/sdk 14.12.0-next.3 → 14.12.0-next.4
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/parseOperationCalldata.js +1 -1
- package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +24 -8
- 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 +13 -13
- package/dist/cjs/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +66 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +71 -12
- package/dist/cjs/preview/prerequisites/index.js +2 -0
- package/dist/cjs/preview/simulate/index.js +5 -2
- package/dist/cjs/preview/simulate/simulateOperation.js +4 -0
- 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/esm/preview/parse/parseOperationCalldata.js +2 -2
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +27 -9
- 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 +13 -13
- package/dist/esm/preview/prerequisites/RWAOpenRequirementsPrerequisite.js +42 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +73 -12
- package/dist/esm/preview/prerequisites/index.js +1 -0
- package/dist/esm/preview/simulate/index.js +3 -1
- package/dist/esm/preview/simulate/simulateOperation.js +8 -1
- 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/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +10 -11
- package/dist/types/preview/parse/types-rwa.d.ts +60 -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 +1 -3
- package/dist/types/preview/prerequisites/RWAOpenRequirementsPrerequisite.d.ts +36 -0
- package/dist/types/preview/prerequisites/index.d.ts +1 -0
- package/dist/types/preview/prerequisites/types.d.ts +10 -8
- package/dist/types/preview/simulate/index.d.ts +2 -0
- package/dist/types/preview/simulate/simulateRWAOperation.d.ts +25 -0
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +4 -0
- package/dist/types/sdk/market/rwa/types.d.ts +13 -5
- package/package.json +1 -1
|
@@ -68,7 +68,7 @@ function parseOperationCalldata(input) {
|
|
|
68
68
|
calldata
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
if (contract
|
|
71
|
+
if (contract && (0, import_sdk.isRWAFactory)(contract)) {
|
|
72
72
|
return (0, import_parseRWAFactoryOperationCalldata.parseRWAFactoryOperationCalldata)({
|
|
73
73
|
sdk,
|
|
74
74
|
factory: contract,
|
|
@@ -21,19 +21,34 @@ __export(parseRWAFactoryOperationCalldata_exports, {
|
|
|
21
21
|
parseRWAFactoryOperationCalldata: () => parseRWAFactoryOperationCalldata
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(parseRWAFactoryOperationCalldata_exports);
|
|
24
|
-
var import_viem = require("viem");
|
|
25
24
|
var import_adapters = require("../../plugins/adapters/index.js");
|
|
26
25
|
var import_sdk = require("../../sdk/index.js");
|
|
27
26
|
var import_classifyInnerOperations = require("./classifyInnerOperations.js");
|
|
28
27
|
var import_extractExpectedBalanceChanges = require("./extractExpectedBalanceChanges.js");
|
|
29
28
|
function parseRWAFactoryOperationCalldata(props) {
|
|
29
|
+
const { contractType, address } = props.factory;
|
|
30
|
+
if ((0, import_sdk.isRWAFactory)(props.factory, import_sdk.RWA_FACTORY_SECURITIZE)) {
|
|
31
|
+
return parseSecuritizeOperationCalldata(props);
|
|
32
|
+
}
|
|
33
|
+
throw new Error(
|
|
34
|
+
`unsupported RWA factory type "${contractType}" on ${address}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
function parseSecuritizeOperationCalldata(props) {
|
|
30
38
|
const { sdk, factory, calldata } = props;
|
|
31
39
|
const parsed = sdk.parseFunctionDataV2(factory.address, calldata);
|
|
32
40
|
const functionName = parsed.functionName.split("(")[0];
|
|
33
41
|
const { rawArgs } = parsed;
|
|
34
42
|
const innerCalls = rawArgs.calls ?? [];
|
|
43
|
+
const tokensToRegister = [
|
|
44
|
+
...rawArgs.tokensToRegister ?? []
|
|
45
|
+
];
|
|
46
|
+
const signaturesToCache = [
|
|
47
|
+
...rawArgs.signaturesToCache ?? []
|
|
48
|
+
];
|
|
35
49
|
const suite = functionName === "openCreditAccount" ? sdk.marketRegister.findCreditManager(rawArgs.creditManager) : resolveSuiteForMulticall(sdk, factory, innerCalls);
|
|
36
50
|
const metadata = {
|
|
51
|
+
factory: factory.address,
|
|
37
52
|
creditManager: suite.creditManager.address,
|
|
38
53
|
creditFacade: suite.creditFacade.address
|
|
39
54
|
};
|
|
@@ -46,20 +61,21 @@ function parseRWAFactoryOperationCalldata(props) {
|
|
|
46
61
|
case "openCreditAccount":
|
|
47
62
|
return {
|
|
48
63
|
...metadata,
|
|
49
|
-
operation: "
|
|
50
|
-
creditAccount: import_viem.zeroAddress,
|
|
51
|
-
onBehalfOf: import_viem.zeroAddress,
|
|
52
|
-
referralCode: 0n,
|
|
64
|
+
operation: "SecuritizeOpenCreditAccount",
|
|
53
65
|
multicall,
|
|
54
|
-
expectedBalanceChanges
|
|
66
|
+
expectedBalanceChanges,
|
|
67
|
+
tokensToRegister,
|
|
68
|
+
signaturesToCache
|
|
55
69
|
};
|
|
56
70
|
case "multicall":
|
|
57
71
|
return {
|
|
58
72
|
...metadata,
|
|
59
|
-
operation: "
|
|
73
|
+
operation: "SecuritizeMulticall",
|
|
60
74
|
creditAccount: rawArgs.creditAccount,
|
|
61
75
|
multicall,
|
|
62
|
-
expectedBalanceChanges
|
|
76
|
+
expectedBalanceChanges,
|
|
77
|
+
tokensToRegister,
|
|
78
|
+
signaturesToCache
|
|
63
79
|
};
|
|
64
80
|
default:
|
|
65
81
|
throw new Error(
|
|
@@ -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_rwa_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_rwa_exports);
|
|
@@ -19,19 +19,26 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var types_exports = {};
|
|
21
21
|
__export(types_exports, {
|
|
22
|
-
isPoolOperation: () => isPoolOperation
|
|
22
|
+
isPoolOperation: () => isPoolOperation,
|
|
23
|
+
isRWAOperation: () => isRWAOperation
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(types_exports);
|
|
25
26
|
__reExport(types_exports, require("./types-adapters.js"), module.exports);
|
|
26
27
|
__reExport(types_exports, require("./types-facades.js"), module.exports);
|
|
27
28
|
__reExport(types_exports, require("./types-pools.js"), module.exports);
|
|
29
|
+
__reExport(types_exports, require("./types-rwa.js"), module.exports);
|
|
28
30
|
function isPoolOperation(tx) {
|
|
29
31
|
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
30
32
|
}
|
|
33
|
+
function isRWAOperation(tx) {
|
|
34
|
+
return tx.operation === "SecuritizeOpenCreditAccount" || tx.operation === "SecuritizeMulticall";
|
|
35
|
+
}
|
|
31
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
37
|
0 && (module.exports = {
|
|
33
38
|
isPoolOperation,
|
|
39
|
+
isRWAOperation,
|
|
34
40
|
...require("./types-adapters.js"),
|
|
35
41
|
...require("./types-facades.js"),
|
|
36
|
-
...require("./types-pools.js")
|
|
42
|
+
...require("./types-pools.js"),
|
|
43
|
+
...require("./types-rwa.js")
|
|
37
44
|
});
|
|
@@ -24,14 +24,14 @@ module.exports = __toCommonJS(AllowancePrerequisite_exports);
|
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
var import_Prerequisite = require("./Prerequisite.js");
|
|
26
26
|
class AllowancePrerequisite extends import_Prerequisite.Prerequisite {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
#id;
|
|
28
|
+
#title;
|
|
29
|
+
#detail;
|
|
30
30
|
constructor(props) {
|
|
31
31
|
super();
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
32
|
+
this.#id = props.id ?? `allowance:${props.token}:${props.owner}:${props.spender}`;
|
|
33
|
+
this.#title = props.title ?? "Token approval";
|
|
34
|
+
this.#detail = {
|
|
35
35
|
token: props.token,
|
|
36
36
|
owner: props.owner,
|
|
37
37
|
spender: props.spender,
|
|
@@ -39,24 +39,24 @@ class AllowancePrerequisite extends import_Prerequisite.Prerequisite {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
get id() {
|
|
42
|
-
return this
|
|
42
|
+
return this.#id;
|
|
43
43
|
}
|
|
44
44
|
get kind() {
|
|
45
45
|
return "allowance";
|
|
46
46
|
}
|
|
47
47
|
get title() {
|
|
48
|
-
return this
|
|
48
|
+
return this.#title;
|
|
49
49
|
}
|
|
50
50
|
get detail() {
|
|
51
|
-
return this
|
|
51
|
+
return this.#detail;
|
|
52
52
|
}
|
|
53
53
|
calls() {
|
|
54
54
|
return [
|
|
55
55
|
{
|
|
56
|
-
address: this.
|
|
56
|
+
address: this.#detail.token,
|
|
57
57
|
abi: import_viem.erc20Abi,
|
|
58
58
|
functionName: "allowance",
|
|
59
|
-
args: [this.
|
|
59
|
+
args: [this.#detail.owner, this.#detail.spender]
|
|
60
60
|
}
|
|
61
61
|
];
|
|
62
62
|
}
|
|
@@ -66,8 +66,8 @@ class AllowancePrerequisite extends import_Prerequisite.Prerequisite {
|
|
|
66
66
|
return this.errorResult((0, import_Prerequisite.toPrerequisiteError)(res?.error));
|
|
67
67
|
}
|
|
68
68
|
const actual = res.result;
|
|
69
|
-
return this.satisfiedResult(actual >= this.
|
|
70
|
-
...this
|
|
69
|
+
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
70
|
+
...this.#detail,
|
|
71
71
|
actual
|
|
72
72
|
});
|
|
73
73
|
}
|
|
@@ -24,38 +24,38 @@ module.exports = __toCommonJS(BalancePrerequisite_exports);
|
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
var import_Prerequisite = require("./Prerequisite.js");
|
|
26
26
|
class BalancePrerequisite extends import_Prerequisite.Prerequisite {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
#id;
|
|
28
|
+
#title;
|
|
29
|
+
#detail;
|
|
30
30
|
constructor(props) {
|
|
31
31
|
super();
|
|
32
|
-
this
|
|
33
|
-
this
|
|
34
|
-
this
|
|
32
|
+
this.#id = props.id ?? `balance:${props.token}:${props.owner}`;
|
|
33
|
+
this.#title = props.title ?? "Sufficient balance";
|
|
34
|
+
this.#detail = {
|
|
35
35
|
token: props.token,
|
|
36
36
|
owner: props.owner,
|
|
37
37
|
required: props.required
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
get id() {
|
|
41
|
-
return this
|
|
41
|
+
return this.#id;
|
|
42
42
|
}
|
|
43
43
|
get kind() {
|
|
44
44
|
return "balance";
|
|
45
45
|
}
|
|
46
46
|
get title() {
|
|
47
|
-
return this
|
|
47
|
+
return this.#title;
|
|
48
48
|
}
|
|
49
49
|
get detail() {
|
|
50
|
-
return this
|
|
50
|
+
return this.#detail;
|
|
51
51
|
}
|
|
52
52
|
calls() {
|
|
53
53
|
return [
|
|
54
54
|
{
|
|
55
|
-
address: this.
|
|
55
|
+
address: this.#detail.token,
|
|
56
56
|
abi: import_viem.erc20Abi,
|
|
57
57
|
functionName: "balanceOf",
|
|
58
|
-
args: [this.
|
|
58
|
+
args: [this.#detail.owner]
|
|
59
59
|
}
|
|
60
60
|
];
|
|
61
61
|
}
|
|
@@ -65,8 +65,8 @@ class BalancePrerequisite extends import_Prerequisite.Prerequisite {
|
|
|
65
65
|
return this.errorResult((0, import_Prerequisite.toPrerequisiteError)(res?.error));
|
|
66
66
|
}
|
|
67
67
|
const actual = res.result;
|
|
68
|
-
return this.satisfiedResult(actual >= this.
|
|
69
|
-
...this
|
|
68
|
+
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
69
|
+
...this.#detail,
|
|
70
70
|
actual
|
|
71
71
|
});
|
|
72
72
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 RWAOpenRequirementsPrerequisite_exports = {};
|
|
20
|
+
__export(RWAOpenRequirementsPrerequisite_exports, {
|
|
21
|
+
RWAOpenRequirementsPrerequisite: () => RWAOpenRequirementsPrerequisite
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(RWAOpenRequirementsPrerequisite_exports);
|
|
24
|
+
var import_Prerequisite = require("./Prerequisite.js");
|
|
25
|
+
class RWAOpenRequirementsPrerequisite extends import_Prerequisite.Prerequisite {
|
|
26
|
+
#id;
|
|
27
|
+
#title;
|
|
28
|
+
#detail;
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super();
|
|
31
|
+
this.#id = props.id ?? `rwaOpenRequirements:${props.factory}:${props.token}`;
|
|
32
|
+
this.#title = props.title ?? "RWA account requirements fulfilled";
|
|
33
|
+
this.#detail = props.requirements;
|
|
34
|
+
}
|
|
35
|
+
get id() {
|
|
36
|
+
return this.#id;
|
|
37
|
+
}
|
|
38
|
+
get kind() {
|
|
39
|
+
return "rwaOpenRequirements";
|
|
40
|
+
}
|
|
41
|
+
get title() {
|
|
42
|
+
return this.#title;
|
|
43
|
+
}
|
|
44
|
+
get detail() {
|
|
45
|
+
return this.#detail;
|
|
46
|
+
}
|
|
47
|
+
/** Pre-resolved: no on-chain reads to contribute. */
|
|
48
|
+
calls() {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
resolve() {
|
|
52
|
+
return this.satisfiedResult(this.#satisfied(), this.#detail);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Satisfied when the borrower has nothing left to do: no tokens pending
|
|
56
|
+
* issuer-side registration and no messages left to sign.
|
|
57
|
+
*/
|
|
58
|
+
#satisfied() {
|
|
59
|
+
const { securitizeTokensToRegister, requiredSignatures } = this.#detail;
|
|
60
|
+
return securitizeTokensToRegister.length === 0 && requiredSignatures.length === 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
RWAOpenRequirementsPrerequisite
|
|
66
|
+
});
|
|
@@ -22,8 +22,10 @@ __export(buildPrerequisites_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(buildPrerequisites_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
26
|
var import_AllowancePrerequisite = require("./AllowancePrerequisite.js");
|
|
26
27
|
var import_BalancePrerequisite = require("./BalancePrerequisite.js");
|
|
28
|
+
var import_RWAOpenRequirementsPrerequisite = require("./RWAOpenRequirementsPrerequisite.js");
|
|
27
29
|
async function buildPrerequisites(tx, ctx) {
|
|
28
30
|
const { wallet } = ctx;
|
|
29
31
|
switch (tx.operation) {
|
|
@@ -151,10 +153,34 @@ async function buildPrerequisites(tx, ctx) {
|
|
|
151
153
|
case "CloseCreditAccount":
|
|
152
154
|
case "LiquidateCreditAccount":
|
|
153
155
|
return collateralPrerequisites(
|
|
154
|
-
tx.operation,
|
|
156
|
+
tx.operation === "OpenCreditAccount" ? { creditManager: tx.creditManager, borrower: wallet } : {
|
|
157
|
+
creditManager: tx.creditManager,
|
|
158
|
+
creditAccount: tx.creditAccount
|
|
159
|
+
},
|
|
160
|
+
tx.multicall,
|
|
161
|
+
ctx
|
|
162
|
+
);
|
|
163
|
+
// RWA-factory operations: same collateral checks as facade operations,
|
|
164
|
+
// plus (for opening) the factory's open-account requirements. The parsed
|
|
165
|
+
// operation carries template (empty) `tokensToRegister`/`signaturesToCache`;
|
|
166
|
+
// the prerequisite detail provides the real values.
|
|
167
|
+
case "SecuritizeOpenCreditAccount":
|
|
168
|
+
return [
|
|
169
|
+
...await collateralPrerequisites(
|
|
170
|
+
{ creditManager: tx.creditManager, borrower: wallet },
|
|
171
|
+
tx.multicall,
|
|
172
|
+
ctx
|
|
173
|
+
),
|
|
174
|
+
...await rwaOpenRequirementsPrerequisites(
|
|
175
|
+
tx.multicall,
|
|
176
|
+
tx.creditManager,
|
|
177
|
+
ctx
|
|
178
|
+
)
|
|
179
|
+
];
|
|
180
|
+
case "SecuritizeMulticall":
|
|
181
|
+
return collateralPrerequisites(
|
|
182
|
+
{ creditManager: tx.creditManager, creditAccount: tx.creditAccount },
|
|
155
183
|
tx.multicall,
|
|
156
|
-
tx.creditManager,
|
|
157
|
-
tx.creditAccount,
|
|
158
184
|
ctx
|
|
159
185
|
);
|
|
160
186
|
case "PartiallyLiquidateCreditAccount": {
|
|
@@ -182,26 +208,24 @@ async function buildPrerequisites(tx, ctx) {
|
|
|
182
208
|
return [];
|
|
183
209
|
}
|
|
184
210
|
}
|
|
185
|
-
async function collateralPrerequisites(
|
|
211
|
+
async function collateralPrerequisites(spenderOptions, multicall, ctx) {
|
|
186
212
|
const { sdk, wallet } = ctx;
|
|
187
213
|
const required = /* @__PURE__ */ new Map();
|
|
188
|
-
for (const
|
|
189
|
-
if (
|
|
214
|
+
for (const op of multicall) {
|
|
215
|
+
if (op.operation !== "AddCollateral" || op.amount === 0n) {
|
|
190
216
|
continue;
|
|
191
217
|
}
|
|
192
|
-
const key =
|
|
218
|
+
const key = op.token.toLowerCase();
|
|
193
219
|
const existing = required.get(key);
|
|
194
220
|
required.set(key, {
|
|
195
|
-
token:
|
|
196
|
-
amount: (existing?.amount ?? 0n) +
|
|
221
|
+
token: op.token,
|
|
222
|
+
amount: (existing?.amount ?? 0n) + op.amount
|
|
197
223
|
});
|
|
198
224
|
}
|
|
199
225
|
if (required.size === 0) {
|
|
200
226
|
return [];
|
|
201
227
|
}
|
|
202
|
-
const spender = await sdk.accounts.getApprovalAddress(
|
|
203
|
-
op === "OpenCreditAccount" ? { creditManager, borrower: wallet } : { creditManager, creditAccount }
|
|
204
|
-
);
|
|
228
|
+
const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
|
|
205
229
|
const prereqs = [];
|
|
206
230
|
for (const { token, amount } of required.values()) {
|
|
207
231
|
prereqs.push(
|
|
@@ -222,6 +246,41 @@ async function collateralPrerequisites(op, multicall, creditManager, creditAccou
|
|
|
222
246
|
}
|
|
223
247
|
return prereqs;
|
|
224
248
|
}
|
|
249
|
+
async function rwaOpenRequirementsPrerequisites(multicall, creditManager, ctx) {
|
|
250
|
+
const { sdk, wallet } = ctx;
|
|
251
|
+
const { rwaFactory } = sdk.marketRegister.findByCreditManager(creditManager);
|
|
252
|
+
if (!rwaFactory) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const rwaTokens = new import_sdk.AddressSet(rwaFactory.getTokens());
|
|
256
|
+
const candidates = new import_sdk.AddressSet();
|
|
257
|
+
for (const op of multicall) {
|
|
258
|
+
if (op.operation === "AddCollateral" || op.operation === "UpdateQuota") {
|
|
259
|
+
candidates.add(op.token);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const prereqs = [];
|
|
263
|
+
for (const token of candidates) {
|
|
264
|
+
if (!rwaTokens.has(token)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const requirements = await sdk.accounts.getOpenAccountRequirements(
|
|
268
|
+
wallet,
|
|
269
|
+
creditManager,
|
|
270
|
+
{ tokenOutAddress: token }
|
|
271
|
+
);
|
|
272
|
+
if (requirements) {
|
|
273
|
+
prereqs.push(
|
|
274
|
+
new import_RWAOpenRequirementsPrerequisite.RWAOpenRequirementsPrerequisite({
|
|
275
|
+
requirements,
|
|
276
|
+
token,
|
|
277
|
+
factory: rwaFactory.address
|
|
278
|
+
})
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return prereqs;
|
|
283
|
+
}
|
|
225
284
|
function underlyingOf(sdk, creditManager) {
|
|
226
285
|
const suite = sdk.marketRegister.creditManagers.find(
|
|
227
286
|
(cm) => (0, import_viem.isAddressEqual)(cm.creditManager.address, creditManager)
|
|
@@ -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
|
});
|
|
@@ -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:
|
|
@@ -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 = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CreditFacadeV310Contract,
|
|
3
|
+
isRWAFactory,
|
|
3
4
|
PoolV310Contract,
|
|
4
|
-
SecuritizeRWAFactory,
|
|
5
5
|
ZapperContract
|
|
6
6
|
} from "../../sdk/index.js";
|
|
7
7
|
import { UnsupportedTargetError } from "./errors.js";
|
|
@@ -50,7 +50,7 @@ function parseOperationCalldata(input) {
|
|
|
50
50
|
calldata
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
if (contract
|
|
53
|
+
if (contract && isRWAFactory(contract)) {
|
|
54
54
|
return parseRWAFactoryOperationCalldata({
|
|
55
55
|
sdk,
|
|
56
56
|
factory: contract,
|
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import { zeroAddress } from "viem";
|
|
2
1
|
import { AbstractAdapterContract } from "../../plugins/adapters/index.js";
|
|
3
2
|
import {
|
|
4
3
|
CreditFacadeV310Contract,
|
|
5
|
-
hexEq
|
|
4
|
+
hexEq,
|
|
5
|
+
isRWAFactory,
|
|
6
|
+
RWA_FACTORY_SECURITIZE
|
|
6
7
|
} from "../../sdk/index.js";
|
|
7
8
|
import { classifyInnerOperations } from "./classifyInnerOperations.js";
|
|
8
9
|
import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
|
|
9
10
|
function parseRWAFactoryOperationCalldata(props) {
|
|
11
|
+
const { contractType, address } = props.factory;
|
|
12
|
+
if (isRWAFactory(props.factory, RWA_FACTORY_SECURITIZE)) {
|
|
13
|
+
return parseSecuritizeOperationCalldata(props);
|
|
14
|
+
}
|
|
15
|
+
throw new Error(
|
|
16
|
+
`unsupported RWA factory type "${contractType}" on ${address}`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
function parseSecuritizeOperationCalldata(props) {
|
|
10
20
|
const { sdk, factory, calldata } = props;
|
|
11
21
|
const parsed = sdk.parseFunctionDataV2(factory.address, calldata);
|
|
12
22
|
const functionName = parsed.functionName.split("(")[0];
|
|
13
23
|
const { rawArgs } = parsed;
|
|
14
24
|
const innerCalls = rawArgs.calls ?? [];
|
|
25
|
+
const tokensToRegister = [
|
|
26
|
+
...rawArgs.tokensToRegister ?? []
|
|
27
|
+
];
|
|
28
|
+
const signaturesToCache = [
|
|
29
|
+
...rawArgs.signaturesToCache ?? []
|
|
30
|
+
];
|
|
15
31
|
const suite = functionName === "openCreditAccount" ? sdk.marketRegister.findCreditManager(rawArgs.creditManager) : resolveSuiteForMulticall(sdk, factory, innerCalls);
|
|
16
32
|
const metadata = {
|
|
33
|
+
factory: factory.address,
|
|
17
34
|
creditManager: suite.creditManager.address,
|
|
18
35
|
creditFacade: suite.creditFacade.address
|
|
19
36
|
};
|
|
@@ -26,20 +43,21 @@ function parseRWAFactoryOperationCalldata(props) {
|
|
|
26
43
|
case "openCreditAccount":
|
|
27
44
|
return {
|
|
28
45
|
...metadata,
|
|
29
|
-
operation: "
|
|
30
|
-
creditAccount: zeroAddress,
|
|
31
|
-
onBehalfOf: zeroAddress,
|
|
32
|
-
referralCode: 0n,
|
|
46
|
+
operation: "SecuritizeOpenCreditAccount",
|
|
33
47
|
multicall,
|
|
34
|
-
expectedBalanceChanges
|
|
48
|
+
expectedBalanceChanges,
|
|
49
|
+
tokensToRegister,
|
|
50
|
+
signaturesToCache
|
|
35
51
|
};
|
|
36
52
|
case "multicall":
|
|
37
53
|
return {
|
|
38
54
|
...metadata,
|
|
39
|
-
operation: "
|
|
55
|
+
operation: "SecuritizeMulticall",
|
|
40
56
|
creditAccount: rawArgs.creditAccount,
|
|
41
57
|
multicall,
|
|
42
|
-
expectedBalanceChanges
|
|
58
|
+
expectedBalanceChanges,
|
|
59
|
+
tokensToRegister,
|
|
60
|
+
signaturesToCache
|
|
43
61
|
};
|
|
44
62
|
default:
|
|
45
63
|
throw new Error(
|
|
File without changes
|