Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/bridge -> release/v0.4.2 #687

Open
wants to merge 21 commits into
base: release/v0.4.2
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bridge
kobs30 committed Mar 24, 2024
commit 25eefd789e0b008b3c0c303cd3e403a0d8f7cb46
41 changes: 41 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
bridgetypes "github.com/KiraCore/sekai/x/bridge/types"
"time"

kiratypes "github.com/KiraCore/sekai/types"
bridgekeeper "github.com/KiraCore/sekai/x/bridge/keeper"
custodykeeper "github.com/KiraCore/sekai/x/custody/keeper"
custodytypes "github.com/KiraCore/sekai/x/custody/types"
feeprocessingkeeper "github.com/KiraCore/sekai/x/feeprocessing/keeper"
@@ -34,6 +36,7 @@ func NewAnteHandler(
ak keeper.AccountKeeper,
bk types.BankKeeper,
ck custodykeeper.Keeper,
brk bridgekeeper.Keeper,
feegrantKeeper ante.FeegrantKeeper,
extensionOptionChecker ante.ExtensionOptionChecker,
sigGasConsumer ante.SignatureVerificationGasConsumer,
@@ -42,6 +45,7 @@ func NewAnteHandler(
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewBridgeDecorator(brk, cgk),
NewCustodyDecorator(ck, cgk),
NewZeroGasMeterDecorator(),
ante.NewExtensionOptionsDecorator(extensionOptionChecker),
@@ -65,6 +69,43 @@ func NewAnteHandler(
)
}

type BridgeDecorator struct {
brk bridgekeeper.Keeper
gk customgovkeeper.Keeper
}

func NewBridgeDecorator(brk bridgekeeper.Keeper, gk customgovkeeper.Keeper) BridgeDecorator {
return BridgeDecorator{
brk: brk,
gk: gk,
}
}

func (bd BridgeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

properties := bd.gk.GetNetworkProperties(ctx)

for _, msg := range feeTx.GetMsgs() {
switch kiratypes.MsgType(msg) {
case kiratypes.MsgTypeChangeEthereumCosmos:
msg, ok := msg.(*bridgetypes.MsgChangeEthereumCosmos)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgChangeEthereumCosmos")
}

if msg.Addr.String() != properties.BridgeAddress {
return ctx, sdkerrors.Wrap(bridgetypes.ErrWrongBridgeAddr, "Bridge module")
}
}
}

return next(ctx, tx, simulate)
}

type CustodyDecorator struct {
ck custodykeeper.Keeper
gk customgovkeeper.Keeper
1 change: 1 addition & 0 deletions app/ante/testutil_test.go
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
suite.app.AccountKeeper,
suite.app.BankKeeper,
suite.app.CustodyKeeper,
suite.app.BridgeKeeper,
nil,
nil,
ante.DefaultSigVerificationGasConsumer,
18 changes: 15 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@ import (
"github.com/KiraCore/sekai/x/basket"
basketkeeper "github.com/KiraCore/sekai/x/basket/keeper"
baskettypes "github.com/KiraCore/sekai/x/basket/types"
"github.com/KiraCore/sekai/x/bridge"
bridgekeeper "github.com/KiraCore/sekai/x/bridge/keeper"
bridgetypes "github.com/KiraCore/sekai/x/bridge/types"
"github.com/KiraCore/sekai/x/collectives"
collectiveskeeper "github.com/KiraCore/sekai/x/collectives/keeper"
collectivestypes "github.com/KiraCore/sekai/x/collectives/types"
@@ -124,6 +127,7 @@ var (
tokens.AppModuleBasic{},
feeprocessing.AppModuleBasic{},
custody.AppModuleBasic{},
bridge.AppModuleBasic{},
multistaking.AppModuleBasic{},
collectives.AppModuleBasic{},
layer2.AppModuleBasic{},
@@ -169,6 +173,7 @@ type SekaiApp struct {
ParamsKeeper paramskeeper.Keeper

CustodyKeeper custodykeeper.Keeper
BridgeKeeper bridgekeeper.Keeper
CustomGovKeeper customgovkeeper.Keeper
CustomStakingKeeper customstakingkeeper.Keeper
CustomSlashingKeeper customslashingkeeper.Keeper
@@ -234,6 +239,7 @@ func NewInitApp(
feeprocessingtypes.ModuleName,
evidencetypes.StoreKey,
custodytypes.StoreKey,
bridgetypes.StoreKey,
collectivestypes.ModuleName,
layer2types.ModuleName,
consensusparamtypes.StoreKey,
@@ -335,6 +341,7 @@ func NewInitApp(
app.EvidenceKeeper = *evidenceKeeper

app.CustodyKeeper = custodykeeper.NewKeeper(keys[custodytypes.StoreKey], appCodec, app.CustomGovKeeper, app.BankKeeper)
app.BridgeKeeper = bridgekeeper.NewKeeper(keys[bridgetypes.StoreKey], appCodec, app.BankKeeper)

app.RecoveryKeeper = recoverykeeper.NewKeeper(
appCodec,
@@ -428,6 +435,7 @@ func NewInitApp(
feeprocessing.NewAppModule(app.FeeProcessingKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
custody.NewAppModule(app.CustodyKeeper, app.CustomGovKeeper, app.BankKeeper),
bridge.NewAppModule(app.BridgeKeeper, app.BankKeeper),
collectives.NewAppModule(app.CollectivesKeeper),
layer2.NewAppModule(app.Layer2Keeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
@@ -442,9 +450,10 @@ func NewInitApp(
upgradetypes.ModuleName, slashingtypes.ModuleName, recoverytypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName,
spendingtypes.ModuleName, ubitypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
baskettypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
distributortypes.ModuleName,
multistakingtypes.ModuleName,
custodytypes.ModuleName,
bridgetypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
layer2types.ModuleName,
@@ -459,6 +468,7 @@ func NewInitApp(
feeprocessingtypes.ModuleName,
spendingtypes.ModuleName, ubitypes.ModuleName,
distributortypes.ModuleName, multistakingtypes.ModuleName, custodytypes.ModuleName,
bridgetypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
layer2types.ModuleName,
@@ -487,6 +497,7 @@ func NewInitApp(
paramstypes.ModuleName,
distributortypes.ModuleName,
custodytypes.ModuleName,
bridgetypes.ModuleName,
multistakingtypes.ModuleName,
baskettypes.ModuleName,
collectivestypes.ModuleName,
@@ -526,6 +537,7 @@ func NewInitApp(
app.AccountKeeper,
app.BankKeeper,
app.CustodyKeeper,
app.BridgeKeeper,
nil,
nil,
ante.DefaultSigVerificationGasConsumer,
184 changes: 92 additions & 92 deletions proto/kira/basket/basket.proto
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
syntax = "proto3";
package kira.basket;

option go_package = "github.com/KiraCore/sekai/x/basket/types";
option (gogoproto.equal_all) = true;

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

message Basket {
uint64 id = 1; // basket identifier
string suffix = 2; // denom suffix, resulting token denom would be B1_usd when the value is "usd"
string description = 3; // basket description
string amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // total supply of all minted basket tokens
string swap_fee = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, default 0.0015 (0.15%) - percentage fee to be paid for swapping tokens
string slipppage_fee_min = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, default 0.0015 (0.15%) - minimum percentage to be paid as penalty for disbalancing the basket
string tokens_cap = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, E.g: fail mint/burn/swap tx if more than 90% supply would end up being represented by a single token
uint64 limits_period = 8; // // in seconds, period after which all mint/burns limits are reset (default 1 day)
string mints_min = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum amount tokens that must be minted in a single tx
string mints_max = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily issuance limit tokens
bool mints_disabled = 11;
string burns_min = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum amount tokens that must be burned in a single tx
string burns_max = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily burn amount (resulting in aggregate tokens redemptions)
bool burns_disabled = 14;
string swaps_min = 15 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum value of aggregate tokens expressed in B1_usd that must be swapped in a single tx
string swaps_max = 16 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily swap amount of aggregate tokens (resulting in aggregate tokens redemptions)
bool swaps_disabled = 17;
repeated BasketToken tokens = 18 [ (gogoproto.nullable) = false ];
repeated string surplus = 19 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
]; // list of excess tokens deposited as result of rewards and/or swaps (that did not resulted in minting)
}

message BasketToken {
string denom = 1; // denom of one of the aggregate tokens
string weight = 2[
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // relative value of the token to its underlying derivative 100 deposit should result in 99 issuance
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // total deposited amount of usdt available for withdrawl
bool deposits = 4; // defines if deposits of usdt resulting in minting are allowed
bool withdraws = 5; // defines if withdraws of usdt as result of burns are allowed
bool swaps = 6; // defines if swaps of usdt for other tokens are allowed
}

// used to record mint, burn, swap actions to prevent actions from exceeding daily limitation
message AmountAtTime {
uint64 basket_id = 1;
uint64 time = 2;
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}

// Params represents the parameters used for by the module.
message Params {
}
syntax = "proto3";
package kira.basket;
option go_package = "github.com/KiraCore/sekai/x/basket/types";
option (gogoproto.equal_all) = true;
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
message Basket {
uint64 id = 1; // basket identifier
string suffix = 2; // denom suffix, resulting token denom would be B1_usd when the value is "usd"
string description = 3; // basket description
string amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // total supply of all minted basket tokens
string swap_fee = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, default 0.0015 (0.15%) - percentage fee to be paid for swapping tokens
string slipppage_fee_min = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, default 0.0015 (0.15%) - minimum percentage to be paid as penalty for disbalancing the basket
string tokens_cap = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // range of 0 to 1, E.g: fail mint/burn/swap tx if more than 90% supply would end up being represented by a single token
uint64 limits_period = 8; // // in seconds, period after which all mint/burns limits are reset (default 1 day)
string mints_min = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum amount tokens that must be minted in a single tx
string mints_max = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily issuance limit tokens
bool mints_disabled = 11;
string burns_min = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum amount tokens that must be burned in a single tx
string burns_max = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily burn amount (resulting in aggregate tokens redemptions)
bool burns_disabled = 14;
string swaps_min = 15 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // minimum value of aggregate tokens expressed in B1_usd that must be swapped in a single tx
string swaps_max = 16 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // maximum daily swap amount of aggregate tokens (resulting in aggregate tokens redemptions)
bool swaps_disabled = 17;
repeated BasketToken tokens = 18 [ (gogoproto.nullable) = false ];
repeated string surplus = 19 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
]; // list of excess tokens deposited as result of rewards and/or swaps (that did not resulted in minting)
}
message BasketToken {
string denom = 1; // denom of one of the aggregate tokens
string weight = 2[
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // relative value of the token to its underlying derivative 100 deposit should result in 99 issuance
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
]; // total deposited amount of usdt available for withdrawl
bool deposits = 4; // defines if deposits of usdt resulting in minting are allowed
bool withdraws = 5; // defines if withdraws of usdt as result of burns are allowed
bool swaps = 6; // defines if swaps of usdt for other tokens are allowed
}
// used to record mint, burn, swap actions to prevent actions from exceeding daily limitation
message AmountAtTime {
uint64 basket_id = 1;
uint64 time = 2;
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
// Params represents the parameters used for by the module.
message Params {
}
44 changes: 22 additions & 22 deletions proto/kira/basket/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
syntax = "proto3";
package kira.basket;

option go_package = "github.com/KiraCore/sekai/x/basket/types";

import "gogoproto/gogo.proto";
import "kira/basket/basket.proto";

// GenesisState defines the basket module's genesis state.
message GenesisState {
// baskets registered on the module
repeated Basket baskets = 1 [ (gogoproto.nullable) = false ];
// last basket id
uint64 last_basket_id = 2;
// mints by time
repeated AmountAtTime historical_mints = 3 [ (gogoproto.nullable) = false ];
// burns by time
repeated AmountAtTime historical_burns = 4 [ (gogoproto.nullable) = false ];
// swaps by time
repeated AmountAtTime historical_swaps = 5 [ (gogoproto.nullable) = false ];
}

syntax = "proto3";
package kira.basket;
option go_package = "github.com/KiraCore/sekai/x/basket/types";
import "gogoproto/gogo.proto";
import "kira/basket/basket.proto";
// GenesisState defines the basket module's genesis state.
message GenesisState {
// baskets registered on the module
repeated Basket baskets = 1 [ (gogoproto.nullable) = false ];
// last basket id
uint64 last_basket_id = 2;
// mints by time
repeated AmountAtTime historical_mints = 3 [ (gogoproto.nullable) = false ];
// burns by time
repeated AmountAtTime historical_burns = 4 [ (gogoproto.nullable) = false ];
// swaps by time
repeated AmountAtTime historical_swaps = 5 [ (gogoproto.nullable) = false ];
}
// https://www.notion.so/kira-network/KIP-78-Token-Basketing-Module-7e6da1f2667c4c13b2274d546031d5db
Loading