Skip to content

[oracle][wasm] Add support for wasm custom querier#63

Merged
udpatil merged 3 commits intomasterfrom
wasmbindings
Jun 29, 2022
Merged

[oracle][wasm] Add support for wasm custom querier#63
udpatil merged 3 commits intomasterfrom
wasmbindings

Conversation

@udpatil
Copy link
Collaborator

@udpatil udpatil commented Jun 28, 2022

Added unit test, and also tested with sei-cosmwasm sei-tester contract to verify the query works end to end

return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
var contractQuery SeiQueryWrapper
// TODO: debugging, remove this
ctx.Logger().Error("received a custom query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change this to debug level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof sorry, I needed to remove this I forgot to remove from all places 🤦‍♂️

switch contractQuery.Route {
case OracleRoute:
// TODO: debugging, remove this
ctx.Logger().Error("parse route: oracle query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -0,0 +1,282 @@
package wasmbinding

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we plan to keep this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we'll use this when integrating txs from cosmwasm. we'll handle messages (txs) separately from queries so this one will be the plugin for message handling

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we want a custom message dispatcher, rather than use the default message dispatcher with a custom CustomMsg encoder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the default message dispatcher won't allow messages to the custom modules, right? or is that not the case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows custom message but the default behavior is to no-op. If you add something like this to wasmopts you can override the no-op behavior:

	wasmopts := []wasm.Option{wasmkeeper.WithMessageEncoders(&wasmkeeper.MessageEncoders{
		Custom: xwasm.DexCustomEncoder,
	})}

Of course we can change DexCustomEncoder to be something more generic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, in that case i'll remove these files

case parsedQuery.ExchangeRates != nil:
res, err := qp.oracleHandler.GetExchangeRates(ctx)
if err != nil {
return nil, sdkerrors.Wrap(err, "sei oracle GetExchangeRates query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that these errors will be user facing, let's make these error messages more descriptive. I.e.

  • Unable to send GetExchangeRates query
  • Unable to decode GetExchangeRates response

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, will fix 👍

queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: CustomQuerier(wasmQueryPlugin),
})
// messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm if not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need this for when we do integrate message handling (which would be soon presumably for adding in things like PlaceOrder or CancelOrder from smart contract to dex


type WasmQueryExchangeRatesRequest struct{}

// type WasmQueryOracleExchangeRate struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm if not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, will do

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.OracleKeeper), wasmOpts...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can set wasmopts here https://github.com/sei-protocol/sei-chain/blob/master/cmd/seid/cmd/root.go#L233 just in case some future logics in New need to make use of wasmOpts but happens before this line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do that there because we need to already have an OracleKeeper for this option to be added, and the keepers are all initialized in New() not in root, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codchen wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah you're right

@udpatil udpatil merged commit 60051cc into master Jun 29, 2022
@udpatil udpatil deleted the wasmbindings branch June 29, 2022 19:49
masih pushed a commit that referenced this pull request Sep 26, 2025
masih pushed a commit that referenced this pull request Sep 29, 2025
## Describe your changes and provide context
#331 

Adds helpers to support deferring mints and burn messages. Without this,
we would need to define the module account as a dependency in the ACL
mapping for concurrent TXs, and that would result in all mint/burns
running sequentially, which is already the existing behavior.

This keeps track of the mints and burns a mem-var and in sei-chain, at
the end of delieverTx, they are written all at once

## Testing performed to validate your change
See #331
masih pushed a commit that referenced this pull request Sep 30, 2025
## Describe your changes and provide context
#331 

Adds helpers to support deferring mints and burn messages. Without this,
we would need to define the module account as a dependency in the ACL
mapping for concurrent TXs, and that would result in all mint/burns
running sequentially, which is already the existing behavior.

This keeps track of the mints and burns a mem-var and in sei-chain, at
the end of delieverTx, they are written all at once

## Testing performed to validate your change
See #331
masih pushed a commit that referenced this pull request Oct 1, 2025
* Default with simple priority

* fix tests

* fix more tests

* update mockery

* update mockery

* Fix Stop call
masih pushed a commit that referenced this pull request Oct 9, 2025
Fix edge case for iterating over tombstoned value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants