@@ -9,6 +9,7 @@ use super::{
99use crate :: { Quote , SwapperError , SwapperQuoteData , fees:: ReferralFee , fees:: apply_slippage_in_bp} ;
1010use gem_sui:: {
1111 EMPTY_ADDRESS , ESTIMATION_GAS_BUDGET , SuiClient ,
12+ address:: SuiAddress ,
1213 gas_budget:: GAS_BUDGET_MULTIPLIER ,
1314 is_sui_coin,
1415 models:: { CoinAsset , TxOutput } ,
@@ -18,7 +19,8 @@ use gem_sui::{
1819 into_balance, move_call,
1920 } ,
2021} ;
21- use std:: { collections:: HashMap , fmt:: Display , str:: FromStr } ;
22+ use primitives:: Address as AddressTrait ;
23+ use std:: { collections:: HashMap , fmt:: Display } ;
2224use sui_transaction_builder:: { Argument , ObjectInput , TransactionBuilder } ;
2325use sui_types:: { Address , Digest } ;
2426
@@ -112,7 +114,7 @@ pub(super) fn build_batch_quote_inspect(quotes: &[(&Hop, u64)]) -> Result<Vec<u8
112114 let amount = txb. pure ( amount_in) ;
113115 move_call (
114116 & mut txb,
115- CETUS_CLMM_PUBLISHED_AT ,
117+ cetus_clmm_publish_at ( ) ,
116118 MODULE_POOL ,
117119 FUNCTION_CALCULATE_SWAP_RESULT ,
118120 & [ & hop. coin_a , & hop. coin_b ] ,
@@ -132,20 +134,20 @@ pub(super) fn build_batch_multi_hop_quote_inspect(routes: &[(&Hop, &Hop, u64)])
132134 let amount = txb. pure ( amount_in) ;
133135 let csr1 = move_call (
134136 & mut txb,
135- CETUS_CLMM_PUBLISHED_AT ,
137+ cetus_clmm_publish_at ( ) ,
136138 MODULE_POOL ,
137139 FUNCTION_CALCULATE_SWAP_RESULT ,
138140 & [ & hop1. coin_a , & hop1. coin_b ] ,
139141 vec ! [ pool1, a2b1, by_amount_in_1, amount] ,
140142 )
141143 . map_err ( error) ?;
142- let amount2 = move_call ( & mut txb, CETUS_CLMM_PUBLISHED_AT , MODULE_POOL , FUNCTION_CALCULATED_SWAP_RESULT_AMOUNT_OUT , & [ ] , vec ! [ csr1] ) . map_err ( error) ?;
144+ let amount2 = move_call ( & mut txb, cetus_clmm_publish_at ( ) , MODULE_POOL , FUNCTION_CALCULATED_SWAP_RESULT_AMOUNT_OUT , & [ ] , vec ! [ csr1] ) . map_err ( error) ?;
143145 let pool2 = txb. object ( shared_object_input ( & hop2. pool_id , hop2. pool_init_version , false ) ?) ;
144146 let a2b2 = txb. pure ( & hop2. a2b ) ;
145147 let by_amount_in_2 = txb. pure ( & true ) ;
146148 move_call (
147149 & mut txb,
148- CETUS_CLMM_PUBLISHED_AT ,
150+ cetus_clmm_publish_at ( ) ,
149151 MODULE_POOL ,
150152 FUNCTION_CALCULATE_SWAP_RESULT ,
151153 & [ & hop2. coin_a , & hop2. coin_b ] ,
@@ -159,10 +161,10 @@ pub(super) fn build_batch_multi_hop_quote_inspect(routes: &[(&Hop, &Hop, u64)])
159161pub ( super ) fn build_pool_id_inspect ( coin_a : & str , coin_b : & str , tick_spacing : u32 ) -> Result < Vec < u8 > , SwapperError > {
160162 let mut txb = TransactionBuilder :: new ( ) ;
161163 let tick = txb. pure ( & tick_spacing) ;
162- let key = move_call ( & mut txb, CETUS_CLMM_PUBLISHED_AT , MODULE_FACTORY , FUNCTION_NEW_POOL_KEY , & [ coin_a, coin_b] , vec ! [ tick] ) . map_err ( error) ?;
164+ let key = move_call ( & mut txb, cetus_clmm_publish_at ( ) , MODULE_FACTORY , FUNCTION_NEW_POOL_KEY , & [ coin_a, coin_b] , vec ! [ tick] ) . map_err ( error) ?;
163165 let pools = txb. object ( shared_object_input ( CETUS_POOLS_REGISTRY , CETUS_SHARED_INIT_VERSION , false ) ?) ;
164- let info = move_call ( & mut txb, CETUS_CLMM_PUBLISHED_AT , MODULE_FACTORY , FUNCTION_POOL_SIMPLE_INFO , & [ ] , vec ! [ pools, key] ) . map_err ( error) ?;
165- move_call ( & mut txb, CETUS_CLMM_PUBLISHED_AT , MODULE_FACTORY , FUNCTION_POOL_ID , & [ ] , vec ! [ info] ) . map_err ( error) ?;
166+ let info = move_call ( & mut txb, cetus_clmm_publish_at ( ) , MODULE_FACTORY , FUNCTION_POOL_SIMPLE_INFO , & [ ] , vec ! [ pools, key] ) . map_err ( error) ?;
167+ move_call ( & mut txb, cetus_clmm_publish_at ( ) , MODULE_FACTORY , FUNCTION_POOL_ID , & [ ] , vec ! [ info] ) . map_err ( error) ?;
166168 inspect_transaction_kind_bytes ( txb)
167169}
168170
@@ -183,6 +185,7 @@ fn build_transaction(
183185 input : & BuildInput < ' _ > ,
184186) -> Result < TxOutput , SwapperError > {
185187 let mut txb = TransactionBuilder :: new ( ) ;
188+ let published_at = SuiAddress :: from_str ( published_at) . map ( Address :: from) ?;
186189 let input_coin = build_input_coin ( & mut txb, route. input_coin_type ( ) , input. amount , input. from_coins ) . map_err ( error) ?;
187190 let ( swap_coin, swap_amount) = match route. fee_side {
188191 FeeSide :: Input => {
@@ -266,7 +269,7 @@ fn build_transaction(
266269 . map_err ( error) ?;
267270 }
268271
269- let sender = recipient ( & quote. request . wallet_address ) ?;
272+ let sender = SuiAddress :: from_str ( & quote. request . wallet_address ) . map ( Address :: from ) ?;
270273 let output_coin = from_balance ( & mut txb, route. output_coin_type ( ) , current_balance) . map_err ( error) ?;
271274
272275 let pay_output_fee = match route. fee_side {
@@ -279,7 +282,8 @@ fn build_transaction(
279282 . split_coins ( output_coin, vec ! [ fee_amount_arg] )
280283 . pop ( )
281284 . ok_or_else ( || SwapperError :: TransactionError ( "Cetus CLMM output fee split failed" . into ( ) ) ) ?;
282- transfer_coin ( & mut txb, fee_coin, recipient ( & referral_fee. address ) ?) ;
285+ let recipient = SuiAddress :: from_str ( & referral_fee. address ) . map ( Address :: from) ?;
286+ transfer_coin ( & mut txb, fee_coin, recipient) ;
283287 }
284288
285289 let min_out = apply_slippage_in_bp ( & route. net_amount_out ( ) , quote. request . options . slippage . bps ) ;
@@ -290,7 +294,12 @@ fn build_transaction(
290294 . ok_or_else ( || SwapperError :: TransactionError ( "Cetus CLMM min-out split failed" . into ( ) ) ) ?;
291295 txb. merge_coins ( output_coin, vec ! [ split_off] ) ;
292296
293- let dest = swap_recipient ( quote) ?;
297+ let dest = SuiAddress :: from_str ( if quote. request . destination_address . is_empty ( ) {
298+ & quote. request . wallet_address
299+ } else {
300+ & quote. request . destination_address
301+ } )
302+ . map ( Address :: from) ?;
294303 if dest == sender && is_sui_coin ( route. output_coin_type ( ) ) {
295304 let gas = txb. gas ( ) ;
296305 txb. merge_coins ( gas, vec ! [ output_coin] ) ;
@@ -325,7 +334,8 @@ fn pay_referral_fee(txb: &mut TransactionBuilder, input_coin: Argument, fee: u64
325334 . split_coins ( input_coin, vec ! [ fee_amount] )
326335 . pop ( )
327336 . ok_or_else ( || SwapperError :: TransactionError ( "Sui referral fee split failed" . into ( ) ) ) ?;
328- transfer_coin ( txb, fee_coin, recipient ( & referral_fee. address ) ?) ;
337+ let recipient = SuiAddress :: from_str ( & referral_fee. address ) . map ( Address :: from) ?;
338+ transfer_coin ( txb, fee_coin, recipient) ;
329339 Ok ( input_coin)
330340}
331341
@@ -341,25 +351,17 @@ fn transfer_coin(txb: &mut TransactionBuilder, coin: Argument, recipient: Addres
341351 txb. transfer_objects ( vec ! [ coin] , recipient) ;
342352}
343353
344- fn swap_recipient ( quote : & Quote ) -> Result < Address , SwapperError > {
345- if quote. request . destination_address . is_empty ( ) {
346- recipient ( & quote. request . wallet_address )
347- } else {
348- recipient ( & quote. request . destination_address )
349- }
350- }
351-
352- fn recipient ( value : & str ) -> Result < Address , SwapperError > {
353- Address :: from_str ( value) . map_err ( |err| SwapperError :: TransactionError ( format ! ( "Invalid Sui address {value}: {err}" ) ) )
354+ fn cetus_clmm_publish_at ( ) -> Address {
355+ SuiAddress :: from_str ( CETUS_CLMM_PUBLISHED_AT ) . map ( Address :: from) . unwrap ( )
354356}
355357
356358fn shared_object_input ( object_id : & str , initial_shared_version : u64 , mutable : bool ) -> Result < ObjectInput , SwapperError > {
357- let address = Address :: from_str ( object_id) . map_err ( |err| SwapperError :: ComputeQuoteError ( format ! ( "Invalid Sui object id {object_id}: {err}" ) ) ) ?;
359+ let address = SuiAddress :: from_str ( object_id) . map ( Address :: from ) ?;
358360 Ok ( ObjectInput :: shared ( address, initial_shared_version, mutable) )
359361}
360362
361363fn inspect_transaction_kind_bytes ( mut txb : TransactionBuilder ) -> Result < Vec < u8 > , SwapperError > {
362- txb. set_sender ( Address :: from_str ( EMPTY_ADDRESS ) . map_err ( |err| SwapperError :: ComputeQuoteError ( format ! ( "Invalid inspect sender: {err}" ) ) ) ?) ;
364+ txb. set_sender ( SuiAddress :: from_str ( EMPTY_ADDRESS ) . map ( Address :: from ) ?) ;
363365 txb. set_gas_price ( 0 ) ;
364366 txb. set_gas_budget ( 0 ) ;
365367 txb. add_gas_objects ( vec ! [ ObjectInput :: owned( Address :: ZERO , 0 , Digest :: ZERO ) ] ) ;
0 commit comments