Skip to content

Commit

Permalink
Merge pull request #708 from UnUniFi/develop
Browse files Browse the repository at this point in the history
feat: v4.0.0 changes to main
  • Loading branch information
Senna46 authored Nov 20, 2023
2 parents f48528f + c45a9d9 commit 48d4980
Show file tree
Hide file tree
Showing 113 changed files with 14,388 additions and 5,266 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
v3_2 "github.com/UnUniFi/chain/app/upgrades/v3.2"
v3_2_1 "github.com/UnUniFi/chain/app/upgrades/v3.2.1"
v3_2_2 "github.com/UnUniFi/chain/app/upgrades/v3.2.2"
v4 "github.com/UnUniFi/chain/app/upgrades/v4"
)

const Name = "ununifi"
Expand Down Expand Up @@ -106,7 +107,7 @@ var (
stakeibctypes.ModuleName: true,
}

Upgrades = []upgrades.Upgrade{v3.Upgrade, v3_1.Upgrade, v3_2.Upgrade, v3_2_1.Upgrade, v3_2_2.Upgrade}
Upgrades = []upgrades.Upgrade{v3.Upgrade, v3_1.Upgrade, v3_2.Upgrade, v3_2_1.Upgrade, v3_2_2.Upgrade, v4.Upgrade}
)

