@gearbox-protocol/sdk 13.1.0 → 13.2.0-next.1

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 (96) hide show
  1. package/dist/cjs/abi/310/iSecuritizeDegenNFT.js +263 -0
  2. package/dist/cjs/abi/310/iSecuritizeKYCFactory.js +278 -0
  3. package/dist/cjs/{sdk/pools/PoolServiceV310.js → abi/iStateSerializer.js} +14 -8
  4. package/dist/cjs/dev/AccountOpener.js +45 -5
  5. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  6. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  7. package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -1
  8. package/dist/cjs/sdk/base/TokensMeta.js +255 -32
  9. package/dist/cjs/sdk/base/index.js +2 -0
  10. package/dist/cjs/sdk/{constants/phantom-tokens.js → base/token-types.js} +9 -3
  11. package/dist/cjs/sdk/chain/chains.js +2 -1
  12. package/dist/cjs/sdk/constants/index.js +0 -2
  13. package/dist/cjs/sdk/market/MarketRegister.js +2 -2
  14. package/dist/cjs/sdk/market/MarketSuite.js +6 -0
  15. package/dist/cjs/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +110 -6
  16. package/dist/cjs/sdk/market/index.js +3 -1
  17. package/dist/cjs/sdk/market/pool/PoolSuite.js +3 -0
  18. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +17 -2
  19. package/dist/cjs/sdk/market/pool/SecuritizeKYCFactory.js +97 -0
  20. package/dist/cjs/sdk/market/pool/index.js +4 -0
  21. package/dist/cjs/sdk/pools/PoolService.js +391 -0
  22. package/dist/cjs/sdk/pools/index.js +2 -4
  23. package/dist/cjs/sdk/utils/AddressMap.js +1 -1
  24. package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
  25. package/dist/esm/abi/310/iSecuritizeDegenNFT.js +239 -0
  26. package/dist/esm/abi/310/iSecuritizeKYCFactory.js +254 -0
  27. package/dist/esm/abi/iStateSerializer.js +12 -0
  28. package/dist/esm/dev/AccountOpener.js +47 -6
  29. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +462 -104
  30. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +16 -5
  31. package/dist/esm/sdk/base/ChainContractsRegister.js +1 -1
  32. package/dist/esm/sdk/base/TokensMeta.js +261 -32
  33. package/dist/esm/sdk/base/index.js +1 -0
  34. package/dist/esm/sdk/{constants/phantom-tokens.js → base/token-types.js} +4 -0
  35. package/dist/esm/sdk/chain/chains.js +2 -1
  36. package/dist/esm/sdk/constants/index.js +0 -1
  37. package/dist/esm/sdk/market/MarketRegister.js +2 -2
  38. package/dist/esm/sdk/market/MarketSuite.js +6 -0
  39. package/dist/esm/{plugins/zappers/extraZappers.js → sdk/market/ZapperRegister.js} +109 -2
  40. package/dist/esm/sdk/market/index.js +1 -0
  41. package/dist/esm/sdk/market/pool/PoolSuite.js +3 -0
  42. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -2
  43. package/dist/esm/sdk/market/pool/SecuritizeKYCFactory.js +73 -0
  44. package/dist/esm/sdk/market/pool/index.js +2 -0
  45. package/dist/esm/sdk/pools/PoolService.js +371 -0
  46. package/dist/esm/sdk/pools/index.js +1 -2
  47. package/dist/esm/sdk/utils/AddressMap.js +1 -1
  48. package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
  49. package/dist/types/abi/310/iSecuritizeDegenNFT.d.ts +324 -0
  50. package/dist/types/abi/310/iSecuritizeKYCFactory.d.ts +322 -0
  51. package/dist/types/abi/iStateSerializer.d.ts +11 -0
  52. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +123 -27
  53. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
  54. package/dist/types/sdk/accounts/types.d.ts +108 -8
  55. package/dist/types/sdk/base/TokensMeta.d.ts +34 -18
  56. package/dist/types/sdk/base/index.d.ts +1 -0
  57. package/dist/types/sdk/base/token-types.d.ts +33 -0
  58. package/dist/types/sdk/base/types.d.ts +0 -1
  59. package/dist/types/sdk/chain/chains.d.ts +1 -1
  60. package/dist/types/sdk/constants/index.d.ts +0 -1
  61. package/dist/types/sdk/market/MarketRegister.d.ts +2 -2
  62. package/dist/types/sdk/market/MarketSuite.d.ts +3 -0
  63. package/dist/types/sdk/market/ZapperRegister.d.ts +17 -0
  64. package/dist/types/sdk/market/index.d.ts +1 -0
  65. package/dist/types/sdk/market/pool/PoolSuite.d.ts +2 -0
  66. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +6 -2
  67. package/dist/types/sdk/market/pool/SecuritizeKYCFactory.d.ts +345 -0
  68. package/dist/types/sdk/market/pool/index.d.ts +2 -0
  69. package/dist/types/sdk/market/types.d.ts +10 -0
  70. package/dist/types/sdk/pools/PoolService.d.ts +14 -0
  71. package/dist/types/sdk/pools/index.d.ts +1 -2
  72. package/dist/types/sdk/pools/types.d.ts +84 -63
  73. package/dist/types/sdk/utils/AddressMap.d.ts +1 -1
  74. package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
  75. package/package.json +1 -1
  76. package/dist/cjs/plugins/zappers/ZappersPlugin.js +0 -144
  77. package/dist/cjs/plugins/zappers/index.js +0 -26
  78. package/dist/cjs/plugins/zappers/package.json +0 -1
  79. package/dist/cjs/sdk/pools/AbstractPoolService.js +0 -137
  80. package/dist/cjs/sdk/pools/createPoolService.js +0 -35
  81. package/dist/esm/plugins/zappers/ZappersPlugin.js +0 -126
  82. package/dist/esm/plugins/zappers/index.js +0 -3
  83. package/dist/esm/plugins/zappers/package.json +0 -1
  84. package/dist/esm/sdk/pools/AbstractPoolService.js +0 -113
  85. package/dist/esm/sdk/pools/PoolServiceV310.js +0 -6
  86. package/dist/esm/sdk/pools/createPoolService.js +0 -11
  87. package/dist/types/plugins/zappers/ZappersPlugin.d.ts +0 -18
  88. package/dist/types/plugins/zappers/extraZappers.d.ts +0 -6
  89. package/dist/types/plugins/zappers/index.d.ts +0 -3
  90. package/dist/types/plugins/zappers/types.d.ts +0 -12
  91. package/dist/types/sdk/constants/phantom-tokens.d.ts +0 -2
  92. package/dist/types/sdk/pools/AbstractPoolService.d.ts +0 -9
  93. package/dist/types/sdk/pools/PoolServiceV310.d.ts +0 -4
  94. package/dist/types/sdk/pools/createPoolService.d.ts +0 -3
  95. /package/dist/cjs/{plugins/zappers → sdk/market}/types.js +0 -0
  96. /package/dist/esm/{plugins/zappers → sdk/market}/types.js +0 -0
