Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

New pf VARA/USD #210

Closed
guidiaz opened this issue May 22, 2023 · 3 comments
Closed

New pf VARA/USD #210

guidiaz opened this issue May 22, 2023 · 3 comments
Assignees

Comments

@guidiaz
Copy link
Contributor

guidiaz commented May 22, 2023

@guidiaz guidiaz self-assigned this May 22, 2023
@guidiaz
Copy link
Contributor Author

guidiaz commented May 22, 2023

@guidiaz
Copy link
Contributor Author

guidiaz commented May 22, 2023

For some reason, witnet-toolkit is unable to parse as JSON the output from https://api.equilibrefinance.com/api/v1/pairs, when executing this Radon script:

const equilibre = new Witnet.Source("https://api.equilibrefinance.com/api/v1/pairs")
  .parseJSONMap()
  .getArray("data")
  .filter( 
    // From all elements in the array,
    // select the one which "symbol" field
    // matches w/ the one we're looking for
    new Witnet.Script([ Witnet.TYPES.MAP ])
      .getString("symbol")
      .match({ "vAMM-VARA/USDC": true }, false)
  )
  .getMap(0) // Get first (and only) element from the resulting array
  .getMap("token0") 
  .getFloat("price")
  .multiply(10 ** 6) // Use 6 digit precision
  .round() // Cast to integer

@aesedepece
Copy link
Member

For some reason, witnet-toolkit is unable to parse as JSON the output from https://api.equilibrefinance.com/api/v1/pairs, when executing this Radon script:

const equilibre = new Witnet.Source("https://api.equilibrefinance.com/api/v1/pairs")
  .parseJSONMap()
  .getArray("data")
  .filter( 
    // From all elements in the array,
    // select the one which "symbol" field
    // matches w/ the one we're looking for
    new Witnet.Script([ Witnet.TYPES.MAP ])
      .getString("symbol")
      .match({ "vAMM-VARA/USDC": true }, false)
  )
  .getMap(0) // Get first (and only) element from the resulting array
  .getMap("token0") 
  .getFloat("price")
  .multiply(10 ** 6) // Use 6 digit precision
  .round() // Cast to integer

I just tried this on my branch with improved JSON processing (witnet/witnet-rust#2373). It worked!

{"RadonInteger":"41490"}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants