@gearbox-protocol/sdk 17.0.0-next.3 → 17.0.0

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.
Files changed (370) hide show
  1. package/dist/cjs/dev/abi.js +14 -15
  2. package/dist/cjs/dev/claimFromFaucet.js +4 -8
  3. package/dist/cjs/dev/createAnvilClient.js +35 -17
  4. package/dist/cjs/dev/index.js +7 -2
  5. package/dist/cjs/dev/kycUtils.js +66 -58
  6. package/dist/cjs/dev/midasUtils.js +113 -16
  7. package/dist/cjs/dev/securitizeUtils.js +82 -42
  8. package/dist/cjs/dev/withdrawalUtils.js +3 -6
  9. package/dist/cjs/model/errors/index.js +2 -0
  10. package/dist/cjs/model/errors/operation-errors.js +19 -1
  11. package/dist/cjs/model/index.js +4 -2
  12. package/dist/cjs/model/rwa.js +4 -4
  13. package/dist/cjs/model/rwa.schema.js +4 -4
  14. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
  15. package/dist/cjs/onchain/OnchainSDK.js +3 -3
  16. package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -17
  17. package/dist/cjs/onchain/accounts/intents/borrow.js +140 -0
  18. package/dist/cjs/onchain/accounts/intents/collateral-valuation.js +41 -0
  19. package/dist/cjs/onchain/accounts/intents/guards.js +19 -7
  20. package/dist/cjs/onchain/accounts/intents/index.js +107 -20
  21. package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -12
  22. package/dist/cjs/onchain/accounts/intents/maxBorrow.js +89 -0
  23. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  24. package/dist/cjs/onchain/accounts/intents/open-strategy.js +8 -46
  25. package/dist/cjs/onchain/accounts/intents/operations.js +0 -1
  26. package/dist/cjs/onchain/accounts/intents/realize.js +61 -4
  27. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  28. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  29. package/dist/cjs/onchain/accounts/intents/utils/common.js +19 -0
  30. package/dist/cjs/onchain/accounts/intents/utils/credit-account-slice.js +21 -0
  31. package/dist/cjs/onchain/accounts/intents/utils/index.js +2 -0
  32. package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +12 -9
  33. package/dist/cjs/onchain/accounts/intents/utils/router-path.js +4 -5
  34. package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +97 -0
  35. package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  36. package/dist/cjs/onchain/constants/address-provider.js +0 -2
  37. package/dist/cjs/onchain/constants/index.js +0 -1
  38. package/dist/cjs/onchain/core/createAddressProvider.js +2 -5
  39. package/dist/cjs/onchain/index.js +60 -43
  40. package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +2 -2
  41. package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
  42. package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +49 -5
  43. package/dist/cjs/onchain/market/credit/CreditSuite.js +33 -12
  44. package/dist/cjs/onchain/market/index.js +50 -38
  45. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +3 -3
  46. package/dist/cjs/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  47. package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +127 -0
  48. package/dist/cjs/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  49. package/dist/cjs/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  50. package/dist/cjs/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  51. package/dist/cjs/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  52. package/dist/cjs/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  53. package/dist/cjs/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  54. package/dist/cjs/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  55. package/dist/cjs/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  56. package/dist/cjs/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  57. package/dist/cjs/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  58. package/dist/cjs/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  59. package/dist/cjs/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  60. package/dist/cjs/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  61. package/dist/cjs/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  62. package/dist/cjs/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  63. package/dist/cjs/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  64. package/dist/cjs/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  65. package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +35 -0
  66. package/dist/cjs/onchain/market/pricefeeds/index.js +51 -39
  67. package/dist/cjs/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +189 -0
  68. package/dist/cjs/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  69. package/dist/cjs/onchain/market/pricefeeds/updates/index.js +8 -0
  70. package/dist/cjs/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  71. package/dist/cjs/onchain/market/pricefeeds/updates/updatableDependencies.js +14 -0
  72. package/dist/cjs/onchain/market/rwa/RWARegistry.js +4 -7
  73. package/dist/cjs/onchain/market/rwa/index.js +1 -0
  74. package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  75. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +56 -12
  76. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  77. package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  78. package/dist/cjs/onchain/opportunities/OpportunitiesService.js +16 -4
  79. package/dist/cjs/onchain/positions/calcHealthFactor.js +3 -3
  80. package/dist/cjs/onchain/preview/index.js +2 -0
  81. package/dist/cjs/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  82. package/dist/cjs/onchain/preview/preview/index.js +2 -0
  83. package/dist/cjs/onchain/preview/preview/midasGreenlistsAccount.js +17 -0
  84. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +13 -16
  85. package/dist/cjs/onchain/preview/preview/previewOperation.js +19 -11
  86. package/dist/cjs/onchain/preview/preview/replayMulticall.js +4 -3
  87. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  88. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +12 -10
  89. package/dist/cjs/onchain/validation/bundles/checkIncreaseDebt.js +28 -0
  90. package/dist/cjs/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
  91. package/dist/cjs/onchain/validation/bundles/checkMidasAccountGreenlist.js +44 -0
  92. package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  93. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +18 -8
  94. package/dist/cjs/onchain/validation/bundles/index.js +6 -4
  95. package/dist/cjs/onchain/validation/checkOperation.js +0 -1
  96. package/dist/cjs/onchain/validation/checkSimulation.js +1 -1
  97. package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +1 -1
  98. package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +2 -5
  99. package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  100. package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
  101. package/dist/cjs/onchain/validation/checks/index.js +2 -0
  102. package/dist/cjs/onchain/validation/index.js +8 -4
  103. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
  104. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
  105. package/dist/cjs/sdk/execute/ExecuteApi.js +67 -7
  106. package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  107. package/dist/cjs/sdk/prepare/PrepareApi.js +89 -14
  108. package/dist/esm/dev/abi.js +14 -15
  109. package/dist/esm/dev/claimFromFaucet.js +4 -8
  110. package/dist/esm/dev/createAnvilClient.js +36 -19
  111. package/dist/esm/dev/index.js +4 -4
  112. package/dist/esm/dev/kycUtils.js +66 -59
  113. package/dist/esm/dev/midasUtils.js +112 -18
  114. package/dist/esm/dev/securitizeUtils.js +84 -44
  115. package/dist/esm/dev/withdrawalUtils.js +3 -6
  116. package/dist/esm/model/errors/index.js +2 -2
  117. package/dist/esm/model/errors/operation-errors.js +18 -2
  118. package/dist/esm/model/index.js +4 -4
  119. package/dist/esm/model/rwa.js +4 -4
  120. package/dist/esm/model/rwa.schema.js +5 -5
  121. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
  122. package/dist/esm/onchain/OnchainSDK.js +3 -3
  123. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -17
  124. package/dist/esm/onchain/accounts/intents/borrow.js +138 -0
  125. package/dist/esm/onchain/accounts/intents/collateral-valuation.js +40 -0
  126. package/dist/esm/onchain/accounts/intents/guards.js +19 -7
  127. package/dist/esm/onchain/accounts/intents/index.js +107 -20
  128. package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
  129. package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
  130. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  131. package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -46
  132. package/dist/esm/onchain/accounts/intents/operations.js +0 -1
  133. package/dist/esm/onchain/accounts/intents/realize.js +61 -4
  134. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  135. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  136. package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
  137. package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
  138. package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
  139. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +12 -9
  140. package/dist/esm/onchain/accounts/intents/utils/router-path.js +4 -5
  141. package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
  142. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  143. package/dist/esm/onchain/constants/address-provider.js +1 -2
  144. package/dist/esm/onchain/constants/index.js +2 -2
  145. package/dist/esm/onchain/core/createAddressProvider.js +2 -5
  146. package/dist/esm/onchain/index.js +32 -24
  147. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +2 -2
  148. package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
  149. package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +50 -6
  150. package/dist/esm/onchain/market/credit/CreditSuite.js +33 -12
  151. package/dist/esm/onchain/market/index.js +26 -21
  152. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  153. package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  154. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
  155. package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  156. package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  157. package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  158. package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  159. package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  160. package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  161. package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  162. package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  163. package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  164. package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  165. package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  166. package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  167. package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  168. package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  169. package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  170. package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  171. package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  172. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
  173. package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
  174. package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
  175. package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  176. package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
  177. package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  178. package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
  179. package/dist/esm/onchain/market/rwa/RWARegistry.js +4 -8
  180. package/dist/esm/onchain/market/rwa/index.js +2 -2
  181. package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  182. package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
  183. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  184. package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  185. package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
  186. package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
  187. package/dist/esm/onchain/preview/index.js +2 -1
  188. package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  189. package/dist/esm/onchain/preview/preview/index.js +2 -1
  190. package/dist/esm/onchain/preview/preview/midasGreenlistsAccount.js +16 -0
  191. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +14 -17
  192. package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
  193. package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
  194. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  195. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +12 -10
  196. package/dist/esm/onchain/validation/bundles/checkIncreaseDebt.js +27 -0
  197. package/dist/esm/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
  198. package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +43 -0
  199. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  200. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +18 -8
  201. package/dist/esm/onchain/validation/bundles/index.js +4 -3
  202. package/dist/esm/onchain/validation/checkOperation.js +0 -1
  203. package/dist/esm/onchain/validation/checkSimulation.js +1 -1
  204. package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +1 -1
  205. package/dist/esm/onchain/validation/checks/checkDebtLimits.js +2 -5
  206. package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  207. package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
  208. package/dist/esm/onchain/validation/checks/index.js +2 -1
  209. package/dist/esm/onchain/validation/index.js +5 -3
  210. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  211. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
  212. package/dist/esm/sdk/execute/ExecuteApi.js +67 -7
  213. package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  214. package/dist/esm/sdk/prepare/PrepareApi.js +94 -19
  215. package/dist/types/dev/abi.d.ts +13 -15
  216. package/dist/types/dev/claimFromFaucet.d.ts +0 -1
  217. package/dist/types/dev/createAnvilClient.d.ts +10 -3
  218. package/dist/types/dev/index.d.ts +4 -4
  219. package/dist/types/dev/kycUtils.d.ts +15 -24
  220. package/dist/types/dev/midasUtils.d.ts +35 -4
  221. package/dist/types/dev/securitizeUtils.d.ts +3 -9
  222. package/dist/types/model/errors/index.d.ts +2 -2
  223. package/dist/types/model/errors/operation-errors.d.ts +65 -11
  224. package/dist/types/model/index.d.ts +5 -5
  225. package/dist/types/model/opportunities.d.ts +6 -7
  226. package/dist/types/model/previews.d.ts +25 -19
  227. package/dist/types/model/rwa.d.ts +47 -27
  228. package/dist/types/model/rwa.schema.d.ts +3 -3
  229. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
  230. package/dist/types/offchain/opportunities/types.d.ts +1 -4
  231. package/dist/types/onchain/OnchainSDK.d.ts +2 -2
  232. package/dist/types/onchain/accounts/index.d.ts +5 -4
  233. package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
  234. package/dist/types/onchain/accounts/intents/collateral-valuation.d.ts +42 -0
  235. package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
  236. package/dist/types/onchain/accounts/intents/index.d.ts +103 -15
  237. package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
  238. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
  239. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
  240. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
  241. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  242. package/dist/types/onchain/accounts/intents/types.d.ts +51 -6
  243. package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
  244. package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
  245. package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
  246. package/dist/types/onchain/accounts/intents/utils/price-impact.d.ts +4 -1
  247. package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +2 -5
  248. package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
  249. package/dist/types/onchain/accounts/types.d.ts +4 -2
  250. package/dist/types/onchain/constants/address-provider.d.ts +1 -2
  251. package/dist/types/onchain/constants/index.d.ts +2 -2
  252. package/dist/types/onchain/index.d.ts +40 -31
  253. package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +6 -0
  254. package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +20 -4
  255. package/dist/types/onchain/market/adapters/types.d.ts +8 -0
  256. package/dist/types/onchain/market/credit/CreditSuite.d.ts +13 -3
  257. package/dist/types/onchain/market/credit/types.d.ts +2 -2
  258. package/dist/types/onchain/market/index.d.ts +29 -24
  259. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
  260. package/dist/types/onchain/market/oracle/types.d.ts +2 -1
  261. package/dist/types/onchain/market/pool/types.d.ts +1 -1
  262. package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
  263. package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
  264. package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
  265. package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
  266. package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
  267. package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
  268. package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
  269. package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
  270. package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
  271. package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
  272. package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
  273. package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
  274. package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
  275. package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
  276. package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
  277. package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
  278. package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
  279. package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
  280. package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
  281. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
  282. package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
  283. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
  284. package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
  285. package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
  286. package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
  287. package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
  288. package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
  289. package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
  290. package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
  291. package/dist/types/onchain/market/rwa/RWARegistry.d.ts +2 -1
  292. package/dist/types/onchain/market/rwa/index.d.ts +3 -3
  293. package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
  294. package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
  295. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
  296. package/dist/types/onchain/market/rwa/types.d.ts +39 -37
  297. package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
  298. package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
  299. package/dist/types/onchain/opportunities/types.d.ts +6 -1
  300. package/dist/types/onchain/preview/index.d.ts +2 -1
  301. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  302. package/dist/types/onchain/preview/preview/midasGreenlistsAccount.d.ts +13 -0
  303. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
  304. package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
  305. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +5 -4
  306. package/dist/types/onchain/validation/bundles/{checkDraw.d.ts → checkIncreaseDebt.d.ts} +7 -7
  307. package/dist/types/onchain/validation/bundles/{checkQuotasAsked.d.ts → checkIncreaseQuota.d.ts} +3 -3
  308. package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +22 -0
  309. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
  310. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +9 -7
  311. package/dist/types/onchain/validation/bundles/index.d.ts +5 -4
  312. package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +1 -1
  313. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +3 -3
  314. package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +1 -1
  315. package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
  316. package/dist/types/onchain/validation/checks/index.d.ts +2 -1
  317. package/dist/types/onchain/validation/index.d.ts +6 -4
  318. package/dist/types/onchain/validation/raise.d.ts +2 -2
  319. package/dist/types/sdk/execute/index.d.ts +2 -2
  320. package/dist/types/sdk/execute/types.d.ts +48 -6
  321. package/dist/types/sdk/index.d.ts +5 -4
  322. package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
  323. package/dist/types/sdk/opportunities/types.d.ts +9 -3
  324. package/dist/types/sdk/prepare/PrepareApi.d.ts +16 -4
  325. package/dist/types/sdk/prepare/index.d.ts +4 -3
  326. package/dist/types/sdk/prepare/types.d.ts +200 -66
  327. package/package.json +1 -1
  328. package/dist/cjs/onchain/accounts/utils/midasUtils.js +0 -70
  329. package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
  330. package/dist/cjs/onchain/validation/bundles/checkDraw.js +0 -28
  331. package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -61
  332. package/dist/cjs/plugins/degen-distributors/index.js +0 -4
  333. package/dist/cjs/plugins/degen-distributors/package.json +0 -1
  334. package/dist/cjs/plugins/degen-distributors/types.js +0 -1
  335. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -114
  336. package/dist/cjs/plugins/delayed-withdrawal/index.js +0 -4
  337. package/dist/cjs/plugins/delayed-withdrawal/package.json +0 -1
  338. package/dist/cjs/plugins/delayed-withdrawal/types.js +0 -1
  339. package/dist/esm/onchain/accounts/utils/midasUtils.js +0 -69
  340. package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
  341. package/dist/esm/onchain/validation/bundles/checkDraw.js +0 -27
  342. package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -60
  343. package/dist/esm/plugins/degen-distributors/index.js +0 -3
  344. package/dist/esm/plugins/degen-distributors/package.json +0 -1
  345. package/dist/esm/plugins/degen-distributors/types.js +0 -1
  346. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -113
  347. package/dist/esm/plugins/delayed-withdrawal/index.js +0 -3
  348. package/dist/esm/plugins/delayed-withdrawal/package.json +0 -1
  349. package/dist/esm/plugins/delayed-withdrawal/types.js +0 -1
  350. package/dist/types/onchain/accounts/utils/midasUtils.d.ts +0 -38
  351. package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
  352. package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
  353. package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
  354. package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
  355. package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
  356. package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
  357. package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
  358. package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
  359. package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
  360. package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
  361. package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
  362. package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
  363. package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
  364. package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
  365. package/dist/types/plugins/degen-distributors/DegenDistributorsPlugin.d.ts +0 -25
  366. package/dist/types/plugins/degen-distributors/index.d.ts +0 -3
  367. package/dist/types/plugins/degen-distributors/types.d.ts +0 -8
  368. package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +0 -25
  369. package/dist/types/plugins/delayed-withdrawal/index.d.ts +0 -3
  370. package/dist/types/plugins/delayed-withdrawal/types.d.ts +0 -10
