Skip to content

Commit

Permalink
bring back ABI codec for batch call
Browse files Browse the repository at this point in the history
  • Loading branch information
tolak committed Sep 16, 2023
1 parent 622ec45 commit 4d1064f
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 166 deletions.
136 changes: 130 additions & 6 deletions contracts/index_executor/src/abi/handler.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,71 @@
{
"inputs": [
{
"internalType": "bytes",
"name": "raw",
"type": "bytes"
"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": "spender",
"type": "address"
},
{
"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",
Expand Down Expand Up @@ -267,9 +329,71 @@
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "raw",
"type": "bytes"
"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": "spender",
"type": "address"
},
{
"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",
Expand Down
13 changes: 6 additions & 7 deletions contracts/index_executor/src/actions/base/native_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl CallBuilder for NativeWrapper {
value: spend_amount,

need_settle: true,
update_offset: 0,
update_len: 0,
update_offset: U256::from(0),
update_len: U256::from(0),
// No spender
spender: Address::from(&[0; 20]),
spend_asset,
Expand All @@ -77,8 +77,8 @@ impl CallBuilder for NativeWrapper {
value: U256::from(0),

need_settle: true,
update_offset: 4,
update_len: 32,
update_offset: U256::from(4),
update_len: U256::from(32),
// No spender
spender: Address::from(&[0; 20]),
spend_asset,
Expand All @@ -97,7 +97,6 @@ impl CallBuilder for NativeWrapper {
#[cfg(test)]
mod tests {
use super::*;
use crate::call::PackCall;
use crate::utils::ToArray;
use dotenv::dotenv;
use primitive_types::H160;
Expand Down Expand Up @@ -190,7 +189,7 @@ mod tests {
// Estiamte gas before submission
let gas = resolve_ready(handler.estimate_gas(
"batchCall",
calls.clone().pack(),
calls.clone(),
Address::from_slice(&hex::decode("bf526928373748b00763875448ee905367d97f96").unwrap()),
Options::with(|opt| {
// 0.1 GLMR
Expand All @@ -207,7 +206,7 @@ mod tests {
// Uncomment if wanna send it to blockchain
let tx_id = resolve_ready(handler.signed_call(
"batchCall",
calls.pack(),
calls,
Options::with(|opt| {
opt.gas = Some(gas);
// 0.1 GLMR
Expand Down
4 changes: 2 additions & 2 deletions contracts/index_executor/src/actions/base/uniswapv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl CallBuilder for UniswapV2 {
value: U256::from(0),

need_settle: true,
update_offset: 4,
update_len: 32,
update_offset: U256::from(4),
update_len: U256::from(32),
spender: self.router.address(),
spend_asset: asset0,
spend_amount: amount_in,
Expand Down
10 changes: 5 additions & 5 deletions contracts/index_executor/src/actions/base/uniswapv3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ impl CallBuilder for UniswapV3 {
value: U256::from(0),

need_settle: true,
update_offset: 132,
update_len: 32,
update_offset: U256::from(132),
update_len: U256::from(32),
spender: self.router.address(),
spend_asset: asset0,
spend_amount: amount_in,
Expand All @@ -73,7 +73,7 @@ impl CallBuilder for UniswapV3 {
#[cfg(test)]
mod tests {
use super::*;
use crate::{call::PackCall, utils::ToArray};
use crate::utils::ToArray;
use dotenv::dotenv;
use primitive_types::H160;

Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {
// Estiamte gas before submission
let gas = resolve_ready(handler.estimate_gas(
"batchCall",
vec![call.clone()].pack(),
vec![call.clone()],
Address::from_slice(&hex::decode("bf526928373748b00763875448ee905367d97f96").unwrap()),
Options::default(),
))
Expand All @@ -152,7 +152,7 @@ mod tests {
// Uncomment if wanna send it to blockchain
let _tx_id = resolve_ready(handler.signed_call(
"batchCall",
vec![call].pack(),
vec![call],
Options::with(|opt| {
opt.gas = Some(gas);
}),
Expand Down
9 changes: 4 additions & 5 deletions contracts/index_executor/src/actions/ethereum/sygma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ impl CallBuilder for EvmSygmaBridge {
value: U256::from(self.fee_amount),
spender: self.erc20_handler_address,
need_settle: false,
update_offset: 164,
update_len: 32,
update_offset: U256::from(164),
update_len: U256::from(32),
spend_asset,
spend_amount,
receive_asset: spend_asset,
Expand All @@ -172,7 +172,6 @@ impl CallBuilder for EvmSygmaBridge {
#[cfg(test)]
mod tests {
// use crate::utils::ToArray;
use crate::call::PackCall;

use super::*;
use sp_runtime::AccountId32;
Expand Down Expand Up @@ -239,7 +238,7 @@ mod tests {
// Estiamte gas before submission
let _gas = resolve_ready(handler.estimate_gas(
"batchCall",
vec![call.clone()].pack(),
vec![call.clone()],
// Worker address
Address::from_slice(&hex::decode("bf526928373748b00763875448ee905367d97f96").unwrap()),
Options::with(|opt| {
Expand All @@ -266,7 +265,7 @@ mod tests {

// let _tx_id: primitive_types::H256 = resolve_ready(handler.signed_call(
// "batchCall",
// vec![call].pack(),
// vec![call],
// Options::with(|opt| {
// opt.gas = Some(gas);
// // 0.001 ETH
Expand Down
4 changes: 2 additions & 2 deletions contracts/index_executor/src/actions/moonbeam/xtoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl CallBuilder for XTokenBridge {
// Bridge operation do not need do settlement on source chain, because it must be the
// last step on source chain
need_settle: false,
update_offset: 36,
update_len: 32,
update_offset: U256::from(36),
update_len: U256::from(32),
spender: self.xtoken.address(),
spend_asset,
spend_amount,
Expand Down
Loading

0 comments on commit 4d1064f

Please sign in to comment.