diff --git a/contracts/index_executor/Cargo.toml b/contracts/index_executor/Cargo.toml index 9b5c3abc..80b29f79 100644 --- a/contracts/index_executor/Cargo.toml +++ b/contracts/index_executor/Cargo.toml @@ -12,7 +12,7 @@ serde = { version = "=1.0.185", default-features = false, features = ["derive", dyn-clone = "1.0.10" hex-literal = "0.4.1" hex = { version = "0.4.3", default-features = false, features = ["alloc"] } -fixed = { version = "1.23.1", default-features = false, features = ["serde"] } +fixed = { version = "=1.23.1", default-features = false, features = ["serde"] } half = { version = "=2.2.1", default-features = false } ink = { version = "4.2.1", default-features = false } ink_env = { version = "4.2.1", default-features = false } diff --git a/contracts/index_executor/src/actions/acala/asset.rs b/contracts/index_executor/src/actions/acala/asset.rs index 8f6c3a4f..9a9eb19b 100644 --- a/contracts/index_executor/src/actions/acala/asset.rs +++ b/contracts/index_executor/src/actions/acala/asset.rs @@ -1,6 +1,6 @@ use crate::traits::AssetRegistry; use crate::utils::slice_to_generalkey; -use alloc::{vec, vec::Vec}; +use alloc::{collections::BTreeMap, vec::Vec}; use scale::Decode; use scale::Encode; @@ -116,7 +116,7 @@ pub type TokenAttrs = ( pub struct AcalaAssets; impl AcalaAssets { - fn get_map() -> Vec { + fn get_map() -> BTreeMap { let lc_kar: MultiLocation = MultiLocation::new(1, X2(Parachain(2000), slice_to_generalkey(&[0x00, 0x80]))); let lc_pha: MultiLocation = MultiLocation::new(1, X1(Parachain(2004))); @@ -124,19 +124,23 @@ impl AcalaAssets { MultiLocation::new(1, X2(Parachain(2000), slice_to_generalkey(&[0x00, 0x00]))); let lc_dot: MultiLocation = MultiLocation::new(1, X2(Parachain(2000), slice_to_generalkey(&[0x00, 0x02]))); - vec![ - (lc_aca, TokenSymbol::ACA, TokenType::Utility, None), - (lc_dot, TokenSymbol::DOT, TokenType::Native, None), - (lc_kar, TokenSymbol::KAR, TokenType::Native, None), - (lc_pha, TokenSymbol::PHA, TokenType::Foreign, Some(FA_PHA)), - ] + BTreeMap::from([ + (lc_aca, (lc_aca, TokenSymbol::ACA, TokenType::Utility, None)), + (lc_dot, (lc_dot, TokenSymbol::DOT, TokenType::Native, None)), + (lc_kar, (lc_kar, TokenSymbol::KAR, TokenType::Native, None)), + ( + lc_pha, + (lc_pha, TokenSymbol::PHA, TokenType::Foreign, Some(FA_PHA)), + ), + ]) } pub fn get_asset_attrs( location: &MultiLocation, ) -> Option<(TokenSymbol, TokenType, Option)> { let tokens = AcalaAssets::get_map(); - let token = tokens.iter().find(|s| s.0 == *location); + let token = tokens.get(location); + // let token = tokens.iter().find(|s| s.0 == *location); if let Some(token) = token { return Some((token.1, token.2, token.3)); } diff --git a/contracts/index_executor/src/actions/astar/mod.rs b/contracts/index_executor/src/actions/astar/mod.rs index 7b91d96b..7d785919 100644 --- a/contracts/index_executor/src/actions/astar/mod.rs +++ b/contracts/index_executor/src/actions/astar/mod.rs @@ -7,13 +7,11 @@ pub type AstarArthSwap = uniswapv2::UniswapV2; use crate::call::CallBuilder; use crate::chain::Chain; -use crate::utils::ToArray; use alloc::{boxed::Box, string::String, vec, vec::Vec}; pub fn evm_create_actions(chain: &Chain) -> Vec<(String, Box)> { - let arthswap_pancake_router: [u8; 20] = hex::decode("E915D2393a08a00c5A463053edD31bAe2199b9e7") - .unwrap() - .to_array(); + let arthswap_pancake_router: [u8; 20] = + hex_literal::hex!("E915D2393a08a00c5A463053edD31bAe2199b9e7"); vec![( String::from("astar_evm_arthswap"), Box::new(AstarArthSwap::new( diff --git a/contracts/index_executor/src/actions/ethereum/mod.rs b/contracts/index_executor/src/actions/ethereum/mod.rs index 2ffde615..5cd379ee 100644 --- a/contracts/index_executor/src/actions/ethereum/mod.rs +++ b/contracts/index_executor/src/actions/ethereum/mod.rs @@ -4,12 +4,9 @@ pub type EthereumUniswapV2 = uniswapv2::UniswapV2; use crate::call::CallBuilder; use crate::chain::Chain; -use crate::utils::ToArray; pub fn create_actions(chain: &Chain) -> Vec<(String, Box)> { - let uniswapv2_router: [u8; 20] = hex::decode("7a250d5630B4cF539739dF2C5dAcb4c659F2488D") - .unwrap() - .to_array(); + let uniswapv2_router: [u8; 20] = hex_literal::hex!("7a250d5630B4cF539739dF2C5dAcb4c659F2488D"); vec![( String::from("ethereum_uniswapv2"), diff --git a/contracts/index_executor/src/actions/moonbeam/mod.rs b/contracts/index_executor/src/actions/moonbeam/mod.rs index 954f095d..2ef43342 100644 --- a/contracts/index_executor/src/actions/moonbeam/mod.rs +++ b/contracts/index_executor/src/actions/moonbeam/mod.rs @@ -7,13 +7,10 @@ pub type MoonbeamStellaSwap = uniswapv2::UniswapV2; use crate::call::CallBuilder; use crate::chain::Chain; use crate::constants::*; -use crate::utils::ToArray; use alloc::{boxed::Box, string::String, vec, vec::Vec}; pub fn create_actions(chain: &Chain) -> Vec<(String, Box)> { - let stellaswap_router: [u8; 20] = hex::decode("70085a09D30D6f8C4ecF6eE10120d1847383BB57") - .unwrap() - .to_array(); + let stellaswap_router: [u8; 20] = hex_literal::hex!("70085a09D30D6f8C4ecF6eE10120d1847383BB57"); let moonbeam_xtoken: [u8; 20] = hex_literal::hex!("0000000000000000000000000000000000000804"); vec![ diff --git a/contracts/index_executor/src/call.rs b/contracts/index_executor/src/call.rs index ae28bbaa..0a5c093f 100644 --- a/contracts/index_executor/src/call.rs +++ b/contracts/index_executor/src/call.rs @@ -64,26 +64,24 @@ impl Tokenizable for Call { } fn into_token(self) -> Token { - let mut tokens: Vec = vec![]; match (self.params, self.input_call, self.call_index) { - (CallParams::Evm(evm_call), Some(input_call), Some(call_index)) => { - tokens.push(evm_call.target.into_token()); - tokens.push(Bytes(evm_call.calldata).into_token()); - tokens.push(evm_call.value.into_token()); - tokens.push(evm_call.need_settle.into_token()); - tokens.push(evm_call.update_offset.into_token()); - tokens.push(evm_call.update_len.into_token()); - tokens.push(evm_call.spend_asset.into_token()); - tokens.push(evm_call.spend_amount.into_token()); - tokens.push(evm_call.receive_asset.into_token()); - tokens.push(U256::from(input_call).into_token()); - tokens.push(U256::from(call_index).into_token()); - } + (CallParams::Evm(evm_call), Some(input_call), Some(call_index)) => Token::Tuple(vec![ + evm_call.target.into_token(), + Bytes(evm_call.calldata).into_token(), + evm_call.value.into_token(), + evm_call.need_settle.into_token(), + evm_call.update_offset.into_token(), + evm_call.update_len.into_token(), + evm_call.spend_asset.into_token(), + evm_call.spend_amount.into_token(), + evm_call.receive_asset.into_token(), + U256::from(input_call).into_token(), + U256::from(call_index).into_token(), + ]), _ => { return Token::Tuple(vec![]); } } - Token::Tuple(tokens) } } diff --git a/contracts/index_executor/src/chain.rs b/contracts/index_executor/src/chain.rs index effa4593..92194cb0 100644 --- a/contracts/index_executor/src/chain.rs +++ b/contracts/index_executor/src/chain.rs @@ -120,8 +120,8 @@ impl BalanceFetcher for Chain { if self.is_native(&asset) { let web3 = Web3::new(transport); let balance = resolve_ready(web3.eth().balance(evm_account, None)) - .log_err("Fetch data [evm native balance] failed") - .map_err(|_| "FetchDataFailed")?; + .log_err("chain::get_balance: fetch data [evm native balance] failed") + .or(Err("FetchDataFailed"))?; balance.try_into().map_err(|_| "BalanceOverflow") } else { let eth = Eth::new(transport); @@ -138,8 +138,8 @@ impl BalanceFetcher for Chain { Options::default(), None, )) - .log_err("Fetch data [evm erc20 balance] failed") - .map_err(|_| "FetchDataFailed")?; + .log_err("chain::get_balance: fetch data [evm erc20 balance] failed") + .or(Err("FetchDataFailed"))?; balance.try_into().map_err(|_| "BalanceOverflow") } } @@ -154,13 +154,13 @@ impl BalanceFetcher for Chain { ), None, ) - .log_err("Read storage [sub native balance] failed") - .map_err(|_| "FetchDataFailed")? + .log_err("chain::get_balance, read storage [sub native balance] failed") + .or(Err("FetchDataFailed"))? { let account_info: AccountInfo> = scale::Decode::decode(&mut raw_storage.as_slice()) - .log_err("Decode storage [sub native balance] failed") - .map_err(|_| "DecodeStorageFailed")?; + .log_err("chain::get_balance, decode storage [sub native balance] failed") + .or(Err("DecodeStorageFailed"))?; Ok(account_info.data.free) } else { Ok(0u128) @@ -186,14 +186,14 @@ impl BalanceFetcher for Chain { None, ) .log_err( - "Read storage [sub foreign asset balance] from pallet-asset failed", + "chain::get_balance: read storage [sub foreign asset balance] from pallet-asset failed", ) - .map_err(|_| "FetchDataFailed")? + .or(Err("FetchDataFailed"))? { let account_info: AssetAccount = scale::Decode::decode(&mut raw_storage.as_slice()) - .log_err("Decode storage [sub foreign asset balance] from pallet-asset failed") - .map_err(|_| "DecodeStorageFailed")?; + .log_err("chain::get_balance: decode storage [sub foreign asset balance] from pallet-asset failed") + .or(Err("DecodeStorageFailed"))?; Ok(account_info.balance) } else { Ok(0u128) @@ -214,14 +214,14 @@ impl BalanceFetcher for Chain { None, ) .log_err( - "Read storage [sub foreign asset balance] from orml-token failed", + "chain::get_balance: read storage [sub foreign asset balance] from orml-token failed", ) - .map_err(|_| "FetchDataFailed")? + .or(Err("FetchDataFailed"))? { let account_info: OrmlTokenAccountData = scale::Decode::decode(&mut raw_storage.as_slice()) - .log_err("Decode storage [sub foreign asset balance] from orml-token failed") - .map_err(|_| "DecodeStorageFailed")?; + .log_err("chain::get_balance: decode storage [sub foreign asset balance] from orml-token failed") + .or(Err("DecodeStorageFailed"))?; Ok(account_info.free) } else { Ok(0u128) diff --git a/contracts/index_executor/src/constants.rs b/contracts/index_executor/src/constants.rs index e88e056e..26853db5 100644 --- a/contracts/index_executor/src/constants.rs +++ b/contracts/index_executor/src/constants.rs @@ -14,3 +14,5 @@ pub const PHALA_PARACHAIN_ID: u32 = 2035; pub const KHALA_PARACHAIN_ID: u32 = 2004; #[allow(dead_code)] pub const MOONRIVER_PARACHAIN_ID: u32 = 2023; + +pub const HANDLER_ABI: &[u8] = include_bytes!("./abi/handler.json"); diff --git a/contracts/index_executor/src/gov.rs b/contracts/index_executor/src/gov.rs index 8df5b878..855b41f5 100644 --- a/contracts/index_executor/src/gov.rs +++ b/contracts/index_executor/src/gov.rs @@ -21,7 +21,7 @@ impl WorkerGov { ) -> Result, &'static str> { let transport = Eth::new(PinkHttp::new(endpoint)); let handler_contract = - Contract::from_json(transport, handler, include_bytes!("./abi/handler.json")) + Contract::from_json(transport, handler, crate::constants::HANDLER_ABI) .or(Err("ConstructContractFailed"))?; let worker = KeyPair::from(worker_key); @@ -33,7 +33,7 @@ impl WorkerGov { )) .or(Err("GasEstimateFailed"))?; - // Submit the `approve` transaction + // Submit the `drop` transaction let tx_id = resolve_ready(handler_contract.signed_call( "drop", id, diff --git a/contracts/index_executor/src/lib.rs b/contracts/index_executor/src/lib.rs index 7d6e0e8d..f8b99955 100644 --- a/contracts/index_executor/src/lib.rs +++ b/contracts/index_executor/src/lib.rs @@ -128,7 +128,7 @@ mod index_executor { Ok(()) } - /// Debug only, remove before release + /// TODO: Debug only, remove before release #[ink(message)] pub fn export_worker_keys(&self) -> Result> { self.ensure_owner()?; diff --git a/contracts/index_executor/src/registry.rs b/contracts/index_executor/src/registry.rs index c0e540d5..ff456fda 100644 --- a/contracts/index_executor/src/registry.rs +++ b/contracts/index_executor/src/registry.rs @@ -34,11 +34,11 @@ impl Registry { endpoint: "https://mainnet.infura.io/v3/6d61e7957c1c489ea8141e947447405b" .to_string(), chain_type: ChainType::Evm, - native_asset: hex::decode("0000000000000000000000000000000000000000") - .expect("InvalidLocation"), + native_asset: hex_literal::hex!("0000000000000000000000000000000000000000") + .to_vec(), foreign_asset: None, - handler_contract: hex::decode("F9eaE3Ec6BFE94F510eb3a5de8Ac9dEB9E74DF39") - .expect("InvalidLocation"), + handler_contract: hex_literal::hex!("F9eaE3Ec6BFE94F510eb3a5de8Ac9dEB9E74DF39") + .to_vec(), tx_indexer_url: "null".to_string(), }, Chain { @@ -46,11 +46,11 @@ impl Registry { name: "Moonbeam".to_string(), endpoint: "https://moonbeam.api.onfinality.io/public".to_string(), chain_type: ChainType::Evm, - native_asset: hex::decode("0000000000000000000000000000000000000000") - .expect("InvalidLocation"), + native_asset: hex_literal::hex!("0000000000000000000000000000000000000000") + .to_vec(), foreign_asset: None, - handler_contract: hex::decode("635eA86804200F80C16ea8EdDc3c749a54a9C37D") - .expect("InvalidLocation"), + handler_contract: hex_literal::hex!("635eA86804200F80C16ea8EdDc3c749a54a9C37D") + .to_vec(), tx_indexer_url: "https://squid.subsquid.io/graph-moonbeam/graphql".to_string(), }, Chain { @@ -58,11 +58,11 @@ impl Registry { name: "AstarEvm".to_string(), endpoint: "https://astar.public.blastapi.io".to_string(), chain_type: ChainType::Evm, - native_asset: hex::decode("0000000000000000000000000000000000000000") - .expect("InvalidLocation"), + native_asset: hex_literal::hex!("0000000000000000000000000000000000000000") + .to_vec(), foreign_asset: None, - handler_contract: hex::decode("B376b0Ee6d8202721838e76376e81eEc0e2FE864") - .expect("InvalidLocation"), + handler_contract: hex_literal::hex!("B376b0Ee6d8202721838e76376e81eEc0e2FE864") + .to_vec(), tx_indexer_url: "https://squid.subsquid.io/graph-astar/graphql".to_string(), }, Chain { diff --git a/contracts/index_executor/src/step.rs b/contracts/index_executor/src/step.rs index 23d4d5b9..a786a1f0 100644 --- a/contracts/index_executor/src/step.rs +++ b/contracts/index_executor/src/step.rs @@ -1,7 +1,7 @@ use crate::chain::{BalanceFetcher, Chain, ChainType}; use crate::utils::ToArray; -use alloc::vec; -use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec}; +use alloc::{borrow::ToOwned, boxed::Box, format, string::String, vec, vec::Vec}; +use pink_extension::ResultExt; use pink_subrpc::{create_transaction_with_calldata, send_transaction, ExtraParam}; use crate::account::AccountInfo; @@ -123,7 +123,7 @@ impl Step { return Err("InvalidAddressInStep"); } - hex::decode(&address[2..]).map_err(|_| "DecodeAddressFailed") + hex::decode(&address[2..]).or(Err("DecodeAddressFailed")) } } @@ -315,7 +315,7 @@ impl Runner for MultiStep { let handler = Contract::from_json( Eth::new(PinkHttp::new(chain.endpoint)), chain.handler_contract.to_array().into(), - include_bytes!("./abi/handler.json"), + crate::constants::HANDLER_ABI, ) .expect("Bad abi data"); @@ -326,10 +326,11 @@ impl Runner for MultiStep { worker_account.account20.into(), Options::default(), )) - .map_err(|e| { - pink_extension::error!("Failed to estimated step gas cost with error: {:?}", e); - "FailedToEstimateGas" - })?; + .log_err(&format!( + "Step.run: failed to estimated step gas cost with calls: {:?}", + &calls + )) + .or(Err("FailedToEstimateGas"))?; pink_extension::debug!("Estimated step gas error: {:?}", gas); // Actually submit the tx (no guarantee for success) @@ -342,13 +343,11 @@ impl Runner for MultiStep { }), KeyPair::from(signer), )) - .map_err(|e| { - pink_extension::error!( - "Failed to submit step execution tx with error: {:?}", - e - ); - "FailedToSubmitTransaction" - })?; + .log_err(&format!( + "Step.run: failed to submit tx with nonce: {:?}", + &nonce + )) + .or(Err("FailedToSubmitTransaction"))?; tx_id.as_bytes().to_owned() } @@ -365,21 +364,18 @@ impl Runner for MultiStep { era: None, }, ) - .map_err(|e| { - pink_extension::error!( - "Failed to construct substrate tx with error: {:?}", - e - ); - "FailedToCreateTransaction" - })?; - - send_transaction(&chain.endpoint, &signed_tx).map_err(|e| { - pink_extension::error!( - "Failed to submit step execution tx with error: {:?}", - e - ); - "FailedToSubmitTransaction" - })? + .log_err(&format!( + "Step.run: failed to create transaction with nonce: {:?}", + hex::encode(&calldata) + )) + .or(Err("FailedToCreateTransaction"))?; + + send_transaction(&chain.endpoint, &signed_tx) + .log_err(&format!( + "Step.run: failed to submit step execution tx with signed tx: {:?}", + &signed_tx + )) + .or(Err("FailedToSubmitTransaction"))? } _ => return Err("UnexpectedCallType"), }, diff --git a/contracts/index_executor/src/storage.rs b/contracts/index_executor/src/storage.rs index 847ff973..64da91c9 100644 --- a/contracts/index_executor/src/storage.rs +++ b/contracts/index_executor/src/storage.rs @@ -4,7 +4,7 @@ use alloc::{ vec, vec::Vec, }; -use pink_extension::http_req; +use pink_extension::{http_req, ResultExt}; use scale::Decode; use serde::Deserialize; @@ -125,9 +125,12 @@ impl StorageClient { if let Ok(response) = pink_json::from_slice::>(&response_body) { Ok(if !response.is_empty() { let data_str = response[0].document.fields.data.string_value.clone(); - let raw_data = hex::decode(data_str).map_err(|_| "InvalidDataStr")?; - let data: T = - T::decode(&mut raw_data.as_slice()).map_err(|_| "DecodeDataFailed")?; + let raw_data = hex::decode(data_str) + .log_err("Get unexpected data format from database") + .or(Err("InvalidDataStr"))?; + let data: T = T::decode(&mut raw_data.as_slice()) + .log_err("Decode failed from data returned from database") + .or(Err("DecodeDataFailed"))?; let document_id = response[0] .document .name diff --git a/contracts/index_executor/src/task.rs b/contracts/index_executor/src/task.rs index fab3794c..c0038505 100644 --- a/contracts/index_executor/src/task.rs +++ b/contracts/index_executor/src/task.rs @@ -5,11 +5,10 @@ use crate::chain::{Chain, ChainType, NonceFetcher}; use crate::step::{MultiStep, Step}; use crate::storage::StorageClient; use crate::tx; -use alloc::{string::String, vec, vec::Vec}; -use ink::storage::Mapping; -use scale::{Decode, Encode}; - +use alloc::{collections::BTreeMap, format, string::String, vec, vec::Vec}; +use pink_extension::ResultExt; use pink_subrpc::{create_transaction, send_transaction, ExtraParam}; +use scale::{Decode, Encode}; use pink_web3::{ api::{Eth, Namespace}, @@ -118,17 +117,6 @@ impl Task { "Trying to lookup storage for task {:?} before initializing.", hex::encode(self.id), ); - // if client.read_storage::(&self.id)?.is_some() { - // if !(self.has_claimed(context))? { - // pink_extension::debug!( - // "Task {:?} already exist in storage, but hasn't been claimed, try claim it with worker {:?} and return.", - // hex::encode(self.id), - // hex::encode(self.worker), - // ); - // self.claim(context)?; - // } - // return Ok(()); - // } // Lookup free worker list to find if the worker we expected is free, if it's free remove it or return error if let Some(index) = free_accounts.iter().position(|&x| x == self.worker) { @@ -175,8 +163,6 @@ impl Task { pending_tasks_doc, )?; - // self.claim(context)?; - Ok(()) } @@ -420,34 +406,25 @@ impl Task { context: &Context, _client: &StorageClient, ) -> Result<(), &'static str> { - let mut nonce_map: Mapping = Mapping::default(); + let mut nonce_map: BTreeMap = BTreeMap::default(); // Apply claim nonce if hasn't claimed if self.claim_nonce.is_none() || !self.has_claimed(context)? { let claim_nonce = self.get_nonce(context, &self.source)?; - nonce_map.insert(self.source.clone(), &(claim_nonce + 1)); + nonce_map.insert(self.source.clone(), claim_nonce + 1); self.claim_nonce = Some(claim_nonce); } // Apply nonce for each step for index in start_index as usize..self.merged_steps.len() { - let nonce: u64 = - match nonce_map.get(&self.merged_steps[index].as_single_step().source_chain) { - Some(nonce) => nonce, - None => self.get_nonce( - context, - &self.merged_steps[index].as_single_step().source_chain, - )?, - }; + let source_chain = self.merged_steps[index].as_single_step().source_chain; + let nonce: u64 = match nonce_map.get(&source_chain) { + Some(nonce) => *nonce, + None => self.get_nonce(context, &source_chain)?, + }; self.merged_steps[index].set_nonce(nonce); // Increase nonce by 1 - nonce_map.insert( - self.merged_steps[index] - .as_single_step() - .source_chain - .clone(), - &(nonce + 1), - ); + nonce_map.insert(source_chain, nonce + 1); } Ok(()) @@ -461,7 +438,14 @@ impl Task { ChainType::Sub => account_info.account32.to_vec(), // ChainType::Unknown => panic!("chain not supported!"), }; - let nonce = chain.get_nonce(account).map_err(|_| "FetchNonceFailed")?; + let nonce = chain + .get_nonce(account.clone()) + .log_err(&format!( + "call task get_nonce failed on chain {:?} for account {:?}", + chain.name, + hex::encode(account) + )) + .or(Err("FetchNonceFailed"))?; Ok(nonce) } @@ -469,8 +453,7 @@ impl Task { let chain = context .registry .get_chain(&self.source) - .map(Ok) - .unwrap_or(Err("MissingChain"))?; + .ok_or("MissingChain")?; let claim_nonce = self.claim_nonce.ok_or("MissingClaimNonce")?; match chain.chain_type { @@ -488,8 +471,7 @@ impl Task { let chain = context .registry .get_chain(&self.source) - .map(Ok) - .unwrap_or(Err("MissingChain"))?; + .ok_or("MissingChain")?; let account = match chain.chain_type { ChainType::Evm => worker_account.account20.to_vec(), ChainType::Sub => worker_account.account32.to_vec(), @@ -518,8 +500,12 @@ impl Task { ) -> Result, &'static str> { let handler: H160 = H160::from_slice(&chain.handler_contract); let transport = Eth::new(PinkHttp::new(chain.endpoint)); - let handler = Contract::from_json(transport, handler, include_bytes!("./abi/handler.json")) - .map_err(|_| "ConstructContractFailed")?; + let handler = Contract::from_json(transport, handler, crate::constants::HANDLER_ABI) + .log_err(&format!( + "claim_evm_actived_tasks: failed to instatiate handler {:?} on {:?}", + handler, &chain.name + )) + .or(Err("ConstructContractFailed"))?; let worker = KeyPair::from(context.signer); // We call claimAndBatchCall so that first step will be executed along with the claim operation @@ -536,13 +522,11 @@ impl Task { worker.address(), Options::default(), )) - .map_err(|e| { - pink_extension::error!( - "claimAndBatchCall: failed to estimate gas cost with error {:?}", - &e - ); - "GasEstimateFailed" - })?; + .log_err(&format!( + "claim_evm_actived_tasks: failed to estimate gas cost with params: {:?}", + ¶ms + )) + .or(Err("GasEstimateFailed"))?; // Submit the claim transaction let tx_id = resolve_ready(handler.signed_call( @@ -554,10 +538,11 @@ impl Task { }), worker, )) - .map_err(|e| { - pink_extension::error!("claimAndBatchCall: failed to submit tx with error {:?}", &e); - "ClaimSubmitFailed" - })?; + .log_err(&format!( + "claim_evm_actived_tasks: failed to submit tx with nonce: {:?}", + &nonce + )) + .or(Err("ClaimSubmitFailed"))?; // Merge nonce to let check for first step work properly first_step.set_nonce(self.claim_nonce.unwrap()); @@ -596,9 +581,11 @@ impl Task { era: None, }, ) - .map_err(|_| "ClaimInvalidSignature")?; - let tx_id = - send_transaction(&chain.endpoint, &signed_tx).map_err(|_| "ClaimSubmitFailed")?; + .log_err("claim_sub_actived_tasks: failed to create signed transaction") + .or(Err("ClaimInvalidSignature"))?; + let tx_id = send_transaction(&chain.endpoint, &signed_tx) + .log_err("claim_sub_actived_tasks: failed to submit transaction to execute task claim") + .or(Err("ClaimSubmitFailed"))?; pink_extension::info!( "Submit transaction to claim task {:?} on ${:?}, tx id: {:?}", hex::encode(task_id), @@ -1386,7 +1373,7 @@ mod tests { H160::from_slice(&hex::decode("B30A27eE79514614dc363CE0aABb0B939b9deAeD").unwrap()); let transport = Eth::new(PinkHttp::new("https://rpc.api.moonbeam.network")); let handler = - Contract::from_json(transport, handler, include_bytes!("./abi/handler.json")).unwrap(); + Contract::from_json(transport, handler, crate::constants::HANDLER_ABI).unwrap(); let task_id: [u8; 32] = hex::decode("1125000000000000000000000000000000000000000000000000000000000000") .unwrap() diff --git a/contracts/index_executor/src/task_deposit.rs b/contracts/index_executor/src/task_deposit.rs index 069ef366..ae22981c 100644 --- a/contracts/index_executor/src/task_deposit.rs +++ b/contracts/index_executor/src/task_deposit.rs @@ -23,38 +23,38 @@ impl Detokenize for EvmDepositData { where Self: Sized, { - if tokens.len() == 1 { - let deposit_raw = tokens[0].clone(); - match deposit_raw { - Token::Tuple(deposit_data) => { - match ( - deposit_data[0].clone(), - deposit_data[2].clone(), - deposit_data[3].clone(), - deposit_data[4].clone(), - ) { - ( - Token::Address(sender), - Token::Uint(amount), - Token::Bytes(recipient), - Token::String(task), - ) => Ok(EvmDepositData { - sender, - amount, - recipient, - task, - }), - _ => Err(PinkError::InvalidOutputType(String::from( - "Return type dismatch", - ))), - } + if tokens.len() != 1 { + return Err(PinkError::InvalidOutputType(String::from("Invalid length"))); + } + + let deposit_raw = tokens[0].clone(); + match deposit_raw { + Token::Tuple(deposit_data) => { + match ( + deposit_data[0].clone(), + deposit_data[2].clone(), + deposit_data[3].clone(), + deposit_data[4].clone(), + ) { + ( + Token::Address(sender), + Token::Uint(amount), + Token::Bytes(recipient), + Token::String(task), + ) => Ok(EvmDepositData { + sender, + amount, + recipient, + task, + }), + _ => Err(PinkError::InvalidOutputType(String::from( + "Return type dismatch", + ))), } - _ => Err(PinkError::InvalidOutputType(String::from( - "Unexpected output type", - ))), } - } else { - Err(PinkError::InvalidOutputType(String::from("Invalid length"))) + _ => Err(PinkError::InvalidOutputType(String::from( + "Unexpected output type", + ))), } } } diff --git a/contracts/index_executor/src/task_fetcher.rs b/contracts/index_executor/src/task_fetcher.rs index 3f140894..2f7b4582 100644 --- a/contracts/index_executor/src/task_fetcher.rs +++ b/contracts/index_executor/src/task_fetcher.rs @@ -2,7 +2,7 @@ use crate::account::AccountInfo; use crate::chain::{Chain, ChainType}; use crate::task::Task; use crate::task_deposit::{DepositData, EvmDepositData, SubDepositData}; -use alloc::vec::Vec; +use alloc::{format, vec::Vec}; use pink_extension::ResultExt; use pink_subrpc::{ get_storage, @@ -43,14 +43,14 @@ impl ActivedTaskFetcher { chain: &Chain, worker: &AccountInfo, ) -> Result, &'static str> { - let handler_on_goerli: H160 = H160::from_slice(&chain.handler_contract); + let handler: H160 = H160::from_slice(&chain.handler_contract); let transport = Eth::new(PinkHttp::new(&chain.endpoint)); - let handler = Contract::from_json( - transport, - handler_on_goerli, - include_bytes!("./abi/handler.json"), - ) - .map_err(|_| "ConstructContractFailed")?; + let handler = Contract::from_json(transport, handler, crate::constants::HANDLER_ABI) + .log_err(&format!( + "query_evm_actived_task: failed to instantiate handler {:?} on {:?}", + handler, &chain.name + )) + .or(Err("ConstructContractFailed"))?; let worker_address: Address = worker.account20.into(); pink_extension::debug!( @@ -66,7 +66,11 @@ impl ActivedTaskFetcher { Options::default(), None, )) - .map_err(|_| "FailedGetLastActivedTask")?; + .log_err(&format!( + "query_evm_actived_task: failed to get last actived task for worker {:?}", + worker_address + )) + .or(Err("FailedGetLastActivedTask"))?; if task_id == [0; 32] { return Ok(None); } @@ -76,7 +80,11 @@ impl ActivedTaskFetcher { ); let evm_deposit_data: EvmDepositData = resolve_ready(handler.query("getTaskData", task_id, None, Options::default(), None)) - .map_err(|_| "FailedGetTaskData")?; + .log_err(&format!( + "query_evm_actived_task: failed to get task data of task id: {:?}", + hex::encode(task_id) + )) + .or(Err("FailedGetTaskData"))?; pink_extension::debug!( "Fetch deposit data successfully for task {:?} on {:?}, deposit data: {:?}", &hex::encode(task_id), @@ -101,12 +109,15 @@ impl ActivedTaskFetcher { ), None, ) - .log_err("Read storage [actived task] failed") - .map_err(|_| "FailedGetTaskData")? + .log_err(&format!( + "query_sub_actived_task: get actived task failed on chain {:?}", + &chain.name + )) + .or(Err("FailedGetTaskData"))? { let actived_tasks: Vec<[u8; 32]> = scale::Decode::decode(&mut raw_storage.as_slice()) - .log_err("Decode storage [actived task] failed") - .map_err(|_| "DecodeStorageFailed")?; + .log_err("query_sub_actived_task: decode storage [actived task] failed") + .or(Err("DecodeStorageFailed"))?; if !actived_tasks.is_empty() { let oldest_task = actived_tasks[0]; if let Some(raw_storage) = get_storage( @@ -117,13 +128,16 @@ impl ActivedTaskFetcher { ), None, ) - .log_err("Read storage [actived task] failed") - .map_err(|_| "FailedGetDepositData")? + .log_err(&format!( + "query_sub_actived_task: failed to get task data for task id {:?}", + hex::encode(&oldest_task) + )) + .or(Err("FailedGetDepositData"))? { let sub_deposit_data: SubDepositData = scale::Decode::decode(&mut raw_storage.as_slice()) - .log_err("Decode storage [deposit data] failed") - .map_err(|_| "DecodeStorageFailed")?; + .log_err("query_sub_actived_task: decode storage [deposit data] failed") + .or(Err("DecodeStorageFailed"))?; pink_extension::debug!( "Fetch deposit data successfully for task {:?} on {:?}, deposit data: {:?}", &hex::encode(oldest_task), diff --git a/scripts/src/ERC20ABI.json b/scripts/src/ERC20ABI.json deleted file mode 100644 index f7f06ce2..00000000 --- a/scripts/src/ERC20ABI.json +++ /dev/null @@ -1,663 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "string", - "name": "name", - "type": "string" - }, - { - "internalType": "string", - "name": "symbol", - "type": "string" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "previousAdminRole", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "newAdminRole", - "type": "bytes32" - } - ], - "name": "RoleAdminChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "RoleGranted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "RoleRevoked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "inputs": [], - "name": "DEFAULT_ADMIN_ROLE", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "MINTER_ROLE", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "PAUSER_ROLE", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "burn", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "burnFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "decimals", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - } - ], - "name": "getRoleAdmin", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "getRoleMember", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - } - ], - "name": "getRoleMemberCount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasRole", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "addedValue", - "type": "uint256" - } - ], - "name": "increaseAllowance", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "renounceRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] \ No newline at end of file diff --git a/scripts/src/HandlerABI.json b/scripts/src/HandlerABI.json deleted file mode 100644 index e20e620f..00000000 --- a/scripts/src/HandlerABI.json +++ /dev/null @@ -1,657 +0,0 @@ -[ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "worker", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "Claimed", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "worker", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "ClaimedAndExecuted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "recipient", - "type": "bytes" - }, - { - "indexed": false, - "internalType": "string", - "name": "task", - "type": "string" - } - ], - "name": "Deposited", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "worker", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "Dropped", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "_activedTasks", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "_depositRecords", - "outputs": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "contract IERC20", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "recipient", - "type": "bytes" - }, - { - "internalType": "string", - "name": "task", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "_workers", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "target", - "type": "address" - }, - { - "internalType": "bytes", - "name": "callData", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "needSettle", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "updateOffset", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "updateLen", - "type": "uint256" - }, - { - "internalType": "address", - "name": "spendAsset", - "type": "address" - }, - { - "internalType": "uint256", - "name": "spendAmount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "receiveAsset", - "type": "address" - }, - { - "internalType": "uint256", - "name": "inputCall", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "callIndex", - "type": "uint256" - } - ], - "internalType": "struct Handler.Call[]", - "name": "calls", - "type": "tuple[]" - } - ], - "name": "batchCall", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "claim", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "address", - "name": "target", - "type": "address" - }, - { - "internalType": "bytes", - "name": "callData", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "needSettle", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "updateOffset", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "updateLen", - "type": "uint256" - }, - { - "internalType": "address", - "name": "spendAsset", - "type": "address" - }, - { - "internalType": "uint256", - "name": "spendAmount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "receiveAsset", - "type": "address" - }, - { - "internalType": "uint256", - "name": "inputCall", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "callIndex", - "type": "uint256" - } - ], - "internalType": "struct Handler.Call[]", - "name": "calls", - "type": "tuple[]" - } - ], - "name": "claimAndBatchCall", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "recipient", - "type": "bytes" - }, - { - "internalType": "address", - "name": "worker", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "task", - "type": "string" - } - ], - "name": "deposit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "drop", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "worker", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "findActivedTask", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "contract IERC20", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "recipient", - "type": "bytes" - }, - { - "internalType": "string", - "name": "task", - "type": "string" - } - ], - "internalType": "struct Handler.DepositInfo", - "name": "depositInfo", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "worker", - "type": "address" - } - ], - "name": "getActivedTasks", - "outputs": [ - { - "internalType": "bytes32[]", - "name": "", - "type": "bytes32[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "worker", - "type": "address" - } - ], - "name": "getLastActivedTask", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "taskId", - "type": "bytes32" - } - ], - "name": "getTaskData", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "contract IERC20", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "recipient", - "type": "bytes" - }, - { - "internalType": "string", - "name": "task", - "type": "string" - } - ], - "internalType": "struct Handler.DepositInfo", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "worker", - "type": "address" - } - ], - "name": "removeWorker", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "workers", - "type": "address[]" - } - ], - "name": "setMultiWorkers", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "worker", - "type": "address" - } - ], - "name": "setWorker", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] \ No newline at end of file diff --git a/scripts/src/console.js b/scripts/src/console.js index b7db1dea..4b96c989 100644 --- a/scripts/src/console.js +++ b/scripts/src/console.js @@ -14,8 +14,8 @@ const PhalaSDKTypes = PhalaSdk.types const KhalaTypes = require('@phala/typedefs').khalaDev const { loadContractFile, createContract, delay } = require('./utils'); -const ERC20ABI = require('./ERC20ABI.json') -const HandlerABI = require('./HandlerABI.json') +const ERC20ABI = require('../../contracts/index_executor/src/abi/erc20.json') +const HandlerABI = require('../../contracts/index_executor/src/abi//handler.json') function run(afn) { function runner(...args) {