Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDO: Stats and Prices for exchanges/dispensers #525

Open
alexcos20 opened this issue Jul 5, 2024 · 2 comments
Open

DDO: Stats and Prices for exchanges/dispensers #525

alexcos20 opened this issue Jul 5, 2024 · 2 comments
Labels
Type: Enhancement New feature or request
Milestone

Comments

@alexcos20
Copy link
Member

alexcos20 commented Jul 5, 2024

In order to proper display assets in dApps, we need all info regarding assets, including prices.
Every datatoken can have one or more fixed rate exchanges or dispensers.
But we need to be careful when adding this to a DDO, cause this can quickly result to hash missmatches.

To Do:

  • add a root key at ddo level, called offchain. This key will be excluded every time we hash the ddo (like validateDDO or when indexing and comparing)
  • in offchain, add a new key: stats. Then, for each service, add an array that looks like:
{
  datatokenAddress: "0x123",
  name: "Branin dataset: DT1",
  symbol: "DT1",
  serviceId: "0",
  orders: 1,
  prices:[
       {
           type: "fixedrate", // or "dispenser"
           price: "123",
           contract: "contractAddress",
           token: "0x89777", // token accepted for payment
           exchangeId:  "xx" // only for fre, this is exhangeID
   }
  ]
}

So , a DDO can look like:

{
  "@context": [
    "https://w3id.org/did/v1"
  ],
  "id": "did:op:37f710f82f73afcb86b66a32182c2d620d2edd9eb00abb5ba5a36e943bc7cd74",
  "version": "4.1.0",
  "chainId": 137,
  "nftAddress": "0x26C693AD67d45e339A5A50a5a64963892E14EFdD",
  "metadata": {
              ...
  },
  "services": [
    {
      "name": "Download last hour of data",
      "id": "0",
      "type": "access",
      "datatokenAddress": "0x456",
     .....
    },

    {
      "name": "Download last week of data",
      "id": "1",
      "type": "access",
      "datatokenAddress": "0x34e84f653Dcb291838aa8AF8Be1E1eF30e749ba0",
     .....
    },
    {
      "name": "Download last month of data",
      "id": "2",
      "type": "access",
      "datatokenAddress": "0x1234565",
     .....
    }

  ],
 offchain: {
    stats: {
        [
            {
                datatokenAddress: "0x456",
                name: "BDT1",
                symbol: "DT1",
                serviceId: "0",
                orders: 1,
                // this service has one dispenser available
                prices: [
                    {  type: "dispenser", price: "0", contract: "dispenserContractAddress"}]

            },
            {
                datatokenAddress: "0x34e84f653Dcb291838aa8AF8Be1E1eF30e749ba0",
                name: "BDT2",
                symbol: "DT2",
                serviceId: "1",
                orders: 5,
                // this service accepts OCEAN for payment, costs 1 token per access
                prices:[
                            {  type: "fixedrate", price: "1", token:"0x967da4048cD07aB37855c090aAF366e4ce1b9F48", contract: "freContractAddress",  exchangeId:  "23434" }
                        ]
            },
            {
                datatokenAddress: "0x1234565",
                name: "BDT3",
                symbol: "DT3",
                serviceId: "2",
                orders: 5,
                // this service accepts either 2 OCEAN or 1 FETCH for payment
                prices:[  
                   {  type: "fixedrate", price: "2", token:"0x967da4048cD07aB37855c090aAF366e4ce1b9F48", contract: "freContractAddress",  exchangeId:  "23434" },
                  {  type: "fixedrate", price: "1", token:"0xaea46A60368A7bD060eec7DF8CBa43b7EF41Ad85", contract: "freContractAddress",  exchangeId:  "4535" }
             ]
            }
        ]
    }
}            
}

To do:

-[ ] exclude "offchain" from every hash compute

-[ ] for MetaDataCreated:

- For each service:
    - get the list of dispensers (call getDispensers() - https://github.com/oceanprotocol/contracts/blob/main/contracts/templates/ERC20TemplateEnterprise.sol#L1107C14-L1107C27) from datatoken contract
        - for each dispenser, check if active. if yes, add it to the list
    - get the list of fixed rates (call getFixedRates())
        - for each fixed rate, check if active and grab the price, then add it to the list
- Update stats key

-[ ] for MetaDataUpdated:

- For each service:
    - get the list of dispensers (call getDispensers()) from datatoken contract
        - for each dispenser, check if active. if yes, add it to the list
    - get the list of fixed rates (call getFixedRates())
        - for each fixed rate, check if active and grab the price, then add it to the list
- Remove services from stats which are no longer present
- Update stats key

-[ ] indexer: add monitor for DispenserActivated and DispenserDeactivated events (https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/dispenser/Dispenser.sol#L39-L45). If such an event is detected, get all ddos with a match and update it (remove dispenser/add dispenser)

-[ ] indexer: add monitor for ExchangeActivated and ExchangeDeactivated events (https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/fixedRate/FixedRateExchange.sol#L103-L111). If such an event is detected, get all ddos with a match and update it (remove dispenser/add fixed rate)

-[ ] indexer: add monitor for ExchangeRateChanged event(https://github.com/oceanprotocol/contracts/blob/main/contracts/pools/fixedRate/FixedRateExchange.sol#L90C11-L94). If such an event is detected, get all ddos with a match and update them with the new rate

-[ ] indexer: add monitor for OrderStarted event(https://github.com/oceanprotocol/contracts/blob/main/contracts/templates/ERC20TemplateEnterprise.sol#L85-L93). If such an event is detected, get all ddos with a match and update orders count

@alexcos20 alexcos20 added the Type: Enhancement New feature or request label Jul 5, 2024
This was referenced Jul 5, 2024
@alexcos20 alexcos20 added this to the beta milestone Jul 5, 2024
@alexcos20 alexcos20 changed the title DDO: Prices for exchanges/dispensers DDO: Stats and Prices for exchanges/dispensers Jul 5, 2024
@FilipMasar
Copy link
Collaborator

FilipMasar commented Jul 16, 2024

Updated DDO type (based on what we talked about at EOC meeting)

interface TokenInfo {
  address: string
  name: string
  symbol: string
  decimals?: number
}

interface ServicePrice {
  type: 'fixedrate' | 'dispenser'
  price: string
  contract: string
  token?: TokenInfo
  exchangeId?: string
}

interface ServiceStat {
  datatokenAddress: string
  name: string
  symbol: string
  serviceId: string
  orders: number
  prices: ServicePrice[]
}

interface OffChain {
  stats: {
    services: ServiceStat[]
  }
}

interface AssetExtended extends Asset {
  offchain: OffChain
}

@mihaisc
Copy link
Contributor

mihaisc commented Oct 14, 2024

needs update to move all extra metadata in one root key, so we can easily exclude it from hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants