@gearbox-protocol/sdk 14.12.0-next.1 → 14.12.0-next.3
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/abi/iZapper.js +62 -24
- package/dist/cjs/preview/parse/errors.js +5 -2
- package/dist/cjs/preview/parse/index.js +2 -0
- package/dist/cjs/preview/parse/parseOperationCalldata.js +38 -1
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/cjs/preview/parse/parseRWAFactoryOperationCalldata.js +92 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +57 -10
- package/dist/cjs/preview/simulate/errors.js +0 -7
- package/dist/cjs/preview/simulate/index.js +0 -3
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +154 -29
- package/dist/cjs/sdk/MultichainSDK.js +1 -0
- package/dist/cjs/sdk/OnchainSDK.js +7 -3
- package/dist/cjs/sdk/market/MarketRegister.js +10 -5
- package/dist/cjs/sdk/market/ZapperRegister.js +54 -0
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +20 -0
- package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/cjs/sdk/market/zapper/ZapperContract.js +109 -0
- package/dist/cjs/sdk/market/zapper/createZapper.js +12 -4
- package/dist/cjs/{preview/simulate/constants.js → sdk/market/zapper/errors.js} +15 -6
- package/dist/cjs/sdk/market/zapper/index.js +6 -2
- package/dist/cjs/sdk/market/zapper/types.js +16 -0
- package/dist/cjs/sdk/options.js +41 -17
- package/dist/esm/abi/iZapper.js +62 -24
- package/dist/esm/preview/parse/errors.js +3 -1
- package/dist/esm/preview/parse/index.js +1 -0
- package/dist/esm/preview/parse/parseOperationCalldata.js +41 -2
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +10 -2
- package/dist/esm/preview/parse/parseRWAFactoryOperationCalldata.js +71 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +57 -10
- package/dist/esm/preview/simulate/errors.js +0 -6
- package/dist/esm/preview/simulate/index.js +0 -2
- package/dist/esm/preview/simulate/simulatePoolOperation.js +155 -30
- package/dist/esm/sdk/MultichainSDK.js +1 -0
- package/dist/esm/sdk/OnchainSDK.js +7 -3
- package/dist/esm/sdk/market/MarketRegister.js +10 -5
- package/dist/esm/sdk/market/ZapperRegister.js +54 -0
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +23 -1
- package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +3 -38
- package/dist/esm/sdk/market/zapper/ZapperContract.js +85 -0
- package/dist/esm/sdk/market/zapper/createZapper.js +12 -4
- package/dist/esm/sdk/market/zapper/errors.js +13 -0
- package/dist/esm/sdk/market/zapper/index.js +3 -1
- package/dist/esm/sdk/market/zapper/types.js +0 -0
- package/dist/esm/sdk/options.js +39 -15
- package/dist/types/abi/iERC20Zapper.d.ts +91 -23
- package/dist/types/abi/iETHZapper.d.ts +91 -23
- package/dist/types/abi/iZapper.d.ts +91 -23
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +0 -2
- package/dist/types/preview/parse/errors.d.ts +1 -0
- package/dist/types/preview/parse/index.d.ts +1 -0
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +3 -3
- package/dist/types/preview/parse/parseRWAFactoryOperationCalldata.d.ts +23 -0
- package/dist/types/preview/parse/types-pools.d.ts +61 -1
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +1 -1
- package/dist/types/preview/simulate/errors.d.ts +6 -12
- package/dist/types/preview/simulate/index.d.ts +0 -1
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +22 -4
- package/dist/types/preview/simulate/types.d.ts +3 -16
- package/dist/types/sdk/MultichainSDK.d.ts +5 -0
- package/dist/types/sdk/OnchainSDK.d.ts +4 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +15 -6
- package/dist/types/sdk/market/ZapperRegister.d.ts +25 -4
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -1
- package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +93 -39
- package/dist/types/sdk/market/zapper/ZapperContract.d.ts +35 -0
- package/dist/types/sdk/market/zapper/createZapper.d.ts +2 -4
- package/dist/types/sdk/market/zapper/errors.d.ts +10 -0
- package/dist/types/sdk/market/zapper/index.d.ts +3 -1
- package/dist/types/sdk/market/zapper/types.d.ts +64 -0
- package/dist/types/sdk/options.d.ts +10 -5
- package/dist/types/sdk/pools/types.d.ts +3 -3
- package/dist/types/sdk/types/state-human.d.ts +9 -0
- package/dist/types/sdk/types/state.d.ts +7 -0
- package/package.json +3 -3
- package/dist/cjs/preview/simulate/extractERC20Transfers.js +0 -47
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +0 -155
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +0 -106
- package/dist/cjs/sdk/market/zapper/Zapper.js +0 -47
- package/dist/esm/preview/simulate/constants.js +0 -4
- package/dist/esm/preview/simulate/extractERC20Transfers.js +0 -23
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +0 -130
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +0 -82
- package/dist/esm/sdk/market/zapper/Zapper.js +0 -23
- package/dist/types/preview/simulate/constants.d.ts +0 -6
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +0 -11
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +0 -28
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +0 -14
- package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -13
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/sdk/options.js
CHANGED
|
@@ -18,19 +18,25 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var options_exports = {};
|
|
20
20
|
__export(options_exports, {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
attachOptionsSchema: () => attachOptionsSchema,
|
|
22
|
+
onchainSDKOptionsSchema: () => onchainSDKOptionsSchema
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(options_exports);
|
|
25
25
|
var import_v4 = require("zod/v4");
|
|
26
26
|
var import_updates = require("./market/pricefeeds/updates/index.js");
|
|
27
27
|
var import_utils = require("./utils/index.js");
|
|
28
|
-
const
|
|
29
|
-
/**
|
|
28
|
+
const onchainSDKOptionsSchema = import_v4.z.object({
|
|
29
|
+
/**
|
|
30
|
+
* When `true`, throw on unrecognised contract types.
|
|
31
|
+
**/
|
|
30
32
|
strictContractTypes: import_v4.z.boolean().optional(),
|
|
31
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Plugins that extend SDK functionality.
|
|
35
|
+
**/
|
|
32
36
|
plugins: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
33
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Custom logger implementation.
|
|
39
|
+
**/
|
|
34
40
|
logger: import_v4.z.any(),
|
|
35
41
|
/**
|
|
36
42
|
* Explicit gas limit for read-only `eth_call` requests.
|
|
@@ -39,10 +45,14 @@ const OnchainSDKOptionsSchema = import_v4.z.object({
|
|
|
39
45
|
**/
|
|
40
46
|
gasLimit: import_v4.z.bigint().nonnegative().nullable().optional()
|
|
41
47
|
});
|
|
42
|
-
const
|
|
43
|
-
/**
|
|
48
|
+
const attachOptionsSchema = import_v4.z.object({
|
|
49
|
+
/**
|
|
50
|
+
* Override address of the Gearbox AddressProvider contract.
|
|
51
|
+
**/
|
|
44
52
|
addressProvider: (0, import_utils.ZodAddress)().optional(),
|
|
45
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Addresses of market configurator contracts to load.
|
|
55
|
+
**/
|
|
46
56
|
marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
47
57
|
/**
|
|
48
58
|
* Addresses of RWA factory contracts to load.
|
|
@@ -50,19 +60,33 @@ const AttachOptionsSchema = import_v4.z.object({
|
|
|
50
60
|
* (from {@link GearboxChain.rwaFactories})
|
|
51
61
|
**/
|
|
52
62
|
rwaFactories: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
53
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Pin SDK to a specific block number during attach.
|
|
65
|
+
**/
|
|
54
66
|
blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
|
|
55
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Skip fetching updatable price feeds on attach and sync.
|
|
69
|
+
**/
|
|
56
70
|
ignoreUpdateablePrices: import_v4.z.boolean().optional(),
|
|
57
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Pool addresses whose markets should be skipped.
|
|
73
|
+
**/
|
|
58
74
|
ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
|
|
59
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Options for Redstone price-feed updates.
|
|
77
|
+
**/
|
|
60
78
|
redstone: import_updates.RedstoneOptions.optional(),
|
|
61
|
-
/**
|
|
62
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Options for Pyth price-feed updates.
|
|
81
|
+
**/
|
|
82
|
+
pyth: import_updates.PythOptions.optional(),
|
|
83
|
+
/**
|
|
84
|
+
* When `true`, automatically load zappers during attach.
|
|
85
|
+
**/
|
|
86
|
+
loadZappers: import_v4.z.boolean().optional()
|
|
63
87
|
});
|
|
64
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
89
|
0 && (module.exports = {
|
|
66
|
-
|
|
67
|
-
|
|
90
|
+
attachOptionsSchema,
|
|
91
|
+
onchainSDKOptionsSchema
|
|
68
92
|
});
|
package/dist/esm/abi/iZapper.js
CHANGED
|
@@ -1,80 +1,118 @@
|
|
|
1
1
|
const iZapperAbi = [
|
|
2
2
|
{
|
|
3
3
|
type: "function",
|
|
4
|
+
name: "contractType",
|
|
4
5
|
inputs: [],
|
|
6
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
7
|
+
stateMutability: "view"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
type: "function",
|
|
5
11
|
name: "pool",
|
|
6
|
-
|
|
12
|
+
inputs: [],
|
|
13
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
7
14
|
stateMutability: "view"
|
|
8
15
|
},
|
|
9
16
|
{
|
|
10
17
|
type: "function",
|
|
18
|
+
name: "previewDeposit",
|
|
11
19
|
inputs: [
|
|
12
|
-
{ name: "tokenInAmount",
|
|
20
|
+
{ name: "tokenInAmount", type: "uint256", internalType: "uint256" }
|
|
13
21
|
],
|
|
14
|
-
name: "previewDeposit",
|
|
15
22
|
outputs: [
|
|
16
|
-
{ name: "tokenOutAmount",
|
|
23
|
+
{ name: "tokenOutAmount", type: "uint256", internalType: "uint256" }
|
|
17
24
|
],
|
|
18
25
|
stateMutability: "view"
|
|
19
26
|
},
|
|
20
27
|
{
|
|
21
28
|
type: "function",
|
|
29
|
+
name: "previewRedeem",
|
|
22
30
|
inputs: [
|
|
23
|
-
{ name: "tokenOutAmount",
|
|
31
|
+
{ name: "tokenOutAmount", type: "uint256", internalType: "uint256" }
|
|
24
32
|
],
|
|
25
|
-
name: "previewRedeem",
|
|
26
33
|
outputs: [
|
|
27
|
-
{ name: "tokenInAmount",
|
|
34
|
+
{ name: "tokenInAmount", type: "uint256", internalType: "uint256" }
|
|
28
35
|
],
|
|
29
36
|
stateMutability: "view"
|
|
30
37
|
},
|
|
31
38
|
{
|
|
32
39
|
type: "function",
|
|
40
|
+
name: "redeem",
|
|
33
41
|
inputs: [
|
|
34
|
-
{ name: "tokenOutAmount",
|
|
35
|
-
{ name: "receiver",
|
|
42
|
+
{ name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
|
|
43
|
+
{ name: "receiver", type: "address", internalType: "address" }
|
|
36
44
|
],
|
|
37
|
-
name: "redeem",
|
|
38
45
|
outputs: [
|
|
39
|
-
{ name: "tokenInAmount",
|
|
46
|
+
{ name: "tokenInAmount", type: "uint256", internalType: "uint256" }
|
|
40
47
|
],
|
|
41
48
|
stateMutability: "nonpayable"
|
|
42
49
|
},
|
|
43
50
|
{
|
|
44
51
|
type: "function",
|
|
52
|
+
name: "redeemWithPermit",
|
|
45
53
|
inputs: [
|
|
46
|
-
{ name: "tokenOutAmount",
|
|
47
|
-
{ name: "receiver",
|
|
48
|
-
{ name: "deadline",
|
|
49
|
-
{ name: "v",
|
|
50
|
-
{ name: "r",
|
|
51
|
-
{ name: "s",
|
|
54
|
+
{ name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
|
|
55
|
+
{ name: "receiver", type: "address", internalType: "address" },
|
|
56
|
+
{ name: "deadline", type: "uint256", internalType: "uint256" },
|
|
57
|
+
{ name: "v", type: "uint8", internalType: "uint8" },
|
|
58
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
59
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" }
|
|
52
60
|
],
|
|
53
|
-
name: "redeemWithPermit",
|
|
54
61
|
outputs: [
|
|
55
|
-
{ name: "tokenInAmount",
|
|
62
|
+
{ name: "tokenInAmount", type: "uint256", internalType: "uint256" }
|
|
56
63
|
],
|
|
57
64
|
stateMutability: "nonpayable"
|
|
58
65
|
},
|
|
59
66
|
{
|
|
60
67
|
type: "function",
|
|
68
|
+
name: "redeemWithPermitAllowed",
|
|
69
|
+
inputs: [
|
|
70
|
+
{ name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
|
|
71
|
+
{ name: "receiver", type: "address", internalType: "address" },
|
|
72
|
+
{ name: "nonce", type: "uint256", internalType: "uint256" },
|
|
73
|
+
{ name: "expiry", type: "uint256", internalType: "uint256" },
|
|
74
|
+
{ name: "v", type: "uint8", internalType: "uint8" },
|
|
75
|
+
{ name: "r", type: "bytes32", internalType: "bytes32" },
|
|
76
|
+
{ name: "s", type: "bytes32", internalType: "bytes32" }
|
|
77
|
+
],
|
|
78
|
+
outputs: [
|
|
79
|
+
{ name: "tokenInAmount", type: "uint256", internalType: "uint256" }
|
|
80
|
+
],
|
|
81
|
+
stateMutability: "nonpayable"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "function",
|
|
85
|
+
name: "serialize",
|
|
61
86
|
inputs: [],
|
|
62
|
-
name: "
|
|
63
|
-
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
87
|
+
outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
|
|
64
88
|
stateMutability: "view"
|
|
65
89
|
},
|
|
66
90
|
{
|
|
67
91
|
type: "function",
|
|
92
|
+
name: "tokenIn",
|
|
68
93
|
inputs: [],
|
|
69
|
-
name: "
|
|
70
|
-
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
94
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
71
95
|
stateMutability: "view"
|
|
72
96
|
},
|
|
73
97
|
{
|
|
74
98
|
type: "function",
|
|
99
|
+
name: "tokenOut",
|
|
75
100
|
inputs: [],
|
|
101
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
102
|
+
stateMutability: "view"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: "function",
|
|
76
106
|
name: "underlying",
|
|
77
|
-
|
|
107
|
+
inputs: [],
|
|
108
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
109
|
+
stateMutability: "view"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: "function",
|
|
113
|
+
name: "version",
|
|
114
|
+
inputs: [],
|
|
115
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
78
116
|
stateMutability: "view"
|
|
79
117
|
}
|
|
80
118
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnsupportedZapperFunctionError } from "../../sdk/index.js";
|
|
1
2
|
class UnsupportedTargetError extends Error {
|
|
2
3
|
target;
|
|
3
4
|
constructor(target) {
|
|
@@ -18,5 +19,6 @@ class UnsupportedPoolFunctionError extends Error {
|
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
20
21
|
UnsupportedPoolFunctionError,
|
|
21
|
-
UnsupportedTargetError
|
|
22
|
+
UnsupportedTargetError,
|
|
23
|
+
UnsupportedZapperFunctionError
|
|
22
24
|
};
|
|
@@ -4,4 +4,5 @@ export * from "./extractExpectedBalanceChanges.js";
|
|
|
4
4
|
export * from "./parseFacadeOperationCalldata.js";
|
|
5
5
|
export * from "./parseOperationCalldata.js";
|
|
6
6
|
export * from "./parsePoolOperationCalldata.js";
|
|
7
|
+
export * from "./parseRWAFactoryOperationCalldata.js";
|
|
7
8
|
export * from "./types.js";
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CreditFacadeV310Contract,
|
|
3
|
-
PoolV310Contract
|
|
3
|
+
PoolV310Contract,
|
|
4
|
+
SecuritizeRWAFactory,
|
|
5
|
+
ZapperContract
|
|
4
6
|
} from "../../sdk/index.js";
|
|
5
7
|
import { UnsupportedTargetError } from "./errors.js";
|
|
6
8
|
import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
|
|
7
9
|
import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
|
|
10
|
+
import { parseRWAFactoryOperationCalldata } from "./parseRWAFactoryOperationCalldata.js";
|
|
8
11
|
function parseOperationCalldata(input) {
|
|
9
|
-
const { sdk, to, calldata } = input;
|
|
12
|
+
const { sdk, to, calldata, value, sender } = input;
|
|
10
13
|
const contract = sdk.getContract(to);
|
|
11
14
|
if (contract instanceof PoolV310Contract) {
|
|
12
15
|
return parsePoolOperationCalldata({ sdk, pool: contract, calldata });
|
|
13
16
|
}
|
|
17
|
+
if (contract instanceof ZapperContract) {
|
|
18
|
+
const parsed = contract.parseOperation(calldata, value);
|
|
19
|
+
if (parsed.operation === "Deposit") {
|
|
20
|
+
const op2 = {
|
|
21
|
+
operation: "Deposit",
|
|
22
|
+
pool: parsed.pool,
|
|
23
|
+
receiver: parsed.receiver,
|
|
24
|
+
assets: parsed.assets,
|
|
25
|
+
underlying: parsed.underlying,
|
|
26
|
+
tokenIn: parsed.token,
|
|
27
|
+
zapper: parsed.zapper,
|
|
28
|
+
referralCode: parsed.referralCode
|
|
29
|
+
};
|
|
30
|
+
return op2;
|
|
31
|
+
}
|
|
32
|
+
const op = {
|
|
33
|
+
operation: "Redeem",
|
|
34
|
+
pool: parsed.pool,
|
|
35
|
+
receiver: parsed.receiver,
|
|
36
|
+
// The zapper burns the caller's pool shares, so the share owner is the
|
|
37
|
+
// transaction sender.
|
|
38
|
+
owner: sender,
|
|
39
|
+
shares: parsed.shares,
|
|
40
|
+
underlying: parsed.underlying,
|
|
41
|
+
tokenOut: parsed.token,
|
|
42
|
+
zapper: parsed.zapper
|
|
43
|
+
};
|
|
44
|
+
return op;
|
|
45
|
+
}
|
|
14
46
|
if (contract instanceof CreditFacadeV310Contract) {
|
|
15
47
|
return parseFacadeOperationCalldata({
|
|
16
48
|
sdk,
|
|
@@ -18,6 +50,13 @@ function parseOperationCalldata(input) {
|
|
|
18
50
|
calldata
|
|
19
51
|
});
|
|
20
52
|
}
|
|
53
|
+
if (contract instanceof SecuritizeRWAFactory) {
|
|
54
|
+
return parseRWAFactoryOperationCalldata({
|
|
55
|
+
sdk,
|
|
56
|
+
factory: contract,
|
|
57
|
+
calldata
|
|
58
|
+
});
|
|
59
|
+
}
|
|
21
60
|
throw new UnsupportedTargetError(to);
|
|
22
61
|
}
|
|
23
62
|
export {
|
|
@@ -14,6 +14,8 @@ function parsePoolOperationCalldata(props) {
|
|
|
14
14
|
receiver: rawArgs.receiver,
|
|
15
15
|
assets: rawArgs.assets,
|
|
16
16
|
underlying,
|
|
17
|
+
tokenIn: underlying,
|
|
18
|
+
zapper: void 0,
|
|
17
19
|
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
18
20
|
};
|
|
19
21
|
case "mint":
|
|
@@ -24,6 +26,8 @@ function parsePoolOperationCalldata(props) {
|
|
|
24
26
|
receiver: rawArgs.receiver,
|
|
25
27
|
shares: rawArgs.shares,
|
|
26
28
|
underlying,
|
|
29
|
+
tokenIn: underlying,
|
|
30
|
+
zapper: void 0,
|
|
27
31
|
referralCode: functionName === "mintWithReferral" ? rawArgs.referralCode : void 0
|
|
28
32
|
};
|
|
29
33
|
case "withdraw":
|
|
@@ -33,7 +37,9 @@ function parsePoolOperationCalldata(props) {
|
|
|
33
37
|
receiver: rawArgs.receiver,
|
|
34
38
|
owner: rawArgs.owner,
|
|
35
39
|
assets: rawArgs.assets,
|
|
36
|
-
underlying
|
|
40
|
+
underlying,
|
|
41
|
+
tokenOut: underlying,
|
|
42
|
+
zapper: void 0
|
|
37
43
|
};
|
|
38
44
|
case "redeem":
|
|
39
45
|
return {
|
|
@@ -42,7 +48,9 @@ function parsePoolOperationCalldata(props) {
|
|
|
42
48
|
receiver: rawArgs.receiver,
|
|
43
49
|
owner: rawArgs.owner,
|
|
44
50
|
shares: rawArgs.shares,
|
|
45
|
-
underlying
|
|
51
|
+
underlying,
|
|
52
|
+
tokenOut: underlying,
|
|
53
|
+
zapper: void 0
|
|
46
54
|
};
|
|
47
55
|
default:
|
|
48
56
|
throw new UnsupportedPoolFunctionError(pool.address, parsed.functionName);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { zeroAddress } from "viem";
|
|
2
|
+
import { AbstractAdapterContract } from "../../plugins/adapters/index.js";
|
|
3
|
+
import {
|
|
4
|
+
CreditFacadeV310Contract,
|
|
5
|
+
hexEq
|
|
6
|
+
} from "../../sdk/index.js";
|
|
7
|
+
import { classifyInnerOperations } from "./classifyInnerOperations.js";
|
|
8
|
+
import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
|
|
9
|
+
function parseRWAFactoryOperationCalldata(props) {
|
|
10
|
+
const { sdk, factory, calldata } = props;
|
|
11
|
+
const parsed = sdk.parseFunctionDataV2(factory.address, calldata);
|
|
12
|
+
const functionName = parsed.functionName.split("(")[0];
|
|
13
|
+
const { rawArgs } = parsed;
|
|
14
|
+
const innerCalls = rawArgs.calls ?? [];
|
|
15
|
+
const suite = functionName === "openCreditAccount" ? sdk.marketRegister.findCreditManager(rawArgs.creditManager) : resolveSuiteForMulticall(sdk, factory, innerCalls);
|
|
16
|
+
const metadata = {
|
|
17
|
+
creditManager: suite.creditManager.address,
|
|
18
|
+
creditFacade: suite.creditFacade.address
|
|
19
|
+
};
|
|
20
|
+
const multicall = classifyInnerOperations(innerCalls, {
|
|
21
|
+
sdk,
|
|
22
|
+
underlying: suite.underlying
|
|
23
|
+
});
|
|
24
|
+
const expectedBalanceChanges = extractExpectedBalanceChanges(innerCalls);
|
|
25
|
+
switch (functionName) {
|
|
26
|
+
case "openCreditAccount":
|
|
27
|
+
return {
|
|
28
|
+
...metadata,
|
|
29
|
+
operation: "OpenCreditAccount",
|
|
30
|
+
creditAccount: zeroAddress,
|
|
31
|
+
onBehalfOf: zeroAddress,
|
|
32
|
+
referralCode: 0n,
|
|
33
|
+
multicall,
|
|
34
|
+
expectedBalanceChanges
|
|
35
|
+
};
|
|
36
|
+
case "multicall":
|
|
37
|
+
return {
|
|
38
|
+
...metadata,
|
|
39
|
+
operation: "MultiCall",
|
|
40
|
+
creditAccount: rawArgs.creditAccount,
|
|
41
|
+
multicall,
|
|
42
|
+
expectedBalanceChanges
|
|
43
|
+
};
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(
|
|
46
|
+
`unsupported RWA factory function "${parsed.functionName}" on ${factory.address}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function resolveSuiteForMulticall(sdk, factory, innerCalls) {
|
|
51
|
+
for (const call of innerCalls) {
|
|
52
|
+
const contract = sdk.getContract(call.target);
|
|
53
|
+
if (contract instanceof CreditFacadeV310Contract) {
|
|
54
|
+
const suite = sdk.marketRegister.creditManagers.find(
|
|
55
|
+
(cm) => hexEq(cm.creditFacade.address, call.target)
|
|
56
|
+
);
|
|
57
|
+
if (suite) {
|
|
58
|
+
return suite;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (contract instanceof AbstractAdapterContract) {
|
|
62
|
+
return sdk.marketRegister.findCreditManager(contract.creditManager);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error(
|
|
66
|
+
`cannot resolve credit manager for RWA factory multicall on ${factory.address}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
parseRWAFactoryOperationCalldata
|
|
71
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isAddressEqual } from "viem";
|
|
2
2
|
import { AllowancePrerequisite } from "./AllowancePrerequisite.js";
|
|
3
3
|
import { BalancePrerequisite } from "./BalancePrerequisite.js";
|
|
4
|
-
function buildPrerequisites(tx, ctx) {
|
|
4
|
+
async function buildPrerequisites(tx, ctx) {
|
|
5
5
|
const { wallet } = ctx;
|
|
6
6
|
switch (tx.operation) {
|
|
7
7
|
// Deposit and Mint both pull the underlying from the caller into the pool;
|
|
@@ -11,6 +11,23 @@ function buildPrerequisites(tx, ctx) {
|
|
|
11
11
|
// here we approximate Mint by its shares amount (a lower bound on assets is
|
|
12
12
|
// not knowable from calldata alone).
|
|
13
13
|
case "Deposit":
|
|
14
|
+
if (tx.zapper) {
|
|
15
|
+
return [
|
|
16
|
+
new AllowancePrerequisite({
|
|
17
|
+
token: tx.tokenIn,
|
|
18
|
+
owner: wallet,
|
|
19
|
+
spender: tx.zapper,
|
|
20
|
+
required: tx.assets,
|
|
21
|
+
title: "Token approved to zapper"
|
|
22
|
+
}),
|
|
23
|
+
new BalancePrerequisite({
|
|
24
|
+
token: tx.tokenIn,
|
|
25
|
+
owner: wallet,
|
|
26
|
+
required: tx.assets,
|
|
27
|
+
title: "Sufficient token balance"
|
|
28
|
+
})
|
|
29
|
+
];
|
|
30
|
+
}
|
|
14
31
|
return [
|
|
15
32
|
new AllowancePrerequisite({
|
|
16
33
|
token: tx.underlying,
|
|
@@ -45,6 +62,23 @@ function buildPrerequisites(tx, ctx) {
|
|
|
45
62
|
// Redeem and Withdraw both burn LP shares from `owner`; they only differ in
|
|
46
63
|
// which side (shares vs assets) the caller specifies.
|
|
47
64
|
case "Redeem": {
|
|
65
|
+
if (tx.zapper) {
|
|
66
|
+
return [
|
|
67
|
+
new BalancePrerequisite({
|
|
68
|
+
token: tx.pool,
|
|
69
|
+
owner: wallet,
|
|
70
|
+
required: tx.shares,
|
|
71
|
+
title: "Sufficient LP token balance"
|
|
72
|
+
}),
|
|
73
|
+
new AllowancePrerequisite({
|
|
74
|
+
token: tx.pool,
|
|
75
|
+
owner: wallet,
|
|
76
|
+
spender: tx.zapper,
|
|
77
|
+
required: tx.shares,
|
|
78
|
+
title: "LP token approved to zapper"
|
|
79
|
+
})
|
|
80
|
+
];
|
|
81
|
+
}
|
|
48
82
|
const prereqs = [
|
|
49
83
|
new BalancePrerequisite({
|
|
50
84
|
token: tx.pool,
|
|
@@ -93,7 +127,13 @@ function buildPrerequisites(tx, ctx) {
|
|
|
93
127
|
case "OpenCreditAccount":
|
|
94
128
|
case "CloseCreditAccount":
|
|
95
129
|
case "LiquidateCreditAccount":
|
|
96
|
-
return collateralPrerequisites(
|
|
130
|
+
return collateralPrerequisites(
|
|
131
|
+
tx.operation,
|
|
132
|
+
tx.multicall,
|
|
133
|
+
tx.creditManager,
|
|
134
|
+
tx.creditAccount,
|
|
135
|
+
ctx
|
|
136
|
+
);
|
|
97
137
|
case "PartiallyLiquidateCreditAccount": {
|
|
98
138
|
const underlying = underlyingOf(ctx.sdk, tx.creditManager);
|
|
99
139
|
if (!underlying || tx.repaidAmount === 0n) {
|
|
@@ -119,28 +159,35 @@ function buildPrerequisites(tx, ctx) {
|
|
|
119
159
|
return [];
|
|
120
160
|
}
|
|
121
161
|
}
|
|
122
|
-
function collateralPrerequisites(multicall, creditManager,
|
|
162
|
+
async function collateralPrerequisites(op, multicall, creditManager, creditAccount, ctx) {
|
|
163
|
+
const { sdk, wallet } = ctx;
|
|
123
164
|
const required = /* @__PURE__ */ new Map();
|
|
124
|
-
for (const
|
|
125
|
-
if (
|
|
165
|
+
for (const op2 of multicall) {
|
|
166
|
+
if (op2.operation !== "AddCollateral" || op2.amount === 0n) {
|
|
126
167
|
continue;
|
|
127
168
|
}
|
|
128
|
-
const key =
|
|
169
|
+
const key = op2.token.toLowerCase();
|
|
129
170
|
const existing = required.get(key);
|
|
130
171
|
required.set(key, {
|
|
131
|
-
token:
|
|
132
|
-
amount: (existing?.amount ?? 0n) +
|
|
172
|
+
token: op2.token,
|
|
173
|
+
amount: (existing?.amount ?? 0n) + op2.amount
|
|
133
174
|
});
|
|
134
175
|
}
|
|
176
|
+
if (required.size === 0) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const spender = await sdk.accounts.getApprovalAddress(
|
|
180
|
+
op === "OpenCreditAccount" ? { creditManager, borrower: wallet } : { creditManager, creditAccount }
|
|
181
|
+
);
|
|
135
182
|
const prereqs = [];
|
|
136
183
|
for (const { token, amount } of required.values()) {
|
|
137
184
|
prereqs.push(
|
|
138
185
|
new AllowancePrerequisite({
|
|
139
186
|
token,
|
|
140
187
|
owner: wallet,
|
|
141
|
-
spender
|
|
188
|
+
spender,
|
|
142
189
|
required: amount,
|
|
143
|
-
title: "Collateral approved
|
|
190
|
+
title: "Collateral approved"
|
|
144
191
|
}),
|
|
145
192
|
new BalancePrerequisite({
|
|
146
193
|
token,
|
|
@@ -27,11 +27,6 @@ function asPreviewSimulationError(reason, source) {
|
|
|
27
27
|
{ source, detail: decodeSimulationError({ error }) }
|
|
28
28
|
]);
|
|
29
29
|
}
|
|
30
|
-
function combinePreviewSimulationErrors(...errors) {
|
|
31
|
-
return new PreviewSimulationError(
|
|
32
|
-
errors.filter((e) => e).flatMap((e) => e?.failures ?? [])
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
30
|
function decodeSimulationError(revert) {
|
|
36
31
|
const { error, data } = revert;
|
|
37
32
|
if (data && data !== "0x") {
|
|
@@ -70,6 +65,5 @@ function formatDecodedError(errorName, args) {
|
|
|
70
65
|
export {
|
|
71
66
|
PreviewSimulationError,
|
|
72
67
|
asPreviewSimulationError,
|
|
73
|
-
combinePreviewSimulationErrors,
|
|
74
68
|
decodeSimulationError
|
|
75
69
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ETH_SIMULATE_V1_NETWORKS } from "./constants.js";
|
|
2
1
|
import { PreviewSimulationError } from "./errors.js";
|
|
3
2
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
4
3
|
import { simulateOperation } from "./simulateOperation.js";
|
|
5
4
|
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
6
5
|
export {
|
|
7
|
-
ETH_SIMULATE_V1_NETWORKS,
|
|
8
6
|
PreviewSimulationError,
|
|
9
7
|
simulateFacadeOperation,
|
|
10
8
|
simulateOperation,
|