@@ -1,4 +1,6 @@
1
- import { createTestClient, publicActions, testActions, toHex, walletActions } from "viem";
1
+ import { BaseError, createTestClient, publicActions, testActions, toHex, walletActions } from "viem";
2
+ import { getAction } from "viem/utils";
3
+ import { waitForTransactionReceipt, writeContract } from "viem/actions";
2
4
  //#region src/dev/createAnvilClient.ts
3
5
  let dealModulePromise;
4
6
  async function loadDeal() {
@@ -7,23 +9,27 @@ async function loadDeal() {
7
9
  if (!mod) throw new Error("createAnvilClient: deal action requires the 'viem-deal' package; install it as a dependency");
8
10
  return mod.deal;
9
11
  }
12
+ function anvilActions(client) {
13
+ return {
14
+ anvilNodeInfo: () => anvilNodeInfo(client),
15
+ isAnvil: () => isAnvil(client),
16
+ evmMineDetailed: (timestamp) => evmMineDetailed(client, timestamp),
17
+ deal: async (params) => {
18
+ await (await loadDeal())(client, params);
19
+ },
20
+ writeContractSync: (parameters) => writeContractSync(client, parameters)
21
+ };
22
+ }
10
23
  /**
11
24
  * Extends an arbitrary viem `PublicClient` with anvil + wallet actions plus
12
25
  * the SDK's bonus actions (`anvilNodeInfo`, `isAnvil`, `evmMineDetailed`,
13
- * `deal`).
26
+ * `deal`, `writeContractSync`).
14
27
  *
15
28
  * Used to lift `sdk.client` into an `AnvilClient` shape on the fly when test
16
29
  * RPCs (impersonateAccount, setBalance, setStorageAt, ...) are needed.
17
30
  */
18
31
  function extendAnvilClient(client) {
19
- return client.extend(() => ({ mode: "anvil" })).extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => ({
20
- anvilNodeInfo: () => anvilNodeInfo(c),
21
- isAnvil: () => isAnvil(c),
22
- evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
23
- deal: async (params) => {
24
- await (await loadDeal())(c, params);
25
- }
26
- }));
32
+ return client.extend(() => ({ mode: "anvil" })).extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => anvilActions(c));
27
33
  }
