@cetusprotocol/dlmm-sdk 0.0.0-experimental-20250925173459

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 (47) hide show
  1. package/.turbo/turbo-build.log +10444 -0
  2. package/README.md +654 -0
  3. package/dist/index.d.mts +1050 -0
  4. package/dist/index.d.ts +1050 -0
  5. package/dist/index.js +13 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +13 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +35 -0
  10. package/src/config/index.ts +2 -0
  11. package/src/config/mainnet.ts +25 -0
  12. package/src/config/testnet.ts +30 -0
  13. package/src/errors/errors.ts +40 -0
  14. package/src/index.ts +8 -0
  15. package/src/modules/configModule.ts +184 -0
  16. package/src/modules/index.ts +1 -0
  17. package/src/modules/partnerModule.ts +302 -0
  18. package/src/modules/poolModule.ts +578 -0
  19. package/src/modules/positionModule.ts +882 -0
  20. package/src/modules/rewardModule.ts +174 -0
  21. package/src/modules/swapModule.ts +129 -0
  22. package/src/sdk.ts +88 -0
  23. package/src/types/constants.ts +23 -0
  24. package/src/types/dlmm.ts +445 -0
  25. package/src/types/ilm.ts +33 -0
  26. package/src/types/index.ts +3 -0
  27. package/src/utils/binUtils.ts +552 -0
  28. package/src/utils/feeUtils.ts +92 -0
  29. package/src/utils/ilmUtils.ts +187 -0
  30. package/src/utils/index.ts +6 -0
  31. package/src/utils/parseData.ts +519 -0
  32. package/src/utils/strategyUtils.ts +121 -0
  33. package/src/utils/weightUtils.ts +510 -0
  34. package/tests/add_liquidity_bidask.test.ts +180 -0
  35. package/tests/add_liquidity_curve.test.ts +244 -0
  36. package/tests/add_liquidity_spot.test.ts +262 -0
  37. package/tests/bin.test.ts +80 -0
  38. package/tests/config.test.ts +73 -0
  39. package/tests/ilm.test.ts +31 -0
  40. package/tests/partner.test.ts +74 -0
  41. package/tests/pool.test.ts +174 -0
  42. package/tests/position.test.ts +76 -0
  43. package/tests/remove_liquidity.test.ts +137 -0
  44. package/tests/swap.test.ts +96 -0
  45. package/tests/tsconfig.json +26 -0
  46. package/tsconfig.json +5 -0
  47. package/tsup.config.ts +9 -0
@@ -0,0 +1,96 @@
1
+ // buildTestAccount
2
+ import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
3
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
4
+ import { CetusDlmmSDK } from '../src/sdk'
5
+ import { printTransaction } from '@cetusprotocol/common-sdk'
6
+
7
+ const pool_id = '0x94088f9a28a6b355ab3569b9cc32895dbccf4c6716f030d59d3f0cf747305ec9'
8
+
9
+ describe('dlmm swap', () => {
10
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet' })
11
+ let send_key_pair: Ed25519Keypair
12
+ let account: string
13
+
14
+ beforeEach(async () => {
15
+ send_key_pair = buildTestAccount()
16
+ account = send_key_pair.getPublicKey().toSuiAddress()
17
+ sdk.setSenderAddress(account)
18
+ })
19
+
20
+ test('preSwapQuote', async () => {
21
+ const pool = await sdk.Pool.getPool(pool_id)
22
+ const { id, coin_type_a, coin_type_b } = pool
23
+
24
+ const quote = await sdk.Swap.preSwapQuote({
25
+ pool_id,
26
+ a2b: true,
27
+ by_amount_in: true,
28
+ in_amount: '20000',
29
+ coin_type_a,
30
+ coin_type_b,
31
+ })
32
+ console.log('🚀 ~ test ~ quote:', quote)
33
+ })
34
+
35
+ test('swap_a2b', async () => {
36
+ const pool = await sdk.Pool.getPool(pool_id)
37
+ const { id, coin_type_a, coin_type_b } = pool
38
+ console.log('🚀 ~ test ~ pool:', pool)
39
+
40
+ const by_amount_in = true
41
+
42
+ const quote_obj = await sdk.Swap.preSwapQuote({
43
+ pool_id,
44
+ a2b: true,
45
+ by_amount_in,
46
+ in_amount: '100000',
47
+ coin_type_a,
48
+ coin_type_b,
49
+ })
50
+ console.log('🚀 ~ test ~ quote_obj:', quote_obj)
51
+
52
+ const tx = sdk.Swap.swapPayload({
53
+ coin_type_a,
54
+ coin_type_b,
55
+ quote_obj,
56
+ by_amount_in,
57
+ slippage: 0.01,
58
+ })
59
+
60
+ printTransaction(tx)
61
+
62
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
63
+ console.log('🚀 ~ test ~ res:', res)
64
+ })
65
+
66
+ test('swap_b2a', async () => {
67
+ const pool = await sdk.Pool.getPool(pool_id)
68
+ const { id, coin_type_a, coin_type_b } = pool
69
+ console.log('🚀 ~ test ~ pool:', pool)
70
+
71
+ const by_amount_in = true
72
+
73
+ const quote_obj = await sdk.Swap.preSwapQuote({
74
+ pool_id,
75
+ a2b: false,
76
+ by_amount_in,
77
+ in_amount: '30000000',
78
+ coin_type_a,
79
+ coin_type_b,
80
+ })
81
+ console.log('🚀 ~ test ~ quote_obj:', quote_obj)
82
+
83
+ const tx = sdk.Swap.swapPayload({
84
+ coin_type_a,
85
+ coin_type_b,
86
+ quote_obj,
87
+ by_amount_in,
88
+ slippage: 0.01,
89
+ })
90
+
91
+ printTransaction(tx)
92
+
93
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
94
+ console.log('🚀 ~ test ~ res:', res)
95
+ })
96
+ })
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "allowJs": false,
6
+ "declaration": true,
7
+ "lib": [
8
+ "DOM",
9
+ "ES6",
10
+ "DOM.Iterable",
11
+ "ScriptHost",
12
+ "ES2016.Array.Include"
13
+ ],
14
+ "outDir": "./dist",
15
+ "strict": true,
16
+ "esModuleInterop": true,
17
+ "skipLibCheck": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "resolveJsonModule": true,
20
+ "experimentalDecorators": true
21
+ },
22
+ "filesGlob": [
23
+ "src/**/*",
24
+ "tests/**/*"
25
+ ]
26
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["src/**/*"],
4
+ "exclude": ["node_modules", "dist"]
5
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ splitting: false,
6
+ sourcemap: true,
7
+ minify: true,
8
+ target: 'esnext',
9
+ })