Skip to content
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

Failed to decode log from require revert: Invalid data: missing log formatter #1353

Closed
chlenc opened this issue May 1, 2024 · 3 comments
Closed
Assignees

Comments

@chlenc
Copy link

chlenc commented May 1, 2024

Problem Description

Previously, I implemented an order creation as shown below, where pyth was called inside the contract:

let update_data = update_data_bytes(None).await.unwrap();
let fee: u64 = self
    .pyth
    .methods()
    .update_fee(update_data.to_vec())
    .simulate()
    .await
    .unwrap()
    .value;

self.clearing_house
    .methods()
    .open_order(
        base_token,
        I64::new(base_size.unsigned_abs(), base_size < 0),
        order_price,
        update_data,
    )
    .with_tx_policies(
        TxPolicies::default()
            .with_gas_price(2)
            .with_script_gas_limit(20000000),
    )
    .with_contracts(&[
        &self.proxy,
        &self.perp_market,
        &self.pyth,
        &self.account_balance,
        &self.vault,
    ])
    .call_params(CallParameters::default().with_amount(fee))
    .call()
    .await;

Now, I am transitioning to remove the pyth call from within the contract and instead handle the price update in pyth and order opening in a Sway script. The new script setup is as follows:

script;

use i64::I64;
use std::constants::ZERO_B256;
use std::bytes::Bytes;
use pyth_interface::{PythCore, data_structures::price::Price};
use clearing_house_abi::{
    ClearingHouseContract,
    data_structures::{MarketStatus, Market},
    errors::Error,
    InfoClearingHouseContract,
};
use proxy_abi::{InfoProxyContract, ProxyContract};

fn main(base_token: AssetId, base_size: I64, order_price: u64, pyth_price_update_data: Vec<Bytes>, pyth_fee: u64) {
    let proxy_contract = abi(InfoProxyContract, 0x037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8);
    let spark_contracts = proxy_contract.get_spark_contracts();
    
    let clearing_house_contract = abi(ClearingHouseContract, spark_contracts.clearing_house_address.into());
    let pyth_contract = abi(PythCore, spark_contracts.pyth_address.into());
    
    pyth_contract.update_price_feeds{coins: pyth_fee, asset_id: ZERO_B256}(pyth_price_update_data);
    clearing_house_contract.open_order(base_token, base_size, order_price);
}

The new order creation now looks like this:

abigen!(Script(
    name = "CreateOrderScript",
    abi = "perp-contracts/create-order-script/out/debug/create-order-script-abi.json"
));

let bin_path = "perp-contracts/create-order-script/out/debug/create-order-script.bin";
let script_alice_instance = CreateOrderScript::new(alice.clone(), bin_path);
let script_bob_instance = CreateOrderScript::new(bob.clone(), bin_path);

let update_data = update_data_bytes(None).await.unwrap();
let fee = pyth.update_fee(&update_data).await.unwrap().value;

script_alice_instance
    .main(
        btc.asset_id,
        I64::new(btc.parse_units(0.5) as u64, false), //Long position
        btc_price,
        update_data,
        fee,
    )
    .with_contract_ids(&[
        spark.proxy.contract_id().into(),
        spark.perp_market.contract_id().into(),
        spark.pyth.contract_id().into(),
        spark.account_balance.contract_id().into(),
        spark.vault.contract_id().into(),
        spark.clearing_house.contract_id().into(),
    ])
    .call()
    .await
    .unwrap();

However, this call fails with the following error:

called `Result::unwrap()` on an `Err` value: RevertTransactionError { reason: "failed to decode log from require revert: Invalid data: missing log formatter for log_id: `LogId(3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, 3)`, data: `[0, 0, 0, 0, 0, 0, 0, 23]`. Consider adding external contracts with `with_contracts()`", revert_id: 18446744073709486080, receipts: [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 1729785, param1: 640754381, param2: 0, pc: 15824, is: 15824 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 43040, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 34900, is: 15824, data: Some(0000000000000000f3f8c33116...) }, Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, amount: 4, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 1635392, param1: 2305799257, param2: 10768, pc: 15824, is: 15824 }, Return { id: 3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, val: 0, pc: 89356, is: 15824 }, Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 887459, param1: 3788862621, param2: 14936, pc: 15824, is: 15824 }, Call { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 855190, param1: 640754381, param2: 0, pc: 109016, is: 109016 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 136232, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 128092, is: 109016, data: Some(0000000000000000f3f8c33116...) }, Call { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 819283, param1: 640754381, param2: 0, pc: 109016, is: 109016 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 136232, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 128092, is: 109016, data: Some(0000000000000000f3f8c33116...) }, Call { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, to: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 722766, param1: 2753560024, param2: 107272, pc: 109016, is: 109016 }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 694919, param1: 640754381, param2: 0, pc: 377040, is: 377040 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 404256, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 396116, is: 377040, data: Some(0000000000000000f3f8c33116...) }, Return { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, val: 0, pc: 198320, is: 109016 }, Call { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, to: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 473654, param1: 3884451018, param2: 107336, pc: 109016, is: 109016 }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 445783, param1: 640754381, param2: 0, pc: 385032, is: 385032 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 412248, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 404108, is: 385032, data: Some(0000000000000000f3f8c33116...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 410858, param1: 640754381, param2: 0, pc: 385032, is: 385032 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 412248, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 404108, is: 385032, data: Some(0000000000000000f3f8c33116...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 360627, param1: 3417376219, param2: 107368, pc: 385032, is: 385032 }, ReturnData { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, ptr: 472600, len: 144, digest: 0eb412c665aa441d81be69956774e6831a9529e953d3812cb26f648d5bc9d731, pc: 452484, is: 385032, data: Some(593b117a05f5ea64b39ba1f9bc...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 313279, param1: 640754381, param2: 0, pc: 385032, is: 385032 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 412248, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 404108, is: 385032, data: Some(0000000000000000f3f8c33116...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 275341, param1: 640754381, param2: 0, pc: 385032, is: 385032 }, ReturnData { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, ptr: 412248, len: 232, digest: 1ce0ed20ac4499c238b05e96277cc4d7906c2b6b6d7738ee59f8becdc1898c89, pc: 404108, is: 385032, data: Some(0000000000000000f3f8c33116...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 225110, param1: 3417376219, param2: 107368, pc: 385032, is: 385032 }, ReturnData { id: a0ce19b06ae41bebe68af4d2c3518662d19ee8025e65346e14f49fcd9ad44893, ptr: 472600, len: 144, digest: 0eb412c665aa441d81be69956774e6831a9529e953d3812cb26f648d5bc9d731, pc: 452484, is: 385032, data: Some(593b117a05f5ea64b39ba1f9bc...) }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 191783, param1: 448081130, param2: 0, pc: 385032, is: 385032 }, Return { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, val: 4611686020141954078, pc: 405784, is: 385032 }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 16bc08001b750d5ea3559bfc72a95a46e682246d5427d09cb4ba8bfcbb261efc, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 133809, param1: 902148450, param2: 107368, pc: 385032, is: 385032 }, Return { id: 16bc08001b750d5ea3559bfc72a95a46e682246d5427d09cb4ba8bfcbb261efc, val: 57600230252, pc: 510988, is: 385032 }, Call { id: f3f8c33116e5d217eace1b2d2f9acea1bb6fa8c08e3114f55d01ddc68089754b, to: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 101998, param1: 3538106852, param2: 382744, pc: 385032, is: 385032 }, Call { id: 037a8316d374d8ca5212ae639fc52609dd408162f4c782d17c5b2ea4d41cccb8, to: 3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 5655, param1: 1364950170, param2: 413304, pc: 414608, is: 414608 }, LogData { id: 3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, ra: 0, rb: 3, ptr: 678008, len: 8, digest: aed2b8245fdc8acc45eda51abc7d07e612c25f05cadd1579f3474f0bf1f6bdc6, pc: 417600, is: 414608, data: Some(0000000000000017) }, Revert { id: 3cd5005f23321c8ae0ccfa98fb07d9a5ff325c483f21d2d9540d6897007600c9, ra: 18446744073709486080, pc: 417608, is: 414608 }, ScriptResult { result: Revert, gas_used: 1757613 }] }
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1077:23
   4: match_orders::main::{{closure}}
             at ./scripts/match_orders.rs:118:5
   5: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:63
   6: tokio::runtime::coop::with_budget
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5
   7: tokio::runtime::coop::budget
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:73:5
   8: tokio::runtime::park::CachedParkThread::block_on
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:31
   9: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/blocking.rs:66:9
  10: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  11: tokio::runtime::context::runtime::enter_runtime
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/runtime.rs:65:16
  12: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  13: tokio::runtime::runtime::Runtime::block_on
             at /Users/alexey/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/runtime.rs:350:45
  14: match_orders::main
             at ./scripts/match_orders.rs:176:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Environment
SDK version: fuels = { version = "0.55.1", features = ["fuel-core-lib"] }
repo: https://github.com/compolabs/spark-perps
branch: "create-order-script"
toolchain:

Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains
--------------------
beta-5-aarch64-apple-darwin
latest-aarch64-apple-darwin (default)
nightly-2024-01-24-aarch64-apple-darwin
nightly-2024-03-30-aarch64-apple-darwin

active toolchain
----------------
latest-aarch64-apple-darwin (default)
  forc : 0.49.3
    - forc-client
      - forc-deploy : 0.49.3
      - forc-run : 0.49.3
    - forc-crypto : 0.49.3
    - forc-doc : 0.49.3
    - forc-explore : 0.28.1
    - forc-fmt : 0.49.3
    - forc-lsp : 0.49.3
    - forc-tx : 0.49.3
    - forc-wallet : 0.4.3
  fuel-core : 0.22.1
  fuel-core-keygen : 0.22.1

fuels versions
--------------
forc : 0.54.0
forc-wallet : 0.54.0
@digorithm digorithm changed the title ailed to decode log from require revert: Invalid data: missing log formatter Failed to decode log from require revert: Invalid data: missing log formatter May 2, 2024
@hal3e
Copy link
Contributor

hal3e commented May 2, 2024

Can you please try to use with_contracts as you did before. You can do the same with script calls. Something like this:

script_alice_instance
    .main(
        btc.asset_id,
        I64::new(btc.parse_units(0.5) as u64, false), //Long position
        btc_price,
        update_data,
        fee,
    )
    .with_contracts(&[ // all of these should be `contract_instances`
        &spark.proxy,
        &spark.perp_market,
        &spark.pyth,
        &spark.account_balance,
        &spark.vault,
        &spark.clearing_house,
    ])
    .call()
    .await
    .unwrap();

Some context:
There is no way to decode logs if you provide only contract_ids as we do not know the mappings between log IDs and types.

@hal3e
Copy link
Contributor

hal3e commented May 7, 2024

@chlenc did the comment above solve the issue ?

@hal3e hal3e self-assigned this May 21, 2024
@hal3e
Copy link
Contributor

hal3e commented May 21, 2024

Solved by using with_contracts.

@hal3e hal3e closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants