Skip to content

P 1446 add RPC call pumpx_notifyLimitOrderResult #3361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f7a6d7d
fix leftovers
BillyWooo Apr 3, 2025
e76f9ef
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 3, 2025
88dce38
add google auth
Kailai-Wang Apr 4, 2025
f8525f6
format response
Kailai-Wang Apr 5, 2025
e7a200f
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 5, 2025
8a3a85f
Merge remote-tracking branch 'origin/check-google-export-wallet' into…
BillyWooo Apr 5, 2025
a076da1
addwallet
BillyWooo Apr 6, 2025
0b1bb52
rename: NativeTaskOk::PumpxJwt -> NativeTaskOk::PumpxRequestJwt
BillyWooo Apr 6, 2025
a69c0b3
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 7, 2025
8c747d1
addwallet doesn't need encrypt
BillyWooo Apr 7, 2025
bc43569
Use u32 for pumpx chain_id
Kailai-Wang Apr 7, 2025
84fde45
Merge branch 'dev' into use-u32-chain-id
Kailai-Wang Apr 7, 2025
237a6ae
Merge branch 'dev' into use-u32-chain-id
silva-fj Apr 7, 2025
c266aaf
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 7, 2025
9a6335c
add TransferWidthdraw rpc
BillyWooo Apr 7, 2025
621bcc5
Merge remote-tracking branch 'origin/use-u32-chain-id' into p-1420-im…
BillyWooo Apr 7, 2025
46fa204
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 7, 2025
9e10d8f
addWallet rpc return result is empty
BillyWooo Apr 7, 2025
3247f3e
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 7, 2025
b7eab1a
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 7, 2025
cf3f7a0
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 8, 2025
3b59245
re-group error code.
BillyWooo Apr 8, 2025
340cc3a
loop through to sign tx
BillyWooo Apr 8, 2025
ad8e807
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 8, 2025
ac1fae3
clippy
BillyWooo Apr 8, 2025
a826645
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 9, 2025
8650fb2
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 9, 2025
47eeee6
update to use "request_signatures"
BillyWooo Apr 9, 2025
59a8fdc
improvement
BillyWooo Apr 9, 2025
b689267
clippy
BillyWooo Apr 9, 2025
4b79394
Merge remote-tracking branch 'origin/dev' into p-1419-implement-pumpx…
BillyWooo Apr 9, 2025
fd7f351
Merge remote-tracking branch 'origin/p-1419-implement-pumpxaddwallet'…
BillyWooo Apr 9, 2025
c556ba5
refactor
BillyWooo Apr 9, 2025
7813f4d
handle return value
BillyWooo Apr 9, 2025
f5b3b1e
Merge remote-tracking branch 'origin/p-1419-implement-pumpxaddwallet'…
BillyWooo Apr 9, 2025
f3053c5
return API response
BillyWooo Apr 9, 2025
6f92895
Merge remote-tracking branch 'origin/p-1419-implement-pumpxaddwallet'…
BillyWooo Apr 9, 2025
3c41ce6
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 9, 2025
1a27176
fix wrong type
BillyWooo Apr 9, 2025
055873c
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 10, 2025
b6ac8fa
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 10, 2025
f3847eb
update comment
BillyWooo Apr 10, 2025
329667f
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 10, 2025
aa2ec67
remove request_id
BillyWooo Apr 10, 2025
70f5149
Merge remote-tracking branch 'origin/dev' into p-1420-implement-pumpx…
BillyWooo Apr 10, 2025
c8413e7
add rpc call: pumpx_notifyLimitOrderResult
BillyWooo Apr 10, 2025
713e4a8
remove return value of pumpx_notifyLimitOrderResult
BillyWooo Apr 10, 2025
66006cc
Merge remote-tracking branch 'origin/dev' into p-1446-implement-pumpx…
BillyWooo Apr 10, 2025
e328702
Merge remote-tracking branch 'origin/dev' into p-1446-implement-pumpx…
BillyWooo Apr 10, 2025
ce9706d
fix comments
BillyWooo Apr 10, 2025
0cac552
clippy
BillyWooo Apr 10, 2025
29f1af8
remove omni account check
BillyWooo Apr 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tee-worker/omni-executor/executor-core/src/native_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub enum NativeTask {
MaybeGoogleCode, // google_code
Option<String>, // language
),
#[codec(index = 25)]
PumpxNotifyLimitOrderResult(Identity, u32, String, Option<String>),
}

impl NativeTaskTrait for NativeTask {
Expand All @@ -74,6 +76,7 @@ impl NativeTaskTrait for NativeTask {
Self::PumpxAddWallet(sender, ..) => sender,
Self::PumpxSignLimitOrder(sender, ..) => sender,
Self::PumpxTransferWidthdraw(sender, ..) => sender,
Self::PumpxNotifyLimitOrderResult(sender, ..) => sender,
}
}

Expand Down
42 changes: 42 additions & 0 deletions tee-worker/omni-executor/native-task-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,48 @@ async fn handle_native_task<
},
};
},
NativeTask::PumpxNotifyLimitOrderResult(sender, intent_id, result, message) => {
if result != "ok" && result != "nok" {
send_error(
format!("Invalid result value: {}. Must be 'ok' or 'nok'", result),
response_sender,
NativeTaskError::PumpxApiError(PumpxApiError::InvalidInput),
);
return;
}

let execution_result = match result.as_str() {
"ok" => IntentCompletedDetail::Success,
"nok" => IntentCompletedDetail::Failure,
_ => unreachable!(), // Already validated above
};

if let Some(msg) = message {
log::info!("Limit order result message for intent_id {}: {}", intent_id, msg);
}

let intent_executed_call =
parentchain_api_interface::tx().omni_account().intent_completed(
sender.to_omni_account().to_subxt_type(),
intent_id,
execution_result,
);

let tx = ctx.transaction_signer.sign(intent_executed_call).await;

if rpc_client.submit_tx(&tx).await.is_err() {
send_error(
"Failed to submit tx".to_string(),
response_sender,
NativeTaskError::InternalError,
);
ctx.transaction_signer.update_nonce().await;
return;
}

send_ok(response_sender, NativeTaskOk::PumpxNotifyLimitOrderResult);
return;
},
};

