project screenshot 1
project screenshot 2
project screenshot 3

Fuel Predicate

The predicate function checks whether a given transaction meets certain conditions and returns a boolean value indicating whether the conditions are satisfied.

Fuel Predicate

Created At

ETHGlobal Lisbon

Winner of

trophy

🥇 Fuel — Best dapp

Project Description

The code defines several constants and uses some utility functions from the utils module. The configurable macro is used to define default values for some configuration parameters that can be overridden when instantiating the predicate. The main function is the entry point of the predicate. It first checks whether the transaction has two inputs and one of them is owned by the MAKER address. If this condition is true, the function returns true. Otherwise, the function proceeds to calculate the price of the traded assets based on their amounts and decimal precision. The calculated price is compared against the PRICE configuration parameter. If the calculated price is greater than or equal to PRICE, and the traded assets match the expected asset IDs and output type, the function returns true. Otherwise, the function fails with a revert statement.

How it's Made

Here's a high-level overview of how this predicate function is constructed:

1 The code imports several Rust modules and utility functions that will be used in the predicate. 2 The code defines several configuration parameters as constants, using the configurable macro to specify default values that can be overridden later. 3 The code defines a function main that serves as the entry point for the predicate. 4 The main function first checks whether the transaction has two inputs and one of them is owned by a specified address. If this condition is true, the function returns true, indicating that the transaction is valid. 5 Otherwise, the function proceeds to perform some calculations to determine the price of the traded assets based on their amounts and decimal precision. 6 The calculated price is compared against a configuration parameter to determine whether it meets a specified minimum threshold. 7 If the calculated price is greater than or equal to the threshold, and the traded assets match the expected asset IDs and output type, the function returns true. Otherwise, the function fails with a revert statement.

The predicate function is built using Rust, which is a compiled systems programming language that provides low-level control over memory management and is known for its strong type system and memory safety. Rust code can be compiled to run on a variety of platforms, including desktop computers, servers, and embedded devices, as well as blockchain platforms like Ethereum and Solana. The Rust code is likely deployed to the blockchain as part of a larger smart contract that uses the predicate function to enforce more complex rules or business logic.

background image mobile

Join the mailing list

Get the latest news and updates