-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1d0f6d
commit aafeb9c
Showing
18 changed files
with
285 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package bbnclient | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
checkpointtypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" | ||
stakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" | ||
) | ||
|
||
// StakingParams represents the staking parameters of the BBN chain | ||
// Reference: https://github.com/babylonlabs-io/babylon/blob/main/proto/babylon/btcstaking/v1/params.proto | ||
type StakingParams struct { | ||
CovenantPks []string | ||
CovenantQuorum uint32 | ||
MinStakingValueSat int64 | ||
MaxStakingValueSat int64 | ||
MinStakingTimeBlocks uint32 | ||
MaxStakingTimeBlocks uint32 | ||
SlashingPkScript string | ||
MinSlashingTxFeeSat int64 | ||
SlashingRate string | ||
MinUnbondingTimeBlocks uint32 | ||
UnbondingFeeSat int64 | ||
MinCommissionRate string | ||
MaxActiveFinalityProviders uint32 | ||
DelegationCreationBaseGasFee uint64 | ||
} | ||
|
||
func FromBbnStakingParams(params stakingtypes.Params) *StakingParams { | ||
return &StakingParams{ | ||
CovenantPks: params.CovenantPksHex(), | ||
CovenantQuorum: params.CovenantQuorum, | ||
MinStakingValueSat: params.MinStakingValueSat, | ||
MaxStakingValueSat: params.MaxStakingValueSat, | ||
MinStakingTimeBlocks: params.MinStakingTimeBlocks, | ||
MaxStakingTimeBlocks: params.MaxStakingTimeBlocks, | ||
SlashingPkScript: hex.EncodeToString(params.SlashingPkScript), | ||
MinSlashingTxFeeSat: params.MinSlashingTxFeeSat, | ||
SlashingRate: params.SlashingRate.String(), | ||
MinUnbondingTimeBlocks: params.MinUnbondingTimeBlocks, | ||
UnbondingFeeSat: params.UnbondingFeeSat, | ||
MinCommissionRate: params.MinCommissionRate.String(), | ||
MaxActiveFinalityProviders: params.MaxActiveFinalityProviders, | ||
DelegationCreationBaseGasFee: params.DelegationCreationBaseGasFee, | ||
} | ||
} | ||
|
||
type CheckpointParams = checkpointtypes.Params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package model | ||
|
||
type GolablParamDocument struct { | ||
Type string `bson:"type"` | ||
Version uint32 `bson:"version"` | ||
Params interface{} `bson:"params"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/babylonlabs-io/babylon-staking-indexer/internal/db/model" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func (db *Database) SaveGlobalParams( | ||
ctx context.Context, param *model.GolablParamDocument, | ||
) error { | ||
collection := db.client.Database(db.dbName). | ||
Collection(model.GlobalParamsCollection) | ||
|
||
filter := bson.M{ | ||
"type": param.Type, | ||
"version": param.Version, | ||
} | ||
|
||
update := bson.M{ | ||
"$setOnInsert": param, // Only insert if the document doesn't exist | ||
} | ||
|
||
_, err := collection.UpdateOne(ctx, filter, update, options.Update().SetUpsert(true)) | ||
if err != nil { | ||
return fmt.Errorf("error while upserting global params document: %w with type %s and version %d", err, param.Type, param.Version) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.