28
34
  function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval = 50 }) {
29
35
  return createTestClient({
@@ -32,14 +38,7 @@ function createAnvilClient({ chain, transport, cacheTime = 0, pollingInterval =
32
38
  transport,
33
39
  cacheTime,
34
40
  pollingInterval
35
- }).extend(publicActions).extend(walletActions).extend((c) => ({
36
- anvilNodeInfo: () => anvilNodeInfo(c),
37
- isAnvil: () => isAnvil(c),
38
- evmMineDetailed: (timestamp) => evmMineDetailed(c, timestamp),
39
- deal: async (params) => {
40
- await (await loadDeal())(c, params);
41
- }
42
- }));
41
+ }).extend(publicActions).extend(walletActions).extend((c) => anvilActions(c));
43
42
  }
44
43
  /**
45
44
  * View action to detect if client is an anvil client
@@ -84,5 +83,23 @@ async function evmMineDetailed(client, timestamp) {
84
83
  return;
85
84
  }
86
85
  }
86
+ /**
87
+ * Anvil-compatible `writeContractSync`: send via `writeContract` (Anvil
88
+ * supports `eth_sendTransaction` / `eth_sendRawTransaction`) then wait for
89
+ * the receipt. Viem's own action uses `eth_sendRawTransactionSync`, which
90
+ * Anvil does not implement.
91
+ */
92
+ async function writeContractSync(client, parameters) {
93
+ const { throwOnReceiptRevert, pollingInterval, timeout, ...writeParams } = parameters;
94
+ const hash = await getAction(client, writeContract, "writeContract")(writeParams);
95
+ const receipt = await getAction(client, waitForTransactionReceipt, "waitForTransactionReceipt")({
96
+ checkReplacement: false,
97
+ hash,
98
+ pollingInterval,
99
+ timeout
100
+ });
101
+ if (throwOnReceiptRevert && receipt.status === "reverted") throw new BaseError(`Transaction with hash "${receipt.transactionHash}" reverted.`, { name: "TransactionReceiptRevertedError" });
102
+ return receipt;
103
+ }
87
104
  //#endregion
