@cetusprotocol/sui-clmm-sdk 1.0.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 (64) hide show
  1. package/.turbo/turbo-build.log +11100 -0
  2. package/README.md +108 -0
  3. package/dist/index.d.mts +2251 -0
  4. package/dist/index.d.ts +2251 -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/docs/add_liquidity.md +145 -0
  10. package/docs/close_position.md +57 -0
  11. package/docs/collect_fees.md +37 -0
  12. package/docs/create_clmm_pool.md +228 -0
  13. package/docs/error_code.md +69 -0
  14. package/docs/get_clmm_pools.md +92 -0
  15. package/docs/get_positions.md +70 -0
  16. package/docs/get_reward.md +53 -0
  17. package/docs/get_ticks.md +39 -0
  18. package/docs/migrate_to_version_6.0.md +143 -0
  19. package/docs/open_position.md +224 -0
  20. package/docs/partner_swap.md +60 -0
  21. package/docs/pre_swap.md +136 -0
  22. package/docs/remove_liquidity.md +124 -0
  23. package/docs/swap.md +153 -0
  24. package/docs/utils.md +85 -0
  25. package/package.json +37 -0
  26. package/src/config/index.ts +2 -0
  27. package/src/config/mainnet.ts +41 -0
  28. package/src/config/testnet.ts +40 -0
  29. package/src/errors/errors.ts +93 -0
  30. package/src/errors/index.ts +1 -0
  31. package/src/index.ts +10 -0
  32. package/src/math/apr.ts +167 -0
  33. package/src/math/index.ts +1 -0
  34. package/src/modules/configModule.ts +540 -0
  35. package/src/modules/index.ts +5 -0
  36. package/src/modules/poolModule.ts +1066 -0
  37. package/src/modules/positionModule.ts +932 -0
  38. package/src/modules/rewarderModule.ts +430 -0
  39. package/src/modules/swapModule.ts +389 -0
  40. package/src/sdk.ts +131 -0
  41. package/src/types/clmm_type.ts +1002 -0
  42. package/src/types/clmmpool.ts +366 -0
  43. package/src/types/config_type.ts +241 -0
  44. package/src/types/index.ts +8 -0
  45. package/src/types/sui.ts +124 -0
  46. package/src/types/token_type.ts +189 -0
  47. package/src/utils/common.ts +426 -0
  48. package/src/utils/index.ts +3 -0
  49. package/src/utils/positionUtils.ts +434 -0
  50. package/src/utils/swapUtils.ts +499 -0
  51. package/tests/add_liquidity.test.ts +121 -0
  52. package/tests/add_liquidity_fix_token.test.ts +182 -0
  53. package/tests/apr.test.ts +71 -0
  54. package/tests/cetus_config.test.ts +26 -0
  55. package/tests/collect_fees.test.ts +11 -0
  56. package/tests/pool.test.ts +267 -0
  57. package/tests/position.test.ts +145 -0
  58. package/tests/remove_liquidity.test.ts +119 -0
  59. package/tests/rewarder.test.ts +60 -0
  60. package/tests/sdk_config.test.ts +49 -0
  61. package/tests/swap.test.ts +254 -0
  62. package/tests/tsconfig.json +26 -0
  63. package/tsconfig.json +5 -0
  64. package/tsup.config.ts +10 -0
