Skip to content

Commit

Permalink
Merge pull request #839 from comdex-official/bindings-price
Browse files Browse the repository at this point in the history
added wasm bindings to fetch price per asset
  • Loading branch information
dheerajkd30 authored Sep 1, 2023
2 parents 026c3b9 + 68f1a7e commit ef85921
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 13 deletions.
12 changes: 11 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ import (
cwasm "github.com/comdex-official/comdex/app/wasm"

mv12 "github.com/comdex-official/comdex/app/upgrades/mainnet/v12"
tv12_1 "github.com/comdex-official/comdex/app/upgrades/testnet/v12_1"
)

const (
Expand Down Expand Up @@ -842,7 +843,7 @@ func New(
}
supportedFeatures := "iterator,staking,stargate,comdex,cosmwasm_1_1"

wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper, &app.LendKeeper, &app.LiquidityKeeper), wasmOpts...)
wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper, &app.LendKeeper, &app.LiquidityKeeper, &app.MarketKeeper), wasmOpts...)

app.WasmKeeper = wasmkeeper.NewKeeper(
app.cdc,
Expand Down Expand Up @@ -1456,6 +1457,11 @@ func (a *App) registerUpgradeHandlers() {
mv12.UpgradeName,
mv12.CreateUpgradeHandlerV12(a.mm, a.configurator, a.ICQKeeper, a.NewliqKeeper, a.NewaucKeeper, a.BankKeeper, a.CollectorKeeper, a.LendKeeper, a.AuctionKeeper, a.LiquidationKeeper, a.AssetKeeper),
)
case upgradeInfo.Name == tv12_1.UpgradeName:
a.UpgradeKeeper.SetUpgradeHandler(
tv12_1.UpgradeName,
tv12_1.CreateUpgradeHandlerV121(a.mm, a.configurator, a.WasmKeeper),
)
}

var storeUpgrades *storetypes.StoreUpgrades
Expand All @@ -1479,6 +1485,10 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *
auctionsV2types.ModuleName,
},
}
case upgradeInfo.Name == tv12_1.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{},
}
}
return storeUpgrades
}
15 changes: 15 additions & 0 deletions app/upgrades/testnet/v12_1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v12_1

const (
UpgradeName = "v12.1.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
36 changes: 36 additions & 0 deletions app/upgrades/testnet/v12_1/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package v12_1

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// An error occurred during the creation of the CMST/STJUNO pair, as it was mistakenly created in the Harbor app (ID-2) instead of the cSwap app (ID-1).
// As a result, the transaction fee was charged to the creator of the pair, who is entitled to a refund.
// The provided code is designed to initiate the refund process.
// The transaction hash for the pair creation is EF408AD53B8BB0469C2A593E4792CB45552BD6495753CC2C810A1E4D82F3982F.
// MintScan - https://www.mintscan.io/comdex/txs/EF408AD53B8BB0469C2A593E4792CB45552BD6495753CC2C810A1E4D82F3982F

func CreateUpgradeHandlerV121(
mm *module.Manager,
configurator module.Configurator,
wasmKeeper wasmkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Applying test net upgrade - v.12.1.0")

vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}

// update wasm to permissionless
wasmParams := wasmKeeper.GetParams(ctx)
wasmParams.CodeUploadAccess = wasmtypes.AllowEverybody
wasmKeeper.SetParams(ctx, wasmParams)
return vm, err
}
}
9 changes: 9 additions & 0 deletions app/wasm/bindings/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ComdexQuery struct {
CheckBorrowed *CheckBorrowed `json:"check_borrowed,omitempty"`
CheckLiquidityProvided *CheckLiquidityProvided `json:"check_liquidity_provided,omitempty"`
GetPoolByApp *GetPoolByApp `json:"get_pool_by_app,omitempty"`
GetAssetPrice *GetAssetPrice `json:"get_asset_price,omitempty"`
}

type AppData struct {
Expand Down Expand Up @@ -291,3 +292,11 @@ type GetPoolByApp struct {
type GetPoolByAppResponse struct {
Pools []uint64 `json:"pools"`
}

type GetAssetPrice struct {
AssetID uint64 `json:"asset_id"`
}

type GetAssetPriceResponse struct {
Price uint64 `json:"price"`
}
Loading

0 comments on commit ef85921

Please sign in to comment.