88
- export { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil };
105
+ export { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync };
@@ -1,6 +1,6 @@
1
1
  import { iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi } from "./abi.js";
2
2
  import { claimFromFaucet } from "./claimFromFaucet.js";
3
- import { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil } from "./createAnvilClient.js";
3
+ import { anvilNodeInfo, createAnvilClient, evmMineDetailed, extendAnvilClient, isAnvil, writeContractSync } from "./createAnvilClient.js";
4
4
  import { createMinter } from "./mint/factory.js";
5
5
  import "./mint/index.js";
6
6
  import { AccountOpener, OpenTxRevertedError } from "./AccountOpener.js";
@@ -13,10 +13,10 @@ import { detectChain } from "./detectChain.js";
13
13
  import { isOutOfSyncError } from "./isOutOfSyncError.js";
14
14
  import { isRateLimitError } from "./isRateLimitError.js";
15
15
  import { isTransientError } from "./isTransientError.js";
16
- import { greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, writeAndWait } from "./kycUtils.js";
16
+ import { discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault } from "./midasUtils.js";
17
+ import { DEFAULT_MIDAS_ADMIN, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor } from "./kycUtils.js";
17
18
  import { isRangeError, logSplitterTransport } from "./logSplitterTransport.js";
18
19
  import { setLTZero, setLTs } from "./ltUtils.js";
19
- import { unpauseMidasIssuanceVault } from "./midasUtils.js";
20
20
  import { migrateFaucet } from "./migrateFaucet.js";
21
21
  import { SUPPORTED_RPC_PROVIDERS, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getRpcProviderUrl, getThirdWebUrl, rpcProvidersSchema } from "./providers.js";
22
22
  import { replaceStorage } from "./replaceStorage.js";
@@ -25,4 +25,4 @@ import { claimDSToken, claimDSTokens, enableDSTokenBackDating } from "./securiti
25
25
  import "./types.js";
26
26
  import { ONCHAIN_EXECUTION_ID_ADDRESS, verifyTestnet } from "./verifyTestnet.js";
27
27
  import { makePendingWithdrawalsClaimable } from "./withdrawalUtils.js";
28
- export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeAndWait };
28
+ export { AccountOpener, Create2Deployer, DEFAULT_CREATE2_SALT, DEFAULT_MIDAS_ADMIN, EthCallSpy, NoAvailableTransportsError, ONCHAIN_EXECUTION_ID_ADDRESS, OpenTxRevertedError, PUBLIC_CREATE2_FACTORY, RevolverTransport, SUPPORTED_RPC_PROVIDERS, SelectionStrategy, anvilNodeInfo, calcLiquidatableLTs, claimDSToken, claimDSTokens, claimFromFaucet, createAnvilClient, createMinter, deployUsingPublicCreate2, detectChain, discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, enableDSTokenBackDating, evmMineDetailed, extendAnvilClient, getAlchemyUrl, getAnkrUrl, getDrpcUrl, getErpcKey, getPublicCreate2Address, getRpcProviderUrl, getSecuritizeAdmin, getThirdWebUrl, greenlistMidasGateway, httpTransportOptionsSchema, iDegenNftv2Abi, iFaucetAbi, iOnchainExecutionIdAbi, iOwnableAbi, iaclTraitAbi, isAnvil, isDeployedUsingPublicCreate2, isOutOfSyncError, isRangeError, isRateLimitError, isTransientError, logSplitterTransport, makePendingWithdrawalsClaimable, migrateFaucet, providerConfigSchema, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, replaceStorage, resilientTransport, resilientTransportOptionsSchema, revolverTransportConfigBaseSchema, revolverTransportConfigSchema, rpcProvidersSchema, setLTZero, setLTs, unpauseMidasIssuanceVault, verifyTestnet, writeContractSync };
@@ -4,33 +4,52 @@ import { OnchainSDK } from "../onchain/OnchainSDK.js";
4
4
  import "../onchain/index.js";
5
5
  import { iDSRegistryServiceAbi } from "../abi/rwa/iDSRegistryService.js";
6
6
  import { iDSTokenAbi } from "../abi/rwa/iDSToken.js";
7
+ import { discoverMidasCreditSuites, discoverMidasGateways } from "./midasUtils.js";
7
8
  import { midasGatewayAbi } from "./withdrawalAbi.js";
8
- import { isAddressEqual, parseAbi, parseEther, zeroAddress } from "viem";
9
- import { privateKeyToAccount } from "viem/accounts";
9
+ import { getAddress, isAddressEqual, parseAbi, parseEther, slice, toHex, zeroAddress } from "viem";
10
10
  //#region src/dev/kycUtils.ts
11
+ const iMockDSTokenAdminAbi = parseAbi(["function admin() view returns (address)"]);
11
12
  /**
12
- * Writes to a contract, mines a block and waits for the receipt
13
+ * DS trust-service master of `token`: Ownable owner at storage slot 0 of the
14
+ * trust service, same as periphery-v3 SecuritizeAttachHelper. MockDSToken
15
+ * returns itself as the trust service, so `admin()` is used instead.
13
16
  */
14
- async function writeAndWait(anvil, params) {
15
- const hash = await anvil.writeContract(params);
16
- await anvil.mine({ blocks: 1 });
17
- await anvil.waitForTransactionReceipt({
18
- hash,
19
- pollingInterval: 100
17
+ async function getSecuritizeAdmin(anvil, token, logger) {
18
+ const trustServiceId = await anvil.readContract({
19
+ address: token,
20
+ abi: iDSTokenAbi,
21
+ functionName: "TRUST_SERVICE"
20
22
  });
21
- return hash;
23
+ const trustService = await anvil.readContract({
24
+ address: token,
25
+ abi: iDSTokenAbi,
26
+ functionName: "getDSService",
27
+ args: [trustServiceId]
28
+ });
29
+ if (isAddressEqual(trustService, token)) {
30
+ const admin = await anvil.readContract({
31
+ address: token,
32
+ abi: iMockDSTokenAdminAbi,
33
+ functionName: "admin"
34
+ });
35
+ logger?.debug(`securitize: found admin ${admin} for ${token} (token.admin)`);
36
+ return admin;
37
+ }
38
+ const word = await anvil.getStorageAt({
39
+ address: trustService,
40
+ slot: toHex(0, { size: 32 })
41
+ });
42
+ if (!word) throw new Error(`securitize: empty trust-service owner slot on ${trustService}`);
43
+ const admin = getAddress(slice(word, 12));
44
+ logger?.debug(`securitize: found admin ${admin} for ${token} (trust service ${trustService})`);
45
+ return admin;
22
46
  }
23
47
  /**
24
- * Resolves the account that performs the DS registry writes: either the admin
25
- * private key, or the admin address impersonated on the fork
48
+ * Impersonates the DS trust-service admin of `token` on the fork
26
49
  */
27
50
  async function useSecuritizeAdmin(props) {
28
- const { anvil, adminPrivateKey, admin, logger } = props;
29
- if (adminPrivateKey) return {
30
- account: privateKeyToAccount(adminPrivateKey),
31
- release: async () => {}
32
- };
33
- if (!admin) throw new Error("securitize: either adminPrivateKey or admin address is required");
51
+ const { anvil, token, logger } = props;
52
+ const admin = await getSecuritizeAdmin(anvil, token, logger);
34
53
  await anvil.impersonateAccount({ address: admin });
35
54
  await anvil.setBalance({
36
55
  address: admin,
@@ -98,36 +117,39 @@ async function registerSecuritizeInvestor(props) {
98
117
  const { account, release } = await useSecuritizeAdmin(props);
99
118
  try {
100
119
  if (!investorExists) {
101
- await writeAndWait(anvil, {
120
+ await anvil.writeContractSync({
102
121
  account,
103
122
  chain: anvil.chain,
104
123
  address: registryService,
105
124
  abi: iDSRegistryServiceAbi,
106
125
  functionName: "registerInvestor",
107
- args: [investorId, investorId]
126
+ args: [investorId, investorId],
127
+ throwOnReceiptRevert: true
108
128
  });
109
129
  logger?.debug(`Registered investor "${investorId}"`);
110
130
  }
111
- await writeAndWait(anvil, {
131
+ await anvil.writeContractSync({
112
132
  account,
113
133
  chain: anvil.chain,
114
134
  address: registryService,
115
135
  abi: iDSRegistryServiceAbi,
116
136
  functionName: "addWallet",
117
- args: [investor, investorId]
137
+ args: [investor, investorId],
138
+ throwOnReceiptRevert: true
118
139
  });
119
140
  logger?.debug(`Added wallet ${investor} for investor "${investorId}"`);
120
141
  try {
121
- await writeAndWait(anvil, {
142
+ await anvil.writeContractSync({
122
143
  account,
123
144
  chain: anvil.chain,
124
145
  address: registryService,
125
146
  abi: iDSRegistryServiceAbi,
126
147
  functionName: "setCountry",
127
- args: [investorId, "US"]
148
+ args: [investorId, "US"],
149
+ throwOnReceiptRevert: true
128
150
  });
129
151
  logger?.debug(`Set country for investor "${investorId}" to "US"`);
130
- await writeAndWait(anvil, {
152
+ await anvil.writeContractSync({
131
153
  account,
132
154
  chain: anvil.chain,
133
155
  address: registryService,
@@ -139,7 +161,8 @@ async function registerSecuritizeInvestor(props) {
139
161
  BigInt(APPROVED),
140
162
  MAX_UINT256,
141
163
  "fake proof"
142
- ]
164
+ ],
165
+ throwOnReceiptRevert: true
143
166
  });
144
167
  logger?.debug(`Set attributes for investor "${investorId}"`);
145
168
  } catch (e) {
@@ -241,13 +264,14 @@ async function greenlistMidasGateway(props) {
241
264
  logger?.debug(`midas: ${account} already has role ${role}`);
242
265
  continue;
243
266
  }
244
- await writeAndWait(anvil, {
267
+ await anvil.writeContractSync({
245
268
  account: admin,
246
269
  chain: anvil.chain,
247
270
  address: accessControl,
248
271
  abi: iMidasAccessControlAbi,
249
272
  functionName: "grantRole",
250
- args: [role, account]
273
+ args: [role, account],
274
+ throwOnReceiptRevert: true
251
275
  });
252
276
  logger?.debug(`midas: granted role ${role} to ${account}`);
253
277
  }
@@ -265,9 +289,7 @@ async function greenlistMidasGateway(props) {
265
289
  }
266
290
  }
267
291
  /**
268
- * Finds the Midas gateway that issues `token` by scanning the Midas gateway
269
- * adapters of all loaded credit managers, same as the foundry tests do with
270
- * `ICreditConfiguratorV3.allowedAdapters`
292
+ * Finds the Midas gateway that issues `token` among the loaded credit managers.
271
293
  */
272
294
  async function findMidasGateway(props) {
273
295
  const { anvil, token, marketConfigurators, logger } = props;
@@ -279,30 +301,18 @@ async function findMidasGateway(props) {
279
301
  });
280
302
  await sdk.attach({ marketConfigurators });
281
303
  }
282
- const candidates = collectMidasGateways(sdk);
283
- if (candidates.length === 0) throw new Error("no midas gateway adapters found in loaded markets");
284
- const index = (await anvil.multicall({
285
- allowFailure: false,
286
- contracts: candidates.map((address) => ({
287
- address,
288
- abi: midasGatewayAbi,
289
- functionName: "mToken"
290
- }))
291
- })).findIndex((mToken) => isAddressEqual(mToken, token));
292
- if (index === -1) throw new Error(`no midas gateway found for token ${token}`);
293
- logger?.debug(`midas: gateway for ${token} is ${candidates[index]}`);
294
- return candidates[index];
304
+ const suites = await discoverMidasCreditSuites(sdk);
305
+ if (suites.length === 0) throw new Error("no midas gateway adapters or midas degen NFTs found in loaded markets");
306
+ const suite = suites.find(({ mToken }) => isAddressEqual(mToken, token));
307
+ if (!suite) throw new Error(`no midas gateway found for token ${token}`);
308
+ logger?.debug(`midas: gateway for ${token} is ${suite.gateway}`);
309
+ return suite.gateway;
295
310
  }
296
311
  /**
297
- * Collects the target contracts of all Midas gateway adapters of the loaded
298
- * credit managers, same as the foundry tests do with
299
- * `ICreditConfiguratorV3.allowedAdapters`
312
+ * Midas access control admin on mainnet. Holds the admin role of the greenlist
313
+ * operator role.
300
314
  */
301
- function collectMidasGateways(sdk) {
302
- const gateways = new AddressSet();
303
- for (const cm of sdk.marketRegister.creditManagers) for (const adapter of cm.creditManager.adapters.values()) if (adapter.contractType === "ADAPTER::MIDAS_GATEWAY") gateways.add(adapter.targetContract);
304
- return gateways.asArray();
305
- }
315
+ const DEFAULT_MIDAS_ADMIN = "0xd4195CF4df289a4748C1A7B6dDBE770e27bA1227";
306
316
  /**
307
317
  * Registers a wallet as an investor (fake KYC) in every Securitize DSToken and
308
318
  * every Midas gateway of the markets loaded by `sdk`.
@@ -311,17 +321,15 @@ function collectMidasGateways(sdk) {
311
321
  * result instead of aborting the whole run.
312
322
  */
313
323
  async function registerRWAInvestor(props) {
314
- const { anvil, sdk, investor, adminPrivateKey, securitizeAdmin, midasAdmin = "0xd4195CF4df289a4748C1A7B6dDBE770e27bA1227", logger } = props;
324
+ const { anvil, sdk, investor, midasAdmin = DEFAULT_MIDAS_ADMIN, logger } = props;
315
325
  const securitizeTokens = [];
316
326
  const midasGateways = [];
317
327
  const failed = [];
318
328
  const dsTokens = new AddressSet(sdk.rwa.factories.flatMap((factory) => factory.getTokens()));
319
- if (adminPrivateKey || securitizeAdmin) for (const token of dsTokens) try {
329
+ for (const token of dsTokens) try {
320
330
  await registerSecuritizeInvestor({
321
331
  anvil,
322
332
  investor,
323
- adminPrivateKey,
324
- admin: securitizeAdmin,
325
333
  token,
326
334
  logger
327
335
  });
@@ -334,8 +342,7 @@ async function registerRWAInvestor(props) {
334
342
  error: e
335
343
  });
336
344
  }
337
- else if (dsTokens.size > 0) logger?.warn(`securitize: no registry admin, skipping ${dsTokens.size} DSToken(s)`);
338
- const gateways = collectMidasGateways(sdk);
345
+ const gateways = await discoverMidasGateways(sdk);
339
346
  for (const gateway of gateways) try {
340
347
  await greenlistMidasGateway({
341
348
  anvil,
@@ -361,4 +368,4 @@ async function registerRWAInvestor(props) {
361
368
  };
362
369
  }
363
370
  //#endregion
364
- export { greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor, writeAndWait };
371
+ export { DEFAULT_MIDAS_ADMIN, getSecuritizeAdmin, greenlistMidasGateway, registerMidasInvestor, registerRWAInvestor, registerSecuritizeInvestor };
@@ -1,5 +1,8 @@
1
- import { writeAndWait } from "./kycUtils.js";
2
- import { parseAbi, parseEther } from "viem";
1
+ import { AddressSet } from "../onchain/utils/AddressSet.js";
2
+ import { MidasGatewayAdapterContract } from "../onchain/market/adapters/contracts/MidasGatewayAdapterContract.js";
3
+ import { MidasDegenNFT } from "../onchain/market/rwa/midas/MidasDegenNFT.js";
4
+ import "../onchain/index.js";
5
+ import { parseAbi, parseEther, toFunctionSelector } from "viem";
3
6
  //#region src/dev/midasUtils.ts
4
7
  /**
5
8
  * Midas vaults inherit their own `Pausable`, whose global pause is guarded by
@@ -9,14 +12,24 @@ const iMidasPausableVaultAbi = parseAbi([
9
12
  "function paused() external view returns (bool)",
10
13
  "function pause() external",
11
14
  "function unpause() external",
15
+ "function fnPaused(bytes4 fn) external view returns (bool)",
16
+ "function pauseFn(bytes4 fn) external",
17
+ "function unpauseFn(bytes4 fn) external",
12
18
  "function pauseAdminRole() external view returns (bytes32)",
13
19
  "function accessControl() external view returns (address)"
14
20
  ]);
15
21
  const iMidasAccessControlAbi = parseAbi(["function hasRole(bytes32 role, address account) external view returns (bool)", "function grantRole(bytes32 role, address account) external"]);
16
22
  /**
17
- * Unpauses a globally paused Midas issuance vault on an anvil fork, so that
18
- * `depositInstant` stops reverting with `Pausable: paused`, and returns a
19
- * callback that restores the original pause state.
23
+ * Selector for `DepositVault.depositInstant(address,uint256,uint256,bytes32)`,
24
+ * the 4-arg mint Gearbox adapters encode. Distinct from the custom-recipient
25
+ * overload.
26
+ */
27
+ const DEPOSIT_INSTANT_SELECTOR = toFunctionSelector("depositInstant(address,uint256,uint256,bytes32)");
28
+ /**
29
+ * Unpauses a Midas issuance vault on an anvil fork so that `depositInstant`
30
+ * stops reverting with `Pausable: paused` (global) or `Pausable: fn paused`
31
+ * (per-selector), and returns a callback that restores the original pause
32
+ * state of each layer that was cleared.
20
33
  *
21
34
  * Impersonates `admin` and grants it `pauseAdminRole()` when missing, same as
22
35
  * `greenlistMidasGateway` does with the greenlist roles. The grant is not
@@ -24,11 +37,20 @@ const iMidasAccessControlAbi = parseAbi(["function hasRole(bytes32 role, address
24
37
  */
25
38
  async function unpauseMidasIssuanceVault(props) {
26
39
  const { anvil, vault, admin, logger } = props;
27
- if (!await anvil.readContract({
28
- address: vault,
29
- abi: iMidasPausableVaultAbi,
30
- functionName: "paused"
31
- })) {
40
+ const [paused, depositInstantPaused] = await anvil.multicall({
41
+ allowFailure: false,
42
+ contracts: [{
43
+ address: vault,
44
+ abi: iMidasPausableVaultAbi,
45
+ functionName: "paused"
46
+ }, {
47
+ address: vault,
48
+ abi: iMidasPausableVaultAbi,
49
+ functionName: "fnPaused",
50
+ args: [DEPOSIT_INSTANT_SELECTOR]
51
+ }]
52
+ });
53
+ if (!paused && !depositInstantPaused) {
32
54
  logger?.debug(`midas: issuance vault ${vault} is not paused`);
33
55
  return async () => {};
34
56
  }
@@ -50,7 +72,7 @@ async function unpauseMidasIssuanceVault(props) {
50
72
  functionName: "hasRole",
51
73
  args: [pauseAdminRole, admin]
52
74
  });
53
- logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}`);
75
+ logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}` + (paused ? ", global" : "") + (depositInstantPaused ? ", depositInstant" : ""));
54
76
  await anvil.impersonateAccount({ address: admin });
55
77
  try {
56
78
  await anvil.setBalance({
@@ -58,22 +80,33 @@ async function unpauseMidasIssuanceVault(props) {
58
80
  value: parseEther("100")
59
81
  });
60
82
  if (!isPauseAdmin) {
61
- await writeAndWait(anvil, {
83
+ await anvil.writeContractSync({
62
84
  account: admin,
63
85
  chain: anvil.chain,
64
86
  address: accessControl,
65
87
  abi: iMidasAccessControlAbi,
66
88
  functionName: "grantRole",
67
- args: [pauseAdminRole, admin]
89
+ args: [pauseAdminRole, admin],
90
+ throwOnReceiptRevert: true
68
91
  });
69
92
  logger?.debug(`midas: granted pause admin role to ${admin}`);
70
93
  }
71
- await writeAndWait(anvil, {
94
+ if (paused) await anvil.writeContractSync({
72
95
  account: admin,
73
96
  chain: anvil.chain,
74
97
  address: vault,
75
98
  abi: iMidasPausableVaultAbi,
76
- functionName: "unpause"
99
+ functionName: "unpause",
100
+ throwOnReceiptRevert: true
101
+ });
102
+ if (depositInstantPaused) await anvil.writeContractSync({
103
+ account: admin,
104
+ chain: anvil.chain,
105
+ address: vault,
106
+ abi: iMidasPausableVaultAbi,
107
+ functionName: "unpauseFn",
108
+ args: [DEPOSIT_INSTANT_SELECTOR],
109
+ throwOnReceiptRevert: true
77
110
  });
78
111
  } finally {
79
112
  await anvil.stopImpersonatingAccount({ address: admin });
@@ -89,12 +122,22 @@ async function unpauseMidasIssuanceVault(props) {
89
122
  address: admin,
90
123
  value: parseEther("100")
91
124
  });
92
- await writeAndWait(anvil, {
125
+ if (paused) await anvil.writeContractSync({
93
126
  account: admin,
94
127
  chain: anvil.chain,
95
128
  address: vault,
96
129
  abi: iMidasPausableVaultAbi,
97
- functionName: "pause"
130
+ functionName: "pause",
131
+ throwOnReceiptRevert: true
132
+ });
133
+ if (depositInstantPaused) await anvil.writeContractSync({
134
+ account: admin,
135
+ chain: anvil.chain,
136
+ address: vault,
137
+ abi: iMidasPausableVaultAbi,
138
+ functionName: "pauseFn",
139
+ args: [DEPOSIT_INSTANT_SELECTOR],
140
+ throwOnReceiptRevert: true
98
141
  });
99
142
  } catch (e) {
100
143
  logger?.warn(`midas: failed to pause issuance vault ${vault} back: ${e}`);
@@ -103,5 +146,56 @@ async function unpauseMidasIssuanceVault(props) {
103
146
  }
104
147
  };
105
148
  }
149
+ /**
150
+ * Midas credit suites of the loaded credit managers.
151
+ *
152
+ * A manager with a gateway adapter is a suite on its own, so its degen NFT
153
+ * is not consulted. Suites that only have a Midas degen NFT read `mToken`
154
+ * from the gateway.
155
+ */
156
+ async function discoverMidasCreditSuites(sdk) {
157
+ const suites = [];
158
+ for (const cm of sdk.marketRegister.creditManagers) {
159
+ const creditManager = cm.creditManager.address;
160
+ let hasAdapter = false;
161
+ for (const adapter of cm.creditManager.adapters.values()) if (adapter instanceof MidasGatewayAdapterContract) {
162
+ hasAdapter = true;
163
+ suites.push({
164
+ creditManager,
165
+ gateway: adapter.gateway,
166
+ mToken: adapter.mToken
167
+ });
168
+ }
169
+ if (hasAdapter) continue;
170
+ const nft = await cm.degenNFT();
171
+ if (nft instanceof MidasDegenNFT) {
172
+ const [mToken] = await nft.getTokens();
173
+ suites.push({
174
+ creditManager,
175
+ gateway: nft.gateway,
176
+ mToken
177
+ });
178
+ }
179
+ }
180
+ return suites;
181
+ }
182
+ /**
183
+ * Gateways of the Midas credit suites of the loaded credit managers.
184
+ */
185
+ async function discoverMidasGateways(sdk) {
186
+ const suites = await discoverMidasCreditSuites(sdk);
187
+ return new AddressSet(suites.map((suite) => suite.gateway)).asArray();
188
+ }
189
+ /**
190
+ * mTokens of the Midas credit suites of the loaded credit managers.
191
+ *
192
+ * A manager with a gateway adapter contributes that adapter's mToken, so its
193
+ * degen NFT is not consulted. Suites that only have a Midas degen NFT
194
+ * contribute the mToken read from the gateway.
195
+ */
196
+ async function discoverMidasMTokens(sdk) {
197
+ const suites = await discoverMidasCreditSuites(sdk);
198
+ return new AddressSet(suites.map((suite) => suite.mToken)).asArray();
199
+ }
106
200
  //#endregion
107
- export { unpauseMidasIssuanceVault };
201
+ export { discoverMidasCreditSuites, discoverMidasGateways, discoverMidasMTokens, unpauseMidasIssuanceVault };