@kasarlabs/vesu-mcp 0.1.3 → 0.1.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 (84) hide show
  1. package/build/index.js +86 -6
  2. package/build/index.js.map +1 -1
  3. package/build/interfaces/index.d.ts +661 -8
  4. package/build/interfaces/index.js +57 -1
  5. package/build/interfaces/index.js.map +1 -1
  6. package/build/lib/abis/ekuboCore.d.ts +92 -0
  7. package/build/lib/abis/ekuboCore.js +1341 -0
  8. package/build/lib/abis/ekuboCore.js.map +1 -0
  9. package/build/lib/abis/multiplyAbi.d.ts +245 -0
  10. package/build/lib/abis/multiplyAbi.js +341 -0
  11. package/build/lib/abis/multiplyAbi.js.map +1 -0
  12. package/build/lib/abis/poolAbi.d.ts +289 -0
  13. package/build/lib/abis/poolAbi.js +402 -0
  14. package/build/lib/abis/poolAbi.js.map +1 -0
  15. package/build/lib/abis/routerAbi.d.ts +88 -0
  16. package/build/lib/abis/routerAbi.js +86 -0
  17. package/build/lib/abis/routerAbi.js.map +1 -0
  18. package/build/lib/constants/index.d.ts +9 -3
  19. package/build/lib/constants/index.js +8 -3
  20. package/build/lib/constants/index.js.map +1 -1
  21. package/build/lib/utils/contracts.d.ts +535 -89
  22. package/build/lib/utils/contracts.js +39 -5
  23. package/build/lib/utils/contracts.js.map +1 -1
  24. package/build/lib/utils/ekubo.d.ts +55 -0
  25. package/build/lib/utils/ekubo.js +81 -0
  26. package/build/lib/utils/ekubo.js.map +1 -0
  27. package/build/lib/utils/getEkuboQuote.d.ts +4 -0
  28. package/build/lib/utils/getEkuboQuote.js +116 -0
  29. package/build/lib/utils/getEkuboQuote.js.map +1 -0
  30. package/build/lib/utils/math.d.ts +8 -0
  31. package/build/lib/utils/math.js +22 -0
  32. package/build/lib/utils/math.js.map +1 -0
  33. package/build/lib/utils/multiplyCalls.d.ts +10 -0
  34. package/build/lib/utils/multiplyCalls.js +248 -0
  35. package/build/lib/utils/multiplyCalls.js.map +1 -0
  36. package/build/lib/utils/pools.d.ts +8 -0
  37. package/build/lib/utils/pools.js +72 -0
  38. package/build/lib/utils/pools.js.map +1 -0
  39. package/build/lib/utils/tokens.d.ts +6 -0
  40. package/build/lib/utils/tokens.js +23 -0
  41. package/build/lib/utils/tokens.js.map +1 -0
  42. package/build/schemas/index.d.ts +176 -0
  43. package/build/schemas/index.js +201 -1
  44. package/build/schemas/index.js.map +1 -1
  45. package/build/tools/read/getPools.d.ts +3 -0
  46. package/build/tools/read/getPools.js +57 -0
  47. package/build/tools/read/getPools.js.map +1 -0
  48. package/build/tools/read/getPositions.d.ts +3 -0
  49. package/build/tools/read/getPositions.js +43 -0
  50. package/build/tools/read/getPositions.js.map +1 -0
  51. package/build/tools/read/getTokens.d.ts +3 -0
  52. package/build/tools/read/getTokens.js +50 -0
  53. package/build/tools/read/getTokens.js.map +1 -0
  54. package/build/tools/write/deposit_borrow.d.ts +10 -0
  55. package/build/tools/write/deposit_borrow.js +312 -0
  56. package/build/tools/write/deposit_borrow.js.map +1 -0
  57. package/build/tools/write/deposit_earn.d.ts +10 -0
  58. package/build/tools/write/deposit_earn.js +82 -0
  59. package/build/tools/write/deposit_earn.js.map +1 -0
  60. package/build/tools/write/deposit_multiply.d.ts +10 -0
  61. package/build/tools/write/deposit_multiply.js +140 -0
  62. package/build/tools/write/deposit_multiply.js.map +1 -0
  63. package/build/tools/write/repay_borrow.d.ts +10 -0
  64. package/build/tools/write/repay_borrow.js +358 -0
  65. package/build/tools/write/repay_borrow.js.map +1 -0
  66. package/build/tools/write/update_multiply.d.ts +10 -0
  67. package/build/tools/write/update_multiply.js +264 -0
  68. package/build/tools/write/update_multiply.js.map +1 -0
  69. package/build/tools/write/withdraw_earn.d.ts +10 -0
  70. package/build/tools/write/withdraw_earn.js +116 -0
  71. package/build/tools/write/withdraw_earn.js.map +1 -0
  72. package/build/tools/write/withdraw_multiply.d.ts +9 -0
  73. package/build/tools/write/withdraw_multiply.js +187 -0
  74. package/build/tools/write/withdraw_multiply.js.map +1 -0
  75. package/package.json +6 -5
  76. package/build/lib/abis/erc20Abi.d.ts +0 -89
  77. package/build/lib/abis/erc20Abi.js +0 -128
  78. package/build/lib/abis/erc20Abi.js.map +0 -1
  79. package/build/tools/depositService.d.ts +0 -19
  80. package/build/tools/depositService.js +0 -117
  81. package/build/tools/depositService.js.map +0 -1
  82. package/build/tools/withdrawService.d.ts +0 -20
  83. package/build/tools/withdrawService.js +0 -122
  84. package/build/tools/withdrawService.js.map +0 -1