var (
Expand Down
33 changes: 29 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"

Expand All @@ -87,7 +88,7 @@ import (
icacallbackstypes "github.com/UnUniFi/chain/x/yieldaggregator/submodules/icacallbacks/types"
interchainquerykeeper "github.com/UnUniFi/chain/x/yieldaggregator/submodules/interchainquery/keeper"
interchainquerytypes "github.com/UnUniFi/chain/x/yieldaggregator/submodules/interchainquery/types"
records "github.com/UnUniFi/chain/x/yieldaggregator/submodules/records"
"github.com/UnUniFi/chain/x/yieldaggregator/submodules/records"
recordskeeper "github.com/UnUniFi/chain/x/yieldaggregator/submodules/records/keeper"
recordstypes "github.com/UnUniFi/chain/x/yieldaggregator/submodules/records/types"
stakeibc "github.com/UnUniFi/chain/x/yieldaggregator/submodules/stakeibc"
Expand Down Expand Up @@ -140,7 +141,11 @@ type AppKeepers struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasm.Keeper
// IBC hooks
IBCHooksKeeper ibchookskeeper.Keeper
IBCHooksKeeper ibchookskeeper.Keeper
Ics20WasmHooks ibchooks.WasmHooks
ContractKeeper *wasmkeeper.PermissionedKeeper
HooksTransferIBCModule ibchooks.IBCMiddleware
HooksICS4Wrapper ibchooks.ICS4Middleware

NftbackedloanKeeper nftbackedloankeeper.Keeper
NftfactoryKeeper nftfactorykeeper.Keeper
Expand Down Expand Up @@ -376,13 +381,18 @@ func NewAppKeeper(
appKeepers.IBCHooksKeeper = ibchookskeeper.NewKeeper(
appKeepers.keys[ibchookstypes.StoreKey],
)
appKeepers.Ics20WasmHooks = ibchooks.NewWasmHooks(&appKeepers.IBCHooksKeeper, nil, accountAddressPrefix) // The contract keeper needs to be set later
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.Ics20WasmHooks,
)

// Create Transfer Keepers
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
appKeepers.IBCFeeKeeper,
appKeepers.HooksICS4Wrapper, // essentially still app.IBCKeeper.ChannelKeeper under the hood because no hook overrides
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
Expand Down Expand Up @@ -422,7 +432,13 @@ func NewAppKeeper(
// if we want to allow any custom callbacks
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2"

wasmOpts = append(wasmbinding.RegisterCustomPlugins(&appKeepers.BankKeeper, &appKeepers.InterchainqueryKeeper, &appKeepers.RecordsKeeper), wasmOpts...)
wasmOpts = append(
wasmbinding.RegisterCustomPlugins(
&appKeepers.BankKeeper,
&appKeepers.InterchainqueryKeeper,
&appKeepers.RecordsKeeper,
&appKeepers.YieldaggregatorKeeper),
wasmOpts...)

appKeepers.WasmKeeper = wasm.NewKeeper(
appCodec,
Expand All @@ -445,6 +461,10 @@ func NewAppKeeper(
wasmOpts...,
)

// Pass the contract keeper to all the structs (generally ICS4Wrappers for ibc middlewares) that need it
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper

// Instantiate the builder keeper, store keys, and module manager
appKeepers.BuilderKeeper = builderkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -527,6 +547,7 @@ func NewAppKeeper(
appKeepers.keys[interchainquerytypes.StoreKey],
appKeepers.IBCKeeper,
&appKeepers.WasmKeeper,
appKeepers.WasmKeeper,
)

scopedRecordsKeeper := appKeepers.CapabilityKeeper.ScopeToModule(recordstypes.ModuleName)
Expand All @@ -542,6 +563,7 @@ func NewAppKeeper(
*appKeepers.IBCKeeper,
appKeepers.IcacallbacksKeeper,
&appKeepers.WasmKeeper,
appKeepers.WasmKeeper,
)

scopedStakeibcKeeper := appKeepers.CapabilityKeeper.ScopeToModule(stakeibctypes.ModuleName)
Expand Down Expand Up @@ -629,6 +651,9 @@ func NewAppKeeper(
transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
transferStack = records.NewIBCModule(appKeepers.RecordsKeeper, transferStack)
transferStack = ibcfee.NewIBCMiddleware(transferStack, appKeepers.IBCFeeKeeper)
// Add Hooks Middleware
appKeepers.HooksTransferIBCModule = ibchooks.NewIBCMiddleware(transferStack, &appKeepers.HooksICS4Wrapper)
transferStack = appKeepers.HooksTransferIBCModule

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v4/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v4

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/UnUniFi/chain/app/upgrades"
)

const UpgradeName string = "v4"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
135 changes: 135 additions & 0 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package v4

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/UnUniFi/chain/app/keepers"
"github.com/UnUniFi/chain/app/upgrades"
yieldaggregatortypes "github.com/UnUniFi/chain/x/yieldaggregator/types"
)

func CreateUpgradeHandler(mm *module.Manager,
configurator module.Configurator,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info(fmt.Sprintf("update start:%s", UpgradeName))

// yieldaggregator params upgrade
iyaParam, err := keepers.YieldaggregatorKeeper.GetParams(ctx)
if err != nil {
return vm, err
}
iyaParam.IbcTransferTimeoutNanos = 1800000000000 // 3min
_ = keepers.YieldaggregatorKeeper.SetParams(ctx, iyaParam)

// initialize DenomInfos, SymbolInfos, IntermediaryAccountInfo
denomInfos := []yieldaggregatortypes.DenomInfo{}
symbolInfos := []yieldaggregatortypes.SymbolInfo{}
interAcc := yieldaggregatortypes.IntermediaryAccountInfo{}
if ctx.ChainID() == "ununifi-beta-v1" { // mainnet
denomInfos = []yieldaggregatortypes.DenomInfo{
{ // ATOM.osmosis
Denom: "ibc/20D06D04E1BC1FAC482FECC06C2E2879A596904D64D8BA3285B4A3789DEAF910",
Symbol: "ATOM",
Channels: []yieldaggregatortypes.TransferChannel{
{
RecvChainId: "cosmoshub-4",
SendChainId: "osmosis-1",
ChannelId: "channel-0",
},
{
RecvChainId: "osmosis-1",
SendChainId: "ununifi-beta-v1",
ChannelId: "channel-4",
},
},
},
{ // ATOM.cosmoshub
Denom: "ibc/25418646C017D377ADF3202FF1E43590D0DAE3346E594E8D78176A139A928F88",
Symbol: "ATOM",
Channels: []yieldaggregatortypes.TransferChannel{
{
RecvChainId: "cosmoshub-4",
SendChainId: "ununifi-beta-v1",
ChannelId: "channel-7",
},
},
},
{ // OSMO.osmosis
Denom: "ibc/05AC4BBA78C5951339A47DD1BC1E7FC922A9311DF81C85745B1C162F516FF2F1",
Symbol: "OSMO",
Channels: []yieldaggregatortypes.TransferChannel{
{
RecvChainId: "osmosis-1",
SendChainId: "ununifi-beta-v1",
ChannelId: "channel-4",
},
},
},
}

symbolInfos = []yieldaggregatortypes.SymbolInfo{
{
Symbol: "ATOM",
NativeChainId: "cosmoshub-4",
Channels: []yieldaggregatortypes.TransferChannel{
{
SendChainId: "cosmoshub-4",
RecvChainId: "osmosis-1",
ChannelId: "channel-141",
},
{
SendChainId: "cosmoshub-4",
RecvChainId: "ununifi-beta-v1",
ChannelId: "channel-683",
},
},
},
{
Symbol: "OSMO",
NativeChainId: "osmosis-1",
Channels: []yieldaggregatortypes.TransferChannel{
{
SendChainId: "osmosis-1",
RecvChainId: "ununifi-beta-v1",
ChannelId: "channel-2638",
},
},
},
}

interAcc = yieldaggregatortypes.IntermediaryAccountInfo{
Addrs: []yieldaggregatortypes.ChainAddress{
{
ChainId: "cosmoshub-4",
Address: "cosmos1fvhcnyddukcqfnt7nlwv3thm5we22lyxyxylr9h77cvgkcn43xfs60ggw8",
},
{
ChainId: "osmosis-1",
Address: "osmo1fvhcnyddukcqfnt7nlwv3thm5we22lyxyxylr9h77cvgkcn43xfs0jssep",
},
},
}
}

for _, denomInfo := range denomInfos {
keepers.YieldaggregatorKeeper.SetDenomInfo(ctx, denomInfo)
}

for _, symbolInfo := range symbolInfos {
keepers.YieldaggregatorKeeper.SetSymbolInfo(ctx, symbolInfo)
}

keepers.YieldaggregatorKeeper.SetIntermediaryAccountInfo(ctx, interAcc.Addrs)

// migrate vaults
keepers.YieldaggregatorKeeper.MigrateAllLegacyVaults(ctx)

return mm.RunMigrations(ctx, configurator, vm)
}
}
Loading

0 comments on commit 48d4980

Please sign in to comment.