Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/foxy-fix-typo01
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Nov 2, 2023
2 parents 365dcad + 38759d2 commit d6de71f
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 100 deletions.
10 changes: 5 additions & 5 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50393,7 +50393,7 @@ paths:
- OWNER
- EDITOR
default: NO_ROLE
registrationFee:
totalWithdrawalAmount:
type: array
items:
type: object
Expand Down Expand Up @@ -50621,7 +50621,7 @@ paths:
- OWNER
- EDITOR
default: NO_ROLE
registrationFee:
totalWithdrawalAmount:
type: array
items:
type: object
Expand Down Expand Up @@ -81412,7 +81412,7 @@ definitions:
- OWNER
- EDITOR
default: NO_ROLE
registrationFee:
totalWithdrawalAmount:
type: array
items:
type: object
Expand Down Expand Up @@ -81597,7 +81597,7 @@ definitions:
- OWNER
- EDITOR
default: NO_ROLE
registrationFee:
totalWithdrawalAmount:
type: array
items:
type: object
Expand Down Expand Up @@ -81864,7 +81864,7 @@ definitions:
- OWNER
- EDITOR
default: NO_ROLE
registrationFee:
totalWithdrawalAmount:
type: array
items:
type: object
Expand Down
2 changes: 1 addition & 1 deletion proto/mycel/registry/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ option go_package = "github.com/mycel-domain/mycel/x/registry/types";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
float stakingInflationRatio = 1;
float stakingInflationRatio = 1;
int64 topLevelDomainBaseFeeInUsd = 2;
}
2 changes: 1 addition & 1 deletion proto/mycel/registry/top_level_domain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message TopLevelDomain {
SubdomainConfig subdomainConfig = 4;
uint64 subdomainCount = 5;
map<string, DomainRole> accessControl = 6;
repeated cosmos.base.v1beta1.Coin registrationFee = 7 [
repeated cosmos.base.v1beta1.Coin totalWithdrawalAmount = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
Expand Down
2 changes: 1 addition & 1 deletion x/registry/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func EmitUpdateWalletRecordEvent(ctx sdk.Context, msg types.MsgUpdateWalletRecor
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeUpdateWalletRecord,
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventDomainName, msg.Name),
sdk.NewAttribute(types.AttributeUpdateDnsRecordEventDomainParent, msg.Parent),
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventDomainParent, msg.Parent),
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventWalletRecordType, msg.WalletRecordType),
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventValue, msg.Value),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {

afterModuleBalance := suite.app.BankKeeper.GetBalance(suite.ctx, moduleAddress, types.MycelDenom)
suite.Require().Equal(beforeModuleBalance.Add(*fee), afterModuleBalance)
suite.Require().Equal(beforeParent.RegistrationFee.Add(*fee), afterParent.RegistrationFee)
suite.Require().Equal(beforeParent.TotalWithdrawalAmount.Add(*fee), afterParent.TotalWithdrawalAmount)

// Evalute events
events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeRegisterSecondLevelDomain)
Expand Down
2 changes: 1 addition & 1 deletion x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
RegistrationFee: sdk.NewCoins(),
TotalWithdrawalAmount: sdk.NewCoins(),
}

err = k.Keeper.RegisterTopLevelDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)
Expand Down
15 changes: 5 additions & 10 deletions x/registry/keeper/msg_server_withdraw_registration_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ import (

func (k msgServer) WithdrawRegistrationFee(goCtx context.Context, msg *types.MsgWithdrawRegistrationFee) (*types.MsgWithdrawRegistrationFeeResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx

// Get top level domain
topLevelDomain, found := k.Keeper.GetTopLevelDomain(ctx, msg.Name)
if !found {
return nil, errorsmod.Wrapf(types.ErrDomainNotFound, "%s", msg.Name)
}

if topLevelDomain.RegistrationFee.IsZero() {
return nil, errorsmod.Wrapf(types.ErrNoRegistrationFeeToWithdraw, "%s", msg.Name)
if topLevelDomain.TotalWithdrawalAmount.IsZero() {
return nil, errorsmod.Wrapf(types.ErrNoWithdrawalAmountToWithdraw, "%s", msg.Name)
}

// Check if the creator is the owner of the domain
role, ok := topLevelDomain.AccessControl[msg.Creator]
if !ok || role != types.DomainRole_OWNER {
return nil, errorsmod.Wrapf(types.ErrNoPermissionToWithdrawFee, "%s", msg.Creator)
return nil, errorsmod.Wrapf(types.ErrNoPermissionToWithdraw, "%s", msg.Creator)
}

// Send coins from module account to Creator
Expand All @@ -36,17 +32,16 @@ func (k msgServer) WithdrawRegistrationFee(goCtx context.Context, msg *types.Msg
return nil, err
}

registrationFee := topLevelDomain.RegistrationFee
registrationFee := topLevelDomain.TotalWithdrawalAmount
err = k.Keeper.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, creatorAddress, registrationFee)
if err != nil {
return nil, err
}
topLevelDomain.RegistrationFee = sdk.NewCoins()
topLevelDomain.TotalWithdrawalAmount = sdk.NewCoins()
k.Keeper.SetTopLevelDomain(ctx, topLevelDomain)

// Emit event
EmitWithdrawRegistrationFeeEvent(ctx, *msg, registrationFee)


return &types.MsgWithdrawRegistrationFeeResponse{RegistrationFee: registrationFee}, nil
}
19 changes: 15 additions & 4 deletions x/registry/keeper/msg_server_withdraw_registration_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/mycel-domain/mycel/testutil"
"github.com/mycel-domain/mycel/x/registry/types"
Expand All @@ -24,7 +25,7 @@ func (suite *KeeperTestSuite) TestWithdrawRegistrationFee() {
{
withdrawer: testutil.Bob,
topLevelDomainName: "bar",
expErr: errorsmod.Wrapf(types.ErrNoPermissionToWithdrawFee, "%s", testutil.Bob),
expErr: errorsmod.Wrapf(types.ErrNoPermissionToWithdraw, "%s", testutil.Bob),
},
}

Expand Down Expand Up @@ -54,7 +55,9 @@ func (suite *KeeperTestSuite) TestWithdrawRegistrationFee() {
// Before balance
withdrawerAddress, err := sdk.AccAddressFromBech32(tc.withdrawer)
suite.Require().Nil(err)
beforeBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress)
beforeWithdrawerBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress)
registryAddress := authtypes.NewModuleAddress(types.ModuleName)
beforeRegistryAddress := suite.app.BankKeeper.GetAllBalances(suite.ctx, registryAddress)

// Withdraw registration fee
withdrawMsg := &types.MsgWithdrawRegistrationFee{
Expand All @@ -75,8 +78,16 @@ func (suite *KeeperTestSuite) TestWithdrawRegistrationFee() {
}

// Check balance
afterBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress)
suite.Require().Equal(beforeBalance.Add(fees.RegistrationFee...), afterBalance)
afterWithdrawerBalance := suite.app.BankKeeper.GetAllBalances(suite.ctx, withdrawerAddress)
suite.Require().Equal(beforeWithdrawerBalance.Add(fees.RegistrationFee...), afterWithdrawerBalance)
afterRegistyAddress := suite.app.BankKeeper.GetAllBalances(suite.ctx, registryAddress)
suite.Require().Equal(beforeRegistryAddress.Sub(fees.RegistrationFee...), afterRegistyAddress)

