zeitgeist icon indicating copy to clipboard operation
zeitgeist copied to clipboard

[Swaps] getSpotPrices RPC for Scalar markets does not work as expected

Open sea212 opened this issue 2 years ago • 3 comments

After @Robiquet reported the problem of invoking the getSpotPrices rpc for scalar market to me, I was also unable to invoke it correctly. It seems to be impossible to invoke the RPC with correct parameters. The following should work, but it does not:

{
    "scalarOutcome": [
        19,
        "short"
    ]
}

What is going on?

sea212 avatar Mar 17 '22 13:03 sea212

"long", "Long", "Short", 0 and 1 also give the same error message. However a random string or number gives a different error

Robiquet avatar Mar 17 '22 14:03 Robiquet

Any news on this? The new sdk uses the rpc call to fetch prices more heavily and this would need to be fixed for that to work as expected.

yornaath avatar Oct 11 '22 10:10 yornaath

We'll investigate. @yornaath

sea212 avatar Oct 13 '22 11:10 sea212

Currently I am not able to debug this with sdk as it has other issues to fix first.

It seems like SDK needs to update types for get_spot_price after #937 currently I see it has following getSpotPrice: { description: 'get spot price', params: [ { name: 'poolId', type: 'u128', }, { name: 'assetIn', type: 'SwapsAsset', }, { name: 'assetOut', type: 'SwapsAsset', }, { name: 'at', type: 'Option<BlockHash>', }, { name: 'withFees', type: 'bool', }, ], type: 'u128', },

vivekvpandya avatar Feb 13 '23 05:02 vivekvpandya

Following works for me

  console.log( "Vivek " + 
    await api.rpc.swaps.getSpotPrice(
      1,
      { ScalarOutcome: [0, 'long'] },
      { Ztg: null },
      false,
    )
  );

but I have to change following thing in type.json Change

  "ScalarPosition": {
  "_enum": [
    "Long",
    "Short"
  ]
},

to following

  "ScalarPosition": {
  "_enum": [
    "long",
    "short"
  ]
},

vivekvpandya avatar Feb 15 '23 14:02 vivekvpandya

@yornaath @Robiquet as per my above observation it feels this is not an issue on substrate node.

vivekvpandya avatar Feb 22 '23 05:02 vivekvpandya