@@ -0,0 +1,182 @@
1
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
2
+ import BN from 'bn.js'
3
+ import { ClmmPoolUtil, printTransaction, TickMath, toDecimalsAmount } from '@cetusprotocol/common-sdk'
4
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
5
+ import 'isomorphic-fetch'
6
+ import { AddLiquidityFixTokenParams, CustomRangeParams, FullRangeParams } from '../src'
7
+ import { CetusClmmSDK } from '../src/sdk'
8
+
9
+ let send_key_pair: Ed25519Keypair
10
+ const poolId = '0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105'
11
+ const position_nft_id = '0xcf995f40b0f9c40a8b03e0b9d9554fea2bc12a18fe63db3a04c59c46be5c10be'
12
+
13
+ describe('add_liquidity_fix_token', () => {
14
+ const sdk = CetusClmmSDK.createSDK({ env: 'mainnet' })
15
+
16
+ beforeEach(async () => {
17
+ send_key_pair = buildTestAccount()
18
+ sdk.setSenderAddress(send_key_pair.getPublicKey().toSuiAddress())
19
+ })
20
+
21
+ test('1: custom tick range open_and_add_liquidity_fix_token', async () => {
22
+ const pool = await sdk.Pool.getPool(poolId)
23
+ const tick_lower_index = TickMath.getPrevInitializeTickIndex(
24
+ new BN(pool.current_tick_index).toNumber(),
25
+ new BN(pool.tick_spacing).toNumber()
26
+ )
27
+ const tick_upper_index = TickMath.getNextInitializeTickIndex(
28
+ new BN(pool.current_tick_index).toNumber(),
29
+ new BN(pool.tick_spacing).toNumber()
30
+ )
31
+ const coinAmount = new BN(100)
32
+ const fix_amount_a = true
33
+ const slippage = 0.01
34
+ const curSqrtPrice = new BN(pool.current_sqrt_price)
35
+
36
+ const liquidityInput = ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(
37
+ tick_lower_index,
38
+ tick_upper_index,
39
+ coinAmount,
40
+ fix_amount_a,
41
+ true,
42
+ slippage,
43
+ curSqrtPrice
44
+ )
45
+
46
+ const amount_a = fix_amount_a ? coinAmount.toNumber() : Number(liquidityInput.coin_amount_limit_a)
47
+ const amount_b = fix_amount_a ? Number(liquidityInput.coin_amount_limit_b) : coinAmount.toNumber()
48
+
49
+ console.log('amount: ', { amount_a, amount_b })
50
+
51
+ const addLiquidityPayloadParams: AddLiquidityFixTokenParams = {
52
+ coin_type_a: pool.coin_type_a,
53
+ coin_type_b: pool.coin_type_b,
54
+ pool_id: pool.id,
55
+ tick_lower: tick_lower_index.toString(),
56
+ tick_upper: tick_upper_index.toString(),
57
+ fix_amount_a,
58
+ amount_a,
59
+ amount_b,
60
+ slippage,
61
+ is_open: true,
62
+ rewarder_coin_types: [],
63
+ collect_fee: false,
64
+ pos_id: '',
65
+ }
66
+ const createAddLiquidityTransactionPayload = await sdk.Position.createAddLiquidityFixTokenPayload(addLiquidityPayloadParams, {
67
+ slippage: slippage,
68
+ cur_sqrt_price: curSqrtPrice,
69
+ })
70
+
71
+ printTransaction(createAddLiquidityTransactionPayload)
72
+ const transferTxn = await sdk.FullClient.executeTx(send_key_pair, createAddLiquidityTransactionPayload, true)
73
+ console.log('open_and_add_liquidity_fix_token: ', transferTxn)
74
+ })
75
+
76
+ test('2: add_liquidity_fix_token', async () => {
77
+ const pool = await sdk.Pool.getPool(poolId)
78
+ const position = await sdk.Position.getPositionById(position_nft_id)
79
+ const tick_lower_index = position.tick_lower_index
80
+ const tick_upper_index = position.tick_upper_index
81
+ const coinAmount = new BN(500)
82
+ const fix_amount_a = true
83
+ const slippage = 0.1
84
+ const curSqrtPrice = new BN(pool.current_sqrt_price)
85
+
86
+ const liquidityInput = ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(
87
+ tick_lower_index,
88
+ tick_upper_index,
89
+ coinAmount,
90
+ fix_amount_a,
91
+ true,
92
+ slippage,
93
+ curSqrtPrice
94
+ )
95
+
96
+ const amount_a = fix_amount_a ? coinAmount.toNumber() : Number(liquidityInput.coin_amount_limit_a)
97
+ const amount_b = fix_amount_a ? Number(liquidityInput.coin_amount_limit_b) : coinAmount.toNumber()
98
+
99
+ console.log('amount: ', { amount_a, amount_b })
100
+
101
+ const addLiquidityPayloadParams: AddLiquidityFixTokenParams = {
102
+ coin_type_a: pool.coin_type_a,
103
+ coin_type_b: pool.coin_type_b,
104
+ pool_id: pool.id,
105
+ tick_lower: tick_lower_index.toString(),
106
+ tick_upper: tick_upper_index.toString(),
107
+ fix_amount_a,
108
+ amount_a,
109
+ amount_b,
110
+ slippage,
111
+ is_open: false,
112
+ pos_id: position.pos_object_id,
113
+ rewarder_coin_types: [],
114
+ collect_fee: true,
115
+ }
116
+ const addLiquidityPayload = await sdk.Position.createAddLiquidityFixTokenPayload(addLiquidityPayloadParams)
117
+
118
+ printTransaction(addLiquidityPayload)
119
+
120
+ const transferTxn = await sdk.FullClient.executeTx(send_key_pair, addLiquidityPayload, true)
121
+ console.log('add_liquidity_fix_token: ', transferTxn)
122
+ })
123
+
124
+ test('3: custom price range open and add liquidity ', async () => {
125
+ const params: CustomRangeParams = {
126
+ is_full_range: false,
127
+ min_price: '0.2',
128
+ max_price: '0.7',
129
+ coin_decimals_a: 6,
130
+ coin_decimals_b: 9,
131
+ price_base_coin: 'coin_a',
132
+ }
133
+
134
+ const result = await sdk.Position.calculateAddLiquidityResultWithPrice({
135
+ add_mode_params: params,
136
+ pool_id: poolId,
137
+ slippage: 0.01,
138
+ coin_amount: toDecimalsAmount(1, 6).toString(),
139
+ fix_amount_a: true,
140
+ })
141
+
142
+ console.log('result: ', result)
143
+
144
+ const payload = await sdk.Position.createAddLiquidityFixCoinWithPricePayload({
145
+ pool_id: poolId,
146
+ calculate_result: result,
147
+ add_mode_params: params,
148
+ })
149
+
150
+ printTransaction(payload)
151
+
152
+ const transfer_txn = await sdk.FullClient.executeTx(send_key_pair, payload, true)
153
+ console.log('createAddLiquidityPayload: ', transfer_txn)
154
+ })
155
+
156
+ test('4: full range price range open and add liquidity ', async () => {
157
+ const params: FullRangeParams = {
158
+ is_full_range: true,
159
+ }
160
+
161
+ const result = await sdk.Position.calculateAddLiquidityResultWithPrice({
162
+ add_mode_params: params,
163
+ pool_id: poolId,
164
+ slippage: 0.01,
165
+ coin_amount: toDecimalsAmount(1, 6).toString(),
166
+ fix_amount_a: true,
167
+ })
168
+
169
+ console.log('result: ', result)
170
+
171
+ const payload = await sdk.Position.createAddLiquidityFixCoinWithPricePayload({
172
+ pool_id: poolId,
173
+ calculate_result: result,
174
+ add_mode_params: params,
175
+ })
176
+
177
+ printTransaction(payload)
178
+
179
+ const transfer_txn = await sdk.FullClient.executeTx(send_key_pair, payload, false)
180
+ console.log('createAddLiquidityPayload: ', transfer_txn)
181
+ })
182
+ })
@@ -0,0 +1,71 @@
1
+ import BN from 'bn.js'
2
+ import { estPositionAPRWithDeltaMethod, estPositionAPRWithMultiMethod } from '../src/math/apr'
3
+
4
+ describe('APR function test', () => {
5
+ test('test estPositionAPRWithDeltaMethod', async () => {
6
+ const currentTickIndex = -1
7
+ const lowerTickIndex = -443636
8
+ const upperTickIndex = 443636
9
+ const currentSqrtPriceX64 = new BN('18446460903430917184')
10
+ const poolLiquidity = new BN('560867872160365128')
11
+ const decimalsA = 6
12
+ const decimalsB = 6
13
+ const decimalsRewarder0 = 6
14
+ const decimalsRewarder1 = 6
15
+ const decimalsRewarder2 = 6
16
+ const feeRate = 100
17
+ const amountA_str = '1000.000034'
18
+ const amountB_str = '999.969333'
19
+ const poolAmountA = new BN(120754054325992)
20
+ const poolAmountB = new BN(1000205276004441)
21
+ const swapVolume_str = '7588147.89'
22
+ const poolRewarders0_str = '30000000'
23
+ const poolRewarders1_str = '52000000'
24
+ const poolRewarders2_str = '35000000'
25
+ const coinAPrice_str = '0.949513'
26
+ const coinBPrice_str = '1.001'
27
+ const rewarder0Price_str = '13.252911'
28
+ const rewarder1Price_str = '0.949513'
29
+ const rewarder2Price_str = '1.001'
30
+
31
+ const res = estPositionAPRWithDeltaMethod(
32
+ currentTickIndex,
33
+ lowerTickIndex,
34
+ upperTickIndex,
35
+ currentSqrtPriceX64,
36
+ poolLiquidity,
37
+ decimalsA,
38
+ decimalsB,
39
+ decimalsRewarder0,
40
+ decimalsRewarder1,
41
+ decimalsRewarder2,
42
+ feeRate,
43
+ amountA_str,
44
+ amountB_str,
45
+ poolAmountA,
46
+ poolAmountB,
47
+ swapVolume_str,
48
+ poolRewarders0_str,
49
+ poolRewarders1_str,
50
+ poolRewarders2_str,
51
+ coinAPrice_str,
52
+ coinBPrice_str,
53
+ rewarder0Price_str,
54
+ rewarder1Price_str,
55
+ rewarder2Price_str
56
+ )
57
+
58
+ console.log('res: ', res)
59
+ })
60
+
61
+ test('test estPositionAPRWithDeltaMethod', async () => {
62
+ const lowerUserPrice = 0.85
63
+ const upperUserPrice = 0.99
64
+ const lowerHistPrice = 0.06
65
+ const upperHistPrice = 1
66
+
67
+ const res = estPositionAPRWithMultiMethod(lowerUserPrice, upperUserPrice, lowerHistPrice, upperHistPrice)
68
+
69
+ console.log('res: ', res)
70
+ })
71
+ })
@@ -0,0 +1,26 @@
1
+ import 'isomorphic-fetch'
2
+ import { CetusClmmSDK } from '../src/sdk'
3
+
4
+ describe('Config Module', () => {
5
+ const sdk = CetusClmmSDK.createSDK({ env: 'mainnet' })
6
+
7
+ test('getTokenListByCoinTypes', async () => {
8
+ const tokenMap = await sdk.CetusConfig.getTokenListByCoinTypes(['0x2::sui::SUI'])
9
+ console.log('tokenMap: ', tokenMap)
10
+ })
11
+
12
+ test('getCoinConfigs', async () => {
13
+ const coin_list = await sdk.CetusConfig.getCoinConfigs(true)
14
+ console.log('coin_list: ', coin_list)
15
+ })
16
+
17
+ test('getClmmPoolConfigs', async () => {
18
+ const pool_list = await sdk.CetusConfig.getClmmPoolConfigs()
19
+ console.log('pool_list: ', pool_list)
20
+ })
21
+
22
+ test('getLaunchpadPoolConfigs', async () => {
23
+ const pool_list = await sdk.CetusConfig.getLaunchpadPoolConfigs()
24
+ console.log('pool_list: ', pool_list)
25
+ })
26
+ })
@@ -0,0 +1,11 @@
1
+ import 'isomorphic-fetch'
2
+ import { CetusClmmSDK } from '../src/sdk'
3
+
4
+ describe('collect fees', () => {
5
+ const sdk = CetusClmmSDK.createSDK({ env: 'mainnet' })
6
+
7
+ test('batchFetchPositionFees', async () => {
8
+ const res = await sdk.Position.batchFetchPositionFees(['0xcf995f40b0f9c40a8b03e0b9d9554fea2bc12a18fe63db3a04c59c46be5c10be'])
9
+ console.log('res####', res)
10
+ })
11
+ })
@@ -0,0 +1,267 @@
1
+ import BN from 'bn.js'
2
+ import { ClmmPoolUtil, d, isSortedSymbols, printTransaction, TickMath } from '@cetusprotocol/common-sdk'
3
+ import { buildTestAccount } from '@cetusprotocol/test-utils'
4
+ import 'isomorphic-fetch'
5
+ // import { CetusClmmSDK } from '../dist/index.js'
6
+ import { CetusClmmSDK } from '../src'
7
+ import { CreatePoolCustomRangeParams, FullRangeParams } from '../src/types/clmm_type'
8
+ import { buildTransferCoin } from '../src/utils'
9
+ import { SuiClient } from '@mysten/sui/client'
10
+
11
+ // import { buildTransferCoin, PositionUtils } from '../dist/index.js'
12
+ // import { CreatePoolCustomRangeParams, FullRangeParams } from '../dist/index.js'
13
+
14
+ const poolId = '0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105'
15
+ describe('Pool Module', () => {
16
+ let send_key_pair = buildTestAccount()
17
+ const sdk = CetusClmmSDK.createSDK({ env: 'mainnet', sui_client: new SuiClient({ url: 'https://fullnode.mainnet.sui.io:443' }) })
18
+ sdk.setSenderAddress(send_key_pair.getPublicKey().toSuiAddress())
19
+
20
+ test('getAllPools', async () => {
21
+ const pools = await sdk.Pool.getPoolsWithPage()
22
+ console.log(pools)
23
+ })
24
+
25
+ test('getAssignPools', async () => {
26
+ const pools = await sdk.Pool.getAssignPools(['0xcf994611fd4c48e277ce3ffd4d4364c914af2c3cbb05f7bf6facd371de688630'])
27
+ console.log(pools)
28
+ })
29
+
30
+ test('getPoolTransactionList', async () => {
31
+ const res = await sdk.Pool.getPoolTransactionList({
32
+ pool_id: '0xb8d7d9e66a60c239e7a60110efcf8de6c705580ed924d0dde141f4a0e2c90105',
33
+ pagination_args: {
34
+ limit: 10,
35
+ },
36
+ })
37
+ console.log('res', res)
38
+ })
39
+
40
+ test('getSinglePool', async () => {
41
+ const pool = await sdk.Pool.getPool('0xcf994611fd4c48e277ce3ffd4d4364c914af2c3cbb05f7bf6facd371de688630')
42
+ console.log('pool', pool)
43
+ })
44
+
45
+ test('doCreatePools', async () => {
46
+ const tick_spacing = 2
47
+ const initialize_price = 1
48
+ const coin_a_decimals = 6
49
+ const coin_b_decimals = 6
50
+ const coin_type_a = `${sdk.sdkOptions.cetus_config?.package_id}::usdt::USDT`
51
+ const coin_type_b = `{sdk.sdkOptions.faucet?.package_id}::usdc::USDC`
52
+
53
+ const createPoolTransactionPayload = await sdk.Pool.createPoolPayload({
54
+ tick_spacing: tick_spacing,
55
+ initialize_sqrt_price: TickMath.priceToSqrtPriceX64(d(initialize_price), coin_a_decimals, coin_b_decimals).toString(),
56
+ uri: '',
57
+ coin_type_a: coin_type_a,
58
+ coin_type_b: coin_type_b,
59
+ fix_amount_a: true,
60
+ amount_a: '100000000',
61
+ amount_b: '100000000',
62
+ metadata_a: '0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24',
63
+ metadata_b: '0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3',
64
+ tick_lower: -443520,
65
+ tick_upper: 443520,
66
+ })
67
+
68
+ printTransaction(createPoolTransactionPayload)
69
+ const transferTxn = await sdk.FullClient.sendTransaction(buildTestAccount(), createPoolTransactionPayload)
70
+ console.log('doCreatePool: ', transferTxn)
71
+ })
72
+
73
+ test('get partner ref fee', async () => {
74
+ const refFee = await sdk.Pool.getPartnerRefFeeAmount('0x0c1e5401e40129da6a65a973b12a034e6c78b7b0b27c3a07213bc5ce3fa3d881')
75
+ console.log('ref fee:', refFee)
76
+ })
77
+
78
+ test('claim partner ref fee', async () => {
79
+ const partnerCap = 'xxx'
80
+ const partner = 'xxx'
81
+ const claimRefFeePayload = await sdk.Pool.claimPartnerRefFeePayload(partnerCap, partner, '0x2::sui::SUI')
82
+ const transferTxn = await sdk.FullClient.sendTransaction(buildTestAccount(), claimRefFeePayload)
83
+ console.log('doCreatePool: ', JSON.stringify(transferTxn))
84
+ })
85
+
86
+ test('get pool by coin types', async () => {
87
+ const coinA = '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN'
88
+ const coinB = '0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN'
89
+
90
+ const pools = await sdk.Pool.getPoolByCoins([coinA, coinB])
91
+ expect(pools.length).toBeGreaterThan(0)
92
+
93
+ const coinC = '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN'
94
+ const coinD = '0x2::sui::SUI'
95
+
96
+ const pools2 = await sdk.Pool.getPoolByCoins([coinC, coinD])
97
+ expect(pools2.length).toBeGreaterThan(0)
98
+
99
+ const coinE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
100
+
101
+ const pools3 = await sdk.Pool.getPoolByCoins([coinC, coinE])
102
+ expect(pools3.length).toEqual(pools2.length)
103
+
104
+ const coinCetus = '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS'
105
+ const coinBlub = '0xfa7ac3951fdca92c5200d468d31a365eb03b2be9936fde615e69f0c1274ad3a0::BLUB::BLUB'
106
+
107
+ const pools4 = await sdk.Pool.getPoolByCoins([coinCetus, coinBlub])
108
+ console.log('pools4', pools4)
109
+ expect(pools4.length).toEqual(pools2.length)
110
+ })
111
+
112
+ test('ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts: ', () => {
113
+ const lowerTick = -74078
114
+ const upperTick = -58716
115
+ const currentSqrtPrice = '979448777168348479'
116
+ const coinAmountA = new BN(100000000)
117
+ const { coin_amount_b } = ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(
118
+ lowerTick,
119
+ upperTick,
120
+ coinAmountA,
121
+ true,
122
+ true,
123
+ 0,
124
+ new BN(currentSqrtPrice)
125
+ )
126
+ })
127
+
128
+ test('isSortedSymbols', () => {
129
+ const p = isSortedSymbols(
130
+ '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT',
131
+ '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC'
132
+ )
133
+ console.log('🚀🚀🚀 ~ file: pool.test.ts:145 ~ test ~ p:', p)
134
+ })
135
+
136
+ test('createPoolTransactionPayload', async () => {
137
+ const payload = await sdk.Pool.createPoolPayload({
138
+ tick_spacing: 220,
139
+ initialize_sqrt_price: '18446744073709551616',
140
+ uri: '',
141
+ fix_amount_a: true,
142
+ amount_a: '100000000',
143
+ amount_b: '100000000',
144
+ coin_type_a: '0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI',
145
+ coin_type_b: '0x2::sui::SUI',
146
+ metadata_a: '0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24',
147
+ metadata_b: '0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3',
148
+ tick_lower: -443520,
149
+ tick_upper: 443520,
150
+ })
151
+ const cPrice = TickMath.sqrtPriceX64ToPrice(new BN('184467440737095516'), 9, 6)
152
+ console.log('🚀🚀🚀 ~ file: pool.test.ts:168 ~ test ~ cPrice:', cPrice.toString())
153
+ printTransaction(payload)
154
+ const transferTxn = await sdk.FullClient.dryRunTransactionBlock({
155
+ transactionBlock: await payload.build({ client: sdk.FullClient }),
156
+ })
157
+
158
+ console.log('🚀🚀🚀 ~ file: pool.test.ts:168 ~ test ~ transferTxn:', transferTxn)
159
+ })
160
+
161
+ test('createPoolTransactionRowPayload', async () => {
162
+ const coinTypeA = '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS'
163
+ const coinTypeB = '0xfa7ac3951fdca92c5200d468d31a365eb03b2be9936fde615e69f0c1274ad3a0::BLUB::BLUB'
164
+
165
+ const coinMetadataA = await sdk.FullClient.fetchCoinMetadata(coinTypeA)
166
+ const coinMetadataB = await sdk.FullClient.fetchCoinMetadata(coinTypeB)
167
+
168
+ const { tx, pos_id, remain_coin_a, remain_coin_b, remain_coin_type_a, remain_coin_type_b } = await sdk.Pool.createPoolRowPayload({
169
+ tick_spacing: 20,
170
+ initialize_sqrt_price: '31366801070720067977',
171
+ uri: '',
172
+ fix_amount_a: true,
173
+ amount_a: '100000000',
174
+ amount_b: '1000000000',
175
+ coin_type_a: coinTypeA,
176
+ coin_type_b: coinTypeB,
177
+ metadata_a: coinMetadataA!.id!,
178
+ metadata_b: coinMetadataB!.id!,
179
+ tick_lower: -440000,
180
+ tick_upper: 440000,
181
+ })
182
+ const cPrice = TickMath.sqrtPriceX64ToPrice(new BN('184467440737095516'), 0, 9)
183
+ console.log('🚀🚀🚀 ~ file: pool.test.ts:168 ~ test ~ cPrice:', cPrice.toString())
184
+ printTransaction(tx)
185
+
186
+ buildTransferCoin(sdk, tx, remain_coin_a, remain_coin_type_a)
187
+ buildTransferCoin(sdk, tx, remain_coin_b, remain_coin_type_b)
188
+
189
+ tx.transferObjects([pos_id], sdk.getSenderAddress())
190
+ const transferTxn = await sdk.FullClient.executeTx(send_key_pair, tx, true)
191
+ console.log('doCreatePool: ', transferTxn)
192
+ })
193
+
194
+ test('custom price range create pool return position', async () => {
195
+ const tick_spacing = 220
196
+ const modeParams: CreatePoolCustomRangeParams = {
197
+ is_full_range: false,
198
+ min_price: '0.2',
199
+ max_price: '0.7',
200
+ }
201
+ const result = await sdk.Pool.calculateCreatePoolWithPrice({
202
+ tick_spacing,
203
+ current_price: '0.5',
204
+ coin_amount: '1000000',
205
+ fix_amount_a: true,
206
+ add_mode_params: modeParams,
207
+ coin_decimals_a: 6,
208
+ coin_decimals_b: 9,
209
+ price_base_coin: 'coin_a',
210
+ slippage: 0.05,
211
+ })
212
+ console.log('🚀 ~ test ~ result:', result)
213
+
214
+ const coin_type_a = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC'
215
+ const coin_type_b = '0x2::sui::SUI'
216
+
217
+ const { tx, pos_id, remain_coin_a, remain_coin_b, remain_coin_type_a, remain_coin_type_b } =
218
+ await sdk.Pool.createPoolWithPriceReturnPositionPayload({
219
+ tick_spacing,
220
+ calculate_result: result,
221
+ add_mode_params: modeParams,
222
+ coin_type_a,
223
+ coin_type_b,
224
+ })
225
+
226
+ buildTransferCoin(sdk, tx, remain_coin_a, remain_coin_type_a)
227
+ buildTransferCoin(sdk, tx, remain_coin_b, remain_coin_type_b)
228
+
229
+ tx.transferObjects([pos_id], sdk.getSenderAddress())
230
+ const transferTxn = await sdk.FullClient.executeTx(send_key_pair, tx, true)
231
+ console.log('doCreatePool: ', transferTxn)
232
+ })
233
+
234
+ test('full price range create pool', async () => {
235
+ const tick_spacing = 220
236
+ const modeParams: FullRangeParams = {
237
+ is_full_range: true,
238
+ }
239
+
240
+ const result = await sdk.Pool.calculateCreatePoolWithPrice({
241
+ tick_spacing,
242
+ current_price: '0.5',
243
+ coin_amount: '1000000',
244
+ fix_amount_a: true,
245
+ add_mode_params: modeParams,
246
+ coin_decimals_a: 6,
247
+ coin_decimals_b: 9,
248
+ price_base_coin: 'coin_a',
249
+ slippage: 0.05,
250
+ })
251
+ console.log('🚀 ~ test ~ result:', result)
252
+
253
+ const coin_type_a = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC'
254
+ const coin_type_b = '0x2::sui::SUI'
255
+
256
+ const tx = await sdk.Pool.createPoolWithPricePayload({
257
+ tick_spacing,
258
+ calculate_result: result,
259
+ add_mode_params: modeParams,
260
+ coin_type_a,
261
+ coin_type_b,
262
+ })
263
+
264
+ const transferTxn = await sdk.FullClient.executeTx(send_key_pair, tx, true)
265
+ console.log('doCreatePool: ', transferTxn)
266
+ })
267
+ })