Inspiration

Inspiration for Apprecio.Finance (AF) came from August 5, 2021, 1729 Newsletter, sponsored by Bajali Srinivasan (@balajis):

“Inflation is a monetary phenomenon, a function of money printing. But it is also in part a social phenomenon, a function of mass psychology. If enough of the right people believe that inflation is going to happen, it will. As such, when inflation is happening, there is often a push to censor discussion of inflation itself, under the grounds that discussing the problem actually causes it in the first place. That is exactly what happened in Argentina and Venezuela over the last decade […] And that is why the world needs a global, decentralized, censorship-resistant inflation dashboard.

Why do we need an inflation dashboard? Because trillions of dollars have been printed over the last year – and it's not just dollars. Many countries besides the US have been printing fiat like mad to fund the response to COVID. Figures that shocked and stunned ten years ago ($787B for the bailout!) no longer warrant a headline today, though they may well result in headlines tomorrow.

If inflation is a government-caused problem, we can't necessarily rely on government statistics like the CPI to diagnose it or remediate it. Indeed, in places with high inflation, censorship and denial is the rule rather than the exception.”

What it does

AF is a decentralized inflation dashboard: it estimates inflation from various price sources and makes it available through a front-end and on-chain trough Chainlink.

Its main objective is to resist censorship and provide an alternative to centralized measures such as those that come from Central Banks and national statistical agencies. AF implements decentralization at three different times in its design. (1) The price data are obtained from more than 1,000 different sources (in the Mexican case), independent of the government, which prevents the failure or manipulation of any source from significantly affecting the inflation calculation. (2) Data is automatically stored off-chain using the Interplanetary File System (IPFS), for data to be distributed across multiple off-chain nodes, and Filecoin, for data permanence and availability at any moment. (3) Aggregate prices and inflation rate are stored on-chain, Kovan testnet for AF v0.2, using Chainlink. The last two steps would also allow the data to be cryptographically signed twice.

How we built it

AF Design

To achieve the highest possible resistance to censorship, AF implements decentralization at three different times in its design. The following figure captures them.

Decentralization at three stages.

Data Recollection

This step is crucial to maintain decentralization. If manipulation of the data source by a third party can significantly alter AF's inflation rate measurement, then the objective of censorship resistance would be compromised.

Thus, for the Mexican case, our first measure, the data are obtained from two different types of sources.

  1. Small sellers. Through the Apprecio web and mobile applications.

  2. Medium and large sellers. Through web scrapping of online stores.

Data Recollection: Small vendors (tienditas, in Spanish)

AF is unique in that it takes advantage of a data source such as that from small vendors.

In Latin America, these sellers are frequent. Around 700 thousand tienditas exist in Mexico and generate 1% of GDP. Not taking this data source into account would greatly skew the inflation estimate. However, obtaining data from these sources is a grassroots activity. There is no database that tracks prices in these relevant units.

We take advantage of the work of the Mexican Apprecio fintech with more than 8 thousand small vendors as clients throughout the Mexican Republic. Among other financial and strategic services, Apprecio helps small suppliers to calculate the ideal prices for their products. To do this, they require units to charge the prices at which they offer their products. AF then uses these data to calculate inflation.

Apprecio.mx homepage

This source is decentralized. The data, for November 2021, comes from at least 1,000 different units and the number is growing. The fact that a unit does not report accurate data would not affect the general median price of the good and therefore any calculations made with the prices.

Data Recollection: Medium to Big Vendors

Prices from Walmart, La Comer, and Soriana are included to further decentralize data sources. AF scrapes their online stores. For Mexico, it is planned to include at least two additional sources: Costco and Sam's Club.

These sources provide the assurance of the constant presence of at least one price during any period. The main challenge comes from maintaining scrappers that can repeatedly beat the web pages. The 1729 Newsletter mentions several issues related to reliance on scrappers for pricing data, including dealing with automated countermeasures, maintaining the web crawler, and analyzing hard-to-determine units. AF met these problems successfully.

Decentralized storage off-chain

For AF to be a successful tool for openly measuring inflation, it must be available for audit (1) at any time and (2) as cheaply as possible.

Storage has at least two requirements for AF:

  1. Raw price data must be auditable. Currently, raw data storage is done off-chain due to gas prices. Possibly, the next step would be for AF to move to an Ethereum L2 and be able to store raw data on the chain.

  2. The data must be stored in a decentralized way. A central server means the consolidation of control over the data. Even off the chain, due to point 1, this should be achieved.

AF achieves both requirements by storing raw price data off-chain using IFPS. The entire price data set is divided into smaller chunks, cryptographic hashed, and assigned a unique fingerprint called a Content Identifier (CID). The dataset would be stored on at least one node, a local server anywhere in the world. By using the CID, other nodes can request the data and will cache the data themselves locally. This would increase the decentralization of the data set off the chain.

The data must always be online and available for direct request.

“While IPFS guarantees that any content on the network is discoverable, it doesn't guarantee that any content is persistently available. This is where Filecoin comes in […] a decentralized storage network in which storage providers rent their storage space to clients.” (IPFS documentation).

AF uses Filecoin so that price data is always available while maintaining its decentralization. The dataset would be anchored in at least one node.

The Web3.Storage solution enables AF (1) to automatically store the dataset in IPFS and back it up with Filecoin; and (2) replicate pricing data across a network of storage providers and verify its integrity.

This solution allows data to be persistent, available, and decentralized even off-chain. The next layer of decentralization will come from making the data available on-chain.

On-Chain Storage and Availability

Raw off-chain data of available sources are aggregated to obtain the median value of the prices for a determined period of time, leading to a single price per item that must be taken into account in the inflation calculation. AF calculates inflation off-chain using the CalculateInflation.py function in AF's GitHub repository. The calculation is done off-chain to save gas. However, the next step is to allow any user to request an on-chain calculation.

AF v0.2 uses Chainlink to bring off-chain data to the Kovan testnet. The next step would be to run a node directly on the Ethereum Mainnet to add an additional layer of decentralization. Chainlink is a decentralized Oracle network that cryptographically signs and delivers data on-chain. Currently, any user can request (1) the current inflation rate; and (2) the aggregate prices of each of the items in the inflation calculation.

Challenges we ran into

  1. Debugging a Chainlink node was not trivial at first.
  2. Obtaining price data in a decentralized way.
  3. Calculate the inflation as close as possible to how the official calculation in Mexico does.

Accomplishments that we're proud of

  1. We gave the first step in solving an incredibly relevant problem. The 1729 Newsletter, sponsored by Bajali Srinivasan (@balajis), let us see this clearly.
  2. AF is a project that, given support for an amazing team, could really help decentralize economic indicators such as inflation.

What we learned

  1. How to create our own Chainlink node and operate it.
  2. How to use web3.storage for decentrally store files in IPFS.
  3. How Chainlink works and the incredibly relevant role of aggregation. We even wrote a blog post about it.

What's next for Apprecio.Finance

Three main points appear on the AF roadmap:

  1. Coverage extended to new countries. The next would be the United States and Brazil. Requests from other economies are appreciated.

  2. Possible migration to full on-chain storage. With the development of new Ethereum L2 rollups like Starknet, it's cheaper than ever to chain data. This would allow users to request and integrate AF data into their smart contracts inexpensively.

  3. Adding new data sources. The more good quality data sources AF uses, the more decentralized and secure the inflation rate will be. In Mexico, AF is already implementing data from small suppliers (tienditas) and retailers.

Built With

Share this project:

Updates