@steerprotocol/sdk 1.2.0 → 1.4.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 (70) hide show
  1. package/README.md +54 -0
  2. package/dist/cjs/base/StakingClient.js +345 -0
  3. package/dist/cjs/base/StakingClient.js.map +1 -0
  4. package/dist/cjs/base/VaultClient.js +57 -118
  5. package/dist/cjs/base/VaultClient.js.map +1 -1
  6. package/dist/cjs/base/vault/deposit/index.js +484 -0
  7. package/dist/cjs/base/vault/deposit/index.js.map +1 -0
  8. package/dist/cjs/base/vault/deposit/types.js +3 -0
  9. package/dist/cjs/base/vault/deposit/types.js.map +1 -0
  10. package/dist/cjs/base/vault/utils.js +432 -0
  11. package/dist/cjs/base/vault/utils.js.map +1 -0
  12. package/dist/cjs/base/vault/withdraw/index.js +155 -0
  13. package/dist/cjs/base/vault/withdraw/index.js.map +1 -0
  14. package/dist/cjs/base/vault/withdraw/types.js +3 -0
  15. package/dist/cjs/base/vault/withdraw/types.js.map +1 -0
  16. package/dist/cjs/const/chain.js +96 -0
  17. package/dist/cjs/const/chain.js.map +1 -0
  18. package/dist/cjs/const/network.js +801 -0
  19. package/dist/cjs/const/network.js.map +1 -0
  20. package/dist/cjs/const/protocol.js +55 -0
  21. package/dist/cjs/const/protocol.js.map +1 -0
  22. package/dist/cjs/index.js +3 -0
  23. package/dist/cjs/index.js.map +1 -1
  24. package/dist/esm/base/StakingClient.js +341 -0
  25. package/dist/esm/base/StakingClient.js.map +1 -0
  26. package/dist/esm/base/VaultClient.js +57 -118
  27. package/dist/esm/base/VaultClient.js.map +1 -1
  28. package/dist/esm/base/vault/deposit/index.js +480 -0
  29. package/dist/esm/base/vault/deposit/index.js.map +1 -0
  30. package/dist/esm/base/vault/deposit/types.js +2 -0
  31. package/dist/esm/base/vault/deposit/types.js.map +1 -0
  32. package/dist/esm/base/vault/utils.js +425 -0
  33. package/dist/esm/base/vault/utils.js.map +1 -0
  34. package/dist/esm/base/vault/withdraw/index.js +151 -0
  35. package/dist/esm/base/vault/withdraw/index.js.map +1 -0
  36. package/dist/esm/base/vault/withdraw/types.js +2 -0
  37. package/dist/esm/base/vault/withdraw/types.js.map +1 -0
  38. package/dist/esm/const/chain.js +93 -0
  39. package/dist/esm/const/chain.js.map +1 -0
  40. package/dist/esm/const/network.js +797 -0
  41. package/dist/esm/const/network.js.map +1 -0
  42. package/dist/esm/const/protocol.js +47 -0
  43. package/dist/esm/const/protocol.js.map +1 -0
  44. package/dist/esm/index.js +3 -0
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/types/base/StakingClient.d.ts +81 -0
  47. package/dist/types/base/StakingClient.d.ts.map +1 -0
  48. package/dist/types/base/VaultClient.d.ts +81 -16
  49. package/dist/types/base/VaultClient.d.ts.map +1 -1
  50. package/dist/types/base/vault/deposit/index.d.ts +74 -0
  51. package/dist/types/base/vault/deposit/index.d.ts.map +1 -0
  52. package/dist/types/base/vault/deposit/types.d.ts +42 -0
  53. package/dist/types/base/vault/deposit/types.d.ts.map +1 -0
  54. package/dist/types/base/vault/utils.d.ts +26 -0
  55. package/dist/types/base/vault/utils.d.ts.map +1 -0
  56. package/dist/types/base/vault/withdraw/index.d.ts +45 -0
  57. package/dist/types/base/vault/withdraw/index.d.ts.map +1 -0
  58. package/dist/types/base/vault/withdraw/types.d.ts +13 -0
  59. package/dist/types/base/vault/withdraw/types.d.ts.map +1 -0
  60. package/dist/types/const/chain.d.ts +88 -0
  61. package/dist/types/const/chain.d.ts.map +1 -0
  62. package/dist/types/const/network.d.ts +26 -0
  63. package/dist/types/const/network.d.ts.map +1 -0
  64. package/dist/types/const/protocol.d.ts +12 -0
  65. package/dist/types/const/protocol.d.ts.map +1 -0
  66. package/dist/types/index.d.ts +3 -0
  67. package/dist/types/index.d.ts.map +1 -1
  68. package/dist/types/types.d.ts +101 -1
  69. package/dist/types/types.d.ts.map +1 -1
  70. package/package.json +14 -13
