Skip to content

Commit

Permalink
Merge pull request #687 from UnUniFi/develop
Browse files Browse the repository at this point in the history
For release v3.2.2
  • Loading branch information
Senna46 authored Aug 18, 2023
2 parents c2881f2 + d97c9e7 commit 481a721
Show file tree
Hide file tree
Showing 32 changed files with 4,698 additions and 602 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
v3_1 "github.com/UnUniFi/chain/app/upgrades/v3.1"
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"
)

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

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

var (
Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v3.2.2/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v3_2_2

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

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

const UpgradeName string = "v3_2_2"

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

import (
"fmt"
"strings"

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

minttypes "github.com/cosmos/cosmos-sdk/x/mint/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))

// migrate vaults
keepers.YieldaggregatorKeeper.MigrateAllLegacyVaults(ctx)
// migrate strategies
keepers.YieldaggregatorKeeper.MigrateAllLegacyStrategies(ctx)
// migrate denoms
shouldMigrateDenoms := false
keepers.BankKeeper.IterateTotalSupply(ctx, func(coin sdk.Coin) bool {
denomParts := strings.Split(coin.Denom, "/")
if len(denomParts) != 3 {
return false
}
if denomParts[0] == "yield-aggregator" {
shouldMigrateDenoms = true
return true
}
return false
})

if shouldMigrateDenoms {
balances := keepers.BankKeeper.GetAccountsBalances(ctx)
for _, balance := range balances {
for _, coin := range balance.Coins {
denomParts := strings.Split(coin.Denom, "/")

if len(denomParts) != 3 {
continue
}
if denomParts[0] != "yield-aggregator" {
continue
}
err := keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, balance.GetAddress(), yieldaggregatortypes.ModuleName, sdk.NewCoins(coin))
if err != nil {
return vm, err
}
err = keepers.BankKeeper.BurnCoins(ctx, yieldaggregatortypes.ModuleName, sdk.NewCoins(coin))
if err != nil {
return vm, err
}

denomParts[0] = yieldaggregatortypes.ModuleName
migratedCoin := sdk.NewCoin(strings.Join(denomParts, "/"), coin.Amount)
err = keepers.BankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.Coins{migratedCoin})
if err != nil {
return vm, err
}
err = keepers.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, balance.GetAddress(), sdk.Coins{migratedCoin})
if err != nil {
return vm, err
}
}
}
}

return mm.RunMigrations(ctx, configurator, vm)
}
}
77 changes: 64 additions & 13 deletions proto/ununifi/yieldaggregator/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ service Query {
option (google.api.http).get = "/ununifi/yieldaggregator/vaults";
}

rpc VaultAllByShareHolder(QueryAllVaultByShareHolderRequest) returns (QueryAllVaultByShareHolderResponse) {
option (google.api.http).get = "/ununifi/yieldaggregator/vaults/share-holders/{share_holder}";
}

rpc Vault(QueryGetVaultRequest) returns (QueryGetVaultResponse) {
option (google.api.http).get = "/ununifi/yieldaggregator/vaults/{id}";
}
Expand Down Expand Up @@ -59,34 +63,60 @@ message QueryAllVaultRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message VaultContainer {
Vault vault = 1 [(gogoproto.nullable) = false];
string total_bonded_amount = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string total_unbonding_amount = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string withdraw_reserve = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

message QueryAllVaultResponse {
repeated Vault vaults = 1 [(gogoproto.nullable) = false];
repeated VaultContainer vaults = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryAllVaultByShareHolderRequest {
string share_holder = 1;
}

message QueryAllVaultByShareHolderResponse {
repeated VaultContainer vaults = 1 [(gogoproto.nullable) = false];
}

message QueryGetVaultRequest {
uint64 id = 1;
}

message QueryGetVaultResponse {
Vault vault = 1 [(gogoproto.nullable) = false];
repeated Strategy strategies = 2 [(gogoproto.nullable) = false];
string vault_address = 3;
string total_bonded_amount = 4 [
Vault vault = 1 [(gogoproto.nullable) = false];
string total_bonded_amount = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string total_unbonding_amount = 5 [
string total_unbonding_amount = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string total_withdrawal_balance = 6 [
string withdraw_reserve = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
repeated Strategy strategies = 5 [(gogoproto.nullable) = false];
}

message QueryAllStrategyRequest {
Expand All @@ -95,7 +125,7 @@ message QueryAllStrategyRequest {
}

message QueryAllStrategyResponse {
repeated Strategy strategies = 1 [(gogoproto.nullable) = false];
repeated StrategyContainer strategies = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

Expand All @@ -104,8 +134,27 @@ message QueryGetStrategyRequest {
uint64 id = 2;
}

message StrategyContainer {
Strategy strategy = 1 [(gogoproto.nullable) = false];
string deposit_fee_rate = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
string withdraw_fee_rate = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
string performance_fee_rate = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}

message QueryGetStrategyResponse {
Strategy strategy = 1 [(gogoproto.nullable) = false];
StrategyContainer strategy = 1 [(gogoproto.nullable) = false];
}

message QueryEstimateMintAmountRequest {
Expand All @@ -123,5 +172,7 @@ message QueryEstimateRedeemAmountRequest {
}

message QueryEstimateRedeemAmountResponse {
cosmos.base.v1beta1.Coin redeem_amount = 1 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin share_amount = 1 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin fee = 2 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin redeem_amount = 3 [(gogoproto.nullable) = false];
}
49 changes: 43 additions & 6 deletions proto/ununifi/yieldaggregator/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ service Msg {
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
rpc RegisterStrategy(MsgRegisterStrategy) returns (MsgRegisterStrategyResponse);
rpc DeleteVault(MsgDeleteVault) returns (MsgDeleteVaultResponse);
rpc UpdateVault(MsgUpdateVault) returns (MsgUpdateVaultResponse);
rpc UpdateStrategy(MsgUpdateStrategy) returns (MsgUpdateStrategyResponse);
}

// this line is used by starport scaffolding # proto/tx/message
Expand Down Expand Up @@ -63,25 +65,43 @@ message MsgCreateVault {

string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string denom = 2;
string commission_rate = 3 [
string name = 3;
string description = 4;
string commission_rate = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
string withdraw_reserve_rate = 4 [
string withdraw_reserve_rate = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
repeated StrategyWeight strategy_weights = 5 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin fee = 6 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin deposit = 7 [(gogoproto.nullable) = false];
repeated StrategyWeight strategy_weights = 7 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin fee = 8 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin deposit = 9 [(gogoproto.nullable) = false];
string fee_collector_address = 10;
}

message MsgCreateVaultResponse {
uint64 id = 1;
}

message MsgUpdateVault {
option (cosmos.msg.v1.signer) = "sender";

option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 id = 2;
string name = 3;
string description = 4;
string fee_collector_address = 5;
}

message MsgUpdateVaultResponse {}

message MsgTransferVaultOwnership {
option (cosmos.msg.v1.signer) = "sender";

Expand Down Expand Up @@ -117,11 +137,28 @@ message MsgRegisterStrategy {
string denom = 2;
string contract_address = 3;
string name = 4;
string git_url = 5;
string description = 5;
string git_url = 6;
}

message MsgRegisterStrategyResponse {}

message MsgUpdateStrategy {
option (cosmos.msg.v1.signer) = "sender";

option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string denom = 2;
uint64 id = 3;
string name = 4;
string description = 5;
string git_url = 6;
}

message MsgUpdateStrategyResponse {}

message MsgDeleteVault {
option (cosmos.msg.v1.signer) = "sender";

Expand Down
Loading

0 comments on commit 481a721

Please sign in to comment.