Skip to content

Commit

Permalink
Verifying NFT ownership through oracle voting (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
devbv authored Apr 29, 2024
1 parent 938d4da commit 0ea2018
Show file tree
Hide file tree
Showing 107 changed files with 4,103 additions and 6,510 deletions.
5 changes: 4 additions & 1 deletion app/ante/settlement_fee_checker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ante

import (
"strings"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -36,7 +38,8 @@ func newSettlementFeeChecker(k SettlementKeeper) ante.TxFeeChecker {
func calculateGasCost(tx sdk.Tx) (gas uint64) {
for _, msg := range tx.GetMsgs() {
gas += SettlementBasicGasCost
if sdk.MsgTypeURL(msg) == "/settlus.settlement.MsgCreateTenant" {
url := sdk.MsgTypeURL(msg)
if strings.HasPrefix(url, "/settlus.settlement") && strings.HasSuffix(url, "MsgCreateTenant") {
gas += SettlementCreateTenantGasCost
}
}
Expand Down
52 changes: 16 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ import (
"github.com/settlus/chain/app/ante"

"github.com/settlus/chain/swagger"
nftownershipmodule "github.com/settlus/chain/x/nftownership"
nftownershipmodulekeeper "github.com/settlus/chain/x/nftownership/keeper"
nftownershipmoduletypes "github.com/settlus/chain/x/nftownership/types"

oraclemodule "github.com/settlus/chain/x/oracle"
oraclemodulekeeper "github.com/settlus/chain/x/oracle/keeper"
oraclemoduletypes "github.com/settlus/chain/x/oracle/types"
Expand Down Expand Up @@ -184,7 +182,6 @@ var (

// Settlus modules
settlementmodule.AppModuleBasic{},
nftownershipmodule.AppModuleBasic{},
oraclemodule.AppModuleBasic{},
)

Expand All @@ -203,9 +200,8 @@ var (
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},

// settlus modules
settlementmoduletypes.ModuleName: nil,
nftownershipmoduletypes.ModuleName: nil,
oraclemoduletypes.ModuleName: nil,
settlementmoduletypes.ModuleName: nil,
oraclemoduletypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -273,9 +269,8 @@ type App struct {
Erc20Keeper erc20keeper.Keeper

// Settlus keepers
SettlementKeeper *settlementmodulekeeper.SettlementKeeper
NftOwnershipKeeper *nftownershipmodulekeeper.Keeper
OracleKeeper *oraclemodulekeeper.Keeper
SettlementKeeper *settlementmodulekeeper.SettlementKeeper
OracleKeeper *oraclemodulekeeper.Keeper

// mm is the module manager
mm *module.Manager
Expand Down Expand Up @@ -329,7 +324,6 @@ func New(
erc20types.StoreKey,
// Settlus keys
settlementmoduletypes.StoreKey,
nftownershipmoduletypes.StoreKey,
oraclemoduletypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
Expand Down Expand Up @@ -527,35 +521,26 @@ func New(
)

// Settlus Keeper
app.OracleKeeper = oraclemodulekeeper.NewKeeper(
app.SettlementKeeper = settlementmodulekeeper.NewKeeper(
appCodec,
keys[oraclemoduletypes.StoreKey],
app.GetSubspace(oraclemoduletypes.ModuleName),
keys[settlementmoduletypes.StoreKey],
app.GetSubspace(settlementmoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.DistrKeeper,
&stakingKeeper,
distrtypes.ModuleName,
)

app.NftOwnershipKeeper = nftownershipmodulekeeper.NewKeeper(
appCodec,
keys[nftownershipmoduletypes.StoreKey],
app.GetSubspace(nftownershipmoduletypes.ModuleName),
app.AccountKeeper,
app.Erc20Keeper,
app.EvmKeeper,
app.OracleKeeper,
)

app.SettlementKeeper = settlementmodulekeeper.NewKeeper(
app.OracleKeeper = oraclemodulekeeper.NewKeeper(
appCodec,
keys[settlementmoduletypes.StoreKey],
app.GetSubspace(settlementmoduletypes.ModuleName),
keys[oraclemoduletypes.StoreKey],
app.GetSubspace(oraclemoduletypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.Erc20Keeper,
app.EvmKeeper,
app.NftOwnershipKeeper,
app.DistrKeeper,
&stakingKeeper,
app.SettlementKeeper,
distrtypes.ModuleName,
)

// NOTE: app.Erc20Keeper is already initialized elsewhere
Expand Down Expand Up @@ -660,7 +645,6 @@ func New(

// Settlus app modules
settlementmodule.NewAppModule(appCodec, app.SettlementKeeper, app.AccountKeeper, app.BankKeeper),
nftownershipmodule.NewAppModule(appCodec, *app.NftOwnershipKeeper, app.AccountKeeper, app.EvmKeeper),
oraclemodule.NewAppModule(appCodec, *app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
)

Expand Down Expand Up @@ -697,7 +681,6 @@ func New(

// Settlus modules
settlementmoduletypes.ModuleName,
nftownershipmoduletypes.ModuleName,
oraclemoduletypes.ModuleName,
)

Expand Down Expand Up @@ -729,7 +712,6 @@ func New(

// Settlus modules
settlementmoduletypes.ModuleName,
nftownershipmoduletypes.ModuleName,
oraclemoduletypes.ModuleName,
)

Expand Down Expand Up @@ -767,7 +749,6 @@ func New(

// Settlus modules
settlementmoduletypes.ModuleName,
nftownershipmoduletypes.ModuleName,
oraclemoduletypes.ModuleName,

// NOTE: crisis module must go at the end to check for invariants on each module
Expand Down Expand Up @@ -1067,7 +1048,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

// Settlus modules
paramsKeeper.Subspace(settlementmoduletypes.ModuleName)
paramsKeeper.Subspace(nftownershipmoduletypes.ModuleName)
paramsKeeper.Subspace(oraclemoduletypes.ModuleName)

return paramsKeeper
Expand Down
2 changes: 1 addition & 1 deletion contracts/erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
evmtypes "github.com/settlus/chain/evmos/x/evm/types"

"github.com/settlus/chain/x/nftownership/types"
"github.com/settlus/chain/x/settlement/types"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions evmos/x/erc20/types/erc20.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/emirpasic/gods v1.18.1
github.com/ethereum/go-ethereum v1.11.6
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.4
Expand All @@ -33,15 +34,13 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
github.com/tendermint/tendermint v0.34.28
github.com/tendermint/tm-db v0.6.7
github.com/tidwall/gjson v1.17.1
github.com/tidwall/sjson v1.2.5
github.com/tyler-smith/go-bip39 v1.1.0
github.com/zondax/hid v0.9.2
go.opencensus.io v0.24.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/net v0.24.0
golang.org/x/text v0.14.0
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de
Expand Down Expand Up @@ -199,6 +198,7 @@ require (
github.com/status-im/keycard-go v0.2.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.5.0 // indirect
Expand All @@ -217,6 +217,7 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7j
github.com/edsrzf/mmap-go v1.0.0 h1:CEBF7HpRnUCSJgGUb5h1Gm7e3VkmVDrR8lvWVLtrOFw=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
10 changes: 0 additions & 10 deletions proto/settlus/nftownership/genesis.proto

This file was deleted.

13 changes: 0 additions & 13 deletions proto/settlus/nftownership/params.proto

This file was deleted.

43 changes: 0 additions & 43 deletions proto/settlus/nftownership/query.proto

This file was deleted.

2 changes: 1 addition & 1 deletion proto/settlus/oracle/v1alpha1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ message EventPrevote {
message EventVote {
string feeder = 1;
string validator = 2;
repeated BlockData block_data = 3;
repeated VoteData vote_data = 3;
}

message EventFeederDelegationConsent {
Expand Down
35 changes: 30 additions & 5 deletions proto/settlus/oracle/v1alpha1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@ message Chain {
string chain_url = 3;
}

enum OralceTopic {
BLOCK = 0;
OWNERSHIP = 1;
}

message OracleData {
OralceTopic topic = 1;
repeated string sources = 2;
}

message VoteData {
OralceTopic topic = 1;
repeated string data = 2;
}

message AggregatePrevote {
string hash = 1;
string voter = 2;
uint64 submit_block = 3;
}

message AggregateVote {
repeated BlockData block_data = 1;
repeated VoteData vote_data = 1;
string voter = 2;
}

Expand All @@ -62,8 +76,19 @@ message RoundInfo {
uint64 id = 1;
int64 prevote_end = 2;
int64 vote_end = 3;

repeated string chain_ids = 4;
repeated OracleData oracle_data = 4;
// UNIX time in milliseconds
int64 timestamp = 5;
}
}

message Nft {
string chain_id = 1;
string contract_addr = 2 [
(gogoproto.customtype) = "github.com/settlus/chain/types.HexAddressString",
(gogoproto.nullable) = false
];
string token_id = 3 [
(gogoproto.customtype) = "github.com/settlus/chain/types.HexAddressString",
(gogoproto.nullable) = false
];
}
3 changes: 2 additions & 1 deletion proto/settlus/oracle/v1alpha1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package settlus.oracle.v1alpha1;

import "cosmos/msg/v1/msg.proto";
import "settlus/oracle/v1alpha1/oracle.proto";

option go_package = "github.com/settlus/chain/x/oracle/types";

Expand Down Expand Up @@ -35,7 +36,7 @@ message MsgVote {

string feeder = 1;
string validator = 2;
string block_data_string = 3;
repeated VoteData vote_data = 3;
string salt = 4;
uint64 round_id = 5;
}
Expand Down
Loading

0 comments on commit 0ea2018

Please sign in to comment.