package/README.md CHANGED
@@ -36,6 +36,60 @@ const steerClient = new SteerClient({
36
36
  const response = await steerClient.getData<YourDataType>('endpoint');
37
37
  ```
38
38
 
39
+ ## Staking Client
40
+
41
+ The StakingClient provides functionality for interacting with Steer Finance staking pools. It supports both single and dual reward staking pools.
42
+
43
+ ### Features
44
+
45
+ - Fetch available staking pools
46
+ - Stake and withdraw tokens
47
+ - Claim rewards
48
+ - Check earned rewards and balances
49
+ - Calculate APR for staking pools
50
+ - Support for both single and dual reward pools
51
+
52
+ ### Example Usage
53
+
54
+ ```typescript
55
+ // Initialize the staking client
56
+ const stakingClient = steerClient.staking;
57
+
58
+ // Get all staking pools
59
+ const pools = await stakingClient.getStakingPools();
60
+
61
+ // Get pools for a specific chain
62
+ const polygonPools = await stakingClient.getStakingPools(137); // Polygon chain ID
63
+
64
+ // Stake tokens
65
+ await stakingClient.stake({
66
+ stakingPool: '0x...', // staking pool address
67
+ amount: 1000000000000000000n // amount in wei
68
+ });
69
+
70
+ // Check earned rewards
71
+ const earned = await stakingClient.earned('0x...', '0x...'); // pool address, account address
72
+ console.log('Earned rewards:', earned.data);
73
+
74
+ // Calculate APR
75
+ const apr = stakingClient.calculateAPR(
76
+ pool,
77
+ rewardTokenPriceUSD,
78
+ totalStakedUSD
79
+ );
80
+ ```
81
+
82
+ ### Available Methods
83
+
84
+ - `getStakingPools(chainId?: number, protocol?: string)`: Fetch available staking pools
85
+ - `stake(params: StakeParams)`: Stake tokens in a pool
86
+ - `withdraw(params: WithdrawParams)`: Withdraw tokens from a pool
87
+ - `getReward(params: GetRewardParams)`: Claim rewards
88
+ - `earned(stakingPool: Address, account: Address)`: Get earned rewards
89
+ - `totalSupply(stakingPool: Address)`: Get total staked tokens
90
+ - `balanceOf(stakingPool: Address, account: Address)`: Get staked balance
91
+ - `calculateAPR(pool: StakingPool, rewardTokenPriceUSD: number, totalStakedUSD: number)`: Calculate current pool APR
92
+
39
93
  ## Requirements
40
94
 
41
95
  - Node.js >= 18.0.0
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StakingClient = void 0;
4
+ const SubgraphClient_1 = require("./SubgraphClient");
5
+ // ABIs for staking contracts
6
+ const SINGLE_REWARD_ABI = [
7
+ {
8
+ "inputs": [],
9
+ "name": "lastTimeRewardApplicable",
10
+ "outputs": [{ "type": "uint256" }],
11
+ "stateMutability": "view",
12
+ "type": "function"
13
+ },
14
+ {
15
+ "inputs": [{ "type": "address" }],
16
+ "name": "earned",
17
+ "outputs": [{ "type": "uint256" }],
18
+ "stateMutability": "view",
19
+ "type": "function"
20
+ },
21
+ {
22
+ "inputs": [],
23
+ "name": "totalSupply",
24
+ "outputs": [{ "type": "uint256" }],
25
+ "stateMutability": "view",
26
+ "type": "function"
27
+ },
28
+ {
29
+ "inputs": [{ "type": "address" }],
30
+ "name": "balanceOf",
31
+ "outputs": [{ "type": "uint256" }],
32
+ "stateMutability": "view",
33
+ "type": "function"
34
+ },
35
+ {
36
+ "inputs": [{ "type": "uint256" }],
37
+ "name": "stake",
38
+ "outputs": [],
39
+ "stateMutability": "nonpayable",
40
+ "type": "function"
41
+ },
42
+ {
43
+ "inputs": [{ "type": "uint256" }],
44
+ "name": "withdraw",
45
+ "outputs": [],
46
+ "stateMutability": "nonpayable",
47
+ "type": "function"
48
+ },
49
+ {
50
+ "inputs": [],
51
+ "name": "getReward",
52
+ "outputs": [],
53
+ "stateMutability": "nonpayable",
54
+ "type": "function"
55
+ },
56
+ {
57
+ "inputs": [],
58
+ "name": "exit",
59
+ "outputs": [],
60
+ "stateMutability": "nonpayable",
61
+ "type": "function"
62
+ }
63
+ ];
64
+ const DUAL_REWARD_ABI = [
65
+ ...SINGLE_REWARD_ABI,
66
+ {
67
+ "inputs": [{ "type": "address" }],
68
+ "name": "earnedA",
69
+ "outputs": [{ "type": "uint256" }],
70
+ "stateMutability": "view",
71
+ "type": "function"
72
+ },
73
+ {
74
+ "inputs": [{ "type": "address" }],
75
+ "name": "earnedB",
76
+ "outputs": [{ "type": "uint256" }],
77
+ "stateMutability": "view",
78
+ "type": "function"
79
+ }
80
+ ];
81
+ class StakingClient extends SubgraphClient_1.SubgraphClient {
82
+ constructor(client) {
83
+ super(client);
84
+ this.stakingPoolsEndpoint = 'https://9i52h964s3.execute-api.us-east-1.amazonaws.com/dev/staking-pools';
85
+ this.publicClient = client;
86
+ this.walletClient = client;
87
+ }
88
+ /**
89
+ * Fetches staking pool data from the API
90
+ * @param chainId Optional chain ID to filter pools
91
+ * @param protocol Optional protocol name to filter pools
92
+ */
93
+ async getStakingPools(chainId, protocol) {
94
+ try {
95
+ const response = await fetch(this.stakingPoolsEndpoint);
96
+ if (!response.ok) {
97
+ throw new Error('Failed to fetch staking pools');
98
+ }
99
+ let pools = await response.json();
100
+ // Apply filters if provided
101
+ if (chainId) {
102
+ pools = pools.filter(pool => pool.chainId === chainId);
103
+ }
104
+ if (protocol) {
105
+ pools = pools.filter(pool => pool.protocol === protocol);
106
+ }
107
+ return {
108
+ data: pools,
109
+ status: 200,
110
+ success: true,
111
+ };
112
+ }
113
+ catch (error) {
114
+ return {
115
+ data: null,
116
+ status: 500,
117
+ success: false,
118
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
119
+ };
120
+ }
121
+ }
122
+ /**
123
+ * Stakes tokens in a staking pool
124
+ * @param params The staking parameters
125
+ */
126
+ async stake(params) {
127
+ try {
128
+ const account = await this.walletClient.getAddresses();
129
+ if (!account[0])
130
+ throw new Error('No account found');
131
+ const { request } = await this.publicClient.simulateContract({
132
+ address: params.stakingPool,
133
+ abi: SINGLE_REWARD_ABI,
134
+ functionName: 'stake',
135
+ args: [params.amount],
136
+ account: account[0],
137
+ });
138
+ const hash = await this.walletClient.writeContract(request);
139
+ return {
140
+ data: hash,
141
+ status: 200,
142
+ success: true,
143
+ };
144
+ }
145
+ catch (error) {
146
+ return {
147
+ data: null,
148
+ status: 500,
149
+ success: false,
150
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
151
+ };
152
+ }
153
+ }
154
+ /**
155
+ * Withdraws tokens from a staking pool
156
+ * @param params The withdrawal parameters
157
+ */
158
+ async withdraw(params) {
159
+ try {
160
+ const account = await this.walletClient.getAddresses();
161
+ if (!account[0])
162
+ throw new Error('No account found');
163
+ const { request } = await this.publicClient.simulateContract({
164
+ address: params.stakingPool,
165
+ abi: SINGLE_REWARD_ABI,
166
+ functionName: 'withdraw',
167
+ args: [params.amount],
168
+ account: account[0],
169
+ });
170
+ const hash = await this.walletClient.writeContract(request);
171
+ return {
172
+ data: hash,
173
+ status: 200,
174
+ success: true,
175
+ };
176
+ }
177
+ catch (error) {
178
+ return {
179
+ data: null,
180
+ status: 500,
181
+ success: false,
182
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
183
+ };
184
+ }
185
+ }
186
+ /**
187
+ * Claims rewards from a staking pool
188
+ * @param params The reward claim parameters
189
+ */
190
+ async getReward(params) {
191
+ try {
192
+ const account = await this.walletClient.getAddresses();
193
+ if (!account[0])
194
+ throw new Error('No account found');
195
+ const { request } = await this.publicClient.simulateContract({
196
+ address: params.stakingPool,
197
+ abi: SINGLE_REWARD_ABI,
198
+ functionName: 'getReward',
199
+ args: [],
200
+ account: account[0],
201
+ });
202
+ const hash = await this.walletClient.writeContract(request);
203
+ return {
204
+ data: hash,
205
+ status: 200,
206
+ success: true,
207
+ };
208
+ }
209
+ catch (error) {
210
+ return {
211
+ data: null,
212
+ status: 500,
213
+ success: false,
214
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
215
+ };
216
+ }
217
+ }
218
+ /**
219
+ * Gets the earned rewards for an account in a staking pool
220
+ * @param stakingPool The staking pool address
221
+ * @param account The account to check rewards for
222
+ */
223
+ async earned(stakingPool, account) {
224
+ try {
225
+ // First try to read as single reward
226
+ try {
227
+ const reward = await this.publicClient.readContract({
228
+ address: stakingPool,
229
+ abi: SINGLE_REWARD_ABI,
230
+ functionName: 'earned',
231
+ args: [account],
232
+ });
233
+ return {
234
+ data: { rewardA: reward },
235
+ status: 200,
236
+ success: true,
237
+ };
238
+ }
239
+ catch {
240
+ // If single reward fails, try dual rewards
241
+ const [rewardA, rewardB] = await Promise.all([
242
+ this.publicClient.readContract({
243
+ address: stakingPool,
244
+ abi: DUAL_REWARD_ABI,
245
+ functionName: 'earnedA',
246
+ args: [account],
247
+ }),
248
+ this.publicClient.readContract({
249
+ address: stakingPool,
250
+ abi: DUAL_REWARD_ABI,
251
+ functionName: 'earnedB',
252
+ args: [account],
253
+ }),
254
+ ]);
255
+ return {
256
+ data: { rewardA, rewardB },
257
+ status: 200,
258
+ success: true,
259
+ };
260
+ }
261
+ }
262
+ catch (error) {
263
+ return {
264
+ data: null,
265
+ status: 500,
266
+ success: false,
267
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
268
+ };
269
+ }
270
+ }
271
+ /**
272
+ * Gets the total supply of staked tokens in a pool
273
+ * @param stakingPool The staking pool address
274
+ */
275
+ async totalSupply(stakingPool) {
276
+ try {
277
+ const totalSupply = await this.publicClient.readContract({
278
+ address: stakingPool,
279
+ abi: SINGLE_REWARD_ABI,
280
+ functionName: 'totalSupply',
281
+ });
282
+ return {
283
+ data: totalSupply,
284
+ status: 200,
285
+ success: true,
286
+ };
287
+ }
288
+ catch (error) {
289
+ return {
290
+ data: null,
291
+ status: 500,
292
+ success: false,
293
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
294
+ };
295
+ }
296
+ }
297
+ /**
298
+ * Gets the staked balance of an account in a pool
299
+ * @param stakingPool The staking pool address
300
+ * @param account The account to check balance for
301
+ */
302
+ async balanceOf(stakingPool, account) {
303
+ try {
304
+ const balance = await this.publicClient.readContract({
305
+ address: stakingPool,
306
+ abi: SINGLE_REWARD_ABI,
307
+ functionName: 'balanceOf',
308
+ args: [account],
309
+ });
310
+ return {
311
+ data: balance,
312
+ status: 200,
313
+ success: true,
314
+ };
315
+ }
316
+ catch (error) {
317
+ return {
318
+ data: null,
319
+ status: 500,
320
+ success: false,
321
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
322
+ };
323
+ }
324
+ }
325
+ /**
326
+ * Calculates the APR for a staking pool
327
+ * @param pool The staking pool data
328
+ * @param rewardTokenPriceUSD The price of the reward token in USD
329
+ * @param totalStakedUSD The total value staked in USD
330
+ */
331
+ calculateAPR(pool, rewardTokenPriceUSD, totalStakedUSD) {
332
+ if (totalStakedUSD === 0) {
333
+ return 0;
334
+ }
335
+ const dailyRewardUSD = pool.dailyEmissionRewardA * rewardTokenPriceUSD;
336
+ let apr = (dailyRewardUSD * 365 * 100) / totalStakedUSD;
337
+ if (pool.isDualFactory && pool.dailyEmissionRewardB) {
338
+ const dailyRewardBUSD = pool.dailyEmissionRewardB * rewardTokenPriceUSD;
339
+ apr += (dailyRewardBUSD * 365 * 100) / totalStakedUSD;
340
+ }
341
+ return apr;
342
+ }
343
+ }
344
+ exports.StakingClient = StakingClient;
345
+ //# sourceMappingURL=StakingClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StakingClient.js","sourceRoot":"","sources":["../../../src/base/StakingClient.ts"],"names":[],"mappings":";;;AAEA,qDAAkD;AA+BlD,6BAA6B;AAC7B,MAAM,iBAAiB,GAAG;IACxB;QACE,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,0BAA0B;QAClC,SAAS,EAAE,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;QAChC,iBAAiB,EAAE,MAAM;QACzB,MAAM,EAAE,UAAU;KACnB;IACD;QACE,QAAQ,EAAE,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;QAC/B,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;QAChC,iBAAiB,EAAE,MAAM;QACzB,MAAM,EAAE,UAAU;KACnB;IACD;QACE,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,CAAC,EAAC,MAAM,EAAE,SAAS,EAAC,CAAC;QAChC,iBAAiB,EAAE,MAAM;QACz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,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC;gBACnD,OAAO,EAAE,WAAW;gBACpB,GAAG,EAAE,iBAAiB;gBACtB,YAAY,EAAE,WAAW;gBACzB,IAAI,EAAE,CAAC,OAAO,CAAC;aAChB,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB;aACzE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,YAAY,CACjB,IAAiB,EACjB,mBAA2B,EAC3B,cAAsB;QAEtB,IAAI,cAAc,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;QACvE,IAAI,GAAG,GAAG,CAAC,cAAc,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,cAAc,CAAC;QAExD,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACpD,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC;YACxE,GAAG,IAAI,CAAC,eAAe,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,cAAc,CAAC;QACxD,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA7RD,sCA6RC"}
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultClient = void 0;
4
- const SubgraphClient_1 = require("./SubgraphClient");
5
4
  const abis_1 = require("../const/deployments/abis");
6
- const UniswapPool_1 = require("../const/abis/UniswapPool");
5
+ const SubgraphClient_1 = require("./SubgraphClient");
6
+ const deposit_1 = require("./vault/deposit");
7
+ const withdraw_1 = require("./vault/withdraw");
7
8
  const VAULT_ABI = abis_1.abis.QuickSwapUniv3MultiPositionLiquidityManager;
8
- const PERIPHERY_ABI = abis_1.abis.SteerPeriphery;
9
9
  class VaultClient extends SubgraphClient_1.SubgraphClient {
10
10
  constructor(client) {
11
11
  super(client);
12
12
  this.publicClient = client;
13
13
  this.walletClient = client;
14
+ this.depositClient = new deposit_1.VaultDepositClient(client, client);
15
+ this.withdrawClient = new withdraw_1.VaultWithdrawClient(client, client);
14
16
  }
15
17
  /**
16
18
  * Gets the latest vaults from the subgraph
@@ -48,94 +50,30 @@ class VaultClient extends SubgraphClient_1.SubgraphClient {
48
50
  * @param params The deposit parameters
49
51
  */
50
52
  async deposit(params) {
51
- try {
52
- const account = await this.walletClient.getAddresses();
53
- if (!account[0])
54
- throw new Error('No account found');
55
- // Calculate min amounts based on slippage
56
- const amount0Min = params.amount0Desired * BigInt(Math.floor((1 - params.slippage) * 1000)) / 1000n;
57
- const amount1Min = params.amount1Desired * BigInt(Math.floor((1 - params.slippage) * 1000)) / 1000n;
58
- const { request } = await this.publicClient.simulateContract({
59
- address: params.vaultAddress,
60
- abi: PERIPHERY_ABI,
61
- functionName: 'deposit',
62
- args: [
63
- params.vaultAddress,
64
- params.amount0Desired,
65
- params.amount1Desired,
66
- amount0Min,
67
- amount1Min,
68
- params.to ?? account[0]
69
- ],
70
- account: account[0],
71
- });
72
- const hash = await this.walletClient.writeContract(request);
73
- return {
74
- data: hash,
75
- status: 200,
76
- success: true,
77
- };
78
- }
79
- catch (error) {
80
- return {
81
- data: null,
82
- status: 500,
83
- success: false,
84
- error: error instanceof Error ? error.message : 'Unknown error occurred',
85
- };
86
- }
53
+ return this.depositClient.deposit(params);
54
+ }
55
+ /**
56
+ * Prepares the transaction data for depositing tokens into a vault without executing it
57
+ * @param params The deposit parameters
58
+ */
59
+ async prepareDepositTx(params) {
60
+ return this.depositClient.prepareDepositTx(params);
87
61
  }
88
- async getDepositRatio(vaultAddress) {
62
+ /**
63
+ * Gets the deposit ratio for a vault
64
+ * @param vaultAddress The vault address
65
+ */
66
+ async getDepositRatio(vaultAddress, zeroForOne) {
89
67
  try {
90
- // Get vault details to check balances and decimals
91
- const vaultDetails = await this.publicClient.readContract({
92
- address: vaultAddress,
93
- abi: PERIPHERY_ABI,
94
- functionName: 'vaultDetailsByAddress',
95
- args: [vaultAddress]
96
- });
97
- const token0Balance = vaultDetails.token0Balance;
98
- const token1Balance = vaultDetails.token1Balance;
99
- const token0Decimals = vaultDetails.token0Decimals;
100
- const token1Decimals = vaultDetails.token1Decimals;
101
- // Case 1: No liquidity in the vault
102
- if (token0Balance === 0n && token1Balance === 0n) {
103
- // Get the pool contract to fetch current price
104
- const pool = await this.pool(vaultAddress);
105
- if (!pool.data)
106
- throw new Error('Failed to retrieve pool for ratio calculation');
107
- // Get current sqrtPriceX96
108
- const [sqrtPriceX96] = await this.publicClient.readContract({
109
- address: pool.data,
110
- abi: UniswapPool_1.UniswapV3PoolABI,
111
- functionName: 'slot0'
112
- });
113
- // Calculate price = (sqrtPriceX96^2) / 2^192
114
- const price = (sqrtPriceX96 * sqrtPriceX96) / (2n ** 192n);
115
- // Adjust for decimal differences
116
- const decimalAdjustment = 10n ** BigInt(token1Decimals - token0Decimals);
117
- const nativeTokenRatio = price / decimalAdjustment;
118
- return {
119
- data: nativeTokenRatio,
120
- status: 200,
121
- success: true
122
- };
123
- }
124
- // Case 2: Vault has liquidity
125
- // If token1Balance is 0, return token0Balance
126
- if (token1Balance === 0n) {
127
- return {
128
- data: token0Balance,
129
- status: 200,
130
- success: true
131
- };
68
+ const ratioResponse = await this.depositClient.getDepositRatio(vaultAddress, zeroForOne);
69
+ if (!ratioResponse.success || !ratioResponse.data) {
70
+ throw new Error(ratioResponse.error || 'Failed to get deposit ratio');
132
71
  }
133
- // Calculate ratio = token0Balance / token1Balance
134
- // Adjust for decimal precision
135
- const decimalAdjustment = 10n ** BigInt(token1Decimals - token0Decimals);
136
- const ratio = (token0Balance * decimalAdjustment) / token1Balance;
137
72
  return {
138
- data: ratio,
73
+ data: {
74
+ details: ratioResponse.data.vaultDetails,
75
+ ratio: ratioResponse.data.ratio,
76
+ },
139
77
  status: 200,
140
78
  success: true
141
79
  };
@@ -154,37 +92,22 @@ class VaultClient extends SubgraphClient_1.SubgraphClient {
154
92
  * @param params The withdrawal parameters
155
93
  */
156
94
  async withdraw(params) {
157
- try {
158
- const account = await this.walletClient.getAddresses();
159
- if (!account[0])
160
- throw new Error('No account found');
161
- const { request } = await this.publicClient.simulateContract({
162
- address: params.vaultAddress,
163
- abi: VAULT_ABI,
164
- functionName: 'withdraw',
165
- args: [
166
- params.shares,
167
- params.amount0Min,
168
- params.amount1Min,
169
- params.to ?? account[0]
170
- ],
171
- account: account[0],
172
- });
173
- const hash = await this.walletClient.writeContract(request);
174
- return {
175
- data: hash,
176
- status: 200,
177
- success: true,
178
- };
179
- }
180
- catch (error) {
181
- return {
182
- data: null,
183
- status: 500,
184
- success: false,
185
- error: error instanceof Error ? error.message : 'Unknown error occurred',
186
- };
187
- }
95
+ return this.withdrawClient.withdraw(params);
96
+ }
97
+ /**
98
+ * Prepares the transaction data for withdrawing tokens from a vault without executing it
99
+ * @param params The withdrawal parameters
100
+ */
101
+ async prepareWithdrawTx(params) {
102
+ return this.withdrawClient.prepareWithdrawTx(params);
103
+ }
104
+ /**
105
+ * Calculates the amount of tokens that would be received for a given amount of LP tokens
106
+ * @param vaultAddress The vault address
107
+ * @param lpToken The amount of LP tokens to calculate for
108
+ */
109
+ async getTokensFromLp(vaultAddress, lpToken) {
110
+ return this.withdrawClient.getTokensFromLp(vaultAddress, lpToken);
188
111
  }
189
112
  /**
190
113
  * Approves spending of tokens for a vault
@@ -398,6 +321,22 @@ class VaultClient extends SubgraphClient_1.SubgraphClient {
398
321
  };
399
322
  }
400
323
  }
324
+ /**
325
+ * Gets a pool instance for a vault
326
+ * @param params The pool instance parameters
327
+ */
328
+ async getPoolInstance(params) {
329
+ return this.depositClient.getPoolInstance(params);
330
+ }
331
+ /**
332
+ * Gets the corresponding token amount based on the provided token amount and ratio
333
+ * @param vaultAddress The vault address
334
+ * @param amount The amount of token to calculate the corresponding amount for
335
+ * @param zeroForOne If true, calculates token1 amount for given token0, if false calculates token0 amount for given token1
336
+ */
337
+ async getCorrespondingTokenAmount(vaultAddress, amount, zeroForOne) {
338
+ return this.depositClient.getCorrespondingTokenAmount(vaultAddress, amount, zeroForOne);
339
+ }
401
340
  }
402
341
  exports.VaultClient = VaultClient;
403
342
  //# sourceMappingURL=VaultClient.js.map