RevertTransactionError reason: "assertion failed."

GM guys, recently we launched our spark order book on fuel beta5 with its own indexer based on Envio (it works fast), but now we have noticed that our orders cannot be batched with an error

thread 'main' panicked at scripts/match_orders.rs:90:10:
called `Result::unwrap()` on an `Err` value: RevertTransactionError { reason: "assertion failed.", revert_id: 18446744073709486084, receipts: [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 72175cdd41bbf890f8cddfe54fa55ac0f311f963c010746337f1c2ac3d79ffbb, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 198428, param1: 2490974017, param2: 10448, pc: 11864, is: 11864 }, Revert { id: 72175cdd41bbf890f8cddfe54fa55ac0f311f963c010746337f1c2ac3d79ffbb, ra: 18446744073709486084, pc: 81732, is: 11864 }, ScriptResult { result: Revert, gas_used: 238729 }] }

First of all, I noticed we have on matcher logs like on screenshot

After I stopped the matcher on our server, added logs locally, and started it on my machine. As you can see in the screenshot

I checked if orderbook has enough money

balances = {
593b117a05f5ea64b39ba1f9bc3fb7e7a791c9be130e28376ad552eacdb3b746: 57941852, 
0000000000000000000000000000000000000000000000000000000000000000: 0, 
0450e4d385cbd2914f74505f18f01587cc4f4ad1fdef4b80cbde2a8155a86d72: 514865646156
}

Also I tried to run it on Rust SDK

Ts SDK same

But after that, I tried to deploy the same contract on beta5, create and match same orders


    it("should emit and decode data", async () => {
            const wallet = fuelNetwork.walletManager.wallet!;

            const sellSize = 4414
            const sellPrice = 62329750000000
            const buySize = 18812
            const buyPrice = 63649539999990

            console.log("Wallet address: ", wallet.address)
            console.log("Eth balance   : ", await wallet.getBalance(BaseAssetId).then(b => b.toString()), " ETH")

            const byteCode = readFileSync(`./contract/out/debug/orderbook.bin`);
            const abi = JSON.parse(readFileSync(`./contract/out/debug/orderbook-abi.json`, 'utf8'));

            const orderbookfactory = new ContractFactory(byteCode, abi, wallet);
            const {minGasPrice: gasPrice} = wallet.provider.getGasConfig();

            const btc = fuelNetwork.getTokenBySymbol("BTC");
            const usdc = fuelNetwork.getTokenBySymbol("USDC");

            const configurableConstants = {
                QUOTE_TOKEN: {value: usdc.assetId},
                QUOTE_TOKEN_DECIMALS: 6,
                PRICE_DECIMALS: 9,
            }
            const blockNumber = await fuelNetwork.getProviderWallet().then(res => res.provider.getBlockNumber()).then(res => res.toNumber())
            const contract = await orderbookfactory.deployContract({gasPrice, configurableConstants});
            const contractId = contract.id.toHexString()
            console.log({contractId, blockNumber})

            writeFileSync("./tests/orderbookAddresses.json", JSON.stringify({contractId, blockNumber}))

            const api = new Api();

            await api.createSpotMarket(btc, 8, wallet, contractId);
            console.log("Market created: ", btc.assetId)
            await fuelNetwork.mintToken(btc.assetId, sellSize)
            console.log(`${sellSize / 1e8} btc Token minted`)
            const {orderId: sellOrderId} = await api.createSpotOrder(btc, usdc, "-" + sellSize.toString(), sellPrice.toString(), wallet, contractId);
            console.log({sellOrderId})

            const usdcAmount = Math.ceil(new BN(buySize).times(buySize).div(1e8).div(1e8).times(1e6).toNumber());
            await fuelNetwork.mintToken(usdc.assetId, usdcAmount)
            console.log(`${usdcAmount / 1e6} USDC Token minted`)
            const {orderId: buyOrderId} = await api.createSpotOrder(btc, usdc, buySize.toString(), buyPrice.toString(), wallet, contractId);

            await sleep(1000)
            const orderbookAbi = OrderbookAbi__factory.connect(contractId, wallet);

            const sellOrder = await orderbookAbi.functions.order_by_id(sellOrderId).simulate().then(res => res.value)
            const buyOrder = await orderbookAbi.functions.order_by_id(buyOrderId).simulate().then(res => res.value)
            console.log({sellOrder: decodeOrder(sellOrder), buyOrder: decodeOrder(buyOrder)})
            await api.matchSpotOrders(sellOrderId, buyOrderId, wallet, contractId).catch(e => console.error(e.cause.logs));
            console.log("Orders matched")
            await sleep(1000)

            const receiptsResult = await fetchReceiptsFromEnvio(blockNumber, +blockNumber + 1000, [contractId])
            const events = decodeOrderbookReceipts(receiptsResult?.receipts!, orderbookAbi)
            console.log(events)
        },
        60_000,
    );

And orders are matched successfully

Can you help me please to figure out how to keep matching alive?

1 Like

The problem is Solved

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.