@@ -0,0 +1,73 @@
1
+ import { iSecuritizeDegenNFTAbi } from "../../../abi/310/iSecuritizeDegenNFT.js";
2
+ import { iSecuritizeKYCFactoryAbi } from "../../../abi/310/iSecuritizeKYCFactory.js";
3
+ import { BaseContract } from "../../base/index.js";
4
+ import { AddressMap } from "../../index.js";
5
+ const abi = iSecuritizeKYCFactoryAbi;
6
+ class SecuritizeKYCFactory extends BaseContract {
7
+ investorCache;
8
+ #degenNFT;
9
+ constructor(options, address) {
10
+ super(options, {
11
+ addr: address,
12
+ name: "SecuritizeKYCFactory",
13
+ abi
14
+ });
15
+ }
16
+ async precomputeWalletAddress(creditManager, investor) {
17
+ return this.contract.read.precomputeWalletAddress([
18
+ creditManager,
19
+ investor
20
+ ]);
21
+ }
22
+ async getWallet(creditAccount) {
23
+ return this.contract.read.getWallet([creditAccount]);
24
+ }
25
+ /**
26
+ * Returns the investor address for a credit account.
27
+ * @param creditAccount - Credit account address
28
+ * @param fromCache - If true, use and update an in-memory cache (creditAccount -> investor). On cache miss, loads from contract and stores the result for future calls.
29
+ */
30
+ async getInvestor(creditAccount, fromCache) {
31
+ if (fromCache && this.investorCache?.has(creditAccount)) {
32
+ return this.investorCache.get(creditAccount);
33
+ }
34
+ const investor = await this.contract.read.getInvestor([creditAccount]);
35
+ if (fromCache) {
36
+ if (!this.investorCache) {
37
+ this.investorCache = new AddressMap();
38
+ }
39
+ this.investorCache.upsert(creditAccount, investor);
40
+ }
41
+ return investor;
42
+ }
43
+ async getDSTokens() {
44
+ const degenNFT = await this.getDegenNFT();
45
+ const tokens = await this.client.readContract({
46
+ address: degenNFT,
47
+ abi: iSecuritizeDegenNFTAbi,
48
+ functionName: "getDSTokens"
49
+ });
50
+ return [...tokens];
51
+ }
52
+ multicall(creditAccount, calls, tokensToRegister) {
53
+ return this.createRawTx({
54
+ functionName: "multicall",
55
+ args: [creditAccount, calls, tokensToRegister]
56
+ });
57
+ }
58
+ openCreditAccount(creditManager, calls, tokensToRegister) {
59
+ return this.createRawTx({
60
+ functionName: "openCreditAccount",
61
+ args: [creditManager, calls, tokensToRegister]
62
+ });
63
+ }
64
+ async getDegenNFT() {
65
+ if (!this.#degenNFT) {
66
+ this.#degenNFT = await this.contract.read.getDegenNFT();
67
+ }
68
+ return this.#degenNFT;
69
+ }
70
+ }
71
+ export {
72
+ SecuritizeKYCFactory
73
+ };
@@ -1,4 +1,6 @@
1
1
  export * from "./GaugeContract.js";
