@@ -121,7 +121,11 @@ pub fn reply(deps: DepsMut, _env: Env, reply: Reply) -> Result<Response, Contrac
121
121
true ,
122
122
) ?;
123
123
124
- Ok ( Response :: new ( ) . set_data ( ack_fail ( err) ) )
124
+ Ok ( Response :: new ( ) . set_data ( ack_fail ( err) ) . add_attributes ( vec ! [
125
+ attr( "undo_reduce_channel" , reply_args. channel) ,
126
+ attr( "undo_reduce_channel_ibc_denom" , reply_args. denom) ,
127
+ attr( "undo_reduce_channel_amount" , reply_args. amount) ,
128
+ ] ) )
125
129
}
126
130
} ,
127
131
NATIVE_RECEIVE_ID => match reply. result {
@@ -150,7 +154,12 @@ pub fn reply(deps: DepsMut, _env: Env, reply: Reply) -> Result<Response, Contrac
150
154
151
155
Ok ( Response :: new ( )
152
156
. set_data ( ack_fail ( err. clone ( ) ) )
153
- . add_attribute ( "error_transferring_ibc_tokens_to_cw20" , err) )
157
+ . add_attribute ( "error_transferring_ibc_tokens_to_cw20" , err)
158
+ . add_attributes ( vec ! [
159
+ attr( "undo_increase_channel" , reply_args. channel) ,
160
+ attr( "undo_increase_channel_ibc_denom" , reply_args. denom) ,
161
+ attr( "undo_increase_channel_amount" , reply_args. amount) ,
162
+ ] ) )
154
163
}
155
164
} ,
156
165
FOLLOW_UP_FAILURE_ID => match reply. result {
@@ -440,17 +449,10 @@ pub fn get_follow_up_msgs(
440
449
) -> Result < ( Vec < CosmosMsg > , String ) , ContractError > {
441
450
let config = CONFIG . load ( storage) ?;
442
451
let mut cosmos_msgs: Vec < CosmosMsg > = vec ! [ ] ;
443
- if memo. is_empty ( ) {
444
- return Ok ( (
445
- vec ! [ send_amount( to_send, receiver. to_string( ) , None ) ] ,
446
- "" . to_string ( ) ,
447
- ) ) ;
448
- }
449
452
let destination: DestinationInfo = DestinationInfo :: from_str ( memo) ;
450
- // if destination denom, then we simply transfers cw20 to the receiver address.
451
- if destination. destination_denom . is_empty ( ) {
453
+ if is_follow_up_msgs_only_send_amount ( & memo, & destination. destination_denom ) {
452
454
return Ok ( (
453
- vec ! [ send_amount( to_send, destination . receiver. clone ( ) , None ) ] ,
455
+ vec ! [ send_amount( to_send, receiver. to_string ( ) , None ) ] ,
454
456
"" . to_string ( ) ,
455
457
) ) ;
456
458
}
@@ -476,22 +478,25 @@ pub fn get_follow_up_msgs(
476
478
config. fee_denom . as_str ( ) ,
477
479
& destination. destination_denom ,
478
480
) ;
479
-
480
- let response: SimulateSwapOperationsResponse = querier. query_wasm_smart (
481
- config. swap_router_contract . clone ( ) ,
482
- & oraiswap:: router:: QueryMsg :: SimulateSwapOperations {
483
- offer_amount : to_send. amount ( ) . clone ( ) ,
484
- operations : swap_operations. clone ( ) ,
485
- } ,
486
- ) ?;
481
+ let mut minimum_receive = to_send. amount ( ) ;
482
+ if swap_operations. len ( ) > 0 {
483
+ let response: SimulateSwapOperationsResponse = querier. query_wasm_smart (
484
+ config. swap_router_contract . clone ( ) ,
485
+ & oraiswap:: router:: QueryMsg :: SimulateSwapOperations {
486
+ offer_amount : to_send. amount ( ) . clone ( ) ,
487
+ operations : swap_operations. clone ( ) ,
488
+ } ,
489
+ ) ?;
490
+ minimum_receive = response. amount ;
491
+ }
487
492
488
493
let ibc_msg = build_ibc_msg (
489
494
storage,
490
495
env,
491
496
receiver_asset_info,
492
497
receiver,
493
498
packet. dest . channel_id . as_str ( ) ,
494
- response . amount . clone ( ) ,
499
+ minimum_receive . clone ( ) ,
495
500
& sender,
496
501
& destination,
497
502
config. default_timeout ,
@@ -508,17 +513,35 @@ pub fn get_follow_up_msgs(
508
513
ibc_error_msg = ibc_msg. unwrap_err ( ) . to_string ( ) ;
509
514
}
510
515
build_swap_msgs (
511
- response . amount ,
516
+ minimum_receive ,
512
517
& config. swap_router_contract ,
513
518
to_send. amount ( ) ,
514
519
initial_receive_asset_info,
515
520
to,
516
521
& mut cosmos_msgs,
517
522
swap_operations,
518
523
) ?;
524
+ // fallback case. If there's no cosmos messages then we return send amount
525
+ if cosmos_msgs. is_empty ( ) {
526
+ return Ok ( (
527
+ vec ! [ send_amount( to_send, receiver. to_string( ) , None ) ] ,
528
+ ibc_error_msg,
529
+ ) ) ;
530
+ }
519
531
return Ok ( ( cosmos_msgs, ibc_error_msg) ) ;
520
532
}
521
533
534
+ pub fn is_follow_up_msgs_only_send_amount ( memo : & str , destination_denom : & str ) -> bool {
535
+ if memo. is_empty ( ) {
536
+ return true ;
537
+ }
538
+ // if destination denom, then we simply transfers cw20 to the receiver address.
539
+ if destination_denom. is_empty ( ) {
540
+ return true ;
541
+ }
542
+ false
543
+ }
544
+
522
545
pub fn build_swap_operations (
523
546
receiver_asset_info : AssetInfo ,
524
547
initial_receive_asset_info : AssetInfo ,
@@ -529,21 +552,21 @@ pub fn build_swap_operations(
529
552
let fee_denom_asset_info = AssetInfo :: NativeToken {
530
553
denom : fee_denom. to_string ( ) ,
531
554
} ;
532
- let mut swap_operations = vec ! [
533
- SwapOperation :: OraiSwap {
555
+ let mut swap_operations = vec ! [ ] ;
556
+ if receiver_asset_info. eq ( & initial_receive_asset_info) {
557
+ return vec ! [ ] ;
558
+ }
559
+ if initial_receive_asset_info. ne ( & fee_denom_asset_info) {
560
+ swap_operations. push ( SwapOperation :: OraiSwap {
534
561
offer_asset_info : initial_receive_asset_info. clone ( ) ,
535
562
ask_asset_info : fee_denom_asset_info. clone ( ) ,
536
- } ,
537
- SwapOperation :: OraiSwap {
563
+ } )
564
+ }
565
+ if destination_denom. ne ( fee_denom) {
566
+ swap_operations. push ( SwapOperation :: OraiSwap {
538
567
offer_asset_info : fee_denom_asset_info. clone ( ) ,
539
568
ask_asset_info : receiver_asset_info,
540
- } ,
541
- ] ;
542
- if destination_denom. eq ( fee_denom) {
543
- swap_operations. pop ( ) ;
544
- }
545
- if initial_receive_asset_info. eq ( & fee_denom_asset_info) {
546
- swap_operations. pop ( ) ;
569
+ } ) ;
547
570
}
548
571
swap_operations
549
572
}
@@ -710,8 +733,9 @@ pub fn handle_follow_up_failure(
710
733
false ,
711
734
) ?;
712
735
response = response. add_attributes ( vec ! [
713
- attr( "ibc_denom_undo_channel_balance" , ibc_data. ibc_denom) ,
714
- attr( "remote_amount_undo_channel_balance" , ibc_data. remote_amount) ,
736
+ attr( "undo_reduce_channel" , reply_args. channel) ,
737
+ attr( "undo_reduce_channel_ibc_denom" , ibc_data. ibc_denom) ,
738
+ attr( "undo_reduce_channel_balance" , ibc_data. remote_amount) ,
715
739
] ) ;
716
740
}
717
741
let refund_amount = Amount :: from_parts (
0 commit comments