Skip to content

Commit

Permalink
Merge pull request #699 from UnUniFi/feat/iya_strategy_v1
Browse files Browse the repository at this point in the history
Update for iya strategy v1
  • Loading branch information
Senna46 authored Nov 20, 2023
2 parents 6e1db9c + e000e5b commit 66839f0
Show file tree
Hide file tree
Showing 112 changed files with 14,309 additions and 5,261 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
10 changes: 9 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,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 Down Expand Up @@ -541,6 +547,7 @@ func NewAppKeeper(
appKeepers.keys[interchainquerytypes.StoreKey],
appKeepers.IBCKeeper,
&appKeepers.WasmKeeper,
appKeepers.WasmKeeper,
)

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

scopedStakeibcKeeper := appKeepers.CapabilityKeeper.ScopeToModule(stakeibctypes.ModuleName)
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{},
},
}
113 changes: 113 additions & 0 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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.ununifi
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.ununifi
Denom: "ibc/25418646C017D377ADF3202FF1E43590D0DAE3346E594E8D78176A139A928F88",
Symbol: "ATOM",
Channels: []yieldaggregatortypes.TransferChannel{
{
RecvChainId: "cosmoshub-4",
SendChainId: "ununifi-beta-v1",
ChannelId: "channel-7",
},
},
},
}

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",
},
},
},
}

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 66839f0

Please sign in to comment.