@@ -0,0 +1,50 @@
1
+ import { z } from 'zod';
2
+ import { VESU_API_URL } from '../../lib/constants/index.js';
3
+ import { addressSchema } from '../../interfaces/index.js';
4
+ const tokenParser = z.object({
5
+ address: addressSchema,
6
+ name: z.string(),
7
+ symbol: z.string(),
8
+ decimals: z.number(),
9
+ });
10
+ export const getTokens = async (env, params) => {
11
+ try {
12
+ const response = await fetch(`${VESU_API_URL}/tokens`);
13
+ if (!response.ok) {
14
+ throw new Error(`API request failed with status ${response.status}`);
15
+ }
16
+ const data = await response.json();
17
+ const parsedTokens = z
18
+ .object({ data: z.array(tokenParser) })
19
+ .transform(({ data }) => data)
20
+ .parse(data);
21
+ let tokens = parsedTokens.map((token) => ({
22
+ name: token.name,
23
+ address: token.address,
24
+ symbol: token.symbol,
25
+ decimals: token.decimals,
26
+ }));
27
+ if (params.address) {
28
+ const normalizedAddress = params.address.toLowerCase();
29
+ tokens = tokens.filter((token) => token.address.toLowerCase() === normalizedAddress);
30
+ }
31
+ if (params.symbol) {
32
+ const normalizedSymbol = params.symbol.toLowerCase();
33
+ tokens = tokens.filter((token) => token.symbol.toLowerCase() === normalizedSymbol);
34
+ }
35
+ return {
36
+ status: 'success',
37
+ data: tokens,
38
+ };
39
+ }
40
+ catch (error) {
41
+ console.error('Error fetching tokens:', error);
42
+ return {
43
+ status: 'failure',
44
+ error: error instanceof Error
45
+ ? `Failed to fetch tokens: ${error.message}`
46
+ : 'Failed to fetch tokens: Unknown error',
47
+ };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AO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAC,CAAC,CAAC;QAGJ,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACvD,MAAM,GAAG,MAAM,CAAC,MAAM,CACpB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,iBAAiB,CAC7D,CAAC;QACJ,CAAC;QAGD,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACrD,MAAM,GAAG,MAAM,CAAC,MAAM,CACpB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,gBAAgB,CAC3D,CAAC;QACJ,CAAC;QAED,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,KAAK,EACH,KAAK,YAAY,KAAK;gBACpB,CAAC,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE;gBAC5C,CAAC,CAAC,uCAAuC;SAC9C,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { DepositBorrowParams, DepositBorrowResult } from '../../interfaces/index.js';
2
+ import { onchainWrite, toolResult } from '@kasarlabs/ask-starknet-core';
3
+ export declare class DepositBorrowService {
4
+ private env;
5
+ private walletAddress;
6
+ constructor(env: onchainWrite, walletAddress: string);
7
+ depositBorrowTransaction(params: DepositBorrowParams, env: onchainWrite): Promise<DepositBorrowResult>;
8
+ }
9
+ export declare const createDepositBorrowService: (env: onchainWrite, walletAddress?: string) => DepositBorrowService;
10
+ export declare const depositBorrowPosition: (env: onchainWrite, params: DepositBorrowParams) => Promise<toolResult>;
@@ -0,0 +1,312 @@
1
+ import { Account, CairoCustomEnum, Contract } from 'starknet';
2
+ import { GENESIS_POOLID } from '../../lib/constants/index.js';
3
+ import { toI257, toBN, toHex } from '../../lib/utils/num.js';
4
+ import { addressSchema } from '../../interfaces/index.js';
5
+ import { getPool, getExtensionContractAddress, getSingletonAddress, } from '../../lib/utils/pools.js';
6
+ import { formatTokenAmount } from '../../lib/utils/tokens.js';
7
+ import { getSingletonContract, getExtensionContract, getPoolContract, getErc20Contract, } from '../../lib/utils/contracts.js';
8
+ export class DepositBorrowService {
9
+ constructor(env, walletAddress) {
10
+ this.env = env;
11
+ this.walletAddress = walletAddress;
12
+ }
13
+ async depositBorrowTransaction(params, env) {
14
+ try {
15
+ const account = new Account({
16
+ provider: this.env.provider,
17
+ address: this.walletAddress,
18
+ signer: this.env.account.signer,
19
+ });
20
+ const poolId = String(params.poolId || GENESIS_POOLID);
21
+ let pool;
22
+ try {
23
+ pool = await getPool(poolId);
24
+ }
25
+ catch (error) {
26
+ throw new Error(`Failed to get pool: ${error instanceof Error ? error.message : 'Unknown error'}`);
27
+ }
28
+ const extensionContractAddressRaw = getExtensionContractAddress(pool);
29
+ if (!extensionContractAddressRaw) {
30
+ throw new Error('Pool extension contract address not available');
31
+ }
32
+ const extensionContractAddressParse = addressSchema.safeParse(extensionContractAddressRaw);
33
+ if (!extensionContractAddressParse.success) {
34
+ throw new Error(`Invalid extension contract address: ${extensionContractAddressRaw}. ${extensionContractAddressParse.error.message}`);
35
+ }
36
+ const extensionContractAddress = extensionContractAddressParse.data;
37
+ let singletonAddress;
38
+ try {
39
+ const singletonAddressRaw = await getSingletonAddress(pool);
40
+ if (!singletonAddressRaw) {
41
+ throw new Error('Singleton address not available');
42
+ }
43
+ const singletonAddressHex = typeof singletonAddressRaw === 'bigint'
44
+ ? toHex(singletonAddressRaw)
45
+ : singletonAddressRaw;
46
+ const singletonAddressParse = addressSchema.safeParse(singletonAddressHex);
47
+ if (!singletonAddressParse.success) {
48
+ throw new Error(`Invalid singleton address: ${singletonAddressHex}. ${singletonAddressParse.error.message}`);
49
+ }
50
+ singletonAddress = singletonAddressParse.data;
51
+ }
52
+ catch (error) {
53
+ throw new Error(`Failed to get singleton address: ${error instanceof Error ? error.message : 'Unknown error'}`);
54
+ }
55
+ const extensionContract = getExtensionContract(extensionContractAddress);
56
+ const collateralAsset = pool.assets.find((a) => a.symbol.toUpperCase() === params.collateralTokenSymbol.toUpperCase());
57
+ const debtAsset = pool.assets.find((a) => a.symbol.toUpperCase() === params.debtTokenSymbol.toUpperCase());
58
+ if (!collateralAsset) {
59
+ throw new Error('Collateral asset not found in pool');
60
+ }
61
+ if (!debtAsset) {
62
+ throw new Error('Debt asset not found in pool');
63
+ }
64
+ const formattedAmount = formatTokenAmount(params.depositAmount, collateralAsset.decimals);
65
+ const collateralAmount = BigInt(formattedAmount);
66
+ let maxLTVValue;
67
+ let singletonContract = null;
68
+ if (pool.protocolVersion === 'v2') {
69
+ const poolContract = getPoolContract(extensionContractAddress);
70
+ let pairConfig;
71
+ try {
72
+ pairConfig = await poolContract.pair_config(collateralAsset.address, debtAsset.address);
73
+ }
74
+ catch (error) {
75
+ throw new Error(`Failed to get pair config: ${error instanceof Error ? error.message : 'Unknown error'}`);
76
+ }
77
+ maxLTVValue = toBN(pairConfig.max_ltv);
78
+ }
79
+ else {
80
+ singletonContract = getSingletonContract(singletonAddress);
81
+ let ltvConfig;
82
+ try {
83
+ ltvConfig = await singletonContract.ltv_config(poolId, collateralAsset.address, debtAsset.address);
84
+ }
85
+ catch (error) {
86
+ throw new Error(`Failed to get LTV config: ${error instanceof Error ? error.message : 'Unknown error'}`);
87
+ }
88
+ maxLTVValue = toBN(ltvConfig.max_ltv);
89
+ }
90
+ if (!params.targetLTV) {
91
+ throw new Error('Target LTV is required');
92
+ }
93
+ const ltvPercent = BigInt(params.targetLTV);
94
+ if (ltvPercent >= 100n || ltvPercent < 0n) {
95
+ throw new Error('Target LTV must be between 0 and 99');
96
+ }
97
+ const targetLTVValue = ltvPercent * 100n;
98
+ if (targetLTVValue > maxLTVValue) {
99
+ const maxLTVPercent = Number(maxLTVValue) / 100;
100
+ throw new Error(`Target LTV (${params.targetLTV}%) exceeds maximum LTV (${maxLTVPercent}%)`);
101
+ }
102
+ let collateralPrice;
103
+ let debtPrice;
104
+ if (pool.protocolVersion === 'v2') {
105
+ const poolContract = getPoolContract(extensionContractAddress);
106
+ try {
107
+ collateralPrice = await poolContract.price(collateralAsset.address);
108
+ }
109
+ catch (error) {
110
+ throw new Error(`Failed to get collateral price: ${error instanceof Error ? error.message : 'Unknown error'}`);
111
+ }
112
+ try {
113
+ debtPrice = await poolContract.price(debtAsset.address);
114
+ }
115
+ catch (error) {
116
+ throw new Error(`Failed to get debt price: ${error instanceof Error ? error.message : 'Unknown error'}`);
117
+ }
118
+ }
119
+ else {
120
+ try {
121
+ collateralPrice = await extensionContract.price(poolId, collateralAsset.address);
122
+ }
123
+ catch (error) {
124
+ throw new Error(`Failed to get collateral price: ${error instanceof Error ? error.message : 'Unknown error'}`);
125
+ }
126
+ try {
127
+ debtPrice = await extensionContract.price(poolId, debtAsset.address);
128
+ }
129
+ catch (error) {
130
+ throw new Error(`Failed to get debt price: ${error instanceof Error ? error.message : 'Unknown error'}`);
131
+ }
132
+ }
133
+ if (!collateralPrice.is_valid || !debtPrice.is_valid) {
134
+ throw new Error('Invalid price data for assets');
135
+ }
136
+ const collateralPriceBN = toBN(collateralPrice.value);
137
+ const debtPriceBN = toBN(debtPrice.value);
138
+ const collateralValueUSD = (collateralAmount * collateralPriceBN) /
139
+ 10n ** BigInt(collateralAsset.decimals);
140
+ const safetyMargin = 999n;
141
+ const adjustedLTV = (targetLTVValue * safetyMargin) / 1000n;
142
+ const debtValueUSD = (collateralValueUSD * adjustedLTV) / 10000n;
143
+ const debtAmountRaw = (debtValueUSD * 10n ** BigInt(debtAsset.decimals)) / debtPriceBN;
144
+ const debtAmount = debtAmountRaw > 0n ? debtAmountRaw : 0n;
145
+ if (debtAmount === 0n) {
146
+ throw new Error('Calculated debt amount is zero');
147
+ }
148
+ const MAX_U256 = 2n ** 256n - 1n;
149
+ if (debtAmount > MAX_U256 || collateralAmount > MAX_U256) {
150
+ throw new Error('Amount exceeds maximum u256 limit');
151
+ }
152
+ let collateralVTokenApproveCall;
153
+ try {
154
+ const approveToAddress = pool.protocolVersion === 'v2'
155
+ ? extensionContractAddress
156
+ : singletonAddress;
157
+ if (!approveToAddress) {
158
+ throw new Error('Approve address not available');
159
+ }
160
+ const tokenContract = getErc20Contract(collateralAsset.address);
161
+ collateralVTokenApproveCall =
162
+ await tokenContract.populateTransaction.approve(approveToAddress, collateralAmount);
163
+ }
164
+ catch (error) {
165
+ throw new Error(`Failed to approve token: ${error instanceof Error ? error.message : 'Unknown error'}`);
166
+ }
167
+ let modifyPositionParams;
168
+ let contractForTx;
169
+ if (pool.protocolVersion === 'v2') {
170
+ const typedPoolContract = getPoolContract(extensionContractAddress);
171
+ const poolContract = new Contract({
172
+ abi: typedPoolContract.abi,
173
+ address: extensionContractAddress,
174
+ providerOrAccount: env.provider,
175
+ });
176
+ contractForTx = poolContract;
177
+ const assetsEnum = new CairoCustomEnum({ Assets: {} });
178
+ modifyPositionParams = {
179
+ collateral_asset: collateralAsset.address,
180
+ debt_asset: debtAsset.address,
181
+ user: account.address,
182
+ collateral: {
183
+ denomination: assetsEnum,
184
+ value: toI257(collateralAmount),
185
+ },
186
+ debt: {
187
+ denomination: assetsEnum,
188
+ value: toI257(debtAmount),
189
+ },
190
+ };
191
+ }
192
+ else {
193
+ if (!singletonContract) {
194
+ singletonContract = getSingletonContract(singletonAddress);
195
+ }
196
+ contractForTx = new Contract({
197
+ abi: singletonContract.abi,
198
+ address: singletonAddress,
199
+ providerOrAccount: env.provider,
200
+ });
201
+ const deltaEnum = new CairoCustomEnum({ Delta: {} });
202
+ const assetsEnum = new CairoCustomEnum({ Assets: {} });
203
+ modifyPositionParams = {
204
+ pool_id: String(poolId),
205
+ collateral_asset: collateralAsset.address,
206
+ debt_asset: debtAsset.address,
207
+ user: account.address,
208
+ collateral: {
209
+ amount_type: deltaEnum,
210
+ denomination: assetsEnum,
211
+ value: toI257(collateralAmount),
212
+ },
213
+ debt: {
214
+ amount_type: deltaEnum,
215
+ denomination: assetsEnum,
216
+ value: toI257(debtAmount),
217
+ },
218
+ data: [],
219
+ };
220
+ }
221
+ let modifyPositionCall;
222
+ try {
223
+ modifyPositionCall =
224
+ await contractForTx.populateTransaction.modify_position(modifyPositionParams);
225
+ }
226
+ catch (error) {
227
+ throw new Error(`Failed to populate modify_position transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
228
+ }
229
+ const provider = env.provider;
230
+ const wallet = env.account;
231
+ const calls = [
232
+ {
233
+ contractAddress: collateralVTokenApproveCall.contractAddress,
234
+ entrypoint: collateralVTokenApproveCall.entrypoint,
235
+ calldata: collateralVTokenApproveCall.calldata,
236
+ },
237
+ {
238
+ contractAddress: modifyPositionCall.contractAddress,
239
+ entrypoint: modifyPositionCall.entrypoint,
240
+ calldata: modifyPositionCall.calldata,
241
+ },
242
+ ];
243
+ let tx;
244
+ try {
245
+ tx = await wallet.execute(calls);
246
+ }
247
+ catch (error) {
248
+ throw new Error(`Failed to execute transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
249
+ }
250
+ try {
251
+ await provider.waitForTransaction(tx.transaction_hash);
252
+ }
253
+ catch (error) {
254
+ throw new Error(`Failed to wait for transaction: ${error instanceof Error ? error.message : 'Unknown error'}`);
255
+ }
256
+ const result = {
257
+ status: 'success',
258
+ amount: params.depositAmount,
259
+ collateralSymbol: params.collateralTokenSymbol,
260
+ debtSymbol: params.debtTokenSymbol,
261
+ recipient_address: account.address,
262
+ transaction_hash: tx.transaction_hash,
263
+ };
264
+ return result;
265
+ }
266
+ catch (error) {
267
+ console.error('Deposit borrow error:', error);
268
+ return {
269
+ status: 'failure',
270
+ error: error instanceof Error ? error.message : 'Unknown error',
271
+ };
272
+ }
273
+ }
274
+ }
275
+ export const createDepositBorrowService = (env, walletAddress) => {
276
+ if (!walletAddress) {
277
+ throw new Error('Wallet address not configured');
278
+ }
279
+ return new DepositBorrowService(env, walletAddress);
280
+ };
281
+ export const depositBorrowPosition = async (env, params) => {
282
+ const accountAddress = env.account?.address;
283
+ try {
284
+ const depositBorrowService = createDepositBorrowService(env, accountAddress);
285
+ const result = await depositBorrowService.depositBorrowTransaction(params, env);
286
+ if (result.status === 'success') {
287
+ return {
288
+ status: 'success',
289
+ data: {
290
+ amount: result.amount,
291
+ collateralSymbol: result.collateralSymbol,
292
+ debtSymbol: result.debtSymbol,
293
+ recipient_address: result.recipient_address,
294
+ transaction_hash: result.transaction_hash,
295
+ },
296
+ };
297
+ }
298
+ else {
299
+ return {
300
+ status: 'failure',
301
+ error: result.error || 'Unknown error',
302
+ };
303
+ }
304
+ }
305
+ catch (error) {
306
+ return {
307
+ status: 'failure',
308
+ error: error instanceof Error ? error.message : 'Unknown error',
309
+ };
310
+ }
311
+ };
312
+ //# sourceMappingURL=deposit_borrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deposit_borrow.js","sourceRoot":"","sources":["../../../src/tools/write/deposit_borrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAK9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAe,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EACL,OAAO,EACP,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,0BAA0B,C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SAAS;gBACjB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,eAAe;aACvC,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;SAChE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { DepositParams } from '../../interfaces/index.js';
2
+ import { onchainWrite, toolResult } from '@kasarlabs/ask-starknet-core';
3
+ export declare class DepositEarnService {
4
+ private env;
5
+ private walletAddress;
6
+ constructor(env: onchainWrite, walletAddress: string);
7
+ depositEarnTransaction(params: DepositParams, env: onchainWrite): Promise<toolResult>;
8
+ }
9
+ export declare const createDepositEarnService: (env: onchainWrite, walletAddress?: string) => DepositEarnService;
10
+ export declare const depositEarnPosition: (env: onchainWrite, params: DepositParams) => Promise<toolResult>;
@@ -0,0 +1,82 @@
1
+ import { Account } from 'starknet';
2
+ import { GENESIS_POOLID } from '../../lib/constants/index.js';
3
+ import { toU256 } from '../../lib/utils/num.js';
4
+ import { getVTokenContract } from '../../lib/utils/contracts.js';
5
+ import { getPool } from '../../lib/utils/pools.js';
6
+ import { approveVTokenCalls, formatTokenAmount, } from '../../lib/utils/tokens.js';
7
+ export class DepositEarnService {
8
+ constructor(env, walletAddress) {
9
+ this.env = env;
10
+ this.walletAddress = walletAddress;
11
+ }
12
+ async depositEarnTransaction(params, env) {
13
+ try {
14
+ const account = new Account({
15
+ provider: this.env.provider,
16
+ address: this.walletAddress,
17
+ signer: this.env.account.signer,
18
+ });
19
+ const poolId = params.poolId || GENESIS_POOLID;
20
+ const pool = await getPool(poolId);
21
+ const collateralPoolAsset = pool.assets.find((a) => a.symbol.toUpperCase() === params.depositTokenSymbol.toUpperCase());
22
+ if (!collateralPoolAsset) {
23
+ throw new Error('Collateral asset not found in pool');
24
+ }
25
+ const formattedAmount = formatTokenAmount(params.depositAmount, collateralPoolAsset.decimals);
26
+ const collateralAmount = BigInt(formattedAmount);
27
+ const vtokenContract = getVTokenContract(collateralPoolAsset.vToken.address);
28
+ const vTokenApproveCall = await approveVTokenCalls(collateralPoolAsset.address, collateralPoolAsset.vToken.address, collateralAmount);
29
+ const depositVTokenCall = await vtokenContract.populateTransaction.deposit(toU256(collateralAmount), account.address);
30
+ const provider = env.provider;
31
+ const tx = await account.execute([
32
+ {
33
+ contractAddress: vTokenApproveCall.contractAddress,
34
+ entrypoint: vTokenApproveCall.entrypoint,
35
+ calldata: vTokenApproveCall.calldata,
36
+ },
37
+ {
38
+ contractAddress: depositVTokenCall.contractAddress,
39
+ entrypoint: depositVTokenCall.entrypoint,
40
+ calldata: depositVTokenCall.calldata,
41
+ },
42
+ ]);
43
+ await provider.waitForTransaction(tx.transaction_hash);
44
+ return {
45
+ status: 'success',
46
+ data: {
47
+ amount: params.depositAmount,
48
+ symbol: params.depositTokenSymbol,
49
+ recipients_address: account.address,
50
+ transaction_hash: tx.transaction_hash,
51
+ },
52
+ };
53
+ }
54
+ catch (error) {
55
+ return {
56
+ status: 'failure',
57
+ error: error instanceof Error ? error.message : 'Unknown error',
58
+ };
59
+ }
60
+ }
61
+ }
62
+ export const createDepositEarnService = (env, walletAddress) => {
63
+ if (!walletAddress) {
64
+ throw new Error('Wallet address not configured');
65
+ }
66
+ return new DepositEarnService(env, walletAddress);
67
+ };
68
+ export const depositEarnPosition = async (env, params) => {
69
+ const accountAddress = env.account?.address;
70
+ try {
71
+ const depositEarnService = createDepositEarnService(env, accountAddress);
72
+ const res = await depositEarnService.depositEarnTransaction(params, env);
73
+ return res;
74
+ }
75
+ catch (error) {
76
+ return {
77
+ status: 'failure',
78
+ error: error instanceof Error ? error.message : 'Unknown error',
79
+ };
80
+ }
81
+ };
82
+ //# sourceMappingURL=deposit_earn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deposit_earn.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OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AASD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,GAAiB,EACjB,aAAsB,EACF,EAAE;IACtB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AACpD,CAAC,CAAC;AAQF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,GAAiB,EACjB,MAAqB,EACA,EAAE;IACvB,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;IAC5C,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,wBAAwB,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACzE,MAAM,GAAG,GAAG,MAAM,kBAAkB,CAAC,sBAAsB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACzE,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;SAChE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { DepositMultiplyParams, DepositMultiplyResult } from '../../interfaces/index.js';
2
+ import { onchainWrite, toolResult } from '@kasarlabs/ask-starknet-core';
3
+ export declare class DepositMultiplyService {
4
+ private env;
5
+ private walletAddress;
6
+ constructor(env: onchainWrite, walletAddress: string);
7
+ depositMultiplyTransaction(params: DepositMultiplyParams, env: onchainWrite): Promise<DepositMultiplyResult>;
8
+ }
9
+ export declare const createDepositMultiplyService: (env: onchainWrite, walletAddress?: string) => DepositMultiplyService;
10
+ export declare const depositMultiplyPosition: (env: onchainWrite, params: DepositMultiplyParams) => Promise<toolResult>;
@@ -0,0 +1,140 @@
1
+ import { Account } from 'starknet';
2
+ import { GENESIS_POOLID } from '../../lib/constants/index.js';
3
+ import { toBN } from '../../lib/utils/num.js';
4
+ import { getPool } from '../../lib/utils/pools.js';
5
+ import { formatTokenAmount } from '../../lib/utils/tokens.js';
6
+ import { getPoolContract } from '../../lib/utils/contracts.js';
7
+ import { getEkuboQuoteFromAPI, } from '../../lib/utils/ekubo.js';
8
+ import { buildMultiplyCalls } from '../../lib/utils/multiplyCalls.js';
9
+ export class DepositMultiplyService {
10
+ constructor(env, walletAddress) {
11
+ this.env = env;
12
+ this.walletAddress = walletAddress;
13
+ }
14
+ async depositMultiplyTransaction(params, env) {
15
+ try {
16
+ const account = new Account({
17
+ provider: this.env.provider,
18
+ address: this.walletAddress,
19
+ signer: this.env.account.signer,
20
+ });
21
+ const poolId = (params.poolId || GENESIS_POOLID);
22
+ const pool = await getPool(poolId);
23
+ if (pool.protocolVersion !== 'v2') {
24
+ throw new Error(`Multiply operations are only supported on v2 pools. This pool is ${pool.protocolVersion}`);
25
+ }
26
+ const poolContractAddress = poolId;
27
+ const collateralAsset = pool.assets.find((a) => a.symbol.toUpperCase() === params.collateralTokenSymbol.toUpperCase());
28
+ const debtAsset = pool.assets.find((a) => a.symbol.toUpperCase() === params.debtTokenSymbol.toUpperCase());
29
+ if (!collateralAsset) {
30
+ throw new Error('Collateral asset not found in pool');
31
+ }
32
+ if (!debtAsset) {
33
+ throw new Error('Debt asset not found in pool');
34
+ }
35
+ const formattedAmount = formatTokenAmount(params.depositAmount, collateralAsset.decimals);
36
+ const collateralAmount = BigInt(formattedAmount);
37
+ const poolContract = getPoolContract(poolContractAddress);
38
+ const pairConfig = await poolContract.pair_config(collateralAsset.address, debtAsset.address);
39
+ if (!params.targetLTV) {
40
+ throw new Error('Target LTV is required');
41
+ }
42
+ const ltvPercent = BigInt(params.targetLTV);
43
+ if (ltvPercent >= 100n || ltvPercent < 0n) {
44
+ throw new Error('Target LTV must be between 0 and 99');
45
+ }
46
+ const targetLTVValue = ltvPercent * 100n;
47
+ const maxLTVValue = toBN(pairConfig.max_ltv);
48
+ if (targetLTVValue > maxLTVValue) {
49
+ const maxLTVPercent = Number(maxLTVValue) / 100;
50
+ throw new Error(`Target LTV (${params.targetLTV}%) exceeds maximum LTV (${maxLTVPercent}%)`);
51
+ }
52
+ const collateralPrice = await poolContract.price(collateralAsset.address);
53
+ const debtPrice = await poolContract.price(debtAsset.address);
54
+ if (!collateralPrice.is_valid || !debtPrice.is_valid) {
55
+ throw new Error('Invalid price data for assets');
56
+ }
57
+ const collateralValueUSD = (collateralAmount * toBN(collateralPrice.value)) /
58
+ 10n ** BigInt(collateralAsset.decimals);
59
+ const safetyMargin = 999n;
60
+ const adjustedLTV = (targetLTVValue * safetyMargin) / 1000n;
61
+ const debtValueUSD = (collateralValueUSD * adjustedLTV) / (10000n - adjustedLTV);
62
+ const debtAmount = (debtValueUSD * 10n ** BigInt(debtAsset.decimals)) /
63
+ toBN(debtPrice.value);
64
+ const provider = env.provider;
65
+ const wallet = env.account;
66
+ let ekuboQuote = undefined;
67
+ const slippageBps = BigInt(params.ekuboSlippage ?? 50);
68
+ const extraCollateralAmount = (debtValueUSD * 10n ** BigInt(collateralAsset.decimals)) /
69
+ toBN(collateralPrice.value);
70
+ try {
71
+ ekuboQuote = await getEkuboQuoteFromAPI(provider, collateralAsset, debtAsset, extraCollateralAmount, false);
72
+ }
73
+ catch (error) {
74
+ console.warn('Failed to get Ekubo quote from API, continuing without swap routing:', error);
75
+ ekuboQuote = undefined;
76
+ }
77
+ const callsData = await buildMultiplyCalls(collateralAmount, collateralAsset, extraCollateralAmount, debtAsset, poolContractAddress, account, provider, ekuboQuote, slippageBps);
78
+ const calls = callsData.map((call) => ({
79
+ contractAddress: call.contractAddress,
80
+ entrypoint: call.entrypoint,
81
+ calldata: call.calldata,
82
+ }));
83
+ const tx = await wallet.execute(calls);
84
+ await provider.waitForTransaction(tx.transaction_hash);
85
+ const result = {
86
+ status: 'success',
87
+ amount: params.depositAmount,
88
+ collateralSymbol: params.collateralTokenSymbol,
89
+ debtSymbol: params.debtTokenSymbol,
90
+ recipient_address: account.address,
91
+ transaction_hash: tx.transaction_hash,
92
+ };
93
+ return result;
94
+ }
95
+ catch (error) {
96
+ return {
97
+ status: 'failure',
98
+ error: error instanceof Error ? error.message : 'Unknown error',
99
+ };
100
+ }
101
+ }
102
+ }
103
+ export const createDepositMultiplyService = (env, walletAddress) => {
104
+ if (!walletAddress) {
105
+ throw new Error('Wallet address not configured');
106
+ }
107
+ return new DepositMultiplyService(env, walletAddress);
108
+ };
109
+ export const depositMultiplyPosition = async (env, params) => {
110
+ const accountAddress = env.account?.address;
111
+ try {
112
+ const depositMultiplyService = createDepositMultiplyService(env, accountAddress);
113
+ const result = await depositMultiplyService.depositMultiplyTransaction(params, env);
114
+ if (result.status === 'success') {
115
+ return {
116
+ status: 'success',
117
+ data: {
118
+ amount: result.amount,
119
+ collateralSymbol: result.collateralSymbol,
120
+ debtSymbol: result.debtSymbol,
121
+ recipient_address: result.recipient_address,
122
+ transaction_hash: result.transaction_hash,
123
+ },
124
+ };
125
+ }
126
+ else {
127
+ return {
128
+ status: 'failure',
129
+ error: result.error || 'Unknown error',
130
+ };
131
+ }
132
+ }
133
+ catch (error) {
134
+ return {
135
+ status: 'failure',
136
+ error: error instanceof Error ? error.message : 'Unknown error',
137
+ };
138
+ }
139
+ };
140
+ //# sourceMappingURL=deposit_multiply.js.map