Folks Feed Oracle
  • Introduction
  • FOLKS FEED ORACLE
    • Overview
    • Server
    • Provider
    • Smart contract
  • Developers
    • Introduction
    • SDK
      • Python
      • PyTEAL
    • Contract
    • Feeds
  • OTHERS
    • Socials
    • Brand assets
    • Make a request
    • Glossary
Powered by GitBook
On this page
  • Deploy
  • Management
  • Feeds update
  1. FOLKS FEED ORACLE

Smart contract

PreviousProviderNextIntroduction

Last updated 2 years ago

The FFO's smart contract resides on the Algorand blockchain. This chapter explains how the smart contract is created, managed, and how feeds are updated.

Deploy

The contract is deployed by passing, as a parameter, the address of the account that will be admin. When the contract is deployed, the global state time delay (explained later) will have value 0.

Management

Contract management (adding/removing updaters, adding assets, etc.) is organised in two steps so the community and platforms are aware of every operation performed with the contract.

Schedule operation

Contract management operations are handled by the schedule_admin_operation method, which receives as parameters:

  • box_key: key of the box storage that will contain the operation to execute;

  • method: ARC4 selector of the method to be called;

  • timestamp_threshold: timestamp from which the operation can become effective;

  • params: the args to decode and pass to the method;

This method can only be called by the admin and creates a box structured as follows:

[ method selector, timestamp threshold, method params ]

The timestamp threshold must be bigger than current timestamp + time delay and the box with the specified key must not exist yet.

This way, every time a new change is scheduled, anyone will have the opportunity to review what changes will be made.

Before the change is actually made to the contract, the admin has the opportunity to revoke it, calling the method revoke_admin_operation that deletes the box storage.

Execute operation

Once the timestamp_threshold has passed, anyone will be able to trigger the change in a permissionless manner by calling a specific method; passing the box_key used by the admin. Upon calling it, the change will become effective.

Each method used to manage the contract will check the values inside the box storage; in particular, that the timestamp threshold has passed, and the method selector is correct.

The operations are:

update_time_delay: this method updates the time delay attribute. It needs to be within the MIN_TIME_DELAY and MAX_TIME_DELAY. If the new time delay is valid, it will be updated. Time delay is the shortest valid time in which an operation will be pending.

update_updater_authorization: this authorizes or revokes an updater to update prices by setting its local state auth to 1, i.e. true or 0, i.e. false.

add_asset: this method adds a new asset whose price is desired. If the asset doesn't exist yet, a new global state will be set with the value:

[ price, latest timestamp, price_threshold, initialized ]

The price will be set to zero, price_threshold was passed by the admin while initialized will be zero; the initialized flag set to 0 allows the price to be updated without the price threshold check.

update_asset_data: if the asset already exists, then the feed data will be updated. This method allows updating of the price_threshold and the initialized flag; The update of the initialized flag to zero allows the price to be updated without the price threshold check.

update_contract: this method allows the approval and clear programs to be updated. It is checked that the approval program Sha256 and the clear program Sha256 are equal to that saved in the storage box.

update_admin: can be executed only by the new admin, so if the sender's address is the same as that set in the storage box, then the admin will be updated.

Feeds update

update_prices: this method can be called by the authorized updaters, allowing them to update the prices of the inserted assets. If the price change is lower than its price threshold, the prices and the latest timestamps will be updated.