Skip to content

Commit

Permalink
Merge pull request #120 from notional-labs/dang/add-module-param
Browse files Browse the repository at this point in the history
change some hard code to param
  • Loading branch information
GNaD13 authored Mar 24, 2023
2 parents cf4a1ce + f8fb351 commit b6c7b17
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 283 deletions.
8 changes: 4 additions & 4 deletions proto/feeabstraction/absfee/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ option go_package = "github.com/notional-labs/feeabstraction/v1/x/feeabs/types";

// Params defines the parameters for the feeabs module.
message GenesisState {
Params params = 1 [
(gogoproto.moretags) = "yaml:\"params\"",
(gogoproto.nullable) = false
];
Params params = 1 [
(gogoproto.moretags) = "yaml:\"params\"",
(gogoproto.nullable) = false
];
repeated EpochInfo epochs = 2 [ (gogoproto.nullable) = false ];
string port_id = 3;
}
54 changes: 28 additions & 26 deletions proto/feeabstraction/absfee/v1beta1/osmosisibc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "tendermint/abci/types.proto";

option go_package = "github.com/notional-labs/feeabstraction/v1/x/feeabs/types";


message QueryArithmeticTwapToNowRequest {
uint64 pool_id = 1;
string base_asset = 2;
Expand All @@ -21,40 +20,43 @@ message QueryArithmeticTwapToNowRequest {
}

message QueryArithmeticTwapToNowResponse {
string arithmetic_twap = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"arithmetic_twap\"",
(gogoproto.nullable) = false
];
string arithmetic_twap = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"arithmetic_twap\"",
(gogoproto.nullable) = false
];
}

message InterchainQueryRequest{
bytes data = 1;
string path = 2;
message InterchainQueryRequest {
bytes data = 1;
string path = 2;
}

// InterchainQueryPacketData is comprised of raw query.
message InterchainQueryPacketData {
bytes data = 1;
// optional memo
string memo = 2;
bytes data = 1;
// optional memo
string memo = 2;
}

// InterchainQueryPacketAck is comprised of an ABCI query response with non-deterministic fields left empty (e.g. Codespace, Log, Info and ...).
message InterchainQueryPacketAck {
bytes data = 1;
}
// InterchainQueryPacketAck is comprised of an ABCI query response with
// non-deterministic fields left empty (e.g. Codespace, Log, Info and ...).
message InterchainQueryPacketAck { bytes data = 1; }

message InterchainQueryRequestPacket{
repeated InterchainQueryRequest requests = 1 [(gogoproto.nullable) = false];
message InterchainQueryRequestPacket {
repeated InterchainQueryRequest requests = 1 [ (gogoproto.nullable) = false ];
}

// CosmosQuery contains a list of tendermint ABCI query requests. It should be used when sending queries to an SDK host chain.
// CosmosQuery contains a list of tendermint ABCI query requests. It should be
// used when sending queries to an SDK host chain.
message CosmosQuery {
repeated tendermint.abci.RequestQuery requests = 1 [(gogoproto.nullable) = false];
}

// CosmosResponse contains a list of tendermint ABCI query responses. It should be used when receiving responses from an SDK host chain.
message CosmosResponse {
repeated tendermint.abci.ResponseQuery responses = 1 [(gogoproto.nullable) = false];
}
repeated tendermint.abci.RequestQuery requests = 1
[ (gogoproto.nullable) = false ];
}

// CosmosResponse contains a list of tendermint ABCI query responses. It should
// be used when receiving responses from an SDK host chain.
message CosmosResponse {
repeated tendermint.abci.ResponseQuery responses = 1
[ (gogoproto.nullable) = false ];
}
12 changes: 3 additions & 9 deletions proto/feeabstraction/absfee/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ message Params {
// native ibced in osmosis
string native_ibced_in_osmosis = 1;

// we'll update the fee rate each `osmosis_exchange_rate_update_period`
google.protobuf.Duration osmosis_exchange_rate_update_period = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];

// we'll swap our accumulated osmosis fee to native token each
// `accumulated_osmosis_fee_swap_period`
google.protobuf.Duration accumulated_osmosis_fee_swap_period = 3
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
}
// osmosis query TWAP path
string osmosis_query_twap_path = 2;
}
87 changes: 43 additions & 44 deletions proto/feeabstraction/absfee/v1beta1/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,64 @@ import "google/api/annotations.proto";

option go_package = "github.com/notional-labs/feeabstraction/v1/x/feeabs/types";