// Check top level domain
topLevelDomain, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.topLevelDomainName)
suite.Require().True(found)
suite.Require().True(topLevelDomain.TotalWithdrawalAmount.IsEqual(sdk.NewCoins()))

} else {
suite.Require().EqualError(err, tc.expErr.Error())
}
Expand Down
7 changes: 1 addition & 6 deletions x/registry/keeper/register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (k Keeper) PaySLDRegstrationFee(ctx sdk.Context, payer sdk.AccAddress, doma
if !found {
panic("parent not found")
}
parent.RegistrationFee = parent.RegistrationFee.Add(*fee)
parent.TotalWithdrawalAmount = parent.TotalWithdrawalAmount.Add(*fee)
k.SetTopLevelDomain(ctx, parent)

return fee, err
Expand Down Expand Up @@ -87,11 +87,6 @@ func (k Keeper) RegisterSecondLevelDomain(ctx sdk.Context, domain types.SecondLe
return err
}

// Set subdomain registration config
parentDomain.SubdomainConfig = &types.SubdomainConfig{
MaxSubdomainRegistrations: 100,
}

// Increment parents subdomain SubdomainCount
k.IncrementParentsSubdomainCount(ctx, domain)

Expand Down
4 changes: 2 additions & 2 deletions x/registry/keeper/register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (

func (k Keeper) GetBurnWeight(ctx sdk.Context) (weight math.LegacyDec, err error) {
inflation := k.mintKeeper.GetMinter(ctx).Inflation
boundedRatio := k.mintKeeper.BondedRatio(ctx)
bondedRatio := k.mintKeeper.BondedRatio(ctx)

// TODO: Get alpha from params
stakingInflationRatio := k.GetParams(ctx).StakingInflationRatio
alpha := math.LegacyMustNewDecFromStr(fmt.Sprintf("%f", stakingInflationRatio))

w1 := alpha.Mul(boundedRatio)
w1 := alpha.Mul(bondedRatio)
w2 := inflation.Mul(math.LegacyMustNewDecFromStr("1").Sub(alpha))
weight = w1.Add(w2)
return weight, nil
Expand Down
40 changes: 20 additions & 20 deletions x/registry/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import (

// x/mycel module sentinel errors
var (
ErrSample = errorsmod.Register(ModuleName, 1100, "sample error")
ErrDomainIsAlreadyTaken = errorsmod.Register(ModuleName, 1101, "domain is already taken")
ErrInvalidDomainName = errorsmod.Register(ModuleName, 1102, "invalid name")
ErrInvalidDomainParent = errorsmod.Register(ModuleName, 1103, "invalid parent")
ErrDomainNotFound = errorsmod.Register(ModuleName, 1104, "domain not found")
ErrInvalidWalletAddress = errorsmod.Register(ModuleName, 1105, "invalid wallet address")
ErrInvalidWalletRecordType = errorsmod.Register(ModuleName, 1106, "invalid wallet record type")
ErrInvalidDnsRecordValue = errorsmod.Register(ModuleName, 1107, "invalid dns record value")
ErrInvalidDnsRecordType = errorsmod.Register(ModuleName, 1108, "invalid dns record type")
ErrDomainNotEditable = errorsmod.Register(ModuleName, 1109, "role not pemitted to edit the domain")
ErrParentDomainDoesNotExist = errorsmod.Register(ModuleName, 1110, "parent domain does not exist")
ErrParentDomainMustBeEmpty = errorsmod.Register(ModuleName, 1111, "parent domain must be empty")
ErrDomainNotRegistrable = errorsmod.Register(ModuleName, 1112, "domain is not registrable")
ErrMaxSubdomainCountReached = errorsmod.Register(ModuleName, 1113, "max subdomain count reached")
ErrInvalidRegistrationPeriod = errorsmod.Register(ModuleName, 1114, "invalid registration period")
ErrDomainExpired = errorsmod.Register(ModuleName, 1115, "domain expired")
ErrNoEnoughBalance = errorsmod.Register(ModuleName, 1116, "no enough balance")
ErrNoPermissionToWithdrawFee = errorsmod.Register(ModuleName, 1117, "no permission to withdraw fee")
ErrNoRegistrationFeeToWithdraw = errorsmod.Register(ModuleName, 1118, "no registration fee to withdraw")
ErrInvalidDenom = errorsmod.Register(ModuleName, 1119, "invalid denom")
ErrSample = errorsmod.Register(ModuleName, 1100, "sample error")
ErrDomainIsAlreadyTaken = errorsmod.Register(ModuleName, 1101, "domain is already taken")
ErrInvalidDomainName = errorsmod.Register(ModuleName, 1102, "invalid name")
ErrInvalidDomainParent = errorsmod.Register(ModuleName, 1103, "invalid parent")
ErrDomainNotFound = errorsmod.Register(ModuleName, 1104, "domain not found")
ErrInvalidWalletAddress = errorsmod.Register(ModuleName, 1105, "invalid wallet address")
ErrInvalidWalletRecordType = errorsmod.Register(ModuleName, 1106, "invalid wallet record type")
ErrInvalidDnsRecordValue = errorsmod.Register(ModuleName, 1107, "invalid dns record value")
ErrInvalidDnsRecordType = errorsmod.Register(ModuleName, 1108, "invalid dns record type")
ErrDomainNotEditable = errorsmod.Register(ModuleName, 1109, "role not pemitted to edit the domain")
ErrParentDomainDoesNotExist = errorsmod.Register(ModuleName, 1110, "parent domain does not exist")
ErrParentDomainMustBeEmpty = errorsmod.Register(ModuleName, 1111, "parent domain must be empty")
ErrDomainNotRegistrable = errorsmod.Register(ModuleName, 1112, "domain is not registrable")
ErrMaxSubdomainCountReached = errorsmod.Register(ModuleName, 1113, "max subdomain count reached")
ErrInvalidRegistrationPeriod = errorsmod.Register(ModuleName, 1114, "invalid registration period")
ErrDomainExpired = errorsmod.Register(ModuleName, 1115, "domain expired")
ErrNoEnoughBalance = errorsmod.Register(ModuleName, 1116, "no enough balance")
ErrNoPermissionToWithdraw = errorsmod.Register(ModuleName, 1117, "no permission to withdraw")
ErrNoWithdrawalAmountToWithdraw = errorsmod.Register(ModuleName, 1118, "no registration fee to withdraw")
ErrInvalidDenom = errorsmod.Register(ModuleName, 1119, "invalid denom")
)
Loading

0 comments on commit d6de71f

Please sign in to comment.