BLOG — Use cases

372 days ago

Mimicry x Gelato: Automating Data Feeds for Real-Time Accuracy

Mimicry Protocol is a decentralized platform for creating and participating in prediction games based on various market odds.

Participants can bet on the future value of NFT collections, with the platform utilizing an oracle system to provide accurate and up-to-date data for market pricing. By leveraging Gelato’s Web3 Functions, Mimicry automates the data feed update process to ensure that participants can access the current information.

How Does Mimicry Use Web3 Functions?

Update Data Feeds

Mimicry uses the OpenMarketsOracle smart contract to act as a reliable data source. The updateValue function within the smart contract is responsible for updating a data feed's stored value. If specific conditions are met, the Gelato Web3 Function prepares the call data to update the OpenMarketsOracle contract with the new value, using the updateValue function.

Cross-Chain Cloner

Mimicry keeps their testnet and mainnet user interfaces in sync by cloning OpenMarketsOracle values between chains. This is facilitated by a Web3 Function that continuously monitors a “source of truth” smart contract on mainnet. Any time the source of truth is updated, the function clones the updated value to an instance of the OpenMarketsOracle smart contract on a testnet. This mechanism keeps data in sync at all times.

Integrations

The core of this integration lies in automating the oracle smart contract, which is responsible for fetching and updating the necessary data. This automation allows Mimicry to focus on providing a fair prediction game experience for participants.

To accomplish this, Gelato's Web3 Functions takes care of fetching data from various sources, processing it, and determining if an update is needed. The Gelato Web3 Function gathers data from different providers, such as NFTGo, Center, and CoinGecko, which all offer information about NFT collections, tokens, and other relevant data points.

For the NftGo provider:

case "NftGo" /* NFTGO */: {
  const apiKey = await context.secrets.get("NFTGO_API_KEY");
  const newValue2 = await nftCollectionRunner(
    "NftGo" /* NFTGO */,
    apiKey,
    nftCollections,
    currency,
    metric
  );
  nftProviderValues.push(newValue2);
  break;
}

For the Center provider:

case "Center" /* CENTER */: {
  const apiKey = await context.secrets.get("CENTER_API_KEY");
  if (!apiKey)
    throw new Error("CENTER_API_KEY not set in secrets");
  const newValue2 = await nftCollectionRunner(
    "Center" /* CENTER */,
    apiKey,
    nftCollections,
    currency,
    metric
  );
  nftProviderValues.push(newValue2);
  break;
}

For the CoinGecko provider:

case "CoinGecko" /* COINGECKO */: {
  const apiKey = await context.secrets.get("COINGECKO_API_KEY");
  if (!apiKey)
    throw new Error("COINGECKO_API_KEY not set in secrets");
  const newValue2 = await tokenRunner(
    "CoinGecko" /* COINGECKO */,
    apiKey,
    tokens,
    currency
  );
  tokenProviderValues.push(newValue2);
  break;
}

Once the data is collected, a consensus mechanism helps to reach an agreed-upon value from the diverse data sources.

const newValue = reachConsensus(nftProviderValues, consensusMechanism).add(reachConsensus(tokenProviderValues, consensusMechanism));

The purpose of the consensus mechanism is to reduce the influence of any single data source and ensure a more reliable value.

After calculating the new value, the Gelato Web3 Function checks whether it is different from the current value stored in the oracle smart contract.

if (newValue.eq(lastOracleValue)) {
  return { canExec: false, message: `The oracle value has not changed` };
}

If the new value is different and meets certain predefined conditions, the script initiates an update to the oracle smart contract with the new value.

return {
  canExec: true,
  callData: destinationOracle.interface.encodeFunctionData("updateValue", [
    dataFeedId,
    newValue
  ])
};

The predefined conditions include a minimum value difference threshold of 0.25% and a minimum time of 1 hour since the last update.

if (valueDiffPercent.lte(deviation) && timeDiff.lte(heartbeat)) {
  return { canExec: false, message: `Value difference is less than ${deviation / 100}% and the last update was less than ${heartbeat / 60} minutes ago` };
}

These conditions ensure that updates are only made when there is a significant change in the data and a reasonable amount of time has passed. This automated process ensures that the data used in Mimicry's prediction games stays up-to-date and relevant for the participants.

By automating the oracle smart contract updates, the integration between Gelato’s Web3 Functions and Mimicry allows the platform to provide a seamless and accurate prediction game experience for users.

About Gelato's Web3 Functions

Web3 Functions provide an innovative solution for developers to create serverless, decentralized applications with ease. They enable seamless integration of smart contracts with off-chain data, bridging the gap between on-chain and off-chain worlds.

By leveraging Web3 Functions, developers can build robust, scalable, and decentralized web3 applications, supported by a reliable and resilient infrastructure.

Get Started!

Join our community and developer discussion on Discord.

Web3 Functions are available today in private beta. For more information, please check out the Web3 Functions documentation. To learn how to write, test, and deploy your own Web3 Functions, use this Hardhat template

Apply here to be one of the first to test Web3 Functions!