2
2
  export * from "./LinearInterestRateModelContract.js";
3
3
  export * from "./PoolSuite.js";
4
+ export * from "./PoolV310Contract.js";
5
+ export * from "./SecuritizeKYCFactory.js";
4
6
  export * from "./types.js";
@@ -0,0 +1,371 @@
1
+ import { iPoolV310Abi } from "../../abi/310/generated.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.js";
3
+ import { ierc20ZapperDepositsAbi } from "../../abi/iERC20ZapperDeposits.js";
4
+ import { iethZapperDepositsAbi } from "../../abi/iETHZapperDeposits.js";
5
+ import { iZapperAbi } from "../../abi/iZapper.js";
6
+ import {
7
+ KYC_UNDERLYING_DEFAULT,
8
+ KYC_UNDERLYING_ON_DEMAND,
9
+ SDKConstruct
10
+ } from "../base/index.js";
11
+ import { AddressSet, hexEq } from "../index.js";
12
+ import { AddressMap } from "../utils/index.js";
13
+ const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
14
+ const POOL_TOKENS_TO_MIGRATE = new AddressMap([
15
+ // v2 diesels
16
+ ["0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA", "dDAI"],
17
+ ["0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3", "dUSDC"],
18
+ ["0xe753260F1955e8678DCeA8887759e07aa57E8c54", "dWBTC"],
19
+ ["0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278", "dWETH"],
20
+ ["0x2158034dB06f06dcB9A786D2F1F8c38781bA779d", "dwstETH"],
21
+ ["0x8A1112AFef7F4FC7c066a77AABBc01b3Fff31D47", "dFRAX"]
22
+ ]);
23
+ class PoolService extends SDKConstruct {
24
+ getDepositTokensIn(pool) {
25
+ const underlying = this.#describeUnderlying(pool);
26
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
27
+ switch (underlying.contractType) {
28
+ case KYC_UNDERLYING_DEFAULT:
29
+ return this.#depositTokensIn(pool, false);
30
+ case KYC_UNDERLYING_ON_DEMAND:
31
+ return [underlying.asset];
32
+ }
33
+ }
34
+ return this.#depositTokensIn(pool, true);
35
+ }
36
+ getDepositTokensOut(pool, tokenIn) {
37
+ const underlying = this.#describeUnderlying(pool);
38
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
39
+ switch (underlying.contractType) {
40
+ case KYC_UNDERLYING_DEFAULT:
41
+ return this.#depositTokensOut(pool, tokenIn, false);
42
+ case KYC_UNDERLYING_ON_DEMAND:
43
+ return [];
44
+ }
45
+ }
46
+ return this.#depositTokensOut(pool, tokenIn, true);
47
+ }
48
+ getDepositMetadata(pool, tokenIn, tokenOut) {
49
+ const underlying = this.#describeUnderlying(pool);
50
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
51
+ switch (underlying.contractType) {
52
+ case KYC_UNDERLYING_DEFAULT: {
53
+ return this.#depositMetadata(
54
+ "kyc-default",
55
+ pool,
56
+ tokenIn,
57
+ tokenOut,
58
+ false
59
+ );
60
+ }
61
+ case KYC_UNDERLYING_ON_DEMAND:
62
+ return {
63
+ zapper: void 0,
64
+ approveTarget: underlying.liquidityProvider,
65
+ permissible: false,
66
+ type: "kyc-on-demand"
67
+ };
68
+ }
69
+ }
70
+ return this.#depositMetadata("classic", pool, tokenIn, tokenOut, true);
71
+ }
72
+ addLiquidity(props) {
73
+ const { collateral, meta, permit, referralCode, pool, wallet } = props;
74
+ const underlying = this.#describeUnderlying(pool);
75
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
76
+ if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
77
+ return void 0;
78
+ }
79
+ }
80
+ const { zapper } = meta;
81
+ if (zapper && hexEq(zapper.tokenIn.addr, NATIVE_ADDRESS)) {
82
+ return {
83
+ target: zapper.baseParams.addr,
84
+ abi: iethZapperDepositsAbi,
85
+ functionName: "depositWithReferral",
86
+ args: [wallet, referralCode],
87
+ value: collateral.balance
88
+ };
89
+ } else if (zapper) {
90
+ return permit ? {
91
+ target: zapper.baseParams.addr,
92
+ abi: ierc20ZapperDepositsAbi,
93
+ functionName: "depositWithReferralAndPermit",
94
+ args: [
95
+ collateral.balance,
96
+ wallet,
97
+ referralCode,
98
+ permit.deadline,
99
+ permit.v,
100
+ permit.r,
101
+ permit.s
102
+ ]
103
+ } : {
104
+ target: zapper.baseParams.addr,
105
+ abi: ierc20ZapperDepositsAbi,
106
+ functionName: "depositWithReferral",
107
+ args: [collateral.balance, wallet, referralCode]
108
+ };
109
+ } else {
110
+ return {
111
+ target: pool,
112
+ abi: iPoolV310Abi,
113
+ functionName: "depositWithReferral",
114
+ args: [collateral.balance, wallet, referralCode]
115
+ };
116
+ }
117
+ }
118
+ getWithdrawalTokensIn(pool) {
119
+ const underlying = this.#describeUnderlying(pool);
120
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
121
+ switch (underlying.contractType) {
122
+ case KYC_UNDERLYING_DEFAULT:
123
+ return this.#withdrawalTokensIn(pool, false);
124
+ case KYC_UNDERLYING_ON_DEMAND:
125
+ return [];
126
+ }
127
+ }
128
+ return this.#withdrawalTokensIn(pool, true);
129
+ }
130
+ getWithdrawalTokensOut(pool, tokenIn) {
131
+ const underlying = this.#describeUnderlying(pool);
132
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
133
+ switch (underlying.contractType) {
134
+ case KYC_UNDERLYING_DEFAULT:
135
+ return this.#withdrawalTokensOut(pool, tokenIn, false);
136
+ case KYC_UNDERLYING_ON_DEMAND:
137
+ return [underlying.asset];
138
+ }
139
+ }
140
+ return this.#withdrawalTokensOut(pool, tokenIn, true);
141
+ }
142
+ removeLiquidity(props) {
143
+ const { pool, amount, meta, wallet, permit } = props;
144
+ const underlying = this.#describeUnderlying(pool);
145
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
146
+ if (underlying.contractType === KYC_UNDERLYING_ON_DEMAND) {
147
+ return {
148
+ abi: ierc20Abi,
149
+ functionName: "approve",
150
+ args: [underlying.liquidityProvider, 0n],
151
+ target: underlying.asset
152
+ };
153
+ }
154
+ }
155
+ if (meta.zapper) {
156
+ return permit ? {
157
+ target: meta.zapper.baseParams.addr,
158
+ abi: iZapperAbi,
159
+ functionName: "redeemWithPermit",
160
+ args: [
161
+ amount,
162
+ wallet,
163
+ permit.deadline,
164
+ permit.v,
165
+ permit.r,
166
+ permit.s
167
+ ]
168
+ } : {
169
+ target: meta.zapper.baseParams.addr,
170
+ abi: iZapperAbi,
171
+ functionName: "redeem",
172
+ args: [amount, wallet]
173
+ };
174
+ }
175
+ return {
176
+ target: pool,
177
+ abi: iPoolV310Abi,
178
+ functionName: "redeem",
179
+ args: [amount, wallet, wallet]
180
+ };
181
+ }
182
+ getWithdrawalMetadata(pool, tokenIn, tokenOut) {
183
+ const underlying = this.#describeUnderlying(pool);
184
+ if (this.sdk.tokensMeta.isKYCUnderlying(underlying)) {
185
+ switch (underlying.contractType) {
186
+ case KYC_UNDERLYING_DEFAULT: {
187
+ return this.#withdrawalMetadata(
188
+ "kyc-default",
189
+ pool,
190
+ tokenIn,
191
+ tokenOut,
192
+ false
193
+ );
194
+ }
195
+ case KYC_UNDERLYING_ON_DEMAND:
196
+ return {
197
+ zapper: void 0,
198
+ approveTarget: void 0,
199
+ permissible: false,
200
+ type: "kyc-on-demand"
201
+ };
202
+ }
203
+ }
204
+ return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
205
+ }
206
+ /**
207
+ * Filter out v2 diesel tokens (can come from migration v2 -> v3 zappers)
208
+ * Also omits "migration" zappers (v3 -> v3.1) since they are treated in a different way
209
+ */
210
+ #getDepositZappers(poolAddr) {
211
+ const zappers = this.sdk.marketRegister.poolZappers(poolAddr);
212
+ return zappers.filter(
213
+ (z) => z.type !== "migration" && !POOL_TOKENS_TO_MIGRATE.has(z.tokenIn.addr)
214
+ );
215
+ }
216
+ #depositTokensIn(poolAddr, allowDirectDeposit) {
217
+ const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
218
+ const result = new AddressSet();
219
+ if (allowDirectDeposit) {
220
+ result.add(pool.underlying);
221
+ }
222
+ const zappers = this.#getDepositZappers(poolAddr);
223
+ for (const z of zappers) {
224
+ if (hexEq(z.tokenOut.addr, poolAddr)) {
225
+ result.add(z.tokenIn.addr);
226
+ }
227
+ }
228
+ if (result.size === 0) {
229
+ throw new Error(
230
+ `No tokensIn found for pool ${this.labelAddress(poolAddr)}`
231
+ );
232
+ }
233
+ return result.asArray();
234
+ }
235
+ #withdrawalTokensIn(poolAddr, allowDirectDeposit) {
236
+ const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
237
+ const result = new AddressSet();
238
+ if (allowDirectDeposit && pool) {
239
+ result.add(poolAddr);
240
+ }
241
+ const zappers = this.#getDepositZappers(poolAddr);
242
+ for (const z of zappers) {
243
+ result.add(z.tokenOut.addr);
244
+ }
245
+ if (result.size === 0) {
246
+ throw new Error(
247
+ `No tokensIn found for pool ${this.labelAddress(poolAddr)}`
248
+ );
249
+ }
250
+ return result.asArray();
251
+ }
252
+ #depositTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
253
+ const result = new AddressSet();
254
+ const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
255
+ const zappers = this.#getDepositZappers(poolAddr);
256
+ for (const z of zappers) {
257
+ if (hexEq(z.tokenIn.addr, tokenIn)) {
258
+ result.add(z.tokenOut.addr);
259
+ }
260
+ }
261
+ if (allowDirectDeposit && hexEq(tokenIn, pool.underlying)) {
262
+ result.add(poolAddr);
263
+ }
264
+ if (result.size === 0) {
265
+ throw new Error(
266
+ `No tokensOut found for tokenIn ${this.labelAddress(
267
+ tokenIn
268
+ )} on pool ${this.labelAddress(poolAddr)}`
269
+ );
270
+ }
271
+ const r = result.asArray();
272
+ return r;
273
+ }
274
+ #withdrawalTokensOut(poolAddr, tokenIn, allowDirectDeposit) {
275
+ const result = new AddressSet();
276
+ const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
277
+ const zappers = this.#getDepositZappers(poolAddr);
278
+ for (const z of zappers) {
279
+ if (hexEq(z.tokenOut.addr, tokenIn)) {
280
+ result.add(z.tokenIn.addr);
281
+ }
282
+ }
283
+ if (allowDirectDeposit && hexEq(tokenIn, poolAddr)) {
284
+ result.add(pool.underlying);
285
+ }
286
+ if (result.size === 0) {
287
+ throw new Error(
288
+ `No tokensOut found for tokenIn ${this.labelAddress(
289
+ tokenIn
290
+ )} on pool ${this.labelAddress(poolAddr)}`
291
+ );
292
+ }
293
+ const r = result.asArray();
294
+ return r;
295
+ }
296
+ /**
297
+ * Filter out v2 diesel tokens (can come from migration v2 -> v3 zappers)
298
+ * Also omits "migration" zappers (v3 -> v3.1) since they are treated in a different way
299
+ */
300
+ #getDepositZapper(poolAddr, tokenIn, tokenOut) {
301
+ const zappers = this.sdk.marketRegister.getZapper(poolAddr, tokenIn, tokenOut)?.filter(
302
+ (z) => z.type !== "migration" && !POOL_TOKENS_TO_MIGRATE.has(z.tokenIn.addr)
303
+ );
304
+ if (zappers && zappers.length > 1) {
305
+ throw new Error(
306
+ `Multiple zappers found for tokenIn ${this.labelAddress(
307
+ tokenIn
308
+ )} and tokenOut ${this.labelAddress(
309
+ tokenOut
310
+ )} on pool ${this.labelAddress(poolAddr)}`
311
+ );
312
+ }
313
+ return zappers?.[0];
314
+ }
315
+ #depositMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
316
+ if (!tokenOut) {
317
+ throw new Error("tokenOut is required for classic pool deposit");
318
+ }
319
+ const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
320
+ const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
321
+ if (!zapper && !allowDirectDeposit) {
322
+ throw new Error(
323
+ `No zapper found for tokenIn ${this.labelAddress(
324
+ tokenIn
325
+ )} and tokenOut ${this.labelAddress(
326
+ tokenOut
327
+ )} on pool ${this.labelAddress(poolAddr)}`
328
+ );
329
+ }
330
+ return {
331
+ zapper,
332
+ // zapper or pool itself
333
+ approveTarget: zapper?.baseParams.addr ?? pool.pool.address,
334
+ // TODO: instead of permissible, return permitType зависимости от tokenIn
335
+ // "none" | "eip2612" | "dai_like";
336
+ permissible: !!zapper && !hexEq(tokenIn, NATIVE_ADDRESS),
337
+ type
338
+ };
339
+ }
340
+ #withdrawalMetadata(type, poolAddr, tokenIn, tokenOut, allowDirectDeposit) {
341
+ if (!tokenOut) {
342
+ throw new Error("tokenOut is required for classic pool deposit");
343
+ }
344
+ const zapper = this.#getDepositZapper(poolAddr, tokenOut, tokenIn);
345
+ if (!zapper && !allowDirectDeposit) {
346
+ throw new Error(
347
+ `No zapper found for tokenIn ${this.labelAddress(
348
+ tokenOut
349
+ )} and tokenOut ${this.labelAddress(
350
+ tokenIn
351
+ )} on pool ${this.labelAddress(poolAddr)}`
352
+ );
353
+ }
354
+ return {
355
+ zapper,
356
+ // zapper or pool itself
357
+ approveTarget: zapper?.baseParams.addr,
358
+ // TODO: instead of permissible, return permitType зависимости от tokenIn
359
+ // "none" | "eip2612" | "dai_like";
360
+ permissible: !!zapper,
361
+ type
362
+ };
363
+ }
364
+ #describeUnderlying(pool) {
365
+ const market = this.sdk.marketRegister.findByPool(pool);
366
+ return this.sdk.tokensMeta.mustGet(market.underlying);
367
+ }
368
+ }
369
+ export {
370
+ PoolService
371
+ };
@@ -1,3 +1,2 @@
1
- export * from "./AbstractPoolService.js";
2
- export * from "./createPoolService.js";
1
+ export * from "./PoolService.js";
3
2
  export * from "./types.js";
