CosmosContracts / bounties

MIT License
25 stars 12 forks source link

Query price over IBC #5

Closed giansalex closed 2 years ago

giansalex commented 2 years ago

This pr is to share a demo between JUNO UNI testnet and custom osmosis node (gamm IBC).

image

IBC channel

{
      "state": "STATE_OPEN",
      "ordering": "ORDER_UNORDERED",
      "counterparty": {
        "port_id": "gamm",
        "channel_id": "channel-0"
      },
      "connection_hops": [
        "connection-0"
      ],
      "version": "gamm-1",
      "port_id": "wasm.juno1d2r4s2q8kumpmvx6dyj77klhgm5e6fs9njmmz6ye7ukqa77ddtdsafda4d",
      "channel_id": "channel-0"
}

Demo

JakeHartnell commented 2 years ago

Awesome! Can you open source the contract code and link it here? That's an important part of the bounty. :slightly_smiling_face:

JakeHartnell commented 2 years ago

Awesome! Can you open source the contract code and link it here? That's an important part of the bounty. slightly_smiling_face

Still waiting on contract code. :upside_down_face:

VitalyV1337 commented 2 years ago

Did you do any custom modifications to the Osmosis node?

vernonjohnson commented 2 years ago

@VitalyVolozhinov I think he just created a custom Osmosis IBC module that returns price info from the GAMM module. This is a great start, but isn't a representative example of how this would be done in production, given upcoming updates to Osmosis.

Osmosis will soon have cosmwasm bindings for interacting with the AMM. So the Osmosis price fetching logic should be implemented as a cosmwasm contract instead of an IBC module.

Additionally, fetching regular spot price can be easily manipulated, and shouldn't be used in production. The Osmosis team is working on making a more secure TWAP oracle that can be leveraged in cosmwasm contracts.

JakeHartnell commented 2 years ago

@JakeHartnell , this is the source code https://github.com/giansalex/cw-osmo-price

Contract address on Uni Testnet:

Re @verminator23's comment, is this using a custom IBC module? Has that been merged? If not where is the code for that? Would this work with mainnet Osmosis and Juno chains?

VitalyV1337 commented 2 years ago

@JakeHartnell , this is the source code https://github.com/giansalex/cw-osmo-price Contract address on Uni Testnet:

Re @verminator23's comment, is this using a custom IBC module? Has that been merged? If not where is the code for that? Would this work with mainnet Osmosis and Juno chains?

I believe it's not possible to query data over IBC yet from CosmWasm to a Module. I think we have to wait for ICA to be implemented in Osmosis and Juno chains to complete these bounties correctly.

giansalex commented 2 years ago

@JakeHartnell, the challenge is with a custom IBC module, do you need anything else?

JakeHartnell commented 2 years ago

@JakeHartnell, the challenge is with a custom IBC module, do you need anything else?

Has that module been merged into Osmosis? :upside_down_face:

This needs to work with mainnet Juno and mainnet Osmosis.

giansalex commented 2 years ago

but will osmosis accept a custom module? and if they don't accept it, these challenges are unviable.

JakeHartnell commented 2 years ago

but will osmosis accept a custom module? and if they don't accept it, these challenges are unviable.

Worth a shot. Can work out a custom payout with @dimiandre if they are unviable. Part of the reason the bounties are high is that there are lots of pieces.

giansalex commented 2 years ago

I was also working on the swap challenge, and i was able to get it to work. image

JakeHartnell commented 2 years ago

The only thing that would be missing is to integrate the ibc module in osmosis, but that is out of my reach.

Can you give it your best effort? At least submit a PR and link it here?

If anything, it's an important path for discussion. If they are against adding IBC modules for these things, and want to go purely the CosmWasm route then we have our answer.

dimiandre commented 2 years ago

Definitely an awesome job. Can you share access to the code?

And as jake said would be a big plus if you can provide a PR to osmosis repository, then we can help communicating with osmosis community to take this on mainnet.

For bounty payments maybe we can split in phases

giansalex commented 2 years ago

ok, i will prepare the pull request

giansalex commented 2 years ago

For osmosis mainnet, i need to wait for cosmwasm or IBC queries

JakeHartnell commented 2 years ago

For osmosis mainnet, i need to wait for cosmwasm or IBC queries

Saw this. Thanks for the investigation, we're going to do a partial payout for this as it's blocked. Still this was very helpful. :pray:

giansalex commented 2 years ago

I am sharing the Swap module used in another example, it's an IBC module as @JakeHartnell suggested at some point, based on the middleware approach, passed all ibc-transfer tests. https://github.com/disperze/ibc-osmo/tree/master/x/intergamm

There is also a branch for liquidity pool https://github.com/disperze/ibc-osmo/tree/pools

Testnet: osmos: https://osmosis-ibc.web.app/ juno contract: juno1wnx2pe5k8gzd7h2phm7xkg5fxqp380kf8tx50nzlxvzg66hksx8q558ujn