@gearbox-protocol/sdk 18.4.0 → 18.4.1-aave.10
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/rwa/iSecuritizeRWAFactory.js +15 -0
- package/dist/cjs/model/errors/index.js +1 -0
- package/dist/cjs/model/errors/operation-errors.js +9 -0
- package/dist/cjs/model/index.js +2 -4
- package/dist/cjs/offchain/GearboxAPI.js +0 -7
- package/dist/cjs/offchain/index.js +0 -3
- package/dist/cjs/onchain/accounts/bots/AccountBotsService.js +29 -0
- package/dist/cjs/onchain/accounts/bots/PeripheryCompressorV310Contract.js +2 -1
- package/dist/cjs/onchain/accounts/index.js +1 -1
- package/dist/cjs/onchain/accounts/intents/index.js +33 -0
- package/dist/cjs/onchain/accounts/intents/operations.js +21 -0
- package/dist/cjs/onchain/accounts/intents/plan.js +55 -0
- package/dist/cjs/onchain/accounts/intents/readAaveHoldings.js +56 -0
- package/dist/cjs/onchain/accounts/intents/realize.js +84 -2
- package/dist/cjs/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +3 -2
- package/dist/cjs/onchain/accounts/intents/utils/ledger.js +8 -0
- package/dist/cjs/onchain/chain/chains.js +4 -0
- package/dist/cjs/onchain/index.js +25 -1
- package/dist/cjs/onchain/market/ZapperRegister.js +1 -1
- package/dist/cjs/onchain/market/adapters/abi/aave/iAaveHorizonBridge.js +94 -0
- package/dist/cjs/onchain/market/adapters/abi/aave/iAaveOracle.js +20 -0
- package/dist/cjs/onchain/market/adapters/abi/aave/iAaveV3Pool.js +278 -0
- package/dist/cjs/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +11 -0
- package/dist/cjs/onchain/market/adapters/abi/aave/iVariableDebtToken.js +17 -0
- package/dist/cjs/onchain/market/adapters/abi/aave/index.js +11 -0
- package/dist/cjs/onchain/market/adapters/abi/actionAbi.js +1 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +224 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/iAaveV3PoolAdapter.js +177 -0
- package/dist/cjs/onchain/market/adapters/abi/adapters/index.js +4 -0
- package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +2 -0
- package/dist/cjs/onchain/market/adapters/abi/index.js +17 -0
- package/dist/cjs/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.js +15 -0
- package/dist/cjs/onchain/market/adapters/abi/securitize/index.js +2 -0
- package/dist/cjs/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +218 -0
- package/dist/cjs/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +213 -0
- package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +8 -0
- package/dist/cjs/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js +42 -5
- package/dist/cjs/onchain/market/adapters/contracts/index.js +4 -0
- package/dist/cjs/onchain/market/adapters/createAdapter.js +4 -0
- package/dist/cjs/onchain/market/adapters/index.js +20 -0
- package/dist/cjs/onchain/market/adapters/types.js +2 -0
- package/dist/cjs/onchain/market/index.js +20 -0
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
- package/dist/cjs/onchain/positions/MultichainPositionsService.js +15 -0
- package/dist/cjs/onchain/positions/PositionsService.js +31 -0
- package/dist/cjs/onchain/positions/aaveMoveCalls.js +45 -0
- package/dist/cjs/onchain/positions/projectAavePosition.js +178 -0
- package/dist/cjs/onchain/positions/readAavePosition.js +152 -0
- package/dist/cjs/onchain/preview/index.js +2 -0
- package/dist/cjs/onchain/preview/preview/aaveBridgeBorrows.js +24 -0
- package/dist/cjs/onchain/preview/preview/aaveMoveStart.js +27 -0
- package/dist/cjs/onchain/preview/preview/index.js +2 -0
- package/dist/cjs/onchain/preview/preview/loadAdapterReplayState.js +17 -0
- package/dist/cjs/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
- package/dist/cjs/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +5 -2
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +4 -1
- package/dist/cjs/onchain/preview/preview/previewOperation.js +33 -8
- package/dist/cjs/onchain/validation/bundles/checkAaveDelegation.js +54 -0
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +36 -11
- package/dist/cjs/onchain/validation/bundles/index.js +2 -0
- package/dist/cjs/onchain/validation/checkOperation.js +16 -4
- package/dist/cjs/onchain/validation/index.js +2 -0
- package/dist/cjs/sdk/GearboxSDK.js +0 -9
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -0
- package/dist/cjs/sdk/positions/PositionsNamespace.js +6 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +98 -0
- package/dist/cjs/sdk/preview/PreviewNamespace.js +42 -0
- package/dist/esm/abi/rwa/iSecuritizeRWAFactory.js +15 -0
- package/dist/esm/model/errors/index.js +2 -2
- package/dist/esm/model/errors/operation-errors.js +9 -1
- package/dist/esm/model/index.js +3 -4
- package/dist/esm/offchain/GearboxAPI.js +0 -7
- package/dist/esm/offchain/index.js +1 -3
- package/dist/esm/onchain/accounts/bots/AccountBotsService.js +29 -0
- package/dist/esm/onchain/accounts/bots/PeripheryCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/index.js +1 -1
- package/dist/esm/onchain/accounts/intents/index.js +34 -1
- package/dist/esm/onchain/accounts/intents/operations.js +20 -1
- package/dist/esm/onchain/accounts/intents/plan.js +56 -2
- package/dist/esm/onchain/accounts/intents/readAaveHoldings.js +55 -0
- package/dist/esm/onchain/accounts/intents/realize.js +86 -4
- package/dist/esm/onchain/accounts/intents/testing/market.js +1 -0
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +3 -2
- package/dist/esm/onchain/accounts/intents/utils/ledger.js +8 -0
- package/dist/esm/onchain/chain/chains.js +4 -0
- package/dist/esm/onchain/index.js +14 -2
- package/dist/esm/onchain/market/ZapperRegister.js +1 -1
- package/dist/esm/onchain/market/adapters/abi/aave/iAaveHorizonBridge.js +93 -0
- package/dist/esm/onchain/market/adapters/abi/aave/iAaveOracle.js +19 -0
- package/dist/esm/onchain/market/adapters/abi/aave/iAaveV3Pool.js +277 -0
- package/dist/esm/onchain/market/adapters/abi/aave/iPoolAddressesProvider.js +10 -0
- package/dist/esm/onchain/market/adapters/abi/aave/iVariableDebtToken.js +16 -0
- package/dist/esm/onchain/market/adapters/abi/aave/index.js +6 -0
- package/dist/esm/onchain/market/adapters/abi/actionAbi.js +1 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.js +223 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/iAaveV3PoolAdapter.js +176 -0
- package/dist/esm/onchain/market/adapters/abi/adapters/index.js +3 -1
- package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +2 -0
- package/dist/esm/onchain/market/adapters/abi/index.js +10 -1
- package/dist/esm/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.js +14 -0
- package/dist/esm/onchain/market/adapters/abi/securitize/index.js +2 -1
- package/dist/esm/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.js +217 -0
- package/dist/esm/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.js +212 -0
- package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +8 -0
- package/dist/esm/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js +43 -6
- package/dist/esm/onchain/market/adapters/contracts/index.js +3 -1
- package/dist/esm/onchain/market/adapters/createAdapter.js +4 -0
- package/dist/esm/onchain/market/adapters/index.js +11 -1
- package/dist/esm/onchain/market/adapters/types.js +2 -0
- package/dist/esm/onchain/market/index.js +11 -1
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +9 -0
- package/dist/esm/onchain/positions/MultichainPositionsService.js +15 -0
- package/dist/esm/onchain/positions/PositionsService.js +31 -0
- package/dist/esm/onchain/positions/aaveMoveCalls.js +44 -0
- package/dist/esm/onchain/positions/projectAavePosition.js +177 -0
- package/dist/esm/onchain/positions/readAavePosition.js +151 -0
- package/dist/esm/onchain/preview/index.js +2 -1
- package/dist/esm/onchain/preview/preview/aaveBridgeBorrows.js +23 -0
- package/dist/esm/onchain/preview/preview/aaveMoveStart.js +26 -0
- package/dist/esm/onchain/preview/preview/index.js +2 -1
- package/dist/esm/onchain/preview/preview/loadAdapterReplayState.js +16 -0
- package/dist/esm/onchain/preview/preview/previewAdjustStrategyPosition.js +3 -0
- package/dist/esm/onchain/preview/preview/previewExitOrRepayStrategyPosition.js +5 -2
- package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +4 -1
- package/dist/esm/onchain/preview/preview/previewOperation.js +33 -8
- package/dist/esm/onchain/validation/bundles/checkAaveDelegation.js +53 -0
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +36 -11
- package/dist/esm/onchain/validation/bundles/index.js +2 -1
- package/dist/esm/onchain/validation/checkOperation.js +16 -4
- package/dist/esm/onchain/validation/index.js +2 -1
- package/dist/esm/sdk/GearboxSDK.js +0 -9
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -0
- package/dist/esm/sdk/positions/PositionsNamespace.js +6 -0
- package/dist/esm/sdk/prepare/PrepareApi.js +99 -1
- package/dist/esm/sdk/preview/PreviewNamespace.js +42 -0
- package/dist/types/abi/rwa/iSecuritizeRWAFactory.d.ts +14 -0
- package/dist/types/model/aave.d.ts +89 -0
- package/dist/types/model/analytics.d.ts +2 -2
- package/dist/types/model/errors/index.d.ts +2 -2
- package/dist/types/model/errors/operation-errors.d.ts +19 -0
- package/dist/types/model/index.d.ts +6 -7
- package/dist/types/model/positions.d.ts +1 -1
- package/dist/types/model/previews.d.ts +31 -0
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +1 -1
- package/dist/types/offchain/GearboxAPI.d.ts +0 -6
- package/dist/types/offchain/analytics/OffchainAnalytics.d.ts +1 -1
- package/dist/types/offchain/analytics/types.d.ts +1 -1
- package/dist/types/offchain/index.d.ts +1 -3
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -1
- package/dist/types/offchain/opportunities/types.d.ts +1 -1
- package/dist/types/offchain/positions/OffchainPositions.d.ts +1 -1
- package/dist/types/offchain/positions/types.d.ts +1 -1
- package/dist/types/onchain/accounts/bots/AccountBotsService.d.ts +11 -1
- package/dist/types/onchain/accounts/bots/index.d.ts +2 -2
- package/dist/types/onchain/accounts/bots/types.d.ts +7 -1
- package/dist/types/onchain/accounts/index.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/index.d.ts +21 -3
- package/dist/types/onchain/accounts/intents/operations.d.ts +41 -1
- package/dist/types/onchain/accounts/intents/plan.d.ts +32 -3
- package/dist/types/onchain/accounts/intents/readAaveHoldings.d.ts +16 -0
- package/dist/types/onchain/accounts/intents/testing/market.d.ts +4 -0
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +4 -0
- package/dist/types/onchain/accounts/intents/types.d.ts +42 -0
- package/dist/types/onchain/index.d.ts +16 -4
- package/dist/types/onchain/market/adapters/abi/aave/iAaveHorizonBridge.d.ts +83 -0
- package/dist/types/onchain/market/adapters/abi/aave/iAaveOracle.d.ts +22 -0
- package/dist/types/onchain/market/adapters/abi/aave/iAaveV3Pool.d.ts +229 -0
- package/dist/types/onchain/market/adapters/abi/aave/iPoolAddressesProvider.d.ts +11 -0
- package/dist/types/onchain/market/adapters/abi/aave/iVariableDebtToken.d.ts +17 -0
- package/dist/types/onchain/market/adapters/abi/aave/index.d.ts +6 -0
- package/dist/types/onchain/market/adapters/abi/adapters/iAaveHorizonBridgeAdapter.d.ts +207 -0
- package/dist/types/onchain/market/adapters/abi/adapters/iAaveV3PoolAdapter.d.ts +172 -0
- package/dist/types/onchain/market/adapters/abi/adapters/index.d.ts +3 -1
- package/dist/types/onchain/market/adapters/abi/index.d.ts +10 -1
- package/dist/types/onchain/market/adapters/abi/securitize/iSecuritizeNAVProvider.d.ts +13 -0
- package/dist/types/onchain/market/adapters/abi/securitize/index.d.ts +2 -1
- package/dist/types/onchain/market/adapters/contracts/AaveHorizonBridgeAdapterContract.d.ts +361 -0
- package/dist/types/onchain/market/adapters/contracts/AaveV3PoolAdapterContract.d.ts +455 -0
- package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +8 -0
- package/dist/types/onchain/market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.d.ts +19 -4
- package/dist/types/onchain/market/adapters/contracts/index.d.ts +3 -1
- package/dist/types/onchain/market/adapters/index.d.ts +11 -1
- package/dist/types/onchain/market/adapters/types.d.ts +3 -1
- package/dist/types/onchain/market/index.d.ts +11 -1
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +20 -0
- package/dist/types/onchain/market/rwa/types.d.ts +6 -0
- package/dist/types/onchain/positions/MultichainPositionsService.d.ts +7 -1
- package/dist/types/onchain/positions/PositionsService.d.ts +16 -2
- package/dist/types/onchain/positions/aaveMoveCalls.d.ts +30 -0
- package/dist/types/onchain/positions/index.d.ts +2 -2
- package/dist/types/onchain/positions/projectAavePosition.d.ts +46 -0
- package/dist/types/onchain/positions/readAavePosition.d.ts +22 -0
- package/dist/types/onchain/positions/types.d.ts +25 -0
- package/dist/types/onchain/preview/index.d.ts +2 -1
- package/dist/types/onchain/preview/preview/aaveBridgeBorrows.d.ts +15 -0
- package/dist/types/onchain/preview/preview/aaveMoveStart.d.ts +18 -0
- package/dist/types/onchain/preview/preview/index.d.ts +2 -1
- package/dist/types/onchain/preview/preview/loadAdapterReplayState.d.ts +13 -0
- package/dist/types/onchain/validation/bundles/checkAaveDelegation.d.ts +21 -0
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +2 -2
- package/dist/types/onchain/validation/bundles/index.d.ts +2 -1
- package/dist/types/onchain/validation/index.d.ts +2 -1
- package/dist/types/sdk/GearboxSDK.d.ts +1 -8
- package/dist/types/sdk/analytics/AnalyticsNamespace.d.ts +1 -1
- package/dist/types/sdk/analytics/types.d.ts +1 -1
- package/dist/types/sdk/execute/types.d.ts +7 -5
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +1 -1
- package/dist/types/sdk/opportunities/types.d.ts +1 -1
- package/dist/types/sdk/positions/PositionsNamespace.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +10 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +11 -3
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +116 -1
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +5 -1
- package/dist/types/sdk/preview/types.d.ts +12 -1
- package/dist/types/sdk/types.d.ts +0 -20
- package/package.json +1 -1
- package/dist/cjs/model/notices.schema.js +0 -25
- package/dist/cjs/offchain/notices/OffchainNotices.js +0 -27
- package/dist/cjs/offchain/notices/index.js +0 -3
- package/dist/esm/model/notices.schema.js +0 -23
- package/dist/esm/offchain/notices/OffchainNotices.js +0 -26
- package/dist/esm/offchain/notices/index.js +0 -1
- package/dist/types/model/notices.d.ts +0 -28
- package/dist/types/model/notices.schema.d.ts +0 -22
- package/dist/types/offchain/notices/OffchainNotices.d.ts +0 -18
- package/dist/types/offchain/notices/index.d.ts +0 -2
- /package/dist/cjs/model/{notices.js → aave.js} +0 -0
- /package/dist/esm/model/{notices.js → aave.js} +0 -0
|
@@ -79,6 +79,21 @@ const iSecuritizeRWAFactoryAbi = [
|
|
|
79
79
|
}],
|
|
80
80
|
stateMutability: "view"
|
|
81
81
|
},
|
|
82
|
+
{
|
|
83
|
+
type: "function",
|
|
84
|
+
name: "isAllowedBot",
|
|
85
|
+
inputs: [{
|
|
86
|
+
name: "bot",
|
|
87
|
+
type: "address",
|
|
88
|
+
internalType: "address"
|
|
89
|
+
}],
|
|
90
|
+
outputs: [{
|
|
91
|
+
name: "",
|
|
92
|
+
type: "bool",
|
|
93
|
+
internalType: "bool"
|
|
94
|
+
}],
|
|
95
|
+
stateMutability: "view"
|
|
96
|
+
},
|
|
82
97
|
{
|
|
83
98
|
type: "function",
|
|
84
99
|
name: "isCreditAccount",
|
|
@@ -14,6 +14,7 @@ exports.debtOutOfRange = require_model_errors_operation_errors.debtOutOfRange;
|
|
|
14
14
|
exports.forbiddenToken = require_model_errors_operation_errors.forbiddenToken;
|
|
15
15
|
exports.insufficientAllowance = require_model_errors_operation_errors.insufficientAllowance;
|
|
16
16
|
exports.insufficientBalance = require_model_errors_operation_errors.insufficientBalance;
|
|
17
|
+
exports.insufficientBorrowAllowance = require_model_errors_operation_errors.insufficientBorrowAllowance;
|
|
17
18
|
exports.insufficientCollateral = require_model_errors_operation_errors.insufficientCollateral;
|
|
18
19
|
exports.insufficientPoolLiquidity = require_model_errors_operation_errors.insufficientPoolLiquidity;
|
|
19
20
|
exports.leverageOutOfRange = require_model_errors_operation_errors.leverageOutOfRange;
|
|
@@ -142,6 +142,14 @@ function insufficientAllowance(args) {
|
|
|
142
142
|
...args
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
+
/** {@inheritDoc InsufficientBorrowAllowanceError} */
|
|
146
|
+
function insufficientBorrowAllowance(args) {
|
|
147
|
+
return {
|
|
148
|
+
code: "insufficientBorrowAllowance",
|
|
149
|
+
message: `${args.required.value} of ${args.required.token.symbol} borrowing must be delegated to ${args.spender} on ${args.debtToken}, ${args.allowed.value} is.`,
|
|
150
|
+
...args
|
|
151
|
+
};
|
|
152
|
+
}
|
|
145
153
|
/** {@inheritDoc RWAOpenRequirementsError} */
|
|
146
154
|
function rwaOpenRequirementsNotMet(args) {
|
|
147
155
|
return {
|
|
@@ -165,6 +173,7 @@ exports.debtOutOfRange = debtOutOfRange;
|
|
|
165
173
|
exports.forbiddenToken = forbiddenToken;
|
|
166
174
|
exports.insufficientAllowance = insufficientAllowance;
|
|
167
175
|
exports.insufficientBalance = insufficientBalance;
|
|
176
|
+
exports.insufficientBorrowAllowance = insufficientBorrowAllowance;
|
|
168
177
|
exports.insufficientCollateral = insufficientCollateral;
|
|
169
178
|
exports.insufficientPoolLiquidity = insufficientPoolLiquidity;
|
|
170
179
|
exports.leverageOutOfRange = leverageOutOfRange;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./aave.js");
|
|
2
3
|
require("./analytics.js");
|
|
3
4
|
const require_model_charts = require("./charts.js");
|
|
4
5
|
const require_model_compare_schema = require("./compare.schema.js");
|
|
@@ -22,8 +23,6 @@ const require_model_errors_prepare_errors = require("./errors/prepare-errors.js"
|
|
|
22
23
|
const require_model_errors_preview_errors = require("./errors/preview-errors.js");
|
|
23
24
|
require("./errors/index.js");
|
|
24
25
|
const require_model_liquidations = require("./liquidations.js");
|
|
25
|
-
require("./notices.js");
|
|
26
|
-
const require_model_notices_schema = require("./notices.schema.js");
|
|
27
26
|
const require_model_opportunities = require("./opportunities.js");
|
|
28
27
|
const require_model_positions = require("./positions.js");
|
|
29
28
|
const require_model_previews = require("./previews.js");
|
|
@@ -106,6 +105,7 @@ exports.forbiddenToken = require_model_errors_operation_errors.forbiddenToken;
|
|
|
106
105
|
exports.instantReceivedAssetSchema = require_model_liquidations_schema.instantReceivedAssetSchema;
|
|
107
106
|
exports.insufficientAllowance = require_model_errors_operation_errors.insufficientAllowance;
|
|
108
107
|
exports.insufficientBalance = require_model_errors_operation_errors.insufficientBalance;
|
|
108
|
+
exports.insufficientBorrowAllowance = require_model_errors_operation_errors.insufficientBorrowAllowance;
|
|
109
109
|
exports.insufficientCollateral = require_model_errors_operation_errors.insufficientCollateral;
|
|
110
110
|
exports.insufficientPoolLiquidity = require_model_errors_operation_errors.insufficientPoolLiquidity;
|
|
111
111
|
exports.isFilterSet = require_model_filters.isFilterSet;
|
|
@@ -129,8 +129,6 @@ exports.noDelayedRoute = require_model_errors_prepare_errors.noDelayedRoute;
|
|
|
129
129
|
exports.noRecordedIntent = require_model_errors_prepare_errors.noRecordedIntent;
|
|
130
130
|
exports.noStrategyTargetCollateral = require_model_errors_prepare_errors.noStrategyTargetCollateral;
|
|
131
131
|
exports.notEmergencyLiquidator = require_model_errors_liquidation_errors.notEmergencyLiquidator;
|
|
132
|
-
exports.noticeKindSchema = require_model_notices_schema.noticeKindSchema;
|
|
133
|
-
exports.noticeSchema = require_model_notices_schema.noticeSchema;
|
|
134
132
|
exports.offchainOnly = require_model_compare_schema.offchainOnly;
|
|
135
133
|
exports.onchainOnly = require_model_compare_schema.onchainOnly;
|
|
136
134
|
exports.opportunityBaseSchema = require_model_opportunities_schema.opportunityBaseSchema;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_offchain_analytics_OffchainAnalytics = require("./analytics/OffchainAnalytics.js");
|
|
3
3
|
require("./analytics/index.js");
|
|
4
|
-
const require_offchain_notices_OffchainNotices = require("./notices/OffchainNotices.js");
|
|
5
|
-
require("./notices/index.js");
|
|
6
4
|
const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
|
|
7
5
|
require("./opportunities/index.js");
|
|
8
6
|
const require_offchain_positions_OffchainPositions = require("./positions/OffchainPositions.js");
|
|
@@ -40,16 +38,11 @@ var GearboxAPI = class {
|
|
|
40
38
|
* Namespace for the positions a wallet holds.
|
|
41
39
|
**/
|
|
42
40
|
positions;
|
|
43
|
-
/**
|
|
44
|
-
* Namespace for the notices the backend attaches to entities.
|
|
45
|
-
**/
|
|
46
|
-
notices;
|
|
47
41
|
constructor(options) {
|
|
48
42
|
this.chainIds = [...options.chainIds];
|
|
49
43
|
this.analytics = new require_offchain_analytics_OffchainAnalytics.OffchainAnalytics(options);
|
|
50
44
|
this.opportunities = new require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities(options);
|
|
51
45
|
this.positions = new require_offchain_positions_OffchainPositions.OffchainPositions(options);
|
|
52
|
-
this.notices = new require_offchain_notices_OffchainNotices.OffchainNotices(options);
|
|
53
46
|
}
|
|
54
47
|
};
|
|
55
48
|
//#endregion
|
|
@@ -14,8 +14,6 @@ const require_offchain_AbstractOffchainNamespace = require("./AbstractOffchainNa
|
|
|
14
14
|
const require_offchain_analytics_OffchainAnalyticsPositions = require("./analytics/OffchainAnalyticsPositions.js");
|
|
15
15
|
const require_offchain_analytics_OffchainAnalytics = require("./analytics/OffchainAnalytics.js");
|
|
16
16
|
require("./analytics/index.js");
|
|
17
|
-
const require_offchain_notices_OffchainNotices = require("./notices/OffchainNotices.js");
|
|
18
|
-
require("./notices/index.js");
|
|
19
17
|
const require_offchain_opportunities_OffchainOpportunities = require("./opportunities/OffchainOpportunities.js");
|
|
20
18
|
require("./opportunities/index.js");
|
|
21
19
|
const require_offchain_positions_OffchainPositions = require("./positions/OffchainPositions.js");
|
|
@@ -29,7 +27,6 @@ exports.OffchainAnalyticsPositions = require_offchain_analytics_OffchainAnalytic
|
|
|
29
27
|
exports.OffchainInvalidJsonError = require_offchain_errors_OffchainInvalidJsonError.OffchainInvalidJsonError;
|
|
30
28
|
exports.OffchainNotConfiguredError = require_offchain_errors_OffchainNotConfiguredError.OffchainNotConfiguredError;
|
|
31
29
|
exports.OffchainNotImplementedError = require_offchain_errors_OffchainNotImplementedError.OffchainNotImplementedError;
|
|
32
|
-
exports.OffchainNotices = require_offchain_notices_OffchainNotices.OffchainNotices;
|
|
33
30
|
exports.OffchainOpportunities = require_offchain_opportunities_OffchainOpportunities.OffchainOpportunities;
|
|
34
31
|
exports.OffchainPositions = require_offchain_positions_OffchainPositions.OffchainPositions;
|
|
35
32
|
exports.OffchainRequestFailedError = require_offchain_errors_OffchainRequestFailedError.OffchainRequestFailedError;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_abi_310_generated = require("../../../abi/310/generated.js");
|
|
3
|
+
const require_abi_compressors_peripheryCompressor = require("../../../abi/compressors/peripheryCompressor.js");
|
|
4
|
+
const require_onchain_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
5
|
const require_onchain_constants_address_provider = require("../../constants/address-provider.js");
|
|
4
6
|
const require_onchain_constants_versions = require("../../constants/versions.js");
|
|
5
7
|
require("../../constants/index.js");
|
|
8
|
+
require("../../utils/index.js");
|
|
6
9
|
const require_onchain_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
7
10
|
require("../../base/index.js");
|
|
8
11
|
const require_onchain_accounts_bots_abi = require("./abi.js");
|
|
@@ -15,6 +18,32 @@ const require_onchain_accounts_bots_PeripheryCompressorV310Contract = require(".
|
|
|
15
18
|
* and builds the transactions that connect or disconnect one.
|
|
16
19
|
**/
|
|
17
20
|
var AccountBotsService = class extends require_onchain_base_SDKConstruct.SDKConstruct {
|
|
21
|
+
#marketBots = new require_onchain_utils_AddressMap.AddressMap(void 0, "marketBots");
|
|
22
|
+
/**
|
|
23
|
+
* The bots a market configurator lists among its periphery contracts.
|
|
24
|
+
*
|
|
25
|
+
* Read once per configurator and kept for the service's lifetime: the list
|
|
26
|
+
* changes only when the curator adds or removes a bot. A failed read is not
|
|
27
|
+
* kept, so the next call tries again.
|
|
28
|
+
*
|
|
29
|
+
* @param marketConfigurator - Configurator to list the bots of.
|
|
30
|
+
**/
|
|
31
|
+
getMarketBots(marketConfigurator) {
|
|
32
|
+
let bots = this.#marketBots.get(marketConfigurator);
|
|
33
|
+
if (!bots) {
|
|
34
|
+
bots = this.client.readContract({
|
|
35
|
+
address: this.#compressor.address,
|
|
36
|
+
abi: require_abi_compressors_peripheryCompressor.peripheryCompressorAbi,
|
|
37
|
+
functionName: "getBots",
|
|
38
|
+
args: [marketConfigurator]
|
|
39
|
+
}).catch((e) => {
|
|
40
|
+
this.#marketBots.delete(marketConfigurator);
|
|
41
|
+
throw e;
|
|
42
|
+
});
|
|
43
|
+
this.#marketBots.upsert(marketConfigurator, bots);
|
|
44
|
+
}
|
|
45
|
+
return bots;
|
|
46
|
+
}
|
|
18
47
|
/**
|
|
19
48
|
* Reads the bots connected to each of the given credit accounts.
|
|
20
49
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_abi_compressors_peripheryCompressor = require("../../../abi/compressors/peripheryCompressor.js");
|
|
2
3
|
const require_onchain_base_BaseContract = require("../../base/BaseContract.js");
|
|
3
4
|
require("../../base/index.js");
|
|
4
5
|
//#region src/onchain/accounts/bots/PeripheryCompressorV310Contract.ts
|
|
5
|
-
const abi =
|
|
6
|
+
const abi = require_abi_compressors_peripheryCompressor.peripheryCompressorAbi;
|
|
6
7
|
var PeripheryCompressorV310Contract = class extends require_onchain_base_BaseContract.BaseContract {
|
|
7
8
|
constructor(sdk, address) {
|
|
8
9
|
super(sdk, {
|
|
@@ -9,6 +9,7 @@ const require_onchain_accounts_CreditAccountsServiceV310 = require("./CreditAcco
|
|
|
9
9
|
const require_onchain_accounts_intents_utils_pick_token = require("./intents/utils/pick-token.js");
|
|
10
10
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("./intents/utils/credit-account-slice.js");
|
|
11
11
|
const require_onchain_accounts_quota_utils = require("./quota-utils.js");
|
|
12
|
+
const require_onchain_accounts_withdrawal_compressor_intent_codec = require("./withdrawal-compressor/intent-codec.js");
|
|
12
13
|
const require_onchain_accounts_intents_index = require("./intents/index.js");
|
|
13
14
|
const require_onchain_accounts_liquidations_constants = require("./liquidations/constants.js");
|
|
14
15
|
const require_onchain_accounts_liquidations_partialLiquidation = require("./liquidations/partialLiquidation.js");
|
|
@@ -16,7 +17,6 @@ const require_onchain_accounts_liquidations_LiquidationsService = require("./liq
|
|
|
16
17
|
const require_onchain_accounts_liquidations_MultichainLiquidationsService = require("./liquidations/MultichainLiquidationsService.js");
|
|
17
18
|
require("./liquidations/index.js");
|
|
18
19
|
require("./types.js");
|
|
19
|
-
const require_onchain_accounts_withdrawal_compressor_intent_codec = require("./withdrawal-compressor/intent-codec.js");
|
|
20
20
|
const require_onchain_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract = require("./withdrawal-compressor/AbstractWithdrawalCompressorContract.js");
|
|
21
21
|
const require_onchain_accounts_withdrawal_compressor_addresses = require("./withdrawal-compressor/addresses.js");
|
|
22
22
|
const require_onchain_accounts_withdrawal_compressor_RedemptionLoggerV310Contract = require("./withdrawal-compressor/RedemptionLoggerV310Contract.js");
|
|
@@ -19,6 +19,7 @@ const require_onchain_accounts_intents_maxBorrowAndWithdraw = require("./maxBorr
|
|
|
19
19
|
const require_onchain_accounts_intents_maxWithdrawCollateral = require("./maxWithdrawCollateral.js");
|
|
20
20
|
const require_onchain_accounts_intents_open_strategy = require("./open-strategy.js");
|
|
21
21
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
22
|
+
const require_onchain_accounts_intents_readAaveHoldings = require("./readAaveHoldings.js");
|
|
22
23
|
const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
|
|
23
24
|
const require_onchain_accounts_intents_realize = require("./realize.js");
|
|
24
25
|
const require_onchain_accounts_intents_tail = require("./tail.js");
|
|
@@ -239,6 +240,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
239
240
|
switch (intent.type) {
|
|
240
241
|
case "ADJUST_LEVERAGE": return require_onchain_accounts_intents_plan.planAdjustLeverageDelayed(intent, view);
|
|
241
242
|
case "WITHDRAW": return require_onchain_accounts_intents_plan.planWithdrawDelayed(intent, view);
|
|
243
|
+
case "CLOSE_AAVE_POSITION": return require_onchain_accounts_intents_plan.planCloseAavePosition(intent, view);
|
|
242
244
|
default: throw new Error(`${intent.type} - cannot be delayed`);
|
|
243
245
|
}
|
|
244
246
|
}, limits);
|
|
@@ -273,6 +275,37 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
/**
|
|
278
|
+
* Previews leaving `owner`'s Aave Horizon position in `token` in one
|
|
279
|
+
* transaction, see {@link CloseAavePositionIntent}.
|
|
280
|
+
*
|
|
281
|
+
* What the owner holds and owes on Aave is read here, at the block the SDK
|
|
282
|
+
* stands at; the rest is {@link startDelayedIntent}, tail included.
|
|
283
|
+
*
|
|
284
|
+
* @param props - Account slice, quota reserve and slippage, the RWA, the
|
|
285
|
+
* wallet the exit pays, and the owner the bridge resolves for the account:
|
|
286
|
+
* the investor of an RWA factory account, the borrower otherwise
|
|
287
|
+
* @returns The request transaction, the state the exit ends in and what it
|
|
288
|
+
* recorded for the tail, or `{ ok: false, error }`
|
|
289
|
+
*/
|
|
290
|
+
async closeAavePositionIntent(props) {
|
|
291
|
+
const { token, to, owner, ...rest } = props;
|
|
292
|
+
let holdings;
|
|
293
|
+
try {
|
|
294
|
+
holdings = await require_onchain_accounts_intents_readAaveHoldings.readAaveHoldings(rest.sdk, rest.creditAccount.creditManager, owner, token);
|
|
295
|
+
} catch (e) {
|
|
296
|
+
return asRefused(e, rest.draft ?? {});
|
|
297
|
+
}
|
|
298
|
+
return this.startDelayedIntent({
|
|
299
|
+
...rest,
|
|
300
|
+
intent: {
|
|
301
|
+
type: "CLOSE_AAVE_POSITION",
|
|
302
|
+
token,
|
|
303
|
+
to,
|
|
304
|
+
holdings
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
276
309
|
* Previews a delayable intent both ways at once: settled by the router now,
|
|
277
310
|
* and started as a redemption that finishes days later.
|
|
278
311
|
*
|
|
@@ -135,6 +135,25 @@ function buildClaimDelayedWithdrawalOperation(input) {
|
|
|
135
135
|
})
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
+
function buildAaveClosePositionOperation(input) {
|
|
139
|
+
return {
|
|
140
|
+
type: "aaveClosePosition",
|
|
141
|
+
aToken: input.aToken,
|
|
142
|
+
aTokenAmount: input.aTokenAmount,
|
|
143
|
+
debtToken: input.debtToken,
|
|
144
|
+
repayAmount: input.repayAmount,
|
|
145
|
+
calls: [input.adapter.closePositionCall(input.aToken, input.debtToken, input.repayAmount, input.aTokenAmount)]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function buildAaveWithdrawOperation(input) {
|
|
149
|
+
return {
|
|
150
|
+
type: "aaveWithdraw",
|
|
151
|
+
token: input.token,
|
|
152
|
+
aToken: input.aToken,
|
|
153
|
+
amount: input.amount,
|
|
154
|
+
calls: [input.adapter.withdrawDiffCall(input.token, 0n)]
|
|
155
|
+
};
|
|
156
|
+
}
|
|
138
157
|
/**
|
|
139
158
|
* What a request or a claim puts on the account right away, as opposed to what
|
|
140
159
|
* only the phantom token represents.
|
|
@@ -150,6 +169,8 @@ function instantOutput(outputs, token) {
|
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
171
|
//#endregion
|
|
172
|
+
exports.buildAaveClosePositionOperation = buildAaveClosePositionOperation;
|
|
173
|
+
exports.buildAaveWithdrawOperation = buildAaveWithdrawOperation;
|
|
153
174
|
exports.buildAddCollateralOperation = buildAddCollateralOperation;
|
|
154
175
|
exports.buildClaimDelayedWithdrawalOperation = buildClaimDelayedWithdrawalOperation;
|
|
155
176
|
exports.buildCloseSwapOperation = buildCloseSwapOperation;
|
|
@@ -105,6 +105,53 @@ function planRepay(intent, view) {
|
|
|
105
105
|
];
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
+
* The owner's Aave position comes back and leaves: the account borrows what
|
|
109
|
+
* the owner owes on Aave, the bridge repays it and returns the aTokens, the
|
|
110
|
+
* pool turns them back into the RWA, and the RWA is requested for redemption
|
|
111
|
+
* with an exit recorded for the tail — all in one transaction.
|
|
112
|
+
*
|
|
113
|
+
* The repayment is the debt plus {@link CLOSE_AAVE_WINDOW} of interest at the
|
|
114
|
+
* current rate, see {@link CloseAavePositionIntent}.
|
|
115
|
+
*/
|
|
116
|
+
function planCloseAavePosition(intent, view) {
|
|
117
|
+
const { token, holdings } = intent;
|
|
118
|
+
const U = view.underlying;
|
|
119
|
+
if (require_onchain_accounts_intents_utils_common.eq(token, U) || require_onchain_constants_math.isZeroBalance(holdings.supplied)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(view.sdk, token)), `closeAavePosition: the owner holds no aToken of ${token} on Aave`);
|
|
120
|
+
if (holdings.owed <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.debtOutOfRange({
|
|
121
|
+
requested: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, 0n),
|
|
122
|
+
minDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
|
|
123
|
+
maxDebt: require_onchain_validation_helpers_token.toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
|
|
124
|
+
}), "closeAavePosition: the owner owes nothing on Aave");
|
|
125
|
+
const repay = holdings.owed + ceilDiv(holdings.owed * holdings.borrowRate * CLOSE_AAVE_WINDOW, require_onchain_constants_math.RAY * BigInt(require_onchain_constants_math.SECONDS_PER_YEAR));
|
|
126
|
+
let borrowed = require_onchain_accounts_intents_utils_common.toTargetDecimals(repay, holdings.debtToken, U, view.sdk);
|
|
127
|
+
if (require_onchain_accounts_intents_utils_common.toTargetDecimals(borrowed, U, holdings.debtToken, view.sdk) < repay) borrowed += 1n;
|
|
128
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt + borrowed, view.debtLimits, U, view.limits);
|
|
129
|
+
return [
|
|
130
|
+
borrow(borrowed),
|
|
131
|
+
...require_onchain_accounts_intents_utils_common.eq(holdings.debtToken, U) ? [] : [convert(U, holdings.debtToken, borrowed)],
|
|
132
|
+
{
|
|
133
|
+
kind: "aaveClosePosition",
|
|
134
|
+
token,
|
|
135
|
+
repay,
|
|
136
|
+
aTokenAmount: holdings.supplied
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
kind: "aaveWithdraw",
|
|
140
|
+
token
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
kind: "request",
|
|
144
|
+
token,
|
|
145
|
+
amount: view.balanceOf(token) + holdings.supplied,
|
|
146
|
+
reserve: 0n,
|
|
147
|
+
record: {
|
|
148
|
+
type: "CLOSE_ACCOUNT",
|
|
149
|
+
to: intent.to
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
108
155
|
* One token's quota changes; no balance moves and debt is untouched.
|
|
109
156
|
*
|
|
110
157
|
* Only a token the account holds can be quoted here, and only on an account
|
|
@@ -407,6 +454,13 @@ const clearQuotas = () => ({ kind: "clearQuotas" });
|
|
|
407
454
|
*/
|
|
408
455
|
const SETTLE_MARGIN = 10n;
|
|
409
456
|
const withMargin = (debt) => debt + debt * SETTLE_MARGIN / require_onchain_constants_math.PERCENTAGE_FACTOR;
|
|
457
|
+
/**
|
|
458
|
+
* Seconds of Aave interest a closing repays on top of the debt it read: the
|
|
459
|
+
* bridge keeps whatever Aave does not take, so this is paid for, unlike
|
|
460
|
+
* {@link SETTLE_MARGIN}, and an hour costs a fraction of a basis point.
|
|
461
|
+
*/
|
|
462
|
+
const CLOSE_AAVE_WINDOW = 3600n;
|
|
463
|
+
const ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
410
464
|
/** The amount that asks for all of it, whatever "all" turns out to be. */
|
|
411
465
|
const everything = (amount) => amount >= require_onchain_constants_math.MAX_UINT256;
|
|
412
466
|
const min = (a, b) => a < b ? a : b;
|
|
@@ -451,6 +505,7 @@ exports.planAddCollateral = planAddCollateral;
|
|
|
451
505
|
exports.planAdjustLeverage = planAdjustLeverage;
|
|
452
506
|
exports.planAdjustLeverageDelayed = planAdjustLeverageDelayed;
|
|
453
507
|
exports.planBorrowAndWithdraw = planBorrowAndWithdraw;
|
|
508
|
+
exports.planCloseAavePosition = planCloseAavePosition;
|
|
454
509
|
exports.planDeposit = planDeposit;
|
|
455
510
|
exports.planFinishClaimOnly = planFinishClaimOnly;
|
|
456
511
|
exports.planFinishCloseAccount = planFinishCloseAccount;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_market_adapters_abi_aave_iAaveV3Pool = require("../../market/adapters/abi/aave/iAaveV3Pool.js");
|
|
3
|
+
require("../../market/adapters/abi/aave/index.js");
|
|
4
|
+
const require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract = require("../../market/adapters/contracts/AaveV3PoolAdapterContract.js");
|
|
5
|
+
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
6
|
+
require("../../../model/index.js");
|
|
7
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
8
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
9
|
+
let viem = require("viem");
|
|
10
|
+
//#region src/onchain/accounts/intents/readAaveHoldings.ts
|
|
11
|
+
/**
|
|
12
|
+
* What `owner` holds and owes on the Aave pool the credit manager supplies
|
|
13
|
+
* `token` to: its aTokens of `token`, and its variable debt in the asset the
|
|
14
|
+
* Horizon bridge lends there — the underlying, or the asset an RWA underlying
|
|
15
|
+
* wraps.
|
|
16
|
+
*
|
|
17
|
+
* Refused with `unsupportedCollateralToken` when no Aave pool adapter of the
|
|
18
|
+
* credit manager lists `token`.
|
|
19
|
+
*/
|
|
20
|
+
async function readAaveHoldings(sdk, creditManager, owner, token) {
|
|
21
|
+
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
22
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract.AaveV3PoolAdapterContract && a.isAssetAllowed(token));
|
|
23
|
+
if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `readAaveHoldings: no Aave pool adapter lists ${token}`);
|
|
24
|
+
const underlying = suite.underlying;
|
|
25
|
+
const debtToken = sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset ?? underlying;
|
|
26
|
+
const [aToken, reserve] = await Promise.all([adapter.aToken(token), sdk.client.readContract({
|
|
27
|
+
address: adapter.pool,
|
|
28
|
+
abi: require_onchain_market_adapters_abi_aave_iAaveV3Pool.iAaveV3PoolAbi,
|
|
29
|
+
functionName: "getReserveData",
|
|
30
|
+
args: [debtToken]
|
|
31
|
+
})]);
|
|
32
|
+
const [supplied, owed] = await sdk.client.multicall({
|
|
33
|
+
contracts: [{
|
|
34
|
+
address: aToken,
|
|
35
|
+
abi: viem.erc20Abi,
|
|
36
|
+
functionName: "balanceOf",
|
|
37
|
+
args: [owner]
|
|
38
|
+
}, {
|
|
39
|
+
address: reserve.variableDebtTokenAddress,
|
|
40
|
+
abi: viem.erc20Abi,
|
|
41
|
+
functionName: "balanceOf",
|
|
42
|
+
args: [owner]
|
|
43
|
+
}],
|
|
44
|
+
allowFailure: false,
|
|
45
|
+
batchSize: 0
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
aToken,
|
|
49
|
+
debtToken,
|
|
50
|
+
supplied,
|
|
51
|
+
owed,
|
|
52
|
+
borrowRate: reserve.currentVariableBorrowRate
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.readAaveHoldings = readAaveHoldings;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_chain_chains = require("../../chain/chains.js");
|
|
3
3
|
const require_onchain_constants_math = require("../../constants/math.js");
|
|
4
|
+
const require_onchain_market_adapters_contracts_AaveHorizonBridgeAdapterContract = require("../../market/adapters/contracts/AaveHorizonBridgeAdapterContract.js");
|
|
5
|
+
const require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract = require("../../market/adapters/contracts/AaveV3PoolAdapterContract.js");
|
|
6
|
+
const require_onchain_market_adapters_contracts_SecuritizeRedemptionGatewayAdapterContract = require("../../market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js");
|
|
4
7
|
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
5
8
|
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
6
9
|
require("../../../model/index.js");
|
|
@@ -13,6 +16,7 @@ const require_onchain_accounts_intents_utils_ledger = require("./utils/ledger.js
|
|
|
13
16
|
const require_onchain_accounts_intents_utils_price_impact = require("./utils/price-impact.js");
|
|
14
17
|
const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
|
|
15
18
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
19
|
+
const require_onchain_accounts_withdrawal_compressor_intent_codec = require("../withdrawal-compressor/intent-codec.js");
|
|
16
20
|
const require_onchain_accounts_intents_operations = require("./operations.js");
|
|
17
21
|
const require_onchain_accounts_intents_resolveQuotaUpdate = require("./resolveQuotaUpdate.js");
|
|
18
22
|
const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
|
|
@@ -286,12 +290,19 @@ async function realize(steps, props) {
|
|
|
286
290
|
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.withdrawalInProgress(require_onchain_validation_helpers_token.toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
|
|
287
291
|
assertHolds(step.token, step.amount + step.reserve, "request");
|
|
288
292
|
if (step.record.type !== "CLOSE_ACCOUNT") directTransfer ??= require_onchain_chain_chains.getDirectTransferToken(step.token, sdk.networkType);
|
|
289
|
-
const preview = await sdk.accounts.previewDelayedWithdrawal({
|
|
293
|
+
const preview = (creditAccount.tokens.find((t) => require_onchain_accounts_intents_utils_common.eq(t.token, step.token))?.balance ?? 0n) >= step.amount ? await sdk.accounts.previewDelayedWithdrawal({
|
|
290
294
|
creditAccount: creditAccount.creditAccount,
|
|
291
295
|
token: step.token,
|
|
292
296
|
amount: step.amount,
|
|
293
297
|
withdrawalPhantomToken: asset.withdrawalPhantomToken,
|
|
294
298
|
intent: step.record
|
|
299
|
+
}) : await arrivingRedemption({
|
|
300
|
+
sdk,
|
|
301
|
+
suite,
|
|
302
|
+
asset,
|
|
303
|
+
amount: step.amount,
|
|
304
|
+
leftover: ledger.balanceOf(step.token) - step.amount,
|
|
305
|
+
record: step.record
|
|
295
306
|
});
|
|
296
307
|
push(require_onchain_accounts_intents_operations.buildStartDelayedWithdrawalOperation({
|
|
297
308
|
preview,
|
|
@@ -328,8 +339,9 @@ async function realize(steps, props) {
|
|
|
328
339
|
break;
|
|
329
340
|
case "sweep": {
|
|
330
341
|
withdrawsCollateral = true;
|
|
342
|
+
const swept = (token) => !step.token || require_onchain_accounts_intents_utils_common.eq(token, step.token) || rwaAsset !== void 0 && require_onchain_accounts_intents_utils_common.eq(step.token, underlying) && require_onchain_accounts_intents_utils_common.eq(token, rwaAsset);
|
|
331
343
|
const wrapped = ledger.balanceOf(underlying);
|
|
332
|
-
if (rwaAsset && wrapped > 0n) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
|
|
344
|
+
if (rwaAsset && wrapped > 0n && swept(underlying)) push(await require_onchain_accounts_intents_operations.buildUnwrapRwaCollateralOperation({
|
|
333
345
|
tokenIn: underlying,
|
|
334
346
|
all: true,
|
|
335
347
|
amountIn: wrapped,
|
|
@@ -339,6 +351,7 @@ async function realize(steps, props) {
|
|
|
339
351
|
sdk
|
|
340
352
|
}));
|
|
341
353
|
for (const { token, balance } of ledger.snapshot().assets) {
|
|
354
|
+
if (!swept(token)) continue;
|
|
342
355
|
const withdrawal = require_onchain_accounts_intents_operations.buildWithdrawCollateralOperation({
|
|
343
356
|
token,
|
|
344
357
|
amount: balance,
|
|
@@ -354,6 +367,36 @@ async function realize(steps, props) {
|
|
|
354
367
|
}
|
|
355
368
|
break;
|
|
356
369
|
}
|
|
370
|
+
case "aaveClosePosition": {
|
|
371
|
+
const aToken = await aavePoolAdapter(sdk, suite, step.token).aToken(step.token);
|
|
372
|
+
const debtToken = rwaAsset ?? underlying;
|
|
373
|
+
assertHolds(debtToken, step.repay, "aaveClosePosition");
|
|
374
|
+
push(require_onchain_accounts_intents_operations.buildAaveClosePositionOperation({
|
|
375
|
+
adapter: aaveBridgeAdapter(sdk, suite, step.token, {
|
|
376
|
+
aToken,
|
|
377
|
+
debtToken
|
|
378
|
+
}),
|
|
379
|
+
aToken,
|
|
380
|
+
aTokenAmount: step.aTokenAmount,
|
|
381
|
+
debtToken,
|
|
382
|
+
repayAmount: step.repay
|
|
383
|
+
}));
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case "aaveWithdraw": {
|
|
387
|
+
const adapter = aavePoolAdapter(sdk, suite, step.token);
|
|
388
|
+
const aToken = await adapter.aToken(step.token);
|
|
389
|
+
const amount = ledger.balanceOf(aToken);
|
|
390
|
+
assertHolds(aToken, amount, "aaveWithdraw");
|
|
391
|
+
push(require_onchain_accounts_intents_operations.buildAaveWithdrawOperation({
|
|
392
|
+
adapter,
|
|
393
|
+
token: step.token,
|
|
394
|
+
aToken,
|
|
395
|
+
amount
|
|
396
|
+
}));
|
|
397
|
+
raised = amount;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
357
400
|
}
|
|
358
401
|
const floor = ledger.snapshot();
|
|
359
402
|
const { assets, debt } = floor;
|
|
@@ -476,6 +519,45 @@ async function delayedConfig(sdk, creditAccount, token) {
|
|
|
476
519
|
if (assets.length > 1) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.multipleDelayedWithdrawals(require_onchain_validation_helpers_token.toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
477
520
|
return assets[0];
|
|
478
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* The request for a redemption of a balance an earlier call of the same
|
|
524
|
+
* multicall brings in. The withdrawal compressor caps what it quotes at the
|
|
525
|
+
* balance the account holds before the transaction, so the request is built
|
|
526
|
+
* here instead: a diff call that names no amount, its phantom valued the way
|
|
527
|
+
* the gateway values it. Only a Securitize redemption gateway redeems that
|
|
528
|
+
* way; any other redemption is refused with `noDelayedRoute`.
|
|
529
|
+
*/
|
|
530
|
+
async function arrivingRedemption(input) {
|
|
531
|
+
const { sdk, suite, asset, amount } = input;
|
|
532
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_SecuritizeRedemptionGatewayAdapterContract.SecuritizeRedemptionGatewayAdapterContract && require_onchain_accounts_intents_utils_common.eq(a.dsToken, asset.token) && require_onchain_accounts_intents_utils_common.eq(a.redemptionPhantomToken, asset.withdrawalPhantomToken));
|
|
533
|
+
if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.noDelayedRoute(require_onchain_validation_helpers_token.toToken(sdk, asset.token)), `request: ${asset.token} arrives in this transaction, and only a Securitize gateway redeems it without a quote`);
|
|
534
|
+
return {
|
|
535
|
+
token: asset.token,
|
|
536
|
+
amountIn: amount,
|
|
537
|
+
outputs: [{
|
|
538
|
+
token: asset.withdrawalPhantomToken,
|
|
539
|
+
isDelayed: true,
|
|
540
|
+
amount: await adapter.redemptionValue(amount)
|
|
541
|
+
}],
|
|
542
|
+
requestCalls: [adapter.redeemDiffCall(input.leftover, require_onchain_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent(input.record))],
|
|
543
|
+
claimableAt: sdk.timestamp + asset.withdrawalLength
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/** The credit manager's Aave pool adapter that lists `token`. */
|
|
547
|
+
function aavePoolAdapter(sdk, suite, token) {
|
|
548
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveV3PoolAdapterContract.AaveV3PoolAdapterContract && a.isAssetAllowed(token));
|
|
549
|
+
if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aave: no Aave pool adapter lists ${token}`);
|
|
550
|
+
return adapter;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The credit manager's Horizon bridge adapter that takes `aToken` and lends
|
|
554
|
+
* `debtToken`. Refused on `token`, the collateral the aToken stands for.
|
|
555
|
+
*/
|
|
556
|
+
function aaveBridgeAdapter(sdk, suite, token, pair) {
|
|
557
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof require_onchain_market_adapters_contracts_AaveHorizonBridgeAdapterContract.AaveHorizonBridgeAdapterContract && a.isATokenAllowed(pair.aToken) && a.isDebtTokenAllowed(pair.debtToken));
|
|
558
|
+
if (!adapter) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, token)), `aaveClosePosition: no Horizon bridge adapter takes ${pair.aToken} against ${pair.debtToken}`);
|
|
559
|
+
return adapter;
|
|
560
|
+
}
|
|
479
561
|
const callsOf = (operations) => operations.flatMap((op) => op.calls);
|
|
480
562
|
const min = (a, b) => a < b ? a : b;
|
|
481
563
|
/** Balance the router's close path refuses to route, and leaves in place. */
|
|
@@ -114,6 +114,7 @@ function buildMarketSdk(extras) {
|
|
|
114
114
|
debtLimitAvailable: extras?.debtLimitAvailable,
|
|
115
115
|
maxDebtPerBlockMultiplier: extras?.maxDebtPerBlockMultiplier,
|
|
116
116
|
forbiddenTokens: extras?.forbiddenTokens,
|
|
117
|
+
adapters: extras?.adapters,
|
|
117
118
|
strategyTargetCollateral: POS
|
|
118
119
|
});
|
|
119
120
|
}
|
|
@@ -211,7 +211,8 @@ function buildMockSdk(args) {
|
|
|
211
211
|
collateralTokens,
|
|
212
212
|
feeInterest: args.feeInterest ?? 0,
|
|
213
213
|
maxEnabledTokens: args.maxEnabledTokens ?? 4,
|
|
214
|
-
maxLeverage: (collateral, targetHF) => require_onchain_market_math.calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0, targetHF)
|
|
214
|
+
maxLeverage: (collateral, targetHF) => require_onchain_market_math.calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0, targetHF),
|
|
215
|
+
adapters: { values: () => args.adapters ?? [] }
|
|
215
216
|
},
|
|
216
217
|
creditFacade: {
|
|
217
218
|
address: args.creditFacade,
|
|
@@ -325,7 +326,7 @@ function buildMockSdk(args) {
|
|
|
325
326
|
chainId: 1,
|
|
326
327
|
networkType: "Mainnet",
|
|
327
328
|
currentBlock: 1n,
|
|
328
|
-
timestamp: args.timestamp ?? 0,
|
|
329
|
+
timestamp: BigInt(args.timestamp ?? 0),
|
|
329
330
|
withdrawalCompressor,
|
|
330
331
|
tokensMeta: {
|
|
331
332
|
get: (token) => ({
|
|
@@ -80,6 +80,14 @@ var OperationLedger = class {
|
|
|
80
80
|
case "claimDelayedWithdrawal":
|
|
81
81
|
this.#add(op.withdrawalPhantomToken, -op.withdrawalTokenSpent);
|
|
82
82
|
for (const out of op.outputs) this.#add(out.token, out.amount);
|
|
83
|
+
break;
|
|
84
|
+
case "aaveClosePosition":
|
|
85
|
+
this.#add(op.debtToken, -op.repayAmount);
|
|
86
|
+
this.#add(op.aToken, op.aTokenAmount);
|
|
87
|
+
break;
|
|
88
|
+
case "aaveWithdraw":
|
|
89
|
+
this.#add(op.aToken, -op.amount);
|
|
90
|
+
this.#add(op.token, op.amount);
|
|
83
91
|
}
|
|
84
92
|
return this;
|
|
85
93
|
}
|
|
@@ -355,6 +355,10 @@ const chains = {
|
|
|
355
355
|
}),
|
|
356
356
|
Lisk: (0, viem.defineChain)({
|
|
357
357
|
...viem_chains.lisk,
|
|
358
|
+
rpcUrls: {
|
|
359
|
+
...viem_chains.lisk.rpcUrls,
|
|
360
|
+
tenderly: { http: ["https://lisk.gateway.tenderly.co"] }
|
|
361
|
+
},
|
|
358
362
|
network: "Lisk",
|
|
359
363
|
defaultMarketConfigurators: require_onchain_utils_AddressMap.AddressMap.fromRecord({ "0x25778dbf0e56b7feb8358c4aa2f6f9e19a1c145a": "Re7" }),
|
|
360
364
|
rwaFactories: [],
|