@gearbox-protocol/sdk 17.0.0-next.4 → 17.1.0-next.1
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/dev/abi.js +14 -15
- package/dist/cjs/dev/claimFromFaucet.js +4 -8
- package/dist/cjs/dev/createAnvilClient.js +35 -17
- package/dist/cjs/dev/index.js +7 -2
- package/dist/cjs/dev/kycUtils.js +66 -58
- package/dist/cjs/dev/midasUtils.js +113 -16
- package/dist/cjs/dev/securitizeUtils.js +82 -42
- package/dist/cjs/dev/withdrawalUtils.js +3 -6
- package/dist/cjs/model/errors/index.js +2 -0
- package/dist/cjs/model/errors/operation-errors.js +19 -1
- package/dist/cjs/model/index.js +4 -2
- package/dist/cjs/model/rwa.js +4 -4
- package/dist/cjs/model/rwa.schema.js +4 -4
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/cjs/onchain/OnchainSDK.js +3 -3
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -17
- package/dist/cjs/onchain/accounts/intents/borrow.js +140 -0
- package/dist/cjs/onchain/accounts/intents/collateral-valuation.js +41 -0
- package/dist/cjs/onchain/accounts/intents/guards.js +15 -3
- package/dist/cjs/onchain/accounts/intents/index.js +107 -20
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -12
- package/dist/cjs/onchain/accounts/intents/math.js +12 -3
- package/dist/cjs/onchain/accounts/intents/maxBorrow.js +89 -0
- package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +8 -46
- package/dist/cjs/onchain/accounts/intents/operations.js +0 -1
- package/dist/cjs/onchain/accounts/intents/plan.js +1 -8
- package/dist/cjs/onchain/accounts/intents/realize.js +61 -4
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/cjs/onchain/accounts/intents/utils/common.js +19 -0
- package/dist/cjs/onchain/accounts/intents/utils/credit-account-slice.js +21 -0
- package/dist/cjs/onchain/accounts/intents/utils/index.js +2 -0
- package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +12 -9
- package/dist/cjs/onchain/accounts/intents/utils/router-path.js +4 -5
- package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +97 -0
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/cjs/onchain/constants/address-provider.js +0 -2
- package/dist/cjs/onchain/constants/index.js +0 -1
- package/dist/cjs/onchain/core/createAddressProvider.js +2 -5
- package/dist/cjs/onchain/index.js +60 -43
- package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +2 -2
- package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
- package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +49 -5
- package/dist/cjs/onchain/market/credit/CreditSuite.js +26 -9
- package/dist/cjs/onchain/market/index.js +50 -38
- package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +3 -3
- package/dist/cjs/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
- package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +127 -0
- package/dist/cjs/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
- package/dist/cjs/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
- package/dist/cjs/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
- package/dist/cjs/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
- package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +35 -0
- package/dist/cjs/onchain/market/pricefeeds/index.js +51 -39
- package/dist/cjs/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +189 -0
- package/dist/cjs/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
- package/dist/cjs/onchain/market/pricefeeds/updates/index.js +8 -0
- package/dist/cjs/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
- package/dist/cjs/onchain/market/pricefeeds/updates/updatableDependencies.js +14 -0
- package/dist/cjs/onchain/market/rwa/RWARegistry.js +4 -7
- package/dist/cjs/onchain/market/rwa/index.js +1 -0
- package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +56 -12
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
- package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
- package/dist/cjs/onchain/opportunities/OpportunitiesService.js +16 -4
- package/dist/cjs/onchain/pools/PoolService.js +7 -8
- package/dist/cjs/onchain/positions/calcHealthFactor.js +3 -3
- package/dist/cjs/onchain/preview/index.js +2 -0
- package/dist/cjs/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
- package/dist/cjs/onchain/preview/preview/index.js +2 -0
- package/dist/cjs/onchain/preview/preview/midasGreenlistsAccount.js +17 -0
- package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +13 -16
- package/dist/cjs/onchain/preview/preview/previewOperation.js +19 -11
- package/dist/cjs/onchain/preview/preview/replayMulticall.js +4 -3
- package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +3 -3
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +11 -9
- package/dist/cjs/onchain/validation/bundles/{checkDraw.js → checkIncreaseDebt.js} +10 -10
- package/dist/cjs/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
- package/dist/cjs/onchain/validation/bundles/checkMidasAccountGreenlist.js +44 -0
- package/dist/cjs/onchain/validation/bundles/checkPoolOperation.js +2 -8
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +18 -8
- package/dist/cjs/onchain/validation/bundles/index.js +6 -4
- package/dist/cjs/onchain/validation/checkOperation.js +0 -1
- package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +1 -1
- package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +2 -9
- package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
- package/dist/cjs/onchain/validation/checks/index.js +2 -0
- package/dist/cjs/onchain/validation/index.js +8 -4
- package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
- package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
- package/dist/cjs/sdk/execute/ExecuteApi.js +67 -7
- package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
- package/dist/cjs/sdk/prepare/PrepareApi.js +89 -14
- package/dist/esm/dev/abi.js +14 -15
- package/dist/esm/dev/claimFromFaucet.js +4 -8
- package/dist/esm/dev/createAnvilClient.js +36 -19
- package/dist/esm/dev/index.js +4 -4
- package/dist/esm/dev/kycUtils.js +66 -59
- package/dist/esm/dev/midasUtils.js +112 -18
- package/dist/esm/dev/securitizeUtils.js +84 -44
- package/dist/esm/dev/withdrawalUtils.js +3 -6
- package/dist/esm/model/errors/index.js +2 -2
- package/dist/esm/model/errors/operation-errors.js +18 -2
- package/dist/esm/model/index.js +4 -4
- package/dist/esm/model/rwa.js +4 -4
- package/dist/esm/model/rwa.schema.js +5 -5
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/esm/onchain/OnchainSDK.js +3 -3
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -17
- package/dist/esm/onchain/accounts/intents/borrow.js +138 -0
- package/dist/esm/onchain/accounts/intents/collateral-valuation.js +40 -0
- package/dist/esm/onchain/accounts/intents/guards.js +15 -3
- package/dist/esm/onchain/accounts/intents/index.js +107 -20
- package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
- package/dist/esm/onchain/accounts/intents/math.js +13 -5
- package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
- package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
- package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -46
- package/dist/esm/onchain/accounts/intents/operations.js +0 -1
- package/dist/esm/onchain/accounts/intents/plan.js +1 -8
- package/dist/esm/onchain/accounts/intents/realize.js +61 -4
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
- package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
- package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
- package/dist/esm/onchain/accounts/intents/utils/price-impact.js +12 -9
- package/dist/esm/onchain/accounts/intents/utils/router-path.js +4 -5
- package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/constants/address-provider.js +1 -2
- package/dist/esm/onchain/constants/index.js +2 -2
- package/dist/esm/onchain/core/createAddressProvider.js +2 -5
- package/dist/esm/onchain/index.js +32 -24
- package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +2 -2
- package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
- package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +50 -6
- package/dist/esm/onchain/market/credit/CreditSuite.js +26 -9
- package/dist/esm/onchain/market/index.js +26 -21
- package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
- package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
- package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
- package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
- package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
- package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
- package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
- package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
- package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
- package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
- package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
- package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
- package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
- package/dist/esm/onchain/market/rwa/RWARegistry.js +4 -8
- package/dist/esm/onchain/market/rwa/index.js +2 -2
- package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
- package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
- package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
- package/dist/esm/onchain/pools/PoolService.js +7 -8
- package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
- package/dist/esm/onchain/preview/index.js +2 -1
- package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
- package/dist/esm/onchain/preview/preview/index.js +2 -1
- package/dist/esm/onchain/preview/preview/midasGreenlistsAccount.js +16 -0
- package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +14 -17
- package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
- package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
- package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +11 -9
- package/dist/esm/onchain/validation/bundles/checkIncreaseDebt.js +27 -0
- package/dist/esm/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
- package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +43 -0
- package/dist/esm/onchain/validation/bundles/checkPoolOperation.js +2 -8
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +18 -8
- package/dist/esm/onchain/validation/bundles/index.js +4 -3
- package/dist/esm/onchain/validation/checkOperation.js +0 -1
- package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +1 -1
- package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +2 -9
- package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
- package/dist/esm/onchain/validation/checks/index.js +2 -1
- package/dist/esm/onchain/validation/index.js +5 -3
- package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
- package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +67 -7
- package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
- package/dist/esm/sdk/prepare/PrepareApi.js +94 -19
- package/dist/types/dev/abi.d.ts +13 -15
- package/dist/types/dev/claimFromFaucet.d.ts +0 -1
- package/dist/types/dev/createAnvilClient.d.ts +10 -3
- package/dist/types/dev/index.d.ts +4 -4
- package/dist/types/dev/kycUtils.d.ts +15 -24
- package/dist/types/dev/midasUtils.d.ts +35 -4
- package/dist/types/dev/securitizeUtils.d.ts +3 -9
- package/dist/types/model/errors/index.d.ts +2 -2
- package/dist/types/model/errors/operation-errors.d.ts +62 -7
- package/dist/types/model/index.d.ts +5 -5
- package/dist/types/model/opportunities.d.ts +6 -7
- package/dist/types/model/previews.d.ts +25 -19
- package/dist/types/model/rwa.d.ts +47 -27
- package/dist/types/model/rwa.schema.d.ts +3 -3
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
- package/dist/types/offchain/opportunities/types.d.ts +1 -4
- package/dist/types/onchain/OnchainSDK.d.ts +2 -2
- package/dist/types/onchain/accounts/index.d.ts +5 -4
- package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
- package/dist/types/onchain/accounts/intents/collateral-valuation.d.ts +42 -0
- package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
- package/dist/types/onchain/accounts/intents/index.d.ts +103 -15
- package/dist/types/onchain/accounts/intents/math.d.ts +11 -3
- package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
- package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
- package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
- package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
- package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/types.d.ts +51 -6
- package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
- package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
- package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
- package/dist/types/onchain/accounts/intents/utils/price-impact.d.ts +4 -1
- package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +2 -5
- package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
- package/dist/types/onchain/accounts/types.d.ts +4 -2
- package/dist/types/onchain/constants/address-provider.d.ts +1 -2
- package/dist/types/onchain/constants/index.d.ts +2 -2
- package/dist/types/onchain/index.d.ts +40 -31
- package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +6 -0
- package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +20 -4
- package/dist/types/onchain/market/adapters/types.d.ts +8 -0
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +13 -3
- package/dist/types/onchain/market/index.d.ts +29 -24
- package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
- package/dist/types/onchain/market/oracle/types.d.ts +2 -1
- package/dist/types/onchain/market/pool/types.d.ts +1 -1
- package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
- package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
- package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
- package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
- package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
- package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
- package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
- package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
- package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
- package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
- package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
- package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
- package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
- package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
- package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
- package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
- package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
- package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
- package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
- package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
- package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
- package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
- package/dist/types/onchain/market/rwa/RWARegistry.d.ts +2 -1
- package/dist/types/onchain/market/rwa/index.d.ts +3 -3
- package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
- package/dist/types/onchain/market/rwa/types.d.ts +39 -37
- package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
- package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
- package/dist/types/onchain/opportunities/types.d.ts +6 -1
- package/dist/types/onchain/pools/PoolService.d.ts +5 -0
- package/dist/types/onchain/pools/types.d.ts +9 -2
- package/dist/types/onchain/preview/index.d.ts +2 -1
- package/dist/types/onchain/preview/preview/index.d.ts +2 -1
- package/dist/types/onchain/preview/preview/midasGreenlistsAccount.d.ts +13 -0
- package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
- package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
- package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +5 -4
- package/dist/types/onchain/validation/bundles/{checkDraw.d.ts → checkIncreaseDebt.d.ts} +7 -7
- package/dist/types/onchain/validation/bundles/{checkQuotasAsked.d.ts → checkIncreaseQuota.d.ts} +3 -3
- package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +22 -0
- package/dist/types/onchain/validation/bundles/checkPoolOperation.d.ts +1 -7
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +9 -7
- package/dist/types/onchain/validation/bundles/index.d.ts +5 -4
- package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +1 -1
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +2 -2
- package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +1 -8
- package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
- package/dist/types/onchain/validation/checks/index.d.ts +2 -1
- package/dist/types/onchain/validation/index.d.ts +6 -4
- package/dist/types/onchain/validation/raise.d.ts +2 -2
- package/dist/types/sdk/execute/index.d.ts +2 -2
- package/dist/types/sdk/execute/types.d.ts +48 -6
- package/dist/types/sdk/index.d.ts +5 -4
- package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
- package/dist/types/sdk/opportunities/types.d.ts +9 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +16 -4
- package/dist/types/sdk/prepare/index.d.ts +4 -3
- package/dist/types/sdk/prepare/types.d.ts +200 -66
- package/package.json +1 -1
- package/dist/cjs/onchain/accounts/utils/midasUtils.js +0 -70
- package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
- package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -61
- package/dist/cjs/plugins/degen-distributors/index.js +0 -4
- package/dist/cjs/plugins/degen-distributors/package.json +0 -1
- package/dist/cjs/plugins/degen-distributors/types.js +0 -1
- package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -114
- package/dist/cjs/plugins/delayed-withdrawal/index.js +0 -4
- package/dist/cjs/plugins/delayed-withdrawal/package.json +0 -1
- package/dist/cjs/plugins/delayed-withdrawal/types.js +0 -1
- package/dist/esm/onchain/accounts/utils/midasUtils.js +0 -69
- package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
- package/dist/esm/onchain/validation/bundles/checkDraw.js +0 -27
- package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -60
- package/dist/esm/plugins/degen-distributors/index.js +0 -3
- package/dist/esm/plugins/degen-distributors/package.json +0 -1
- package/dist/esm/plugins/degen-distributors/types.js +0 -1
- package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -113
- package/dist/esm/plugins/delayed-withdrawal/index.js +0 -3
- package/dist/esm/plugins/delayed-withdrawal/package.json +0 -1
- package/dist/esm/plugins/delayed-withdrawal/types.js +0 -1
- package/dist/types/onchain/accounts/utils/midasUtils.d.ts +0 -38
- package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
- package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
- package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
- package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
- package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
- package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
- package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
- package/dist/types/plugins/degen-distributors/DegenDistributorsPlugin.d.ts +0 -25
- package/dist/types/plugins/degen-distributors/index.d.ts +0 -3
- package/dist/types/plugins/degen-distributors/types.d.ts +0 -8
- package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +0 -25
- package/dist/types/plugins/delayed-withdrawal/index.d.ts +0 -3
- package/dist/types/plugins/delayed-withdrawal/types.d.ts +0 -10
|
@@ -5,7 +5,6 @@ require("../onchain/index.js");
|
|
|
5
5
|
const require_abi_rwa_iDSToken = require("../abi/rwa/iDSToken.js");
|
|
6
6
|
const require_dev_kycUtils = require("./kycUtils.js");
|
|
7
7
|
let viem = require("viem");
|
|
8
|
-
let viem_accounts = require("viem/accounts");
|
|
9
8
|
//#region src/dev/securitizeUtils.ts
|
|
10
9
|
/**
|
|
11
10
|
* `COMPLIANCE_CONFIGURATION_SERVICE` id in the DS protocol service registry
|
|
@@ -65,7 +64,7 @@ async function issueDSTokens(props) {
|
|
|
65
64
|
const { timestamp } = await anvil.getBlock();
|
|
66
65
|
const issuanceTime = timestamp - lockPeriod - 1n;
|
|
67
66
|
try {
|
|
68
|
-
const
|
|
67
|
+
const receipt = await anvil.writeContractSync({
|
|
69
68
|
account,
|
|
70
69
|
chain: anvil.chain,
|
|
71
70
|
address: token,
|
|
@@ -78,14 +77,15 @@ async function issueDSTokens(props) {
|
|
|
78
77
|
0n,
|
|
79
78
|
"",
|
|
80
79
|
0n
|
|
81
|
-
]
|
|
80
|
+
],
|
|
81
|
+
throwOnReceiptRevert: true
|
|
82
82
|
});
|
|
83
83
|
logger?.debug({
|
|
84
84
|
issuanceTime,
|
|
85
85
|
investor,
|
|
86
86
|
amount
|
|
87
87
|
}, "issueTokensCustom successful");
|
|
88
|
-
return
|
|
88
|
+
return receipt.transactionHash;
|
|
89
89
|
} catch (e) {
|
|
90
90
|
logger?.debug(`issueTokensCustom failed: ${e}`);
|
|
91
91
|
}
|
|
@@ -94,14 +94,15 @@ async function issueDSTokens(props) {
|
|
|
94
94
|
investor,
|
|
95
95
|
amount
|
|
96
96
|
}, "Falling back to issueTokens");
|
|
97
|
-
return
|
|
97
|
+
return (await anvil.writeContractSync({
|
|
98
98
|
account,
|
|
99
99
|
chain: anvil.chain,
|
|
100
100
|
address: token,
|
|
101
101
|
abi: require_abi_rwa_iDSToken.iDSTokenAbi,
|
|
102
102
|
functionName: "issueTokens",
|
|
103
|
-
args: [investor, amount]
|
|
104
|
-
|
|
103
|
+
args: [investor, amount],
|
|
104
|
+
throwOnReceiptRevert: true
|
|
105
|
+
})).transactionHash;
|
|
105
106
|
}
|
|
106
107
|
/**
|
|
107
108
|
* Resolves unique compliance configuration services of `tokens`: several
|
|
@@ -109,7 +110,7 @@ async function issueDSTokens(props) {
|
|
|
109
110
|
* Tokens without one (e.g. MockDSToken) are skipped
|
|
110
111
|
*/
|
|
111
112
|
async function getComplianceConfigurationServices({ anvil, tokens, logger }) {
|
|
112
|
-
const services = new
|
|
113
|
+
const services = /* @__PURE__ */ new Map();
|
|
113
114
|
for (const token of new require_onchain_utils_AddressSet.AddressSet(tokens)) try {
|
|
114
115
|
const service = await anvil.readContract({
|
|
115
116
|
address: token,
|
|
@@ -121,11 +122,16 @@ async function getComplianceConfigurationServices({ anvil, tokens, logger }) {
|
|
|
121
122
|
logger?.debug(`${token} has no compliance configuration service`);
|
|
122
123
|
continue;
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
+
const checksummed = (0, viem.getAddress)(service);
|
|
126
|
+
if (services.has(checksummed)) continue;
|
|
127
|
+
services.set(checksummed, await require_dev_kycUtils.getSecuritizeAdmin(anvil, token, logger));
|
|
125
128
|
} catch (e) {
|
|
126
129
|
logger?.debug(`Failed to get compliance configuration service of ${token}: ${e}`);
|
|
127
130
|
}
|
|
128
|
-
return [...services]
|
|
131
|
+
return [...services].map(([service, admin]) => ({
|
|
132
|
+
service,
|
|
133
|
+
admin
|
|
134
|
+
}));
|
|
129
135
|
}
|
|
130
136
|
/**
|
|
131
137
|
* Sets `disallowBackDating` to false on compliance configuration services of
|
|
@@ -133,18 +139,17 @@ async function getComplianceConfigurationServices({ anvil, tokens, logger }) {
|
|
|
133
139
|
* honoured: DS protocol silently replaces it with `block.timestamp` otherwise,
|
|
134
140
|
* and freshly minted tokens stay under lock-up.
|
|
135
141
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
142
|
+
* Impersonates the DS trust-service admin of each token. Ownable `owner()` of
|
|
143
|
+
* the compliance configuration service alone is not enough.
|
|
138
144
|
*
|
|
139
145
|
* The flag is only read while tokens are issued, so restoring it does not
|
|
140
146
|
* re-lock tokens minted in the meantime.
|
|
141
147
|
*/
|
|
142
148
|
async function enableDSTokenBackDating(props) {
|
|
143
|
-
const { anvil,
|
|
144
|
-
const account = (0, viem_accounts.privateKeyToAccount)(adminPrivateKey);
|
|
149
|
+
const { anvil, logger } = props;
|
|
145
150
|
const services = await getComplianceConfigurationServices(props);
|
|
146
151
|
let toRestore = [];
|
|
147
|
-
for (const service of services) {
|
|
152
|
+
for (const { service, admin } of services) {
|
|
148
153
|
let disallowBackDating;
|
|
149
154
|
try {
|
|
150
155
|
disallowBackDating = await anvil.readContract({
|
|
@@ -161,30 +166,53 @@ async function enableDSTokenBackDating(props) {
|
|
|
161
166
|
continue;
|
|
162
167
|
}
|
|
163
168
|
logger?.info(`Allowing back-dating on ${service}`);
|
|
164
|
-
await
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
await anvil.impersonateAccount({ address: admin });
|
|
170
|
+
try {
|
|
171
|
+
await anvil.setBalance({
|
|
172
|
+
address: admin,
|
|
173
|
+
value: (0, viem.parseEther)("100")
|
|
174
|
+
});
|
|
175
|
+
await anvil.writeContractSync({
|
|
176
|
+
account: admin,
|
|
177
|
+
chain: anvil.chain,
|
|
178
|
+
address: service,
|
|
179
|
+
abi: iDSComplianceConfigurationServiceAbi,
|
|
180
|
+
functionName: "setDisallowBackDating",
|
|
181
|
+
args: [false],
|
|
182
|
+
throwOnReceiptRevert: true
|
|
183
|
+
});
|
|
184
|
+
} finally {
|
|
185
|
+
await anvil.stopImpersonatingAccount({ address: admin });
|
|
186
|
+
}
|
|
187
|
+
toRestore.push({
|
|
188
|
+
service,
|
|
189
|
+
admin
|
|
171
190
|
});
|
|
172
|
-
toRestore.push(service);
|
|
173
191
|
}
|
|
174
192
|
return async () => {
|
|
175
193
|
const services = toRestore;
|
|
176
194
|
toRestore = [];
|
|
177
|
-
for (const service of services) {
|
|
195
|
+
for (const { service, admin } of services) {
|
|
178
196
|
logger?.info(`Disallowing back-dating on ${service}`);
|
|
179
197
|
try {
|
|
180
|
-
await
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
await anvil.impersonateAccount({ address: admin });
|
|
199
|
+
try {
|
|
200
|
+
await anvil.setBalance({
|
|
201
|
+
address: admin,
|
|
202
|
+
value: (0, viem.parseEther)("100")
|
|
203
|
+
});
|
|
204
|
+
await anvil.writeContractSync({
|
|
205
|
+
account: admin,
|
|
206
|
+
chain: anvil.chain,
|
|
207
|
+
address: service,
|
|
208
|
+
abi: iDSComplianceConfigurationServiceAbi,
|
|
209
|
+
functionName: "setDisallowBackDating",
|
|
210
|
+
args: [true],
|
|
211
|
+
throwOnReceiptRevert: true
|
|
212
|
+
});
|
|
213
|
+
} finally {
|
|
214
|
+
await anvil.stopImpersonatingAccount({ address: admin });
|
|
215
|
+
}
|
|
188
216
|
} catch (e) {
|
|
189
217
|
logger?.warn(`Failed to restore disallowBackDating on ${service}: ${e}`);
|
|
190
218
|
}
|
|
@@ -192,8 +220,7 @@ async function enableDSTokenBackDating(props) {
|
|
|
192
220
|
};
|
|
193
221
|
}
|
|
194
222
|
async function claimDSToken(props) {
|
|
195
|
-
const { anvil, investor,
|
|
196
|
-
const account = (0, viem_accounts.privateKeyToAccount)(adminPrivateKey);
|
|
223
|
+
const { anvil, investor, token, marketConfigurators, rwaFactories, usdAmount: usdAmountProp = "100000" } = props;
|
|
197
224
|
const symbol = await anvil.readContract({
|
|
198
225
|
address: token,
|
|
199
226
|
abi: viem.erc20Abi,
|
|
@@ -217,18 +244,31 @@ async function claimDSToken(props) {
|
|
|
217
244
|
if (amount === 0n) throw new Error(`No market found for token ${token}`);
|
|
218
245
|
logger?.debug(`${usdAmountProp} USD === ${amount} ${symbol}`);
|
|
219
246
|
await require_dev_kycUtils.registerSecuritizeInvestor({
|
|
220
|
-
...props,
|
|
221
|
-
logger
|
|
222
|
-
});
|
|
223
|
-
logger?.debug(`Issuing ${amount} tokens to ${investor}...`);
|
|
224
|
-
const mintHash = await issueDSTokens({
|
|
225
247
|
anvil,
|
|
226
|
-
account,
|
|
227
|
-
token,
|
|
228
248
|
investor,
|
|
229
|
-
|
|
249
|
+
token,
|
|
230
250
|
logger
|
|
231
251
|
});
|
|
252
|
+
const admin = await require_dev_kycUtils.getSecuritizeAdmin(anvil, token, logger);
|
|
253
|
+
logger?.debug(`Issuing ${amount} tokens to ${investor}...`);
|
|
254
|
+
await anvil.impersonateAccount({ address: admin });
|
|
255
|
+
let mintHash;
|
|
256
|
+
try {
|
|
257
|
+
await anvil.setBalance({
|
|
258
|
+
address: admin,
|
|
259
|
+
value: (0, viem.parseEther)("100")
|
|
260
|
+
});
|
|
261
|
+
mintHash = await issueDSTokens({
|
|
262
|
+
anvil,
|
|
263
|
+
account: admin,
|
|
264
|
+
token,
|
|
265
|
+
investor,
|
|
266
|
+
amount,
|
|
267
|
+
logger
|
|
268
|
+
});
|
|
269
|
+
} finally {
|
|
270
|
+
await anvil.stopImpersonatingAccount({ address: admin });
|
|
271
|
+
}
|
|
232
272
|
logger?.debug(`Done! tx: ${mintHash}`);
|
|
233
273
|
const balance = await anvil.readContract({
|
|
234
274
|
address: token,
|
|
@@ -205,18 +205,15 @@ async function fulfillMidasRedeemer(anvil, redeemer, logger) {
|
|
|
205
205
|
address: MIDAS_VAULT_ADMIN,
|
|
206
206
|
value: (0, viem.parseEther)("100")
|
|
207
207
|
});
|
|
208
|
-
|
|
208
|
+
await anvil.writeContractSync({
|
|
209
209
|
chain: anvil.chain,
|
|
210
210
|
address: midasRedemptionVault,
|
|
211
211
|
account: MIDAS_VAULT_ADMIN,
|
|
212
212
|
abi: iMidasRedemptionVaultExtAbi,
|
|
213
213
|
functionName: "safeApproveRequest",
|
|
214
|
-
args: [requestId, mTokenRate]
|
|
214
|
+
args: [requestId, mTokenRate],
|
|
215
|
+
throwOnReceiptRevert: true
|
|
215
216
|
});
|
|
216
|
-
if ((await anvil.waitForTransactionReceipt({
|
|
217
|
-
hash,
|
|
218
|
-
pollingInterval: 100
|
|
219
|
-
})).status !== "success") throw new Error(`midas: safeApproveRequest tx ${hash} reverted`);
|
|
220
217
|
await anvil.stopImpersonatingAccount({ address: MIDAS_VAULT_ADMIN });
|
|
221
218
|
}
|
|
222
219
|
/**
|
|
@@ -5,6 +5,7 @@ const require_model_errors_operation_errors = require("./operation-errors.js");
|
|
|
5
5
|
const require_model_errors_oracle_errors = require("./oracle-errors.js");
|
|
6
6
|
const require_model_errors_prepare_errors = require("./prepare-errors.js");
|
|
7
7
|
const require_model_errors_preview_errors = require("./preview-errors.js");
|
|
8
|
+
exports.accountNotMidasGreenlisted = require_model_errors_operation_errors.accountNotMidasGreenlisted;
|
|
8
9
|
exports.creditAccountFrozen = require_model_errors_liquidation_errors.creditAccountFrozen;
|
|
9
10
|
exports.creditAccountNotEmpty = require_model_errors_prepare_errors.creditAccountNotEmpty;
|
|
10
11
|
exports.creditAccountNotFound = require_model_errors_prepare_errors.creditAccountNotFound;
|
|
@@ -28,6 +29,7 @@ exports.poolPaused = require_model_errors_operation_errors.poolPaused;
|
|
|
28
29
|
exports.poolSunset = require_model_errors_operation_errors.poolSunset;
|
|
29
30
|
exports.quotaCountExceeded = require_model_errors_operation_errors.quotaCountExceeded;
|
|
30
31
|
exports.quotaLimitReached = require_model_errors_operation_errors.quotaLimitReached;
|
|
32
|
+
exports.reservePriceLimited = require_model_errors_operation_errors.reservePriceLimited;
|
|
31
33
|
exports.rwaOpenRequirementsNotMet = require_model_errors_operation_errors.rwaOpenRequirementsNotMet;
|
|
32
34
|
exports.unexpectedFailure = require_model_errors_prepare_errors.unexpectedFailure;
|
|
33
35
|
exports.unpriceableTokenError = require_model_errors_oracle_errors.unpriceableTokenError;
|
|
@@ -67,6 +67,14 @@ function insufficientCollateral(args) {
|
|
|
67
67
|
...args
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/** {@inheritDoc ReservePriceLimitedError} */
|
|
71
|
+
function reservePriceLimited(args) {
|
|
72
|
+
return {
|
|
73
|
+
code: "reservePriceLimited",
|
|
74
|
+
message: `The reserve price feed values this collateral below what the operation pays out: the account covers its debt at ${args.atMainPrices} on the main feed and only ${args.healthFactor} at the reserve one, below ${args.healthFactorThreshold}.`,
|
|
75
|
+
...args
|
|
76
|
+
};
|
|
77
|
+
}
|
|
70
78
|
/** {@inheritDoc ForbiddenTokenError} */
|
|
71
79
|
function forbiddenToken(token) {
|
|
72
80
|
return {
|
|
@@ -114,11 +122,20 @@ function insufficientAllowance(args) {
|
|
|
114
122
|
function rwaOpenRequirementsNotMet(args) {
|
|
115
123
|
return {
|
|
116
124
|
code: "rwaOpenRequirementsNotMet",
|
|
117
|
-
message:
|
|
125
|
+
message: `${args.protocol} still wants something from the borrower before ${args.token.symbol} can be opened on.`,
|
|
126
|
+
...args
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** {@inheritDoc AccountNotMidasGreenlistedError} */
|
|
130
|
+
function accountNotMidasGreenlisted(args) {
|
|
131
|
+
return {
|
|
132
|
+
code: "accountNotMidasGreenlisted",
|
|
133
|
+
message: `The credit account is not Midas-greenlisted for ${args.token.symbol}.`,
|
|
118
134
|
...args
|
|
119
135
|
};
|
|
120
136
|
}
|
|
121
137
|
//#endregion
|
|
138
|
+
exports.accountNotMidasGreenlisted = accountNotMidasGreenlisted;
|
|
122
139
|
exports.creditManagerPaused = creditManagerPaused;
|
|
123
140
|
exports.debtOutOfRange = debtOutOfRange;
|
|
124
141
|
exports.forbiddenToken = forbiddenToken;
|
|
@@ -132,4 +149,5 @@ exports.poolPaused = poolPaused;
|
|
|
132
149
|
exports.poolSunset = poolSunset;
|
|
133
150
|
exports.quotaCountExceeded = quotaCountExceeded;
|
|
134
151
|
exports.quotaLimitReached = quotaLimitReached;
|
|
152
|
+
exports.reservePriceLimited = reservePriceLimited;
|
|
135
153
|
exports.rwaOpenRequirementsNotMet = rwaOpenRequirementsNotMet;
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -39,17 +39,18 @@ exports.CHART_METRIC_UNITS = require_model_charts.CHART_METRIC_UNITS;
|
|
|
39
39
|
exports.CHART_RANGES = require_model_charts.CHART_RANGES;
|
|
40
40
|
exports.CHART_UNAVAILABLE_CODES = require_model_charts.CHART_UNAVAILABLE_CODES;
|
|
41
41
|
exports.FILTER_ALL = require_model_filters.FILTER_ALL;
|
|
42
|
-
exports.KYC_PROTOCOLS = require_model_rwa.KYC_PROTOCOLS;
|
|
43
42
|
exports.KYC_REGISTRATION_LINKS = require_model_rwa.KYC_REGISTRATION_LINKS;
|
|
44
43
|
exports.POOL_OPPORTUNITY_CHART_METRICS = require_model_charts.POOL_OPPORTUNITY_CHART_METRICS;
|
|
45
44
|
exports.POOL_POSITION_CHART_METRICS = require_model_charts.POOL_POSITION_CHART_METRICS;
|
|
46
45
|
exports.PROTOCOL_CHART_METRICS = require_model_charts.PROTOCOL_CHART_METRICS;
|
|
47
46
|
exports.RWA_FACTORY_SECURITIZE = require_model_rwa.RWA_FACTORY_SECURITIZE;
|
|
48
47
|
exports.RWA_FACTORY_TYPES = require_model_rwa.RWA_FACTORY_TYPES;
|
|
48
|
+
exports.RWA_PROTOCOLS = require_model_rwa.RWA_PROTOCOLS;
|
|
49
49
|
exports.SECURITIZE_REGISTER_VAULT_TYPES = require_model_rwa.SECURITIZE_REGISTER_VAULT_TYPES;
|
|
50
50
|
exports.STRATEGY_OPPORTUNITY_CHART_METRICS = require_model_charts.STRATEGY_OPPORTUNITY_CHART_METRICS;
|
|
51
51
|
exports.STRATEGY_POSITION_CHART_METRICS = require_model_charts.STRATEGY_POSITION_CHART_METRICS;
|
|
52
52
|
exports.STRATEGY_POSITION_COLLATERAL_ERROR = require_model_positions.STRATEGY_POSITION_COLLATERAL_ERROR;
|
|
53
|
+
exports.accountNotMidasGreenlisted = require_model_errors_operation_errors.accountNotMidasGreenlisted;
|
|
53
54
|
exports.amountSchema = require_model_primitives_schema.amountSchema;
|
|
54
55
|
exports.analyticsChartQueryOptionsSchema = require_model_analytics_schema.analyticsChartQueryOptionsSchema;
|
|
55
56
|
exports.analyticsChartQueryParamsSchema = require_model_analytics_schema.analyticsChartQueryParamsSchema;
|
|
@@ -102,7 +103,6 @@ exports.insufficientBalance = require_model_errors_operation_errors.insufficient
|
|
|
102
103
|
exports.insufficientCollateral = require_model_errors_operation_errors.insufficientCollateral;
|
|
103
104
|
exports.insufficientPoolLiquidity = require_model_errors_operation_errors.insufficientPoolLiquidity;
|
|
104
105
|
exports.isFilterSet = require_model_filters.isFilterSet;
|
|
105
|
-
exports.kycProtocolSchema = require_model_rwa_schema.kycProtocolSchema;
|
|
106
106
|
exports.kycRequirementSchema = require_model_rwa_schema.kycRequirementSchema;
|
|
107
107
|
exports.leverageOutOfRange = require_model_errors_operation_errors.leverageOutOfRange;
|
|
108
108
|
exports.leverageSchema = require_model_primitives_schema.leverageSchema;
|
|
@@ -176,11 +176,13 @@ exports.quotaLimitReached = require_model_errors_operation_errors.quotaLimitReac
|
|
|
176
176
|
exports.rateCurvePointSchema = require_model_opportunities_schema.rateCurvePointSchema;
|
|
177
177
|
exports.rateCurveSchema = require_model_opportunities_schema.rateCurveSchema;
|
|
178
178
|
exports.receivedAssetSchema = require_model_liquidations_schema.receivedAssetSchema;
|
|
179
|
+
exports.reservePriceLimited = require_model_errors_operation_errors.reservePriceLimited;
|
|
179
180
|
exports.responseMetadataSchema = require_model_response_schema.responseMetadataSchema;
|
|
180
181
|
exports.responseSchema = require_model_response_schema.responseSchema;
|
|
181
182
|
exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
|
|
182
183
|
exports.rewardsSchema = require_model_opportunities_schema.rewardsSchema;
|
|
183
184
|
exports.rwaOpenRequirementsNotMet = require_model_errors_operation_errors.rwaOpenRequirementsNotMet;
|
|
185
|
+
exports.rwaProtocolSchema = require_model_rwa_schema.rwaProtocolSchema;
|
|
184
186
|
exports.safeValue = require_model_result.safeValue;
|
|
185
187
|
exports.sdkErr = require_model_result.sdkErr;
|
|
186
188
|
exports.sdkOk = require_model_result.sdkOk;
|
package/dist/cjs/model/rwa.js
CHANGED
|
@@ -35,19 +35,19 @@ const SECURITIZE_REGISTER_VAULT_TYPES = { RegisterVault: [
|
|
|
35
35
|
}
|
|
36
36
|
] };
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* RWA protocols that require dedicated flows
|
|
39
39
|
**/
|
|
40
|
-
const
|
|
40
|
+
const RWA_PROTOCOLS = ["securitize", "midas"];
|
|
41
41
|
/**
|
|
42
|
-
* Hardcoded registration URLs for each {@link
|
|
42
|
+
* Hardcoded registration URLs for each {@link RWAProtocol}.
|
|
43
43
|
**/
|
|
44
44
|
const KYC_REGISTRATION_LINKS = {
|
|
45
45
|
securitize: "https://securitize.io/",
|
|
46
46
|
midas: "https://form.typeform.com/to/DqZaw6kr"
|
|
47
47
|
};
|
|
48
48
|
//#endregion
|
|
49
|
-
exports.KYC_PROTOCOLS = KYC_PROTOCOLS;
|
|
50
49
|
exports.KYC_REGISTRATION_LINKS = KYC_REGISTRATION_LINKS;
|
|
51
50
|
exports.RWA_FACTORY_SECURITIZE = RWA_FACTORY_SECURITIZE;
|
|
52
51
|
exports.RWA_FACTORY_TYPES = RWA_FACTORY_TYPES;
|
|
52
|
+
exports.RWA_PROTOCOLS = RWA_PROTOCOLS;
|
|
53
53
|
exports.SECURITIZE_REGISTER_VAULT_TYPES = SECURITIZE_REGISTER_VAULT_TYPES;
|
|
@@ -4,17 +4,17 @@ const require_model_rwa = require("./rwa.js");
|
|
|
4
4
|
let zod_v4 = require("zod/v4");
|
|
5
5
|
//#region src/model/rwa.schema.ts
|
|
6
6
|
/**
|
|
7
|
-
* {@link ./rwa.js#
|
|
7
|
+
* {@link ./rwa.js#RWAProtocol}
|
|
8
8
|
**/
|
|
9
|
-
const
|
|
9
|
+
const rwaProtocolSchema = zod_v4.z.enum(require_model_rwa.RWA_PROTOCOLS);
|
|
10
10
|
/**
|
|
11
11
|
* {@link ./rwa.js#KycRequirement}
|
|
12
12
|
**/
|
|
13
13
|
const kycRequirementSchema = zod_v4.z.object({
|
|
14
|
-
protocol:
|
|
14
|
+
protocol: rwaProtocolSchema,
|
|
15
15
|
token: require_model_primitives_schema.tokenSchema.optional(),
|
|
16
16
|
registrationLink: zod_v4.z.string()
|
|
17
17
|
});
|
|
18
18
|
//#endregion
|
|
19
|
-
exports.kycProtocolSchema = kycProtocolSchema;
|
|
20
19
|
exports.kycRequirementSchema = kycRequirementSchema;
|
|
20
|
+
exports.rwaProtocolSchema = rwaProtocolSchema;
|
|
@@ -36,7 +36,7 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
|
|
|
36
36
|
/**
|
|
37
37
|
* {@inheritDoc IOffchainOpportunities.getStrategy}
|
|
38
38
|
**/
|
|
39
|
-
async getStrategy(key
|
|
39
|
+
async getStrategy(key) {
|
|
40
40
|
return this.get({
|
|
41
41
|
path: this.#strategyPath(key),
|
|
42
42
|
schema: require_model_opportunities_schema.strategyOpportunityDetailSchema
|
|
@@ -14,7 +14,7 @@ const require_onchain_base_ChainContractsRegister = require("./base/ChainContrac
|
|
|
14
14
|
require("./base/index.js");
|
|
15
15
|
const require_onchain_utils_viem_executeDelegatedMulticalls = require("./utils/viem/executeDelegatedMulticalls.js");
|
|
16
16
|
require("./utils/viem/index.js");
|
|
17
|
-
const
|
|
17
|
+
const require_onchain_market_pricefeeds_updates_UpdatablePriceFeedRegistry = require("./market/pricefeeds/updates/UpdatablePriceFeedRegistry.js");
|
|
18
18
|
require("./market/pricefeeds/index.js");
|
|
19
19
|
const require_onchain_market_MarketRegister = require("./market/MarketRegister.js");
|
|
20
20
|
const require_onchain_market_rwa_RWARegistry = require("./market/rwa/RWARegistry.js");
|
|
@@ -168,7 +168,7 @@ var OnchainSDK = class extends require_onchain_base_ChainContractsRegister.Chain
|
|
|
168
168
|
this.#currentBlock = block.number;
|
|
169
169
|
this.#timestamp = block.timestamp;
|
|
170
170
|
if (blockNumber && !redstone?.historicTimestamp && time - Number(block.timestamp) * 1e3 > 6e4) this.logger?.warn("attaching to fixed block number, but redstone historicTimestamp is not set. price updates might fail");
|
|
171
|
-
this.#priceFeeds = new
|
|
171
|
+
this.#priceFeeds = new require_onchain_market_pricefeeds_updates_UpdatablePriceFeedRegistry.UpdatablePriceFeedRegistry(this, { redstone });
|
|
172
172
|
this.logger?.debug(`attach block number ${this.currentBlock} timestamp ${this.timestamp}`);
|
|
173
173
|
this.#addressProvider = await require_onchain_core_createAddressProvider.createAddressProvider(this, addressProvider);
|
|
174
174
|
this.logger?.debug(`address provider version: ${this.#addressProvider.version}`);
|
|
@@ -263,7 +263,7 @@ var OnchainSDK = class extends require_onchain_base_ChainContractsRegister.Chain
|
|
|
263
263
|
this.logger?.info({ networkType: this.networkType }, "hydrating sdk state");
|
|
264
264
|
this.#currentBlock = state.currentBlock;
|
|
265
265
|
this.#timestamp = state.timestamp;
|
|
266
|
-
this.#priceFeeds = new
|
|
266
|
+
this.#priceFeeds = new require_onchain_market_pricefeeds_updates_UpdatablePriceFeedRegistry.UpdatablePriceFeedRegistry(this, { redstone });
|
|
267
267
|
this.#addressProvider = require_onchain_core_createAddressProvider.hydrateAddressProvider(this, state.addressProvider);
|
|
268
268
|
this.logger?.debug(`address provider version: ${this.#addressProvider.version}`);
|
|
269
269
|
this.#marketRegister = new require_onchain_market_MarketRegister.MarketRegister(this, ignoreMarkets);
|
|
@@ -16,7 +16,6 @@ require("../market/index.js");
|
|
|
16
16
|
const require_onchain_accounts_credit_account_compressor_CreditAccountCompressor = require("./credit-account-compressor/CreditAccountCompressor.js");
|
|
17
17
|
require("./credit-account-compressor/index.js");
|
|
18
18
|
const require_onchain_accounts_multicall_utils = require("./multicall-utils.js");
|
|
19
|
-
const require_onchain_accounts_utils_midasUtils = require("./utils/midasUtils.js");
|
|
20
19
|
let viem = require("viem");
|
|
21
20
|
//#region src/onchain/accounts/CreditAccountsServiceV310.ts
|
|
22
21
|
/**
|
|
@@ -189,9 +188,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
189
188
|
* {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
|
|
190
189
|
*/
|
|
191
190
|
async getOpenAccountRequirements(borrower, creditManager, props) {
|
|
192
|
-
|
|
193
|
-
if (!rwaFactory) return;
|
|
194
|
-
return rwaFactory.getOpenAccountRequirements(borrower, props);
|
|
191
|
+
return (await this.sdk.marketRegister.findCreditManager(creditManager).degenNFT())?.getOpenAccountRequirements(borrower, props);
|
|
195
192
|
}
|
|
196
193
|
/**
|
|
197
194
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
@@ -215,7 +212,7 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
215
212
|
}),
|
|
216
213
|
...callsAfter ?? []
|
|
217
214
|
];
|
|
218
|
-
calls = await
|
|
215
|
+
calls = [...await cmSuite.openingCalls(), ...calls];
|
|
219
216
|
calls = await this.prependPriceUpdates(cm.address, calls);
|
|
220
217
|
const tx = reopenCreditAccount ? cmSuite.multicallTx(reopenCreditAccount, calls, rwaOptions) : cmSuite.openCreditAccountTx(to, calls, referralCode, rwaOptions);
|
|
221
218
|
tx.value = ethAmount.toString(10);
|
|
@@ -442,18 +439,6 @@ var CreditAccountsServiceV310 = class extends require_onchain_base_SDKConstruct.
|
|
|
442
439
|
return this.sdk.addressProvider.mustGetLatest(require_onchain_constants_address_provider.AP_REWARDS_COMPRESSOR, require_onchain_constants_versions.VERSION_RANGE_310)[0];
|
|
443
440
|
}
|
|
444
441
|
/**
|
|
445
|
-
* {@inheritDoc ICreditAccountsService.prependMidasReceiveGreenlist}
|
|
446
|
-
*/
|
|
447
|
-
async #prependMidasReceiveGreenlist(creditManager, calls) {
|
|
448
|
-
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
449
|
-
return require_onchain_accounts_utils_midasUtils.prependMidasReceiveGreenlist({
|
|
450
|
-
cm,
|
|
451
|
-
client: this.client,
|
|
452
|
-
calls,
|
|
453
|
-
logger: this.logger
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
442
|
* Withdrawal compressor of the current chain.
|
|
458
443
|
* @throws If no withdrawal compressor is supported on the current chain.
|
|
459
444
|
**/
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
|
|
3
|
+
const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
|
|
4
|
+
require("../../../model/index.js");
|
|
5
|
+
const require_onchain_validation_helpers_token = require("../../validation/helpers/token.js");
|
|
6
|
+
const require_onchain_validation_raise = require("../../validation/raise.js");
|
|
7
|
+
require("../../validation/index.js");
|
|
8
|
+
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
9
|
+
const require_onchain_accounts_intents_guards = require("./guards.js");
|
|
10
|
+
const require_onchain_accounts_intents_math = require("./math.js");
|
|
11
|
+
const require_onchain_accounts_intents_utils_credit_account_slice = require("./utils/credit-account-slice.js");
|
|
12
|
+
const require_onchain_accounts_intents_utils_price_impact = require("./utils/price-impact.js");
|
|
13
|
+
const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
|
|
14
|
+
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
15
|
+
require("./utils/index.js");
|
|
16
|
+
//#region src/onchain/accounts/intents/borrow.ts
|
|
17
|
+
/**
|
|
18
|
+
* Builds the state a borrow would leave behind.
|
|
19
|
+
*
|
|
20
|
+
* The debt is named rather than derived: a borrow asks for an amount, where an
|
|
21
|
+
* opening asks for a leverage and lets the collateral decide. Everything the
|
|
22
|
+
* loan pays out leaves the account, so the collateral alone backs it — which
|
|
23
|
+
* is what makes the health factor here a straight function of the two amounts.
|
|
24
|
+
*
|
|
25
|
+
* Produces no operation list, as opening never does: the caller hands the
|
|
26
|
+
* numbers and the calls to `sdk.accounts.openCA`, with `withdrawToken` set to
|
|
27
|
+
* the payout.
|
|
28
|
+
*/
|
|
29
|
+
async function buildBorrowState(props) {
|
|
30
|
+
const { sdk, creditManager, collateralAmount, borrowAmount, slippage = 0, quotaReserve, creditAccount: existing } = props;
|
|
31
|
+
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
32
|
+
const market = sdk.marketRegister.findByCreditManager(creditManager);
|
|
33
|
+
require_onchain_accounts_intents_guards.assertMarketOperable(suite);
|
|
34
|
+
const underlying = market.pool.underlying.toLowerCase();
|
|
35
|
+
const collateralToken = props.collateralToken.toLowerCase();
|
|
36
|
+
const borrowToken = props.borrowToken.toLowerCase();
|
|
37
|
+
const convert = (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value;
|
|
38
|
+
if (require_onchain_accounts_intents_utils_common.eq(collateralToken, borrowToken)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, collateralToken)), "borrow: the payout token cannot also be the collateral");
|
|
39
|
+
const rwaAsset = sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset?.toLowerCase();
|
|
40
|
+
const unwrapsPayout = !!rwaAsset && require_onchain_accounts_intents_utils_common.eq(borrowToken, rwaAsset);
|
|
41
|
+
if (rwaAsset && require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying)) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_prepare_errors.unsupportedCollateralToken(require_onchain_validation_helpers_token.toToken(sdk, borrowToken)), `borrow: ${underlying} cannot leave the account, ask for the payout in ${rwaAsset}`);
|
|
42
|
+
if (collateralAmount <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: no collateral supplied");
|
|
43
|
+
if (borrowAmount <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: nothing to borrow");
|
|
44
|
+
const margin = convert(collateralToken, underlying, collateralAmount);
|
|
45
|
+
if (margin <= 0n) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrow: collateral is worth nothing in underlying");
|
|
46
|
+
const debt = require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) ? borrowAmount : unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(borrowAmount, borrowToken, underlying, sdk) : convert(borrowToken, underlying, borrowAmount);
|
|
47
|
+
require_onchain_accounts_intents_math.assertDebtLimits(sdk, debt, suite.creditFacade, underlying);
|
|
48
|
+
require_onchain_accounts_intents_guards.assertCanBorrow(sdk, suite, debt);
|
|
49
|
+
const account = existing ?? require_onchain_accounts_intents_utils_credit_account_slice.unopenedAccountSlice({
|
|
50
|
+
creditManager,
|
|
51
|
+
creditFacade: suite.creditFacade.address,
|
|
52
|
+
underlying
|
|
53
|
+
});
|
|
54
|
+
const leg = require_onchain_accounts_intents_utils_common.eq(borrowToken, underlying) || unwrapsPayout ? void 0 : await require_onchain_accounts_intents_utils_router_path.createRouterPaths({
|
|
55
|
+
sdk,
|
|
56
|
+
creditAccount: account,
|
|
57
|
+
slippage
|
|
58
|
+
}).swap({
|
|
59
|
+
tokenIn: underlying,
|
|
60
|
+
tokenOut: borrowToken,
|
|
61
|
+
amount: debt,
|
|
62
|
+
keep: require_onchain_accounts_intents_utils_common.eq(collateralToken, underlying) ? collateralAmount : 0n
|
|
63
|
+
});
|
|
64
|
+
const unwrap = unwrapsPayout ? await sdk.accounts.assembleRWAUnwrapCalls(debt, creditManager) : void 0;
|
|
65
|
+
if (unwrapsPayout && !unwrap) throw new Error(`borrow: no unwrap calls found for ${borrowToken}`);
|
|
66
|
+
const assets = [{
|
|
67
|
+
token: collateralToken,
|
|
68
|
+
balance: collateralAmount
|
|
69
|
+
}];
|
|
70
|
+
const quotaIncrease = borrowCollateralQuota({
|
|
71
|
+
sdk,
|
|
72
|
+
creditManager,
|
|
73
|
+
assets,
|
|
74
|
+
quotaReserve
|
|
75
|
+
});
|
|
76
|
+
require_onchain_accounts_intents_guards.assertGrowthAllowed({
|
|
77
|
+
sdk,
|
|
78
|
+
suite,
|
|
79
|
+
market,
|
|
80
|
+
before: [],
|
|
81
|
+
after: assets
|
|
82
|
+
});
|
|
83
|
+
require_onchain_accounts_intents_guards.assertQuotaAvailable(sdk, market, quotaIncrease);
|
|
84
|
+
const snapshot = {
|
|
85
|
+
creditManager,
|
|
86
|
+
assets,
|
|
87
|
+
quotas: quotaIncrease,
|
|
88
|
+
totalDebt: debt,
|
|
89
|
+
totalValue: margin
|
|
90
|
+
};
|
|
91
|
+
const projection = sdk.positions.projection(snapshot, { availableLiquidityChange: -debt });
|
|
92
|
+
require_onchain_accounts_intents_guards.assertCollateralised(projection.safeHealthFactor, true);
|
|
93
|
+
const priced = (token, balance) => market.priceOracle.toTokenAmount(token, balance);
|
|
94
|
+
const payout = unwrapsPayout ? require_onchain_accounts_intents_utils_common.toTargetDecimals(debt, underlying, borrowToken, sdk) : leg ? leg.amount : debt;
|
|
95
|
+
return {
|
|
96
|
+
...projection,
|
|
97
|
+
currentPrice: sdk.positions.currentPrice(snapshot),
|
|
98
|
+
executionCost: void 0,
|
|
99
|
+
priceImpact: await require_onchain_accounts_intents_utils_price_impact.collectPriceImpact(leg?.probe ? [leg.probe] : [], {
|
|
100
|
+
totalValue: margin,
|
|
101
|
+
netValue: margin - debt,
|
|
102
|
+
toUnderlying: (from, amount) => convert(from, underlying, amount),
|
|
103
|
+
toUnderlyingAmount: market.toUnderlyingAmount
|
|
104
|
+
}),
|
|
105
|
+
collateral: priced(collateralToken, collateralAmount),
|
|
106
|
+
borrowed: priced(borrowToken, payout),
|
|
107
|
+
minBorrowed: priced(borrowToken, leg ? leg.minAmount : payout),
|
|
108
|
+
slippage,
|
|
109
|
+
quotaIncrease,
|
|
110
|
+
calls: leg ? [...leg.calls] : unwrap ?? [],
|
|
111
|
+
creditAccount: existing?.creditAccount
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Quota a borrow buys for its collateral on an account that holds none yet.
|
|
116
|
+
*
|
|
117
|
+
* Shared with `maxBorrow`, because a quota short of the collateral's weighted
|
|
118
|
+
* value is what caps the loan: the two have to read the same number or the
|
|
119
|
+
* ceiling one offers is one the other refuses.
|
|
120
|
+
*
|
|
121
|
+
* @param props - {@link BorrowCollateralQuotaProps}
|
|
122
|
+
**/
|
|
123
|
+
function borrowCollateralQuota({ sdk, creditManager, assets, quotaReserve }) {
|
|
124
|
+
const suite = sdk.marketRegister.findCreditManager(creditManager);
|
|
125
|
+
const market = sdk.marketRegister.findByCreditManager(creditManager);
|
|
126
|
+
return require_onchain_accounts_intents_utils_quotas_for_update.getQuotasForUpdate({
|
|
127
|
+
assetsBefore: [],
|
|
128
|
+
assetsAfter: assets,
|
|
129
|
+
initialQuotas: [],
|
|
130
|
+
quotaReserve,
|
|
131
|
+
underlyingToken: market.pool.underlying,
|
|
132
|
+
liquidationThresholds: suite.creditManager.liquidationThresholds,
|
|
133
|
+
quotas: market.pool.pqk.quotas,
|
|
134
|
+
maxDebt: suite.creditFacade.maxDebt,
|
|
135
|
+
convert: (from, to, amount) => market.priceOracle.safeConvert(from, to, amount).value
|
|
136
|
+
}).quotaIncrease;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
exports.borrowCollateralQuota = borrowCollateralQuota;
|
|
140
|
+
exports.buildBorrowState = buildBorrowState;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
|
|
3
|
+
const require_onchain_constants_math = require("../../constants/math.js");
|
|
4
|
+
require("../../utils/index.js");
|
|
5
|
+
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
6
|
+
//#region src/onchain/accounts/intents/collateral-valuation.ts
|
|
7
|
+
/** {@inheritDoc CollateralValuation} */
|
|
8
|
+
function collateralValuation(creditAccount, sdk) {
|
|
9
|
+
const { market, creditManager } = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
10
|
+
const { priceOracle } = market;
|
|
11
|
+
const { pqk } = market.pool;
|
|
12
|
+
const underlying = market.pool.underlying;
|
|
13
|
+
const masked = creditAccount.enabledTokensMask !== 0n;
|
|
14
|
+
const mainUsd = (token, amount) => {
|
|
15
|
+
try {
|
|
16
|
+
return priceOracle.convertToUSD(token, amount);
|
|
17
|
+
} catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const lt = (token) => BigInt(creditManager.liquidationThresholds.get(token) ?? 0);
|
|
22
|
+
const checkedUsd = (holding) => require_onchain_accounts_intents_utils_common.eq(holding.token, underlying) ? mainUsd(holding.token, holding.balance) ?? 0n : priceOracle.safeConvertMinUSD(holding.token, holding.balance).value;
|
|
23
|
+
/** A quota is underlying-denominated, and a closed market backs nothing. */
|
|
24
|
+
const quotaValue = (holding) => pqk.hasActiveQuota(holding.token) ? (mainUsd(underlying, holding.quota) ?? 0n) * require_onchain_constants_math.PERCENTAGE_FACTOR : 0n;
|
|
25
|
+
const weigh = (holding) => {
|
|
26
|
+
const weighted = checkedUsd(holding) * lt(holding.token);
|
|
27
|
+
if (holding.quota === 0n) return weighted;
|
|
28
|
+
return require_onchain_utils_bigint_math.BigIntMath.min(quotaValue(holding), weighted);
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
underlying,
|
|
32
|
+
counts: (holding) => holding.balance > 10n && (!masked || (holding.mask & creditAccount.enabledTokensMask) !== 0n),
|
|
33
|
+
weigh,
|
|
34
|
+
quotaValue,
|
|
35
|
+
mainUsd,
|
|
36
|
+
checkedUsd,
|
|
37
|
+
lt
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.collateralValuation = collateralValuation;
|