@gearbox-protocol/sdk 14.0.0 → 14.1.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 (109) hide show
  1. package/dist/cjs/abi/kyc/iDSRegistryService.js +149 -0
  2. package/dist/cjs/abi/kyc/iDSToken.js +71 -0
  3. package/dist/cjs/abi/kyc/iKYCCompressor.js +196 -0
  4. package/dist/cjs/abi/kyc/iKYCFactory.js +122 -0
  5. package/dist/cjs/abi/kyc/iKYCUnderlying.js +401 -0
  6. package/dist/cjs/abi/kyc/iSecuritizeDegenNFT.js +326 -0
  7. package/dist/cjs/abi/kyc/iSecuritizeKYCFactory.js +319 -0
  8. package/dist/cjs/dev/AccountOpener.js +45 -5
  9. package/dist/cjs/sdk/OnchainSDK.js +55 -5
  10. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +335 -21
  11. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  12. package/dist/cjs/sdk/base/TokensMeta.js +22 -42
  13. package/dist/cjs/sdk/base/token-types.js +9 -0
  14. package/dist/cjs/sdk/chain/chains.js +18 -1
  15. package/dist/cjs/sdk/constants/address-provider.js +3 -0
  16. package/dist/cjs/sdk/market/MarketRegister.js +70 -116
  17. package/dist/cjs/sdk/market/MarketSuite.js +3 -0
  18. package/dist/cjs/sdk/market/index.js +2 -0
  19. package/dist/cjs/sdk/market/kyc/KYCRegistry.js +269 -0
  20. package/dist/cjs/sdk/market/kyc/index.js +26 -0
  21. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +242 -0
  22. package/dist/cjs/sdk/market/kyc/securitize/constants.js +28 -0
  23. package/dist/cjs/sdk/market/kyc/securitize/index.js +26 -0
  24. package/dist/cjs/sdk/market/kyc/securitize/types.js +16 -0
  25. package/dist/cjs/sdk/{accounts/utils.js → market/kyc/types.js} +11 -15
  26. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  27. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +11 -2
  28. package/dist/cjs/sdk/market/pool/index.js +2 -0
  29. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  30. package/dist/cjs/sdk/options.js +6 -0
  31. package/dist/cjs/sdk/pools/PoolService.js +104 -12
  32. package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +38 -0
  33. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  34. package/dist/esm/abi/kyc/iDSRegistryService.js +125 -0
  35. package/dist/esm/abi/kyc/iDSToken.js +47 -0
  36. package/dist/esm/abi/kyc/iKYCCompressor.js +172 -0
  37. package/dist/esm/abi/kyc/iKYCFactory.js +98 -0
  38. package/dist/esm/abi/kyc/iKYCUnderlying.js +377 -0
  39. package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +302 -0
  40. package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +295 -0
  41. package/dist/esm/dev/AccountOpener.js +47 -6
  42. package/dist/esm/sdk/OnchainSDK.js +57 -5
  43. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +336 -22
  44. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  45. package/dist/esm/sdk/base/TokensMeta.js +22 -44
  46. package/dist/esm/sdk/base/token-types.js +6 -0
  47. package/dist/esm/sdk/chain/chains.js +18 -1
  48. package/dist/esm/sdk/constants/address-provider.js +2 -0
  49. package/dist/esm/sdk/market/MarketRegister.js +74 -118
  50. package/dist/esm/sdk/market/MarketSuite.js +3 -0
  51. package/dist/esm/sdk/market/index.js +1 -0
  52. package/dist/esm/sdk/market/kyc/KYCRegistry.js +253 -0
  53. package/dist/esm/sdk/market/kyc/index.js +3 -0
  54. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +218 -0
  55. package/dist/esm/sdk/market/kyc/securitize/constants.js +4 -0
  56. package/dist/esm/sdk/market/kyc/securitize/index.js +3 -0
  57. package/dist/esm/sdk/market/kyc/securitize/types.js +0 -0
  58. package/dist/esm/sdk/market/kyc/types.js +9 -0
  59. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  60. package/dist/esm/sdk/market/pool/PoolV310Contract.js +11 -2
  61. package/dist/esm/sdk/market/pool/index.js +1 -0
  62. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  63. package/dist/esm/sdk/options.js +6 -0
  64. package/dist/esm/sdk/pools/PoolService.js +109 -13
  65. package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +14 -0
  66. package/dist/esm/sdk/utils/viem/index.js +1 -0
  67. package/dist/types/abi/kyc/iDSRegistryService.d.ts +191 -0
  68. package/dist/types/abi/kyc/iDSToken.d.ts +67 -0
  69. package/dist/types/abi/kyc/iKYCCompressor.d.ts +228 -0
  70. package/dist/types/abi/kyc/iKYCFactory.d.ts +139 -0
  71. package/dist/types/abi/kyc/iKYCUnderlying.d.ts +548 -0
  72. package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +404 -0
  73. package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +376 -0
  74. package/dist/types/sdk/OnchainSDK.d.ts +19 -1
  75. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +59 -6
  76. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  77. package/dist/types/sdk/accounts/types.d.ts +114 -14
  78. package/dist/types/sdk/base/TokensMeta.d.ts +14 -3
  79. package/dist/types/sdk/base/token-types.d.ts +44 -4
  80. package/dist/types/sdk/base/types.d.ts +116 -2
  81. package/dist/types/sdk/chain/chains.d.ts +5 -1
  82. package/dist/types/sdk/constants/address-provider.d.ts +1 -0
  83. package/dist/types/sdk/market/MarketRegister.d.ts +6 -9
  84. package/dist/types/sdk/market/MarketSuite.d.ts +2 -0
  85. package/dist/types/sdk/market/index.d.ts +1 -0
  86. package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +52 -0
  87. package/dist/types/sdk/market/kyc/index.d.ts +3 -0
  88. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +429 -0
  89. package/dist/types/sdk/market/kyc/securitize/constants.d.ts +1 -0
  90. package/dist/types/sdk/market/kyc/securitize/index.d.ts +3 -0
  91. package/dist/types/sdk/market/kyc/securitize/types.d.ts +136 -0
  92. package/dist/types/sdk/market/kyc/types.d.ts +171 -0
  93. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +3 -2
  94. package/dist/types/sdk/market/oracle/types.d.ts +3 -10
  95. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  96. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  97. package/dist/types/sdk/market/pool/index.d.ts +1 -0
  98. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
  99. package/dist/types/sdk/market/types.d.ts +1 -1
  100. package/dist/types/sdk/options.d.ts +1 -0
  101. package/dist/types/sdk/pools/PoolService.d.ts +8 -8
  102. package/dist/types/sdk/pools/types.d.ts +1 -1
  103. package/dist/types/sdk/types/state-human.d.ts +2 -0
  104. package/dist/types/sdk/types/state.d.ts +5 -0
  105. package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +28 -0
  106. package/dist/types/sdk/utils/viem/index.d.ts +1 -0
  107. package/package.json +1 -1
  108. package/dist/esm/sdk/accounts/utils.js +0 -14
  109. package/dist/types/sdk/accounts/utils.d.ts +0 -2
@@ -0,0 +1,253 @@
1
+ import { decodeAbiParameters } from "viem";
2
+ import { iKYCCompressorAbi } from "../../../abi/kyc/iKYCCompressor.js";
3
+ import {
4
+ KYC_ON_DEMAND_LP_MONOPOLIZED,
5
+ KYC_UNDERLYING_DEFAULT,
6
+ KYC_UNDERLYING_ON_DEMAND,
7
+ SDKConstruct
8
+ } from "../../base/index.js";
9
+ import { AP_KYC_COMPRESSOR, VERSION_RANGE_310 } from "../../constants/index.js";
10
+ import { AddressMap, bytes32ToString } from "../../utils/index.js";
11
+ import {
12
+ KYC_FACTORY_SECURITIZE,
13
+ SecuritizeKYCFactory
14
+ } from "./securitize/index.js";
15
+ class KYCRegistry extends SDKConstruct {
16
+ #state;
17
+ #factories = new AddressMap();
18
+ /**
19
+ * @internal
20
+ *
21
+ * Returns delegated multicalls for loading all KYC underlying tokens from the on-chain KYC compressor.
22
+ * Used by the SDK to compose batched RPC calls.
23
+ *
24
+ * @param configurators - Market configurators to query.
25
+ * @param kycFactories - KYC factory contracts to query.
26
+ */
27
+ getLoadMulticalls(configurators, kycFactories = []) {
28
+ if (!kycFactories.length) return [];
29
+ const [kycCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
30
+ AP_KYC_COMPRESSOR,
31
+ VERSION_RANGE_310
32
+ );
33
+ return [
34
+ {
35
+ call: {
36
+ abi: iKYCCompressorAbi,
37
+ address: kycCompressorAddress,
38
+ functionName: "getKYCMarketsData",
39
+ args: [configurators, kycFactories]
40
+ },
41
+ onResult: (resp) => this.setState(resp)
42
+ }
43
+ ];
44
+ }
45
+ /**
46
+ * Fetches decoded investor data from the on-chain KYC compressor.
47
+ *
48
+ * Each factory produces its own investor data (e.g. registered tokens,
49
+ * cached signatures, EIP-712 messages to sign).
50
+ *
51
+ * @param investor - Investor EOA address.
52
+ * @param factories_ - Optional subset of factory addresses to query.
53
+ * When omitted, all loaded factories are used.
54
+ */
55
+ async getInvestorData(investor, factories_) {
56
+ const [kycCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
57
+ AP_KYC_COMPRESSOR,
58
+ VERSION_RANGE_310
59
+ );
60
+ let factories = this.#factories.values();
61
+ if (factories_?.length) {
62
+ factories = factories_.map((f) => this.#factories.mustGet(f));
63
+ }
64
+ const resp = await this.client.readContract({
65
+ abi: iKYCCompressorAbi,
66
+ address: kycCompressorAddress,
67
+ functionName: "getKYCInvestorData",
68
+ args: [investor, factories.map((f) => f.address)]
69
+ });
70
+ const result = [];
71
+ for (let i = 0; i < factories.length; i++) {
72
+ const factory = factories[i];
73
+ const factoryData = resp[i];
74
+ const investorData = factory.decodeInvestorData(factoryData);
75
+ result.push(investorData);
76
+ }
77
+ return result;
78
+ }
79
+ /** All loaded KYC factory instances. */
80
+ get factories() {
81
+ return this.#factories.values();
82
+ }
83
+ /** Raw KYC compressor response, or `undefined` before attach/hydrate. */
84
+ get state() {
85
+ return this.#state;
86
+ }
87
+ /**
88
+ * Returns a human-readable snapshot of the KYC state.
89
+ */
90
+ stateHuman(raw) {
91
+ return {
92
+ factories: this.factories.map((f) => f.stateHuman(raw))
93
+ };
94
+ }
95
+ /**
96
+ * @internal
97
+ *
98
+ * Replaces the internal state with a new KYC compressor response.
99
+ * Rebuilds token metadata for KYC underlyings and re-instantiates factory
100
+ * wrappers.
101
+ */
102
+ setState(resp) {
103
+ this.#state = resp;
104
+ for (const u of resp?.[0] ?? []) {
105
+ this.#loadUnderlyingTokenData(u);
106
+ }
107
+ this.#factories.clear();
108
+ for (const f of resp?.[1] ?? []) {
109
+ this.#loadKYCFactoryData(f);
110
+ }
111
+ }
112
+ #loadUnderlyingTokenData(u) {
113
+ const contractType = bytes32ToString(u.baseParams.contractType);
114
+ const meta = this.tokensMeta.get(u.baseParams.addr);
115
+ if (!meta) {
116
+ throw new Error(
117
+ `KYC underlying token ${contractType} (${u.baseParams.addr}) not found in tokensMeta`
118
+ );
119
+ }
120
+ switch (contractType) {
121
+ case KYC_UNDERLYING_DEFAULT:
122
+ this.#loadKYCUnderlyingDefault(meta, u);
123
+ break;
124
+ case KYC_UNDERLYING_ON_DEMAND:
125
+ this.#loadKYCUnderlyingOnDemand(meta, u);
126
+ break;
127
+ default:
128
+ if (this.sdk.strictContractTypes) {
129
+ throw new Error(`Unknown KYC underlying type: ${contractType}`);
130
+ }
131
+ this.logger?.warn(`unknown KYC underlying type: ${contractType}`);
132
+ }
133
+ }
134
+ #loadKYCUnderlyingDefault(meta, data) {
135
+ const decoded = decodeAbiParameters(
136
+ [
137
+ { name: "factory", type: "address" },
138
+ { name: "asset", type: "address" }
139
+ ],
140
+ data.baseParams.serializedParams
141
+ );
142
+ this.tokensMeta.upsert(data.baseParams.addr, {
143
+ ...meta,
144
+ contractType: KYC_UNDERLYING_DEFAULT,
145
+ kycFactory: decoded[0],
146
+ asset: decoded[1]
147
+ });
148
+ }
149
+ #loadKYCUnderlyingOnDemand(meta, data) {
150
+ const decoded = decodeAbiParameters(
151
+ [
152
+ { name: "factory", type: "address" },
153
+ { name: "asset", type: "address" },
154
+ { name: "pool", type: "address" },
155
+ { name: "liquidityProvider", type: "address" },
156
+ { name: "marketConfigurator", type: "address" },
157
+ { name: "allowedDepositors", type: "address[]" }
158
+ ],
159
+ data.baseParams.serializedParams
160
+ );
161
+ const lpMeta = this.#getOnDemandLPMeta(data.extraDetails);
162
+ if (decoded[3] !== lpMeta.addr) {
163
+ throw new Error(
164
+ `Liquidity provider mismatch: ${decoded[3]} !== ${lpMeta.addr} for on-demand underlying ${data.baseParams.addr}`
165
+ );
166
+ }
167
+ this.tokensMeta.upsert(data.baseParams.addr, {
168
+ ...meta,
169
+ contractType: KYC_UNDERLYING_ON_DEMAND,
170
+ kycFactory: decoded[0],
171
+ asset: decoded[1],
172
+ pool: decoded[2],
173
+ marketConfigurator: decoded[4],
174
+ allowedDepositors: decoded[5],
175
+ // liquidityProvider: decoded[3],
176
+ liquidityProvider: lpMeta
177
+ });
178
+ }
179
+ #getOnDemandLPMeta(extraDetails) {
180
+ const [decoded] = decodeAbiParameters(
181
+ [
182
+ {
183
+ name: "baseParams",
184
+ type: "tuple",
185
+ components: [
186
+ { name: "addr", type: "address" },
187
+ { name: "version", type: "uint256" },
188
+ { name: "contractType", type: "bytes32" },
189
+ { name: "serializedParams", type: "bytes" }
190
+ ]
191
+ }
192
+ ],
193
+ extraDetails
194
+ );
195
+ const contractType = bytes32ToString(decoded.contractType);
196
+ switch (contractType) {
197
+ case KYC_ON_DEMAND_LP_MONOPOLIZED:
198
+ return this.#getOnDemandLPMonopolizedMeta(
199
+ decoded.addr,
200
+ decoded.version,
201
+ decoded.serializedParams
202
+ );
203
+ default:
204
+ throw new Error(`Unknown on-demand LP contract type: ${contractType}`);
205
+ }
206
+ }
207
+ #getOnDemandLPMonopolizedMeta(addr, version, serializedParams) {
208
+ const [marketConfigurator, depositor, pools] = decodeAbiParameters(
209
+ [
210
+ { name: "marketConfigurator", type: "address" },
211
+ { name: "depositor", type: "address" },
212
+ {
213
+ name: "pools",
214
+ type: "tuple[]",
215
+ components: [
216
+ { name: "pool", type: "address" },
217
+ { name: "wrappedUnderlying", type: "address" },
218
+ { name: "unwrappedUnderlying", type: "address" },
219
+ { name: "depositAllowance", type: "uint256" },
220
+ { name: "claimableAmount", type: "uint256" }
221
+ ]
222
+ }
223
+ ],
224
+ serializedParams
225
+ );
226
+ return {
227
+ addr,
228
+ version,
229
+ contractType: KYC_ON_DEMAND_LP_MONOPOLIZED,
230
+ marketConfigurator,
231
+ depositor,
232
+ pools: [...pools]
233
+ };
234
+ }
235
+ #loadKYCFactoryData(data) {
236
+ const contractType = bytes32ToString(data.baseParams.contractType);
237
+ switch (contractType) {
238
+ case KYC_FACTORY_SECURITIZE:
239
+ this.#factories.upsert(
240
+ data.baseParams.addr,
241
+ new SecuritizeKYCFactory(this.sdk, data)
242
+ );
243
+ break;
244
+ default:
245
+ throw new Error(
246
+ `Unknown KYC factory type: ${contractType} for ${data.baseParams.addr}`
247
+ );
248
+ }
249
+ }
250
+ }
251
+ export {
252
+ KYCRegistry
253
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./KYCRegistry.js";
2
+ export * from "./securitize/index.js";
3
+ export * from "./types.js";
@@ -0,0 +1,218 @@
1
+ import { decodeAbiParameters } from "viem";
2
+ import { iSecuritizeKYCFactoryAbi } from "../../../../abi/kyc/iSecuritizeKYCFactory.js";
3
+ import { BaseContract } from "../../../base/index.js";
4
+ import { AddressMap, AddressSet } from "../../../utils/index.js";
5
+ import { KYC_FACTORY_SECURITIZE } from "./constants.js";
6
+ const abi = iSecuritizeKYCFactoryAbi;
7
+ class SecuritizeKYCFactory extends BaseContract {
8
+ #sdk;
9
+ #investorCache = new AddressMap();
10
+ degenNFT;
11
+ owner;
12
+ dsTokens;
13
+ contractType = KYC_FACTORY_SECURITIZE;
14
+ constructor(sdk, data) {
15
+ super(sdk, {
16
+ ...data.baseParams,
17
+ name: "SecuritizeKYCFactory",
18
+ abi
19
+ });
20
+ this.#sdk = sdk;
21
+ const decoded = decodeAbiParameters(
22
+ [
23
+ { name: "owner", type: "address" },
24
+ { name: "degenNFT", type: "address" },
25
+ {
26
+ name: "dsTokensData",
27
+ type: "tuple[]",
28
+ components: [
29
+ { name: "token", type: "address" },
30
+ { name: "registrar", type: "address" },
31
+ { name: "operators", type: "address[]" }
32
+ ]
33
+ }
34
+ ],
35
+ data.baseParams.serializedParams
36
+ );
37
+ this.owner = decoded[0];
38
+ this.degenNFT = decoded[1];
39
+ for (const t of data.tokens) {
40
+ this.tokensMeta.upsert(t.addr, t);
41
+ }
42
+ this.dsTokens = decoded[2].map((t) => ({
43
+ address: t.token,
44
+ registrar: t.registrar,
45
+ operators: [...t.operators]
46
+ }));
47
+ }
48
+ /**
49
+ * {@inheritDoc IKYCFactory.decodeInvestorData}
50
+ */
51
+ decodeInvestorData(data) {
52
+ const { creditAccounts, extraDetails } = data;
53
+ const [registeredTokens, cachedSignatures, registerVaultMessages] = decodeAbiParameters(
54
+ [
55
+ { name: "registeredTokens", type: "address[]" },
56
+ {
57
+ name: "cachedSignatures",
58
+ type: "tuple[]",
59
+ components: [...registerMessageTuple]
60
+ },
61
+ {
62
+ name: "registerVaultMessages",
63
+ type: "tuple[]",
64
+ components: [...registerVaultMessageTuple]
65
+ }
66
+ ],
67
+ extraDetails
68
+ );
69
+ return {
70
+ type: KYC_FACTORY_SECURITIZE,
71
+ factory: this.address,
72
+ cachedSignatures: [...cachedSignatures],
73
+ registerVaultMessages: [...registerVaultMessages],
74
+ registeredTokens: [...registeredTokens],
75
+ creditAccounts: creditAccounts.map((ca) => {
76
+ const [registeredTokens2] = decodeAbiParameters(
77
+ [{ name: "registeredTokens", type: "address[]" }],
78
+ ca.extraDetails
79
+ );
80
+ return {
81
+ ...ca,
82
+ registeredTokens: [...registeredTokens2]
83
+ };
84
+ })
85
+ };
86
+ }
87
+ /**
88
+ * {@inheritDoc IKYCFactory.getInvestor}
89
+ */
90
+ async getInvestor(creditAccount, fromCache) {
91
+ if (fromCache && this.#investorCache.has(creditAccount)) {
92
+ return this.#investorCache.mustGet(creditAccount);
93
+ }
94
+ const investor = await this.contract.read.getInvestor([creditAccount]);
95
+ if (fromCache) {
96
+ this.#investorCache.upsert(creditAccount, investor);
97
+ }
98
+ return investor;
99
+ }
100
+ /**
101
+ * {@inheritDoc IKYCFactory.getApprovalAddress}
102
+ */
103
+ async getApprovalAddress(options) {
104
+ if ("creditAccount" in options) {
105
+ return this.getWallet(options.creditAccount);
106
+ }
107
+ return this.#precomputeWalletAddress(
108
+ options.creditManager,
109
+ options.borrower
110
+ );
111
+ }
112
+ /**
113
+ * {@inheritDoc IKYCFactory.getWallet}
114
+ */
115
+ async getWallet(creditAccount) {
116
+ return this.contract.read.getWallet([creditAccount]);
117
+ }
118
+ /**
119
+ * {@inheritDoc IKYCFactory.multicall}
120
+ */
121
+ multicall(creditAccount, calls, options) {
122
+ const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
123
+ return this.createRawTx({
124
+ functionName: "multicall",
125
+ args: [creditAccount, calls, tokensToRegister, signaturesToCache]
126
+ });
127
+ }
128
+ /**
129
+ * {@inheritDoc IKYCFactory.getOpenAccountRequirements}
130
+ */
131
+ async getOpenAccountRequirements(investor, props) {
132
+ const [investorData] = await this.#sdk.kyc.getInvestorData(investor, [
133
+ this.address
134
+ ]);
135
+ const tokensToRegister = new AddressSet([props.tokenOutAddress]);
136
+ const registredTokens = new AddressSet(investorData.registeredTokens);
137
+ const signedTokens = new AddressSet(
138
+ investorData.cachedSignatures.map((s) => s.token)
139
+ );
140
+ const unsignedTokens = tokensToRegister.difference(signedTokens);
141
+ const securitizeTokensToRegister = tokensToRegister.difference(registredTokens);
142
+ const requiredSignatures = investorData.registerVaultMessages.filter(
143
+ (m) => unsignedTokens.has(m.token)
144
+ );
145
+ return {
146
+ type: KYC_FACTORY_SECURITIZE,
147
+ securitizeTokensToRegister: Array.from(securitizeTokensToRegister),
148
+ tokensToRegister: Array.from(tokensToRegister),
149
+ requiredSignatures
150
+ };
151
+ }
152
+ /**
153
+ * {@inheritDoc IKYCFactory.openCreditAccount}
154
+ */
155
+ openCreditAccount(creditManager, calls, options) {
156
+ const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
157
+ return this.createRawTx({
158
+ functionName: "openCreditAccount",
159
+ args: [creditManager, calls, tokensToRegister, signaturesToCache]
160
+ });
161
+ }
162
+ stateHuman(_raw) {
163
+ return {
164
+ ...super.stateHuman(_raw),
165
+ owner: this.labelAddress(this.owner),
166
+ degenNFT: this.labelAddress(this.degenNFT),
167
+ dsTokens: this.dsTokens.map((t) => ({
168
+ ...this.tokensMeta.mustGet(t.address),
169
+ registrar: this.labelAddress(t.registrar),
170
+ operators: t.operators.map((o) => this.labelAddress(o))
171
+ }))
172
+ };
173
+ }
174
+ /**
175
+ * Precomputes the wallet address that will own a new credit account
176
+ * for the given investor in the given credit manager.
177
+ *
178
+ * @param creditManager - credit manager address
179
+ * @param investor - investor address
180
+ **/
181
+ async #precomputeWalletAddress(creditManager, investor) {
182
+ return this.contract.read.precomputeWalletAddress([
183
+ creditManager,
184
+ investor
185
+ ]);
186
+ }
187
+ }
188
+ const registerMessageTuple = [
189
+ { name: "token", type: "address" },
190
+ {
191
+ name: "signature",
192
+ type: "tuple",
193
+ components: [
194
+ { name: "deadline", type: "uint256" },
195
+ { name: "signature", type: "bytes" }
196
+ ]
197
+ }
198
+ ];
199
+ const registerVaultMessageTuple = [
200
+ {
201
+ name: "domain",
202
+ type: "tuple",
203
+ components: [
204
+ { name: "name", type: "string" },
205
+ { name: "version", type: "string" },
206
+ { name: "chainId", type: "uint256" },
207
+ { name: "verifyingContract", type: "address" }
208
+ ]
209
+ },
210
+ { name: "investor", type: "address" },
211
+ { name: "operator", type: "address" },
212
+ { name: "token", type: "address" },
213
+ { name: "nonce", type: "uint256" },
214
+ { name: "deadline", type: "uint256" }
215
+ ];
216
+ export {
217
+ SecuritizeKYCFactory
218
+ };
@@ -0,0 +1,4 @@
1
+ const KYC_FACTORY_SECURITIZE = "KYC_FACTORY::SECURITIZE";
2
+ export {
3
+ KYC_FACTORY_SECURITIZE
4
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./constants.js";
2
+ export * from "./SecuritizeKYCFactory.js";
3
+ export * from "./types.js";
File without changes
@@ -0,0 +1,9 @@
1
+ import { KYC_FACTORY_SECURITIZE } from "./securitize/index.js";
2
+ const KYC_FACTORY_TYPES = [KYC_FACTORY_SECURITIZE];
3
+ function isKYCFactory(factory, type) {
4
+ return factory.contractType === type;
5
+ }
6
+ export {
7
+ KYC_FACTORY_TYPES,
8
+ isKYCFactory
9
+ };
@@ -55,6 +55,9 @@ class PoolSuite extends SDKConstruct {
55
55
  get underlying() {
56
56
  return this.pool.underlying;
57
57
  }
58
+ get kycFactory() {
59
+ return this.pool.kycFactory;
60
+ }
58
61
  get dirty() {
59
62
  return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
60
63
  }
@@ -10,13 +10,15 @@ import {
10
10
  const abi = [...iPoolV310Abi, ...iPausableAbi];
11
11
  class PoolV310Contract extends BaseContract {
12
12
  creditManagerDebtParams;
13
- constructor(options, data) {
13
+ #sdk;
14
+ constructor(sdk, data) {
14
15
  const { baseParams, creditManagerDebtParams, ...rest } = data;
15
- super(options, {
16
+ super(sdk, {
16
17
  ...data.baseParams,
17
18
  name: `PoolV3(${data.name})`,
18
19
  abi
19
20
  });
21
+ this.#sdk = sdk;
20
22
  Object.assign(this, rest);
21
23
  this.creditManagerDebtParams = new AddressMap(
22
24
  creditManagerDebtParams.map((p) => [p.creditManager, p])
@@ -28,6 +30,13 @@ class PoolV310Contract extends BaseContract {
28
30
  symbol: data.symbol
29
31
  });
30
32
  }
33
+ get kycFactory() {
34
+ const meta = this.#sdk.tokensMeta.mustGet(this.underlying);
35
+ if (this.#sdk.tokensMeta.isKYCUnderlying(meta)) {
36
+ return this.#sdk.mustGetContract(meta.kycFactory);
37
+ }
38
+ return void 0;
39
+ }
31
40
  stateHuman(raw = true) {
32
41
  return {
33
42
  ...super.stateHuman(raw),
@@ -1,4 +1,5 @@
1
1
  export * from "./GaugeContract.js";
2
2
  export * from "./LinearInterestRateModelContract.js";
3
3
  export * from "./PoolSuite.js";
4
+ export * from "./PoolV310Contract.js";
4
5
  export * from "./types.js";
@@ -221,13 +221,13 @@ class PriceFeedRegister extends SDKConstruct {
221
221
  * Loads PARTIAL information about all updatable price feeds from MarketCompressor
222
222
  * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
223
223
  */
224
- async getPartialUpdatablePriceFeeds(configurators, pools) {
224
+ async getPartialUpdatablePriceFeeds(configurators) {
225
225
  const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
226
226
  AP_PRICE_FEED_COMPRESSOR,
227
227
  VERSION_RANGE_310
228
228
  );
229
229
  this.logger?.debug(
230
- { configurators, pools },
230
+ { configurators },
231
231
  `calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`
232
232
  );
233
233
  const result = await this.client.readContract({
@@ -237,7 +237,7 @@ class PriceFeedRegister extends SDKConstruct {
237
237
  args: [
238
238
  {
239
239
  configurators,
240
- pools: pools ?? [],
240
+ pools: [],
241
241
  underlying: ADDRESS_0X0
242
242
  }
243
243
  ],
@@ -23,6 +23,12 @@ const AttachOptionsSchema = z.object({
23
23
  addressProvider: ZodAddress().optional(),
24
24
  /** Addresses of market configurator contracts to load. */
25
25
  marketConfigurators: z.array(ZodAddress()).optional(),
26
+ /**
27
+ * Addresses of KYC factory contracts to load.
28
+ * If not set, all default KYC factories for the chain are loaded
29
+ * (from {@link GearboxChain.kycFactories})
30
+ **/
31
+ kycFactories: z.array(ZodAddress()).optional(),
26
32
  /** Pin SDK to a specific block number during attach. */
27
33
  blockNumber: z.union([z.bigint().nonnegative(), z.number().int().nonnegative()]).optional(),
28
34
  /** Skip fetching updatable price feeds on attach and sync. */