osmosis icon indicating copy to clipboard operation
osmosis copied to clipboard

Cannot Estimate Swap in v12

Open samsheff opened this issue 3 years ago • 5 comments

Background

  • We cannot estimate a swap in the latest version. Our project is using the v12 version of the osmosis chain and sdk on testnet and we get a very generic error trying to query for an estimated swap amount. It looks like a lot changed in the API in the latest version and we cannot find a working example.
  • We've tried porting implementations like this one, in addition to several other examples: https://github.com/marsthechocolatebar/osmosis-sample-smc/blob/e523349ba1ac23efeaa2af623f9299b69d11d03e/contracts/executor/src/contract.rs#L72
  • The error we get is very generic. It looks like this: Error: rpc error: code = InvalidArgument desc = Generic error: Querier contract error: codespace: sdk, code: 5: query wasm contract failed: invalid request

If you could at least point us in the right direction, it would be greatly appreciated. I've looked through all the docs and implementations that I could find, and only am writing as a last resort. If you need additional info/context I can provide it. Thank you in advance.

samsheff avatar Oct 04 '22 11:10 samsheff

The current EstimateSwap implementation requires the sender account to have balance of the asset you're trying to estimate. This should be getting fixed in the next upgrade, the PR is currently up in https://github.com/osmosis-labs/osmosis/pull/2764

mattverse avatar Oct 05 '22 07:10 mattverse

@mattverse That you so much for this, that was the missing link.

One more question - we cant cast to the EstimatePriceResponse struct after querying. Says that it cant find the amount field. Is this another API change or something you guys know about?

We get this: Error: rpc error: code = InvalidArgument desc = Error parsing into type osmo_bindings::query::EstimatePriceResponse: missing field `amount`: query wasm contract failed: invalid request

samsheff avatar Oct 05 '22 13:10 samsheff

what's the repo or the source of the osmo_bindings package you were using?

mattverse avatar Oct 06 '22 12:10 mattverse

osmo_bindings are at 0.5.1 - is there a different one we need to use? osmosis_std is at 0.12.0 as well.

Source is just a rust crate, we dont pull from git.

Update: Tried the latest version from the repo instead of from crates. Looks like you guys took out or renamed the EstimatePriceResponse struct? We still get the same error with that version, even for spot pricing. But that reponse type isnt there anymore.

samsheff avatar Oct 06 '22 15:10 samsheff

@mattverse Is there anything you can point us to? We're still stuck on this... I've tried just about everything I can think of.

If you have a moment I'd be very grateful!

samsheff avatar Oct 09 '22 00:10 samsheff

@mattverse Hey, we're still stuck on this. I've tried everything. Same error as above.

If there's any way you could point us in the right direction that would be a lifesaver. Thanks

samsheff avatar Oct 24 '22 05:10 samsheff

Hey srry for the late reply on this. @iboss-ptk do you have an idea of the osmo_bindings and osmosis_std?

mattverse avatar Oct 26 '22 00:10 mattverse

can you try these msgs instead see if it works?

https://github.com/osmosis-labs/osmosis-rust/blob/28ffd12efce20ee36bb78505e5af136b26344b70/packages/osmosis-std/src/types/osmosis/gamm/v1beta1.rs#L801-L886

iboss-ptk avatar Oct 31 '22 08:10 iboss-ptk

hello. @samsheff did you solve this problem in v13? we also stucked in same issue. and faced following error.

Error: Query failed with (18): Generic error: Querier contract error: codespace: sdk, code: 5: query wasm contract failed: invalid request
    at QueryClient.queryUnverified (/Users/agrajak/.npm/_npx/ea2a98de724f1c93/node_modules/@cosmjs/stargate/build/queryclient/queryclient.js:106:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.queryContractSmart (/Users/agrajak/.npm/_npx/ea2a98de724f1c93/node_modules/@cosmjs/cosmwasm-stargate/build/modules/wasm/queries.js:59:34)
    at async CosmWasmClient.queryContractSmart (/Users/agrajak/.npm/_npx/ea2a98de724f1c93/node_modules/@cosmjs/cosmwasm-stargate/build/cosmwasmclient.js:302:20)

AtticusDavid avatar Dec 11 '22 11:12 AtticusDavid