Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8b65111
exp: draft oh the photon module
tbruyelle Oct 1, 2024
9bce90f
burn msg
tbruyelle Oct 1, 2024
4584002
wip: MsgBurn implementation
tbruyelle Oct 2, 2024
d23aeb9
apply conversion
tbruyelle Oct 10, 2024
bfe0b5c
separate method for conversion rate
tbruyelle Oct 10, 2024
78dc06b
query conversion rate
tbruyelle Oct 10, 2024
bdae728
photon cli conversion-rate
tbruyelle Oct 10, 2024
f81fb27
photon tx cli burn
tbruyelle Oct 10, 2024
604e3df
rename file
tbruyelle Oct 10, 2024
2d0d772
remove x/params usage
tbruyelle Oct 10, 2024
86228e8
photon MsgUpdateParams
tbruyelle Oct 10, 2024
8b6ef34
setup tests with mocks
tbruyelle Oct 10, 2024
249b7bb
chore: add mockgen in devdeps
tbruyelle Oct 28, 2024
d142c79
test: add TestMsgServerUpdateParams
tbruyelle Oct 28, 2024
d0cb9b0
test: TestMsgServerBurn
tbruyelle Oct 28, 2024
8a6e583
TODO addressed
tbruyelle Oct 28, 2024
426dd55
fix photon max supply
tbruyelle Oct 28, 2024
63ad065
add TODO
tbruyelle Oct 28, 2024
be00193
chore: rename MsgBurn to MsgMintPhoton
tbruyelle Oct 29, 2024
0bd5deb
test: photon simulation
tbruyelle Oct 29, 2024
dfc1e03
fix lint
tbruyelle Nov 7, 2024
2de5cc2
feat(photon): add events for MintPhoton tx
tbruyelle Nov 7, 2024
b2e06d7
chore: improve start-localnet-ci target
tbruyelle Nov 7, 2024
148abcc
fix(photon): cli mint command
tbruyelle Nov 7, 2024
434edf6
test: add e2e test for minting photons
tbruyelle Nov 7, 2024
69532da
test: ConversionRate query
tbruyelle Nov 8, 2024
189ee74
add types.Denom const
tbruyelle Nov 8, 2024
9e328bd
move max supply into types pkg
tbruyelle Nov 8, 2024
3f2493b
test(e2e): photon param change proposal
tbruyelle Nov 8, 2024
22a813e
never return negative convert rate
tbruyelle Nov 8, 2024
fed4d77
test
tbruyelle Nov 26, 2024
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
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ docker-build-hermes:

docker-build-all: docker-build-debug docker-build-hermes

.PHONY: docker-build-debug docker-build-hermes docker-build-all
mockgen_cmd=$(rundep) github.com/golang/mock/mockgen

mocks-gen:
$(mockgen_cmd) -source=x/gov/testutil/expected_keepers.go -package testutil -destination x/gov/testutil/expected_keepers_mocks.go
$(mockgen_cmd) -source=x/photon/types/expected_keepers.go -package testutil -destination x/photon/testutil/expected_keepers_mocks.go

.PHONY: docker-build-debug docker-build-hermes docker-build-all mocks-gen

###############################################################################
### Linting ###
Expand Down Expand Up @@ -258,12 +264,14 @@ update-swagger-docs: proto-swagger-gen

