@gearbox-protocol/sdk 16.3.0-next.3 → 16.3.0-next.4

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 (62) hide show
  1. package/dist/cjs/model/errors/operation-errors.js +1 -1
  2. package/dist/cjs/model/index.js +2 -2
  3. package/dist/cjs/model/rwa.js +4 -4
  4. package/dist/cjs/model/rwa.schema.js +4 -4
  5. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
  6. package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +1 -3
  7. package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  8. package/dist/cjs/onchain/market/credit/CreditSuite.js +19 -9
  9. package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  10. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +56 -12
  11. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  12. package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  13. package/dist/cjs/onchain/opportunities/OpportunitiesService.js +16 -4
  14. package/dist/cjs/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  15. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +1 -1
  16. package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  17. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +6 -5
  18. package/dist/cjs/sdk/execute/ExecuteApi.js +2 -2
  19. package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  20. package/dist/esm/model/errors/operation-errors.js +1 -1
  21. package/dist/esm/model/index.js +3 -3
  22. package/dist/esm/model/rwa.js +4 -4
  23. package/dist/esm/model/rwa.schema.js +5 -5
  24. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
  25. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +1 -3
  26. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  27. package/dist/esm/onchain/market/credit/CreditSuite.js +19 -9
  28. package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  29. package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
  30. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  31. package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  32. package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
  33. package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  34. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +1 -1
  35. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  36. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +6 -5
  37. package/dist/esm/sdk/execute/ExecuteApi.js +2 -2
  38. package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  39. package/dist/types/model/errors/operation-errors.d.ts +6 -4
  40. package/dist/types/model/index.d.ts +3 -3
  41. package/dist/types/model/opportunities.d.ts +4 -5
  42. package/dist/types/model/rwa.d.ts +47 -27
  43. package/dist/types/model/rwa.schema.d.ts +3 -3
  44. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
  45. package/dist/types/offchain/opportunities/types.d.ts +1 -4
  46. package/dist/types/onchain/accounts/types.d.ts +4 -2
  47. package/dist/types/onchain/index.d.ts +2 -2
  48. package/dist/types/onchain/market/credit/CreditSuite.d.ts +8 -3
  49. package/dist/types/onchain/market/index.d.ts +2 -2
  50. package/dist/types/onchain/market/rwa/index.d.ts +2 -2
  51. package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
  52. package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
  53. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
  54. package/dist/types/onchain/market/rwa/types.d.ts +39 -37
  55. package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
  56. package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
  57. package/dist/types/onchain/opportunities/types.d.ts +6 -1
  58. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
  59. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +3 -3
  60. package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
  61. package/dist/types/sdk/opportunities/types.d.ts +9 -3
  62. package/package.json +1 -1
@@ -7,8 +7,8 @@ import { FILTER_ALL, isFilterSet } from "./filters.js";
7
7
  import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
8
8
  import { curatorNameSchema, curatorSchema } from "./curators.schema.js";
9
9
  import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
10
- import { KYC_PROTOCOLS, KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES } from "./rwa.js";
11
- import { kycProtocolSchema, kycRequirementSchema } from "./rwa.schema.js";
10
+ import { KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES } from "./rwa.js";
11
+ import { kycRequirementSchema, rwaProtocolSchema } from "./rwa.schema.js";
12
12
  import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
13
13
  import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionsTotalsSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
14
14
  import { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema } from "./analytics.schema.js";
@@ -32,4 +32,4 @@ import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourc
32
32
  import { safeValue, sdkErr, sdkOk } from "./result.js";
33
33
  import "./withdrawals.js";
34
34
  import { positionClaimableWithdrawalSchema, positionPendingWithdrawalSchema, positionWithdrawalsSchema, withdrawalOutputAmountSchema } from "./withdrawals.schema.js";