match rpc_client.submit_and_watch_tx_until(&tx, XtStatus::Finalized).await {
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/omni-executor/native-task-handler/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum NativeTaskOk {
PumpxAddWallet(AddWalletResponse),
PumpxSignLimitOrder(Vec<Vec<u8>>),
PumpxTransferWithdraw(SendTransferTxResponse),
PumpxNotifyLimitOrderResult,
}

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
Expand All @@ -46,6 +47,7 @@ pub enum PumpxApiError {
AddWalletFailed,
CreateTransferUnsignedTxFailed,
SendTransferTxFailed,
InvalidInput,
}

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/omni-executor/rpc-server/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const PUMPX_API_ERROR_CODE: i32 = -32033;
const PUMPX_API_ADD_WALLET_FAILED_CODE: i32 = -32034;
const PUMPX_API_CREATE_TRANSFER_UNSIGNED_TX_FAILED_CODE: i32 = -32035;
const PUMPX_API_SEND_TRANSFER_TX_FAILED_CODE: i32 = -32036;
const PUMPX_API_INVALID_INPUT_FAILED_CODE: i32 = -32037;

const PUMPX_SIGNER_REQUEST_SIGNATURE_FAILED_CODE: i32 = -32050;

Expand All @@ -47,6 +48,7 @@ pub fn get_native_task_error_code(error: &NativeTaskError) -> i32 {
PUMPX_API_CREATE_TRANSFER_UNSIGNED_TX_FAILED_CODE
},
PumpxApiError::SendTransferTxFailed => PUMPX_API_SEND_TRANSFER_TX_FAILED_CODE,
PumpxApiError::InvalidInput => PUMPX_API_INVALID_INPUT_FAILED_CODE,
},
NativeTaskError::PumpxSignerError(signer_error) => match signer_error {
PumpxSignerError::RequestSignatureFailed => PUMPX_SIGNER_REQUEST_SIGNATURE_FAILED_CODE,
Expand Down
4 changes: 4 additions & 0 deletions tee-worker/omni-executor/rpc-server/src/methods/pumpx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ use get_next_intent_id::*;
mod sign_limit_order;
use sign_limit_order::*;

mod notify_limit_order_result;
use notify_limit_order_result::*;

pub fn register_pumpx(module: &mut RpcModule<RpcContext>) {
register_request_jwt(module);
register_export_wallet(module);
Expand All @@ -30,4 +33,5 @@ pub fn register_pumpx(module: &mut RpcModule<RpcContext>) {
register_submit_swap_order(module);
register_get_next_intent_id(module);
register_sign_limit_order_params(module);
register_notify_limit_order_result(module);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use crate::{
error_code::*, oneshot, server::RpcContext, verify_auth::verify_auth, Decode, Deserialize,
ErrorCode,
};
use executor_core::native_task::*;
use executor_crypto::jwt;
use executor_primitives::{utils::hex::FromHexPrefixed, OmniAuth};
use heima_authentication::auth_token::AuthTokenClaims;
use heima_primitives::{Address32, Identity};
use jsonrpsee::{types::ErrorObject, RpcModule};
use native_task_handler::{NativeTaskError, NativeTaskOk, NativeTaskResponse};
use rsa::pkcs1::DecodeRsaPrivateKey;
use rsa::pkcs1::EncodeRsaPublicKey;
use rsa::RsaPrivateKey;

#[derive(Debug, Deserialize)]
pub struct NotifyLimitOrderResultParams {
pub intent_id: u32,
pub result: String,
pub message: Option<String>,
pub auth_token: String,
}

pub fn register_notify_limit_order_result(module: &mut RpcModule<RpcContext>) {
module
.register_async_method("pumpx_notifyLimitOrderResult", |params, ctx, _| async move {
let internal_error: ErrorObject = ErrorCode::InternalError.into();
let params = params.parse::<NotifyLimitOrderResultParams>()?;

let private_key = RsaPrivateKey::from_pkcs1_der(&ctx.jwt_rsa_private_key)
.map_err(|_| internal_error.clone())?;
let public_key =
private_key.to_public_key().to_pkcs1_der().map_err(|_| internal_error.clone())?;

let Ok(token) =
jwt::decode::<AuthTokenClaims>(&params.auth_token, public_key.as_bytes())
else {
return Err(ErrorCode::ServerError(AUTH_VERIFICATION_FAILED_CODE).into());
};
if token.typ != "access" {
return Err(ErrorCode::ServerError(AUTH_VERIFICATION_FAILED_CODE).into());
}

let omni_account = token.sub;
let Ok(address) = Address32::from_hex(&omni_account) else {
log::error!("Not a valid address");
return Err(internal_error);
};

let wrapper = NativeTaskWrapper {
task: NativeTask::PumpxNotifyLimitOrderResult(
Identity::Substrate(address),
params.intent_id,
params.result,
params.message,
),
nonce: None,
auth: Some(OmniAuth::AuthToken(params.auth_token)),
};

if wrapper.task.require_auth() && verify_auth(ctx.clone(), &wrapper).await.is_err() {
return Err(ErrorCode::ServerError(AUTH_VERIFICATION_FAILED_CODE).into());
}

let (response_sender, response_receiver) = oneshot::channel();

if ctx.native_task_sender.send((wrapper, response_sender)).await.is_err() {
log::error!("Failed to send request to native call executor");
return Err(ErrorCode::InternalError.into());
}

match response_receiver.await {
Ok(response) => {
let native_task_response: NativeTaskResponse =
Decode::decode(&mut response.as_slice())
.map_err(|_| internal_error.clone())?;
match native_task_response {
Ok(NativeTaskOk::PumpxNotifyLimitOrderResult) => Ok(()),
Err(NativeTaskError::InternalError) => {
log::error!("Internal error in native task");
Err(internal_error)
},
Err(native_task_error) => {
log::error!("Native task error: {:?}", native_task_error);
Err(ErrorCode::ServerError(get_native_task_error_code(
&native_task_error,
))
.into())
},
_ => {
log::error!("Unexpected response type");
Err(internal_error)
},
}
},
Err(e) => {
log::error!("Failed to receive response from native call handler: {:?}", e);
Err(internal_error)
},
}
})
.expect("Failed to register pumpx_notifyLimitOrderResult method");
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ use rsa::pkcs1::EncodeRsaPublicKey;
use crate::error_code::get_native_task_error_code;
use crate::error_code::AUTH_VERIFICATION_FAILED_CODE;
use crate::server::RpcContext;
use crate::verify_auth::verify_auth;
use crate::ErrorCode;
use ethers::types::Bytes;
use executor_core::native_task::NativeTask;
use executor_core::native_task::NativeTaskTrait;
use executor_core::native_task::NativeTaskWrapper;
use executor_core::native_task::PumpxChainId;
use executor_core::native_task::PumxWalletIndex;
Expand Down Expand Up @@ -88,7 +90,7 @@ pub fn register_sign_limit_order_params(module: &mut RpcModule<RpcContext>) {
return Err(internal_error);
};

let task_wrapper = NativeTaskWrapper {
let wrapper = NativeTaskWrapper {
task: NativeTask::PumpxSignLimitOrder(
Identity::Substrate(address),
params.chain_id,
Expand All @@ -99,9 +101,13 @@ pub fn register_sign_limit_order_params(module: &mut RpcModule<RpcContext>) {
auth: Some(OmniAuth::AuthToken(params.auth_token)),
};

if wrapper.task.require_auth() && verify_auth(ctx.clone(), &wrapper).await.is_err() {
return Err(ErrorCode::ServerError(AUTH_VERIFICATION_FAILED_CODE).into());
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @kziemianek I think we missed this part in SignLimitOrder

let (response_sender, response_receiver) = oneshot::channel();

if ctx.native_task_sender.send((task_wrapper, response_sender)).await.is_err() {
if ctx.native_task_sender.send((wrapper, response_sender)).await.is_err() {
log::error!("Failed to send request to native call executor");
return Err(internal_error);
}
Expand Down