From dfefb715f605c186b1954fef3c08c374c639ae32 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Thu, 23 May 2024 12:47:14 +0200 Subject: [PATCH] working on wrapper call --- crates/erc20_payment_lib/config-payments.toml | 4 +- .../contracts/wrapper_call.json | 112 +++++++++--------- crates/erc20_payment_lib/src/contracts.rs | 29 +++-- crates/erc20_payment_lib/src/eth.rs | 1 + 4 files changed, 73 insertions(+), 73 deletions(-) diff --git a/crates/erc20_payment_lib/config-payments.toml b/crates/erc20_payment_lib/config-payments.toml index 5b8e9a9a..9939b1ca 100644 --- a/crates/erc20_payment_lib/config-payments.toml +++ b/crates/erc20_payment_lib/config-payments.toml @@ -212,7 +212,7 @@ currency-symbol = "tETH" priority-fee = 0.000001 max-fee-per-gas = 20.0 transaction-timeout = 100 -wrapper-contract = { address = "0x9a553Ee4497765Ee1EE47091354B9cd58620E481" } +wrapper-contract = { address = "0xE168bCa171ccf51066E2106d8955BF22705a6905" } token = { address = "0x8888888815bf4DB87e57B609A50f938311EEd068", symbol = "tGLM" } multi-contract = { address = "0xAaAAAaA00E1841A63342db7188abA84BDeE236c7", max-at-once = 10 } mint-contract = { address = "0xFACe100969FF47EB58d2CF603321B581A84bcEaC", max-glm-allowed = 400 } @@ -309,7 +309,7 @@ priority-fee = 30.111 max-fee-per-gas = 500.0 transaction-timeout = 100 token = { address = "0x0B220b82F3eA3B7F6d9A1D8ab58930C064A2b5Bf", symbol = "GLM" } -wrapper-contract = { address = "0x229727AcEE595CB3e0de042E7d5A7370EdED8f89" } +wrapper-contract = { address = "0xbB6aad747990BB6F7f56851556A3277e474C656a" } lock-contract = { address = "0x633193F5524849C84368ADF39aFDB0EedFAf8B29" } multi-contract = { address = "0x50100d4faf5f3b09987dea36dc2eddd57a3e561b", max-at-once = 10 } attestation-contract = { address = "0x5E634ef5355f45A855d02D66eCD687b1502AF790" } diff --git a/crates/erc20_payment_lib/contracts/wrapper_call.json b/crates/erc20_payment_lib/contracts/wrapper_call.json index 3200fcab..4ddfb449 100644 --- a/crates/erc20_payment_lib/contracts/wrapper_call.json +++ b/crates/erc20_payment_lib/contracts/wrapper_call.json @@ -1,9 +1,4 @@ [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, { "inputs": [ { @@ -22,29 +17,32 @@ { "components": [ { - "components": [ - { - "internalType": "uint256", - "name": "number", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "internalType": "struct BlockDetails", - "name": "details", - "type": "tuple" + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "callerBalance", + "type": "uint256" }, { "internalType": "bytes", - "name": "result", + "name": "callResult", "type": "bytes" } ], - "internalType": "struct CallWithDetailsResult", + "internalType": "struct WrapperCall.CallWithDetailsResult", "name": "", "type": "tuple" } @@ -53,28 +51,21 @@ "type": "function" }, { - "inputs": [], - "name": "detailsOnly", - "outputs": [ + "inputs": [ { - "components": [ - { - "internalType": "uint256", - "name": "number", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "internalType": "struct BlockDetails", - "name": "", - "type": "tuple" + "internalType": "address[]", + "name": "externalContractAddresses", + "type": "address[]" + }, + { + "internalType": "bytes[]", + "name": "callDataArray", + "type": "bytes[]" } ], - "stateMutability": "view", + "name": "multiCall", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { @@ -86,7 +77,7 @@ }, { "internalType": "bytes[]", - "name": "callDatas", + "name": "callDataArray", "type": "bytes[]" } ], @@ -95,29 +86,32 @@ { "components": [ { - "components": [ - { - "internalType": "uint256", - "name": "number", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "internalType": "struct BlockDetails", - "name": "details", - "type": "tuple" + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "callerBalance", + "type": "uint256" }, { "internalType": "bytes[]", - "name": "results", + "name": "callResults", "type": "bytes[]" } ], - "internalType": "struct MultiCallWithDetailsResult", + "internalType": "struct WrapperCall.MultiCallWithDetailsResult", "name": "", "type": "tuple" } diff --git a/crates/erc20_payment_lib/src/contracts.rs b/crates/erc20_payment_lib/src/contracts.rs index f98741a6..e885b589 100644 --- a/crates/erc20_payment_lib/src/contracts.rs +++ b/crates/erc20_payment_lib/src/contracts.rs @@ -102,35 +102,40 @@ pub fn encode_erc20_allowance( uint256 basefee; */ #[derive(Debug, Clone)] -pub struct CallWithDetailsBlockInfo { +pub struct CallWithDetails { + pub chain_id: u64, + pub eth_balance: U256, pub block_number: u64, pub block_datetime: DateTime, } pub fn decode_call_with_details( bytes: &[u8], -) -> Result<(crate::contracts::CallWithDetailsBlockInfo, Vec), PaymentError> { +) -> Result<(crate::contracts::CallWithDetails, Vec), PaymentError> { let decoded = ethabi::decode( &[ethabi::ParamType::Tuple(vec![ - ethabi::ParamType::Tuple(vec![ - ethabi::ParamType::Uint(256), - ethabi::ParamType::Uint(256), - ]), + ethabi::ParamType::Uint(256), + ethabi::ParamType::Uint(256), + ethabi::ParamType::Uint(256), + ethabi::ParamType::Uint(256), ethabi::ParamType::Bytes, ])], bytes, ) .map_err(|err| err_custom_create!("Failed to decode call with details: {}", err))?; - let tuple_main = decoded[0].clone().into_tuple().unwrap(); - let tuple_block_info = tuple_main[0].clone().into_tuple().unwrap(); + let tuple = decoded[0].clone().into_tuple().unwrap(); - let number: U256 = tuple_block_info[0].clone().into_uint().unwrap(); - let timestamp: U256 = tuple_block_info[1].clone().into_uint().unwrap(); + let chain_id: U256 = tuple[0].clone().into_uint().unwrap(); + let number: U256 = tuple[1].clone().into_uint().unwrap(); + let timestamp: U256 = tuple[2].clone().into_uint().unwrap(); + let balance: U256 = tuple[3].clone().into_uint().unwrap(); - let call_result = tuple_main[1].clone().into_bytes().unwrap(); + let call_result = tuple[4].clone().into_bytes().unwrap(); - let block_details = CallWithDetailsBlockInfo { + let block_details = CallWithDetails { + chain_id: chain_id.as_u64(), + eth_balance: balance, block_number: number.as_u64(), block_datetime: datetime_from_u256_timestamp(timestamp).ok_or(err_custom_create!( "Failed to convert timestamp to datetime" diff --git a/crates/erc20_payment_lib/src/eth.rs b/crates/erc20_payment_lib/src/eth.rs index f97b9d60..6f162d88 100644 --- a/crates/erc20_payment_lib/src/eth.rs +++ b/crates/erc20_payment_lib/src/eth.rs @@ -502,6 +502,7 @@ pub async fn get_balance( .clone() .eth_call( CallRequest { + from: Some(address), to: Some(call_with_details), data: Some(Bytes::from(call_data)), ..Default::default()