@cetusprotocol/dlmm-sdk 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -281,6 +281,109 @@ console.log('Variable fee:', variableFee)
281
281
  console.log('Variable fee percentage:', d(variableFee).div(d(FEE_PRECISION)).toString())
282
282
  ```
283
283
 
284
+ **getTotalFeeRate Return Value**
285
+
286
+ The `getTotalFeeRate` method returns a `FeeRate` object containing the following fields:
287
+
288
+ ```typescript
289
+ type FeeRate = {
290
+ base_fee_rate: string // Base fee rate
291
+ var_fee_rate: string // Variable fee rate
292
+ total_fee_rate: string // Total fee rate
293
+ }
294
+ ```
295
+
296
+ **Field Descriptions:**
297
+
298
+ - **`base_fee_rate`**: Base fee rate, calculated from the pool's `bin_step` and `base_factor`, is a fixed value
299
+ - **`var_fee_rate`**: Variable fee rate, dynamically calculated based on the pool's volatility accumulator (`volatility_accumulator`), changes with market volatility
300
+ - **`total_fee_rate`**: Total fee rate, equals `base_fee_rate + var_fee_rate`, but will not exceed the maximum fee rate limit (`MAX_FEE_RATE = 100,000,000`)
301
+
302
+ **Fee Rate Precision:**
303
+ - All fee rate values use `FEE_PRECISION = 1,000,000,000` as the precision unit
304
+ - To get the actual percentage, divide the fee rate value by `FEE_PRECISION`
305
+ - Example: If `total_fee_rate` is `3000000`, the actual fee rate is `3000000 / 1000000000 = 0.003 = 0.3%`
306
+
307
+ **Usage Example:**
308
+ ```typescript
309
+ const feeRate = await sdk.Pool.getTotalFeeRate({
310
+ pool_id: "0x...",
311
+ coin_type_a: "0x...",
312
+ coin_type_b: "0x..."
313
+ })
314
+
315
+ // Calculate actual percentages
316
+ const baseFeePercentage = d(feeRate.base_fee_rate).div(d(FEE_PRECISION)).mul(100).toString()
317
+ const varFeePercentage = d(feeRate.var_fee_rate).div(d(FEE_PRECISION)).mul(100).toString()
318
+ const totalFeePercentage = d(feeRate.total_fee_rate).div(d(FEE_PRECISION)).mul(100).toString()
319
+
320
+ console.log(`Base fee rate: ${baseFeePercentage}%`)
321
+ console.log(`Variable fee rate: ${varFeePercentage}%`)
322
+ console.log(`Total fee rate: ${totalFeePercentage}%`)
323
+ ```
324
+
325
+ #### FeeUtils Utility Methods
326
+
327
+ The `FeeUtils` class provides several utility methods for fee calculations:
328
+
329
+ **1. `getVariableFee(variableParameters: VariableParameters): string`**
330
+
331
+ Calculates the variable fee based on pool parameters and market volatility.
332
+
333
+ ```typescript
334
+ import { FeeUtils } from '@cetusprotocol/dlmm-sdk'
335
+
336
+ const variableFee = FeeUtils.getVariableFee(pool.variable_parameters)
337
+ console.log('Variable fee:', variableFee)
338
+ console.log('Variable fee percentage:', d(variableFee).div(d(FEE_PRECISION)).toString())
339
+ ```
340
+
341
+ **2. `calculateCompositionFee(amount: string, total_fee_rate: string): string`**
342
+
343
+ Calculates composition fees for liquidity operations.
344
+
345
+ ```typescript
346
+ const compositionFee = FeeUtils.calculateCompositionFee(amount, total_fee_rate)
347
+ ```
348
+
349
+ **3. `calculateProtocolFee(fee_amount: string, protocol_fee_rate: string): string`**
350
+
351
+ Calculates protocol fees based on fee amount and protocol fee rate.
352
+
353
+ ```typescript
354
+ const protocolFee = FeeUtils.calculateProtocolFee(fee_amount, protocol_fee_rate)
355
+ ```
356
+
357
+ **4. `getProtocolFees(fee_a: string, fee_b: string, protocol_fee_rate: string)`**
358
+
359
+ Calculates protocol fees for both tokens in a pair.
360
+
361
+ ```typescript
362
+ const { protocol_fee_a, protocol_fee_b } = FeeUtils.getProtocolFees(fee_a, fee_b, protocol_fee_rate)
363
+ console.log('Protocol fee A:', protocol_fee_a)
364
+ console.log('Protocol fee B:', protocol_fee_b)
365
+ ```
366
+
367
+ **5. `getCompositionFees(active_bin: BinAmount, used_bin: BinAmount, variableParameters: VariableParameters)`**
368
+
369
+ Calculates composition fees for active and used bins, considering variable parameters.
370
+
371
+ ```typescript
372
+ const { fees_a, fees_b } = FeeUtils.getCompositionFees(active_bin, used_bin, variableParameters)
373
+ console.log('Composition fees A:', fees_a)
374
+ console.log('Composition fees B:', fees_b)
375
+ ```
376
+
377
+ **FeeUtils Methods Summary:**
378
+
379
+ | Method | Description | Parameters | Returns |
380
+ | ------------------------- | ------------------------------------------- | ---------------------------------------------- | ---------------------------------- |
381
+ | `getVariableFee` | Calculate variable fee from pool parameters | `variableParameters` | `string` |
382
+ | `calculateCompositionFee` | Calculate composition fee for an amount | `amount`, `total_fee_rate` | `string` |
383
+ | `calculateProtocolFee` | Calculate protocol fee | `fee_amount`, `protocol_fee_rate` | `string` |
384
+ | `getProtocolFees` | Calculate protocol fees for both tokens | `fee_a`, `fee_b`, `protocol_fee_rate` | `{protocol_fee_a, protocol_fee_b}` |
385
+ | `getCompositionFees` | Calculate composition fees for bins | `active_bin`, `used_bin`, `variableParameters` | `{fees_a, fees_b}` |
386
+
284
387
  #### Fee and Reward Collection
285
388
 
286
389
  You can collect fees from your positions in several ways:
package/dist/index.d.mts CHANGED
@@ -474,13 +474,13 @@ declare class PoolModule implements IModule<CetusDlmmSDK> {
474
474
  * @param tx - The transaction object
475
475
  * @returns The transaction object
476
476
  */
477
- createPoolPayload(option: CreatePoolOption, tx: Transaction): Promise<TransactionObjectArgument>;
477
+ createPoolPayload(option: CreatePoolOption, tx: Transaction): TransactionObjectArgument;
478
478
  /**
479
479
  * Create a pool and add liquidity
480
480
  * @param option - The option for creating a pool and adding liquidity
481
481
  * @returns The transaction for creating a pool and adding liquidity
482
482
  */
483
- createPoolAndAddLiquidityPayload(option: CreatePoolAndAddOption): Promise<Transaction>;
483
+ createPoolAndAddLiquidityPayload(option: CreatePoolAndAddOption): Transaction;
484
484
  }
485
485
 
486
486
  declare class PositionModule implements IModule<CetusDlmmSDK> {
package/dist/index.d.ts CHANGED
@@ -474,13 +474,13 @@ declare class PoolModule implements IModule<CetusDlmmSDK> {
474
474
  * @param tx - The transaction object
475
475
  * @returns The transaction object
476
476
  */
477
- createPoolPayload(option: CreatePoolOption, tx: Transaction): Promise<TransactionObjectArgument>;
477
+ createPoolPayload(option: CreatePoolOption, tx: Transaction): TransactionObjectArgument;
478
478
  /**
479
479
  * Create a pool and add liquidity
480
480
  * @param option - The option for creating a pool and adding liquidity
481
481
  * @returns The transaction for creating a pool and adding liquidity
482
482
  */
483
- createPoolAndAddLiquidityPayload(option: CreatePoolAndAddOption): Promise<Transaction>;
483
+ createPoolAndAddLiquidityPayload(option: CreatePoolAndAddOption): Transaction;
484
484
  }
485
485
 
486
486
  declare class PositionModule implements IModule<CetusDlmmSDK> {