start-localnet-ci: build
rm -rf ~/.atomoned-liveness
./build/atomoned init liveness --chain-id liveness --home ~/.atomoned-liveness
./build/atomoned init liveness --default-denom uatone --chain-id liveness --home ~/.atomoned-liveness
./build/atomoned config chain-id liveness --home ~/.atomoned-liveness
./build/atomoned config keyring-backend test --home ~/.atomoned-liveness
./build/atomoned keys add val --home ~/.atomoned-liveness
./build/atomoned genesis add-genesis-account val 10000000000000000000000000stake --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned genesis gentx val 1000000000stake --home ~/.atomoned-liveness --chain-id liveness
./build/atomoned genesis add-genesis-account val 1000000000000uatone --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned keys add user --home ~/.atomoned-liveness
./build/atomoned genesis add-genesis-account user 1000000000uatone --home ~/.atomoned-liveness --keyring-backend test
./build/atomoned genesis gentx val 1000000000uatone --home ~/.atomoned-liveness --chain-id liveness
./build/atomoned genesis collect-gentxs --home ~/.atomoned-liveness
sed -i.bak'' 's/minimum-gas-prices = ""/minimum-gas-prices = "0uatone"/' ~/.atomoned-liveness/config/app.toml
./build/atomoned start --home ~/.atomoned-liveness --x-crisis-skip-assert-invariants
Expand Down
Empty file added X
Empty file.
12 changes: 12 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ import (
govtypes "github.com/atomone-hub/atomone/x/gov/types"
govv1 "github.com/atomone-hub/atomone/x/gov/types/v1"
govv1beta1 "github.com/atomone-hub/atomone/x/gov/types/v1beta1"
photonkeeper "github.com/atomone-hub/atomone/x/photon/keeper"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

type AppKeepers struct {
Expand Down Expand Up @@ -90,6 +92,7 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
PhotonKeeper *photonkeeper.Keeper

// Modules
ICAModule ica.AppModule
Expand Down Expand Up @@ -208,6 +211,15 @@ func NewAppKeeper(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.PhotonKeeper = photonkeeper.NewKeeper(
appCodec,
appKeepers.keys[photontypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appKeepers.BankKeeper,
appKeepers.AccountKeeper,
appKeepers.StakingKeeper,
)

appKeepers.MintKeeper = mintkeeper.NewKeeper(
appCodec,
appKeepers.keys[minttypes.StoreKey],
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

govtypes "github.com/atomone-hub/atomone/x/gov/types"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -47,6 +48,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
feegrant.StoreKey,
authzkeeper.StoreKey,
consensusparamtypes.StoreKey,
photontypes.StoreKey,
)

// Define transient store keys
Expand Down
12 changes: 10 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
"github.com/atomone-hub/atomone/x/gov"
govclient "github.com/atomone-hub/atomone/x/gov/client"
govtypes "github.com/atomone-hub/atomone/x/gov/types"
"github.com/atomone-hub/atomone/x/photon"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

var maccPerms = map[string][]string{
Expand All @@ -58,8 +60,8 @@ var maccPerms = map[string][]string{
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
// liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
photontypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand All @@ -85,6 +87,7 @@ var ModuleBasics = module.NewBasicManager(
sdkparams.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
photon.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
Expand Down Expand Up @@ -121,6 +124,7 @@ func appModules(
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
photon.NewAppModule(appCodec, *app.PhotonKeeper, app.BankKeeper, app.AccountKeeper, app.StakingKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -150,6 +154,7 @@ func simulationModules(
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
photon.NewAppModule(appCodec, *app.PhotonKeeper, app.BankKeeper, app.AccountKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
sdkparams.NewAppModule(app.ParamsKeeper),
Expand Down Expand Up @@ -185,6 +190,7 @@ func orderBeginBlockers() []string {
stakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
photontypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
ibcexported.ModuleName,
Expand Down Expand Up @@ -218,6 +224,7 @@ func orderEndBlockers() []string {
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
photontypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
Expand Down Expand Up @@ -248,6 +255,7 @@ func orderInitBlockers() []string {
distrtypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
photontypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
Expand Down
1 change: 1 addition & 0 deletions contrib/devdeps/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/atomone-hub/atomone/contrib/devdeps
go 1.21

require (
github.com/golang/mock v1.6.0
github.com/golangci/golangci-lint v1.56.0
github.com/goreleaser/goreleaser v1.25.1
github.com/rakyll/statik v0.1.7
Expand Down
2 changes: 2 additions & 0 deletions contrib/devdeps/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
5 changes: 4 additions & 1 deletion contrib/devdeps/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
package devdeps

import (
// required for formatting, linting, pls.
// formatting
_ "mvdan.cc/gofumpt"

// linter
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"

// mocks
_ "github.com/golang/mock/mockgen"

// for releases
_ "github.com/goreleaser/goreleaser"

Expand Down
13 changes: 13 additions & 0 deletions proto/atomone/photon/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package atomone.photon.v1;

import "gogoproto/gogo.proto";
import "atomone/photon/v1/photon.proto";
import "amino/amino.proto";

option go_package = "github.com/atomone-hub/atomone/x/photon/types";

// GenesisState defines the x/photon module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
12 changes: 12 additions & 0 deletions proto/atomone/photon/v1/photon.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package atomone.photon.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/atomone-hub/atomone/x/photon/types";

// Params defines the parameters for the x/photon module.
message Params {
// mint photon or not
bool mint_disabled = 1;
}
42 changes: 42 additions & 0 deletions proto/atomone/photon/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";
package atomone.photon.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "atomone/photon/v1/photon.proto";
import "cosmos/base/v1beta1/coin.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/atomone-hub/atomone/x/photon/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/atomone/photon/v1/params";
}
// ConversionRate queries the photon's conversion rate
rpc ConversionRate(QueryConversionRateRequest) returns (QueryConversionRateResponse) {
option (google.api.http).get = "/atomone/photon/v1/conversion_rate";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

// QueryConversionRateRequest is request type for the Query/ConversionRate RPC method.
message QueryConversionRateRequest {}

// QueryConversionRateResponse is response type for the Query/ConversionRate RPC method.
message QueryConversionRateResponse {
// conversion_rate represents the factor used to convert atone to photon.
string conversion_rate = 1 [ (cosmos_proto.scalar) = "cosmos.Dec" ];
}
66 changes: 66 additions & 0 deletions proto/atomone/photon/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
syntax = "proto3";
package atomone.photon.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "atomone/photon/v1/photon.proto";

option go_package = "github.com/atomone-hub/atomone/x/photon/types";

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// MintPhoton defines a method to burn atone and mint photons.
rpc MintPhoton(MsgMintPhoton) returns (MsgMintPhotonResponse);

// UpdateParams defines a governance operation for updating the x/photon
// module parameters. The authority is defined in the keeper.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgMintPhoton defines an sdk.Msg for burning atone and minting photons.
message MsgMintPhoton {
option (cosmos.msg.v1.signer) = "to_address";
option (amino.name) = "atomone/photon/v1/MsgMintPhoton";

option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string to_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
cosmos.base.v1beta1.Coin amount = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

message MsgMintPhotonResponse {
cosmos.base.v1beta1.Coin minted = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// conversion_rate represents the factor used to convert atone to photon.
string conversion_rate = 2 [ (cosmos_proto.scalar) = "cosmos.Dec" ];
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "atomone/x/photon/v1/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/gov parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}

2 changes: 2 additions & 0 deletions tests/e2e/chain.go → tests/e2e/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
atomoneparams "github.com/atomone-hub/atomone/app/params"
govv1types "github.com/atomone-hub/atomone/x/gov/types/v1"
govv1beta1types "github.com/atomone-hub/atomone/x/gov/types/v1beta1"
photontypes "github.com/atomone-hub/atomone/x/photon/types"
)

const (
Expand Down Expand Up @@ -61,6 +62,7 @@ func init() {
upgradetypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
distribtypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ibctransfertypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)
photontypes.RegisterInterfaces(encodingConfig.InterfaceRegistry)

cdc = encodingConfig.Marshaler
txConfig = encodingConfig.TxConfig
Expand Down
10 changes: 4 additions & 6 deletions tests/e2e/e2e_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ func (s *IntegrationTestSuite) fundCommunityPool() {

s.execDistributionFundCommunityPool(s.chainA, 0, sender.String(), tokenAmount.String(), standardFees.String())

// there are still tokens being added to the community pool through block production rewards but they should be less than 500 tokens
marginOfErrorForBlockReward := sdk.NewInt64Coin(uatoneDenom, 500)

s.Require().Eventually(
func() bool {
afterDistPhotonBalance, err := getSpecificBalance(chainAAPIEndpoint, distModuleAddress, tokenAmount.Denom)
s.Require().NoErrorf(err, "Error getting balance: %s", afterDistPhotonBalance)
afterDistUatoneBalance, err := getSpecificBalance(chainAAPIEndpoint, distModuleAddress, tokenAmount.Denom)
s.Require().NoErrorf(err, "Error getting balance: %s", afterDistUatoneBalance)

return beforeDistUatoneBalance.Add(tokenAmount.Add(standardFees)).Sub(afterDistPhotonBalance).IsLT(marginOfErrorForBlockReward)
// check if the balance is increased by the tokenAmount
return beforeDistUatoneBalance.Add(tokenAmount).IsLT(afterDistUatoneBalance)
},
15*time.Second,
time.Second,
Expand Down
Loading
Loading