message HostChainFeeAbsConfig{
// ibc token is allowed to be used as fee token
string ibc_denom = 1
[(gogoproto.moretags) = "yaml:\"allowed_token\"" ];

// token_in in cross_chain swap contract.
string osmosis_pool_token_denom_in = 2;
message HostChainFeeAbsConfig {
// ibc token is allowed to be used as fee token
string ibc_denom = 1 [ (gogoproto.moretags) = "yaml:\"allowed_token\"" ];

//TODO: middleware address in hostchain, can we refator this logic ?
string middleware_address = 3;
// token_in in cross_chain swap contract.
string osmosis_pool_token_denom_in = 2;

// transfer channel from customer_chain -> host chain
string ibc_transfer_channel = 4;
// TODO: middleware address in hostchain, can we refator this logic ?
string middleware_address = 3;

// transfer channel from host chain -> osmosis
string host_zone_ibc_transfer_channel = 5;
// transfer channel from customer_chain -> host chain
string ibc_transfer_channel = 4;

// crosschain-swap contract address
string crosschain_swap_address = 6;
// transfer channel from host chain -> osmosis
string host_zone_ibc_transfer_channel = 5;

// pool id
uint64 pool_id = 7;
// crosschain-swap contract address
string crosschain_swap_address = 6;

// Active
bool is_osmosis = 8;
// pool id
uint64 pool_id = 7;

// Frozen
bool frozen = 9;
// Active
bool is_osmosis = 8;

// Query channel
string osmosis_query_channel = 10;
// Frozen
bool frozen = 9;

// Query channel
string osmosis_query_channel = 10;
}

message AddHostZoneProposal {
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
}

message DeleteHostZoneProposal {
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
}

message SetHostZoneProposal {
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
option (gogoproto.goproto_getters) = false;
// the title of the proposal
string title = 1;
// the description of the proposal
string description = 2;
// the host chain config
HostChainFeeAbsConfig host_chain_config = 3;
}
21 changes: 12 additions & 9 deletions proto/feeabstraction/absfee/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ service Query {
"/fee-abstraction/feeabs/v1/host-chain-config/{ibc_denom}";
}

rpc AllHostChainConfig(AllQueryHostChainConfigRequest) returns (AllQueryHostChainConfigRespone) {
option (google.api.http).get = "/fee-abstraction/feeabs/v1/all-host-chain-config";
}}
rpc AllHostChainConfig(AllQueryHostChainConfigRequest)
returns (AllQueryHostChainConfigRespone) {
option (google.api.http).get =
"/fee-abstraction/feeabs/v1/all-host-chain-config";
}
}

message QueryHostChainConfigRequest { string ibc_denom = 1; }

Expand Down Expand Up @@ -60,12 +63,12 @@ message QueryOsmosisArithmeticTwapResponse {
message QueryFeeabsModuleBalacesRequest {}

message QueryFeeabsModuleBalacesResponse {
repeated cosmos.base.v1beta1.Coin balances = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"balances\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string address = 2;
repeated cosmos.base.v1beta1.Coin balances = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"balances\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string address = 2;
}

message AllQueryHostChainConfigRequest {}
Expand Down
27 changes: 14 additions & 13 deletions proto/feeabstraction/absfee/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@ option go_package = "github.com/notional-labs/feeabstraction/v1/x/feeabs/types";

// Msg is the cosmos.group.v1 Msg service.
service Msg {
rpc SendQueryIbcDenomTWAP(MsgSendQueryIbcDenomTWAP) returns (MsgSendQueryIbcDenomTWAPResponse);
rpc SwapCrossChain(MsgSwapCrossChain) returns (MsgSwapCrossChainResponse);
rpc FundFeeAbsModuleAccount(MsgFundFeeAbsModuleAccount) returns (MsgFundFeeAbsModuleAccountResponse);
rpc SendQueryIbcDenomTWAP(MsgSendQueryIbcDenomTWAP)
returns (MsgSendQueryIbcDenomTWAPResponse);
rpc SwapCrossChain(MsgSwapCrossChain) returns (MsgSwapCrossChainResponse);
rpc FundFeeAbsModuleAccount(MsgFundFeeAbsModuleAccount)
returns (MsgFundFeeAbsModuleAccountResponse);
}

// Msg fund module account
message MsgFundFeeAbsModuleAccount {
string from_address = 1;
repeated cosmos.base.v1beta1.Coin amount = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string from_address = 1;
repeated cosmos.base.v1beta1.Coin amount = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

message MsgFundFeeAbsModuleAccountResponse{}
message MsgFundFeeAbsModuleAccountResponse {}

// Params defines the parameters for the feeabs module.
message MsgSendQueryIbcDenomTWAP {
string from_address = 1;
}
message MsgSendQueryIbcDenomTWAP { string from_address = 1; }

message MsgSendQueryIbcDenomTWAPResponse {}

// Params defines the parameters for the feeabs module.
Expand Down
6 changes: 6 additions & 0 deletions x/feeabs/keeper/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// HasEpochInfo return true if has epoch info
func (k Keeper) HasEpochInfo(ctx sdk.Context, identifier string) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(append(types.KeyPrefixEpoch, []byte(identifier)...))
}

// GetEpochInfo returns epoch info by identifier.
func (k Keeper) GetEpochInfo(ctx sdk.Context, identifier string) types.EpochInfo {
epoch := types.EpochInfo{}
Expand Down
13 changes: 1 addition & 12 deletions x/feeabs/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@ import (

var now = time.Now().UTC()

var testGenesis = types.GenesisState{
Params: types.Params{
OsmosisExchangeRateUpdatePeriod: types.DefaultQueryPeriod,
AccumulatedOsmosisFeeSwapPeriod: types.DefaultSwapPeriod,
NativeIbcedInOsmosis: "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878",
},
Epochs: []types.EpochInfo{
types.NewGenesisEpochInfo("query", types.DefaultQueryPeriod),
types.NewGenesisEpochInfo("swap", types.DefaultSwapPeriod),
},
PortId: types.IBCPortID,
}
var testGenesis = types.DefaultGenesis()

func TestInitGenesis(t *testing.T) {
app := apphelpers.Setup(t, false, 1)
Expand Down
17 changes: 11 additions & 6 deletions x/feeabs/keeper/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, capability *capabilitytypes.Cap

// Send request for query EstimateSwapExactAmountIn over IBC. Move to use TWAP.
func (k Keeper) SendOsmosisQueryRequest(ctx sdk.Context, twapReqs []types.QueryArithmeticTwapToNowRequest, sourcePort, sourceChannel string) error {
path := "/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow" // hard code for now should add to params

params := k.GetParams(ctx)
IcqReqs := make([]abci.RequestQuery, len(twapReqs))
for i, req := range twapReqs {
IcqReqs[i] = abci.RequestQuery{
Path: path,
Path: params.OsmosisQueryTwapPath,
Data: k.cdc.MustMarshal(&req),
}
}
Expand Down Expand Up @@ -325,10 +324,16 @@ func (k Keeper) executeTransferMsg(ctx sdk.Context, transferMsg *transfertypes.M

}

// TODO: use TWAP instead of spotprice
func (k Keeper) handleOsmosisIbcQuery(ctx sdk.Context) error {
// TODO: `time.Minute * 5` it should be a chain param
startTime := ctx.BlockTime().Add(-time.Minute * 5)
hasQueryEpochInfo := k.HasEpochInfo(ctx, types.DefaultQueryEpochIdentifier)
if !hasQueryEpochInfo {
k.Logger(ctx).Error(fmt.Sprintf("Don't have query epoch information: %s", types.DefaultQueryEpochIdentifier))
return nil
}

// set startTime for query twap
queryTwapEpochInfo := k.GetEpochInfo(ctx, types.DefaultQueryEpochIdentifier)
startTime := ctx.BlockTime().Add(-queryTwapEpochInfo.Duration)
k.Logger(ctx).Info(fmt.Sprintf("Start time: %v", startTime.Unix()))

params := k.GetParams(ctx)
Expand Down
7 changes: 7 additions & 0 deletions x/feeabs/types/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import (
"time"
)

const (
DefaultSwapPeriod time.Duration = time.Minute * 180
DefaultQueryPeriod time.Duration = time.Minute * 60
DefaultSwapEpochIdentifier string = "swap"
DefaultQueryEpochIdentifier string = "query"
)

func KeyPrefix(p string) []byte {
return []byte(p)
}
Expand Down
7 changes: 3 additions & 4 deletions x/feeabs/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import fmt "fmt"
func DefaultGenesis() *GenesisState {
return &GenesisState{
Params: Params{
OsmosisExchangeRateUpdatePeriod: DefaultQueryPeriod,
AccumulatedOsmosisFeeSwapPeriod: DefaultSwapPeriod,
NativeIbcedInOsmosis: "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878",
OsmosisQueryTwapPath: DefaultOsmosisQueryTwapPath,
NativeIbcedInOsmosis: "ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878",
},
Epochs: []EpochInfo{NewGenesisEpochInfo("query", DefaultQueryPeriod), NewGenesisEpochInfo("swap", DefaultSwapPeriod)},
Epochs: []EpochInfo{NewGenesisEpochInfo(DefaultQueryEpochIdentifier, DefaultQueryPeriod), NewGenesisEpochInfo(DefaultSwapEpochIdentifier, DefaultSwapPeriod)},
PortId: IBCPortID,
}
}
Expand Down
Loading

0 comments on commit b6c7b17

Please sign in to comment.