@wildcatfi/wildcat-sdk 3.0.76-beta → 3.1.1-beta
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/README.md +2 -2
- package/dist/access/access-control.d.ts +23 -36
- package/dist/access/access-control.d.ts.map +1 -1
- package/dist/access/access-control.js +104 -142
- package/dist/access/access-control.js.map +1 -1
- package/dist/access/fixed-term.d.ts +23 -36
- package/dist/access/fixed-term.d.ts.map +1 -1
- package/dist/access/fixed-term.js +115 -154
- package/dist/access/fixed-term.js.map +1 -1
- package/dist/access/index.d.ts +9 -15
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +21 -59
- package/dist/access/index.js.map +1 -1
- package/dist/access/periodic-term.d.ts +84 -0
- package/dist/access/periodic-term.d.ts.map +1 -0
- package/dist/access/periodic-term.js +298 -0
- package/dist/access/periodic-term.js.map +1 -0
- package/dist/access/utils.d.ts +1 -11
- package/dist/access/utils.d.ts.map +1 -1
- package/dist/access/utils.js +11 -87
- package/dist/access/utils.js.map +1 -1
- package/dist/access/validation.d.ts +8 -32
- package/dist/access/validation.d.ts.map +1 -1
- package/dist/access/validation.js +1 -18
- package/dist/access/validation.js.map +1 -1
- package/dist/account/index.d.ts +39 -35
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +301 -315
- package/dist/account/index.js.map +1 -1
- package/dist/account/validation.d.ts +19 -3
- package/dist/account/validation.d.ts.map +1 -1
- package/dist/account/validation.js +16 -2
- package/dist/account/validation.js.map +1 -1
- package/dist/collateral/collateral-events.d.ts +10 -9
- package/dist/collateral/collateral-events.d.ts.map +1 -1
- package/dist/collateral/collateral-events.js +4 -4
- package/dist/collateral/collateral-events.js.map +1 -1
- package/dist/collateral/index.d.ts +10 -7
- package/dist/collateral/index.d.ts.map +1 -1
- package/dist/collateral/index.js +37 -36
- package/dist/collateral/index.js.map +1 -1
- package/dist/constants.d.ts +13 -100
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +27 -290
- package/dist/constants.js.map +1 -1
- package/dist/controller.d.ts +17 -10
- package/dist/controller.d.ts.map +1 -1
- package/dist/controller.js +67 -67
- package/dist/controller.js.map +1 -1
- package/dist/gql/getActiveLendersByMarket.d.ts +4 -5
- package/dist/gql/getActiveLendersByMarket.d.ts.map +1 -1
- package/dist/gql/getActiveLendersByMarket.js +10 -11
- package/dist/gql/getActiveLendersByMarket.js.map +1 -1
- package/dist/gql/getAllHooksDataForBorrower.d.ts.map +1 -1
- package/dist/gql/getAllHooksDataForBorrower.js +8 -11
- package/dist/gql/getAllHooksDataForBorrower.js.map +1 -1
- package/dist/gql/getAllHooksTemplates.d.ts.map +1 -1
- package/dist/gql/getAllHooksTemplates.js +4 -6
- package/dist/gql/getAllHooksTemplates.js.map +1 -1
- package/dist/gql/getLenderAccountsForAllMarkets.d.ts +1 -8
- package/dist/gql/getLenderAccountsForAllMarkets.d.ts.map +1 -1
- package/dist/gql/getLenderAccountsForAllMarkets.js +11 -26
- package/dist/gql/getLenderAccountsForAllMarkets.js.map +1 -1
- package/dist/gql/getMarketRecords.d.ts +2 -2
- package/dist/gql/getMarketRecords.d.ts.map +1 -1
- package/dist/gql/getMarketRecords.js +6 -2
- package/dist/gql/getMarketRecords.js.map +1 -1
- package/dist/gql/getMarketsForBorrower.d.ts.map +1 -1
- package/dist/gql/getMarketsForBorrower.js +2 -32
- package/dist/gql/getMarketsForBorrower.js.map +1 -1
- package/dist/gql/getMarketsWithEvents.d.ts.map +1 -1
- package/dist/gql/getMarketsWithEvents.js +0 -28
- package/dist/gql/getMarketsWithEvents.js.map +1 -1
- package/dist/gql/graphql.d.ts +678 -1480
- package/dist/gql/graphql.d.ts.map +1 -1
- package/dist/gql/graphql.js +243 -591
- package/dist/gql/graphql.js.map +1 -1
- package/dist/gql/index.d.ts +0 -2
- package/dist/gql/index.d.ts.map +1 -1
- package/dist/gql/index.js +0 -2
- package/dist/gql/index.js.map +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/market.d.ts +22 -73
- package/dist/market.d.ts.map +1 -1
- package/dist/market.js +284 -582
- package/dist/market.js.map +1 -1
- package/dist/mockerc20factory.d.ts +11 -4
- package/dist/mockerc20factory.d.ts.map +1 -1
- package/dist/mockerc20factory.js +15 -20
- package/dist/mockerc20factory.js.map +1 -1
- package/dist/token.d.ts +12 -54
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +57 -148
- package/dist/token.js.map +1 -1
- package/dist/typechain/AccountQuery.d.ts +54 -0
- package/dist/typechain/AccountQuery.d.ts.map +1 -0
- package/dist/typechain/AccountQuery.js +3 -0
- package/dist/typechain/AccountQuery.js.map +1 -0
- package/dist/typechain/AccountsQuery.d.ts +54 -0
- package/dist/typechain/AccountsQuery.d.ts.map +1 -0
- package/dist/typechain/AccountsQuery.js +3 -0
- package/dist/typechain/AccountsQuery.js.map +1 -0
- package/dist/typechain/CheckBorrowersRegistered.d.ts +29 -0
- package/dist/typechain/CheckBorrowersRegistered.d.ts.map +1 -0
- package/dist/typechain/CheckBorrowersRegistered.js +3 -0
- package/dist/typechain/CheckBorrowersRegistered.js.map +1 -0
- package/dist/typechain/CheckSafeSignature.d.ts +29 -0
- package/dist/typechain/CheckSafeSignature.d.ts.map +1 -0
- package/dist/typechain/CheckSafeSignature.js +3 -0
- package/dist/typechain/CheckSafeSignature.js.map +1 -0
- package/dist/typechain/CollateralLens.d.ts +220 -0
- package/dist/typechain/CollateralLens.d.ts.map +1 -0
- package/dist/typechain/CollateralLens.js +3 -0
- package/dist/typechain/CollateralLens.js.map +1 -0
- package/dist/typechain/DescribeSignature.d.ts +100 -0
- package/dist/typechain/DescribeSignature.d.ts.map +1 -0
- package/dist/typechain/DescribeSignature.js +3 -0
- package/dist/typechain/DescribeSignature.js.map +1 -0
- package/dist/typechain/HooksFactory.d.ts +591 -16
- package/dist/typechain/HooksFactory.d.ts.map +1 -1
- package/dist/typechain/IERC20.d.ts +232 -0
- package/dist/typechain/IERC20.d.ts.map +1 -0
- package/dist/{lens-types.js → typechain/IERC20.js} +1 -1
- package/dist/typechain/IERC20.js.map +1 -0
- package/dist/typechain/IFixedTermHooks.d.ts +1032 -0
- package/dist/typechain/IFixedTermHooks.d.ts.map +1 -0
- package/dist/typechain/IFixedTermHooks.js +3 -0
- package/dist/typechain/IFixedTermHooks.js.map +1 -0
- package/dist/typechain/IOpenTermHooks.d.ts +987 -0
- package/dist/typechain/IOpenTermHooks.d.ts.map +1 -0
- package/dist/typechain/IOpenTermHooks.js +3 -0
- package/dist/typechain/IOpenTermHooks.js.map +1 -0
- package/dist/typechain/IPeriodicTermHooks.d.ts +663 -0
- package/dist/typechain/IPeriodicTermHooks.d.ts.map +1 -0
- package/dist/typechain/IPeriodicTermHooks.js +3 -0
- package/dist/typechain/IPeriodicTermHooks.js.map +1 -0
- package/dist/typechain/ISafe.d.ts +124 -0
- package/dist/typechain/ISafe.d.ts.map +1 -0
- package/dist/typechain/ISafe.js +3 -0
- package/dist/typechain/ISafe.js.map +1 -0
- package/dist/typechain/MarketLens.d.ts +611 -0
- package/dist/typechain/MarketLens.d.ts.map +1 -0
- package/dist/typechain/MarketLens.js +3 -0
- package/dist/typechain/MarketLens.js.map +1 -0
- package/dist/typechain/MarketLensV2.d.ts +710 -0
- package/dist/typechain/MarketLensV2.d.ts.map +1 -0
- package/dist/typechain/MarketLensV2.js +3 -0
- package/dist/typechain/MarketLensV2.js.map +1 -0
- package/dist/typechain/MockArchControllerOwner.d.ts +130 -0
- package/dist/typechain/MockArchControllerOwner.d.ts.map +1 -0
- package/dist/typechain/MockArchControllerOwner.js +3 -0
- package/dist/typechain/MockArchControllerOwner.js.map +1 -0
- package/dist/typechain/MockERC20Factory.d.ts +122 -0
- package/dist/typechain/MockERC20Factory.d.ts.map +1 -0
- package/dist/typechain/MockERC20Factory.js +3 -0
- package/dist/typechain/MockERC20Factory.js.map +1 -0
- package/dist/typechain/SimpleMarketCollateral.d.ts +270 -0
- package/dist/typechain/SimpleMarketCollateral.d.ts.map +1 -0
- package/dist/typechain/SimpleMarketCollateral.js +3 -0
- package/dist/typechain/SimpleMarketCollateral.js.map +1 -0
- package/dist/typechain/WildcatArchController.d.ts +545 -0
- package/dist/typechain/WildcatArchController.d.ts.map +1 -0
- package/dist/typechain/WildcatArchController.js +3 -0
- package/dist/typechain/WildcatArchController.js.map +1 -0
- package/dist/typechain/WildcatCollateralFactory.d.ts +164 -0
- package/dist/typechain/WildcatCollateralFactory.d.ts.map +1 -0
- package/dist/typechain/WildcatCollateralFactory.js +3 -0
- package/dist/typechain/WildcatCollateralFactory.js.map +1 -0
- package/dist/typechain/WildcatMarket.d.ts +1062 -0
- package/dist/typechain/WildcatMarket.d.ts.map +1 -0
- package/dist/typechain/WildcatMarket.js +3 -0
- package/dist/typechain/WildcatMarket.js.map +1 -0
- package/dist/typechain/WildcatMarketController.d.ts +553 -0
- package/dist/typechain/WildcatMarketController.d.ts.map +1 -0
- package/dist/typechain/WildcatMarketController.js +3 -0
- package/dist/typechain/WildcatMarketController.js.map +1 -0
- package/dist/typechain/WildcatMarketControllerFactory.d.ts +344 -0
- package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +1 -0
- package/dist/typechain/WildcatMarketControllerFactory.js +3 -0
- package/dist/typechain/WildcatMarketControllerFactory.js.map +1 -0
- package/dist/typechain/WildcatMarketV2.d.ts +1086 -0
- package/dist/typechain/WildcatMarketV2.d.ts.map +1 -0
- package/dist/typechain/WildcatMarketV2.js +3 -0
- package/dist/typechain/WildcatMarketV2.js.map +1 -0
- package/dist/typechain/common.d.ts +23 -0
- package/dist/typechain/common.d.ts.map +1 -0
- package/dist/typechain/common.js +3 -0
- package/dist/typechain/common.js.map +1 -0
- package/dist/typechain/factories/AccountQuery__factory.d.ts +59 -0
- package/dist/typechain/factories/AccountQuery__factory.d.ts.map +1 -0
- package/dist/typechain/factories/AccountQuery__factory.js +91 -0
- package/dist/typechain/factories/AccountQuery__factory.js.map +1 -0
- package/dist/typechain/factories/AccountsQuery__factory.d.ts +59 -0
- package/dist/typechain/factories/AccountsQuery__factory.d.ts.map +1 -0
- package/dist/typechain/factories/AccountsQuery__factory.js +91 -0
- package/dist/typechain/factories/AccountsQuery__factory.js.map +1 -0
- package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts +36 -0
- package/dist/typechain/factories/CheckBorrowersRegistered__factory.d.ts.map +1 -0
- package/dist/typechain/factories/CheckBorrowersRegistered__factory.js +60 -0
- package/dist/typechain/factories/CheckBorrowersRegistered__factory.js.map +1 -0
- package/dist/typechain/factories/CheckSafeSignature__factory.d.ts +40 -0
- package/dist/typechain/factories/CheckSafeSignature__factory.d.ts.map +1 -0
- package/dist/typechain/factories/CheckSafeSignature__factory.js +65 -0
- package/dist/typechain/factories/CheckSafeSignature__factory.js.map +1 -0
- package/dist/typechain/factories/CollateralLens__factory.d.ts +854 -0
- package/dist/typechain/factories/CollateralLens__factory.d.ts.map +1 -0
- package/dist/typechain/factories/CollateralLens__factory.js +1101 -0
- package/dist/typechain/factories/CollateralLens__factory.js.map +1 -0
- package/dist/typechain/factories/DescribeSignature__factory.d.ts +141 -0
- package/dist/typechain/factories/DescribeSignature__factory.d.ts.map +1 -0
- package/dist/typechain/factories/DescribeSignature__factory.js +198 -0
- package/dist/typechain/factories/DescribeSignature__factory.js.map +1 -0
- package/dist/typechain/factories/HooksFactory__factory.d.ts +902 -0
- package/dist/typechain/factories/HooksFactory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/HooksFactory__factory.js +1168 -0
- package/dist/typechain/factories/HooksFactory__factory.js.map +1 -0
- package/dist/typechain/factories/IERC20__factory.d.ts +235 -0
- package/dist/typechain/factories/IERC20__factory.d.ts.map +1 -0
- package/dist/typechain/factories/IERC20__factory.js +315 -0
- package/dist/typechain/factories/IERC20__factory.js.map +1 -0
- package/dist/typechain/factories/IFixedTermHooks__factory.d.ts +1894 -0
- package/dist/typechain/factories/IFixedTermHooks__factory.d.ts.map +1 -0
- package/dist/typechain/factories/IFixedTermHooks__factory.js +2423 -0
- package/dist/typechain/factories/IFixedTermHooks__factory.js.map +1 -0
- package/dist/typechain/factories/IOpenTermHooks__factory.d.ts +1791 -0
- package/dist/typechain/factories/IOpenTermHooks__factory.d.ts.map +1 -0
- package/dist/typechain/factories/IOpenTermHooks__factory.js +2293 -0
- package/dist/typechain/factories/IOpenTermHooks__factory.js.map +1 -0
- package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts +750 -0
- package/dist/typechain/factories/IPeriodicTermHooks__factory.d.ts.map +1 -0
- package/dist/typechain/factories/IPeriodicTermHooks__factory.js +975 -0
- package/dist/typechain/factories/IPeriodicTermHooks__factory.js.map +1 -0
- package/dist/typechain/factories/ISafe__factory.d.ts +163 -0
- package/dist/typechain/factories/ISafe__factory.d.ts.map +1 -0
- package/dist/typechain/factories/ISafe__factory.js +225 -0
- package/dist/typechain/factories/ISafe__factory.js.map +1 -0
- package/dist/typechain/factories/MarketLensV2__factory.d.ts +6708 -0
- package/dist/typechain/factories/MarketLensV2__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MarketLensV2__factory.js +8574 -0
- package/dist/typechain/factories/MarketLensV2__factory.js.map +1 -0
- package/dist/typechain/factories/MarketLens__factory.d.ts +3572 -0
- package/dist/typechain/factories/MarketLens__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MarketLens__factory.js +4569 -0
- package/dist/typechain/factories/MarketLens__factory.js.map +1 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +85 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.js +118 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +1 -0
- package/dist/typechain/factories/MockERC20Factory__factory.d.ts +114 -0
- package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MockERC20Factory__factory.js +157 -0
- package/dist/typechain/factories/MockERC20Factory__factory.js.map +1 -0
- package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts +264 -0
- package/dist/typechain/factories/SimpleMarketCollateral__factory.d.ts.map +1 -0
- package/dist/typechain/factories/SimpleMarketCollateral__factory.js +354 -0
- package/dist/typechain/factories/SimpleMarketCollateral__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatArchController__factory.d.ts +554 -0
- package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatArchController__factory.js +728 -0
- package/dist/typechain/factories/WildcatArchController__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts +160 -0
- package/dist/typechain/factories/WildcatCollateralFactory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatCollateralFactory__factory.js +223 -0
- package/dist/typechain/factories/WildcatCollateralFactory__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +421 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +549 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarketController__factory.d.ts +671 -0
- package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarketController__factory.js +870 -0
- package/dist/typechain/factories/WildcatMarketController__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarketV2__factory.d.ts +1304 -0
- package/dist/typechain/factories/WildcatMarketV2__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarketV2__factory.js +1680 -0
- package/dist/typechain/factories/WildcatMarketV2__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarket__factory.d.ts +1326 -0
- package/dist/typechain/factories/WildcatMarket__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarket__factory.js +1712 -0
- package/dist/typechain/factories/WildcatMarket__factory.js.map +1 -0
- package/dist/typechain/factories/index.d.ts +24 -0
- package/dist/typechain/factories/index.d.ts.map +1 -0
- package/dist/typechain/factories/index.js +53 -0
- package/dist/typechain/factories/index.js.map +1 -0
- package/dist/typechain/index.d.ts +60 -84
- package/dist/typechain/index.d.ts.map +1 -1
- package/dist/typechain/index.js +71 -120
- package/dist/typechain/index.js.map +1 -1
- package/dist/types.d.ts +34 -75
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -21
- package/dist/types.js.map +1 -1
- package/dist/utils/check-registered-borrowers.d.ts.map +1 -1
- package/dist/utils/check-registered-borrowers.js +6 -7
- package/dist/utils/check-registered-borrowers.js.map +1 -1
- package/dist/utils/describe-account.d.ts +2 -5
- package/dist/utils/describe-account.d.ts.map +1 -1
- package/dist/utils/describe-account.js +8 -38
- package/dist/utils/describe-account.js.map +1 -1
- package/dist/utils/describe-signature.d.ts +1 -1
- package/dist/utils/describe-signature.d.ts.map +1 -1
- package/dist/utils/describe-signature.js +25 -80
- package/dist/utils/describe-signature.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +1 -0
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/math.d.ts +13 -1
- package/dist/utils/math.d.ts.map +1 -1
- package/dist/utils/math.js +50 -14
- package/dist/utils/math.js.map +1 -1
- package/dist/utils/misc.d.ts +4 -5
- package/dist/utils/misc.d.ts.map +1 -1
- package/dist/utils/misc.js +6 -6
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/record-types.d.ts +10 -7
- package/dist/utils/record-types.d.ts.map +1 -1
- package/dist/utils/record-types.js +2 -2
- package/dist/utils/record-types.js.map +1 -1
- package/dist/utils/type-parsers.d.ts +3 -9
- package/dist/utils/type-parsers.d.ts.map +1 -1
- package/dist/utils/type-parsers.js +13 -12
- package/dist/utils/type-parsers.js.map +1 -1
- package/dist/withdrawal-batch.d.ts +9 -12
- package/dist/withdrawal-batch.d.ts.map +1 -1
- package/dist/withdrawal-batch.js +30 -46
- package/dist/withdrawal-batch.js.map +1 -1
- package/dist/withdrawal-status.d.ts +7 -12
- package/dist/withdrawal-status.d.ts.map +1 -1
- package/dist/withdrawal-status.js +12 -29
- package/dist/withdrawal-status.js.map +1 -1
- package/package.json +12 -20
- package/dist/abi/generated.d.ts +0 -34504
- package/dist/abi/generated.d.ts.map +0 -1
- package/dist/abi/generated.js +0 -44192
- package/dist/abi/generated.js.map +0 -1
- package/dist/abi/index.d.ts +0 -3
- package/dist/abi/index.d.ts.map +0 -1
- package/dist/abi/index.js +0 -19
- package/dist/abi/index.js.map +0 -1
- package/dist/abi/manual.d.ts +0 -354
- package/dist/abi/manual.d.ts.map +0 -1
- package/dist/abi/manual.js +0 -202
- package/dist/abi/manual.js.map +0 -1
- package/dist/access/revolving.d.ts +0 -8
- package/dist/access/revolving.d.ts.map +0 -1
- package/dist/access/revolving.js +0 -15
- package/dist/access/revolving.js.map +0 -1
- package/dist/access/subgraph-template.d.ts +0 -14
- package/dist/access/subgraph-template.d.ts.map +0 -1
- package/dist/access/subgraph-template.js +0 -20
- package/dist/access/subgraph-template.js.map +0 -1
- package/dist/client.d.ts +0 -22
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -51
- package/dist/client.js.map +0 -1
- package/dist/gql/getMarketChartsData.d.ts +0 -35
- package/dist/gql/getMarketChartsData.d.ts.map +0 -1
- package/dist/gql/getMarketChartsData.js +0 -56
- package/dist/gql/getMarketChartsData.js.map +0 -1
- package/dist/gql/getMarketList.d.ts +0 -16
- package/dist/gql/getMarketList.d.ts.map +0 -1
- package/dist/gql/getMarketList.js +0 -23
- package/dist/gql/getMarketList.js.map +0 -1
- package/dist/internal/arch-controller.d.ts +0 -6
- package/dist/internal/arch-controller.d.ts.map +0 -1
- package/dist/internal/arch-controller.js +0 -36
- package/dist/internal/arch-controller.js.map +0 -1
- package/dist/internal/ethers-signer.d.ts +0 -4
- package/dist/internal/ethers-signer.d.ts.map +0 -1
- package/dist/internal/ethers-signer.js +0 -12
- package/dist/internal/ethers-signer.js.map +0 -1
- package/dist/internal/ethers-viem.d.ts +0 -4
- package/dist/internal/ethers-viem.d.ts.map +0 -1
- package/dist/internal/ethers-viem.js +0 -43
- package/dist/internal/ethers-viem.js.map +0 -1
- package/dist/internal/market-lens.d.ts +0 -28
- package/dist/internal/market-lens.d.ts.map +0 -1
- package/dist/internal/market-lens.js +0 -125
- package/dist/internal/market-lens.js.map +0 -1
- package/dist/internal/viem-read.d.ts +0 -3
- package/dist/internal/viem-read.d.ts.map +0 -1
- package/dist/internal/viem-read.js +0 -13
- package/dist/internal/viem-read.js.map +0 -1
- package/dist/internal/viem-write.d.ts +0 -10
- package/dist/internal/viem-write.d.ts.map +0 -1
- package/dist/internal/viem-write.js +0 -51
- package/dist/internal/viem-write.js.map +0 -1
- package/dist/lens-types.d.ts +0 -309
- package/dist/lens-types.d.ts.map +0 -1
- package/dist/lens-types.js.map +0 -1
- package/dist/utils/bigint.d.ts +0 -22
- package/dist/utils/bigint.d.ts.map +0 -1
- package/dist/utils/bigint.js +0 -111
- package/dist/utils/bigint.js.map +0 -1
- package/dist/utils/viem-encoding.d.ts +0 -15
- package/dist/utils/viem-encoding.d.ts.map +0 -1
- package/dist/utils/viem-encoding.js +0 -33
- package/dist/utils/viem-encoding.js.map +0 -1
- package/dist/wrapper/index.d.ts +0 -94
- package/dist/wrapper/index.d.ts.map +0 -1
- package/dist/wrapper/index.js +0 -296
- package/dist/wrapper/index.js.map +0 -1
package/dist/market.js
CHANGED
|
@@ -1,63 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Market = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const abstract_signer_1 = require("@ethersproject/abstract-signer");
|
|
6
|
+
const typechain_1 = require("./typechain");
|
|
5
7
|
const constants_1 = require("./constants");
|
|
6
|
-
const arch_controller_1 = require("./internal/arch-controller");
|
|
7
|
-
const market_lens_1 = require("./internal/market-lens");
|
|
8
8
|
const token_1 = require("./token");
|
|
9
9
|
const types_1 = require("./types");
|
|
10
|
+
const utils_1 = require("ethers/lib/utils");
|
|
10
11
|
const account_1 = require("./account");
|
|
11
|
-
const
|
|
12
|
+
const utils_2 = require("./utils");
|
|
12
13
|
const access_1 = require("./access");
|
|
13
|
-
const abi_1 = require("./abi");
|
|
14
|
-
const viem_write_1 = require("./internal/viem-write");
|
|
15
|
-
const ethers_signer_1 = require("./internal/ethers-signer");
|
|
16
|
-
const hasUnifiedLatestLensForDirectReads = (chainId) => {
|
|
17
|
-
return (0, constants_1.hasDeploymentAddress)(chainId, "MarketLensV2_5");
|
|
18
|
-
};
|
|
19
|
-
const toUnifiedMarketDataV2 = (data) => {
|
|
20
|
-
if ("market" in data) {
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
market: data,
|
|
25
|
-
commitmentFeeBips: {
|
|
26
|
-
isPresent: false,
|
|
27
|
-
value: 0n
|
|
28
|
-
},
|
|
29
|
-
drawnAmount: {
|
|
30
|
-
isPresent: false,
|
|
31
|
-
value: 0n
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const hasSubgraphMarketTotals = (data) => "totalBorrowed" in data;
|
|
36
|
-
const hasSubgraphMarketRecords = (data) => "depositRecords" in data;
|
|
37
14
|
class Market extends types_1.ContractWrapper {
|
|
15
|
+
get _contractAddress() {
|
|
16
|
+
return this.address;
|
|
17
|
+
}
|
|
38
18
|
constructor({ provider, ...args }) {
|
|
39
19
|
super(provider);
|
|
20
|
+
this.contractFactory = typechain_1.WildcatMarket__factory;
|
|
40
21
|
const { address, name, symbol, decimals } = args.marketToken;
|
|
41
22
|
Object.assign(this, {
|
|
42
23
|
address,
|
|
43
24
|
name,
|
|
44
25
|
symbol,
|
|
45
|
-
decimals
|
|
46
|
-
contract: {
|
|
47
|
-
address,
|
|
48
|
-
interface: {
|
|
49
|
-
encodeFunctionData: (functionName, args = []) => (0, viem_1.encodeFunctionData)({
|
|
50
|
-
abi: abi_1.wildcatMarketAbi,
|
|
51
|
-
functionName,
|
|
52
|
-
args
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
}
|
|
26
|
+
decimals
|
|
56
27
|
});
|
|
57
28
|
Object.assign(this, args);
|
|
58
|
-
this.depositRecords = (args.depositRecords ?? []).map((log) => (0,
|
|
59
|
-
this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0,
|
|
60
|
-
this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0,
|
|
29
|
+
this.depositRecords = (args.depositRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
|
|
30
|
+
this.repaymentRecords = (args.repaymentRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
|
|
31
|
+
this.borrowRecords = (args.borrowRecords ?? []).map((log) => (0, utils_2.parseMarketRecord)(this.underlyingToken, log));
|
|
61
32
|
this.feeCollectionRecords = (args.feeCollectionRecords ?? []).map(({ feesCollected, __typename, ...rest }) => ({
|
|
62
33
|
...rest,
|
|
63
34
|
__typename: "FeesCollected",
|
|
@@ -79,86 +50,47 @@ class Market extends types_1.ContractWrapper {
|
|
|
79
50
|
const fixedTermEndTime = config.fixedTermEndTime;
|
|
80
51
|
return fixedTermEndTime >= Date.now() / 1000;
|
|
81
52
|
}
|
|
53
|
+
get isPeriodicWithdrawalWindowOpen() {
|
|
54
|
+
if (this.version !== types_1.MarketVersion.V2)
|
|
55
|
+
return false;
|
|
56
|
+
const config = this.hooksConfig;
|
|
57
|
+
if (!config || config.kind !== types_1.HooksKind.PeriodicTerm)
|
|
58
|
+
return false;
|
|
59
|
+
if (this.isClosed || config.periodicTermClosed)
|
|
60
|
+
return true;
|
|
61
|
+
if (config.periodDuration === 0)
|
|
62
|
+
return false;
|
|
63
|
+
const now = Math.floor(Date.now() / 1000);
|
|
64
|
+
if (now < config.firstWithdrawalWindowStart)
|
|
65
|
+
return false;
|
|
66
|
+
return ((now - config.firstWithdrawalWindowStart) % config.periodDuration <
|
|
67
|
+
config.withdrawalWindowDuration);
|
|
68
|
+
}
|
|
69
|
+
get currentOrNextPeriodicWithdrawalWindowStart() {
|
|
70
|
+
if (this.version !== types_1.MarketVersion.V2)
|
|
71
|
+
return undefined;
|
|
72
|
+
const config = this.hooksConfig;
|
|
73
|
+
if (!config || config.kind !== types_1.HooksKind.PeriodicTerm || config.periodDuration === 0) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const now = Math.floor(Date.now() / 1000);
|
|
77
|
+
if (now < config.firstWithdrawalWindowStart)
|
|
78
|
+
return config.firstWithdrawalWindowStart;
|
|
79
|
+
const timeInPeriod = (now - config.firstWithdrawalWindowStart) % config.periodDuration;
|
|
80
|
+
const windowStart = now - timeInPeriod;
|
|
81
|
+
return timeInPeriod < config.withdrawalWindowDuration
|
|
82
|
+
? windowStart
|
|
83
|
+
: windowStart + config.periodDuration;
|
|
84
|
+
}
|
|
82
85
|
/** @returns Percentage growth of the market since it was created */
|
|
83
86
|
get allTimeGrowth() {
|
|
84
87
|
// 27 - 2 to convert to percentage
|
|
85
|
-
return +(0, utils_1.
|
|
88
|
+
return +(0, utils_1.formatUnits)(this.scaleFactor, 25);
|
|
86
89
|
}
|
|
87
90
|
/** @returns Maximum amount of underlying token that can be deposited */
|
|
88
91
|
get maximumDeposit() {
|
|
89
92
|
return this.underlyingToken.getAmount(this.maxTotalSupply.satsub(this.totalSupply.raw));
|
|
90
93
|
}
|
|
91
|
-
get currentRevolvingAprMetrics() {
|
|
92
|
-
const commitmentFeeBips = this.commitmentFeeBips;
|
|
93
|
-
const drawnAmount = this.drawnAmount;
|
|
94
|
-
if (commitmentFeeBips == null || drawnAmount == null) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
const totalSupply = this.totalSupply.raw;
|
|
98
|
-
const drawnAmountRaw = drawnAmount.raw > totalSupply ? totalSupply : drawnAmount.raw;
|
|
99
|
-
const utilizationBips = totalSupply > 0n ? Number((drawnAmountRaw * utils_1.BIP_BIGINT) / totalSupply) : 0;
|
|
100
|
-
const utilizationAprBips = totalSupply > 0n
|
|
101
|
-
? Number((drawnAmountRaw * BigInt(this.annualInterestBips)) / totalSupply)
|
|
102
|
-
: 0;
|
|
103
|
-
const blendedBaseAprBips = commitmentFeeBips + utilizationAprBips;
|
|
104
|
-
const protocolAprBips = Number((BigInt(blendedBaseAprBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
|
|
105
|
-
const penaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
|
|
106
|
-
return {
|
|
107
|
-
commitmentFeeBips,
|
|
108
|
-
drawnAmount,
|
|
109
|
-
utilizationBips,
|
|
110
|
-
utilizationAprBips,
|
|
111
|
-
blendedBaseAprBips,
|
|
112
|
-
protocolAprBips,
|
|
113
|
-
penaltyAprBips,
|
|
114
|
-
effectiveLenderAprBips: blendedBaseAprBips + penaltyAprBips
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
get currentBaseLenderAprBips() {
|
|
118
|
-
return this.currentRevolvingAprMetrics?.blendedBaseAprBips ?? this.annualInterestBips;
|
|
119
|
-
}
|
|
120
|
-
get currentAprDisplayBips() {
|
|
121
|
-
const revolvingMetrics = this.currentRevolvingAprMetrics;
|
|
122
|
-
if (revolvingMetrics) {
|
|
123
|
-
return {
|
|
124
|
-
isRevolving: true,
|
|
125
|
-
marketType: this.marketType,
|
|
126
|
-
configuredAprKind: "utilization",
|
|
127
|
-
configuredAprBips: this.annualInterestBips,
|
|
128
|
-
configuredAnnualInterestBips: this.annualInterestBips,
|
|
129
|
-
configuredUtilizationAprBips: this.annualInterestBips,
|
|
130
|
-
commitmentAprBips: revolvingMetrics.commitmentFeeBips,
|
|
131
|
-
utilizationBips: revolvingMetrics.utilizationBips,
|
|
132
|
-
currentUtilizationAprBips: revolvingMetrics.utilizationAprBips,
|
|
133
|
-
currentBaseLenderAprBips: revolvingMetrics.blendedBaseAprBips,
|
|
134
|
-
currentProtocolAprBips: revolvingMetrics.protocolAprBips,
|
|
135
|
-
currentPenaltyAprBips: revolvingMetrics.penaltyAprBips,
|
|
136
|
-
currentEffectiveLenderAprBips: revolvingMetrics.effectiveLenderAprBips
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
const currentProtocolAprBips = Number((BigInt(this.annualInterestBips) * BigInt(this.protocolFeeBips)) / utils_1.BIP_BIGINT);
|
|
140
|
-
const currentPenaltyAprBips = this.isIncurringPenalties ? this.delinquencyFeeBips : 0;
|
|
141
|
-
return {
|
|
142
|
-
isRevolving: false,
|
|
143
|
-
marketType: this.marketType,
|
|
144
|
-
configuredAprKind: "annualInterest",
|
|
145
|
-
configuredAprBips: this.annualInterestBips,
|
|
146
|
-
configuredAnnualInterestBips: this.annualInterestBips,
|
|
147
|
-
currentBaseLenderAprBips: this.annualInterestBips,
|
|
148
|
-
currentProtocolAprBips,
|
|
149
|
-
currentPenaltyAprBips,
|
|
150
|
-
currentEffectiveLenderAprBips: this.annualInterestBips + currentPenaltyAprBips
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
get currentBaseLenderAPR() {
|
|
154
|
-
return (0, utils_1.bipToRayBigint)(this.currentBaseLenderAprBips);
|
|
155
|
-
}
|
|
156
|
-
get currentPenaltyAPR() {
|
|
157
|
-
return this.isIncurringPenalties ? (0, utils_1.bipToRayBigint)(this.delinquencyFeeBips) : 0n;
|
|
158
|
-
}
|
|
159
|
-
get currentProtocolAPR() {
|
|
160
|
-
return (0, utils_1.bipMulBigint)(this.currentBaseLenderAPR, this.protocolFeeBips);
|
|
161
|
-
}
|
|
162
94
|
/** @returns Whether the borrower is in penalized delinquency */
|
|
163
95
|
get isIncurringPenalties() {
|
|
164
96
|
return this.timeDelinquent > this.delinquencyGracePeriod;
|
|
@@ -204,7 +136,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
204
136
|
const targetRatio = this.reserveRatioBips / 100;
|
|
205
137
|
const actualRatio = this.totalSupply.eq(0)
|
|
206
138
|
? 100
|
|
207
|
-
: +(0, utils_1.
|
|
139
|
+
: +(0, utils_1.formatUnits)(this.totalAssets.raw.mul(utils_2.RAY).div(this.totalSupply.raw), 25);
|
|
208
140
|
if (this.temporaryReserveRatio) {
|
|
209
141
|
return {
|
|
210
142
|
targetRatio,
|
|
@@ -217,7 +149,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
217
149
|
return { targetRatio, actualRatio };
|
|
218
150
|
}
|
|
219
151
|
get normalizedPendingWithdrawals() {
|
|
220
|
-
return this.underlyingToken.getAmount((0,
|
|
152
|
+
return this.underlyingToken.getAmount((0, utils_2.rayMul)(this.scaledPendingWithdrawals, this.scaleFactor));
|
|
221
153
|
}
|
|
222
154
|
/** @returns Whether the borrower can change the APR */
|
|
223
155
|
get canReduceAPR() {
|
|
@@ -233,7 +165,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
233
165
|
return this.totalAssets.satsub(unavailableAssets);
|
|
234
166
|
}
|
|
235
167
|
get minimumReserves() {
|
|
236
|
-
return this.
|
|
168
|
+
return this.underlyingToken.getAmount((0, utils_2.bipMul)(this.outstandingTotalSupply.raw, ethers_1.BigNumber.from(this.reserveRatioBips)));
|
|
237
169
|
}
|
|
238
170
|
get borrowableAssets() {
|
|
239
171
|
return this.totalAssets.satsub(this.coverageLiquidity);
|
|
@@ -271,59 +203,63 @@ class Market extends types_1.ContractWrapper {
|
|
|
271
203
|
};
|
|
272
204
|
}
|
|
273
205
|
normalizeAmount(amount) {
|
|
274
|
-
return (0,
|
|
206
|
+
return (0, utils_2.rayMul)(amount, this.scaleFactor);
|
|
275
207
|
}
|
|
276
208
|
scaleAmount(amount) {
|
|
277
|
-
return (0,
|
|
209
|
+
return (0, utils_2.rayDiv)(amount, this.scaleFactor);
|
|
278
210
|
}
|
|
279
211
|
get secondsBeforeDelinquency() {
|
|
280
212
|
if (this.willBeDelinquent || this.totalDebts.eq(0))
|
|
281
213
|
return 0;
|
|
282
214
|
const scaledBase = this.scaledTotalSupply;
|
|
283
|
-
const basePrincipal = this.underlyingToken.getAmount((0,
|
|
284
|
-
const baseAPRRay = this.
|
|
285
|
-
const protocolFeeAPRRay = this.
|
|
286
|
-
const delinquencyFeeAPRRay = this.
|
|
215
|
+
const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
|
|
216
|
+
const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
|
|
217
|
+
const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
|
|
218
|
+
const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
|
|
219
|
+
? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
|
|
220
|
+
: ethers_1.BigNumber.from(0);
|
|
287
221
|
// lender APR portion
|
|
288
222
|
const lenderRequirementGrowthPerSecond = basePrincipal
|
|
289
|
-
.rayMul(baseAPRRay
|
|
290
|
-
.div(
|
|
223
|
+
.rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
|
|
224
|
+
.div(utils_2.SECONDS_IN_365_DAYS)
|
|
291
225
|
.bipMul(this.reserveRatioBips);
|
|
292
226
|
// protocol fee portion
|
|
293
227
|
const protocolRequirementGrowthPerSecond = basePrincipal
|
|
294
228
|
.rayMul(protocolFeeAPRRay)
|
|
295
|
-
.div(
|
|
229
|
+
.div(utils_2.SECONDS_IN_365_DAYS);
|
|
296
230
|
const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
|
|
297
231
|
// essentially if apr=0 and rr=0 then bips alone wont move us to delinquency
|
|
298
|
-
if (totalRequirementGrowthPerSecond.raw
|
|
232
|
+
if (totalRequirementGrowthPerSecond.raw.isZero())
|
|
299
233
|
return Number.MAX_SAFE_INTEGER;
|
|
300
234
|
const buffer = this.liquidReserves.sub(this.minimumReserves);
|
|
301
|
-
if (buffer.raw
|
|
235
|
+
if (buffer.raw.lte(0))
|
|
302
236
|
return 0; // we are delinquent
|
|
303
|
-
return
|
|
237
|
+
return buffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber(); // seconds until the party
|
|
304
238
|
}
|
|
305
239
|
getSecondsBeforeDelinquencyForBorrowedAmount(borrowAmount) {
|
|
306
240
|
if (this.isDelinquent || this.totalDebts.eq(0))
|
|
307
241
|
return 0;
|
|
308
242
|
const scaledBase = this.scaledTotalSupply;
|
|
309
|
-
const basePrincipal = this.underlyingToken.getAmount((0,
|
|
310
|
-
const baseAPRRay = this.
|
|
311
|
-
const protocolFeeAPRRay = this.
|
|
312
|
-
const delinquencyFeeAPRRay = this.
|
|
243
|
+
const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
|
|
244
|
+
const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
|
|
245
|
+
const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
|
|
246
|
+
const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
|
|
247
|
+
? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
|
|
248
|
+
: ethers_1.BigNumber.from(0);
|
|
313
249
|
const lenderRequirementGrowthPerSecond = basePrincipal
|
|
314
|
-
.rayMul(baseAPRRay
|
|
315
|
-
.div(
|
|
250
|
+
.rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
|
|
251
|
+
.div(utils_2.SECONDS_IN_365_DAYS)
|
|
316
252
|
.bipMul(this.reserveRatioBips);
|
|
317
253
|
const protocolRequirementGrowthPerSecond = basePrincipal
|
|
318
254
|
.rayMul(protocolFeeAPRRay)
|
|
319
|
-
.div(
|
|
255
|
+
.div(utils_2.SECONDS_IN_365_DAYS);
|
|
320
256
|
const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
|
|
321
|
-
if (totalRequirementGrowthPerSecond.raw
|
|
257
|
+
if (totalRequirementGrowthPerSecond.raw.isZero())
|
|
322
258
|
return Number.MAX_SAFE_INTEGER;
|
|
323
259
|
const postBorrowBuffer = this.liquidReserves.sub(this.minimumReserves).sub(borrowAmount);
|
|
324
|
-
if (postBorrowBuffer.raw
|
|
260
|
+
if (postBorrowBuffer.raw.lte(0))
|
|
325
261
|
return 0;
|
|
326
|
-
return
|
|
262
|
+
return postBorrowBuffer.div(totalRequirementGrowthPerSecond, true).raw.toNumber();
|
|
327
263
|
}
|
|
328
264
|
/**
|
|
329
265
|
* @dev Calculate token amount to be repayed by borrower for a given duration
|
|
@@ -331,20 +267,22 @@ class Market extends types_1.ContractWrapper {
|
|
|
331
267
|
* @return token amount to be repayed
|
|
332
268
|
**/
|
|
333
269
|
repayRequiredForDuration(timeToPayInSeconds) {
|
|
334
|
-
const scaledBase = this.scaledTotalSupply
|
|
335
|
-
if (scaledBase
|
|
270
|
+
const scaledBase = this.scaledTotalSupply.sub(this.scaledPendingWithdrawals);
|
|
271
|
+
if (scaledBase.lte(0))
|
|
336
272
|
return this.underlyingToken.getAmount(0);
|
|
337
|
-
const basePrincipal = this.underlyingToken.getAmount((0,
|
|
338
|
-
const baseAPRRay = this.
|
|
339
|
-
const protocolFeeAPRRay = this.
|
|
340
|
-
const delinquencyFeeAPRRay = this.
|
|
273
|
+
const basePrincipal = this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledBase, this.scaleFactor));
|
|
274
|
+
const baseAPRRay = (0, utils_2.bipToRay)(this.annualInterestBips);
|
|
275
|
+
const protocolFeeAPRRay = (0, utils_2.bipMul)(baseAPRRay, ethers_1.BigNumber.from(this.protocolFeeBips));
|
|
276
|
+
const delinquencyFeeAPRRay = this.timeDelinquent > this.delinquencyGracePeriod
|
|
277
|
+
? (0, utils_2.bipToRay)(this.delinquencyFeeBips)
|
|
278
|
+
: ethers_1.BigNumber.from(0);
|
|
341
279
|
const lenderRequirementGrowthPerSecond = basePrincipal
|
|
342
|
-
.rayMul(baseAPRRay
|
|
343
|
-
.div(
|
|
280
|
+
.rayMul(baseAPRRay.add(delinquencyFeeAPRRay))
|
|
281
|
+
.div(utils_2.SECONDS_IN_365_DAYS)
|
|
344
282
|
.bipMul(this.reserveRatioBips);
|
|
345
283
|
const protocolRequirementGrowthPerSecond = basePrincipal
|
|
346
284
|
.rayMul(protocolFeeAPRRay)
|
|
347
|
-
.div(
|
|
285
|
+
.div(utils_2.SECONDS_IN_365_DAYS);
|
|
348
286
|
const totalRequirementGrowthPerSecond = lenderRequirementGrowthPerSecond.add(protocolRequirementGrowthPerSecond.raw);
|
|
349
287
|
return totalRequirementGrowthPerSecond.mul(timeToPayInSeconds);
|
|
350
288
|
}
|
|
@@ -355,12 +293,13 @@ class Market extends types_1.ContractWrapper {
|
|
|
355
293
|
*
|
|
356
294
|
* @return apr paid by borrower in ray
|
|
357
295
|
*/
|
|
358
|
-
// Preserve ethers-era consumers whose formatting helpers typed APR rays as BigNumber.
|
|
359
|
-
// Runtime remains bigint, with BigInt compatibility methods installed by token.ts.
|
|
360
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
361
296
|
get effectiveBorrowerAPR() {
|
|
362
|
-
|
|
363
|
-
|
|
297
|
+
// apr + (apr * protocolFee)
|
|
298
|
+
let apr = (0, utils_2.bipMul)((0, utils_2.bipToRay)(this.annualInterestBips), utils_2.BIP.add(this.protocolFeeBips));
|
|
299
|
+
if (this.timeDelinquent > this.delinquencyGracePeriod) {
|
|
300
|
+
apr = apr.add((0, utils_2.bipToRay)(this.delinquencyFeeBips));
|
|
301
|
+
}
|
|
302
|
+
return apr;
|
|
364
303
|
}
|
|
365
304
|
/**
|
|
366
305
|
* @dev Calculate effective interest rate currently earned by lenders.
|
|
@@ -368,41 +307,36 @@ class Market extends types_1.ContractWrapper {
|
|
|
368
307
|
*
|
|
369
308
|
* @return apr earned by lender in ray
|
|
370
309
|
*/
|
|
371
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
372
310
|
get effectiveLenderAPR() {
|
|
373
|
-
|
|
311
|
+
let apr = this.annualInterestBips;
|
|
312
|
+
if (this.timeDelinquent > this.delinquencyGracePeriod) {
|
|
313
|
+
apr += this.delinquencyFeeBips;
|
|
314
|
+
}
|
|
315
|
+
return (0, utils_2.bipToRay)(apr);
|
|
374
316
|
}
|
|
375
317
|
/* -------------------------------------------------------------------------- */
|
|
376
318
|
/* Withdrawal Execution */
|
|
377
319
|
/* -------------------------------------------------------------------------- */
|
|
378
320
|
async executeWithdrawal({ lender, expiry }) {
|
|
379
|
-
return
|
|
380
|
-
to: this.address,
|
|
381
|
-
abi: abi_1.wildcatMarketAbi,
|
|
382
|
-
functionName: "executeWithdrawal",
|
|
383
|
-
args: [lender, expiry]
|
|
384
|
-
}));
|
|
321
|
+
return this.contract.executeWithdrawal(lender, expiry);
|
|
385
322
|
}
|
|
386
323
|
async executeWithdrawals(withdrawals) {
|
|
387
324
|
const lenders = withdrawals.map((w) => w.lender);
|
|
388
325
|
const expiries = withdrawals.map((w) => w.expiry);
|
|
389
|
-
return
|
|
390
|
-
to: this.address,
|
|
391
|
-
abi: abi_1.wildcatMarketAbi,
|
|
392
|
-
functionName: "executeWithdrawals",
|
|
393
|
-
args: [lenders, expiries]
|
|
394
|
-
}));
|
|
326
|
+
return this.contract.executeWithdrawals(lenders, expiries);
|
|
395
327
|
}
|
|
396
328
|
populateRepayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
|
|
397
|
-
return
|
|
329
|
+
return {
|
|
398
330
|
to: this.address,
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
331
|
+
data: this.contract.interface.encodeFunctionData("repayAndProcessUnpaidWithdrawalBatches", [
|
|
332
|
+
amount.raw,
|
|
333
|
+
maxBatches
|
|
334
|
+
]),
|
|
335
|
+
value: "0"
|
|
336
|
+
};
|
|
403
337
|
}
|
|
404
338
|
async repayAndProcessUnpaidWithdrawalBatches(amount, maxBatches = 10) {
|
|
405
|
-
return
|
|
339
|
+
return this.contract.repayAndProcessUnpaidWithdrawalBatches(amount.raw, maxBatches);
|
|
406
340
|
}
|
|
407
341
|
/* -------------------------------------------------------------------------- */
|
|
408
342
|
/* Set APR */
|
|
@@ -418,8 +352,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
418
352
|
if (annualInterestBips < originalAnnualInterestBips) {
|
|
419
353
|
let doubleRelativeDiff;
|
|
420
354
|
if (this.version === types_1.MarketVersion.V2) {
|
|
421
|
-
const relativeDiff =
|
|
422
|
-
BigInt(originalAnnualInterestBips));
|
|
355
|
+
const relativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(10000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
|
|
423
356
|
if (relativeDiff <= 2500) {
|
|
424
357
|
// In v2, if the relative diff is 25% or less, the reserve ratio is not changed
|
|
425
358
|
return originalReserveRatioBips;
|
|
@@ -427,8 +360,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
427
360
|
doubleRelativeDiff = 2 * relativeDiff;
|
|
428
361
|
}
|
|
429
362
|
else {
|
|
430
|
-
doubleRelativeDiff =
|
|
431
|
-
BigInt(originalAnnualInterestBips));
|
|
363
|
+
doubleRelativeDiff = (0, utils_2.mulDiv)((0, token_1.toBn)(20000), (0, token_1.toBn)(originalAnnualInterestBips - annualInterestBips), (0, token_1.toBn)(originalAnnualInterestBips)).toNumber();
|
|
432
364
|
}
|
|
433
365
|
const boundRelativeDiff = Math.min(10000, doubleRelativeDiff);
|
|
434
366
|
return Math.max(boundRelativeDiff, originalReserveRatioBips);
|
|
@@ -440,11 +372,10 @@ class Market extends types_1.ContractWrapper {
|
|
|
440
372
|
return originalReserveRatioBips;
|
|
441
373
|
}
|
|
442
374
|
calculateLiquidityCoverageForReserveRatio(reserveRatio) {
|
|
443
|
-
const scaledRequiredReserves = (0,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
this.
|
|
447
|
-
this.normalizedUnclaimedWithdrawals.raw);
|
|
375
|
+
const scaledRequiredReserves = (0, utils_2.bipMul)(this.scaledTotalSupply.sub(this.scaledPendingWithdrawals), (0, token_1.toBn)(reserveRatio)).add(this.scaledPendingWithdrawals);
|
|
376
|
+
return this.underlyingToken.getAmount((0, utils_2.rayMul)(scaledRequiredReserves, this.scaleFactor)
|
|
377
|
+
.add(this.lastAccruedProtocolFees.raw)
|
|
378
|
+
.add(this.normalizedUnclaimedWithdrawals.raw));
|
|
448
379
|
}
|
|
449
380
|
canChangeAPR(annualInterestBips) {
|
|
450
381
|
const originalAnnualInterestBips = this.temporaryReserveRatio
|
|
@@ -474,186 +405,89 @@ class Market extends types_1.ContractWrapper {
|
|
|
474
405
|
/* Updates */
|
|
475
406
|
/* -------------------------------------------------------------------------- */
|
|
476
407
|
async update() {
|
|
477
|
-
|
|
478
|
-
if (hasUnifiedLatestLensForDirectReads(this.chainId)) {
|
|
479
|
-
try {
|
|
480
|
-
const market = await (0, market_lens_1.getUnifiedMarketDataV2)(this.chainId, this.provider, this.address);
|
|
481
|
-
this.updateWith(market);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
catch (_) {
|
|
485
|
-
// Fall back to the pre-2.5 V2 lens until unified lens deployment is reliable.
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
const market = await (0, market_lens_1.getV2MarketData)(this.chainId, this.provider, this.address);
|
|
489
|
-
this.updateWith(market);
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
const market = await (0, market_lens_1.getLegacyMarketData)(this.chainId, this.provider, this.address);
|
|
408
|
+
const market = await (0, constants_1.getLensContract)(this.chainId, this.provider).getMarketData(this.address);
|
|
493
409
|
this.updateWith(market);
|
|
494
410
|
}
|
|
495
411
|
updateWith(data) {
|
|
496
|
-
const baseData = "market" in data ? data.market : data;
|
|
497
|
-
const nextScaleFactor = (0, token_1.toRawAmount)(baseData.scaleFactor);
|
|
498
|
-
const nextScaledTotalSupply = (0, token_1.toRawAmount)(baseData.scaledTotalSupply);
|
|
499
|
-
const nextScaledPendingWithdrawals = (0, token_1.toRawAmount)(baseData.scaledPendingWithdrawals);
|
|
500
|
-
const nextLastAccruedProtocolFees = (0, token_1.toRawAmount)(baseData.lastAccruedProtocolFees);
|
|
501
412
|
// Note: this adds all the interest accrued to the base interest accrued, since the lens
|
|
502
413
|
// doesn't give us any way to distinguish between base interest and delinquency fees.
|
|
503
|
-
if (this.scaledTotalSupply
|
|
504
|
-
|
|
414
|
+
if (this.scaledTotalSupply.eq(data.scaledTotalSupply) &&
|
|
415
|
+
data.scaleFactor.gt(this.scaleFactor) &&
|
|
505
416
|
this.totalBaseInterestAccrued) {
|
|
506
|
-
const lastTotalValue = (0,
|
|
507
|
-
const currentTotalValue = (0,
|
|
508
|
-
const baseInterestAccrued = currentTotalValue
|
|
417
|
+
const lastTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, this.scaleFactor);
|
|
418
|
+
const currentTotalValue = (0, utils_2.rayMul)(this.scaledTotalSupply, data.scaleFactor);
|
|
419
|
+
const baseInterestAccrued = currentTotalValue.sub(lastTotalValue);
|
|
509
420
|
this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(baseInterestAccrued);
|
|
510
421
|
}
|
|
511
|
-
if (
|
|
512
|
-
this.totalProtocolFeesAccrued) {
|
|
513
|
-
this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(nextLastAccruedProtocolFees - this.lastAccruedProtocolFees.raw);
|
|
514
|
-
}
|
|
515
|
-
this.feeRecipient = baseData.feeRecipient;
|
|
516
|
-
this.protocolFeeBips = (0, utils_1.toNumber)(baseData.protocolFeeBips);
|
|
517
|
-
this.delinquencyFeeBips = (0, utils_1.toNumber)(baseData.delinquencyFeeBips);
|
|
518
|
-
this.delinquencyGracePeriod = (0, utils_1.toNumber)(baseData.delinquencyGracePeriod);
|
|
519
|
-
this.withdrawalBatchDuration = (0, utils_1.toNumber)(baseData.withdrawalBatchDuration);
|
|
520
|
-
this.reserveRatioBips = (0, utils_1.toNumber)(baseData.reserveRatioBips);
|
|
521
|
-
this.annualInterestBips = (0, utils_1.toNumber)(baseData.annualInterestBips);
|
|
522
|
-
this.temporaryReserveRatio = baseData.temporaryReserveRatio;
|
|
523
|
-
this.originalAnnualInterestBips = (0, utils_1.toNumber)(baseData.originalAnnualInterestBips);
|
|
524
|
-
this.originalReserveRatioBips = (0, utils_1.toNumber)(baseData.originalReserveRatioBips);
|
|
525
|
-
this.temporaryReserveRatioExpiry = (0, utils_1.toNumber)(baseData.temporaryReserveRatioExpiry);
|
|
526
|
-
this.isClosed = baseData.isClosed;
|
|
527
|
-
this.scaleFactor = nextScaleFactor;
|
|
528
|
-
this.totalSupply = this.marketToken.getAmount(baseData.totalSupply);
|
|
529
|
-
this.maxTotalSupply = this.marketToken.getAmount(baseData.maxTotalSupply);
|
|
530
|
-
this.scaledTotalSupply = nextScaledTotalSupply;
|
|
531
|
-
this.totalAssets = this.underlyingToken.getAmount(baseData.totalAssets);
|
|
532
|
-
this.lastAccruedProtocolFees = this.underlyingToken.getAmount(baseData.lastAccruedProtocolFees);
|
|
533
|
-
this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(baseData.normalizedUnclaimedWithdrawals);
|
|
534
|
-
this.scaledPendingWithdrawals = nextScaledPendingWithdrawals;
|
|
535
|
-
this.pendingWithdrawalExpiry = (0, utils_1.toNumber)(baseData.pendingWithdrawalExpiry);
|
|
536
|
-
this.isDelinquent = baseData.isDelinquent;
|
|
537
|
-
this.timeDelinquent = (0, utils_1.toNumber)(baseData.timeDelinquent);
|
|
538
|
-
this.lastInterestAccruedTimestamp = (0, utils_1.toNumber)(baseData.lastInterestAccruedTimestamp);
|
|
539
|
-
this.unpaidWithdrawalBatchExpiries = baseData.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber);
|
|
540
|
-
this.coverageLiquidity = this.underlyingToken.getAmount(baseData.coverageLiquidity);
|
|
541
|
-
if ("hooksFactory" in baseData) {
|
|
542
|
-
this.hooksFactory = baseData.hooksFactory;
|
|
543
|
-
this.marketType = (0, constants_1.getMarketTypeForHooksFactory)(this.chainId, baseData.hooksFactory);
|
|
544
|
-
}
|
|
545
|
-
if ("hooksConfig" in baseData) {
|
|
546
|
-
(0, utils_1.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
|
|
547
|
-
const config = this.hooksConfig;
|
|
548
|
-
(0, utils_1.assert)(config !== undefined, `V2 market has no hooksConfig!`);
|
|
549
|
-
config.minimumDeposit = this.underlyingToken.getAmount(baseData.hooksConfig.minimumDeposit);
|
|
550
|
-
if (config.kind === types_1.HooksKind.FixedTerm) {
|
|
551
|
-
config.fixedTermEndTime = (0, utils_1.toNumber)(baseData.hooksConfig.fixedTermEndTime);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
(0, utils_1.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
|
|
556
|
-
}
|
|
557
|
-
if ("market" in data) {
|
|
558
|
-
this.commitmentFeeBips = data.commitmentFeeBips.isPresent
|
|
559
|
-
? (0, utils_1.toNumber)(data.commitmentFeeBips.value)
|
|
560
|
-
: undefined;
|
|
561
|
-
this.drawnAmount = data.drawnAmount.isPresent
|
|
562
|
-
? this.underlyingToken.getAmount(data.drawnAmount.value)
|
|
563
|
-
: undefined;
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
this.commitmentFeeBips = undefined;
|
|
567
|
-
this.drawnAmount = undefined;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
updateWithLiveData(data) {
|
|
571
|
-
(0, utils_1.assert)(data.market.toLowerCase() === this.address.toLowerCase(), `Live market data address mismatch`);
|
|
572
|
-
const nextScaleFactor = (0, token_1.toRawAmount)(data.scaleFactor);
|
|
573
|
-
const nextScaledTotalSupply = (0, token_1.toRawAmount)(data.scaledTotalSupply);
|
|
574
|
-
const nextScaledPendingWithdrawals = (0, token_1.toRawAmount)(data.scaledPendingWithdrawals);
|
|
575
|
-
const nextLastAccruedProtocolFees = (0, token_1.toRawAmount)(data.lastAccruedProtocolFees);
|
|
576
|
-
if (this.scaledTotalSupply === nextScaledTotalSupply &&
|
|
577
|
-
nextScaleFactor > this.scaleFactor &&
|
|
578
|
-
this.totalBaseInterestAccrued) {
|
|
579
|
-
const lastTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, this.scaleFactor);
|
|
580
|
-
const currentTotalValue = (0, utils_1.rayMulBigint)(this.scaledTotalSupply, nextScaleFactor);
|
|
581
|
-
this.totalBaseInterestAccrued = this.totalBaseInterestAccrued.add(currentTotalValue - lastTotalValue);
|
|
582
|
-
}
|
|
583
|
-
if (nextLastAccruedProtocolFees > this.lastAccruedProtocolFees.raw &&
|
|
422
|
+
if (data.lastAccruedProtocolFees.gt(this.lastAccruedProtocolFees.raw) &&
|
|
584
423
|
this.totalProtocolFeesAccrued) {
|
|
585
|
-
this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(
|
|
586
|
-
}
|
|
587
|
-
this.
|
|
588
|
-
this.
|
|
589
|
-
this.
|
|
424
|
+
this.totalProtocolFeesAccrued = this.totalProtocolFeesAccrued.add(data.lastAccruedProtocolFees.sub(this.lastAccruedProtocolFees.raw));
|
|
425
|
+
}
|
|
426
|
+
this.feeRecipient = data.feeRecipient;
|
|
427
|
+
this.protocolFeeBips = data.protocolFeeBips.toNumber();
|
|
428
|
+
this.delinquencyFeeBips = data.delinquencyFeeBips.toNumber();
|
|
429
|
+
this.delinquencyGracePeriod = data.delinquencyGracePeriod.toNumber();
|
|
430
|
+
this.withdrawalBatchDuration = data.withdrawalBatchDuration.toNumber();
|
|
431
|
+
this.reserveRatioBips = data.reserveRatioBips.toNumber();
|
|
432
|
+
this.annualInterestBips = data.annualInterestBips.toNumber();
|
|
433
|
+
this.temporaryReserveRatio = data.temporaryReserveRatio;
|
|
434
|
+
this.originalAnnualInterestBips = data.originalAnnualInterestBips.toNumber();
|
|
435
|
+
this.originalReserveRatioBips = data.originalReserveRatioBips.toNumber();
|
|
436
|
+
this.temporaryReserveRatioExpiry = data.temporaryReserveRatioExpiry.toNumber();
|
|
590
437
|
this.isClosed = data.isClosed;
|
|
591
|
-
this.scaleFactor =
|
|
438
|
+
this.scaleFactor = data.scaleFactor;
|
|
592
439
|
this.totalSupply = this.marketToken.getAmount(data.totalSupply);
|
|
593
440
|
this.maxTotalSupply = this.marketToken.getAmount(data.maxTotalSupply);
|
|
594
|
-
this.scaledTotalSupply =
|
|
441
|
+
this.scaledTotalSupply = data.scaledTotalSupply;
|
|
595
442
|
this.totalAssets = this.underlyingToken.getAmount(data.totalAssets);
|
|
596
443
|
this.lastAccruedProtocolFees = this.underlyingToken.getAmount(data.lastAccruedProtocolFees);
|
|
597
444
|
this.normalizedUnclaimedWithdrawals = this.underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals);
|
|
598
|
-
this.scaledPendingWithdrawals =
|
|
599
|
-
this.pendingWithdrawalExpiry =
|
|
445
|
+
this.scaledPendingWithdrawals = data.scaledPendingWithdrawals;
|
|
446
|
+
this.pendingWithdrawalExpiry = data.pendingWithdrawalExpiry.toNumber();
|
|
600
447
|
this.isDelinquent = data.isDelinquent;
|
|
601
|
-
this.timeDelinquent =
|
|
602
|
-
this.lastInterestAccruedTimestamp =
|
|
448
|
+
this.timeDelinquent = data.timeDelinquent.toNumber();
|
|
449
|
+
this.lastInterestAccruedTimestamp = data.lastInterestAccruedTimestamp.toNumber();
|
|
450
|
+
this.unpaidWithdrawalBatchExpiries = data.unpaidWithdrawalBatchExpiries;
|
|
603
451
|
this.coverageLiquidity = this.underlyingToken.getAmount(data.coverageLiquidity);
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
452
|
+
if ("hooksConfig" in data) {
|
|
453
|
+
(0, utils_2.assert)(this.version === types_1.MarketVersion.V2, `Can not push V2 lens data to V1 market!`);
|
|
454
|
+
const config = this.hooksConfig;
|
|
455
|
+
(0, utils_2.assert)(config !== undefined, `V2 market has no hooksConfig!`);
|
|
456
|
+
config.minimumDeposit = this.underlyingToken.getAmount(data.hooksConfig.minimumDeposit);
|
|
457
|
+
if (config.kind === types_1.HooksKind.FixedTerm) {
|
|
458
|
+
config.fixedTermEndTime = data.hooksConfig.fixedTermEndTime;
|
|
459
|
+
}
|
|
460
|
+
else if (config.kind === types_1.HooksKind.PeriodicTerm) {
|
|
461
|
+
config.firstWithdrawalWindowStart = data.hooksConfig.firstWithdrawalWindowStart;
|
|
462
|
+
config.periodDuration = data.hooksConfig.periodDuration;
|
|
463
|
+
config.withdrawalWindowDuration = data.hooksConfig.withdrawalWindowDuration;
|
|
464
|
+
config.periodicTermClosed = data.hooksConfig.periodicTermClosed;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
(0, utils_2.assert)(this.version === types_1.MarketVersion.V1, `Can not push V1 lens data to V2 market!`);
|
|
469
|
+
}
|
|
610
470
|
}
|
|
611
471
|
/* -------------------------------------------------------------------------- */
|
|
612
472
|
/* Class Builder Methods */
|
|
613
473
|
/* -------------------------------------------------------------------------- */
|
|
614
474
|
static fromSubgraphMarketData(chainId, provider, data, signerAddress) {
|
|
615
475
|
const underlyingToken = token_1.Token.fromSubgraphToken(chainId, data._asset, provider);
|
|
616
|
-
const marketToken =
|
|
617
|
-
const
|
|
618
|
-
const
|
|
619
|
-
const
|
|
620
|
-
const
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const coverageLiquidity = (0, utils_1.rayMulBigint)(scaledRequiredReserves, scaleFactor) +
|
|
625
|
-
(0, token_1.toRawAmount)(data.pendingProtocolFees) +
|
|
626
|
-
(0, token_1.toRawAmount)(data.normalizedUnclaimedWithdrawals);
|
|
476
|
+
const marketToken = token_1.Token.fromSubgraphMarketData(chainId, data, provider);
|
|
477
|
+
const scaledTotalSupply = ethers_1.BigNumber.from(data.scaledTotalSupply);
|
|
478
|
+
const scaleFactor = ethers_1.BigNumber.from(data.scaleFactor);
|
|
479
|
+
const scaledWithdrawals = ethers_1.BigNumber.from(data.scaledPendingWithdrawals);
|
|
480
|
+
const scaledRequiredReserves = (0, utils_2.bipMul)(scaledTotalSupply.sub(scaledWithdrawals), ethers_1.BigNumber.from(data.reserveRatioBips)).add(scaledWithdrawals);
|
|
481
|
+
const coverageLiquidity = (0, utils_2.rayMul)(scaledRequiredReserves, scaleFactor)
|
|
482
|
+
.add(data.pendingProtocolFees)
|
|
483
|
+
.add(data.normalizedUnclaimedWithdrawals);
|
|
627
484
|
let hooksConfig;
|
|
628
|
-
let hooksFactory;
|
|
629
485
|
if (data.version === types_1.MarketVersion.V2) {
|
|
630
|
-
(0,
|
|
631
|
-
(0,
|
|
632
|
-
const { minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowTermReduction, fixedTermEndTime, transfersDisabled } = data.hooksConfig;
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
useOnQueueWithdrawal: data.hooksConfig.useOnQueueWithdrawal,
|
|
636
|
-
useOnExecuteWithdrawal: data.hooksConfig.useOnExecuteWithdrawal,
|
|
637
|
-
useOnTransfer: data.hooksConfig.useOnTransfer,
|
|
638
|
-
useOnBorrow: data.hooksConfig.useOnBorrow,
|
|
639
|
-
useOnRepay: data.hooksConfig.useOnRepay,
|
|
640
|
-
useOnCloseMarket: data.hooksConfig.useOnCloseMarket,
|
|
641
|
-
useOnNukeFromOrbit: data.hooksConfig.useOnNukeFromOrbit,
|
|
642
|
-
useOnSetMaxTotalSupply: data.hooksConfig.useOnSetMaxTotalSupply,
|
|
643
|
-
useOnSetAnnualInterestAndReserveRatioBips: data.hooksConfig.useOnSetAnnualInterestAndReserveRatioBips,
|
|
644
|
-
useOnSetProtocolFeeBips: data.hooksConfig.useOnSetProtocolFeeBips
|
|
645
|
-
};
|
|
646
|
-
const { id } = data.hooks;
|
|
647
|
-
const templateData = data.hooks.factoryHooksTemplate.name
|
|
648
|
-
? data.hooks.factoryHooksTemplate
|
|
649
|
-
: {
|
|
650
|
-
...data.hooks.factoryHooksTemplate,
|
|
651
|
-
// Older subgraph deployments can contain placeholder factory-template rows
|
|
652
|
-
// created before HooksTemplateAdded populated the template name.
|
|
653
|
-
name: fixedTermEndTime > 0 ? "FixedTermHooks" : "OpenTermHooks"
|
|
654
|
-
};
|
|
655
|
-
const template = (0, access_1.hooksTemplateFromSubgraph)(chainId, provider, templateData);
|
|
656
|
-
hooksFactory = template.hooksFactory;
|
|
486
|
+
(0, utils_2.assert)(!!data.hooks, `V2 markets require hooks`);
|
|
487
|
+
(0, utils_2.assert)(!!data.hooksConfig, `V2 markets require hooksConfig`);
|
|
488
|
+
const { __typename: _, minimumDeposit: _minimumDeposit, depositRequiresAccess, transferRequiresAccess, queueWithdrawalRequiresAccess, allowClosureBeforeTerm, allowForceBuyBacks, allowTermReduction, fixedTermEndTime, firstWithdrawalWindowStart, periodDuration, withdrawalWindowDuration, periodicTermClosed, pendingAnnualInterestBips, pendingAnnualInterestProposalTimestamp, pendingAnnualInterestResponseWindowStart, pendingAnnualInterestResponseWindowEnd, transfersDisabled, ...flags } = data.hooksConfig;
|
|
489
|
+
const { id, hooksTemplate: hooksTemplateData } = data.hooks;
|
|
490
|
+
const template = (0, access_1.hooksTemplateFromSubgraph)(chainId, provider, hooksTemplateData);
|
|
657
491
|
const minimumDeposit = _minimumDeposit
|
|
658
492
|
? underlyingToken.getAmount(_minimumDeposit)
|
|
659
493
|
: undefined;
|
|
@@ -666,7 +500,7 @@ class Market extends types_1.ContractWrapper {
|
|
|
666
500
|
minimumDeposit,
|
|
667
501
|
transferRequiresAccess,
|
|
668
502
|
depositRequiresAccess,
|
|
669
|
-
allowForceBuyBacks
|
|
503
|
+
allowForceBuyBacks,
|
|
670
504
|
transfersDisabled
|
|
671
505
|
};
|
|
672
506
|
}
|
|
@@ -681,19 +515,38 @@ class Market extends types_1.ContractWrapper {
|
|
|
681
515
|
depositRequiresAccess,
|
|
682
516
|
queueWithdrawalRequiresAccess,
|
|
683
517
|
allowClosureBeforeTerm,
|
|
684
|
-
allowForceBuyBacks
|
|
518
|
+
allowForceBuyBacks,
|
|
685
519
|
allowTermReduction,
|
|
686
520
|
fixedTermEndTime,
|
|
687
521
|
transfersDisabled
|
|
688
522
|
};
|
|
689
523
|
}
|
|
524
|
+
else if (template.kind === types_1.HooksKind.PeriodicTerm) {
|
|
525
|
+
hooksConfig = {
|
|
526
|
+
kind: types_1.HooksKind.PeriodicTerm,
|
|
527
|
+
hooksAddress: id,
|
|
528
|
+
template,
|
|
529
|
+
flags,
|
|
530
|
+
minimumDeposit,
|
|
531
|
+
transferRequiresAccess,
|
|
532
|
+
depositRequiresAccess,
|
|
533
|
+
queueWithdrawalRequiresAccess,
|
|
534
|
+
transfersDisabled,
|
|
535
|
+
firstWithdrawalWindowStart,
|
|
536
|
+
periodDuration,
|
|
537
|
+
withdrawalWindowDuration,
|
|
538
|
+
periodicTermClosed,
|
|
539
|
+
pendingAnnualInterestBips,
|
|
540
|
+
pendingAnnualInterestProposalTimestamp,
|
|
541
|
+
pendingAnnualInterestResponseWindowStart,
|
|
542
|
+
pendingAnnualInterestResponseWindowEnd
|
|
543
|
+
};
|
|
544
|
+
}
|
|
690
545
|
}
|
|
691
546
|
return new Market({
|
|
692
547
|
chainId,
|
|
693
548
|
provider,
|
|
694
549
|
version: data.version,
|
|
695
|
-
hooksFactory,
|
|
696
|
-
marketType: hooksFactory ? (0, constants_1.getMarketTypeForHooksFactory)(chainId, hooksFactory) : undefined,
|
|
697
550
|
hooksConfig,
|
|
698
551
|
marketToken,
|
|
699
552
|
underlyingToken,
|
|
@@ -711,32 +564,30 @@ class Market extends types_1.ContractWrapper {
|
|
|
711
564
|
originalReserveRatioBips: data.originalReserveRatioBips,
|
|
712
565
|
temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry,
|
|
713
566
|
isClosed: data.isClosed,
|
|
714
|
-
scaleFactor,
|
|
715
|
-
totalSupply: marketToken.getAmount((0,
|
|
567
|
+
scaleFactor: ethers_1.BigNumber.from(data.scaleFactor),
|
|
568
|
+
totalSupply: marketToken.getAmount((0, utils_2.rayMul)(scaledTotalSupply, scaleFactor)),
|
|
716
569
|
maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
|
|
717
570
|
scaledTotalSupply: scaledTotalSupply,
|
|
718
571
|
totalAssets: underlyingToken.getAmount(0),
|
|
719
572
|
lastAccruedProtocolFees: underlyingToken.getAmount(data.pendingProtocolFees),
|
|
720
573
|
normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
|
|
721
|
-
scaledPendingWithdrawals:
|
|
574
|
+
scaledPendingWithdrawals: ethers_1.BigNumber.from(data.scaledPendingWithdrawals),
|
|
722
575
|
pendingWithdrawalExpiry: +data.pendingWithdrawalExpiry,
|
|
723
576
|
isDelinquent: data.isDelinquent,
|
|
724
577
|
timeDelinquent: data.timeDelinquent,
|
|
725
578
|
lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp,
|
|
726
579
|
unpaidWithdrawalBatchExpiries: [] /* data.unpaidWithdrawalBatchExpiries */,
|
|
727
580
|
coverageLiquidity: underlyingToken.getAmount(coverageLiquidity),
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
borrowRecords: hasRecords ? data.borrowRecords : undefined,
|
|
739
|
-
feeCollectionRecords: hasRecords ? data.feeCollectionRecords : undefined,
|
|
581
|
+
totalBorrowed: underlyingToken.getAmount(data.totalBorrowed),
|
|
582
|
+
totalRepaid: underlyingToken.getAmount(data.totalRepaid),
|
|
583
|
+
totalBaseInterestAccrued: underlyingToken.getAmount(data.totalBaseInterestAccrued),
|
|
584
|
+
totalDelinquencyFeesAccrued: underlyingToken.getAmount(data.totalDelinquencyFeesAccrued),
|
|
585
|
+
totalProtocolFeesAccrued: underlyingToken.getAmount(data.totalProtocolFeesAccrued),
|
|
586
|
+
totalDeposited: underlyingToken.getAmount(data.totalDeposited),
|
|
587
|
+
depositRecords: data.depositRecords,
|
|
588
|
+
repaymentRecords: data.repaymentRecords,
|
|
589
|
+
borrowRecords: data.borrowRecords,
|
|
590
|
+
feeCollectionRecords: data.feeCollectionRecords,
|
|
740
591
|
deployedEvent: data.deployedEvent,
|
|
741
592
|
eventIndex: data.eventIndex,
|
|
742
593
|
numCollateralContracts: data.numCollateralContracts,
|
|
@@ -755,30 +606,30 @@ class Market extends types_1.ContractWrapper {
|
|
|
755
606
|
borrower: data.borrower,
|
|
756
607
|
controller: data.controller,
|
|
757
608
|
feeRecipient: data.feeRecipient,
|
|
758
|
-
protocolFeeBips:
|
|
759
|
-
delinquencyFeeBips:
|
|
760
|
-
delinquencyGracePeriod:
|
|
761
|
-
withdrawalBatchDuration:
|
|
762
|
-
reserveRatioBips:
|
|
763
|
-
annualInterestBips:
|
|
609
|
+
protocolFeeBips: data.protocolFeeBips.toNumber(),
|
|
610
|
+
delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
|
|
611
|
+
delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
|
|
612
|
+
withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
|
|
613
|
+
reserveRatioBips: data.reserveRatioBips.toNumber(),
|
|
614
|
+
annualInterestBips: data.annualInterestBips.toNumber(),
|
|
764
615
|
temporaryReserveRatio: data.temporaryReserveRatio,
|
|
765
|
-
originalAnnualInterestBips:
|
|
766
|
-
originalReserveRatioBips:
|
|
767
|
-
temporaryReserveRatioExpiry:
|
|
616
|
+
originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
|
|
617
|
+
originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
|
|
618
|
+
temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
|
|
768
619
|
isClosed: data.isClosed,
|
|
769
|
-
scaleFactor:
|
|
620
|
+
scaleFactor: data.scaleFactor,
|
|
770
621
|
totalSupply: marketToken.getAmount(data.totalSupply),
|
|
771
622
|
maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
|
|
772
|
-
scaledTotalSupply:
|
|
623
|
+
scaledTotalSupply: data.scaledTotalSupply,
|
|
773
624
|
totalAssets: underlyingToken.getAmount(data.totalAssets),
|
|
774
625
|
lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
|
|
775
626
|
normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
|
|
776
|
-
scaledPendingWithdrawals:
|
|
777
|
-
pendingWithdrawalExpiry:
|
|
627
|
+
scaledPendingWithdrawals: data.scaledPendingWithdrawals,
|
|
628
|
+
pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
|
|
778
629
|
isDelinquent: data.isDelinquent,
|
|
779
|
-
timeDelinquent:
|
|
780
|
-
lastInterestAccruedTimestamp:
|
|
781
|
-
unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries
|
|
630
|
+
timeDelinquent: data.timeDelinquent.toNumber(),
|
|
631
|
+
lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
|
|
632
|
+
unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
|
|
782
633
|
coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
|
|
783
634
|
totalBorrowed: undefined,
|
|
784
635
|
totalRepaid: undefined,
|
|
@@ -795,13 +646,13 @@ class Market extends types_1.ContractWrapper {
|
|
|
795
646
|
signerAddress: signerAddress
|
|
796
647
|
});
|
|
797
648
|
}
|
|
798
|
-
static fromMarketDataV2(chainId, provider, { hooks, hooksConfig: hooksConfigData, ...data }
|
|
649
|
+
static fromMarketDataV2(chainId, provider, { hooks, hooksConfig: hooksConfigData, ...data }) {
|
|
799
650
|
const marketToken = token_1.Token.fromTokenMetadata(chainId, data.marketToken, provider);
|
|
800
651
|
const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
|
|
801
652
|
const { hooksAddress } = hooks;
|
|
802
653
|
let hooksConfig;
|
|
803
|
-
const
|
|
804
|
-
if (
|
|
654
|
+
const allowForceBuyBacks = hooksConfigData.allowForceBuyBacks ?? false;
|
|
655
|
+
if (hooksConfigData.kind === 1) {
|
|
805
656
|
hooksConfig = {
|
|
806
657
|
kind: types_1.HooksKind.OpenTerm,
|
|
807
658
|
hooksAddress: hooksAddress,
|
|
@@ -810,10 +661,10 @@ class Market extends types_1.ContractWrapper {
|
|
|
810
661
|
transferRequiresAccess: hooksConfigData.transferRequiresAccess,
|
|
811
662
|
transfersDisabled: hooksConfigData.transfersDisabled,
|
|
812
663
|
minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
|
|
813
|
-
allowForceBuyBacks
|
|
664
|
+
allowForceBuyBacks
|
|
814
665
|
};
|
|
815
666
|
}
|
|
816
|
-
else if (
|
|
667
|
+
else if (hooksConfigData.kind === 2) {
|
|
817
668
|
hooksConfig = {
|
|
818
669
|
kind: types_1.HooksKind.FixedTerm,
|
|
819
670
|
hooksAddress: hooksAddress,
|
|
@@ -822,142 +673,73 @@ class Market extends types_1.ContractWrapper {
|
|
|
822
673
|
transferRequiresAccess: hooksConfigData.transferRequiresAccess,
|
|
823
674
|
transfersDisabled: hooksConfigData.transfersDisabled,
|
|
824
675
|
minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
|
|
825
|
-
fixedTermEndTime:
|
|
676
|
+
fixedTermEndTime: hooksConfigData.fixedTermEndTime,
|
|
826
677
|
queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
|
|
827
678
|
allowTermReduction: hooksConfigData.allowTermReduction,
|
|
828
679
|
allowClosureBeforeTerm: hooksConfigData.allowClosureBeforeTerm,
|
|
829
|
-
allowForceBuyBacks
|
|
680
|
+
allowForceBuyBacks
|
|
830
681
|
};
|
|
831
682
|
}
|
|
832
|
-
else {
|
|
833
|
-
throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksKind}`);
|
|
834
|
-
}
|
|
835
|
-
return new Market({
|
|
836
|
-
provider,
|
|
837
|
-
hooksFactory: data.hooksFactory,
|
|
838
|
-
marketType: (0, constants_1.getMarketTypeForHooksFactory)(chainId, data.hooksFactory),
|
|
839
|
-
hooksConfig,
|
|
840
|
-
version: types_1.MarketVersion.V2,
|
|
841
|
-
chainId: chainId,
|
|
842
|
-
marketToken: marketToken,
|
|
843
|
-
underlyingToken: underlyingToken,
|
|
844
|
-
borrower: data.borrower,
|
|
845
|
-
feeRecipient: data.feeRecipient,
|
|
846
|
-
protocolFeeBips: (0, utils_1.toNumber)(data.protocolFeeBips),
|
|
847
|
-
delinquencyFeeBips: (0, utils_1.toNumber)(data.delinquencyFeeBips),
|
|
848
|
-
delinquencyGracePeriod: (0, utils_1.toNumber)(data.delinquencyGracePeriod),
|
|
849
|
-
withdrawalBatchDuration: (0, utils_1.toNumber)(data.withdrawalBatchDuration),
|
|
850
|
-
reserveRatioBips: (0, utils_1.toNumber)(data.reserveRatioBips),
|
|
851
|
-
annualInterestBips: (0, utils_1.toNumber)(data.annualInterestBips),
|
|
852
|
-
temporaryReserveRatio: data.temporaryReserveRatio,
|
|
853
|
-
originalAnnualInterestBips: (0, utils_1.toNumber)(data.originalAnnualInterestBips),
|
|
854
|
-
originalReserveRatioBips: (0, utils_1.toNumber)(data.originalReserveRatioBips),
|
|
855
|
-
temporaryReserveRatioExpiry: (0, utils_1.toNumber)(data.temporaryReserveRatioExpiry),
|
|
856
|
-
isClosed: data.isClosed,
|
|
857
|
-
scaleFactor: (0, token_1.toRawAmount)(data.scaleFactor),
|
|
858
|
-
totalSupply: marketToken.getAmount(data.totalSupply),
|
|
859
|
-
maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
|
|
860
|
-
scaledTotalSupply: (0, token_1.toRawAmount)(data.scaledTotalSupply),
|
|
861
|
-
totalAssets: underlyingToken.getAmount(data.totalAssets),
|
|
862
|
-
lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
|
|
863
|
-
normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
|
|
864
|
-
scaledPendingWithdrawals: (0, token_1.toRawAmount)(data.scaledPendingWithdrawals),
|
|
865
|
-
pendingWithdrawalExpiry: (0, utils_1.toNumber)(data.pendingWithdrawalExpiry),
|
|
866
|
-
isDelinquent: data.isDelinquent,
|
|
867
|
-
timeDelinquent: (0, utils_1.toNumber)(data.timeDelinquent),
|
|
868
|
-
lastInterestAccruedTimestamp: (0, utils_1.toNumber)(data.lastInterestAccruedTimestamp),
|
|
869
|
-
unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries.map(utils_1.toNumber),
|
|
870
|
-
coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity),
|
|
871
|
-
signerAddress
|
|
872
|
-
// borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
static fromMarketDataV2_5(chainId, provider, { market, commitmentFeeBips, drawnAmount }, allowForceBuyBacks, signerAddress) {
|
|
876
|
-
void allowForceBuyBacks;
|
|
877
|
-
const { hooks, hooksConfig: hooksConfigData, ...data } = market;
|
|
878
|
-
const marketToken = token_1.Token.fromTokenMetadata(chainId, data.marketToken, provider);
|
|
879
|
-
const underlyingToken = token_1.Token.fromTokenMetadata(chainId, data.underlyingToken, provider);
|
|
880
|
-
const { hooksAddress } = hooks;
|
|
881
|
-
let hooksConfig;
|
|
882
|
-
const hooksKind = (0, utils_1.toNumber)(hooksConfigData.kind);
|
|
883
|
-
if (hooksKind === 1) {
|
|
884
|
-
hooksConfig = {
|
|
885
|
-
kind: types_1.HooksKind.OpenTerm,
|
|
886
|
-
hooksAddress,
|
|
887
|
-
flags: { ...hooksConfigData.flags },
|
|
888
|
-
depositRequiresAccess: hooksConfigData.depositRequiresAccess,
|
|
889
|
-
transferRequiresAccess: hooksConfigData.transferRequiresAccess,
|
|
890
|
-
transfersDisabled: hooksConfigData.transfersDisabled,
|
|
891
|
-
minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
|
|
892
|
-
allowForceBuyBacks: false
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
else if (hooksKind === 2) {
|
|
683
|
+
else if (hooksConfigData.kind === 3) {
|
|
896
684
|
hooksConfig = {
|
|
897
|
-
kind: types_1.HooksKind.
|
|
898
|
-
hooksAddress,
|
|
685
|
+
kind: types_1.HooksKind.PeriodicTerm,
|
|
686
|
+
hooksAddress: hooksAddress,
|
|
899
687
|
flags: { ...hooksConfigData.flags },
|
|
900
688
|
depositRequiresAccess: hooksConfigData.depositRequiresAccess,
|
|
901
689
|
transferRequiresAccess: hooksConfigData.transferRequiresAccess,
|
|
902
690
|
transfersDisabled: hooksConfigData.transfersDisabled,
|
|
903
691
|
minimumDeposit: underlyingToken.getAmount(hooksConfigData.minimumDeposit),
|
|
904
|
-
fixedTermEndTime: (0, utils_1.toNumber)(hooksConfigData.fixedTermEndTime),
|
|
905
692
|
queueWithdrawalRequiresAccess: hooksConfigData.withdrawalRequiresAccess,
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
693
|
+
firstWithdrawalWindowStart: hooksConfigData.firstWithdrawalWindowStart,
|
|
694
|
+
periodDuration: hooksConfigData.periodDuration,
|
|
695
|
+
withdrawalWindowDuration: hooksConfigData.withdrawalWindowDuration,
|
|
696
|
+
periodicTermClosed: hooksConfigData.periodicTermClosed,
|
|
697
|
+
pendingAnnualInterestBips: 0,
|
|
698
|
+
pendingAnnualInterestProposalTimestamp: 0,
|
|
699
|
+
pendingAnnualInterestResponseWindowStart: 0,
|
|
700
|
+
pendingAnnualInterestResponseWindowEnd: 0
|
|
909
701
|
};
|
|
910
702
|
}
|
|
911
703
|
else {
|
|
912
|
-
throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${
|
|
704
|
+
throw Error(`Unknown hooks kind: ${hooks.hooksTemplate.name}, version #${hooksConfigData.kind}`);
|
|
913
705
|
}
|
|
914
706
|
return new Market({
|
|
915
707
|
provider,
|
|
916
|
-
hooksFactory: data.hooksFactory,
|
|
917
|
-
marketType: (0, constants_1.getMarketTypeForHooksFactory)(chainId, data.hooksFactory),
|
|
918
708
|
hooksConfig,
|
|
919
709
|
version: types_1.MarketVersion.V2,
|
|
920
|
-
chainId,
|
|
921
|
-
marketToken,
|
|
922
|
-
underlyingToken,
|
|
710
|
+
chainId: chainId,
|
|
711
|
+
marketToken: marketToken,
|
|
712
|
+
underlyingToken: underlyingToken,
|
|
923
713
|
borrower: data.borrower,
|
|
924
714
|
feeRecipient: data.feeRecipient,
|
|
925
|
-
protocolFeeBips:
|
|
926
|
-
delinquencyFeeBips:
|
|
927
|
-
delinquencyGracePeriod:
|
|
928
|
-
withdrawalBatchDuration:
|
|
929
|
-
reserveRatioBips:
|
|
930
|
-
annualInterestBips:
|
|
715
|
+
protocolFeeBips: data.protocolFeeBips.toNumber(),
|
|
716
|
+
delinquencyFeeBips: data.delinquencyFeeBips.toNumber(),
|
|
717
|
+
delinquencyGracePeriod: data.delinquencyGracePeriod.toNumber(),
|
|
718
|
+
withdrawalBatchDuration: data.withdrawalBatchDuration.toNumber(),
|
|
719
|
+
reserveRatioBips: data.reserveRatioBips.toNumber(),
|
|
720
|
+
annualInterestBips: data.annualInterestBips.toNumber(),
|
|
931
721
|
temporaryReserveRatio: data.temporaryReserveRatio,
|
|
932
|
-
originalAnnualInterestBips:
|
|
933
|
-
originalReserveRatioBips:
|
|
934
|
-
temporaryReserveRatioExpiry:
|
|
722
|
+
originalAnnualInterestBips: data.originalAnnualInterestBips.toNumber(),
|
|
723
|
+
originalReserveRatioBips: data.originalReserveRatioBips.toNumber(),
|
|
724
|
+
temporaryReserveRatioExpiry: data.temporaryReserveRatioExpiry.toNumber(),
|
|
935
725
|
isClosed: data.isClosed,
|
|
936
|
-
scaleFactor:
|
|
726
|
+
scaleFactor: data.scaleFactor,
|
|
937
727
|
totalSupply: marketToken.getAmount(data.totalSupply),
|
|
938
728
|
maxTotalSupply: marketToken.getAmount(data.maxTotalSupply),
|
|
939
|
-
scaledTotalSupply:
|
|
729
|
+
scaledTotalSupply: data.scaledTotalSupply,
|
|
940
730
|
totalAssets: underlyingToken.getAmount(data.totalAssets),
|
|
941
731
|
lastAccruedProtocolFees: underlyingToken.getAmount(data.lastAccruedProtocolFees),
|
|
942
732
|
normalizedUnclaimedWithdrawals: underlyingToken.getAmount(data.normalizedUnclaimedWithdrawals),
|
|
943
|
-
scaledPendingWithdrawals:
|
|
944
|
-
pendingWithdrawalExpiry:
|
|
733
|
+
scaledPendingWithdrawals: data.scaledPendingWithdrawals,
|
|
734
|
+
pendingWithdrawalExpiry: data.pendingWithdrawalExpiry.toNumber(),
|
|
945
735
|
isDelinquent: data.isDelinquent,
|
|
946
|
-
timeDelinquent:
|
|
947
|
-
lastInterestAccruedTimestamp:
|
|
948
|
-
unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries
|
|
949
|
-
coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity)
|
|
950
|
-
|
|
951
|
-
? (0, utils_1.toNumber)(commitmentFeeBips.value)
|
|
952
|
-
: undefined,
|
|
953
|
-
drawnAmount: drawnAmount.isPresent ? underlyingToken.getAmount(drawnAmount.value) : undefined,
|
|
954
|
-
signerAddress
|
|
736
|
+
timeDelinquent: data.timeDelinquent.toNumber(),
|
|
737
|
+
lastInterestAccruedTimestamp: data.lastInterestAccruedTimestamp.toNumber(),
|
|
738
|
+
unpaidWithdrawalBatchExpiries: data.unpaidWithdrawalBatchExpiries,
|
|
739
|
+
coverageLiquidity: underlyingToken.getAmount(data.coverageLiquidity)
|
|
740
|
+
// borrowableAssets: underlyingToken.getAmount(data.borrowableAssets)
|
|
955
741
|
});
|
|
956
742
|
}
|
|
957
|
-
static async fromUnifiedMarketData(chainId, provider, data, signerAddress) {
|
|
958
|
-
const marketData = toUnifiedMarketDataV2(data);
|
|
959
|
-
return Market.fromMarketDataV2_5(chainId, provider, marketData, false, signerAddress);
|
|
960
|
-
}
|
|
961
743
|
/* -------------------------------------------------------------------------- */
|
|
962
744
|
/* Static Queries */
|
|
963
745
|
/* -------------------------------------------------------------------------- */
|
|
@@ -965,133 +747,53 @@ class Market extends types_1.ContractWrapper {
|
|
|
965
747
|
* @returns `Market` instance for `market`
|
|
966
748
|
*/
|
|
967
749
|
static async getMarket(chainId, market, provider) {
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
|
|
972
|
-
return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
|
|
973
|
-
}
|
|
974
|
-
catch (_) {
|
|
975
|
-
// Fall back to the legacy lens for V1 markets and pre-unified deployments.
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
const data = await (0, market_lens_1.getLegacyMarketData)(chainId, provider, market);
|
|
979
|
-
return Market.fromMarketData(chainId, data, provider, signerAddress);
|
|
750
|
+
const lens = (0, constants_1.getLensContract)(chainId, provider);
|
|
751
|
+
const data = await lens.getMarketData(market);
|
|
752
|
+
return Market.fromMarketData(chainId, data, provider, abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined);
|
|
980
753
|
}
|
|
981
754
|
/**
|
|
982
755
|
* @returns `Market` instance for `market`
|
|
983
756
|
*/
|
|
984
757
|
static async getMarketV2(chainId, market, provider) {
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
const data = await (0, market_lens_1.getUnifiedMarketDataV2)(chainId, provider, market);
|
|
989
|
-
return Market.fromUnifiedMarketData(chainId, provider, data, signerAddress);
|
|
990
|
-
}
|
|
991
|
-
catch (_) {
|
|
992
|
-
// Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
|
|
996
|
-
return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* @returns V2 `Market` instances for `markets`, preserving V2.5/RCF fields
|
|
1000
|
-
* when the current lens exposes them.
|
|
1001
|
-
*/
|
|
1002
|
-
static async getMarketsV2(chainId, markets, provider) {
|
|
1003
|
-
const signerAddress = await (0, ethers_signer_1.getEthersSignerAddress)(provider);
|
|
1004
|
-
if (hasUnifiedLatestLensForDirectReads(chainId)) {
|
|
1005
|
-
try {
|
|
1006
|
-
const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
|
|
1007
|
-
return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
|
|
1008
|
-
}
|
|
1009
|
-
catch (_) {
|
|
1010
|
-
// Fall back to the pre-2.5 V2 lens for chains that have not fully migrated.
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
return Promise.all(markets.map(async (market) => {
|
|
1014
|
-
const data = await (0, market_lens_1.getV2MarketData)(chainId, provider, market);
|
|
1015
|
-
return Market.fromMarketDataV2(chainId, provider, data, signerAddress);
|
|
1016
|
-
}));
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Refresh existing V2 market instances with the focused live lens surface when available.
|
|
1020
|
-
* Falls back to broad V2 market reads so callers can use this as a route-intent API.
|
|
1021
|
-
*/
|
|
1022
|
-
static async refreshMarketsV2LiveData(chainId, markets, provider) {
|
|
1023
|
-
if (markets.length === 0) {
|
|
1024
|
-
return markets;
|
|
1025
|
-
}
|
|
1026
|
-
const marketAddresses = markets.map((market) => market.address);
|
|
1027
|
-
if (hasUnifiedLatestLensForDirectReads(chainId)) {
|
|
1028
|
-
try {
|
|
1029
|
-
const updates = await (0, market_lens_1.getUnifiedMarketsLiveDataV2)(chainId, provider, marketAddresses);
|
|
1030
|
-
updates.forEach((update, i) => {
|
|
1031
|
-
markets[i].updateWithLiveData(update);
|
|
1032
|
-
});
|
|
1033
|
-
return markets;
|
|
1034
|
-
}
|
|
1035
|
-
catch (_) {
|
|
1036
|
-
// Fall back to broad reads for older unified lens deployments.
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
const refreshedMarkets = await Market.getMarketsV2(chainId, marketAddresses, provider);
|
|
1040
|
-
refreshedMarkets.forEach((market, i) => {
|
|
1041
|
-
Object.assign(markets[i], market);
|
|
1042
|
-
});
|
|
1043
|
-
return markets;
|
|
758
|
+
const lens = (0, constants_1.getLensV2Contract)(chainId, provider);
|
|
759
|
+
const data = await lens.getMarketData(market);
|
|
760
|
+
return Market.fromMarketDataV2(chainId, provider, data);
|
|
1044
761
|
}
|
|
1045
762
|
/**
|
|
1046
763
|
* @returns `Market` instances for `markets`
|
|
1047
764
|
*/
|
|
1048
765
|
static async getMarkets(chainId, markets, provider) {
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const data = await (0, market_lens_1.getUnifiedMarketsDataV2)(chainId, provider, markets);
|
|
1053
|
-
return Promise.all(data.map((market) => Market.fromUnifiedMarketData(chainId, provider, market, signerAddress)));
|
|
1054
|
-
}
|
|
1055
|
-
catch (_) {
|
|
1056
|
-
return Promise.all(markets.map((market) => Market.getMarket(chainId, market, provider)));
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
const data = await (0, market_lens_1.getLegacyMarketsData)(chainId, provider, markets);
|
|
766
|
+
const lens = (0, constants_1.getLensContract)(chainId, provider);
|
|
767
|
+
const data = await lens.getMarketsData(markets);
|
|
768
|
+
const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
|
|
1060
769
|
return data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress));
|
|
1061
770
|
}
|
|
1062
771
|
/**
|
|
1063
772
|
* @return All deployed markets
|
|
1064
773
|
*/
|
|
1065
774
|
static async getAllMarkets(chainId, provider) {
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
775
|
+
const lens = (0, constants_1.getLensContract)(chainId, provider);
|
|
776
|
+
const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
|
|
777
|
+
return lens
|
|
778
|
+
.getAllMarketsData()
|
|
779
|
+
.then((data) => data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress)));
|
|
1071
780
|
}
|
|
1072
781
|
/**
|
|
1073
782
|
* @dev Get a paginated list of deployed markets.
|
|
1074
783
|
*/
|
|
1075
784
|
static async getPaginatedMarkets(chainId, provider, start = 0, count) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
return [];
|
|
1082
|
-
}
|
|
1083
|
-
const end = Math.min(start + count, totalMarkets);
|
|
1084
|
-
const markets = await (0, arch_controller_1.getRegisteredMarketsPage)(chainId, provider, start, end);
|
|
1085
|
-
if (!markets.length) {
|
|
1086
|
-
return [];
|
|
1087
|
-
}
|
|
1088
|
-
return Market.getMarkets(chainId, markets, provider);
|
|
785
|
+
const signerAddress = abstract_signer_1.Signer.isSigner(provider) ? await provider.getAddress() : undefined;
|
|
786
|
+
const lens = (0, constants_1.getLensContract)(chainId, provider);
|
|
787
|
+
return lens
|
|
788
|
+
.getPaginatedMarketsData(start, count)
|
|
789
|
+
.then((data) => data.map((market) => Market.fromMarketData(chainId, market, provider, signerAddress)));
|
|
1089
790
|
}
|
|
1090
791
|
/**
|
|
1091
792
|
* @return Total number of deployed markets.
|
|
1092
793
|
*/
|
|
1093
794
|
static async getMarketsCount(chainId, provider) {
|
|
1094
|
-
|
|
795
|
+
const lens = (0, constants_1.getLensContract)(chainId, provider);
|
|
796
|
+
return lens.getMarketsCount().then((count) => count.toNumber());
|
|
1095
797
|
}
|
|
1096
798
|
}
|
|
1097
799
|
exports.Market = Market;
|