@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,80 @@
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 { BinUtils } from '../src/utils/binUtils'
6
+ import { Transaction } from '@mysten/sui/transactions'
7
+ import { asUintN, d, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { CalculateAddLiquidityOption, StrategyType } from '../src/types/dlmm'
9
+ import { safeMulAmount } from '../src/utils'
10
+
11
+ describe('dlmm bin', () => {
12
+ const sdk = CetusDlmmSDK.createSDK({ env: 'mainnet' })
13
+ let send_key_pair: Ed25519Keypair
14
+ let account: string
15
+
16
+ beforeEach(async () => {
17
+ send_key_pair = buildTestAccount()
18
+ account = send_key_pair.getPublicKey().toSuiAddress()
19
+ sdk.setSenderAddress(account)
20
+ })
21
+
22
+ test('getBinIdFromPrice', async () => {
23
+ const binId = BinUtils.getBinIdFromPrice(d(1).div('0.0013360404960738484928').toString(), 20, false, 9, 6)
24
+ console.log('🚀 ~ test ~ binId:', binId)
25
+ })
26
+
27
+ test('getPriceFromBinId', async () => {
28
+ const price = BinUtils.getPriceFromBinId(1113, 400, 6, 6)
29
+ console.log('🚀 ~ test ~ price:', price)
30
+ })
31
+
32
+ test('getPricePerLamportFromQPrice', async () => {
33
+ const q_price = BinUtils.getQPriceFromId(-4400, 100)
34
+ console.log('🚀 ~ test ~ q_price:', q_price)
35
+ const price_per_lamport = BinUtils.getPricePerLamportFromQPrice(q_price)
36
+ console.log('🚀 ~ test ~ price_per_lamport:', price_per_lamport)
37
+ })
38
+
39
+ test('getPositionCount', async () => {
40
+ const positionCount = BinUtils.getPositionCount(-750, 845)
41
+ console.log('🚀 ~ test ~ positionCount:', positionCount)
42
+ })
43
+
44
+ test('getLiquidity', async () => {
45
+ const liquidity = BinUtils.getLiquidity('0', '266666', '18431994054197767090')
46
+ console.log('🚀 ~ test ~ liquidity:', liquidity)
47
+ })
48
+
49
+ test('getAmountAFromLiquidity', async () => {
50
+ const amountA = BinUtils.getAmountAFromLiquidity('4101094304427826916657468', '18461505896777422276')
51
+ console.log('🚀 ~ test ~ amountA:', amountA)
52
+ })
53
+
54
+ test('getAmountBFromLiquidity', async () => {
55
+ const amountB = BinUtils.getAmountBFromLiquidity('4919119455159831291232256')
56
+ console.log('🚀 ~ test ~ amountB:', amountB)
57
+ })
58
+
59
+ test('calculateAddLiquidityInfo', async () => {
60
+ const calculateOption: CalculateAddLiquidityOption = {
61
+ amount_a: '100000000',
62
+ amount_b: '100000000',
63
+ active_id: 0,
64
+ bin_step: 2,
65
+ lower_bin_id: 0,
66
+ upper_bin_id: 70,
67
+ amount_a_in_active_bin: '0',
68
+ amount_b_in_active_bin: '0',
69
+ strategy_type: StrategyType.Spot,
70
+ }
71
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo(calculateOption)
72
+ console.log('🚀 ~ test ~ split_bin_infos:', bin_infos.bins.length)
73
+ const split_bin_infos = BinUtils.splitBinLiquidityInfo(bin_infos, 0, 70)
74
+ console.log('🚀 ~ test ~ split_bin_infos:', split_bin_infos.length)
75
+ })
76
+
77
+ test('findMinMaxBinId', async () => {
78
+ console.log('bin step 10 : ', BinUtils.findMinMaxBinId(10))
79
+ })
80
+ })
@@ -0,0 +1,73 @@
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 { parseCurrentRewardPeriodEmission, parseRewardPeriodEmission } from '../src/utils/parseData'
6
+ import { Transaction } from '@mysten/sui/transactions'
7
+ import { CoinAssist, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { toB64, toBase64 } from '@mysten/sui/utils'
9
+ import BN from 'bn.js'
10
+
11
+ describe('config', () => {
12
+ const sdk = CetusDlmmSDK.createSDK({ env: 'mainnet' })
13
+ let send_key_pair: Ed25519Keypair
14
+ let account: string
15
+
16
+ beforeEach(async () => {
17
+ send_key_pair = buildTestAccount()
18
+ account = send_key_pair.getPublicKey().toSuiAddress()
19
+ sdk.setSenderAddress(account)
20
+ })
21
+
22
+ test('getDlmmGlobalConfig', async () => {
23
+ const res = await sdk.Config.getDlmmGlobalConfig()
24
+ console.log('🚀 ~ test ~ res:', res)
25
+ })
26
+
27
+ test('build rawBytes', async () => {
28
+ const tx = new Transaction()
29
+
30
+ const zeroCoin = CoinAssist.buildCoinWithBalance(
31
+ BigInt(100),
32
+ '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
33
+ tx
34
+ )
35
+ tx.transferObjects([zeroCoin], tx.pure.address(account))
36
+ tx.setSender(account)
37
+
38
+ printTransaction(tx)
39
+ // build rawBytes
40
+ const data = await tx.build({ client: sdk.FullClient })
41
+ const rawBytes = toBase64(data)
42
+ console.log('rawBytes: ', rawBytes)
43
+ })
44
+
45
+ test('getBinStepConfigList', async () => {
46
+ const res = await sdk.Config.getBinStepConfigList('0xc00e4dbc372948b2b72ae5554c7296b39e107a92821baff08aa640aba0b07aed')
47
+ console.log('🚀 ~ test ~ res:', res)
48
+ })
49
+
50
+ test('fetchDlmmSdkConfigs', async () => {
51
+ const res = await sdk.Config.fetchDlmmSdkConfigs()
52
+ console.log('🚀 ~ test ~ res:', res)
53
+ })
54
+
55
+ test('getPool', async () => {
56
+ const pool = await sdk.Pool.getPool('0x8b131bccc1b4da0b463c19fa8cacdb71fc9f2ff632841769650886db2f0995f8')
57
+ console.log('🚀 ~ test ~ pool:', JSON.stringify(pool, null, 2))
58
+ })
59
+
60
+ test('getRewardPeriodEmission', async () => {
61
+ const currentTime = new Date().getTime() / 1000
62
+ const res = await sdk.Reward.getRewardPeriodEmission(
63
+ '0x59fbe11899d46c36b597b9899d86f62b880f0aa05727e25454a1158a52bf290d',
64
+ '22080.13295225819507789012012891061154107319453032687306404113769',
65
+ 1756354616
66
+ )
67
+ console.log('🚀 ~ test ~ res:', JSON.stringify(res, null, 2))
68
+ const result = parseRewardPeriodEmission(res, currentTime, currentTime + 60 * 60 * 24 * 20, 60 * 60 * 24)
69
+ console.log('🚀 ~ test ~ result:', JSON.stringify(result, null, 2))
70
+ const currentEmission = parseCurrentRewardPeriodEmission(res)
71
+ console.log('🚀 ~ test ~ currentEmission:', currentEmission)
72
+ })
73
+ })
@@ -0,0 +1,31 @@
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 { BinUtils } from '../src/utils/binUtils'
6
+ import { Transaction } from '@mysten/sui/transactions'
7
+ import { asUintN, d, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { CalculateAddLiquidityOption, StrategyType } from '../src/types/dlmm'
9
+ import { IlmUtils, safeMulAmount } from '../src/utils'
10
+ import { IlmInputOptions } from '../src/types/ilm'
11
+
12
+ describe('ilm', () => {
13
+ test('calculateIlm', async () => {
14
+ const options: IlmInputOptions = {
15
+ curvature: 0.6,
16
+ initial_price: '0.01',
17
+ max_price: '0.04',
18
+ bin_step: 80,
19
+ total_supply: '200',
20
+ pool_share_percentage: 30,
21
+ config: {
22
+ price_curve_points_num: 101,
23
+ liquidity_distribution_num: 101,
24
+ tokens_table_num: 10,
25
+ price_table_num: 10,
26
+ },
27
+ }
28
+ const result = IlmUtils.calculateIlm(options)
29
+ console.log('🚀 ~ test ~ result:', result)
30
+ })
31
+ })
@@ -0,0 +1,74 @@
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 { BinUtils } from '../src/utils/binUtils'
6
+ import { StrategyType } from '../src/types/dlmm'
7
+ import { d, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { Transaction } from '@mysten/sui/transactions'
9
+
10
+ describe('partner', () => {
11
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz' })
12
+ let send_key_pair: Ed25519Keypair
13
+ let account: string
14
+
15
+ beforeEach(async () => {
16
+ send_key_pair = buildTestAccount()
17
+ account = send_key_pair.getPublicKey().toSuiAddress()
18
+ sdk.setSenderAddress(account)
19
+ })
20
+
21
+ test('getPartnerList', async () => {
22
+ const partnerList = await sdk.Partner.getPartnerList()
23
+ console.log('🚀 ~ test ~ partnerList:', partnerList)
24
+ })
25
+
26
+ test('getPartner', async () => {
27
+ const partner = await sdk.Partner.getPartner('0x9d171399393e3cbedffc24269eb606e735fb56fee17c15153eb5e2d5274a3677')
28
+ console.log('🚀 ~ test ~ partner:', partner)
29
+ })
30
+
31
+ test('getPartnerCapId', async () => {
32
+ const partnerCapId = await sdk.Partner.getPartnerCapId(account, '0x9d171399393e3cbedffc24269eb606e735fb56fee17c15153eb5e2d5274a3677')
33
+ console.log('🚀 ~ test ~ partnerCapId:', partnerCapId)
34
+ })
35
+
36
+ test('getPartnerBalance', async () => {
37
+ const partnerBalance = await sdk.Partner.getPartnerBalance('0x2f14a9ed1e9fb5b027b36d6b166de1f5fec2f26c444d64b22c26cd216b38c65b')
38
+ console.log('🚀 ~ test ~ partnerBalance:', partnerBalance)
39
+ })
40
+
41
+ test('createPartnerPayload', async () => {
42
+ const start_time = Number(d(Date.now()).div(1000).add(5000).toFixed(0))
43
+ const tx = sdk.Partner.createPartnerPayload({
44
+ name: 'test lb 2',
45
+ ref_fee_rate: 0.01,
46
+ start_time,
47
+ end_time: start_time + 9 * 24 * 3600,
48
+ recipient: account,
49
+ })
50
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
51
+ console.log('🚀 ~ test ~ res2:', res)
52
+ })
53
+
54
+ test('updateRefFeeRatePayload', async () => {
55
+ const tx = await sdk.Partner.updateRefFeeRatePayload({
56
+ partner_id: '0x9d171399393e3cbedffc24269eb606e735fb56fee17c15153eb5e2d5274a3677',
57
+ ref_fee_rate: 0.02,
58
+ })
59
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
60
+ console.log('🚀 ~ test ~ res2:', res)
61
+ })
62
+
63
+ test('updateTimeRangePayload', async () => {
64
+ const start_time = Number(d(Date.now()).div(1000).toFixed(0))
65
+ const tx = await sdk.Partner.updateTimeRangePayload({
66
+ partner_id: '0x9d171399393e3cbedffc24269eb606e735fb56fee17c15153eb5e2d5274a3677',
67
+ start_time,
68
+ end_time: start_time + 10 * 7 * 24 * 3600,
69
+ })
70
+
71
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
72
+ console.log('🚀 ~ test ~ res2:', res)
73
+ })
74
+ })
@@ -0,0 +1,174 @@
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 { BinUtils } from '../src/utils/binUtils'
6
+ import { StrategyType } from '../src/types/dlmm'
7
+ import { asIntN, asUintN, d, printTransaction } from '@cetusprotocol/common-sdk'
8
+ import { Transaction } from '@mysten/sui/transactions'
9
+ import { FeeUtils } from '../src/utils'
10
+ import { FEE_PRECISION, MAX_FEE_RATE } from '../src/types/constants'
11
+
12
+ describe('pool', () => {
13
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet' })
14
+ let send_key_pair: Ed25519Keypair
15
+ let account: string
16
+
17
+ beforeEach(async () => {
18
+ send_key_pair = buildTestAccount()
19
+ account = send_key_pair.getPublicKey().toSuiAddress()
20
+ sdk.setSenderAddress(account)
21
+ })
22
+
23
+ test('faucet coin', async () => {
24
+ const tx = new Transaction()
25
+ const supply_ids = [
26
+ { module: 'btc', id: '0x4730c9b8495f2f655ac423dfc2737269fd856e29fe311fed563bde212b8efb30' },
27
+ { module: 'cetus', id: '0x81f9f8c196d15cb0b2421d1955112b3200b792b33584e2ae1f1d69605e6e09b6' },
28
+ { module: 'eth', id: '0x171f59e0d0fb462ddfa323b0bf27f308fd2466fc3d44a1e1cbdcc774a206cc3c' },
29
+ { module: 'usdc', id: '0xfed8db19bd2c51a3b1d9e667f30e054d7e74beab2921b4ee38c473fd072e3765' },
30
+ { module: 'usdt', id: '0x53b597d3f2771a71793d04238ca2ceafb26e5cea898de76535393ff4837d73e3' },
31
+ ]
32
+
33
+ supply_ids.forEach((supply) => {
34
+ tx.moveCall({
35
+ package: '0x89ab72c6c7a43a7be93987ba98748c7d0fda462e7b5d58b44f432d30417768c4',
36
+ module: supply.module,
37
+ function: 'faucet',
38
+ typeArguments: [],
39
+ arguments: [tx.object(supply.id)],
40
+ })
41
+ })
42
+
43
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
44
+ console.log('🚀 ~ test ~ res:', res)
45
+ })
46
+
47
+ test('getBasePoolList', async () => {
48
+ const res = await sdk.Pool.getBasePoolList()
49
+ console.log('🚀 ~ test ~ res:', res)
50
+ })
51
+
52
+ test('getPools', async () => {
53
+ const res = await sdk.Pool.getPools()
54
+ console.log('🚀 ~ test ~ res:', res.data)
55
+ })
56
+
57
+ test('getAssignPoolList', async () => {
58
+ const pools = await sdk.Pool.getAssignPoolList(['0xbef9d0b90acfd1e58584d0d2a5070ef3d5ae3b52cc80a888435e5d935427fb55'])
59
+ console.log('🚀 ~ test ~ pools:', pools)
60
+ })
61
+
62
+ test('getPool', async () => {
63
+ const pool = await sdk.Pool.getPool('0x4650ca3fd23deef634fdc84eb35c578a5d003dbf5a40e19376f4d7c1aef702de')
64
+ console.log('🚀 ~ test ~ pool:', JSON.stringify(pool, null, 2))
65
+ })
66
+
67
+ test('getBinInfo', async () => {
68
+ const binId = 77
69
+ const bin_info = await sdk.Pool.getBinInfo('0xce63f2e8e796747294532a2bfaee755075ff0a35334e15c286d7e91a93386f28', binId, 2)
70
+ console.log('🚀 ~ test ~ bin_info:', bin_info)
71
+ })
72
+
73
+ test('getVariableFee', async () => {
74
+ const pool = await sdk.Pool.getPool('0xe7e85914ab054a8d0d6d8f5f3e52445d17153da1efba857fed986f2d79e43412')
75
+ console.log('🚀 ~ test ~ pool:', JSON.stringify(pool, null, 2))
76
+
77
+ const variable_fee = FeeUtils.getVariableFee(pool.variable_parameters)
78
+
79
+ console.log('🚀 ~ test ~ variable_fee:', variable_fee)
80
+ console.log('🚀 ~ test ~ variable_fee2:', d(variable_fee).div(d(FEE_PRECISION)).toString())
81
+ console.log('🚀 ~ test ~ variable_fee2:', d(MAX_FEE_RATE).div(d(FEE_PRECISION)).toString())
82
+ })
83
+
84
+ test('1 getPoolBinInfo', async () => {
85
+ const bin_info = await sdk.Pool.getPoolBinInfo({
86
+ pool_id: '0xffd4260d625f99349542badf632037c824ad919425ee227de1745b19edc05133',
87
+ coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdt::USDT',
88
+ coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
89
+ })
90
+ console.log('🚀 ~ test ~ bin_info:', bin_info)
91
+ })
92
+
93
+ test('getTotalFeeRate', async () => {
94
+ const fee_rate = await sdk.Pool.getTotalFeeRate({
95
+ pool_id: '0x838405c8600897728aee3e8de0d9b6129a0c0d3103ba8b733d2e816855a4792a',
96
+ coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdt::USDT',
97
+ coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
98
+ })
99
+ console.log('🚀 ~ test ~ fee_rate:', fee_rate)
100
+ })
101
+
102
+ test('getPoolTransactionList', async () => {
103
+ const res = await sdk.Pool.getPoolTransactionList({
104
+ pool_id: '0xe7e85914ab054a8d0d6d8f5f3e52445d17153da1efba857fed986f2d79e43412',
105
+ pagination_args: { limit: 10, cursor: '8r1oXezKZsyupRBdvvRkYAe9aT5anpwiVKJte63ofprn' },
106
+ })
107
+ console.log('🚀 ~ test ~ res:', res)
108
+ })
109
+
110
+ test('createPoolAndAddWithPayload', async () => {
111
+ const bin_step = 2
112
+ const base_factor = 10000
113
+ const coin_amount_a = '10000000'
114
+ const price = '0.00038398'
115
+ const active_id = BinUtils.getBinIdFromPrice(price, bin_step, true, 6, 9)
116
+
117
+ const lower_bin_id = active_id - 10
118
+ const upper_bin_id = active_id + 10
119
+
120
+ const bin_infos = sdk.Position.calculateAddLiquidityInfo({
121
+ active_id,
122
+ bin_step,
123
+ lower_bin_id,
124
+ upper_bin_id,
125
+ amount_a_in_active_bin: '0',
126
+ amount_b_in_active_bin: '0',
127
+ strategy_type: StrategyType.Spot,
128
+ coin_amount: coin_amount_a,
129
+ fix_amount_a: true,
130
+ })
131
+
132
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
133
+
134
+ const tx = await sdk.Pool.createPoolAndAddLiquidityPayload({
135
+ active_id,
136
+ lower_bin_id,
137
+ upper_bin_id,
138
+ bin_step,
139
+ bin_infos,
140
+ coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
141
+ coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::eth::ETH',
142
+ strategy_type: StrategyType.Spot,
143
+ use_bin_infos: false,
144
+ base_factor,
145
+ })
146
+
147
+ printTransaction(tx)
148
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
149
+ console.log('🚀 ~ test ~ res:', res)
150
+ })
151
+
152
+ test('createPoolPayload', async () => {
153
+ const bin_step = 2
154
+ const base_factor = 10000
155
+ const price = '1.1'
156
+ const active_id = BinUtils.getBinIdFromPrice(price, bin_step, true, 6, 6)
157
+
158
+ const tx = new Transaction()
159
+ await sdk.Pool.createPoolPayload(
160
+ {
161
+ active_id,
162
+ bin_step,
163
+ coin_type_a: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdt::USDT',
164
+ coin_type_b: '0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48::usdc::USDC',
165
+ base_factor,
166
+ },
167
+ tx
168
+ )
169
+
170
+ printTransaction(tx)
171
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
172
+ console.log('🚀 ~ test ~ res:', res)
173
+ })
174
+ })
@@ -0,0 +1,76 @@
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
+ import { parseLiquidityShares } from '../src/utils/parseData'
7
+
8
+ const pool_id = '0x94088f9a28a6b355ab3569b9cc32895dbccf4c6716f030d59d3f0cf747305ec9'
9
+ const position_id = '0x4c9ff5d666bfd1fc01f102df3c77bd3fdd51f248cad8ef02d250c60ed708a004'
10
+
11
+ describe('dlmm position', () => {
12
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet' })
13
+ let send_key_pair: Ed25519Keypair
14
+ let account: string
15
+
16
+ beforeEach(async () => {
17
+ send_key_pair = buildTestAccount()
18
+ account = send_key_pair.getPublicKey().toSuiAddress()
19
+ sdk.setSenderAddress(account)
20
+ })
21
+
22
+ test('get owner position list', async () => {
23
+ const res = await sdk.Position.getOwnerPositionList(account)
24
+ console.log('🚀 ~ test ~ res:', res)
25
+ })
26
+
27
+ test('getPosition', async () => {
28
+ const res = await sdk.Position.getPosition('0x8d9fee92ddfcf1ec7688124a2bcf5a102acd70e470546170aa2db334f8081eba')
29
+ console.log('🚀 ~ test ~ res:', res)
30
+ })
31
+
32
+ test('get position', async () => {
33
+ const pool = await sdk.Pool.getPool('0x6055e7eb872d7db12a6267fe43310326189aaf2cc1ba5ad4228f1c2c3b3998c2')
34
+ const res = await sdk.Position.getPosition('0xf3385e599ca649880233194e34b1910991c997f5f72f4888c831df79c6c65d17')
35
+ console.log('🚀 ~ test ~ res:', res)
36
+
37
+ const active_bin = await sdk.Pool.getBinInfo(pool.bin_manager.bin_manager_handle, pool.active_id, pool.bin_step)
38
+ console.log('🚀 ~ test ~ active_bin:', active_bin)
39
+ const data = parseLiquidityShares(res.liquidity_shares, pool.bin_step, res.lower_bin_id, active_bin)
40
+ console.log('🚀 ~ test ~ data:', data)
41
+ })
42
+
43
+ test('fetchPositionFeeAndReward', async () => {
44
+ const pool = await sdk.Pool.getPool('0x4bb32fb02ed81c8a3d9702a86df73fff9215e63577c7a8ef3874ada8e01cac37')
45
+ const { id, coin_type_a, coin_type_b, reward_manager } = pool
46
+
47
+ const res = await sdk.Position.fetchPositionFeeAndReward([
48
+ {
49
+ pool_id: id,
50
+ position_id: '0x8d9fee92ddfcf1ec7688124a2bcf5a102acd70e470546170aa2db334f8081eba',
51
+ reward_coins: reward_manager.rewards.map((reward) => reward.reward_coin),
52
+ coin_type_a: coin_type_a,
53
+ coin_type_b: coin_type_b,
54
+ },
55
+ ])
56
+
57
+ console.log('🚀 ~ test ~ res:', JSON.stringify(res, null, 2))
58
+ })
59
+ test('collectRewardAndFeePayload', async () => {
60
+ const pool = await sdk.Pool.getPool(pool_id)
61
+ const { id, coin_type_a, coin_type_b, reward_manager } = pool
62
+
63
+ const tx = sdk.Position.collectRewardAndFeePayload([
64
+ {
65
+ pool_id: id,
66
+ position_id: position_id,
67
+ reward_coins: reward_manager.rewards.map((reward) => reward.reward_coin),
68
+ coin_type_a,
69
+ coin_type_b,
70
+ },
71
+ ])
72
+ printTransaction(tx)
73
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
74
+ console.log('🚀 ~ test ~ res:', res)
75
+ })
76
+ })
@@ -0,0 +1,137 @@
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 {
6
+ CalculateRemoveLiquidityBothOption,
7
+ CalculateRemoveLiquidityOnlyOption,
8
+ ClosePositionOption,
9
+ DlmmPool,
10
+ RemoveLiquidityOption,
11
+ } from '../src/types/dlmm'
12
+ import { printTransaction } from '@cetusprotocol/common-sdk'
13
+ import { parseLiquidityShares } from '../src/utils/parseData'
14
+
15
+ const pool_id = '0x0bec57bb33a99d0a999a3257c047c8ab35e611acd59d7a2b7a0fb5d89aaffe9e'
16
+ const position_id = '0xa99890fa6a8d4be06413759d04351d712377e5fda3cc03daf7f4815d99477d77'
17
+
18
+ describe('dlmm remove liquidity ', () => {
19
+ const sdk = CetusDlmmSDK.createSDK({ env: 'testnet', full_rpc_url: 'https://rpc-testnet.suiscan.xyz' })
20
+ let send_key_pair: Ed25519Keypair
21
+ let account: string
22
+ let pool: DlmmPool
23
+
24
+ beforeEach(async () => {
25
+ send_key_pair = buildTestAccount()
26
+ account = send_key_pair.getPublicKey().toSuiAddress()
27
+ sdk.setSenderAddress(account)
28
+ })
29
+
30
+ test('1 remove liquidity with both amounts ', async () => {
31
+ pool = await sdk.Pool.getPool(pool_id)
32
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
33
+ console.log('🚀 ~ pool:', pool)
34
+
35
+ const position = await sdk.Position.getPosition(position_id)
36
+ const { lower_bin_id, liquidity_shares } = position
37
+ // console.log('🚀 ~ position:', position)
38
+
39
+ const active_bin = await sdk.Pool.getBinInfo(bin_manager.bin_manager_handle, active_id, bin_step)
40
+ const liquidity_shares_data = parseLiquidityShares(liquidity_shares, bin_step, lower_bin_id, active_bin)
41
+
42
+ console.log('🚀 ~ test ~ liquidity_shares_data:', liquidity_shares_data)
43
+
44
+ const calculateOption: CalculateRemoveLiquidityBothOption = {
45
+ // bins: liquidity_shares_data.bins.slice(0, -500),
46
+ bins: liquidity_shares_data.bins,
47
+ active_id,
48
+ fix_amount_a: false,
49
+ coin_amount: '200000000',
50
+ }
51
+ const bin_infos = sdk.Position.calculateRemoveLiquidityInfo(calculateOption)
52
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
53
+
54
+ const removeOption: RemoveLiquidityOption = {
55
+ pool_id,
56
+ bin_infos,
57
+ coin_type_a,
58
+ coin_type_b,
59
+ position_id,
60
+ slippage: 0.01,
61
+ active_id,
62
+ collect_fee: true,
63
+ reward_coins: [],
64
+ bin_step,
65
+ remove_percent: 0.5,
66
+ }
67
+ const tx = sdk.Position.removeLiquidityPayload(removeOption)
68
+ tx.setGasBudget(10000000000)
69
+ printTransaction(tx)
70
+
71
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
72
+ console.log('🚀 ~ test ~ res:', res)
73
+ })
74
+
75
+ test('2 remove liquidity with only coin a ', async () => {
76
+ pool = await sdk.Pool.getPool(pool_id)
77
+ const { active_id, bin_step, bin_manager, coin_type_a, coin_type_b } = pool
78
+ console.log('🚀 ~ pool:', pool)
79
+
80
+ const position = await sdk.Position.getPosition(position_id)
81
+ const { lower_bin_id, liquidity_shares } = position
82
+ console.log('🚀 ~ position:', position)
83
+
84
+ const active_bin = await sdk.Pool.getBinInfo(bin_manager.bin_manager_handle, active_id, bin_step)
85
+ const liquidity_shares_data = parseLiquidityShares(liquidity_shares, bin_step, lower_bin_id, active_bin)
86
+
87
+ console.log('🚀 ~ test ~ liquidity_shares_data:', liquidity_shares_data)
88
+
89
+ const calculateOption: CalculateRemoveLiquidityOnlyOption = {
90
+ bins: liquidity_shares_data.bins,
91
+ active_id,
92
+ is_only_a: true,
93
+ coin_amount: '100000',
94
+ }
95
+ const bin_infos = sdk.Position.calculateRemoveLiquidityInfo(calculateOption)
96
+ console.log('🚀 ~ test ~ bin_infos:', bin_infos)
97
+
98
+ const removeOption: RemoveLiquidityOption = {
99
+ pool_id,
100
+ bin_infos,
101
+ coin_type_a,
102
+ coin_type_b,
103
+ position_id,
104
+ slippage: 0.01,
105
+ active_id,
106
+ reward_coins: [],
107
+ collect_fee: true,
108
+ bin_step,
109
+ }
110
+ const tx = sdk.Position.removeLiquidityPayload(removeOption)
111
+
112
+ printTransaction(tx)
113
+
114
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, true)
115
+ console.log('🚀 ~ test ~ res:', res)
116
+ })
117
+
118
+ test('3 close position ', async () => {
119
+ pool = await sdk.Pool.getPool(pool_id)
120
+ const { reward_manager, coin_type_a, coin_type_b } = pool
121
+ console.log('🚀 ~ pool:', pool)
122
+
123
+ const closeOption: ClosePositionOption = {
124
+ pool_id,
125
+ coin_type_a,
126
+ coin_type_b,
127
+ position_id,
128
+ reward_coins: reward_manager.rewards.map((reward) => reward.reward_coin),
129
+ }
130
+ const tx = sdk.Position.closePositionPayload(closeOption)
131
+
132
+ printTransaction(tx)
133
+
134
+ const res = await sdk.FullClient.executeTx(send_key_pair, tx, false)
135
+ console.log('🚀 ~ test ~ res:', res)
136
+ })
137
+ })