@azuro-org/toolkit
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Toolkit Package

This package provides helpers to develop an app using Azuro Protocol.

Installation

npm i --save @azuro-org/toolkit

Helpers

aggregateOutcomesByMarkets.ts

This helper function allows you to aggregate outcomes that are obtained from conditions by markets. This function takes an array of conditions and groups outcomes by their market key. It then sorts the outcomes within each market group and returns an array of market objects, each containing an array of outcomes.

Here is an example of how you can use it:

query Game($id: String!) {
  game(id: $id) {
    liquidityPool {
      address
    }
    conditions {
      conditionId
      coreAddress
      outcomes {
        outcomeId
      }
    }
  }
}
type Conditions = {
  conditionId: string
  coreAddress: string
  outcomes: {
    outcomeId: string
  }
}

aggregateOutcomesByMarkets({
  lpAddress: game.liquidityPool.lpAddress,
  conditions: game.conditions,
  dictionaries, // **
})

The result will be of type

type Outcome = {
  selectionName: string
  conditionId: string
  outcomeId: string
  lpAddress: string
  coreAddress: string
}

type OutcomesByMarkets = {
  marketName: string
  outcomes: Outcome[][] // *
}[]

* returned outcomes are wrapped with additional array Outcome[][]

** dictionaries contain a set of texts for each outcome ID used in Azuro. These texts can be used to display outcomes in a user-friendly way and provide more context about what the outcome represents. Dictionaries are an important component of Azuro's infrastructure as they allow for standardized and consistent outcomes across all markets and events. Read more about dictionaries.


You can pass additional data in outcomes if required, the helper will add it to outcomes in the result:

query Game($id: String!) {
  game(id: $id) {
    ...
    conditions {
      ...
      outcomes {
        ...
        odds
      }
    }
  }
}
type MyOutcome = {
  outcomeId: string
  odds: string
}

aggregateOutcomesByMarkets<MyOutcome>(...)

The result will be of type

type Outcome = {
  selectionName: string
  conditionId: string
  outcomeId: string
  lpAddress: string
  coreAddress: string
  odds: string
}

type OutcomesByMarkets = {
  marketName: string
  outcomes: Outcome[][]
}[]

Package Sidebar

Install

npm i @azuro-org/toolkit

Weekly Downloads

370

Version

3.0.0

License

ISC

Unpacked Size

16.3 kB

Total Files

9

Last publish

Collaborators

  • clean_bread
  • on47sky
  • dkazuro
  • azuro-vivanov
  • grammka