Dapp-Example

To help you better understand how a Dapp - ADCS works, let’s dive into the following example together Meme Coin Trend Application.

The Meme Coin Trend application utilizes cutting-edge AI and blockchain technology to monitor trending meme coins and analyze market data in real time. With an integrated AI agent, the platform autonomously trades meme coins using insights gathered from the ADCS network, ensuring efficient and data-driven trading decisions.

Step-by-step guide on how to approach building the application

1. Adapter Definition:

Visit here to learn How to create an adaptor.

You need to define an adapter that outlines the necessary parameters.

  • Provider: Meme Coin Trend

  • Network: Rivalz

  • Category : Meme Coin

  • Output Type : StringAndBool

  • Adaptor Name (String): Meme Coin Trend.

  • Description(String): Get a trending meme coin and make decisions which meme coin should buy.

  • Prompt: Retrieve the current trending meme coins and analyze market conditions to recommend which meme coin should be bought.

Once an adaptor is created, the system will generate a unique JobID.

Oxd7....2352 is the JobID for your Meme Coin Trend Adaptor.

2. Setup Your Consumer Contract:

Depending on the type of outputData you have defined in the adaptor, your consumer contract must inherit from the appropriate ADCS fulfillment contract. Here the outputData is StringandBool so the consumer contract will inherit the ADCSConsumerFulfillStringAndBool.

Struct

MemeCoin is a custom data type used to to represent a meme coin with three properties:

Contract Variables:

The memeCoins variable represents an array of MemeCoin structs, allowing the contract to store multiple meme coins

Constructor:

ADCSConsumerBase is an abstract contract that serves as the base for consumer contracts interacting with the ADCS coordinator. It initializes data requests and verifies the fulfillment.

The constructor takes the Coordinator contract's address (_coordinator) as input and passes it to the base contract. The Coordinator manages the interaction between oracles and consumers, facilitating the flow of data requests and responses.

_weth: the address of the WETH (Wrapped Ether) token contract.

_swapRouter: the address of the Uniswap V3 swap router contract, used to interact with the Uniswap decentralized exchange (DEX) to swap tokens

Different Coordinator contract addresses are provided, each tailored to handle a specific output type, such as uint256, bool, or bytes. This allows consumers to interact with oracles in a way that matches the data type of the responses they expect.

Main functions

Request Functions:

This function Initiates a data request to the ADCS network and requests :

  • _callbackGasLimit: The maximum amount of gas a user is willing to pay for completing the function.

  • _jobId: The jobID that the consuming contract is registered to.

  • The function uses the buildRequest() function to create a request, adds the necessary parameters, and sends it to the Coordinator.

Fulfillment Functions:

This function is called by the ADCS coordinator to fulfill the data request and trigger a trade.

TradeMemeCoin Function:

The tradeMemeCoin function executes the buy or sell trade on Uniswap V3 based on the data received and triggered by the fulfillDataRequest function.

After processing the received data, the tradeMemeCoin function is called with the tokenName and the result (true/false).

  • If result is true, the contract performs a buy trade by swapping WETH (Wrapped Ether) for the specified meme coin on Uniswap V3.

  • If result is false, the contract performs a sell trade by swapping the meme coin for WETH on Uniswap V3.

addMemeCoin Function: Adds a new memecoin to the list of tradable tokens

setWethAmountForTrade Function: Sets the amount of WETH to use for trading.

3. Deploy the consumer contract

After defining all necessary functions, the global state, and the Coordinator contract for your consumer contract, the next step is to deploy the contract to the blockchain. Learn more here.

4. How the Meme Coin Trend Application works

When receiving a request from the consumer contract, the system listens for the request and then identifies an appropriate AI to process the data.

  1. The AI system processes the request, identifying the meme coin (e.g., "Shiba Inu") and making a recommendation (e.g., buy or sell).

  2. The Coordinator contract receives the result from the AI system and calls the fulfillDataRequest() function in the consumer contract, passing the processed result (token name and recommendation).

  3. The consumer contract processes the result in the fulfillDataRequest() function, which identifies the meme coin (via the name) and calls the tradeMemeCoin() function to execute the buy or sell action.

  4. The contract interacts with the Uniswap V3 router to perform the trade, and once completed, the TradeSuccess event is emitted.

FullCode Example

We've also built some examples to help you easily understand what you can do with ADCS network here

Github.

Last updated