14
14
// You should have received a copy of the GNU General Public License
15
15
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.
16
16
17
- use alloy:: primitives:: { Address , U256 } ;
17
+ use alloy:: consensus:: { SignableTransaction , TxLegacy } ;
18
+ use alloy:: primitives:: { Address , PrimitiveSignature , U256 } ;
18
19
use async_trait:: async_trait;
19
20
use base58:: ToBase58 ;
20
21
use binance_api:: spot_trading_api:: types:: {
@@ -50,16 +51,8 @@ use pumpx::methods::create_cross_order::CrossOrderInfo;
50
51
use pumpx:: signer_client:: ChainType ;
51
52
use pumpx:: signer_client:: SignerClient ;
52
53
53
- use pumpx:: methods:: create_cross_order:: CreateCrossOrderBody ;
54
- use pumpx:: methods:: create_limit_order:: CreateLimitOrderBody ;
55
- use pumpx:: methods:: create_market_order_tx:: CreateMarketOrderTxBody ;
56
- use pumpx:: methods:: cross_fail:: CrossFailBody ;
57
- use pumpx:: PumpxApi ;
58
- use pumpx:: { pubkey_to_evm_address, pubkey_to_solana_address} ;
59
- use std:: collections:: HashMap ;
60
- use std:: sync:: Arc ;
61
-
62
54
use accounting_contract_client:: AccountingContractApi ;
55
+ use alloy:: primitives:: private:: alloy_rlp:: Decodable ;
63
56
use binance_api:: BinanceApi ;
64
57
use executor_primitives:: AccountId ;
65
58
use executor_primitives:: ChainAsset ;
@@ -69,9 +62,18 @@ use parentchain_rpc_client::CustomConfig;
69
62
use parentchain_rpc_client:: SubxtClient ;
70
63
use parentchain_rpc_client:: SubxtClientFactory ;
71
64
use parentchain_signer:: TxSigner ;
65
+ use pumpx:: methods:: create_cross_order:: CreateCrossOrderBody ;
66
+ use pumpx:: methods:: create_limit_order:: CreateLimitOrderBody ;
67
+ use pumpx:: methods:: create_market_order_tx:: CreateMarketOrderTxBody ;
68
+ use pumpx:: methods:: cross_fail:: CrossFailBody ;
69
+ use pumpx:: PumpxApi ;
70
+ use pumpx:: { pubkey_to_evm_address, pubkey_to_solana_address} ;
71
+ use std:: collections:: HashMap ;
72
+ use std:: sync:: Arc ;
72
73
73
74
use log:: debug;
74
-
75
+ use pumpx:: methods:: create_market_order_unsigned_tx:: CreateMarketOrderUnsignedTxBody ;
76
+ use pumpx:: methods:: send_order_tx:: { SendOrderTxBody , SendOrderTxResponse } ;
75
77
// use intent_asset_lock::always_unlocked::AlwaysUnlockedAssetsLock;
76
78
// use intent_asset_lock::AccountAssetLocks;
77
79
@@ -1010,7 +1012,7 @@ impl<BinanceClient: BinanceApi> IntentExecutor for CrossChainIntentExecutor<Bina
1010
1012
} ;
1011
1013
1012
1014
debug ! ( "Doing market order" ) ;
1013
- let body = CreateMarketOrderTxBody {
1015
+ let body = CreateMarketOrderUnsignedTxBody {
1014
1016
request_id : intent_id,
1015
1017
chain_id : pumpx_config. to_chain_id ,
1016
1018
token_ca : to_token_ca. clone ( ) ,
@@ -1039,14 +1041,14 @@ impl<BinanceClient: BinanceApi> IntentExecutor for CrossChainIntentExecutor<Bina
1039
1041
} ,
1040
1042
slippage : pumpx_config. slippage ,
1041
1043
wallet_index : pumpx_config. wallet_index ,
1044
+ recipient_address : String :: from ( "" ) ,
1042
1045
} ;
1043
1046
debug ! ( "Calling pumpx create_market_order_tx, body: {:?}" , body) ;
1044
- let response =
1045
- self . pumpx_api . create_market_order_tx ( & access_token, body) . await . map_err (
1046
- |_| {
1047
- log:: error!( "Failed to create market order tx" ) ;
1048
- } ,
1049
- ) ?;
1047
+
1048
+ let response = self
1049
+ . create_market_order_tx ( & access_token, body, account_id)
1050
+ . await
1051
+ . map_err ( |_| log:: error!( "Failed to create and submit market order tx" ) ) ?;
1050
1052
1051
1053
debug ! ( "Response create_market_order_tx: {:?}" , response) ;
1052
1054
result = ( Some ( response. encode ( ) ) , true ) ;
@@ -1074,6 +1076,75 @@ impl<BinanceClient: BinanceApi> IntentExecutor for CrossChainIntentExecutor<Bina
1074
1076
}
1075
1077
}
1076
1078
1079
+ impl < BinanceClient : BinanceApi > CrossChainIntentExecutor < BinanceClient > {
1080
+ pub async fn create_market_order_tx (
1081
+ & self ,
1082
+ access_token : & str ,
1083
+ order : CreateMarketOrderUnsignedTxBody ,
1084
+ account_id : & AccountId ,
1085
+ ) -> Result < SendOrderTxResponse , ( ) > {
1086
+ let wallet_index = order. wallet_index ;
1087
+ let response = self
1088
+ . pumpx_api
1089
+ . create_market_order_unsigned_tx ( access_token, order)
1090
+ . await
1091
+ . map_err ( |_| log:: error!( "Failed to get unsigned market order tx" ) ) ?;
1092
+
1093
+ let unsigned_tx_string = response. data . tx_data . ok_or_else ( || {
1094
+ log:: error!( "Failed to unwrap tx_data" ) ;
1095
+ } ) ?;
1096
+ let order_id = response. data . order_id . ok_or_else ( || {
1097
+ log:: error!( "Failed to unwrap order_id" ) ;
1098
+ } ) ?;
1099
+ let chain_id = response. data . chain_id . ok_or_else ( || {
1100
+ log:: error!( "Failed to unwrap chain_id" ) ;
1101
+ } ) ?;
1102
+
1103
+ let unsigned_tx_bytes = unsigned_tx_string
1104
+ . iter ( )
1105
+ . map ( |s| {
1106
+ let hex_str = s. trim_start_matches ( "0x" ) ;
1107
+ hex:: decode ( hex_str) . expect ( "Invalid hex string" )
1108
+ } )
1109
+ . collect ( ) ;
1110
+
1111
+ let signatures = self
1112
+ . pumpx_signer_client
1113
+ . request_signatures (
1114
+ ChainType :: Evm ,
1115
+ wallet_index,
1116
+ * account_id. as_ref ( ) ,
1117
+ unsigned_tx_bytes,
1118
+ )
1119
+ . await ?;
1120
+
1121
+ let mut tx_data: Vec < String > = vec ! [ ] ;
1122
+ for ( x, y) in unsigned_tx_string. into_iter ( ) . zip ( signatures. into_iter ( ) ) {
1123
+ let bytes = hex:: decode ( x. trim_start_matches ( "0x" ) )
1124
+ . map_err ( |_| log:: error!( "invalid hex string" ) ) ?;
1125
+ // We should be able to decode it to Legacy Transaction
1126
+ // As it is RLP Encoded Bytes which adheres to string encoding rules
1127
+ let unsigned_tx = TxLegacy :: decode ( & mut & bytes[ ..] )
1128
+ . map_err ( |_| log:: error!( "Failed to decode legacy tx" ) ) ?;
1129
+ let signature = PrimitiveSignature :: try_from ( y. as_ref ( ) )
1130
+ . map_err ( |_| log:: error!( "Failed to create Typed signature" ) ) ?;
1131
+
1132
+ let signed_tx = unsigned_tx. into_signed ( signature) ;
1133
+ let mut encoded_signed_tx = vec ! [ ] ;
1134
+ signed_tx. rlp_encode ( & mut encoded_signed_tx) ;
1135
+ tx_data. push ( hex:: encode ( encoded_signed_tx) ) ;
1136
+ }
1137
+
1138
+ let response = self
1139
+ . pumpx_api
1140
+ . send_order_tx ( access_token, SendOrderTxBody { order_id, chain_id, tx_data } )
1141
+ . await
1142
+ . map_err ( |_| log:: error!( "Failed to send order tx" ) ) ?;
1143
+
1144
+ Ok ( response)
1145
+ }
1146
+ }
1147
+
1077
1148
fn str_to_u256 ( amount : & str , decimals : u32 ) -> Option < U256 > {
1078
1149
let amount = Decimal :: from_str ( amount) . ok ( ) ?;
1079
1150
let factor = Decimal :: from ( 10u64 . pow ( decimals) ) ;
0 commit comments