Skip to content

Commit

Permalink
working on wrapper call
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed May 23, 2024
1 parent bf28c6a commit dfefb71
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 73 deletions.
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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" }
Expand Down
112 changes: 53 additions & 59 deletions crates/erc20_payment_lib/contracts/wrapper_call.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
Expand All @@ -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"
}
Expand All @@ -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"
},
{
Expand All @@ -86,7 +77,7 @@
},
{
"internalType": "bytes[]",
"name": "callDatas",
"name": "callDataArray",
"type": "bytes[]"
}
],
Expand All @@ -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"
}
Expand Down
29 changes: 17 additions & 12 deletions crates/erc20_payment_lib/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utc>,
}

pub fn decode_call_with_details(
bytes: &[u8],
) -> Result<(crate::contracts::CallWithDetailsBlockInfo, Vec<u8>), PaymentError> {
) -> Result<(crate::contracts::CallWithDetails, Vec<u8>), 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"
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit dfefb71

Please sign in to comment.