35
- export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_PROTOCOLS, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycProtocolSchema, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAssetSchema, quotaCountExceeded, quotaLimitReached, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
35
+ export { ANALYTICS_POSITIONS_DEFAULT_LIMIT, ANALYTICS_POSITIONS_MAX_LIMIT, CHART_METRIC_UNITS, CHART_RANGES, CHART_UNAVAILABLE_CODES, FILTER_ALL, KYC_REGISTRATION_LINKS, POOL_OPPORTUNITY_CHART_METRICS, POOL_POSITION_CHART_METRICS, PROTOCOL_CHART_METRICS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES, STRATEGY_OPPORTUNITY_CHART_METRICS, STRATEGY_POSITION_CHART_METRICS, STRATEGY_POSITION_COLLATERAL_ERROR, amountSchema, analyticsChartQueryOptionsSchema, analyticsChartQueryParamsSchema, analyticsChartQuerySchema, analyticsPositionListOptionsSchema, analyticsPositionListQueryParamsSchema, analyticsPositionListQuerySchema, analyticsPositionPageSchema, analyticsPositionSchema, analyticsPositionSortFieldSchema, analyticsSortDirectionSchema, apyBreakdownSchema, asEstimated, assetTypeSchema, backendPreferred, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, chartBundleSchemaFor, chartDenominationSchema, chartMetricSchema, chartQueryCodec, chartQueryParamsSchema, chartQuerySchema, chartRangeSchema, chartSeriesSchema, chartValueSchema, chartWindowSchema, compareTagOf, creditAccountFrozen, creditAccountNotEmpty, creditAccountNotFound, creditManagerPaused, curatorNameSchema, curatorSchema, dataSourceSchema, debtOutOfRange, delayedReceivedAssetSchema, encodeFlag, filterAllSchema, filterable, forbiddenToken, instantReceivedAssetSchema, insufficientAllowance, insufficientBalance, insufficientCollateral, insufficientPoolLiquidity, isFilterSet, kycRequirementSchema, leverageOutOfRange, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, liquidatorNotEligible, malformedTransaction, marketExpired, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, multipleDelayedWithdrawals, noDelayedRoute, noRecordedIntent, noStrategyTargetCollateral, notEmergencyLiquidator, noticeKindSchema, noticeSchema, offchainOnly, onchainOnly, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, opportunityTotalsSchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolOpportunityChartMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPaused, poolPositionChartMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, poolSunset, positionClaimableWithdrawalSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionId, positionKeySchema, positionKindSchema, positionPendingWithdrawalSchema, positionSchema, positionTransactionKindSchema, positionTransactionSchema, positionWithdrawalsSchema, positionsTotalsSchema, priceFeedDataSchema, priceFeedSummarySchema, protocolChartMetricSchema, quotaAssetSchema, quotaCountExceeded, quotaLimitReached, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, rwaOpenRequirementsNotMet, rwaProtocolSchema, safeValue, sdkErr, sdkOk, strategyOpportunityChartMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionChartMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenQuotaRateSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, tolerance, txCallSchema, underlyingTokenSchema, unexpectedFailure, unpriceableTokenError, unsupportedCollateralToken, unsupportedTokenPair, withdrawalInProgress, withdrawalOutputAmountSchema };
@@ -34,15 +34,15 @@ const SECURITIZE_REGISTER_VAULT_TYPES = { RegisterVault: [
34
34
  }
35
35
  ] };
36
36
  /**
37
- * KYC providers a strategy may be gated by
37
+ * RWA protocols that require dedicated flows
38
38
  **/
39
- const KYC_PROTOCOLS = ["securitize", "midas"];
39
+ const RWA_PROTOCOLS = ["securitize", "midas"];
40
40
  /**
41
- * Hardcoded registration URLs for each {@link KycProtocol}.
41
+ * Hardcoded registration URLs for each {@link RWAProtocol}.
42
42
  **/
43
43
  const KYC_REGISTRATION_LINKS = {
44
44
  securitize: "https://securitize.io/",
45
45
  midas: "https://form.typeform.com/to/DqZaw6kr"
46
46
  };
47
47
  //#endregion
48
- export { KYC_PROTOCOLS, KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, SECURITIZE_REGISTER_VAULT_TYPES };
48
+ export { KYC_REGISTRATION_LINKS, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_PROTOCOLS, SECURITIZE_REGISTER_VAULT_TYPES };
@@ -1,18 +1,18 @@
1
1
  import { tokenSchema } from "./primitives.schema.js";
2
- import { KYC_PROTOCOLS } from "./rwa.js";
2
+ import { RWA_PROTOCOLS } from "./rwa.js";
3
3
  import { z } from "zod/v4";
4
4
  //#region src/model/rwa.schema.ts
5
5
  /**
6
- * {@link ./rwa.js#KycProtocol}
6
+ * {@link ./rwa.js#RWAProtocol}
7
7
  **/
8
- const kycProtocolSchema = z.enum(KYC_PROTOCOLS);
8
+ const rwaProtocolSchema = z.enum(RWA_PROTOCOLS);
9
9
  /**
10
10
  * {@link ./rwa.js#KycRequirement}
11
11
  **/
12
12
  const kycRequirementSchema = z.object({
13
- protocol: kycProtocolSchema,
13
+ protocol: rwaProtocolSchema,
14
14
  token: tokenSchema.optional(),
15
15
  registrationLink: z.string()
16
16
  });
17
17
  //#endregion
