@gearbox-protocol/sdk 13.6.0 → 13.7.0-kyc.2

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 +70 -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/history/errors.js +2 -0
  10. package/dist/cjs/sdk/GearboxSDK.js +51 -4
  11. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +324 -16
  12. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  13. package/dist/cjs/sdk/base/TokensMeta.js +32 -43
  14. package/dist/cjs/sdk/base/token-types.js +9 -0
  15. package/dist/cjs/sdk/chain/chains.js +2 -1
  16. package/dist/cjs/sdk/constants/address-provider.js +3 -0
  17. package/dist/cjs/sdk/market/MarketRegister.js +70 -116
  18. package/dist/cjs/sdk/market/MarketSuite.js +3 -0
  19. package/dist/cjs/sdk/market/index.js +2 -0
  20. package/dist/cjs/sdk/market/kyc/KYCRegistry.js +269 -0
  21. package/dist/cjs/sdk/market/kyc/index.js +26 -0
  22. package/dist/cjs/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +244 -0
  23. package/dist/cjs/sdk/market/kyc/securitize/constants.js +28 -0
  24. package/dist/cjs/sdk/market/kyc/securitize/index.js +26 -0
  25. package/dist/cjs/sdk/market/kyc/securitize/types.js +16 -0
  26. package/dist/cjs/sdk/market/kyc/types.js +34 -0
  27. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  28. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +11 -2
  29. package/dist/cjs/sdk/market/pool/index.js +2 -0
  30. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  31. package/dist/cjs/sdk/options.js +6 -0
  32. package/dist/cjs/sdk/pools/PoolService.js +104 -12
  33. package/dist/cjs/sdk/utils/viem/executeDelegatedMulticalls.js +38 -0
  34. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  35. package/dist/esm/abi/kyc/iDSRegistryService.js +46 -0
  36. package/dist/esm/abi/kyc/iDSToken.js +47 -0
  37. package/dist/esm/abi/kyc/iKYCCompressor.js +172 -0
  38. package/dist/esm/abi/kyc/iKYCFactory.js +98 -0
  39. package/dist/esm/abi/kyc/iKYCUnderlying.js +377 -0
  40. package/dist/esm/abi/kyc/iSecuritizeDegenNFT.js +302 -0
  41. package/dist/esm/abi/kyc/iSecuritizeKYCFactory.js +295 -0
  42. package/dist/esm/dev/AccountOpener.js +47 -6
  43. package/dist/esm/history/errors.js +2 -0
  44. package/dist/esm/sdk/GearboxSDK.js +55 -5
  45. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +328 -17
  46. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +7 -1
  47. package/dist/esm/sdk/base/TokensMeta.js +32 -45
  48. package/dist/esm/sdk/base/token-types.js +6 -0
  49. package/dist/esm/sdk/chain/chains.js +2 -1
  50. package/dist/esm/sdk/constants/address-provider.js +2 -0
  51. package/dist/esm/sdk/market/MarketRegister.js +74 -118
  52. package/dist/esm/sdk/market/MarketSuite.js +3 -0
  53. package/dist/esm/sdk/market/index.js +1 -0
  54. package/dist/esm/sdk/market/kyc/KYCRegistry.js +253 -0
  55. package/dist/esm/sdk/market/kyc/index.js +3 -0
  56. package/dist/esm/sdk/market/kyc/securitize/SecuritizeKYCFactory.js +220 -0
  57. package/dist/esm/sdk/market/kyc/securitize/constants.js +4 -0
  58. package/dist/esm/sdk/market/kyc/securitize/index.js +3 -0
  59. package/dist/esm/sdk/market/kyc/securitize/types.js +0 -0
  60. package/dist/esm/sdk/market/kyc/types.js +9 -0
  61. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  62. package/dist/esm/sdk/market/pool/PoolV310Contract.js +11 -2
  63. package/dist/esm/sdk/market/pool/index.js +1 -0
  64. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -3
  65. package/dist/esm/sdk/options.js +6 -0
  66. package/dist/esm/sdk/pools/PoolService.js +109 -13
  67. package/dist/esm/sdk/utils/viem/executeDelegatedMulticalls.js +14 -0
  68. package/dist/esm/sdk/utils/viem/index.js +1 -0
  69. package/dist/types/abi/kyc/iDSRegistryService.d.ts +71 -0
  70. package/dist/types/abi/kyc/iDSToken.d.ts +67 -0
  71. package/dist/types/abi/kyc/iKYCCompressor.d.ts +228 -0
  72. package/dist/types/abi/kyc/iKYCFactory.d.ts +139 -0
  73. package/dist/types/abi/kyc/iKYCUnderlying.d.ts +548 -0
  74. package/dist/types/abi/kyc/iSecuritizeDegenNFT.d.ts +404 -0
  75. package/dist/types/abi/kyc/iSecuritizeKYCFactory.d.ts +376 -0
  76. package/dist/types/sdk/GearboxSDK.d.ts +7 -0
  77. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +52 -2
  78. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  79. package/dist/types/sdk/accounts/types.d.ts +93 -13
  80. package/dist/types/sdk/base/TokensMeta.d.ts +14 -3
  81. package/dist/types/sdk/base/token-types.d.ts +44 -4
  82. package/dist/types/sdk/base/types.d.ts +116 -2
  83. package/dist/types/sdk/chain/chains.d.ts +5 -1
  84. package/dist/types/sdk/constants/address-provider.d.ts +1 -0
  85. package/dist/types/sdk/market/MarketRegister.d.ts +6 -9
  86. package/dist/types/sdk/market/MarketSuite.d.ts +2 -0
  87. package/dist/types/sdk/market/index.d.ts +1 -0
  88. package/dist/types/sdk/market/kyc/KYCRegistry.d.ts +52 -0
  89. package/dist/types/sdk/market/kyc/index.d.ts +3 -0
  90. package/dist/types/sdk/market/kyc/securitize/SecuritizeKYCFactory.d.ts +428 -0
  91. package/dist/types/sdk/market/kyc/securitize/constants.d.ts +1 -0
  92. package/dist/types/sdk/market/kyc/securitize/index.d.ts +3 -0
  93. package/dist/types/sdk/market/kyc/securitize/types.d.ts +127 -0
  94. package/dist/types/sdk/market/kyc/types.d.ts +170 -0
  95. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +3 -2
  96. package/dist/types/sdk/market/oracle/types.d.ts +3 -10
  97. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  98. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  99. package/dist/types/sdk/market/pool/index.d.ts +1 -0
  100. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +1 -1
  101. package/dist/types/sdk/market/types.d.ts +1 -1
  102. package/dist/types/sdk/options.d.ts +1 -0
  103. package/dist/types/sdk/pools/PoolService.d.ts +8 -8
  104. package/dist/types/sdk/pools/types.d.ts +1 -1
  105. package/dist/types/sdk/types/state-human.d.ts +2 -0
  106. package/dist/types/sdk/types/state.d.ts +5 -0
  107. package/dist/types/sdk/utils/viem/executeDelegatedMulticalls.d.ts +28 -0
  108. package/dist/types/sdk/utils/viem/index.d.ts +1 -0
  109. package/package.json +8 -7
@@ -0,0 +1,220 @@
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
+ factory: this.address,
71
+ cachedSignatures: [...cachedSignatures],
72
+ registerVaultMessages: [...registerVaultMessages],
73
+ registeredTokens: [...registeredTokens],
74
+ creditAccounts: creditAccounts.map((ca) => {
75
+ const [registeredTokens2] = decodeAbiParameters(
76
+ [{ name: "registeredTokens", type: "address[]" }],
77
+ ca.extraDetails
78
+ );
79
+ return {
80
+ ...ca,
81
+ registeredTokens: [...registeredTokens2]
82
+ };
83
+ })
84
+ };
85
+ }
86
+ /**
87
+ * {@inheritDoc IKYCFactory.getInvestor}
88
+ */
89
+ async getInvestor(creditAccount, fromCache) {
90
+ if (fromCache && this.#investorCache.has(creditAccount)) {
91
+ return this.#investorCache.mustGet(creditAccount);
92
+ }
93
+ const investor = await this.contract.read.getInvestor([creditAccount]);
94
+ if (fromCache) {
95
+ this.#investorCache.upsert(creditAccount, investor);
96
+ }
97
+ return investor;
98
+ }
99
+ /**
100
+ * {@inheritDoc IKYCFactory.getApprovalAddress}
101
+ */
102
+ async getApprovalAddress(options) {
103
+ if ("creditAccount" in options) {
104
+ return this.getWallet(options.creditAccount);
105
+ }
106
+ return this.#precomputeWalletAddress(
107
+ options.creditManager,
108
+ options.borrower
109
+ );
110
+ }
111
+ /**
112
+ * {@inheritDoc IKYCFactory.getWallet}
113
+ */
114
+ async getWallet(creditAccount) {
115
+ return this.contract.read.getWallet([creditAccount]);
116
+ }
117
+ /**
118
+ * {@inheritDoc IKYCFactory.multicall}
119
+ */
120
+ multicall(creditAccount, calls, options) {
121
+ const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
122
+ return this.createRawTx({
123
+ functionName: "multicall",
124
+ args: [creditAccount, calls, tokensToRegister, signaturesToCache]
125
+ });
126
+ }
127
+ /**
128
+ * {@inheritDoc IKYCFactory.getOpenAccountRequirements}
129
+ */
130
+ async getOpenAccountRequirements(investor) {
131
+ const [investorData] = await this.#sdk.kyc.getInvestorData(investor, [
132
+ this.address
133
+ ]);
134
+ const dsTokens = new AddressSet(this.dsTokens.map((t) => t.address));
135
+ const desiredTokens = dsTokens;
136
+ const registredTokens = new AddressSet(investorData.registeredTokens);
137
+ const signedTokens = new AddressSet(
138
+ investorData.cachedSignatures.map((s) => s.token)
139
+ );
140
+ const unsignedTokens = desiredTokens.difference(signedTokens);
141
+ const tokensToRegister = desiredTokens.difference(registredTokens);
142
+ const requiredSignatures = investorData.registerVaultMessages.filter(
143
+ (m) => unsignedTokens.has(m.token)
144
+ );
145
+ if (tokensToRegister.size === 0 && requiredSignatures.length === 0) {
146
+ return void 0;
147
+ }
148
+ return {
149
+ type: KYC_FACTORY_SECURITIZE,
150
+ tokensToRegister: Array.from(tokensToRegister),
151
+ requiredSignatures
152
+ };
153
+ }
154
+ /**
155
+ * {@inheritDoc IKYCFactory.openCreditAccount}
156
+ */
157
+ openCreditAccount(creditManager, calls, options) {
158
+ const { tokensToRegister = [], signaturesToCache = [] } = options ?? {};
159
+ return this.createRawTx({
160
+ functionName: "openCreditAccount",
161
+ args: [creditManager, calls, tokensToRegister, signaturesToCache]
162
+ });
163
+ }
164
+ stateHuman(_raw) {
165
+ return {
166
+ ...super.stateHuman(_raw),
167
+ owner: this.labelAddress(this.owner),
168
+ degenNFT: this.labelAddress(this.degenNFT),
169
+ dsTokens: this.dsTokens.map((t) => ({
170
+ ...this.tokensMeta.mustGet(t.address),
171
+ registrar: this.labelAddress(t.registrar),
172
+ operators: t.operators.map((o) => this.labelAddress(o))
173
+ }))
174
+ };
175
+ }
176
+ /**
177
+ * Precomputes the wallet address that will own a new credit account
178
+ * for the given investor in the given credit manager.
179
+ *
180
+ * @param creditManager - credit manager address
181
+ * @param investor - investor address
182
+ **/
183
+ async #precomputeWalletAddress(creditManager, investor) {
184
+ return this.contract.read.precomputeWalletAddress([
185
+ creditManager,
186
+ investor
187
+ ]);
188
+ }
189
+ }
190
+ const registerMessageTuple = [
191
+ { name: "token", type: "address" },
192
+ {
193
+ name: "signature",
194
+ type: "tuple",
195
+ components: [
196
+ { name: "deadline", type: "uint256" },
197
+ { name: "signature", type: "bytes" }
198
+ ]
199
+ }
200
+ ];
201
+ const registerVaultMessageTuple = [
202
+ {
203
+ name: "domain",
204
+ type: "tuple",
205
+ components: [
206
+ { name: "name", type: "string" },
207
+ { name: "version", type: "string" },
208
+ { name: "chainId", type: "uint256" },
209
+ { name: "verifyingContract", type: "address" }
210
+ ]
211
+ },
212
+ { name: "investor", type: "address" },
213
+ { name: "operator", type: "address" },
214
+ { name: "token", type: "address" },
215
+ { name: "nonce", type: "uint256" },
216
+ { name: "deadline", type: "uint256" }
217
+ ];
218
+ export {
219
+ SecuritizeKYCFactory
220
+ };
@@ -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
  ],
@@ -16,6 +16,12 @@ const SDKOptions = z.object({
16
16
  * (from {@link GearboxChain.defaultMarketConfigurators})
17
17
  **/
18
18
  marketConfigurators: z.array(ZodAddress()).optional(),
19
+ /**
20
+ * Addresses of KYC factory contracts to load.
21
+ * If not set, all default KYC factories for the chain are loaded
22
+ * (from {@link GearboxChain.kycFactories})
23
+ **/
24
+ kycFactories: z.array(ZodAddress()).optional(),
19
25
  /**
20
26
  * Pin SDK to a specific block number during attach.
21
27
  * When set, all on-chain reads use this block instead of `latest`.
@@ -1,34 +1,84 @@
1
1
  import { iPoolV310Abi } from "../../abi/310/generated.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.js";
2
3
  import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
3
4
  import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
4
5
  import { iZapperAbi } from "../../abi/iZapper.js";
5
- import { SDKConstruct } from "../base/index.js";
6
+ import {
7
+ KYC_UNDERLYING_DEFAULT,
8
+ KYC_UNDERLYING_ON_DEMAND,
9
+ SDKConstruct
10
+ } from "../base/index.js";
6
11
  import { NATIVE_ADDRESS } from "../constants/index.js";
7
12
  import { AddressSet, hexEq } from "../utils/index.js";
8
13
  class PoolService extends SDKConstruct {
9
14
  /**
10
- * @inheritdoc IPoolsService.getDepositTokensIn
15
+ * {@inheritDoc IPoolsService.getDepositTokensIn}
11
16
  */
12
17
  getDepositTokensIn(pool) {
18
+ const underlying = this.#describeUnderlying(pool);
19
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
20
+ switch (underlying.contractType) {
21
+ case KYC_UNDERLYING_DEFAULT:
22
+ return this.#depositTokensIn(pool, false);
23
+ case KYC_UNDERLYING_ON_DEMAND:
24
+ return [underlying.asset];
25
+ }
26
+ }
13
27
  return this.#depositTokensIn(pool, true);
14
28
  }
15
29
  /**
16
- * @inheritdoc IPoolsService.getDepositTokensOut
30
+ * {@inheritDoc IPoolsService.getDepositTokensOut}
17
31
  */
18
32
  getDepositTokensOut(pool, tokenIn) {
33
+ const underlying = this.#describeUnderlying(pool);
34
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
35
+ switch (underlying.contractType) {
36
+ case KYC_UNDERLYING_DEFAULT:
37
+ return this.#depositTokensOut(pool, tokenIn, false);
38
+ case KYC_UNDERLYING_ON_DEMAND:
39
+ return [];
40
+ }
41
+ }
19
42
  return this.#depositTokensOut(pool, tokenIn, true);
20
43
  }
21
44
  /**
22
- * @inheritdoc IPoolsService.getDepositMetadata
45
+ * {@inheritDoc IPoolsService.getDepositMetadata}
23
46
  */
24
47
  getDepositMetadata(pool, tokenIn, tokenOut) {
48
+ const underlying = this.#describeUnderlying(pool);
49
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
50
+ switch (underlying.contractType) {
51
+ case KYC_UNDERLYING_DEFAULT: {
52
+ return this.#depositMetadata(
53
+ "kyc-default",
54
+ pool,
55
+ tokenIn,
56
+ tokenOut,
57
+ false
58
+ );
59
+ }
60
+ case KYC_UNDERLYING_ON_DEMAND:
61
+ return {
62
+ zapper: void 0,
63
+ approveTarget: underlying.liquidityProvider.addr,
64
+ permissible: false,
65
+ type: "kyc-on-demand"
66
+ };
67
+ }
68
+ }
25
69
  return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
26
70
  }
27
71
  /**
28
- * @inheritdoc IPoolsService.addLiquidity
72
+ * {@inheritDoc IPoolsService.addLiquidity}
29
73
  */
30
74
  addLiquidity(props) {
31
75
  const { collateral, meta, permit, referralCode, pool, wallet } = props;
76
+ const underlying = this.#describeUnderlying(pool);
77
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
78
+ if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
79
+ return void 0;
80
+ }
81
+ }
32
82
  const { zapper } = meta;
33
83
  if (zapper && hexEq(zapper.tokenIn.addr, NATIVE_ADDRESS)) {
34
84
  return {
@@ -68,22 +118,51 @@ class PoolService extends SDKConstruct {
68
118
  }
69
119
  }
70
120
  /**
71
- * @inheritdoc IPoolsService.getWithdrawalTokensIn
121
+ * {@inheritDoc IPoolsService.getWithdrawalTokensIn}
72
122
  */
73
123
  getWithdrawalTokensIn(pool) {
124
+ const underlying = this.#describeUnderlying(pool);
125
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
126
+ switch (underlying.contractType) {
127
+ case KYC_UNDERLYING_DEFAULT:
128
+ return this.#withdrawalTokensIn(pool, false);
129
+ case KYC_UNDERLYING_ON_DEMAND:
130
+ return [];
131
+ }
132
+ }
74
133
  return this.#withdrawalTokensIn(pool, true);
75
134
  }
76
135
  /**
77
- * @inheritdoc IPoolsService.getWithdrawalTokensOut
136
+ * {@inheritDoc IPoolsService.getWithdrawalTokensOut}
78
137
  */
79
138
  getWithdrawalTokensOut(pool, tokenIn) {
139
+ const underlying = this.#describeUnderlying(pool);
140
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
141
+ switch (underlying.contractType) {
142
+ case KYC_UNDERLYING_DEFAULT:
143
+ return this.#withdrawalTokensOut(pool, tokenIn, false);
144
+ case KYC_UNDERLYING_ON_DEMAND:
145
+ return [underlying.asset];
146
+ }
147
+ }
80
148
  return this.#withdrawalTokensOut(pool, tokenIn, true);
81
149
  }
82
150
  /**
83
- * @inheritdoc IPoolsService.removeLiquidity
151
+ * {@inheritDoc IPoolsService.removeLiquidity}
84
152
  */
85
153
  removeLiquidity(props) {
86
154
  const { pool, amount, meta, wallet, permit } = props;
155
+ const underlying = this.#describeUnderlying(pool);
156
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
157
+ if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
158
+ return {
159
+ abi: ierc20Abi,
160
+ functionName: "approve",
161
+ args: [underlying.liquidityProvider, 0n],
162
+ target: underlying.asset
163
+ };
164
+ }
165
+ }
87
166
  if (meta.zapper) {
88
167
  return permit ? {
89
168
  target: meta.zapper.baseParams.addr,
@@ -112,9 +191,30 @@ class PoolService extends SDKConstruct {
112
191
  };
113
192
  }
114
193
  /**
115
- * @inheritdoc IPoolsService.getWithdrawalMetadata
194
+ * {@inheritDoc IPoolsService.getWithdrawalMetadata}
116
195
  */
117
196
  getWithdrawalMetadata(pool, tokenIn, tokenOut) {
197
+ const underlying = this.#describeUnderlying(pool);
198
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
199
+ switch (underlying.contractType) {
200
+ case KYC_UNDERLYING_DEFAULT: {
201
+ return this.#withdrawalMetadata(
202
+ "kyc-default",
203
+ pool,
204
+ tokenIn,
205
+ tokenOut,
206
+ false
207
+ );
208
+ }
209
+ case KYC_UNDERLYING_ON_DEMAND:
210
+ return {
211
+ zapper: void 0,
212
+ approveTarget: void 0,
213
+ permissible: false,
214
+ type: "kyc-on-demand"
215
+ };
216
+ }
217
+ }
118
218
  return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
119
219
  }
120
220
  /**
@@ -274,8 +374,6 @@ class PoolService extends SDKConstruct {
274
374
  zapper,
275
375
  // Approval target is zapper when routed, otherwise the pool contract.
276
376
  approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
277
- // TODO: instead of permissible, return permitType depending on tokenIn
278
- // "none" | "eip2612" | "dai_like";
279
377
  permissible: !!zapper && !hexEq(tokenIn, NATIVE_ADDRESS),
280
378
  type
281
379
  };
@@ -303,8 +401,6 @@ class PoolService extends SDKConstruct {
303
401
  zapper,
304
402
  // Approval target exists only for zapper-based withdrawals.
305
403
  approveTarget: zapper?.baseParams.addr,
306
- // TODO: instead of permissible, return permitType depending on tokenIn
307
- // "none" | "eip2612" | "dai_like";
308
404
  permissible: !!zapper,
309
405
  type
310
406
  };
@@ -0,0 +1,14 @@
1
+ import { simulateWithPriceUpdates } from "./simulateWithPriceUpdates.js";
2
+ async function executeDelegatedMulticalls(client, multicalls, opts) {
3
+ if (!multicalls.length) return;
4
+ const results = await simulateWithPriceUpdates(client, {
5
+ ...opts,
6
+ contracts: multicalls.map((d) => d.call)
7
+ });
8
+ for (let i = 0; i < multicalls.length; i++) {
9
+ multicalls[i].onResult(results[i]);
10
+ }
11
+ }
12
+ export {
13
+ executeDelegatedMulticalls
14
+ };
@@ -1,4 +1,5 @@
1
1
  export * from "./cast.js";
2
+ export * from "./executeDelegatedMulticalls.js";
2
3
  export * from "./getLogsPaginated.js";
3
4
  export * from "./getLogsSafe.js";
4
5
  export * from "./sendRawTx.js";
@@ -0,0 +1,71 @@
1
+ export declare const iDSRegistryServiceAbi: readonly [{
2
+ readonly type: "function";
3
+ readonly name: "addWallet";
4
+ readonly inputs: readonly [{
5
+ readonly name: "wallet";
6
+ readonly type: "address";
7
+ readonly internalType: "address";
8
+ }, {
9
+ readonly name: "investorId";
10
+ readonly type: "string";
11
+ readonly internalType: "string";
12
+ }];
13
+ readonly outputs: readonly [];
14
+ readonly stateMutability: "nonpayable";
15
+ }, {
16
+ readonly type: "function";
17
+ readonly name: "getInvestor";
18
+ readonly inputs: readonly [{
19
+ readonly name: "wallet";
20
+ readonly type: "address";
21
+ readonly internalType: "address";
22
+ }];
23
+ readonly outputs: readonly [{
24
+ readonly name: "";
25
+ readonly type: "string";
26
+ readonly internalType: "string";
27
+ }];
28
+ readonly stateMutability: "view";
29
+ }, {
30
+ readonly type: "function";
31
+ readonly name: "isInvestor";
32
+ readonly inputs: readonly [{
33
+ readonly name: "investorId";
34
+ readonly type: "string";
35
+ readonly internalType: "string";
36
+ }];
37
+ readonly outputs: readonly [{
38
+ readonly name: "";
39
+ readonly type: "bool";
40
+ readonly internalType: "bool";
41
+ }];
42
+ readonly stateMutability: "view";
43
+ }, {
44
+ readonly type: "function";
45
+ readonly name: "isWallet";
46
+ readonly inputs: readonly [{
47
+ readonly name: "wallet";
48
+ readonly type: "address";
49
+ readonly internalType: "address";
50
+ }];
51
+ readonly outputs: readonly [{
52
+ readonly name: "";
53
+ readonly type: "bool";
54
+ readonly internalType: "bool";
55
+ }];
56
+ readonly stateMutability: "view";
57
+ }, {
58
+ readonly type: "function";
59
+ readonly name: "registerInvestor";
60
+ readonly inputs: readonly [{
61
+ readonly name: "investorId";
62
+ readonly type: "string";
63
+ readonly internalType: "string";
64
+ }, {
65
+ readonly name: "collisionHash";
66
+ readonly type: "string";
67
+ readonly internalType: "string";
68
+ }];
69
+ readonly outputs: readonly [];
70
+ readonly stateMutability: "nonpayable";
71
+ }];
@@ -0,0 +1,67 @@
1
+ export declare const iDSTokenAbi: readonly [{
2
+ readonly type: "function";
3
+ readonly name: "REGISTRY_SERVICE";
4
+ readonly inputs: readonly [];
5
+ readonly outputs: readonly [{
6
+ readonly name: "";
7
+ readonly type: "uint256";
8
+ readonly internalType: "uint256";
9
+ }];
10
+ readonly stateMutability: "view";
11
+ }, {
12
+ readonly type: "function";
13
+ readonly name: "TRUST_SERVICE";
14
+ readonly inputs: readonly [];
15
+ readonly outputs: readonly [{
16
+ readonly name: "";
17
+ readonly type: "uint256";
18
+ readonly internalType: "uint256";
19
+ }];
20
+ readonly stateMutability: "view";
21
+ }, {
22
+ readonly type: "function";
23
+ readonly name: "burn";
24
+ readonly inputs: readonly [{
25
+ readonly name: "from";
26
+ readonly type: "address";
27
+ readonly internalType: "address";
28
+ }, {
29
+ readonly name: "amount";
30
+ readonly type: "uint256";
31
+ readonly internalType: "uint256";
32
+ }, {
33
+ readonly name: "reason";
34
+ readonly type: "string";
35
+ readonly internalType: "string";
36
+ }];
37
+ readonly outputs: readonly [];
38
+ readonly stateMutability: "nonpayable";
39
+ }, {
40
+ readonly type: "function";
41
+ readonly name: "getDSService";
42
+ readonly inputs: readonly [{
43
+ readonly name: "serviceId";
44
+ readonly type: "uint256";
45
+ readonly internalType: "uint256";
46
+ }];
47
+ readonly outputs: readonly [{
48
+ readonly name: "";
49
+ readonly type: "address";
50
+ readonly internalType: "address";
51
+ }];
52
+ readonly stateMutability: "view";
53
+ }, {
54
+ readonly type: "function";
55
+ readonly name: "issueTokens";
56
+ readonly inputs: readonly [{
57
+ readonly name: "to";
58
+ readonly type: "address";
59
+ readonly internalType: "address";
60
+ }, {
61
+ readonly name: "amount";
62
+ readonly type: "uint256";
63
+ readonly internalType: "uint256";
64
+ }];
65
+ readonly outputs: readonly [];
66
+ readonly stateMutability: "nonpayable";
67
+ }];