@@ -14,7 +14,7 @@ class AddressMap {
14
14
  this.#name = name;
15
15
  }
16
16
  /**
17
- * Adds or updates value, undefined removes value
17
+ * Adds or overwrites value, undefined removes value
18
18
  * @param address
19
19
  * @param value
20
20
  */
@@ -1,4 +1,7 @@
1
- import { sendTransaction } from "viem/actions";
1
+ import {
2
+ estimateGas,
3
+ sendTransaction
4
+ } from "viem/actions";
2
5
  import { getAction } from "viem/utils";
3
6
  async function sendRawTx(client, params) {
4
7
  const { tx, ...rest } = params;
@@ -13,6 +16,21 @@ async function sendRawTx(client, params) {
13
16
  value: BigInt(tx.value)
14
17
  });
15
18
  }
19
+ async function estimateRawTxGas(client, params) {
20
+ const { tx, ...rest } = params;
21
+ return getAction(
22
+ client,
23
+ estimateGas,
24
+ "estimateGas"
25
+ )({
26
+ ...rest,
27
+ account: params.account,
28
+ data: tx.callData,
29
+ to: tx.to,
30
+ value: BigInt(tx.value)
31
+ });
32
+ }
16
33
  export {
34
+ estimateRawTxGas,
17
35
  sendRawTx
18
36
  };