18
- export { kycProtocolSchema, kycRequirementSchema };
18
+ export { kycRequirementSchema, rwaProtocolSchema };
@@ -35,7 +35,7 @@ var OffchainOpportunities = class extends AbstractOffchainNamespace {
35
35
  /**
36
36
  * {@inheritDoc IOffchainOpportunities.getStrategy}
37
37
  **/
38
- async getStrategy(key, _wallet) {
38
+ async getStrategy(key) {
39
39
  return this.get({
40
40
  path: this.#strategyPath(key),
41
41
  schema: strategyOpportunityDetailSchema
@@ -188,9 +188,7 @@ var CreditAccountsServiceV310 = class extends SDKConstruct {
188
188
  * {@inheritDoc ICreditAccountsService.getOpenAccountRequirements}
189
189
  */
190
190
  async getOpenAccountRequirements(borrower, creditManager, props) {
191
- const { rwaFactory } = this.sdk.marketRegister.findCreditManager(creditManager);
192
- if (!rwaFactory) return;
193
- return rwaFactory.getOpenAccountRequirements(borrower, props);
191
+ return (await this.sdk.marketRegister.findCreditManager(creditManager).degenNFT())?.getOpenAccountRequirements(borrower, props);
194
192
  }
195
193
  /**
196
194
  * {@inheritDoc ICreditAccountsService.openCA}
@@ -9,9 +9,9 @@ import "../../utils/index.js";
9
9
  import { SDKConstruct } from "../../base/SDKConstruct.js";
10
10
  import "../../base/index.js";
11
11
  import { usdToNumber } from "../../market/math.js";
12
+ import { RWA_LIQUIDATOR_MIDAS } from "../../market/rwa/midas/constants.js";
12
13
  import { matchesLiquidatableAccountFilter } from "../../../model/liquidations.js";
13
14
  import "../../../model/index.js";
14
- import { RWA_LIQUIDATOR_MIDAS } from "../../market/rwa/midas/constants.js";
15
15
  import { RWA_LIQUIDATOR_SECURITIZE } from "../../market/rwa/securitize/constants.js";
16
16
  import { dominantCollateral } from "../../market/credit/collateralUtils.js";
17
17
  import { MidasLiquidatorContract } from "../../market/rwa/midas/MidasLiquidatorContract.js";
@@ -7,8 +7,6 @@ import "../../utils/index.js";
7
7
  import { SDKConstruct } from "../../base/SDKConstruct.js";
8
8
  import "../../base/index.js";
9
9
  import { calcBorrowApy, calcQuotaRate, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount } from "../math.js";
10
- import { KYC_REGISTRATION_LINKS } from "../../../model/rwa.js";
11
- import "../../../model/index.js";
12
10
  import { createDegenNFT } from "../rwa/createDegenNFT.js";
13
11
  import { strategyName } from "../strategyName.js";
14
12
  import { dominantCollateral, isStrategyCollateral, pickStrategyTargetCollateral } from "./collateralUtils.js";
@@ -125,25 +123,37 @@ var CreditSuite = class extends SDKConstruct {
125
123
  degenNFT() {
126
124
  const address = this.creditFacade.degenNFT;
127
125
  if (isAddressEqual(address, "0x0000000000000000000000000000000000000000")) return Promise.resolve(void 0);
126
+ const factoryNft = this.rwaFactory?.degenNFT;
127
+ if (factoryNft && isAddressEqual(factoryNft.address, address)) return Promise.resolve(factoryNft);
128
128
  if (!this.#degenNFT) this.#degenNFT = createDegenNFT(this.sdk, address);
129
129
  return this.#degenNFT;
130
130
  }
131
131
  /**
132
- * What `wallet` still has to do before the facade lets it open an account;
133
- * `null` when nothing (no degen NFT, not a KYC gate, or already eligible).
132
+ * The KYC gate of this suite's strategy; `null` when there is none.
133
+ * Wallet-independent.
134
134
  */
135
- async kycRequirement(wallet, targetCollateral) {
135
+ async kycRequirement(targetCollateral) {
136
136
  const nft = await this.degenNFT();
137
137
  if (!nft) return null;
138
- const { eligible, token } = await nft.checkKyc(wallet, targetCollateral);
139
- if (eligible) return null;
138
+ const tokens = await nft.getTokens();
139
+ const token = tokens.find((t) => isAddressEqual(t, targetCollateral)) ?? tokens[0];
140
140
  return {
141
141
  protocol: nft.protocol,
142
- token: this.tokensMeta.getToken(token),
143
- registrationLink: KYC_REGISTRATION_LINKS[nft.protocol]
142
+ token: token ? this.tokensMeta.getToken(token) : void 0,
143
+ registrationLink: nft.registrationLink
144
144
  };
145
145
  }
146
146
  /**
147
+ * Whether `wallet` may open this suite's strategy today; `true` when there
148
+ * is no KYC gate.
149
+ */
150
+ async isEligibleForStrategy(wallet, targetCollateral) {
151
+ const nft = await this.degenNFT();
152
+ if (!nft) return true;
153
+ const requirements = await nft.getOpenAccountRequirements(wallet, { tokenOutAddress: targetCollateral });
154
+ return nft.isRegistered(requirements);
155
+ }
156
+ /**
147
157
  * Builds a transaction that executes a multicall on one of this suite's
148
158
  * credit accounts.
149
159
  *
@@ -5,14 +5,23 @@ import "../../adapters/abi/index.js";
5
5
  import { iMidasDegenNFTAbi } from "../../../../abi/rwa/iMidasDegenNFT.js";
6
6
  import "./constants.js";
7
7
  import { iMidasAccessControlAbi } from "../../../../abi/rwa/iMidasAccessControl.js";
8
+ import { KYC_REGISTRATION_LINKS } from "../../../../model/rwa.js";
9
+ import "../../../../model/index.js";
8
10
  import { decodeAbiParameters } from "viem";
9
11
  //#region src/onchain/market/rwa/midas/MidasDegenNFT.ts
10
12
  const abi = iMidasDegenNFTAbi;
13
+ /**
14
+ * Midas is an RWA protocol without a factory: accounts open through the plain
15
+ * facade. Only a Permissioned-mode gateway deploys a degen NFT, so a Midas
16
+ * strategy that does not require KYC has no NFT at all.
17
+ */
11
18
  var MidasDegenNFT = class extends BaseContract {
12
19
  protocol = "midas";
20
+ registrationLink = KYC_REGISTRATION_LINKS.midas;
13
21
  gateway;
14
22
  accessControl;
15
23
  greenlistedRole;
24
+ #mToken;
16
25
  constructor(sdk, baseParams) {
17
26
  super(sdk, {
18
27
  ...baseParams,
@@ -30,9 +39,26 @@ var MidasDegenNFT = class extends BaseContract {
30
39
  this.accessControl = accessControl;
31
40
  this.greenlistedRole = greenlistedRole;
32
41
  }
33
- /** Same predicate `MidasDegenNFT.burn` reverts on; the mToken rides along in the batch. */
34
- async checkKyc(wallet, _targetCollateral) {
35
- const [eligible, token] = await this.client.multicall({
42
+ async getTokens() {
43
+ return [await this.#mTokenAddress()];
44
+ }
45
+ /**
46
+ * Same predicate `MidasDegenNFT.burn` reverts on; the mToken rides along in
47
+ * the batch until it is cached.
48
+ */
49
+ async getOpenAccountRequirements(wallet, _props) {
50
+ const token = this.#mToken;
51
+ if (token !== void 0) return {
52
+ protocol: "midas",
53
+ token,
54
+ greenlisted: await this.client.readContract({
55
+ abi: iMidasAccessControlAbi,
56
+ address: this.accessControl,
57
+ functionName: "hasRole",
58
+ args: [this.greenlistedRole, wallet]
59
+ })
60
+ };
61
+ const [greenlisted, mToken] = await this.client.multicall({
36
62
  allowFailure: false,
37
63
  contracts: [{
38
64
  abi: iMidasAccessControlAbi,
@@ -45,11 +71,25 @@ var MidasDegenNFT = class extends BaseContract {
45
71
  functionName: "mToken"
46
72
  }]
47
73
  });
74
+ this.#mToken = mToken;
48
75
  return {
49
- eligible,
50
- token
76
+ protocol: "midas",
77
+ token: mToken,
78
+ greenlisted
51
79
  };
52
80
  }
81
+ isRegistered(requirements) {
82
+ return requirements.greenlisted;
83
+ }
84
+ getMissingRequirements() {}
85
+ async #mTokenAddress() {
86
+ if (this.#mToken === void 0) this.#mToken = await this.client.readContract({
87
+ abi: iMidasGatewayV311Abi,
88
+ address: this.gateway,
89
+ functionName: "mToken"
90
+ });
91
+ return this.#mToken;
92
+ }
53
93
  };
54
94
  //#endregion
55
95
  export { MidasDegenNFT };
@@ -1,13 +1,23 @@
1
+ import { AddressSet } from "../../../utils/AddressSet.js";
2
+ import "../../../utils/index.js";
1
3
  import { BaseContract } from "../../../base/BaseContract.js";
2
4
  import "../../../base/index.js";
5
+ import { KYC_REGISTRATION_LINKS } from "../../../../model/rwa.js";
6
+ import "../../../../model/index.js";
3
7
  import { DEGEN_NFT_SECURITIZE } from "./constants.js";
4
8
  import { iSecuritizeDegenNFTAbi } from "../../../../abi/rwa/iSecuritizeDegenNFT.js";
5
- import { isAddressEqual } from "viem";
6
9
  //#region src/onchain/market/rwa/securitize/SecuritizeDegenNFT.ts
7
10
  const abi = iSecuritizeDegenNFTAbi;
11
+ /**
12
+ * Securitize always has a factory, which deploys this NFT. DS-token data,
13
+ * registrars and cached signatures live here; the factory only builds txs
14
+ * and looks up investor/wallet addresses.
15
+ */
8
16
  var SecuritizeDegenNFT = class extends BaseContract {
9
17
  protocol = "securitize";
18
+ registrationLink = KYC_REGISTRATION_LINKS.securitize;
10
19
  factory;
20
+ #sdk;
11
21
  constructor(sdk, address, factory) {
12
22
  super(sdk, {
13
23
  addr: address,
@@ -16,19 +26,54 @@ var SecuritizeDegenNFT = class extends BaseContract {
16
26
  name: "SecuritizeDegenNFT",
17
27
  abi
18
28
  });
29
+ this.#sdk = sdk;
19
30
  this.factory = factory;
20
31
  }
21
- /** Registration on Securitize is the only KYC step; pending EIP-712 signatures are not. */
22
- async checkKyc(wallet, targetCollateral) {
23
- const { factory } = this;
24
- if (!factory.getTokens().some((t) => isAddressEqual(t, targetCollateral))) return {
25
- eligible: true,
26
- token: targetCollateral
32
+ async getTokens() {
33
+ return this.factory.getTokens();
34
+ }
35
+ /**
36
+ * Registration on Securitize is the protocol-side KYC step; pending
37
+ * EIP-712 signatures are tx-side leftover, not KYC.
38
+ */
39
+ async getOpenAccountRequirements(wallet, props) {
40
+ const tokensToRegister = new AddressSet(this.factory.getTokens()).has(props.tokenOutAddress) ? new AddressSet([props.tokenOutAddress]) : new AddressSet();
41
+ if (tokensToRegister.size === 0) return {
42
+ protocol: "securitize",
43
+ factory: this.factory.address,
44
+ securitizeTokensToRegister: [],
45
+ tokensToRegister: [],
46
+ requiredSignatures: []
47
+ };
48
+ const [investorData] = await this.#sdk.rwa.getInvestorData(wallet, [this.factory.address]);
49
+ const registredTokens = new AddressSet(investorData.registeredTokens);
50
+ const signedTokens = new AddressSet(investorData.cachedSignatures.map((s) => s.token));
51
+ const unsignedTokens = tokensToRegister.difference(signedTokens);
52
+ const securitizeTokensToRegister = tokensToRegister.difference(registredTokens);
53
+ const requiredSignatures = investorData.registerVaultMessages.filter((m) => unsignedTokens.has(m.message.token));
54
+ return {
55
+ protocol: "securitize",
56
+ factory: this.factory.address,
57
+ securitizeTokensToRegister: Array.from(securitizeTokensToRegister),
58
+ tokensToRegister: Array.from(tokensToRegister),
59
+ requiredSignatures
27
60
  };
28
- const req = await factory.getOpenAccountRequirements(wallet, { tokenOutAddress: targetCollateral });
61
+ }
62
+ isRegistered(requirements) {
63
+ return requirements.securitizeTokensToRegister.length === 0;
64
+ }
65
+ /**
66
+ * A required signature is omitted when `providedArgs.signaturesToCache`
67
+ * already carries a signature for the same token: the transaction caches it
68
+ * on-chain as part of the operation.
69
+ */
70
+ getMissingRequirements(requirements, providedArgs) {
71
+ const providedTokens = new AddressSet((providedArgs?.signaturesToCache ?? []).map((s) => s.token));
72
+ const requiredSignatures = requirements.requiredSignatures.filter((message) => !providedTokens.has(message.message.token));
73
+ if (requiredSignatures.length === 0) return;
29
74
  return {
30
- eligible: !req || req.securitizeTokensToRegister.length === 0,
31
- token: req?.securitizeTokensToRegister[0] ?? targetCollateral
75
+ protocol: "securitize",
76
+ requiredSignatures
32
77
  };
33
78
  }
34
79
  };
@@ -1,5 +1,4 @@
1
1
  import { AddressMap } from "../../../utils/AddressMap.js";
2
- import { AddressSet } from "../../../utils/AddressSet.js";
3
2
  import "../../../utils/index.js";
4
3
  import { BaseContract } from "../../../base/BaseContract.js";
5
4
  import "../../../base/index.js";
@@ -11,7 +10,6 @@ import { decodeAbiParameters } from "viem";
11
10
  //#region src/onchain/market/rwa/securitize/SecuritizeRWAFactory.ts
12
11
  const abi = iSecuritizeRWAFactoryAbi;
13
12
  var SecuritizeRWAFactory = class extends BaseContract {
14
- #sdk;
15
13
  #investorCache = new AddressMap();
16
14
  degenNFT;
17
15
  owner;
@@ -23,7 +21,6 @@ var SecuritizeRWAFactory = class extends BaseContract {
23
21
  name: "SecuritizeRWAFactory",
24
22
  abi
25
23
  });
26
- this.#sdk = sdk;
27
24
  const decoded = decodeAbiParameters([
28
25
  {
29
26
  name: "owner",
@@ -184,40 +181,6 @@ var SecuritizeRWAFactory = class extends BaseContract {
184
181
  });
185
182
  }
186
183
  /**
187
- * {@inheritDoc IRWAFactory.getOpenAccountRequirements}
188
- */
189
- async getOpenAccountRequirements(investor, props) {
190
- const [investorData] = await this.#sdk.rwa.getInvestorData(investor, [this.address]);
191
- const tokensToRegister = new AddressSet([props.tokenOutAddress]);
192
- const registredTokens = new AddressSet(investorData.registeredTokens);
193
- const signedTokens = new AddressSet(investorData.cachedSignatures.map((s) => s.token));
194
- const unsignedTokens = tokensToRegister.difference(signedTokens);
195
- const securitizeTokensToRegister = tokensToRegister.difference(registredTokens);
196
- const requiredSignatures = investorData.registerVaultMessages.filter((m) => unsignedTokens.has(m.message.token));
197
- return {
198
- type: RWA_FACTORY_SECURITIZE,
199
- securitizeTokensToRegister: Array.from(securitizeTokensToRegister),
200
- tokensToRegister: Array.from(tokensToRegister),
201
- requiredSignatures
202
- };
203
- }
204
- /**
205
- * {@inheritDoc IRWAFactory.getMissingRequirements}
206
- *
207
- * A required signature is omitted when `providedArgs.signaturesToCache`
208
- * already carries a signature for the same token: the transaction caches it
209
- * on-chain as part of the operation.
210
- */
211
- getMissingRequirements(requirements, providedArgs) {
212
- const providedTokens = new AddressSet((providedArgs?.signaturesToCache ?? []).map((s) => s.token));
213
- const requiredSignatures = requirements.requiredSignatures.filter((message) => !providedTokens.has(message.message.token));
214
- if (requiredSignatures.length === 0) return;
215
- return {
216
- type: RWA_FACTORY_SECURITIZE,
217
- requiredSignatures
218
- };
219
- }
220
- /**
221
184
  * {@inheritDoc IRWAFactory.openCreditAccount}
222
185
  */
223
186
  openCreditAccount(creditManager, calls, args) {
@@ -37,12 +37,18 @@ var MultichainOpportunitiesService = class extends MultichainConstruct {
37
37
  *
38
38
  * See {@link MultichainOpportunitiesService.getPool}.
39
39
  **/
40
- async getStrategy(key, wallet) {
40
+ async getStrategy(key) {
41
41
  return this.queryChain({
42
42
  network: key.chainId,
43
- run: (sdk) => sdk.opportunities.getStrategy(key, wallet)
43
+ run: (sdk) => sdk.opportunities.getStrategy(key)
44
44
  });
45
45
  }
46
+ /**
47
+ * {@inheritDoc OpportunitiesService.isEligibleForStrategy}
48
+ **/
49
+ async isEligibleForStrategy(key, wallet) {
50
+ return this.sdk.chain(key.chainId).opportunities.isEligibleForStrategy(key, wallet);
51
+ }
46
52
  };
47
53
  //#endregion
48
54
  export { MultichainOpportunitiesService };
@@ -36,22 +36,34 @@ var OpportunitiesService = class extends SDKConstruct {
36
36
  * A single strategy opportunity plus the rate curve of the pool it borrows
37
37
  * from and the price feeds its liquidation price depends on.
38
38
  *
39
- * @param wallet - When given, `kyc` says whether this wallet must register
40
- * with the strategy's KYC provider first; `null` otherwise.
39
+ * `kyc` is the strategy's KYC gate, independent of any wallet.
41
40
  *
42
41
  * @throws If the credit manager is unknown, or does not currently offer a
43
42
  * strategy.
44
43
  **/
45
- async getStrategy(key, wallet) {
44
+ async getStrategy(key) {
46
45
  const suite = this.sdk.marketRegister.findCreditManager(key.creditManager);
47
46
  const detail = suite.strategyOpportunityDetail();
48
47
  if (!detail) throw new Error(`credit manager ${key.creditManager} does not currently offer a strategy`);
49
- const kyc = wallet ? await suite.kycRequirement(wallet, detail.targetCollateral.address) : null;
48
+ const kyc = await suite.kycRequirement(detail.targetCollateral.address);
50
49
  return {
51
50
  ...detail,
52
51
  kyc
53
52
  };
54
53
  }
54
+ /**
55
+ * Whether `wallet` may open this strategy today: `true` when it is not
56
+ * KYC-gated or the wallet already passed the gate.
57
+ *
58
+ * @throws If the credit manager is unknown, or does not currently offer a
59
+ * strategy.
60
+ **/
61
+ async isEligibleForStrategy(key, wallet) {
62
+ const suite = this.sdk.marketRegister.findCreditManager(key.creditManager);
63
+ const opportunity = suite.strategyOpportunity();
64
+ if (!opportunity) throw new Error(`credit manager ${key.creditManager} does not currently offer a strategy`);
65
+ return suite.isEligibleForStrategy(wallet, opportunity.targetCollateral.address);
66
+ }
55
67
  };
56
68
  //#endregion
57
69
  export { OpportunitiesService };
@@ -1,7 +1,7 @@
1
1
  import { hexEq } from "../../utils/hex.js";
2
2
  import { AbstractAdapterContract } from "../../market/adapters/contracts/AbstractAdapter.js";
3
3
  import { CreditFacadeV310Contract } from "../../market/credit/CreditFacadeV310Contract.js";
4
- import { RWA_FACTORY_SECURITIZE } from "../../../model/rwa.js";
4
+ import "../../../model/rwa.js";
5
5
  import "../../../model/index.js";
6
6
  import { isRWAFactory } from "../../market/rwa/types.js";
7
7
  import { classifyInnerOperations } from "./classifyInnerOperations.js";
@@ -32,7 +32,7 @@ function parseSecuritizeOperationCalldata(sdk, factory, calldata) {
32
32
  const { rawArgs } = parsed;
33
33
  const innerCalls = rawArgs.calls ?? [];
34
34
  const args = {
35
- type: RWA_FACTORY_SECURITIZE,
35
+ protocol: "securitize",
36
36
  tokensToRegister: [...rawArgs.tokensToRegister ?? []],
37
37
  signaturesToCache: [...rawArgs.signaturesToCache ?? []]
38
38
  };
@@ -50,7 +50,7 @@ async function checkCreditOperation(args) {
50
50
  preview,
51
51
  sender,
52
52
  blockNumber
53
- }), preview.operation === "RWAOpenCreditAccount" ? checkRWAOpening({
53
+ }), preview.operation === "OpenCreditAccount" || preview.operation === "RWAOpenCreditAccount" ? checkRWAOpening({
54
54
  sdk,
55
55
  preview,
56
56
  sender
@@ -5,24 +5,24 @@ import { toToken } from "../helpers/token.js";
5
5
  import "../helpers/index.js";
6
6
  //#region src/onchain/validation/bundles/checkRWAOpenRequirements.ts
7
7
  /**
8
- * The RWA factory is satisfied that `wallet` may open on `token` with the
8
+ * The degen NFT is satisfied that `wallet` may open on `token` with the
9
9
  * registration args already on the transaction.
10
10
  */
11
11
  async function checkRWAOpenRequirements(input) {
12
12
  const { sdk, wallet, creditManager, token, providedArgs } = input;
13
13
  try {
14
- const requirements = await sdk.accounts.getOpenAccountRequirements(wallet, creditManager, { tokenOutAddress: token });
15
- if (!requirements) return [];
16
- const { rwaFactory } = sdk.marketRegister.findByCreditManager(creditManager);
17
- if (!rwaFactory) throw new Error(`no RWA factory for credit manager ${creditManager}`);
18
- const missing = rwaFactory.getMissingRequirements(requirements, providedArgs);
19
- if (!missing && requirements.securitizeTokensToRegister.length === 0) return [];
14
+ const nft = await sdk.marketRegister.findCreditManager(creditManager).degenNFT();
15
+ if (!nft) return [];
16
+ const requirements = await nft.getOpenAccountRequirements(wallet, { tokenOutAddress: token });
17
+ const missing = nft.getMissingRequirements(requirements, providedArgs);
18
+ if (!missing && nft.isRegistered(requirements)) return [];
20
19
  return [rwaOpenRequirementsNotMet({
21
20
  token: toToken(sdk, token),
22
21
  creditManager,
23
- factory: rwaFactory.address,
22
+ protocol: nft.protocol,
23
+ registrationLink: nft.registrationLink,
24
24
  requirements,
25
- ...missing === void 0 ? {} : { missing }
25
+ missing
26
26
  })];
27
27
  } catch (cause) {
28
28
  return [unexpectedFailure(cause, "read the RWA opening requirements")];
@@ -2,21 +2,22 @@ import { AddressSet } from "../../utils/AddressSet.js";
2
2
  import { checkRWAOpenRequirements } from "./checkRWAOpenRequirements.js";
3
3
  //#region src/onchain/validation/bundles/checkRWAOpening.ts
4
4
  /**
5
- * Per factory-gated token among `collateralAdded ∪ quotas`, whether the
5
+ * Per KYC-gated token among `collateralAdded ∪ quotas`, whether the
6
6
  * borrower still has to register or sign before this opening can land.
7
7
  */
8
8
  async function checkRWAOpening(input) {
9
9
  const { sdk, preview, sender } = input;
10
- const { rwaFactory } = sdk.marketRegister.findByCreditManager(preview.creditManager);
11
- if (!rwaFactory) return [];
12
- const gated = new AddressSet(rwaFactory.getTokens());
10
+ const nft = await sdk.marketRegister.findCreditManager(preview.creditManager).degenNFT();
11
+ if (!nft) return [];
12
+ const gated = new AddressSet(await nft.getTokens());
13
13
  const candidates = new AddressSet([...preview.collateralAdded.map((a) => a.token.address), ...preview.quotas.map((q) => q.token.address)]);
14
+ const providedArgs = preview.operation === "RWAOpenCreditAccount" ? preview.rwaArgs : void 0;
14
15
  return (await Promise.all([...candidates].filter((token) => gated.has(token)).map((token) => checkRWAOpenRequirements({
15
16
  sdk,
16
17
  wallet: sender,
17
18
  creditManager: preview.creditManager,
18
19
  token,
19
- providedArgs: preview.rwaArgs
20
+ providedArgs
20
21
  })))).flat();
21
22
  }
22
23
  //#endregion
@@ -73,9 +73,9 @@ async function openTx(sdk, request) {
73
73
  async function openRwaOptions(sdk, request) {
74
74
  if (!request.targetToken) return;
75
75
  const requirements = await sdk.accounts.getOpenAccountRequirements(request.wallet, request.creditManager, { tokenOutAddress: request.targetToken });
76
- if (!requirements) return;
76
+ if (requirements?.protocol !== "securitize") return;
77
77
  return {
78
- type: requirements.type,
78
+ protocol: "securitize",
79
79
  tokensToRegister: requirements.tokensToRegister,
80
80
  signaturesToCache: request.signaturesToCache ?? []
81
81
  };
@@ -70,15 +70,21 @@ var OpportunitiesNamespace = class extends AbstractNamespace {
70
70
  /**
71
71
  * {@inheritDoc IOpportunitiesBase.getStrategy}
72
72
  **/
73
- async getStrategy(key, wallet) {
73
+ async getStrategy(key) {
74
74
  return this.merged("get strategy opportunity", {
75
75
  chainIds: [key.chainId],
76
- fromChain: (source) => source.getStrategy(key, wallet),
77
- fromBackend: (source) => source.getStrategy(key, wallet),
76
+ fromChain: (source) => source.getStrategy(key),
77
+ fromBackend: (source) => source.getStrategy(key),
78
78
  merge: this.merge.strategy
79
79
  });
80
80
  }
81
81
  /**
82
+ * {@inheritDoc IOpportunitiesOnchainOnly.isEligibleForStrategy}
83
+ **/
84
+ async isEligibleForStrategy(key, wallet) {
85
+ return this.onchain.isEligibleForStrategy(key, wallet);
86
+ }
87
+ /**
82
88
  * {@inheritDoc IOpportunitiesBase.filter}
83
89
  **/
84
90
  filter(response, filter) {
@@ -1,6 +1,6 @@
1
1
  import { Bps, Token, TokenAmount } from "../primitives.js";
2
2
  import { IGearboxError } from "./base.js";
3
- import { RWAMissingOpenAccountRequirements, RWAOpenAccountRequirements } from "../rwa.js";
3
+ import { RWAMissingOpenAccountRequirements, RWAOpenAccountRequirements, RWAProtocol } from "../rwa.js";
4
4
  import { MaxBorrowAmount } from "../../onchain/market/credit/types.js";
5
5
  import "../../onchain/index.js";
6
6
  import { Address } from "viem";
@@ -201,17 +201,19 @@ interface InsufficientAllowanceError extends IGearboxError {
201
201
  /** {@inheritDoc InsufficientAllowanceError} */
202
202
  declare function insufficientAllowance(args: Omit<InsufficientAllowanceError, "code" | "message">): InsufficientAllowanceError;
203
203
  /**
204
- * The RWA factory still wants something from the borrower before this token
204
+ * The RWA protocol still wants something from the borrower before this token
205
205
  * can be opened on.
206
206
  **/
207
207
  interface RWAOpenRequirementsError extends IGearboxError {
208
208
  code: "rwaOpenRequirementsNotMet";
209
209
  token: Token;
210
210
  creditManager: Address;
211
- factory: Address;
211
+ protocol: RWAProtocol;
212
+ /** Where the wallet completes registration with {@link protocol}. */
213
+ registrationLink: string;
212
214
  /** Always present on the error. */
213
215
  requirements: RWAOpenAccountRequirements;
214
- /** Absent when only issuer-side registration is pending. */
216
+ /** Absent when only issuer-side registration is pending (or Midas greenlist). */
215
217
  missing?: RWAMissingOpenAccountRequirements;
216
218
  }
217
219
  /** {@inheritDoc RWAOpenRequirementsError} */