@cetusprotocol/dlmm-sdk 0.0.1

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 (44) hide show
  1. package/.turbo/turbo-build.log +10423 -0
  2. package/README.md +646 -0
  3. package/dist/index.d.mts +1015 -0
  4. package/dist/index.d.ts +1015 -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 +888 -0
  20. package/src/modules/rewardModule.ts +175 -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/index.ts +2 -0
  26. package/src/utils/binUtils.ts +552 -0
  27. package/src/utils/feeUtils.ts +92 -0
  28. package/src/utils/index.ts +5 -0
  29. package/src/utils/parseData.ts +519 -0
  30. package/src/utils/strategyUtils.ts +121 -0
  31. package/src/utils/weightUtils.ts +510 -0
  32. package/tests/add_liquidity_bidask.test.ts +180 -0
  33. package/tests/add_liquidity_curve.test.ts +244 -0
  34. package/tests/add_liquidity_spot.test.ts +262 -0
  35. package/tests/bin.test.ts +80 -0
  36. package/tests/config.test.ts +51 -0
  37. package/tests/partner.test.ts +74 -0
  38. package/tests/pool.test.ts +174 -0
  39. package/tests/position.test.ts +76 -0
  40. package/tests/remove_liquidity.test.ts +137 -0
  41. package/tests/swap.test.ts +96 -0
  42. package/tests/tsconfig.json +26 -0
  43. package/tsconfig.json +5 -0
  44. package/tsup.config.ts +9 -0
@@ -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: 'mainnet' })
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 = '0x1702f2ab918c3def2a1265ddd5e4306807d3dcb1ba91b28fb42e50337895a857'
16
+ const position_id = '0x47a4db49d4eaa6d943df9aa3eb1b4f1d0113298d03a5e0f44f523365002497b1'
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, true)
135
+ console.log('🚀 ~ test ~ res:', res)
136
+ })
137
+ })
@@ -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
+ })