@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
package/dist/esm/model/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./aave.js";
|
|
1
2
|
import "./analytics.js";
|
|
2
3
|
import { CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS } from "./charts.js";
|
|
3
4
|
import { backendPreferred, compareTagOf, offchainOnly, onchainOnly, tolerance } from "./compare.schema.js";
|
|
@@ -15,14 +16,12 @@ import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analy
|
|
|
15
16
|
import "./curators.js";
|
|
16
17
|
import "./delayed-intents.js";
|
|
17
18
|
import { creditAccountFrozen, liquidatorNotEligible, notEmergencyLiquidator, partialLiquidationImpossible } from "./errors/liquidation-errors.js";
|
|
18
|
-
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
19
|
+
import { accountNotMidasGreenlisted, creditManagerPaused, debtOutOfRange, forbiddenToken, insufficientAllowance, insufficientBalance, insufficientBorrowAllowance, insufficientCollateral, insufficientPoolLiquidity, leverageOutOfRange, marketExpired, poolPaused, poolSunset, quotaAboveMax, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, reservePriceLimited, rwaOpenRequirementsNotMet } from "./errors/operation-errors.js";
|
|
19
20
|
import { unpriceableTokenError } from "./errors/oracle-errors.js";
|
|
20
21
|
import { creditAccountNotEmpty, creditAccountNotFound, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress } from "./errors/prepare-errors.js";
|
|
21
22
|
import { malformedTransaction } from "./errors/preview-errors.js";
|
|
22
23
|
import "./errors/index.js";
|
|
23
24
|
import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
24
|
-
import "./notices.js";
|
|
25
|
-
import { noticeKindSchema, noticeSchema } from "./notices.schema.js";
|
|
26
25
|
import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
27
26
|
import { STRATEGY_POSITION_COLLATERAL_ERROR, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
28
27
|
import { asEstimated } from "./previews.js";
|
|
@@ -33,4 +32,4 @@ import { safeValue, sdkErr, sdkOk } from "./result.js";
|
|
|
33
32
|
import "./rewards.js";
|
|
34
33
|
import "./withdrawals.js";
|
|
35
34
|
import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
|
|
36
|
-
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator,
|
|
35
|
+
export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, accountNotMidasGreenlisted, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsContractOptionSchema, analyticsContractRefSchema, analyticsCuratorOptionSchema, analyticsPositionFilterOptionsQuerySchema, analyticsPositionFilterOptionsSchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientBorrowAllowance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, partialLiquidationImpossible, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAboveMax, quotaAssetSchema, quotaCountExceeded, quotaInactive, quotaLimitReached, quotaUnchanged, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, reservePriceLimited, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { OffchainAnalytics } from "./analytics/OffchainAnalytics.js";
|
|
2
2
|
import "./analytics/index.js";
|
|
3
|
-
import { OffchainNotices } from "./notices/OffchainNotices.js";
|
|
4
|
-
import "./notices/index.js";
|
|
5
3
|
import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
|
|
6
4
|
import "./opportunities/index.js";
|
|
7
5
|
import { OffchainPositions } from "./positions/OffchainPositions.js";
|
|
@@ -39,16 +37,11 @@ var GearboxAPI = class {
|
|
|
39
37
|
* Namespace for the positions a wallet holds.
|
|
40
38
|
**/
|
|
41
39
|
positions;
|
|
42
|
-
/**
|
|
43
|
-
* Namespace for the notices the backend attaches to entities.
|
|
44
|
-
**/
|
|
45
|
-
notices;
|
|
46
40
|
constructor(options) {
|
|
47
41
|
this.chainIds = [...options.chainIds];
|
|
48
42
|
this.analytics = new OffchainAnalytics(options);
|
|
49
43
|
this.opportunities = new OffchainOpportunities(options);
|
|
50
44
|
this.positions = new OffchainPositions(options);
|
|
51
|
-
this.notices = new OffchainNotices(options);
|
|
52
45
|
}
|
|
53
46
|
};
|
|
54
47
|
//#endregion
|
|
@@ -13,12 +13,10 @@ import { AbstractOffchainNamespace } from "./AbstractOffchainNamespace.js";
|
|
|
13
13
|
import { OffchainAnalyticsPositions } from "./analytics/OffchainAnalyticsPositions.js";
|
|
14
14
|
import { OffchainAnalytics } from "./analytics/OffchainAnalytics.js";
|
|
15
15
|
import "./analytics/index.js";
|
|
16
|
-
import { OffchainNotices } from "./notices/OffchainNotices.js";
|
|
17
|
-
import "./notices/index.js";
|
|
18
16
|
import { OffchainOpportunities } from "./opportunities/OffchainOpportunities.js";
|
|
19
17
|
import "./opportunities/index.js";
|
|
20
18
|
import { OffchainPositions } from "./positions/OffchainPositions.js";
|
|
21
19
|
import "./positions/index.js";
|
|
22
20
|
import { GearboxAPI } from "./GearboxAPI.js";
|
|
23
21
|
import "./types.js";
|
|
24
|
-
export { AbstractOffchainNamespace, GearboxAPI, OffchainAnalytics, OffchainAnalyticsPositions, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError,
|
|
22
|
+
export { AbstractOffchainNamespace, GearboxAPI, OffchainAnalytics, OffchainAnalyticsPositions, OffchainInvalidJsonError, OffchainNotConfiguredError, OffchainNotImplementedError, OffchainOpportunities, OffchainPositions, OffchainRequestFailedError, OffchainStatusError, OffchainTransportError, OffchainValidationError, backendMessage, errorCause, readResponseBody };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { iBotListV310Abi } from "../../../abi/310/generated.js";
|
|
2
|
+
import { peripheryCompressorAbi } from "../../../abi/compressors/peripheryCompressor.js";
|
|
3
|
+
import { AddressMap } from "../../utils/AddressMap.js";
|
|
2
4
|
import { AP_PERIPHERY_COMPRESSOR } from "../../constants/address-provider.js";
|
|
3
5
|
import { VERSION_RANGE_310 } from "../../constants/versions.js";
|
|
4
6
|
import "../../constants/index.js";
|
|
7
|
+
import "../../utils/index.js";
|
|
5
8
|
import { SDKConstruct } from "../../base/SDKConstruct.js";
|
|
6
9
|
import "../../base/index.js";
|
|
7
10
|
import { iBotAbi } from "./abi.js";
|
|
@@ -14,6 +17,32 @@ import { PeripheryCompressorV310Contract } from "./PeripheryCompressorV310Contra
|
|
|
14
17
|
* and builds the transactions that connect or disconnect one.
|
|
15
18
|
**/
|
|
16
19
|
var AccountBotsService = class extends SDKConstruct {
|
|
20
|
+
#marketBots = new AddressMap(void 0, "marketBots");
|
|
21
|
+
/**
|
|
22
|
+
* The bots a market configurator lists among its periphery contracts.
|
|
23
|
+
*
|
|
24
|
+
* Read once per configurator and kept for the service's lifetime: the list
|
|
25
|
+
* changes only when the curator adds or removes a bot. A failed read is not
|
|
26
|
+
* kept, so the next call tries again.
|
|
27
|
+
*
|
|
28
|
+
* @param marketConfigurator - Configurator to list the bots of.
|
|
29
|
+
**/
|
|
30
|
+
getMarketBots(marketConfigurator) {
|
|
31
|
+
let bots = this.#marketBots.get(marketConfigurator);
|
|
32
|
+
if (!bots) {
|
|
33
|
+
bots = this.client.readContract({
|
|
34
|
+
address: this.#compressor.address,
|
|
35
|
+
abi: peripheryCompressorAbi,
|
|
36
|
+
functionName: "getBots",
|
|
37
|
+
args: [marketConfigurator]
|
|
38
|
+
}).catch((e) => {
|
|
39
|
+
this.#marketBots.delete(marketConfigurator);
|
|
40
|
+
throw e;
|
|
41
|
+
});
|
|
42
|
+
this.#marketBots.upsert(marketConfigurator, bots);
|
|
43
|
+
}
|
|
44
|
+
return bots;
|
|
45
|
+
}
|
|
17
46
|
/**
|
|
18
47
|
* Reads the bots connected to each of the given credit accounts.
|
|
19
48
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { peripheryCompressorAbi } from "../../../abi/compressors/peripheryCompressor.js";
|
|
1
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
3
|
import "../../base/index.js";
|
|
3
|
-
import { peripheryCompressorAbi } from "../../../abi/compressors/peripheryCompressor.js";
|
|
4
4
|
//#region src/onchain/accounts/bots/PeripheryCompressorV310Contract.ts
|
|
5
5
|
const abi = peripheryCompressorAbi;
|
|
6
6
|
var PeripheryCompressorV310Contract = class extends BaseContract {
|
|
@@ -8,6 +8,7 @@ import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
|
|
|
8
8
|
import { isPhantomToken } from "./intents/utils/pick-token.js";
|
|
9
9
|
import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
|
|
10
10
|
import { DIRECT_TRANSFERS_QUOTA, calcDefaultQuota, calcQuotaUpdate, calcRecommendedQuota, maxAmountForQuota, roundUpQuota } from "./quota-utils.js";
|
|
11
|
+
import { DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, decodeDelayedIntent, encodeDelayedIntent } from "./withdrawal-compressor/intent-codec.js";
|
|
11
12
|
import { CreditAccountOperationsService } from "./intents/index.js";
|
|
12
13
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./liquidations/constants.js";
|
|
13
14
|
import { optimalPartialLiquidation, partialLiquidationParams } from "./liquidations/partialLiquidation.js";
|
|
@@ -15,7 +16,6 @@ import { LiquidationsService } from "./liquidations/LiquidationsService.js";
|
|
|
15
16
|
import { MultichainLiquidationsService } from "./liquidations/MultichainLiquidationsService.js";
|
|
16
17
|
import "./liquidations/index.js";
|
|
17
18
|
import "./types.js";
|
|
18
|
-
import { DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, decodeDelayedIntent, encodeDelayedIntent } from "./withdrawal-compressor/intent-codec.js";
|
|
19
19
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./withdrawal-compressor/AbstractWithdrawalCompressorContract.js";
|
|
20
20
|
import { getWithdrawalCompressorAddress } from "./withdrawal-compressor/addresses.js";
|
|
21
21
|
import { RedemptionLoggerV310Contract } from "./withdrawal-compressor/RedemptionLoggerV310Contract.js";
|
|
@@ -17,7 +17,8 @@ import { maxBorrow } from "./maxBorrow.js";
|
|
|
17
17
|
import { maxBorrowAndWithdraw } from "./maxBorrowAndWithdraw.js";
|
|
18
18
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
19
19
|
import { buildOpenStrategyState } from "./open-strategy.js";
|
|
20
|
-
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planDeposit, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
20
|
+
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planCloseAavePosition, planDeposit, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
21
|
+
import { readAaveHoldings } from "./readAaveHoldings.js";
|
|
21
22
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
22
23
|
import { realize } from "./realize.js";
|
|
23
24
|
import { planTail, projectTail } from "./tail.js";
|
|
@@ -238,6 +239,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
238
239
|
switch (intent.type) {
|
|
239
240
|
case "ADJUST_LEVERAGE": return planAdjustLeverageDelayed(intent, view);
|
|
240
241
|
case "WITHDRAW": return planWithdrawDelayed(intent, view);
|
|
242
|
+
case "CLOSE_AAVE_POSITION": return planCloseAavePosition(intent, view);
|
|
241
243
|
default: throw new Error(`${intent.type} - cannot be delayed`);
|
|
242
244
|
}
|
|
243
245
|
}, limits);
|
|
@@ -272,6 +274,37 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
272
274
|
}
|
|
273
275
|
}
|
|
274
276
|
/**
|
|
277
|
+
* Previews leaving `owner`'s Aave Horizon position in `token` in one
|
|
278
|
+
* transaction, see {@link CloseAavePositionIntent}.
|
|
279
|
+
*
|
|
280
|
+
* What the owner holds and owes on Aave is read here, at the block the SDK
|
|
281
|
+
* stands at; the rest is {@link startDelayedIntent}, tail included.
|
|
282
|
+
*
|
|
283
|
+
* @param props - Account slice, quota reserve and slippage, the RWA, the
|
|
284
|
+
* wallet the exit pays, and the owner the bridge resolves for the account:
|
|
285
|
+
* the investor of an RWA factory account, the borrower otherwise
|
|
286
|
+
* @returns The request transaction, the state the exit ends in and what it
|
|
287
|
+
* recorded for the tail, or `{ ok: false, error }`
|
|
288
|
+
*/
|
|
289
|
+
async closeAavePositionIntent(props) {
|
|
290
|
+
const { token, to, owner, ...rest } = props;
|
|
291
|
+
let holdings;
|
|
292
|
+
try {
|
|
293
|
+
holdings = await readAaveHoldings(rest.sdk, rest.creditAccount.creditManager, owner, token);
|
|
294
|
+
} catch (e) {
|
|
295
|
+
return asRefused(e, rest.draft ?? {});
|
|
296
|
+
}
|
|
297
|
+
return this.startDelayedIntent({
|
|
298
|
+
...rest,
|
|
299
|
+
intent: {
|
|
300
|
+
type: "CLOSE_AAVE_POSITION",
|
|
301
|
+
token,
|
|
302
|
+
to,
|
|
303
|
+
holdings
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
275
308
|
* Previews a delayable intent both ways at once: settled by the router now,
|
|
276
309
|
* and started as a redemption that finishes days later.
|
|
277
310
|
*
|
|
@@ -134,6 +134,25 @@ function buildClaimDelayedWithdrawalOperation(input) {
|
|
|
134
134
|
})
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
+
function buildAaveClosePositionOperation(input) {
|
|
138
|
+
return {
|
|
139
|
+
type: "aaveClosePosition",
|
|
140
|
+
aToken: input.aToken,
|
|
141
|
+
aTokenAmount: input.aTokenAmount,
|
|
142
|
+
debtToken: input.debtToken,
|
|
143
|
+
repayAmount: input.repayAmount,
|
|
144
|
+
calls: [input.adapter.closePositionCall(input.aToken, input.debtToken, input.repayAmount, input.aTokenAmount)]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function buildAaveWithdrawOperation(input) {
|
|
148
|
+
return {
|
|
149
|
+
type: "aaveWithdraw",
|
|
150
|
+
token: input.token,
|
|
151
|
+
aToken: input.aToken,
|
|
152
|
+
amount: input.amount,
|
|
153
|
+
calls: [input.adapter.withdrawDiffCall(input.token, 0n)]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
137
156
|
/**
|
|
138
157
|
* What a request or a claim puts on the account right away, as opposed to what
|
|
139
158
|
* only the phantom token represents.
|
|
@@ -149,4 +168,4 @@ function instantOutput(outputs, token) {
|
|
|
149
168
|
}
|
|
150
169
|
}
|
|
151
170
|
//#endregion
|
|
152
|
-
export { buildAddCollateralOperation, buildClaimDelayedWithdrawalOperation, buildCloseSwapOperation, buildDecreaseDebtOperation, buildIncreaseDebtOperation, buildQuotaUpdateOperation, buildStartDelayedWithdrawalOperation, buildSwapOperation, buildUnwrapRwaCollateralOperation, buildWithdrawCollateralOperation, buildWrapRwaCollateralOperation, instantOutput };
|
|
171
|
+
export { buildAaveClosePositionOperation, buildAaveWithdrawOperation, buildAddCollateralOperation, buildClaimDelayedWithdrawalOperation, buildCloseSwapOperation, buildDecreaseDebtOperation, buildIncreaseDebtOperation, buildQuotaUpdateOperation, buildStartDelayedWithdrawalOperation, buildSwapOperation, buildUnwrapRwaCollateralOperation, buildWithdrawCollateralOperation, buildWrapRwaCollateralOperation, instantOutput };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_UINT256, PERCENTAGE_FACTOR, isZeroBalance } from "../../constants/math.js";
|
|
1
|
+
import { MAX_UINT256, PERCENTAGE_FACTOR, RAY, SECONDS_PER_YEAR, isZeroBalance } from "../../constants/math.js";
|
|
2
2
|
import "../../constants/index.js";
|
|
3
3
|
import { debtOutOfRange, insufficientBalance, leverageOutOfRange } from "../../../model/errors/operation-errors.js";
|
|
4
4
|
import { noDelayedRoute, unsupportedCollateralToken } from "../../../model/errors/prepare-errors.js";
|
|
@@ -104,6 +104,53 @@ function planRepay(intent, view) {
|
|
|
104
104
|
];
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
+
* The owner's Aave position comes back and leaves: the account borrows what
|
|
108
|
+
* the owner owes on Aave, the bridge repays it and returns the aTokens, the
|
|
109
|
+
* pool turns them back into the RWA, and the RWA is requested for redemption
|
|
110
|
+
* with an exit recorded for the tail — all in one transaction.
|
|
111
|
+
*
|
|
112
|
+
* The repayment is the debt plus {@link CLOSE_AAVE_WINDOW} of interest at the
|
|
113
|
+
* current rate, see {@link CloseAavePositionIntent}.
|
|
114
|
+
*/
|
|
115
|
+
function planCloseAavePosition(intent, view) {
|
|
116
|
+
const { token, holdings } = intent;
|
|
117
|
+
const U = view.underlying;
|
|
118
|
+
if (eq(token, U) || isZeroBalance(holdings.supplied)) throw new IntentPreviewError(unsupportedCollateralToken(toToken(view.sdk, token)), `closeAavePosition: the owner holds no aToken of ${token} on Aave`);
|
|
119
|
+
if (holdings.owed <= 0n) throw new IntentPreviewError(debtOutOfRange({
|
|
120
|
+
requested: toTokenAmount(view.sdk, U, 0n),
|
|
121
|
+
minDebt: toTokenAmount(view.sdk, U, view.debtLimits.minDebt),
|
|
122
|
+
maxDebt: toTokenAmount(view.sdk, U, view.debtLimits.maxDebt)
|
|
123
|
+
}), "closeAavePosition: the owner owes nothing on Aave");
|
|
124
|
+
const repay = holdings.owed + ceilDiv(holdings.owed * holdings.borrowRate * CLOSE_AAVE_WINDOW, RAY * BigInt(SECONDS_PER_YEAR));
|
|
125
|
+
let borrowed = toTargetDecimals(repay, holdings.debtToken, U, view.sdk);
|
|
126
|
+
if (toTargetDecimals(borrowed, U, holdings.debtToken, view.sdk) < repay) borrowed += 1n;
|
|
127
|
+
assertDebtLimits(view.sdk, view.debt + borrowed, view.debtLimits, U, view.limits);
|
|
128
|
+
return [
|
|
129
|
+
borrow(borrowed),
|
|
130
|
+
...eq(holdings.debtToken, U) ? [] : [convert(U, holdings.debtToken, borrowed)],
|
|
131
|
+
{
|
|
132
|
+
kind: "aaveClosePosition",
|
|
133
|
+
token,
|
|
134
|
+
repay,
|
|
135
|
+
aTokenAmount: holdings.supplied
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
kind: "aaveWithdraw",
|
|
139
|
+
token
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
kind: "request",
|
|
143
|
+
token,
|
|
144
|
+
amount: view.balanceOf(token) + holdings.supplied,
|
|
145
|
+
reserve: 0n,
|
|
146
|
+
record: {
|
|
147
|
+
type: "CLOSE_ACCOUNT",
|
|
148
|
+
to: intent.to
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
107
154
|
* One token's quota changes; no balance moves and debt is untouched.
|
|
108
155
|
*
|
|
109
156
|
* Only a token the account holds can be quoted here, and only on an account
|
|
@@ -406,6 +453,13 @@ const clearQuotas = () => ({ kind: "clearQuotas" });
|
|
|
406
453
|
*/
|
|
407
454
|
const SETTLE_MARGIN = 10n;
|
|
408
455
|
const withMargin = (debt) => debt + debt * SETTLE_MARGIN / PERCENTAGE_FACTOR;
|
|
456
|
+
/**
|
|
457
|
+
* Seconds of Aave interest a closing repays on top of the debt it read: the
|
|
458
|
+
* bridge keeps whatever Aave does not take, so this is paid for, unlike
|
|
459
|
+
* {@link SETTLE_MARGIN}, and an hour costs a fraction of a basis point.
|
|
460
|
+
*/
|
|
461
|
+
const CLOSE_AAVE_WINDOW = 3600n;
|
|
462
|
+
const ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
409
463
|
/** The amount that asks for all of it, whatever "all" turns out to be. */
|
|
410
464
|
const everything = (amount) => amount >= MAX_UINT256;
|
|
411
465
|
const min = (a, b) => a < b ? a : b;
|
|
@@ -445,4 +499,4 @@ function assertPositive(amount, flow) {
|
|
|
445
499
|
if (amount <= 0n) throw new IntentPreviewError(insufficientBalance(), `${flow}: amount must be positive`);
|
|
446
500
|
}
|
|
447
501
|
//#endregion
|
|
448
|
-
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
502
|
+
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planCloseAavePosition, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { iAaveV3PoolAbi } from "../../market/adapters/abi/aave/iAaveV3Pool.js";
|
|
2
|
+
import "../../market/adapters/abi/aave/index.js";
|
|
3
|
+
import { AaveV3PoolAdapterContract } from "../../market/adapters/contracts/AaveV3PoolAdapterContract.js";
|
|
4
|
+
import { unsupportedCollateralToken } from "../../../model/errors/prepare-errors.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
6
|
+
import { toToken } from "../../validation/helpers/token.js";
|
|
7
|
+
import { IntentPreviewError } from "../../validation/raise.js";
|
|
8
|
+
import { erc20Abi } from "viem";
|
|
9
|
+
//#region src/onchain/accounts/intents/readAaveHoldings.ts
|
|
10
|
+
/**
|
|
11
|
+
* What `owner` holds and owes on the Aave pool the credit manager supplies
|
|
12
|
+
* `token` to: its aTokens of `token`, and its variable debt in the asset the
|
|
13
|
+
* Horizon bridge lends there — the underlying, or the asset an RWA underlying
|
|
14
|
+
* wraps.
|
|
15
|
+
*
|
|
16
|
+
* Refused with `unsupportedCollateralToken` when no Aave pool adapter of the
|
|
17
|
+
* credit manager lists `token`.
|
|
18
|
+
*/
|
|
19
|
+
async function readAaveHoldings(sdk, creditManager, owner, token) {
|
|
20
|
+
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
21
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof AaveV3PoolAdapterContract && a.isAssetAllowed(token));
|
|
22
|
+
if (!adapter) throw new IntentPreviewError(unsupportedCollateralToken(toToken(sdk, token)), `readAaveHoldings: no Aave pool adapter lists ${token}`);
|
|
23
|
+
const underlying = suite.underlying;
|
|
24
|
+
const debtToken = sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset ?? underlying;
|
|
25
|
+
const [aToken, reserve] = await Promise.all([adapter.aToken(token), sdk.client.readContract({
|
|
26
|
+
address: adapter.pool,
|
|
27
|
+
abi: iAaveV3PoolAbi,
|
|
28
|
+
functionName: "getReserveData",
|
|
29
|
+
args: [debtToken]
|
|
30
|
+
})]);
|
|
31
|
+
const [supplied, owed] = await sdk.client.multicall({
|
|
32
|
+
contracts: [{
|
|
33
|
+
address: aToken,
|
|
34
|
+
abi: erc20Abi,
|
|
35
|
+
functionName: "balanceOf",
|
|
36
|
+
args: [owner]
|
|
37
|
+
}, {
|
|
38
|
+
address: reserve.variableDebtTokenAddress,
|
|
39
|
+
abi: erc20Abi,
|
|
40
|
+
functionName: "balanceOf",
|
|
41
|
+
args: [owner]
|
|
42
|
+
}],
|
|
43
|
+
allowFailure: false,
|
|
44
|
+
batchSize: 0
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
aToken,
|
|
48
|
+
debtToken,
|
|
49
|
+
supplied,
|
|
50
|
+
owed,
|
|
51
|
+
borrowRate: reserve.currentVariableBorrowRate
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { readAaveHoldings };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { getDirectTransferToken } from "../../chain/chains.js";
|
|
2
2
|
import { PERCENTAGE_FACTOR_1KK } from "../../constants/math.js";
|
|
3
|
+
import { AaveHorizonBridgeAdapterContract } from "../../market/adapters/contracts/AaveHorizonBridgeAdapterContract.js";
|
|
4
|
+
import { AaveV3PoolAdapterContract } from "../../market/adapters/contracts/AaveV3PoolAdapterContract.js";
|
|
5
|
+
import { SecuritizeRedemptionGatewayAdapterContract } from "../../market/adapters/contracts/SecuritizeRedemptionGatewayAdapterContract.js";
|
|
3
6
|
import { insufficientBalance } from "../../../model/errors/operation-errors.js";
|
|
4
|
-
import { multipleDelayedWithdrawals, noDelayedRoute, withdrawalInProgress } from "../../../model/errors/prepare-errors.js";
|
|
7
|
+
import { multipleDelayedWithdrawals, noDelayedRoute, unsupportedCollateralToken, withdrawalInProgress } from "../../../model/errors/prepare-errors.js";
|
|
5
8
|
import "../../../model/index.js";
|
|
6
9
|
import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
|
|
7
10
|
import { IntentPreviewError } from "../../validation/raise.js";
|
|
@@ -12,7 +15,8 @@ import { OperationLedger } from "./utils/ledger.js";
|
|
|
12
15
|
import { collectPriceImpact } from "./utils/price-impact.js";
|
|
13
16
|
import { clearedQuotas, getQuotasForUpdate, quotasAfterUpdate, withDirectTransferQuota } from "./utils/quotas-for-update.js";
|
|
14
17
|
import { createRouterPaths } from "./utils/router-path.js";
|
|
15
|
-
import {
|
|
18
|
+
import { encodeDelayedIntent } from "../withdrawal-compressor/intent-codec.js";
|
|
19
|
+
import { buildAaveClosePositionOperation, buildAaveWithdrawOperation, buildAddCollateralOperation, buildClaimDelayedWithdrawalOperation, buildCloseSwapOperation, buildDecreaseDebtOperation, buildIncreaseDebtOperation, buildQuotaUpdateOperation, buildStartDelayedWithdrawalOperation, buildSwapOperation, buildUnwrapRwaCollateralOperation, buildWithdrawCollateralOperation, buildWrapRwaCollateralOperation, instantOutput } from "./operations.js";
|
|
16
20
|
import { resolveQuotaUpdate } from "./resolveQuotaUpdate.js";
|
|
17
21
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
18
22
|
//#region src/onchain/accounts/intents/realize.ts
|
|
@@ -285,12 +289,19 @@ async function realize(steps, props) {
|
|
|
285
289
|
if (ledger.balanceOf(asset.withdrawalPhantomToken) > 0n) throw new IntentPreviewError(withdrawalInProgress(toTokenAmount(sdk, asset.withdrawalPhantomToken, ledger.balanceOf(asset.withdrawalPhantomToken))), `request: ${asset.withdrawalPhantomToken} already holds a pending withdrawal`);
|
|
286
290
|
assertHolds(step.token, step.amount + step.reserve, "request");
|
|
287
291
|
if (step.record.type !== "CLOSE_ACCOUNT") directTransfer ??= getDirectTransferToken(step.token, sdk.networkType);
|
|
288
|
-
const preview = await sdk.accounts.previewDelayedWithdrawal({
|
|
292
|
+
const preview = (creditAccount.tokens.find((t) => eq(t.token, step.token))?.balance ?? 0n) >= step.amount ? await sdk.accounts.previewDelayedWithdrawal({
|
|
289
293
|
creditAccount: creditAccount.creditAccount,
|
|
290
294
|
token: step.token,
|
|
291
295
|
amount: step.amount,
|
|
292
296
|
withdrawalPhantomToken: asset.withdrawalPhantomToken,
|
|
293
297
|
intent: step.record
|
|
298
|
+
}) : await arrivingRedemption({
|
|
299
|
+
sdk,
|
|
300
|
+
suite,
|
|
301
|
+
asset,
|
|
302
|
+
amount: step.amount,
|
|
303
|
+
leftover: ledger.balanceOf(step.token) - step.amount,
|
|
304
|
+
record: step.record
|
|
294
305
|
});
|
|
295
306
|
push(buildStartDelayedWithdrawalOperation({
|
|
296
307
|
preview,
|
|
@@ -327,8 +338,9 @@ async function realize(steps, props) {
|
|
|
327
338
|
break;
|
|
328
339
|
case "sweep": {
|
|
329
340
|
withdrawsCollateral = true;
|
|
341
|
+
const swept = (token) => !step.token || eq(token, step.token) || rwaAsset !== void 0 && eq(step.token, underlying) && eq(token, rwaAsset);
|
|
330
342
|
const wrapped = ledger.balanceOf(underlying);
|
|
331
|
-
if (rwaAsset && wrapped > 0n) push(await buildUnwrapRwaCollateralOperation({
|
|
343
|
+
if (rwaAsset && wrapped > 0n && swept(underlying)) push(await buildUnwrapRwaCollateralOperation({
|
|
332
344
|
tokenIn: underlying,
|
|
333
345
|
all: true,
|
|
334
346
|
amountIn: wrapped,
|
|
@@ -338,6 +350,7 @@ async function realize(steps, props) {
|
|
|
338
350
|
sdk
|
|
339
351
|
}));
|
|
340
352
|
for (const { token, balance } of ledger.snapshot().assets) {
|
|
353
|
+
if (!swept(token)) continue;
|
|
341
354
|
const withdrawal = buildWithdrawCollateralOperation({
|
|
342
355
|
token,
|
|
343
356
|
amount: balance,
|
|
@@ -353,6 +366,36 @@ async function realize(steps, props) {
|
|
|
353
366
|
}
|
|
354
367
|
break;
|
|
355
368
|
}
|
|
369
|
+
case "aaveClosePosition": {
|
|
370
|
+
const aToken = await aavePoolAdapter(sdk, suite, step.token).aToken(step.token);
|
|
371
|
+
const debtToken = rwaAsset ?? underlying;
|
|
372
|
+
assertHolds(debtToken, step.repay, "aaveClosePosition");
|
|
373
|
+
push(buildAaveClosePositionOperation({
|
|
374
|
+
adapter: aaveBridgeAdapter(sdk, suite, step.token, {
|
|
375
|
+
aToken,
|
|
376
|
+
debtToken
|
|
377
|
+
}),
|
|
378
|
+
aToken,
|
|
379
|
+
aTokenAmount: step.aTokenAmount,
|
|
380
|
+
debtToken,
|
|
381
|
+
repayAmount: step.repay
|
|
382
|
+
}));
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
case "aaveWithdraw": {
|
|
386
|
+
const adapter = aavePoolAdapter(sdk, suite, step.token);
|
|
387
|
+
const aToken = await adapter.aToken(step.token);
|
|
388
|
+
const amount = ledger.balanceOf(aToken);
|
|
389
|
+
assertHolds(aToken, amount, "aaveWithdraw");
|
|
390
|
+
push(buildAaveWithdrawOperation({
|
|
391
|
+
adapter,
|
|
392
|
+
token: step.token,
|
|
393
|
+
aToken,
|
|
394
|
+
amount
|
|
395
|
+
}));
|
|
396
|
+
raised = amount;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
356
399
|
}
|
|
357
400
|
const floor = ledger.snapshot();
|
|
358
401
|
const { assets, debt } = floor;
|
|
@@ -475,6 +518,45 @@ async function delayedConfig(sdk, creditAccount, token) {
|
|
|
475
518
|
if (assets.length > 1) throw new IntentPreviewError(multipleDelayedWithdrawals(toToken(sdk, token), assets.length), `request: ${token} has ${assets.length} delayed withdrawal configs`);
|
|
476
519
|
return assets[0];
|
|
477
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* The request for a redemption of a balance an earlier call of the same
|
|
523
|
+
* multicall brings in. The withdrawal compressor caps what it quotes at the
|
|
524
|
+
* balance the account holds before the transaction, so the request is built
|
|
525
|
+
* here instead: a diff call that names no amount, its phantom valued the way
|
|
526
|
+
* the gateway values it. Only a Securitize redemption gateway redeems that
|
|
527
|
+
* way; any other redemption is refused with `noDelayedRoute`.
|
|
528
|
+
*/
|
|
529
|
+
async function arrivingRedemption(input) {
|
|
530
|
+
const { sdk, suite, asset, amount } = input;
|
|
531
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof SecuritizeRedemptionGatewayAdapterContract && eq(a.dsToken, asset.token) && eq(a.redemptionPhantomToken, asset.withdrawalPhantomToken));
|
|
532
|
+
if (!adapter) throw new IntentPreviewError(noDelayedRoute(toToken(sdk, asset.token)), `request: ${asset.token} arrives in this transaction, and only a Securitize gateway redeems it without a quote`);
|
|
533
|
+
return {
|
|
534
|
+
token: asset.token,
|
|
535
|
+
amountIn: amount,
|
|
536
|
+
outputs: [{
|
|
537
|
+
token: asset.withdrawalPhantomToken,
|
|
538
|
+
isDelayed: true,
|
|
539
|
+
amount: await adapter.redemptionValue(amount)
|
|
540
|
+
}],
|
|
541
|
+
requestCalls: [adapter.redeemDiffCall(input.leftover, encodeDelayedIntent(input.record))],
|
|
542
|
+
claimableAt: sdk.timestamp + asset.withdrawalLength
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
/** The credit manager's Aave pool adapter that lists `token`. */
|
|
546
|
+
function aavePoolAdapter(sdk, suite, token) {
|
|
547
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof AaveV3PoolAdapterContract && a.isAssetAllowed(token));
|
|
548
|
+
if (!adapter) throw new IntentPreviewError(unsupportedCollateralToken(toToken(sdk, token)), `aave: no Aave pool adapter lists ${token}`);
|
|
549
|
+
return adapter;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The credit manager's Horizon bridge adapter that takes `aToken` and lends
|
|
553
|
+
* `debtToken`. Refused on `token`, the collateral the aToken stands for.
|
|
554
|
+
*/
|
|
555
|
+
function aaveBridgeAdapter(sdk, suite, token, pair) {
|
|
556
|
+
const adapter = suite.creditManager.adapters.values().find((a) => a instanceof AaveHorizonBridgeAdapterContract && a.isATokenAllowed(pair.aToken) && a.isDebtTokenAllowed(pair.debtToken));
|
|
557
|
+
if (!adapter) throw new IntentPreviewError(unsupportedCollateralToken(toToken(sdk, token)), `aaveClosePosition: no Horizon bridge adapter takes ${pair.aToken} against ${pair.debtToken}`);
|
|
558
|
+
return adapter;
|
|
559
|
+
}
|
|
478
560
|
const callsOf = (operations) => operations.flatMap((op) => op.calls);
|
|
479
561
|
const min = (a, b) => a < b ? a : b;
|
|
480
562
|
/** 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) => calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0, targetHF)
|
|
214
|
+
maxLeverage: (collateral, targetHF) => 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) => ({
|
|
@@ -79,6 +79,14 @@ var OperationLedger = class {
|
|
|
79
79
|
case "claimDelayedWithdrawal":
|
|
80
80
|
this.#add(op.withdrawalPhantomToken, -op.withdrawalTokenSpent);
|
|
81
81
|
for (const out of op.outputs) this.#add(out.token, out.amount);
|
|
82
|
+
break;
|
|
83
|
+
case "aaveClosePosition":
|
|
84
|
+
this.#add(op.debtToken, -op.repayAmount);
|
|
85
|
+
this.#add(op.aToken, op.aTokenAmount);
|
|
86
|
+
break;
|
|
87
|
+
case "aaveWithdraw":
|
|
88
|
+
this.#add(op.aToken, -op.amount);
|
|
89
|
+
this.#add(op.token, op.amount);
|
|
82
90
|
}
|
|
83
91
|
return this;
|
|
84
92
|
}
|
|
@@ -354,6 +354,10 @@ const chains = {
|
|
|
354
354
|
}),
|
|
355
355
|
Lisk: defineChain({
|
|
356
356
|
...lisk,
|
|
357
|
+
rpcUrls: {
|
|
358
|
+
...lisk.rpcUrls,
|
|
359
|
+
tenderly: { http: ["https://lisk.gateway.tenderly.co"] }
|
|
360
|
+
},
|
|
357
361
|
network: "Lisk",
|
|
358
362
|
defaultMarketConfigurators: AddressMap.fromRecord({ "0x25778dbf0e56b7feb8358c4aa2f6f9e19a1c145a": "Re7" }),
|
|
359
363
|
rwaFactories: [],
|