@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
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export * from "./types-adapters.js";
|
|
2
2
|
export * from "./types-facades.js";
|
|
3
3
|
export * from "./types-pools.js";
|
|
4
|
+
export * from "./types-rwa.js";
|
|
4
5
|
function isPoolOperation(tx) {
|
|
5
6
|
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
6
7
|
}
|
|
8
|
+
function isRWAOperation(tx) {
|
|
9
|
+
return tx.operation === "SecuritizeOpenCreditAccount" || tx.operation === "SecuritizeMulticall";
|
|
10
|
+
}
|
|
7
11
|
export {
|
|
8
|
-
isPoolOperation
|
|
12
|
+
isPoolOperation,
|
|
13
|
+
isRWAOperation
|
|
9
14
|
};
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
toPrerequisiteError
|
|
5
5
|
} from "./Prerequisite.js";
|
|
6
6
|
class AllowancePrerequisite extends Prerequisite {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
#id;
|
|
8
|
+
#title;
|
|
9
|
+
#detail;
|
|
10
10
|
constructor(props) {
|
|
11
11
|
super();
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this
|
|
12
|
+
this.#id = props.id ?? `allowance:${props.token}:${props.owner}:${props.spender}`;
|
|
13
|
+
this.#title = props.title ?? "Token approval";
|
|
14
|
+
this.#detail = {
|
|
15
15
|
token: props.token,
|
|
16
16
|
owner: props.owner,
|
|
17
17
|
spender: props.spender,
|
|
@@ -19,24 +19,24 @@ class AllowancePrerequisite extends Prerequisite {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
get id() {
|
|
22
|
-
return this
|
|
22
|
+
return this.#id;
|
|
23
23
|
}
|
|
24
24
|
get kind() {
|
|
25
25
|
return "allowance";
|
|
26
26
|
}
|
|
27
27
|
get title() {
|
|
28
|
-
return this
|
|
28
|
+
return this.#title;
|
|
29
29
|
}
|
|
30
30
|
get detail() {
|
|
31
|
-
return this
|
|
31
|
+
return this.#detail;
|
|
32
32
|
}
|
|
33
33
|
calls() {
|
|
34
34
|
return [
|
|
35
35
|
{
|
|
36
|
-
address: this.
|
|
36
|
+
address: this.#detail.token,
|
|
37
37
|
abi: erc20Abi,
|
|
38
38
|
functionName: "allowance",
|
|
39
|
-
args: [this.
|
|
39
|
+
args: [this.#detail.owner, this.#detail.spender]
|
|
40
40
|
}
|
|
41
41
|
];
|
|
42
42
|
}
|
|
@@ -46,8 +46,8 @@ class AllowancePrerequisite extends Prerequisite {
|
|
|
46
46
|
return this.errorResult(toPrerequisiteError(res?.error));
|
|
47
47
|
}
|
|
48
48
|
const actual = res.result;
|
|
49
|
-
return this.satisfiedResult(actual >= this.
|
|
50
|
-
...this
|
|
49
|
+
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
50
|
+
...this.#detail,
|
|
51
51
|
actual
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -4,38 +4,38 @@ import {
|
|
|
4
4
|
toPrerequisiteError
|
|
5
5
|
} from "./Prerequisite.js";
|
|
6
6
|
class BalancePrerequisite extends Prerequisite {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
#id;
|
|
8
|
+
#title;
|
|
9
|
+
#detail;
|
|
10
10
|
constructor(props) {
|
|
11
11
|
super();
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this
|
|
12
|
+
this.#id = props.id ?? `balance:${props.token}:${props.owner}`;
|
|
13
|
+
this.#title = props.title ?? "Sufficient balance";
|
|
14
|
+
this.#detail = {
|
|
15
15
|
token: props.token,
|
|
16
16
|
owner: props.owner,
|
|
17
17
|
required: props.required
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
get id() {
|
|
21
|
-
return this
|
|
21
|
+
return this.#id;
|
|
22
22
|
}
|
|
23
23
|
get kind() {
|
|
24
24
|
return "balance";
|
|
25
25
|
}
|
|
26
26
|
get title() {
|
|
27
|
-
return this
|
|
27
|
+
return this.#title;
|
|
28
28
|
}
|
|
29
29
|
get detail() {
|
|
30
|
-
return this
|
|
30
|
+
return this.#detail;
|
|
31
31
|
}
|
|
32
32
|
calls() {
|
|
33
33
|
return [
|
|
34
34
|
{
|
|
35
|
-
address: this.
|
|
35
|
+
address: this.#detail.token,
|
|
36
36
|
abi: erc20Abi,
|
|
37
37
|
functionName: "balanceOf",
|
|
38
|
-
args: [this.
|
|
38
|
+
args: [this.#detail.owner]
|
|
39
39
|
}
|
|
40
40
|
];
|
|
41
41
|
}
|
|
@@ -45,8 +45,8 @@ class BalancePrerequisite extends Prerequisite {
|
|
|
45
45
|
return this.errorResult(toPrerequisiteError(res?.error));
|
|
46
46
|
}
|
|
47
47
|
const actual = res.result;
|
|
48
|
-
return this.satisfiedResult(actual >= this.
|
|
49
|
-
...this
|
|
48
|
+
return this.satisfiedResult(actual >= this.#detail.required, {
|
|
49
|
+
...this.#detail,
|
|
50
50
|
actual
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Prerequisite } from "./Prerequisite.js";
|
|
2
|
+
class RWAOpenRequirementsPrerequisite extends Prerequisite {
|
|
3
|
+
#id;
|
|
4
|
+
#title;
|
|
5
|
+
#detail;
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super();
|
|
8
|
+
this.#id = props.id ?? `rwaOpenRequirements:${props.factory}:${props.token}`;
|
|
9
|
+
this.#title = props.title ?? "RWA account requirements fulfilled";
|
|
10
|
+
this.#detail = props.requirements;
|
|
11
|
+
}
|
|
12
|
+
get id() {
|
|
13
|
+
return this.#id;
|
|
14
|
+
}
|
|
15
|
+
get kind() {
|
|
16
|
+
return "rwaOpenRequirements";
|
|
17
|
+
}
|
|
18
|
+
get title() {
|
|
19
|
+
return this.#title;
|
|
20
|
+
}
|
|
21
|
+
get detail() {
|
|
22
|
+
return this.#detail;
|
|
23
|
+
}
|
|
24
|
+
/** Pre-resolved: no on-chain reads to contribute. */
|
|
25
|
+
calls() {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
resolve() {
|
|
29
|
+
return this.satisfiedResult(this.#satisfied(), this.#detail);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Satisfied when the borrower has nothing left to do: no tokens pending
|
|
33
|
+
* issuer-side registration and no messages left to sign.
|
|
34
|
+
*/
|
|
35
|
+
#satisfied() {
|
|
36
|
+
const { securitizeTokensToRegister, requiredSignatures } = this.#detail;
|
|
37
|
+
return securitizeTokensToRegister.length === 0 && requiredSignatures.length === 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
RWAOpenRequirementsPrerequisite
|
|
42
|
+
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { isAddressEqual } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
AddressSet
|
|
4
|
+
} from "../../sdk/index.js";
|
|
2
5
|
import { AllowancePrerequisite } from "./AllowancePrerequisite.js";
|
|
3
6
|
import { BalancePrerequisite } from "./BalancePrerequisite.js";
|
|
7
|
+
import { RWAOpenRequirementsPrerequisite } from "./RWAOpenRequirementsPrerequisite.js";
|
|
4
8
|
async function buildPrerequisites(tx, ctx) {
|
|
5
9
|
const { wallet } = ctx;
|
|
6
10
|
switch (tx.operation) {
|
|
@@ -128,10 +132,34 @@ async function buildPrerequisites(tx, ctx) {
|
|
|
128
132
|
case "CloseCreditAccount":
|
|
129
133
|
case "LiquidateCreditAccount":
|
|
130
134
|
return collateralPrerequisites(
|
|
131
|
-
tx.operation,
|
|
135
|
+
tx.operation === "OpenCreditAccount" ? { creditManager: tx.creditManager, borrower: wallet } : {
|
|
136
|
+
creditManager: tx.creditManager,
|
|
137
|
+
creditAccount: tx.creditAccount
|
|
138
|
+
},
|
|
139
|
+
tx.multicall,
|
|
140
|
+
ctx
|
|
141
|
+
);
|
|
142
|
+
// RWA-factory operations: same collateral checks as facade operations,
|
|
143
|
+
// plus (for opening) the factory's open-account requirements. The parsed
|
|
144
|
+
// operation carries template (empty) `tokensToRegister`/`signaturesToCache`;
|
|
145
|
+
// the prerequisite detail provides the real values.
|
|
146
|
+
case "SecuritizeOpenCreditAccount":
|
|
147
|
+
return [
|
|
148
|
+
...await collateralPrerequisites(
|
|
149
|
+
{ creditManager: tx.creditManager, borrower: wallet },
|
|
150
|
+
tx.multicall,
|
|
151
|
+
ctx
|
|
152
|
+
),
|
|
153
|
+
...await rwaOpenRequirementsPrerequisites(
|
|
154
|
+
tx.multicall,
|
|
155
|
+
tx.creditManager,
|
|
156
|
+
ctx
|
|
157
|
+
)
|
|
158
|
+
];
|
|
159
|
+
case "SecuritizeMulticall":
|
|
160
|
+
return collateralPrerequisites(
|
|
161
|
+
{ creditManager: tx.creditManager, creditAccount: tx.creditAccount },
|
|
132
162
|
tx.multicall,
|
|
133
|
-
tx.creditManager,
|
|
134
|
-
tx.creditAccount,
|
|
135
163
|
ctx
|
|
136
164
|
);
|
|
137
165
|
case "PartiallyLiquidateCreditAccount": {
|
|
@@ -159,26 +187,24 @@ async function buildPrerequisites(tx, ctx) {
|
|
|
159
187
|
return [];
|
|
160
188
|
}
|
|
161
189
|
}
|
|
162
|
-
async function collateralPrerequisites(
|
|
190
|
+
async function collateralPrerequisites(spenderOptions, multicall, ctx) {
|
|
163
191
|
const { sdk, wallet } = ctx;
|
|
164
192
|
const required = /* @__PURE__ */ new Map();
|
|
165
|
-
for (const
|
|
166
|
-
if (
|
|
193
|
+
for (const op of multicall) {
|
|
194
|
+
if (op.operation !== "AddCollateral" || op.amount === 0n) {
|
|
167
195
|
continue;
|
|
168
196
|
}
|
|
169
|
-
const key =
|
|
197
|
+
const key = op.token.toLowerCase();
|
|
170
198
|
const existing = required.get(key);
|
|
171
199
|
required.set(key, {
|
|
172
|
-
token:
|
|
173
|
-
amount: (existing?.amount ?? 0n) +
|
|
200
|
+
token: op.token,
|
|
201
|
+
amount: (existing?.amount ?? 0n) + op.amount
|
|
174
202
|
});
|
|
175
203
|
}
|
|
176
204
|
if (required.size === 0) {
|
|
177
205
|
return [];
|
|
178
206
|
}
|
|
179
|
-
const spender = await sdk.accounts.getApprovalAddress(
|
|
180
|
-
op === "OpenCreditAccount" ? { creditManager, borrower: wallet } : { creditManager, creditAccount }
|
|
181
|
-
);
|
|
207
|
+
const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
|
|
182
208
|
const prereqs = [];
|
|
183
209
|
for (const { token, amount } of required.values()) {
|
|
184
210
|
prereqs.push(
|
|
@@ -199,6 +225,41 @@ async function collateralPrerequisites(op, multicall, creditManager, creditAccou
|
|
|
199
225
|
}
|
|
200
226
|
return prereqs;
|
|
201
227
|
}
|
|
228
|
+
async function rwaOpenRequirementsPrerequisites(multicall, creditManager, ctx) {
|
|
229
|
+
const { sdk, wallet } = ctx;
|
|
230
|
+
const { rwaFactory } = sdk.marketRegister.findByCreditManager(creditManager);
|
|
231
|
+
if (!rwaFactory) {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
const rwaTokens = new AddressSet(rwaFactory.getTokens());
|
|
235
|
+
const candidates = new AddressSet();
|
|
236
|
+
for (const op of multicall) {
|
|
237
|
+
if (op.operation === "AddCollateral" || op.operation === "UpdateQuota") {
|
|
238
|
+
candidates.add(op.token);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const prereqs = [];
|
|
242
|
+
for (const token of candidates) {
|
|
243
|
+
if (!rwaTokens.has(token)) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const requirements = await sdk.accounts.getOpenAccountRequirements(
|
|
247
|
+
wallet,
|
|
248
|
+
creditManager,
|
|
249
|
+
{ tokenOutAddress: token }
|
|
250
|
+
);
|
|
251
|
+
if (requirements) {
|
|
252
|
+
prereqs.push(
|
|
253
|
+
new RWAOpenRequirementsPrerequisite({
|
|
254
|
+
requirements,
|
|
255
|
+
token,
|
|
256
|
+
factory: rwaFactory.address
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return prereqs;
|
|
262
|
+
}
|
|
202
263
|
function underlyingOf(sdk, creditManager) {
|
|
203
264
|
const suite = sdk.marketRegister.creditManagers.find(
|
|
204
265
|
(cm) => isAddressEqual(cm.creditManager.address, creditManager)
|
|
@@ -3,5 +3,6 @@ export * from "./BalancePrerequisite.js";
|
|
|
3
3
|
export * from "./buildPrerequisites.js";
|
|
4
4
|
export * from "./Prerequisite.js";
|
|
5
5
|
export * from "./prepareAction.js";
|
|
6
|
+
export * from "./RWAOpenRequirementsPrerequisite.js";
|
|
6
7
|
export * from "./runPrerequisites.js";
|
|
7
8
|
export * from "./types.js";
|
|
@@ -2,9 +2,11 @@ import { PreviewSimulationError } from "./errors.js";
|
|
|
2
2
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
3
3
|
import { simulateOperation } from "./simulateOperation.js";
|
|
4
4
|
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
5
|
+
import { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
5
6
|
export {
|
|
6
7
|
PreviewSimulationError,
|
|
7
8
|
simulateFacadeOperation,
|
|
8
9
|
simulateOperation,
|
|
9
|
-
simulatePoolOperation
|
|
10
|
+
simulatePoolOperation,
|
|
11
|
+
simulateRWAOperation
|
|
10
12
|
};
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isPoolOperation,
|
|
3
|
+
isRWAOperation
|
|
4
|
+
} from "../parse/index.js";
|
|
2
5
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
3
6
|
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
7
|
+
import { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
4
8
|
async function simulateOperation(input, options) {
|
|
5
9
|
const { operation } = input;
|
|
6
10
|
if (isPoolOperation(operation)) {
|
|
7
11
|
return simulatePoolOperation({ ...input, operation }, options);
|
|
8
12
|
}
|
|
13
|
+
if (isRWAOperation(operation)) {
|
|
14
|
+
return simulateRWAOperation({ ...input, operation }, options);
|
|
15
|
+
}
|
|
9
16
|
return simulateFacadeOperation({ ...input, operation }, options);
|
|
10
17
|
}
|
|
11
18
|
export {
|
|
@@ -54,17 +54,21 @@ class SecuritizeRWAFactory extends BaseContract {
|
|
|
54
54
|
parseFunctionParamsV2(params, strict) {
|
|
55
55
|
switch (params.functionName) {
|
|
56
56
|
case "openCreditAccount": {
|
|
57
|
-
const [creditManager, calls] = params.args;
|
|
57
|
+
const [creditManager, calls, tokensToRegister, signaturesToCache] = params.args;
|
|
58
58
|
return {
|
|
59
59
|
creditManager,
|
|
60
|
-
calls: this.register.parseMultiCallV2([...calls], strict)
|
|
60
|
+
calls: this.register.parseMultiCallV2([...calls], strict),
|
|
61
|
+
tokensToRegister,
|
|
62
|
+
signaturesToCache
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
case "multicall": {
|
|
64
|
-
const [creditAccount, calls] = params.args;
|
|
66
|
+
const [creditAccount, calls, tokensToRegister, signaturesToCache] = params.args;
|
|
65
67
|
return {
|
|
66
68
|
creditAccount,
|
|
67
|
-
calls: this.register.parseMultiCallV2([...calls], strict)
|
|
69
|
+
calls: this.register.parseMultiCallV2([...calls], strict),
|
|
70
|
+
tokensToRegister,
|
|
71
|
+
signaturesToCache
|
|
68
72
|
};
|
|
69
73
|
}
|
|
70
74
|
default:
|
|
@@ -126,6 +130,12 @@ class SecuritizeRWAFactory extends BaseContract {
|
|
|
126
130
|
})
|
|
127
131
|
};
|
|
128
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* {@inheritDoc IRWAFactory.getTokens}
|
|
135
|
+
*/
|
|
136
|
+
getTokens() {
|
|
137
|
+
return this.dsTokens.map((t) => t.address);
|
|
138
|
+
}
|
|
129
139
|
/**
|
|
130
140
|
* {@inheritDoc IRWAFactory.getInvestor}
|
|
131
141
|
*/
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { RWA_FACTORY_SECURITIZE } from "./securitize/index.js";
|
|
2
2
|
const RWA_FACTORY_TYPES = [RWA_FACTORY_SECURITIZE];
|
|
3
|
-
function isRWAFactory(
|
|
4
|
-
|
|
3
|
+
function isRWAFactory(contract, type) {
|
|
4
|
+
if (type) {
|
|
5
|
+
return contract.contractType === type;
|
|
6
|
+
}
|
|
7
|
+
return contract.contractType.startsWith("RWA_FACTORY::");
|
|
5
8
|
}
|
|
6
9
|
export {
|
|
7
10
|
RWA_FACTORY_TYPES,
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import type {
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
import { type IRWAFactory, type OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { RWAOperation } from "./types-rwa.js";
|
|
4
4
|
export interface ParseRWAFactoryOperationCalldataProps {
|
|
5
5
|
sdk: OnchainSDK;
|
|
6
6
|
/** Resolved RWA factory contract for the transaction target. */
|
|
7
|
-
factory:
|
|
7
|
+
factory: IRWAFactory;
|
|
8
8
|
calldata: Hex;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Decodes a RWA-factory entry-point call into the matching
|
|
12
|
-
* {@link
|
|
12
|
+
* {@link RWAOperation}.
|
|
13
13
|
*
|
|
14
14
|
* RWA credit accounts are opened and managed through the market's RWA factory
|
|
15
|
-
* (see `CreditAccountsServiceV310`) rather than the credit facade, but the
|
|
16
|
-
* `calls` share the credit-facade multicall shape, so classification is
|
|
15
|
+
* (see `CreditAccountsServiceV310`) rather than the credit facade, but the
|
|
16
|
+
* inner `calls` share the credit-facade multicall shape, so classification is
|
|
17
17
|
* identical to {@link parseFacadeOperationCalldata}.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `zeroAddress`/`0n`.
|
|
19
|
+
* Dispatches on the factory's contract type; supporting a new factory type
|
|
20
|
+
* requires a new branch here plus new operation types in `types-rwa.ts`.
|
|
22
21
|
*/
|
|
23
|
-
export declare function parseRWAFactoryOperationCalldata(props: ParseRWAFactoryOperationCalldataProps):
|
|
22
|
+
export declare function parseRWAFactoryOperationCalldata(props: ParseRWAFactoryOperationCalldataProps): RWAOperation;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { SecuritizeRegisterMessage } from "../../sdk/index.js";
|
|
3
|
+
import type { ExpectedBalanceChange, InnerOperation } from "./types-facades.js";
|
|
4
|
+
/**
|
|
5
|
+
* Metadata shared by all RWA factory operations. RWA credit accounts are
|
|
6
|
+
* opened and managed through the market's RWA factory rather than the credit
|
|
7
|
+
* facade, but the inner `calls` still target the facade/adapters, so the
|
|
8
|
+
* credit suite is known.
|
|
9
|
+
*/
|
|
10
|
+
export interface RWAOperationMetadata {
|
|
11
|
+
/** RWA factory contract the transaction is sent to. */
|
|
12
|
+
factory: Address;
|
|
13
|
+
creditManager: Address;
|
|
14
|
+
creditFacade: Address;
|
|
15
|
+
}
|
|
16
|
+
export interface SecuritizeOpenCreditAccountOperation<Ext extends object = {}> extends RWAOperationMetadata {
|
|
17
|
+
operation: "SecuritizeOpenCreditAccount";
|
|
18
|
+
multicall: InnerOperation<Ext>[];
|
|
19
|
+
/**
|
|
20
|
+
* Potential balance changes declared by a router-generated
|
|
21
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
22
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
23
|
+
*/
|
|
24
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
25
|
+
/**
|
|
26
|
+
* DSToken addresses to register, decoded from calldata. Empty in the
|
|
27
|
+
* template flow, where the real value comes from the factory's open-account
|
|
28
|
+
* requirements.
|
|
29
|
+
*/
|
|
30
|
+
tokensToRegister: Address[];
|
|
31
|
+
/**
|
|
32
|
+
* EIP-712 registration signatures to store on-chain, decoded from calldata.
|
|
33
|
+
* Empty in the template flow.
|
|
34
|
+
*/
|
|
35
|
+
signaturesToCache: SecuritizeRegisterMessage[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `SecuritizeRWAFactory.multicall` call: like the facade's `multicall`, plus
|
|
39
|
+
* the factory-specific registration args.
|
|
40
|
+
*/
|
|
41
|
+
export interface SecuritizeMulticallOperation<Ext extends object = {}> extends RWAOperationMetadata {
|
|
42
|
+
operation: "SecuritizeMulticall";
|
|
43
|
+
creditAccount: Address;
|
|
44
|
+
multicall: InnerOperation<Ext>[];
|
|
45
|
+
/**
|
|
46
|
+
* Potential balance changes declared by a router-generated
|
|
47
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
48
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
49
|
+
*/
|
|
50
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
51
|
+
/** DSToken addresses to register, decoded from calldata. */
|
|
52
|
+
tokensToRegister: Address[];
|
|
53
|
+
/** EIP-712 registration signatures to store on-chain, decoded from calldata. */
|
|
54
|
+
signaturesToCache: SecuritizeRegisterMessage[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Discriminated union of all RWA factory operation types. Extend it when
|
|
58
|
+
* adding support for a new RWA factory type.
|
|
59
|
+
*/
|
|
60
|
+
export type RWAOperation<Ext extends object = {}> = SecuritizeOpenCreditAccountOperation<Ext> | SecuritizeMulticallOperation<Ext>;
|
|
@@ -2,9 +2,11 @@ import type { AdaptersPlugin } from "../../plugins/adapters/index.js";
|
|
|
2
2
|
import type { OnchainSDK, PluginsMap } from "../../sdk/index.js";
|
|
3
3
|
import type { OuterFacadeOperation } from "./types-facades.js";
|
|
4
4
|
import type { PoolOperation } from "./types-pools.js";
|
|
5
|
+
import type { RWAOperation } from "./types-rwa.js";
|
|
5
6
|
export * from "./types-adapters.js";
|
|
6
7
|
export * from "./types-facades.js";
|
|
7
8
|
export * from "./types-pools.js";
|
|
9
|
+
export * from "./types-rwa.js";
|
|
8
10
|
/**
|
|
9
11
|
* True when the plugin map `P` contains the {@link AdaptersPlugin} under any
|
|
10
12
|
* key. Matched nominally (the plugin's private fields make it non-structural),
|
|
@@ -29,16 +31,19 @@ export type RequireAdaptersPlugin<P extends PluginsMap> = HasAdaptersPlugin<P> e
|
|
|
29
31
|
*/
|
|
30
32
|
export type SdkWithAdapters<P extends PluginsMap = PluginsMap> = OnchainSDK<P> & RequireAdaptersPlugin<P>;
|
|
31
33
|
/**
|
|
32
|
-
* Result of decoding a single raw operation calldata:
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* Calldata-only parse produces base (descriptor) adapter operations, so the
|
|
36
|
-
* facade operations are used with the default `Ext = {}`.
|
|
34
|
+
* Result of decoding a single raw operation calldata: a pool deposit/redeem,
|
|
35
|
+
* one of the credit-facade operations, or an RWA-factory operation.
|
|
37
36
|
*/
|
|
38
|
-
export type Operation = PoolOperation | OuterFacadeOperation;
|
|
37
|
+
export type Operation = PoolOperation | OuterFacadeOperation | RWAOperation;
|
|
39
38
|
/**
|
|
40
39
|
* Narrows an {@link Operation} to a {@link PoolOperation} (deposit, mint,
|
|
41
40
|
* withdraw or redeem). Used by the UI to decide whether a custom view exists for
|
|
42
41
|
* the parsed result; everything else falls back to the raw JSON view.
|
|
43
42
|
*/
|
|
44
43
|
export declare function isPoolOperation(tx: Operation): tx is PoolOperation;
|
|
44
|
+
/**
|
|
45
|
+
* Narrows an {@link Operation} to an {@link RWAOperation} (an RWA-factory
|
|
46
|
+
* open-account or multicall). Used to route parsed operations to the
|
|
47
|
+
* RWA-specific simulation path.
|
|
48
|
+
*/
|
|
49
|
+
export declare function isRWAOperation(tx: Operation): tx is RWAOperation;
|
|
@@ -11,9 +11,7 @@ export interface AllowancePrerequisiteProps {
|
|
|
11
11
|
}
|
|
12
12
|
/** Checks that `owner` granted `spender` an ERC-20 allowance >= `required`. */
|
|
13
13
|
export declare class AllowancePrerequisite extends Prerequisite<"allowance"> {
|
|
14
|
-
private
|
|
15
|
-
private readonly _title;
|
|
16
|
-
private readonly _detail;
|
|
14
|
+
#private;
|
|
17
15
|
constructor(props: AllowancePrerequisiteProps);
|
|
18
16
|
get id(): string;
|
|
19
17
|
get kind(): "allowance";
|
|
@@ -10,9 +10,7 @@ export interface BalancePrerequisiteProps {
|
|
|
10
10
|
}
|
|
11
11
|
/** Checks that `owner` holds an ERC-20 balance >= `required`. */
|
|
12
12
|
export declare class BalancePrerequisite extends Prerequisite<"balance"> {
|
|
13
|
-
private
|
|
14
|
-
private readonly _title;
|
|
15
|
-
private readonly _detail;
|
|
13
|
+
#private;
|
|
16
14
|
constructor(props: BalancePrerequisiteProps);
|
|
17
15
|
get id(): string;
|
|
18
16
|
get kind(): "balance";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Address, ContractFunctionParameters } from "viem";
|
|
2
|
+
import type { RWAOpenAccountRequirements } from "../../sdk/index.js";
|
|
3
|
+
import { Prerequisite } from "./Prerequisite.js";
|
|
4
|
+
import type { PrerequisiteDetail, PrerequisiteResult } from "./types.js";
|
|
5
|
+
export interface RWAOpenRequirementsPrerequisiteProps {
|
|
6
|
+
/** Requirements already resolved via `sdk.accounts.getOpenAccountRequirements`. */
|
|
7
|
+
requirements: RWAOpenAccountRequirements;
|
|
8
|
+
/** RWA token (e.g. Securitize DSToken) the requirements were computed for. */
|
|
9
|
+
token: Address;
|
|
10
|
+
/** RWA factory that produced the requirements. */
|
|
11
|
+
factory: Address;
|
|
12
|
+
title?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks that the borrower has fulfilled the RWA factory's open-account
|
|
17
|
+
* requirements (issuer-side token registration, EIP-712 signatures).
|
|
18
|
+
*
|
|
19
|
+
* Unlike `allowance`/`balance`, the requirements cannot be derived from plain
|
|
20
|
+
* ERC-20 multicall reads: they come from an async compressor read performed by
|
|
21
|
+
* `sdk.accounts.getOpenAccountRequirements`. The prerequisite is therefore
|
|
22
|
+
* *pre-resolved*: it is constructed with the requirements already computed,
|
|
23
|
+
* contributes no calls to the verification multicall, and `resolve` only
|
|
24
|
+
* interprets the stored payload.
|
|
25
|
+
*/
|
|
26
|
+
export declare class RWAOpenRequirementsPrerequisite extends Prerequisite<"rwaOpenRequirements"> {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(props: RWAOpenRequirementsPrerequisiteProps);
|
|
29
|
+
get id(): string;
|
|
30
|
+
get kind(): "rwaOpenRequirements";
|
|
31
|
+
get title(): string;
|
|
32
|
+
get detail(): PrerequisiteDetail<"rwaOpenRequirements">;
|
|
33
|
+
/** Pre-resolved: no on-chain reads to contribute. */
|
|
34
|
+
calls(): ContractFunctionParameters[];
|
|
35
|
+
resolve(): PrerequisiteResult<"rwaOpenRequirements">;
|
|
36
|
+
}
|
|
@@ -3,5 +3,6 @@ export * from "./BalancePrerequisite.js";
|
|
|
3
3
|
export * from "./buildPrerequisites.js";
|
|
4
4
|
export * from "./Prerequisite.js";
|
|
5
5
|
export * from "./prepareAction.js";
|
|
6
|
+
export * from "./RWAOpenRequirementsPrerequisite.js";
|
|
6
7
|
export * from "./runPrerequisites.js";
|
|
7
8
|
export * from "./types.js";
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { OnchainSDK } from "../../sdk/index.js";
|
|
2
|
+
import type { OnchainSDK, RWAOpenAccountRequirements } from "../../sdk/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Extension point that ties each prerequisite kind to its detail payload.
|
|
5
5
|
*
|
|
6
|
-
* Adding a new prerequisite kind only requires a new entry here: the generic
|
|
7
|
-
* machinery below and the UI renderer registry both key off this map, so TS
|
|
8
|
-
* forces every consumer to handle the new kind.
|
|
9
|
-
*
|
|
10
6
|
* IMPORTANT: only add prerequisites that are *actionable by the transaction
|
|
11
7
|
* sender* (the LP provider or borrower). A valid prerequisite is one the user
|
|
12
8
|
* can resolve themselves before retrying, e.g. approve a token (`allowance`)
|
|
13
|
-
* or
|
|
14
|
-
*
|
|
15
|
-
*
|
|
9
|
+
* or perform offchain KYC verification.
|
|
10
|
+
*
|
|
11
|
+
* Do NOT add protocol- or admin-level state the user cannot change.
|
|
16
12
|
*/
|
|
17
13
|
export interface PrerequisiteDetailMap {
|
|
18
14
|
/** ERC-20 allowance from `owner` to `spender` must cover `required`. */
|
|
@@ -32,6 +28,12 @@ export interface PrerequisiteDetailMap {
|
|
|
32
28
|
/** On-chain balance read; only present when the read succeeded. */
|
|
33
29
|
actual?: bigint;
|
|
34
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* RWA (e.g. Securitize) open-account requirements: off-chain token
|
|
33
|
+
* registration and/or EIP-712 signatures the borrower must provide before
|
|
34
|
+
* opening a credit account in an RWA market.
|
|
35
|
+
*/
|
|
36
|
+
rwaOpenRequirements: RWAOpenAccountRequirements;
|
|
35
37
|
}
|
|
36
38
|
export type PrerequisiteKind = keyof PrerequisiteDetailMap;
|
|
37
39
|
export type PrerequisiteDetail<K extends PrerequisiteKind = PrerequisiteKind> = PrerequisiteDetailMap[K];
|
|
@@ -5,4 +5,6 @@ export { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
|
5
5
|
export type { SimulateOperationInput } from "./simulateOperation.js";
|
|
6
6
|
export { simulateOperation } from "./simulateOperation.js";
|
|
7
7
|
export { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
8
|
+
export type { SimulateRWAOperationInput } from "./simulateRWAOperation.js";
|
|
9
|
+
export { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
8
10
|
export type { AddressBalanceChanges, OperationSimulationOptions, PoolOperationSimulation, PoolOperationSimulationInput, PoolOperationSimulationResult, TokenBalanceChange, } from "./types.js";
|