Skip to content
New issue

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

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

Already on GitHub? # to your account

Add bridge switch params #36

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51002,6 +51002,12 @@ paths:
btc_voucher_denom:
type: string
title: The denomination of the voucher
deposit_enabled:
type: boolean
title: Indicates if deposit is enabled
withdraw_enabled:
type: boolean
title: Indicates if withdrawal is enabled
vaults:
type: array
items:
Expand Down Expand Up @@ -82670,6 +82676,12 @@ definitions:
btc_voucher_denom:
type: string
title: The denomination of the voucher
deposit_enabled:
type: boolean
title: Indicates if deposit is enabled
withdraw_enabled:
type: boolean
title: Indicates if withdrawal is enabled
vaults:
type: array
items:
Expand Down Expand Up @@ -83102,6 +83114,12 @@ definitions:
btc_voucher_denom:
type: string
title: The denomination of the voucher
deposit_enabled:
type: boolean
title: Indicates if deposit is enabled
withdraw_enabled:
type: boolean
title: Indicates if withdrawal is enabled
vaults:
type: array
items:
Expand Down
12 changes: 8 additions & 4 deletions proto/side/btcbridge/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ message Params {
uint64 max_acceptable_block_depth = 2;
// The denomination of the voucher
string btc_voucher_denom = 3;
// Indicates if deposit is enabled
bool deposit_enabled = 4;
// Indicates if withdrawal is enabled
bool withdraw_enabled = 5;
// Asset vaults
repeated Vault vaults = 4;
repeated Vault vaults = 6;
// Protocol limitations
ProtocolLimits protocol_limits = 5 [(gogoproto.nullable) = false];
ProtocolLimits protocol_limits = 7 [(gogoproto.nullable) = false];
// Protocol fees
ProtocolFees protocol_fees = 6 [(gogoproto.nullable) = false];
ProtocolFees protocol_fees = 8 [(gogoproto.nullable) = false];
// TSS params
TSSParams tss_params = 7 [(gogoproto.nullable) = false];
TSSParams tss_params = 9 [(gogoproto.nullable) = false];
}

// AssetType defines the type of asset
Expand Down
5 changes: 0 additions & 5 deletions x/btcbridge/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,6 @@ func (k Keeper) getOutputsForMintRunes(ctx sdk.Context, tx *wire.MsgTx, edict *t
return outs, vouts, vaults, nil
}

// ProtocolDepositFeeEnabled returns true if the protocol fee is required for deposit, false otherwise
func (k Keeper) ProtocolDepositFeeEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).ProtocolFees.DepositFee > 0
}

func (k Keeper) existsInHistory(ctx sdk.Context, txHash string) bool {
store := ctx.KVStore(k.storeKey)

Expand Down
8 changes: 8 additions & 0 deletions x/btcbridge/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (m msgServer) SubmitDepositTransaction(goCtx context.Context, msg *types.Ms
return nil, err
}

if !m.DepositEnabled(ctx) {
return nil, types.ErrDepositNotEnabled
}

txHash, recipient, err := m.ProcessBitcoinDepositTransaction(ctx, msg)
if err != nil {
ctx.Logger().Error("Error processing bitcoin deposit transaction", "error", err)
Expand Down Expand Up @@ -98,6 +102,10 @@ func (m msgServer) WithdrawToBitcoin(goCtx context.Context, msg *types.MsgWithdr

ctx := sdk.UnwrapSDKContext(goCtx)

if !m.WithdrawEnabled(ctx) {
return nil, types.ErrWithdrawNotEnabled
}

sender := sdk.MustAccAddressFromBech32(msg.Sender)

amount, err := sdk.ParseCoinNormalized(msg.Amount)
Expand Down
25 changes: 25 additions & 0 deletions x/btcbridge/keeper/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

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

// DepositEnabled returns true if deposit enabled, false otherwise
func (k Keeper) DepositEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).DepositEnabled
}

// WithdrawEnabled returns true if withdrawal enabled, false otherwise
func (k Keeper) WithdrawEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).WithdrawEnabled
}

// ProtocolDepositFeeEnabled returns true if the protocol fee is required for deposit, false otherwise
func (k Keeper) ProtocolDepositFeeEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).ProtocolFees.DepositFee > 0
}

// ProtocolWithdrawFeeEnabled returns true if the protocol fee is required for withdrawal, false otherwise
func (k Keeper) ProtocolWithdrawFeeEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).ProtocolFees.WithdrawFee > 0
}
5 changes: 0 additions & 5 deletions x/btcbridge/keeper/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,3 @@ func (k Keeper) burnLockedAssets(ctx sdk.Context, txHash string) error {

return nil
}

// ProtocolWithdrawFeeEnabled returns true if the protocol fee is required for withdrawal, false otherwise
func (k Keeper) ProtocolWithdrawFeeEnabled(ctx sdk.Context) bool {
return k.GetParams(ctx).ProtocolFees.WithdrawFee > 0
}
2 changes: 2 additions & 0 deletions x/btcbridge/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
ErrTransactionAlreadyMinted = errorsmod.Register(ModuleName, 2107, "transaction already minted")
ErrInvalidDepositTransaction = errorsmod.Register(ModuleName, 2108, "invalid deposit transaction")
ErrInvalidDepositAmount = errorsmod.Register(ModuleName, 2109, "invalid deposit amount")
ErrDepositNotEnabled = errorsmod.Register(ModuleName, 2110, "deposit not enabled")

ErrInvalidAmount = errorsmod.Register(ModuleName, 3100, "invalid amount")
ErrInvalidFeeRate = errorsmod.Register(ModuleName, 3101, "invalid fee rate")
Expand All @@ -33,6 +34,7 @@ var (
ErrInvalidSignatures = errorsmod.Register(ModuleName, 3108, "invalid signatures")
ErrWithdrawRequestNotExist = errorsmod.Register(ModuleName, 3109, "withdrawal request does not exist")
ErrWithdrawRequestConfirmed = errorsmod.Register(ModuleName, 3110, "withdrawal request has been confirmed")
ErrWithdrawNotEnabled = errorsmod.Register(ModuleName, 3111, "withdrawal not enabled")

ErrUTXODoesNotExist = errorsmod.Register(ModuleName, 4100, "utxo does not exist")
ErrUTXOLocked = errorsmod.Register(ModuleName, 4101, "utxo locked")
Expand Down
2 changes: 2 additions & 0 deletions x/btcbridge/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func NewParams() Params {
Confirmations: 1,
MaxAcceptableBlockDepth: 100,
BtcVoucherDenom: "sat",
DepositEnabled: true,
WithdrawEnabled: true,
Vaults: []*Vault{},
ProtocolLimits: ProtocolLimits{
BtcMinDeposit: 50000, // 0.0005 BTC
Expand Down
Loading