mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
Merge pull request #4 from Solovyov1796/pruning-module
Pruning module, merge code and rename all "kava"
This commit is contained in:
commit
d83175fee3
1
.gitignore
vendored
1
.gitignore
vendored
@ -41,3 +41,4 @@ build/linux
|
||||
# Go workspace files
|
||||
go.work
|
||||
go.work.sum
|
||||
.build/0gchaind
|
||||
|
@ -7,7 +7,7 @@ FROM golang:1.21-alpine AS build-env
|
||||
RUN apk add bash git make libc-dev gcc linux-headers eudev-dev jq curl
|
||||
|
||||
# Set working directory for the build
|
||||
WORKDIR /root/kava
|
||||
WORKDIR /root/0g-chain
|
||||
# default home directory is /root
|
||||
|
||||
# Copy dependency files first to facilitate dependency caching
|
||||
@ -32,6 +32,6 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
FROM alpine:3.15
|
||||
|
||||
RUN apk add bash jq curl
|
||||
COPY --from=build-env /go/bin/kava /bin/kava
|
||||
COPY --from=build-env /go/bin/0gchaind /bin/0gchaind
|
||||
|
||||
CMD ["kava"]
|
||||
CMD ["0gchaind"]
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM golang:1.21-bullseye AS kava-builder
|
||||
FROM golang:1.21-bullseye AS chain-builder
|
||||
|
||||
# Set up dependencies
|
||||
RUN apt-get update \
|
||||
@ -19,7 +19,7 @@ RUN git clone https://github.com/facebook/rocksdb.git \
|
||||
&& make -j$(nproc) install-shared \
|
||||
&& ldconfig
|
||||
|
||||
WORKDIR /root/kava
|
||||
WORKDIR /root/0gchain
|
||||
# Copy dependency files first to facilitate dependency caching
|
||||
COPY ./go.mod ./
|
||||
COPY ./go.sum ./
|
||||
@ -32,13 +32,13 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
# Add source files
|
||||
COPY . .
|
||||
|
||||
ARG kava_database_backend=rocksdb
|
||||
ENV KAVA_DATABASE_BACKEND=$kava_database_backend
|
||||
ARG 0gchain_database_backend=rocksdb
|
||||
ENV 0GCHAIN_DATABASE_BACKEND=$0gchain_database_backend
|
||||
|
||||
# Mount go build and mod caches as container caches, persisted between builder invocations
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
make install COSMOS_BUILD_OPTIONS=$KAVA_DATABASE_BACKEND
|
||||
make install COSMOS_BUILD_OPTIONS=$0GCHAIN_DATABASE_BACKEND
|
||||
|
||||
|
||||
FROM ubuntu:22.04
|
||||
@ -48,10 +48,10 @@ RUN apt-get update \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# copy rocksdb shared objects
|
||||
COPY --from=kava-builder /usr/local/lib/ /usr/local/lib/
|
||||
COPY --from=chain-builder /usr/local/lib/ /usr/local/lib/
|
||||
RUN ldconfig
|
||||
|
||||
# copy kava binary
|
||||
COPY --from=kava-builder /go/bin/kava /bin/kava
|
||||
# copy 0g-chain binary
|
||||
COPY --from=chain-builder /go/bin/0gchaind /bin/0gchaind
|
||||
|
||||
CMD ["kava"]
|
||||
CMD ["0gchaind"]
|
||||
|
45
Makefile
45
Makefile
@ -1,8 +1,10 @@
|
||||
################################################################################
|
||||
### Project Info ###
|
||||
################################################################################
|
||||
PROJECT_NAME := kava# unique namespace for project
|
||||
|
||||
PROJECT_NAME := 0g-chain# unique namespace for project
|
||||
BINARY_NAME := 0gchaind
|
||||
MAIN_ENTRY := ./cmd/$(BINARY_NAME)
|
||||
DOCKER_IMAGE_NAME := 0glabs/$(PROJECT_NAME)
|
||||
GO_BIN ?= go
|
||||
|
||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
@ -37,7 +39,7 @@ print-git-info:
|
||||
|
||||
.PHONY: print-version
|
||||
print-version:
|
||||
@echo "kava $(VERSION)\ntendermint $(TENDERMINT_VERSION)\ncosmos $(COSMOS_SDK_VERSION)"
|
||||
@echo "$(BINARY_NAME) $(VERSION)\ntendermint $(TENDERMINT_VERSION)\ncosmos $(COSMOS_SDK_VERSION)"
|
||||
|
||||
################################################################################
|
||||
### Project Settings ###
|
||||
@ -45,7 +47,7 @@ print-version:
|
||||
LEDGER_ENABLED ?= true
|
||||
DOCKER:=docker
|
||||
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
|
||||
HTTPS_GIT := https://github.com/Kava-Labs/kava.git
|
||||
HTTPS_GIT := https://github.com/0glabs/0g-chain.git
|
||||
|
||||
################################################################################
|
||||
### Machine Info ###
|
||||
@ -142,8 +144,8 @@ build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
|
||||
|
||||
# process linker flags
|
||||
|
||||
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=kava \
|
||||
-X github.com/cosmos/cosmos-sdk/version.AppName=kava \
|
||||
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(PROJECT_NAME) \
|
||||
-X github.com/cosmos/cosmos-sdk/version.AppName=$(PROJECT_NAME) \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION_NUMBER) \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Commit=$(GIT_COMMIT) \
|
||||
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
|
||||
@ -188,15 +190,15 @@ all: install
|
||||
|
||||
build: go.sum
|
||||
ifeq ($(OS), Windows_NT)
|
||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/kava.exe ./cmd/kava
|
||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/$(BINARY_NAME).exe $(MAIN_ENTRY)
|
||||
else
|
||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/kava ./cmd/kava
|
||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/$(BINARY_NAME) $(MAIN_ENTRY)
|
||||
endif
|
||||
|
||||
build-linux: go.sum
|
||||
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
|
||||
|
||||
# build on rocksdb-backed kava on macOS with shared libs from brew
|
||||
# build on rocksdb-backed 0gchaind on macOS with shared libs from brew
|
||||
# this assumes you are on macOS & these deps have been installed with brew:
|
||||
# rocksdb, snappy, lz4, and zstd
|
||||
# use like `make build-rocksdb-brew COSMOS_BUILD_OPTIONS=rocksdb`
|
||||
@ -205,7 +207,7 @@ build-rocksdb-brew:
|
||||
export CGO_LDFLAGS := -L$(shell brew --prefix rocksdb)/lib -lrocksdb -lstdc++ -lm -lz -L$(shell brew --prefix snappy)/lib -L$(shell brew --prefix lz4)/lib -L$(shell brew --prefix zstd)/lib
|
||||
|
||||
install: go.sum
|
||||
$(GO_BIN) install -mod=readonly $(BUILD_FLAGS) ./cmd/kava
|
||||
$(GO_BIN) install -mod=readonly $(BUILD_FLAGS) $(MAIN_ENTRY)
|
||||
|
||||
########################################
|
||||
### Tools & dependencies
|
||||
@ -227,6 +229,7 @@ go.sum: go.mod
|
||||
# Set to exclude riot links as they trigger false positives
|
||||
link-check:
|
||||
@$(GO_BIN) get -u github.com/raviqqe/liche@f57a5d1c5be4856454cb26de155a65a4fd856ee3
|
||||
# TODO: replace kava in following line with project name
|
||||
liche -r . --exclude "^http://127.*|^https://riot.im/app*|^http://kava-testnet*|^https://testnet-dex*|^https://kava3.data.kava.io*|^https://ipfs.io*|^https://apps.apple.com*|^https://kava.quicksync.io*"
|
||||
|
||||
|
||||
@ -241,26 +244,26 @@ format:
|
||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w
|
||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/tendermint
|
||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
|
||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/kava-labs/kava
|
||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/0glabs/0g-chain
|
||||
.PHONY: format
|
||||
|
||||
###############################################################################
|
||||
### Localnet ###
|
||||
###############################################################################
|
||||
|
||||
# Build docker image and tag as kava/kava:local
|
||||
# Build docker image and tag as 0glabs/0g-chain:local
|
||||
docker-build:
|
||||
DOCKER_BUILDKIT=1 $(DOCKER) build -t kava/kava:local .
|
||||
DOCKER_BUILDKIT=1 $(DOCKER) build -t $(DOCKER_IMAGE_NAME):local .
|
||||
|
||||
docker-build-rocksdb:
|
||||
DOCKER_BUILDKIT=1 $(DOCKER) build -f Dockerfile-rocksdb -t kava/kava:local .
|
||||
DOCKER_BUILDKIT=1 $(DOCKER) build -f Dockerfile-rocksdb -t $(DOCKER_IMAGE_NAME):local .
|
||||
|
||||
build-docker-local-kava:
|
||||
build-docker-local-0gchain:
|
||||
@$(MAKE) -C networks/local
|
||||
|
||||
# Run a 4-node testnet locally
|
||||
localnet-start: build-linux localnet-stop
|
||||
@if ! [ -f build/node0/kvd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/kvd:Z kava/kavanode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
|
||||
@if ! [ -f build/node0/kvd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/kvd:Z $(DOCKER_IMAGE_NAME)-node testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
|
||||
docker-compose up -d
|
||||
|
||||
localnet-stop:
|
||||
@ -269,7 +272,7 @@ localnet-stop:
|
||||
# Launch a new single validator chain
|
||||
start:
|
||||
./contrib/devnet/init-new-chain.sh
|
||||
kava start
|
||||
$(BINARY_NAME) start
|
||||
|
||||
#proto-format:
|
||||
#@echo "Formatting Protobuf files"
|
||||
@ -310,7 +313,7 @@ test:
|
||||
@$(GO_BIN) test $$($(GO_BIN) list ./... | grep -v 'contrib' | grep -v 'tests/e2e')
|
||||
|
||||
test-rocksdb:
|
||||
@go test -tags=rocksdb ./cmd/kava/opendb
|
||||
@go test -tags=rocksdb $(MAIN_ENTRY)/opendb
|
||||
|
||||
# Run cli integration tests
|
||||
# `-p 4` to use 4 cores, `-tags cli_test` to tell $(GO_BIN) not to ignore the cli package
|
||||
@ -326,15 +329,15 @@ test-migrate:
|
||||
# This submits an AWS Batch job to run a lot of sims, each within a docker image. Results are uploaded to S3
|
||||
start-remote-sims:
|
||||
# build the image used for running sims in, and tag it
|
||||
docker build -f simulations/Dockerfile -t kava/kava-sim:master .
|
||||
docker build -f simulations/Dockerfile -t $(DOCKER_IMAGE_NAME)-sim:master .
|
||||
# push that image to the hub
|
||||
docker push kava/kava-sim:master
|
||||
docker push $(DOCKER_IMAGE_NAME)-sim:master
|
||||
# submit an array job on AWS Batch, using 1000 seeds, spot instances
|
||||
aws batch submit-job \
|
||||
-—job-name "master-$(VERSION)" \
|
||||
-—job-queue “simulation-1-queue-spot" \
|
||||
-—array-properties size=1000 \
|
||||
-—job-definition kava-sim-master \
|
||||
-—job-definition $(BINARY_NAME)-sim-master \
|
||||
-—container-override environment=[{SIM_NAME=master-$(VERSION)}]
|
||||
|
||||
update-kvtool:
|
||||
|
@ -32,15 +32,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
|
||||
"github.com/kava-labs/kava/x/auction"
|
||||
"github.com/kava-labs/kava/x/bep3"
|
||||
"github.com/kava-labs/kava/x/cdp"
|
||||
"github.com/kava-labs/kava/x/committee"
|
||||
"github.com/kava-labs/kava/x/incentive"
|
||||
"github.com/kava-labs/kava/x/kavadist"
|
||||
"github.com/kava-labs/kava/x/pricefeed"
|
||||
"github.com/kava-labs/kava/x/swap"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||
)
|
||||
|
||||
type StoreKeysPrefixes struct {
|
||||
|
@ -9,7 +9,8 @@ import (
|
||||
"testing"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||
@ -52,9 +53,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
||||
}
|
||||
|
||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
suite.Require().NoError(err)
|
||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
simRequest := app.SimulateRequest{
|
||||
@ -62,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
bank.MsgSend{
|
||||
FromAddress: fromAddr,
|
||||
ToAddress: toAddr,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
},
|
||||
Fee: auth.StdFee{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||
Gas: 1e6,
|
||||
},
|
||||
Memo: "test memo",
|
||||
|
@ -6,12 +6,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
tmdb "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -22,13 +20,14 @@ import (
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
bep3types "github.com/kava-labs/kava/x/bep3/types"
|
||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@ -36,10 +35,10 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(10)
|
||||
unauthed := testAddresses[0:2]
|
||||
unauthedKeys := testPrivKeys[0:2]
|
||||
deputy := testAddresses[2]
|
||||
deputyKey := testPrivKeys[2]
|
||||
oracles := testAddresses[3:6]
|
||||
oraclesKeys := testPrivKeys[3:6]
|
||||
// deputy := testAddresses[2]
|
||||
// deputyKey := testPrivKeys[2]
|
||||
// oracles := testAddresses[3:6]
|
||||
// oraclesKeys := testPrivKeys[3:6]
|
||||
manual := testAddresses[6:]
|
||||
manualKeys := testPrivKeys[6:]
|
||||
|
||||
@ -53,7 +52,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
App: *app.NewApp(
|
||||
log.NewNopLogger(),
|
||||
tmdb.NewMemDB(),
|
||||
app.DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
encodingConfig,
|
||||
opts,
|
||||
@ -67,11 +66,11 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
chainID,
|
||||
app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||
testAddresses,
|
||||
),
|
||||
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||
newPricefeedGenStateMulti(tApp.AppCodec(), oracles),
|
||||
// newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||
// newPricefeedGenStateMulti(tApp.AppCodec(), oracles),
|
||||
)
|
||||
|
||||
testcases := []struct {
|
||||
@ -86,18 +85,18 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
privKey: unauthedKeys[1],
|
||||
expectPass: false,
|
||||
},
|
||||
{
|
||||
name: "oracle",
|
||||
address: oracles[1],
|
||||
privKey: oraclesKeys[1],
|
||||
expectPass: true,
|
||||
},
|
||||
{
|
||||
name: "deputy",
|
||||
address: deputy,
|
||||
privKey: deputyKey,
|
||||
expectPass: true,
|
||||
},
|
||||
// {
|
||||
// name: "oracle",
|
||||
// address: oracles[1],
|
||||
// privKey: oraclesKeys[1],
|
||||
// expectPass: true,
|
||||
// },
|
||||
// {
|
||||
// name: "deputy",
|
||||
// address: deputy,
|
||||
// privKey: deputyKey,
|
||||
// expectPass: true,
|
||||
// },
|
||||
{
|
||||
name: "manual",
|
||||
address: manual[1],
|
||||
@ -115,7 +114,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
tc.address,
|
||||
testAddresses[0],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -145,53 +144,53 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newPricefeedGenStateMulti(cdc codec.JSONCodec, oracles []sdk.AccAddress) app.GenesisState {
|
||||
pfGenesis := pricefeedtypes.GenesisState{
|
||||
Params: pricefeedtypes.Params{
|
||||
Markets: []pricefeedtypes.Market{
|
||||
{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracles, Active: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
|
||||
}
|
||||
// func newPricefeedGenStateMulti(cdc codec.JSONCodec, oracles []sdk.AccAddress) app.GenesisState {
|
||||
// pfGenesis := pricefeedtypes.GenesisState{
|
||||
// Params: pricefeedtypes.Params{
|
||||
// Markets: []pricefeedtypes.Market{
|
||||
// {MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracles, Active: true},
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
|
||||
// }
|
||||
|
||||
func newBep3GenStateMulti(cdc codec.JSONCodec, deputyAddress sdk.AccAddress) app.GenesisState {
|
||||
bep3Genesis := bep3types.GenesisState{
|
||||
Params: bep3types.Params{
|
||||
AssetParams: bep3types.AssetParams{
|
||||
bep3types.AssetParam{
|
||||
Denom: "bnb",
|
||||
CoinID: 714,
|
||||
SupplyLimit: bep3types.SupplyLimit{
|
||||
Limit: sdkmath.NewInt(350000000000000),
|
||||
TimeLimited: false,
|
||||
TimeBasedLimit: sdk.ZeroInt(),
|
||||
TimePeriod: time.Hour,
|
||||
},
|
||||
Active: true,
|
||||
DeputyAddress: deputyAddress,
|
||||
FixedFee: sdkmath.NewInt(1000),
|
||||
MinSwapAmount: sdk.OneInt(),
|
||||
MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
},
|
||||
},
|
||||
},
|
||||
Supplies: bep3types.AssetSupplies{
|
||||
bep3types.NewAssetSupply(
|
||||
sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
time.Duration(0),
|
||||
),
|
||||
},
|
||||
PreviousBlockTime: bep3types.DefaultPreviousBlockTime,
|
||||
}
|
||||
return app.GenesisState{bep3types.ModuleName: cdc.MustMarshalJSON(&bep3Genesis)}
|
||||
}
|
||||
// func newBep3GenStateMulti(cdc codec.JSONCodec, deputyAddress sdk.AccAddress) app.GenesisState {
|
||||
// bep3Genesis := bep3types.GenesisState{
|
||||
// Params: bep3types.Params{
|
||||
// AssetParams: bep3types.AssetParams{
|
||||
// bep3types.AssetParam{
|
||||
// Denom: "bnb",
|
||||
// CoinID: 714,
|
||||
// SupplyLimit: bep3types.SupplyLimit{
|
||||
// Limit: sdkmath.NewInt(350000000000000),
|
||||
// TimeLimited: false,
|
||||
// TimeBasedLimit: sdk.ZeroInt(),
|
||||
// TimePeriod: time.Hour,
|
||||
// },
|
||||
// Active: true,
|
||||
// DeputyAddress: deputyAddress,
|
||||
// FixedFee: sdkmath.NewInt(1000),
|
||||
// MinSwapAmount: sdk.OneInt(),
|
||||
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
// MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// Supplies: bep3types.AssetSupplies{
|
||||
// bep3types.NewAssetSupply(
|
||||
// sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
// sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
// sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
// sdk.NewCoin("bnb", sdk.ZeroInt()),
|
||||
// time.Duration(0),
|
||||
// ),
|
||||
// },
|
||||
// PreviousBlockTime: bep3types.DefaultPreviousBlockTime,
|
||||
// }
|
||||
// return app.GenesisState{bep3types.ModuleName: cdc.MustMarshalJSON(&bep3Genesis)}
|
||||
// }
|
||||
|
||||
func TestAppAnteHandler_RejectMsgsInAuthz(t *testing.T) {
|
||||
testPrivKeys, testAddresses := app.GeneratePrivKeyAddressPairs(10)
|
||||
|
@ -10,8 +10,9 @@ import (
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/ante"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
||||
@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[2],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -14,8 +14,9 @@ import (
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/ante"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
||||
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
[]sdk.Msg{banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
)}),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
),
|
||||
&evmtypes.MsgEthereumTx{},
|
||||
},
|
||||
|
@ -33,13 +33,15 @@ import (
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
||||
evmutilkeeper "github.com/kava-labs/kava/x/evmutil/keeper"
|
||||
evmutiltestutil "github.com/kava-labs/kava/x/evmutil/testutil"
|
||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
||||
hardtypes "github.com/kava-labs/kava/x/hard/types"
|
||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
// hardtypes "github.com/0glabs/0g-chain/x/hard/types"
|
||||
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -158,7 +160,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// Genesis states
|
||||
evmGs := evmtypes.NewGenesisState(
|
||||
evmtypes.NewParams(
|
||||
"akava", // evmDenom
|
||||
chaincfg.BaseDenom, // evmDenom
|
||||
false, // allowedUnprotectedTxs
|
||||
true, // enableCreate
|
||||
true, // enableCall
|
||||
@ -173,104 +175,104 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
feemarketGenesis.Params.EnableHeight = 1
|
||||
feemarketGenesis.Params.NoBaseFee = false
|
||||
|
||||
cdpGenState := cdptypes.DefaultGenesisState()
|
||||
cdpGenState.Params.GlobalDebtLimit = sdk.NewInt64Coin("usdx", 53000000000000)
|
||||
cdpGenState.Params.CollateralParams = cdptypes.CollateralParams{
|
||||
{
|
||||
Denom: USDCCoinDenom,
|
||||
Type: USDCCDPType,
|
||||
LiquidationRatio: sdk.MustNewDecFromStr("1.01"),
|
||||
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
|
||||
StabilityFee: sdk.OneDec(),
|
||||
AuctionSize: sdkmath.NewIntFromUint64(10000000000),
|
||||
LiquidationPenalty: sdk.MustNewDecFromStr("0.05"),
|
||||
CheckCollateralizationIndexCount: sdkmath.NewInt(10),
|
||||
KeeperRewardPercentage: sdk.MustNewDecFromStr("0.01"),
|
||||
SpotMarketID: "usdc:usd",
|
||||
LiquidationMarketID: "usdc:usd:30",
|
||||
ConversionFactor: sdkmath.NewInt(18),
|
||||
},
|
||||
}
|
||||
// cdpGenState := cdptypes.DefaultGenesisState()
|
||||
// cdpGenState.Params.GlobalDebtLimit = sdk.NewInt64Coin("usdx", 53000000000000)
|
||||
// cdpGenState.Params.CollateralParams = cdptypes.CollateralParams{
|
||||
// {
|
||||
// Denom: USDCCoinDenom,
|
||||
// Type: USDCCDPType,
|
||||
// LiquidationRatio: sdk.MustNewDecFromStr("1.01"),
|
||||
// DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
|
||||
// StabilityFee: sdk.OneDec(),
|
||||
// AuctionSize: sdkmath.NewIntFromUint64(10000000000),
|
||||
// LiquidationPenalty: sdk.MustNewDecFromStr("0.05"),
|
||||
// CheckCollateralizationIndexCount: sdkmath.NewInt(10),
|
||||
// KeeperRewardPercentage: sdk.MustNewDecFromStr("0.01"),
|
||||
// SpotMarketID: "usdc:usd",
|
||||
// LiquidationMarketID: "usdc:usd:30",
|
||||
// ConversionFactor: sdkmath.NewInt(18),
|
||||
// },
|
||||
// }
|
||||
|
||||
hardGenState := hardtypes.DefaultGenesisState()
|
||||
hardGenState.Params.MoneyMarkets = []hardtypes.MoneyMarket{
|
||||
{
|
||||
Denom: "usdx",
|
||||
BorrowLimit: hardtypes.BorrowLimit{
|
||||
HasMaxLimit: true,
|
||||
MaximumLimit: sdk.MustNewDecFromStr("100000000000"),
|
||||
LoanToValue: sdk.MustNewDecFromStr("1"),
|
||||
},
|
||||
SpotMarketID: "usdx:usd",
|
||||
ConversionFactor: sdkmath.NewInt(1_000_000),
|
||||
InterestRateModel: hardtypes.InterestRateModel{
|
||||
BaseRateAPY: sdk.MustNewDecFromStr("0.05"),
|
||||
BaseMultiplier: sdk.MustNewDecFromStr("2"),
|
||||
Kink: sdk.MustNewDecFromStr("0.8"),
|
||||
JumpMultiplier: sdk.MustNewDecFromStr("10"),
|
||||
},
|
||||
ReserveFactor: sdk.MustNewDecFromStr("0.05"),
|
||||
KeeperRewardPercentage: sdk.ZeroDec(),
|
||||
},
|
||||
}
|
||||
// hardGenState := hardtypes.DefaultGenesisState()
|
||||
// hardGenState.Params.MoneyMarkets = []hardtypes.MoneyMarket{
|
||||
// {
|
||||
// Denom: "usdx",
|
||||
// BorrowLimit: hardtypes.BorrowLimit{
|
||||
// HasMaxLimit: true,
|
||||
// MaximumLimit: sdk.MustNewDecFromStr("100000000000"),
|
||||
// LoanToValue: sdk.MustNewDecFromStr("1"),
|
||||
// },
|
||||
// SpotMarketID: "usdx:usd",
|
||||
// ConversionFactor: sdkmath.NewInt(1_000_000),
|
||||
// InterestRateModel: hardtypes.InterestRateModel{
|
||||
// BaseRateAPY: sdk.MustNewDecFromStr("0.05"),
|
||||
// BaseMultiplier: sdk.MustNewDecFromStr("2"),
|
||||
// Kink: sdk.MustNewDecFromStr("0.8"),
|
||||
// JumpMultiplier: sdk.MustNewDecFromStr("10"),
|
||||
// },
|
||||
// ReserveFactor: sdk.MustNewDecFromStr("0.05"),
|
||||
// KeeperRewardPercentage: sdk.ZeroDec(),
|
||||
// },
|
||||
// }
|
||||
|
||||
pricefeedGenState := pricefeedtypes.DefaultGenesisState()
|
||||
pricefeedGenState.Params.Markets = []pricefeedtypes.Market{
|
||||
{
|
||||
MarketID: "usdx:usd",
|
||||
BaseAsset: "usdx",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: []sdk.AccAddress{},
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "usdc:usd",
|
||||
BaseAsset: "usdc",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: []sdk.AccAddress{},
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "usdc:usd:30",
|
||||
BaseAsset: "usdc",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: []sdk.AccAddress{},
|
||||
Active: true,
|
||||
},
|
||||
}
|
||||
pricefeedGenState.PostedPrices = []pricefeedtypes.PostedPrice{
|
||||
{
|
||||
MarketID: "usdx:usd",
|
||||
OracleAddress: sdk.AccAddress{},
|
||||
Price: sdk.MustNewDecFromStr("1.00"),
|
||||
Expiry: time.Now().Add(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
MarketID: "usdc:usd",
|
||||
OracleAddress: sdk.AccAddress{},
|
||||
Price: sdk.MustNewDecFromStr("1.00"),
|
||||
Expiry: time.Now().Add(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
MarketID: "usdc:usd:30",
|
||||
OracleAddress: sdk.AccAddress{},
|
||||
Price: sdk.MustNewDecFromStr("1.00"),
|
||||
Expiry: time.Now().Add(1 * time.Hour),
|
||||
},
|
||||
}
|
||||
// pricefeedGenState := pricefeedtypes.DefaultGenesisState()
|
||||
// pricefeedGenState.Params.Markets = []pricefeedtypes.Market{
|
||||
// {
|
||||
// MarketID: "usdx:usd",
|
||||
// BaseAsset: "usdx",
|
||||
// QuoteAsset: "usd",
|
||||
// Oracles: []sdk.AccAddress{},
|
||||
// Active: true,
|
||||
// },
|
||||
// {
|
||||
// MarketID: "usdc:usd",
|
||||
// BaseAsset: "usdc",
|
||||
// QuoteAsset: "usd",
|
||||
// Oracles: []sdk.AccAddress{},
|
||||
// Active: true,
|
||||
// },
|
||||
// {
|
||||
// MarketID: "usdc:usd:30",
|
||||
// BaseAsset: "usdc",
|
||||
// QuoteAsset: "usd",
|
||||
// Oracles: []sdk.AccAddress{},
|
||||
// Active: true,
|
||||
// },
|
||||
// }
|
||||
// pricefeedGenState.PostedPrices = []pricefeedtypes.PostedPrice{
|
||||
// {
|
||||
// MarketID: "usdx:usd",
|
||||
// OracleAddress: sdk.AccAddress{},
|
||||
// Price: sdk.MustNewDecFromStr("1.00"),
|
||||
// Expiry: time.Now().Add(1 * time.Hour),
|
||||
// },
|
||||
// {
|
||||
// MarketID: "usdc:usd",
|
||||
// OracleAddress: sdk.AccAddress{},
|
||||
// Price: sdk.MustNewDecFromStr("1.00"),
|
||||
// Expiry: time.Now().Add(1 * time.Hour),
|
||||
// },
|
||||
// {
|
||||
// MarketID: "usdc:usd:30",
|
||||
// OracleAddress: sdk.AccAddress{},
|
||||
// Price: sdk.MustNewDecFromStr("1.00"),
|
||||
// Expiry: time.Now().Add(1 * time.Hour),
|
||||
// },
|
||||
// }
|
||||
|
||||
genState := app.GenesisState{
|
||||
evmtypes.ModuleName: cdc.MustMarshalJSON(evmGs),
|
||||
feemarkettypes.ModuleName: cdc.MustMarshalJSON(feemarketGenesis),
|
||||
cdptypes.ModuleName: cdc.MustMarshalJSON(&cdpGenState),
|
||||
hardtypes.ModuleName: cdc.MustMarshalJSON(&hardGenState),
|
||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
// cdptypes.ModuleName: cdc.MustMarshalJSON(&cdpGenState),
|
||||
// hardtypes.ModuleName: cdc.MustMarshalJSON(&hardGenState),
|
||||
// pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
}
|
||||
|
||||
// funds our test accounts with some ukava
|
||||
// funds our test accounts with some a0gi
|
||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||
)
|
||||
|
||||
@ -357,45 +359,17 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
params := evmKeeper.GetParams(suite.ctx)
|
||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
{Name: "receiver", Type: "string"},
|
||||
{Name: "kava_erc20_address", Type: "string"},
|
||||
{Name: "0gchain_erc20_address", Type: "string"},
|
||||
{Name: "amount", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
||||
MsgValueTypeName: "MsgValueCDPCreate",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "principal", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueCDPDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "owner", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueHardDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
@ -403,23 +377,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
{Name: "amount", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgRepayDebt",
|
||||
MsgValueTypeName: "MsgValueCDPRepayDebt",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
{Name: "payment", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgWithdraw",
|
||||
MsgValueTypeName: "MsgValueHardWithdraw",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
}
|
||||
evmKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
@ -465,7 +422,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
||||
suite.tApp.FundModuleAccount(
|
||||
suite.ctx,
|
||||
evmutiltypes.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||
@ -487,40 +444,43 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx bool
|
||||
errMsg string
|
||||
}{
|
||||
{
|
||||
name: "processes deposit eip712 messages successfully",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 99,
|
||||
},
|
||||
// TODO: need fix
|
||||
// {
|
||||
// name: "processes deposit eip712 messages successfully",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 99,
|
||||
// },
|
||||
{
|
||||
name: "fails when convertion more erc20 usdc than balance",
|
||||
usdcDepositAmt: 51_000,
|
||||
usdxToMintAmt: 100,
|
||||
errMsg: "transfer amount exceeds balance",
|
||||
},
|
||||
{
|
||||
name: "fails when minting more usdx than allowed",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 100,
|
||||
errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||
},
|
||||
{
|
||||
name: "fails when trying to convert usdc for another address",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 90,
|
||||
errMsg: "unauthorized",
|
||||
failCheckTx: true,
|
||||
updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||
convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||
suite.testEVMAddr2,
|
||||
suite.testAddr,
|
||||
suite.usdcEVMAddr,
|
||||
suite.getEVMAmount(100),
|
||||
)
|
||||
msgs[0] = &convertMsg
|
||||
return msgs
|
||||
},
|
||||
},
|
||||
// TODO: need fix
|
||||
// {
|
||||
// name: "fails when minting more usdx than allowed",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 100,
|
||||
// errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||
// },
|
||||
// TODO: need fix
|
||||
// {
|
||||
// name: "fails when trying to convert usdc for another address",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 90,
|
||||
// errMsg: "unauthorized",
|
||||
// failCheckTx: true,
|
||||
// updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||
// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||
// suite.testEVMAddr2,
|
||||
// suite.testAddr,
|
||||
// suite.usdcEVMAddr,
|
||||
// suite.getEVMAmount(100),
|
||||
// )
|
||||
// msgs[0] = &convertMsg
|
||||
// return msgs
|
||||
// },
|
||||
// },
|
||||
{
|
||||
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
||||
usdcDepositAmt: 100,
|
||||
@ -562,7 +522,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
errMsg: "insufficient funds",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
bk := suite.tApp.GetBankKeeper()
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ukava")
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom)
|
||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||
return txBuilder
|
||||
},
|
||||
@ -574,9 +534,9 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid chain-id",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
suite.testAddr, suite.testPrivKey, "0gchaintest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
},
|
||||
},
|
||||
@ -587,7 +547,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid pubkey",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -607,27 +567,27 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
suite.usdcEVMAddr,
|
||||
usdcAmt,
|
||||
)
|
||||
usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(tc.usdxToMintAmt))
|
||||
mintMsg := cdptypes.NewMsgCreateCDP(
|
||||
suite.testAddr,
|
||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
USDCCDPType,
|
||||
)
|
||||
lendMsg := hardtypes.NewMsgDeposit(
|
||||
suite.testAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
)
|
||||
// usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(tc.usdxToMintAmt))
|
||||
// mintMsg := cdptypes.NewMsgCreateCDP(
|
||||
// suite.testAddr,
|
||||
// sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||
// sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
// USDCCDPType,
|
||||
// )
|
||||
// lendMsg := hardtypes.NewMsgDeposit(
|
||||
// suite.testAddr,
|
||||
// sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
// )
|
||||
msgs := []sdk.Msg{
|
||||
&convertMsg,
|
||||
&mintMsg,
|
||||
&lendMsg,
|
||||
// &mintMsg,
|
||||
// &lendMsg,
|
||||
}
|
||||
if tc.updateMsgs != nil {
|
||||
msgs = tc.updateMsgs(msgs)
|
||||
}
|
||||
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -665,17 +625,17 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
suite.Require().Equal(sdk.ZeroInt(), amt.Amount)
|
||||
|
||||
// validate cdp
|
||||
cdp, found := suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||
suite.Require().True(found)
|
||||
suite.Require().Equal(suite.testAddr, cdp.Owner)
|
||||
suite.Require().Equal(sdk.NewCoin(USDCCoinDenom, suite.getEVMAmount(100)), cdp.Collateral)
|
||||
suite.Require().Equal(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000)), cdp.Principal)
|
||||
// cdp, found := suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||
// suite.Require().True(found)
|
||||
// suite.Require().Equal(suite.testAddr, cdp.Owner)
|
||||
// suite.Require().Equal(sdk.NewCoin(USDCCoinDenom, suite.getEVMAmount(100)), cdp.Collateral)
|
||||
// suite.Require().Equal(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000)), cdp.Principal)
|
||||
|
||||
// validate hard
|
||||
hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
suite.Require().True(found)
|
||||
suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||
// // validate hard
|
||||
// hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
// suite.Require().True(found)
|
||||
// suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||
// suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||
} else {
|
||||
suite.Require().NotEqual(resDeliverTx.Code, uint32(0), resCheckTx.Log)
|
||||
suite.Require().Contains(resDeliverTx.Log, tc.errMsg)
|
||||
@ -695,25 +655,25 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
suite.usdcEVMAddr,
|
||||
usdcAmt,
|
||||
)
|
||||
usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(99))
|
||||
mintMsg := cdptypes.NewMsgCreateCDP(
|
||||
suite.testAddr,
|
||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
USDCCDPType,
|
||||
)
|
||||
lendMsg := hardtypes.NewMsgDeposit(
|
||||
suite.testAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
)
|
||||
// usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(99))
|
||||
// mintMsg := cdptypes.NewMsgCreateCDP(
|
||||
// suite.testAddr,
|
||||
// sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||
// sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
// USDCCDPType,
|
||||
// )
|
||||
// lendMsg := hardtypes.NewMsgDeposit(
|
||||
// suite.testAddr,
|
||||
// sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
// )
|
||||
depositMsgs := []sdk.Msg{
|
||||
&convertMsg,
|
||||
&mintMsg,
|
||||
&lendMsg,
|
||||
// &mintMsg,
|
||||
// &lendMsg,
|
||||
}
|
||||
|
||||
// deliver deposit msg
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||
)
|
||||
@ -726,11 +686,11 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
)
|
||||
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
||||
|
||||
// validate hard
|
||||
hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
suite.Require().True(found)
|
||||
suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||
// // validate hard
|
||||
// hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
// suite.Require().True(found)
|
||||
// suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||
// suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||
|
||||
// validate erc20 balance
|
||||
coinBal, err := suite.evmutilKeeper.QueryERC20BalanceOf(suite.ctx, suite.usdcEVMAddr, suite.testEVMAddr)
|
||||
@ -743,18 +703,18 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
suite.testEVMAddr.String(),
|
||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||
)
|
||||
cdpWithdrawMsg := cdptypes.NewMsgRepayDebt(
|
||||
suite.testAddr,
|
||||
USDCCDPType,
|
||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
)
|
||||
hardWithdrawMsg := hardtypes.NewMsgWithdraw(
|
||||
suite.testAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
)
|
||||
// cdpWithdrawMsg := cdptypes.NewMsgRepayDebt(
|
||||
// suite.testAddr,
|
||||
// USDCCDPType,
|
||||
// sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
||||
// )
|
||||
// hardWithdrawMsg := hardtypes.NewMsgWithdraw(
|
||||
// suite.testAddr,
|
||||
// sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
||||
// )
|
||||
withdrawMsgs := []sdk.Msg{
|
||||
&hardWithdrawMsg,
|
||||
&cdpWithdrawMsg,
|
||||
// &hardWithdrawMsg,
|
||||
// &cdpWithdrawMsg,
|
||||
&withdrawConvertMsg,
|
||||
}
|
||||
|
||||
@ -772,10 +732,10 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
||||
|
||||
// validate hard & cdp should be repayed
|
||||
_, found = suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
suite.Require().False(found)
|
||||
_, found = suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||
suite.Require().False(found)
|
||||
// _, found = suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||
// suite.Require().False(found)
|
||||
// _, found = suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||
// suite.Require().False(found)
|
||||
|
||||
// validate user cosmos erc20/usd balance
|
||||
bk := suite.tApp.GetBankKeeper()
|
||||
|
@ -11,8 +11,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/ante"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
||||
@ -30,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
|
||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||
EvmDenom: "akava",
|
||||
EvmDenom: chaincfg.BaseDenom,
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
mustParseDecCoins(""),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price",
|
||||
mustParseDecCoins("0ukava"),
|
||||
mustParseDecCoins("0ukava"),
|
||||
"zero a0gi gas price",
|
||||
mustParseDecCoins("0a0gi"),
|
||||
mustParseDecCoins("0a0gi"),
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price",
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
"non-zero a0gi gas price",
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0ukava;100000akava"),
|
||||
mustParseDecCoins("0ukava"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0a0gi;100000neuron"),
|
||||
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price, other token",
|
||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price, other token",
|
||||
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
||||
"non-zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,9 @@ import (
|
||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/ante"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
||||
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreateVestingAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||
false,
|
||||
),
|
||||
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreatePermanentLockedAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
true,
|
||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"other messages not affected",
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
false,
|
||||
"",
|
||||
|
511
app/app.go
511
app/app.go
@ -3,10 +3,6 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
stdlog "log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -103,77 +99,27 @@ import (
|
||||
"github.com/evmos/ethermint/x/feemarket"
|
||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/kava-labs/kava/app/ante"
|
||||
kavaparams "github.com/kava-labs/kava/app/params"
|
||||
"github.com/kava-labs/kava/x/auction"
|
||||
auctionkeeper "github.com/kava-labs/kava/x/auction/keeper"
|
||||
auctiontypes "github.com/kava-labs/kava/x/auction/types"
|
||||
"github.com/kava-labs/kava/x/bep3"
|
||||
bep3keeper "github.com/kava-labs/kava/x/bep3/keeper"
|
||||
bep3types "github.com/kava-labs/kava/x/bep3/types"
|
||||
"github.com/kava-labs/kava/x/cdp"
|
||||
cdpkeeper "github.com/kava-labs/kava/x/cdp/keeper"
|
||||
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
||||
"github.com/kava-labs/kava/x/committee"
|
||||
committeeclient "github.com/kava-labs/kava/x/committee/client"
|
||||
committeekeeper "github.com/kava-labs/kava/x/committee/keeper"
|
||||
committeetypes "github.com/kava-labs/kava/x/committee/types"
|
||||
"github.com/kava-labs/kava/x/community"
|
||||
communityclient "github.com/kava-labs/kava/x/community/client"
|
||||
communitykeeper "github.com/kava-labs/kava/x/community/keeper"
|
||||
communitytypes "github.com/kava-labs/kava/x/community/types"
|
||||
earn "github.com/kava-labs/kava/x/earn"
|
||||
earnclient "github.com/kava-labs/kava/x/earn/client"
|
||||
earnkeeper "github.com/kava-labs/kava/x/earn/keeper"
|
||||
earntypes "github.com/kava-labs/kava/x/earn/types"
|
||||
evmutil "github.com/kava-labs/kava/x/evmutil"
|
||||
evmutilkeeper "github.com/kava-labs/kava/x/evmutil/keeper"
|
||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
||||
"github.com/kava-labs/kava/x/hard"
|
||||
hardkeeper "github.com/kava-labs/kava/x/hard/keeper"
|
||||
hardtypes "github.com/kava-labs/kava/x/hard/types"
|
||||
"github.com/kava-labs/kava/x/incentive"
|
||||
incentivekeeper "github.com/kava-labs/kava/x/incentive/keeper"
|
||||
incentivetypes "github.com/kava-labs/kava/x/incentive/types"
|
||||
issuance "github.com/kava-labs/kava/x/issuance"
|
||||
issuancekeeper "github.com/kava-labs/kava/x/issuance/keeper"
|
||||
issuancetypes "github.com/kava-labs/kava/x/issuance/types"
|
||||
"github.com/kava-labs/kava/x/kavadist"
|
||||
kavadistclient "github.com/kava-labs/kava/x/kavadist/client"
|
||||
kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper"
|
||||
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
|
||||
"github.com/kava-labs/kava/x/liquid"
|
||||
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
|
||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
||||
metrics "github.com/kava-labs/kava/x/metrics"
|
||||
metricstypes "github.com/kava-labs/kava/x/metrics/types"
|
||||
pricefeed "github.com/kava-labs/kava/x/pricefeed"
|
||||
pricefeedkeeper "github.com/kava-labs/kava/x/pricefeed/keeper"
|
||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
||||
"github.com/kava-labs/kava/x/router"
|
||||
routerkeeper "github.com/kava-labs/kava/x/router/keeper"
|
||||
routertypes "github.com/kava-labs/kava/x/router/types"
|
||||
savings "github.com/kava-labs/kava/x/savings"
|
||||
savingskeeper "github.com/kava-labs/kava/x/savings/keeper"
|
||||
savingstypes "github.com/kava-labs/kava/x/savings/types"
|
||||
"github.com/kava-labs/kava/x/swap"
|
||||
swapkeeper "github.com/kava-labs/kava/x/swap/keeper"
|
||||
swaptypes "github.com/kava-labs/kava/x/swap/types"
|
||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
||||
validatorvestingrest "github.com/kava-labs/kava/x/validator-vesting/client/rest"
|
||||
validatorvestingtypes "github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
const (
|
||||
appName = "kava"
|
||||
evmutil "github.com/0glabs/0g-chain/x/evmutil"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
|
||||
committee "github.com/0glabs/0g-chain/x/committee/v1"
|
||||
committeekeeper "github.com/0glabs/0g-chain/x/committee/v1/keeper"
|
||||
committeetypes "github.com/0glabs/0g-chain/x/committee/v1/types"
|
||||
das "github.com/0glabs/0g-chain/x/das/v1"
|
||||
daskeeper "github.com/0glabs/0g-chain/x/das/v1/keeper"
|
||||
dastypes "github.com/0glabs/0g-chain/x/das/v1/types"
|
||||
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||
validatorvestingrest "github.com/0glabs/0g-chain/x/validator-vesting/client/rest"
|
||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultNodeHome default home directories for the application daemon
|
||||
DefaultNodeHome string
|
||||
|
||||
// ModuleBasics manages simple versions of full app modules.
|
||||
// It's used for things such as codec registration and genesis file verification.
|
||||
ModuleBasics = module.NewBasicManager(
|
||||
@ -189,12 +135,6 @@ var (
|
||||
upgradeclient.LegacyCancelProposalHandler,
|
||||
ibcclientclient.UpdateClientProposalHandler,
|
||||
ibcclientclient.UpgradeProposalHandler,
|
||||
kavadistclient.ProposalHandler,
|
||||
committeeclient.ProposalHandler,
|
||||
earnclient.DepositProposalHandler,
|
||||
earnclient.WithdrawProposalHandler,
|
||||
communityclient.LendDepositProposalHandler,
|
||||
communityclient.LendWithdrawProposalHandler,
|
||||
}),
|
||||
params.AppModuleBasic{},
|
||||
crisis.AppModuleBasic{},
|
||||
@ -210,54 +150,27 @@ var (
|
||||
vesting.AppModuleBasic{},
|
||||
evm.AppModuleBasic{},
|
||||
feemarket.AppModuleBasic{},
|
||||
kavadist.AppModuleBasic{},
|
||||
auction.AppModuleBasic{},
|
||||
issuance.AppModuleBasic{},
|
||||
bep3.AppModuleBasic{},
|
||||
pricefeed.AppModuleBasic{},
|
||||
swap.AppModuleBasic{},
|
||||
cdp.AppModuleBasic{},
|
||||
hard.AppModuleBasic{},
|
||||
committee.AppModuleBasic{},
|
||||
incentive.AppModuleBasic{},
|
||||
savings.AppModuleBasic{},
|
||||
validatorvesting.AppModuleBasic{},
|
||||
evmutil.AppModuleBasic{},
|
||||
liquid.AppModuleBasic{},
|
||||
earn.AppModuleBasic{},
|
||||
router.AppModuleBasic{},
|
||||
mint.AppModuleBasic{},
|
||||
community.AppModuleBasic{},
|
||||
metrics.AppModuleBasic{},
|
||||
consensus.AppModuleBasic{},
|
||||
committee.AppModuleBasic{},
|
||||
das.AppModuleBasic{},
|
||||
)
|
||||
|
||||
// module account permissions
|
||||
// If these are changed, the permissions stored in accounts
|
||||
// must also be migrated during a chain upgrade.
|
||||
mAccPerms = map[string][]string{
|
||||
authtypes.FeeCollectorName: nil,
|
||||
distrtypes.ModuleName: nil,
|
||||
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
|
||||
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
|
||||
govtypes.ModuleName: {authtypes.Burner},
|
||||
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
|
||||
evmutiltypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||
kavadisttypes.KavaDistMacc: {authtypes.Minter},
|
||||
auctiontypes.ModuleName: nil,
|
||||
issuancetypes.ModuleAccountName: {authtypes.Minter, authtypes.Burner},
|
||||
bep3types.ModuleName: {authtypes.Burner, authtypes.Minter},
|
||||
swaptypes.ModuleName: nil,
|
||||
cdptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||
cdptypes.LiquidatorMacc: {authtypes.Minter, authtypes.Burner},
|
||||
hardtypes.ModuleAccountName: {authtypes.Minter},
|
||||
savingstypes.ModuleAccountName: nil,
|
||||
liquidtypes.ModuleAccountName: {authtypes.Minter, authtypes.Burner},
|
||||
earntypes.ModuleAccountName: nil,
|
||||
kavadisttypes.FundModuleAccount: nil,
|
||||
minttypes.ModuleName: {authtypes.Minter},
|
||||
communitytypes.ModuleName: nil,
|
||||
authtypes.FeeCollectorName: nil,
|
||||
distrtypes.ModuleName: nil,
|
||||
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
|
||||
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
|
||||
govtypes.ModuleName: {authtypes.Burner},
|
||||
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
|
||||
evmutiltypes.ModuleName: {authtypes.Minter, authtypes.Burner},
|
||||
minttypes.ModuleName: {authtypes.Minter},
|
||||
}
|
||||
)
|
||||
|
||||
@ -276,7 +189,6 @@ type Options struct {
|
||||
MempoolAuthAddresses []sdk.AccAddress
|
||||
EVMTrace string
|
||||
EVMMaxGasWanted uint64
|
||||
TelemetryOptions metricstypes.TelemetryOptions
|
||||
}
|
||||
|
||||
// DefaultOptions is a sensible default Options value.
|
||||
@ -285,7 +197,7 @@ var DefaultOptions = Options{
|
||||
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
||||
}
|
||||
|
||||
// App is the Kava ABCI application.
|
||||
// App is the 0gChain ABCI application.
|
||||
type App struct {
|
||||
*baseapp.BaseApp
|
||||
|
||||
@ -318,23 +230,10 @@ type App struct {
|
||||
upgradeKeeper upgradekeeper.Keeper
|
||||
evidenceKeeper evidencekeeper.Keeper
|
||||
transferKeeper ibctransferkeeper.Keeper
|
||||
kavadistKeeper kavadistkeeper.Keeper
|
||||
auctionKeeper auctionkeeper.Keeper
|
||||
issuanceKeeper issuancekeeper.Keeper
|
||||
bep3Keeper bep3keeper.Keeper
|
||||
pricefeedKeeper pricefeedkeeper.Keeper
|
||||
swapKeeper swapkeeper.Keeper
|
||||
cdpKeeper cdpkeeper.Keeper
|
||||
hardKeeper hardkeeper.Keeper
|
||||
committeeKeeper committeekeeper.Keeper
|
||||
incentiveKeeper incentivekeeper.Keeper
|
||||
savingsKeeper savingskeeper.Keeper
|
||||
liquidKeeper liquidkeeper.Keeper
|
||||
earnKeeper earnkeeper.Keeper
|
||||
routerKeeper routerkeeper.Keeper
|
||||
mintKeeper mintkeeper.Keeper
|
||||
communityKeeper communitykeeper.Keeper
|
||||
consensusParamsKeeper consensusparamkeeper.Keeper
|
||||
CommitteeKeeper committeekeeper.Keeper
|
||||
DasKeeper daskeeper.Keeper
|
||||
|
||||
// make scoped keepers public for test purposes
|
||||
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
|
||||
@ -350,22 +249,13 @@ type App struct {
|
||||
configurator module.Configurator
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
stdlog.Printf("Failed to get home dir %v", err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".kava")
|
||||
}
|
||||
|
||||
// NewApp returns a reference to an initialized App.
|
||||
func NewApp(
|
||||
logger tmlog.Logger,
|
||||
db dbm.DB,
|
||||
homePath string,
|
||||
traceStore io.Writer,
|
||||
encodingConfig kavaparams.EncodingConfig,
|
||||
encodingConfig chainparams.EncodingConfig,
|
||||
options Options,
|
||||
baseAppOptions ...func(*baseapp.BaseApp),
|
||||
) *App {
|
||||
@ -373,23 +263,34 @@ func NewApp(
|
||||
legacyAmino := encodingConfig.Amino
|
||||
interfaceRegistry := encodingConfig.InterfaceRegistry
|
||||
|
||||
bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp := baseapp.NewBaseApp(chaincfg.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp.SetCommitMultiStoreTracer(traceStore)
|
||||
bApp.SetVersion(version.Version)
|
||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||
|
||||
keys := sdk.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
|
||||
distrtypes.StoreKey, slashingtypes.StoreKey, packetforwardtypes.StoreKey,
|
||||
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey,
|
||||
upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey,
|
||||
evmtypes.StoreKey, feemarkettypes.StoreKey, authzkeeper.StoreKey,
|
||||
capabilitytypes.StoreKey, kavadisttypes.StoreKey, auctiontypes.StoreKey,
|
||||
issuancetypes.StoreKey, bep3types.StoreKey, pricefeedtypes.StoreKey,
|
||||
swaptypes.StoreKey, cdptypes.StoreKey, hardtypes.StoreKey, communitytypes.StoreKey,
|
||||
committeetypes.StoreKey, incentivetypes.StoreKey, evmutiltypes.StoreKey,
|
||||
savingstypes.StoreKey, earntypes.StoreKey, minttypes.StoreKey,
|
||||
consensusparamtypes.StoreKey, crisistypes.StoreKey,
|
||||
authtypes.StoreKey,
|
||||
banktypes.StoreKey,
|
||||
stakingtypes.StoreKey,
|
||||
distrtypes.StoreKey,
|
||||
slashingtypes.StoreKey,
|
||||
packetforwardtypes.StoreKey,
|
||||
govtypes.StoreKey,
|
||||
paramstypes.StoreKey,
|
||||
ibcexported.StoreKey,
|
||||
upgradetypes.StoreKey,
|
||||
evidencetypes.StoreKey,
|
||||
ibctransfertypes.StoreKey,
|
||||
evmtypes.StoreKey,
|
||||
feemarkettypes.StoreKey,
|
||||
authzkeeper.StoreKey,
|
||||
capabilitytypes.StoreKey,
|
||||
evmutiltypes.StoreKey,
|
||||
minttypes.StoreKey,
|
||||
consensusparamtypes.StoreKey,
|
||||
crisistypes.StoreKey,
|
||||
committeetypes.StoreKey,
|
||||
dastypes.StoreKey,
|
||||
)
|
||||
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
|
||||
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
|
||||
@ -422,23 +323,12 @@ func NewApp(
|
||||
slashingSubspace := app.paramsKeeper.Subspace(slashingtypes.ModuleName)
|
||||
govSubspace := app.paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
|
||||
crisisSubspace := app.paramsKeeper.Subspace(crisistypes.ModuleName)
|
||||
kavadistSubspace := app.paramsKeeper.Subspace(kavadisttypes.ModuleName)
|
||||
auctionSubspace := app.paramsKeeper.Subspace(auctiontypes.ModuleName)
|
||||
issuanceSubspace := app.paramsKeeper.Subspace(issuancetypes.ModuleName)
|
||||
bep3Subspace := app.paramsKeeper.Subspace(bep3types.ModuleName)
|
||||
pricefeedSubspace := app.paramsKeeper.Subspace(pricefeedtypes.ModuleName)
|
||||
swapSubspace := app.paramsKeeper.Subspace(swaptypes.ModuleName)
|
||||
cdpSubspace := app.paramsKeeper.Subspace(cdptypes.ModuleName)
|
||||
hardSubspace := app.paramsKeeper.Subspace(hardtypes.ModuleName)
|
||||
incentiveSubspace := app.paramsKeeper.Subspace(incentivetypes.ModuleName)
|
||||
savingsSubspace := app.paramsKeeper.Subspace(savingstypes.ModuleName)
|
||||
ibcSubspace := app.paramsKeeper.Subspace(ibcexported.ModuleName)
|
||||
ibctransferSubspace := app.paramsKeeper.Subspace(ibctransfertypes.ModuleName)
|
||||
packetforwardSubspace := app.paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
|
||||
feemarketSubspace := app.paramsKeeper.Subspace(feemarkettypes.ModuleName)
|
||||
evmSubspace := app.paramsKeeper.Subspace(evmtypes.ModuleName)
|
||||
evmutilSubspace := app.paramsKeeper.Subspace(evmutiltypes.ModuleName)
|
||||
earnSubspace := app.paramsKeeper.Subspace(earntypes.ModuleName)
|
||||
mintSubspace := app.paramsKeeper.Subspace(minttypes.ModuleName)
|
||||
|
||||
// set the BaseApp's parameter store
|
||||
@ -602,96 +492,6 @@ func NewApp(
|
||||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
|
||||
app.ibcKeeper.SetRouter(ibcRouter)
|
||||
|
||||
app.auctionKeeper = auctionkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[auctiontypes.StoreKey],
|
||||
auctionSubspace,
|
||||
app.bankKeeper,
|
||||
app.accountKeeper,
|
||||
)
|
||||
app.issuanceKeeper = issuancekeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[issuancetypes.StoreKey],
|
||||
issuanceSubspace,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
)
|
||||
app.bep3Keeper = bep3keeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[bep3types.StoreKey],
|
||||
app.bankKeeper,
|
||||
app.accountKeeper,
|
||||
bep3Subspace,
|
||||
app.ModuleAccountAddrs(),
|
||||
)
|
||||
app.pricefeedKeeper = pricefeedkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[pricefeedtypes.StoreKey],
|
||||
pricefeedSubspace,
|
||||
)
|
||||
swapKeeper := swapkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[swaptypes.StoreKey],
|
||||
swapSubspace,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
)
|
||||
cdpKeeper := cdpkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[cdptypes.StoreKey],
|
||||
cdpSubspace,
|
||||
app.pricefeedKeeper,
|
||||
app.auctionKeeper,
|
||||
app.bankKeeper,
|
||||
app.accountKeeper,
|
||||
mAccPerms,
|
||||
)
|
||||
hardKeeper := hardkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[hardtypes.StoreKey],
|
||||
hardSubspace,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
app.pricefeedKeeper,
|
||||
app.auctionKeeper,
|
||||
)
|
||||
app.liquidKeeper = liquidkeeper.NewDefaultKeeper(
|
||||
appCodec,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
app.stakingKeeper,
|
||||
&app.distrKeeper,
|
||||
)
|
||||
savingsKeeper := savingskeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[savingstypes.StoreKey],
|
||||
savingsSubspace,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
app.liquidKeeper,
|
||||
)
|
||||
earnKeeper := earnkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[earntypes.StoreKey],
|
||||
earnSubspace,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
&app.liquidKeeper,
|
||||
&hardKeeper,
|
||||
&savingsKeeper,
|
||||
&app.distrKeeper,
|
||||
)
|
||||
|
||||
app.kavadistKeeper = kavadistkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[kavadisttypes.StoreKey],
|
||||
kavadistSubspace,
|
||||
app.bankKeeper,
|
||||
app.accountKeeper,
|
||||
app.distrKeeper,
|
||||
app.loadBlockedMaccAddrs(),
|
||||
)
|
||||
|
||||
app.mintKeeper = mintkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[minttypes.StoreKey],
|
||||
@ -702,76 +502,13 @@ func NewApp(
|
||||
govAuthAddrStr,
|
||||
)
|
||||
|
||||
// x/community's deposit/withdraw to lend proposals depend on hard keeper.
|
||||
app.communityKeeper = communitykeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[communitytypes.StoreKey],
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
&cdpKeeper,
|
||||
app.distrKeeper,
|
||||
&hardKeeper,
|
||||
&app.mintKeeper,
|
||||
&app.kavadistKeeper,
|
||||
app.stakingKeeper,
|
||||
govAuthAddr,
|
||||
)
|
||||
|
||||
app.incentiveKeeper = incentivekeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[incentivetypes.StoreKey],
|
||||
incentiveSubspace,
|
||||
app.bankKeeper,
|
||||
&cdpKeeper,
|
||||
&hardKeeper,
|
||||
app.accountKeeper,
|
||||
app.stakingKeeper,
|
||||
&swapKeeper,
|
||||
&savingsKeeper,
|
||||
&app.liquidKeeper,
|
||||
&earnKeeper,
|
||||
app.mintKeeper,
|
||||
app.distrKeeper,
|
||||
app.pricefeedKeeper,
|
||||
)
|
||||
app.routerKeeper = routerkeeper.NewKeeper(
|
||||
&app.earnKeeper,
|
||||
app.liquidKeeper,
|
||||
app.stakingKeeper,
|
||||
)
|
||||
|
||||
// create committee keeper with router
|
||||
committeeGovRouter := govv1beta1.NewRouter()
|
||||
committeeGovRouter.
|
||||
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
|
||||
AddRoute(communitytypes.RouterKey, community.NewCommunityPoolProposalHandler(app.communityKeeper)).
|
||||
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
|
||||
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.upgradeKeeper))
|
||||
// Note: the committee proposal handler is not registered on the committee router. This means committees cannot create or update other committees.
|
||||
// Adding the committee proposal handler to the router is possible but awkward as the handler depends on the keeper which depends on the handler.
|
||||
app.committeeKeeper = committeekeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[committeetypes.StoreKey],
|
||||
committeeGovRouter,
|
||||
app.paramsKeeper,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
)
|
||||
|
||||
// register the staking hooks
|
||||
app.stakingKeeper.SetHooks(
|
||||
stakingtypes.NewMultiStakingHooks(
|
||||
app.distrKeeper.Hooks(),
|
||||
app.slashingKeeper.Hooks(),
|
||||
app.incentiveKeeper.Hooks(),
|
||||
))
|
||||
|
||||
app.swapKeeper = *swapKeeper.SetHooks(app.incentiveKeeper.Hooks())
|
||||
app.cdpKeeper = *cdpKeeper.SetHooks(cdptypes.NewMultiCDPHooks(app.incentiveKeeper.Hooks()))
|
||||
app.hardKeeper = *hardKeeper.SetHooks(hardtypes.NewMultiHARDHooks(app.incentiveKeeper.Hooks()))
|
||||
app.savingsKeeper = savingsKeeper // savings incentive hooks disabled
|
||||
app.earnKeeper = *earnKeeper.SetHooks(app.incentiveKeeper.Hooks())
|
||||
|
||||
// create gov keeper with router
|
||||
// NOTE this must be done after any keepers referenced in the gov router (ie committee) are defined
|
||||
govRouter := govv1beta1.NewRouter()
|
||||
@ -779,11 +516,7 @@ func NewApp(
|
||||
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
|
||||
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
|
||||
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.upgradeKeeper)).
|
||||
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper)).
|
||||
AddRoute(kavadisttypes.RouterKey, kavadist.NewCommunityPoolMultiSpendProposalHandler(app.kavadistKeeper)).
|
||||
AddRoute(earntypes.RouterKey, earn.NewCommunityPoolProposalHandler(app.earnKeeper)).
|
||||
AddRoute(communitytypes.RouterKey, community.NewCommunityPoolProposalHandler(app.communityKeeper)).
|
||||
AddRoute(committeetypes.RouterKey, committee.NewProposalHandler(app.committeeKeeper))
|
||||
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper))
|
||||
|
||||
govConfig := govtypes.DefaultConfig()
|
||||
govKeeper := govkeeper.NewKeeper(
|
||||
@ -799,12 +532,10 @@ func NewApp(
|
||||
govKeeper.SetLegacyRouter(govRouter)
|
||||
app.govKeeper = *govKeeper
|
||||
|
||||
// override x/gov tally handler with custom implementation
|
||||
tallyHandler := NewTallyHandler(
|
||||
app.govKeeper, *app.stakingKeeper, app.savingsKeeper, app.earnKeeper,
|
||||
app.liquidKeeper, app.bankKeeper,
|
||||
app.CommitteeKeeper = committeekeeper.NewKeeper(
|
||||
keys[committeetypes.StoreKey], appCodec, app.stakingKeeper,
|
||||
)
|
||||
app.govKeeper.SetTallyHandler(tallyHandler)
|
||||
app.DasKeeper = daskeeper.NewKeeper(keys[dastypes.StoreKey], appCodec, app.stakingKeeper)
|
||||
|
||||
// create the module manager (Note: Any module instantiated in the module manager that is later modified
|
||||
// must be passed by reference here.)
|
||||
@ -829,41 +560,17 @@ func NewApp(
|
||||
transferModule,
|
||||
vesting.NewAppModule(app.accountKeeper, app.bankKeeper),
|
||||
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry),
|
||||
kavadist.NewAppModule(app.kavadistKeeper, app.accountKeeper),
|
||||
auction.NewAppModule(app.auctionKeeper, app.accountKeeper, app.bankKeeper),
|
||||
issuance.NewAppModule(app.issuanceKeeper, app.accountKeeper, app.bankKeeper),
|
||||
bep3.NewAppModule(app.bep3Keeper, app.accountKeeper, app.bankKeeper),
|
||||
pricefeed.NewAppModule(app.pricefeedKeeper, app.accountKeeper),
|
||||
validatorvesting.NewAppModule(app.bankKeeper),
|
||||
swap.NewAppModule(app.swapKeeper, app.accountKeeper),
|
||||
cdp.NewAppModule(app.cdpKeeper, app.accountKeeper, app.pricefeedKeeper, app.bankKeeper),
|
||||
hard.NewAppModule(app.hardKeeper, app.accountKeeper, app.bankKeeper, app.pricefeedKeeper),
|
||||
committee.NewAppModule(app.committeeKeeper, app.accountKeeper),
|
||||
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.bankKeeper, app.cdpKeeper),
|
||||
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper, app.accountKeeper),
|
||||
savings.NewAppModule(app.savingsKeeper, app.accountKeeper, app.bankKeeper),
|
||||
liquid.NewAppModule(app.liquidKeeper),
|
||||
earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper),
|
||||
router.NewAppModule(app.routerKeeper),
|
||||
// nil InflationCalculationFn, use SDK's default inflation function
|
||||
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil, mintSubspace),
|
||||
community.NewAppModule(app.communityKeeper, app.accountKeeper),
|
||||
metrics.NewAppModule(options.TelemetryOptions),
|
||||
)
|
||||
|
||||
// Warning: Some begin blockers must run before others. Ensure the dependencies are understood before modifying this list.
|
||||
app.mm.SetOrderBeginBlockers(
|
||||
metricstypes.ModuleName,
|
||||
// Upgrade begin blocker runs migrations on the first block after an upgrade. It should run before any other module.
|
||||
upgradetypes.ModuleName,
|
||||
// Capability begin blocker runs non state changing initialization.
|
||||
capabilitytypes.ModuleName,
|
||||
// Committee begin blocker changes module params by enacting proposals.
|
||||
// Run before to ensure params are updated together before state changes.
|
||||
committeetypes.ModuleName,
|
||||
// Community begin blocker should run before x/mint and x/kavadist since
|
||||
// the disable inflation upgrade will update those modules' params.
|
||||
communitytypes.ModuleName,
|
||||
minttypes.ModuleName,
|
||||
distrtypes.ModuleName,
|
||||
// During begin block slashing happens after distr.BeginBlocker so that
|
||||
@ -874,20 +581,9 @@ func NewApp(
|
||||
stakingtypes.ModuleName,
|
||||
feemarkettypes.ModuleName,
|
||||
evmtypes.ModuleName,
|
||||
kavadisttypes.ModuleName,
|
||||
// Auction begin blocker will close out expired auctions and pay debt back to cdp.
|
||||
// It should be run before cdp begin blocker which cancels out debt with stable and starts more auctions.
|
||||
auctiontypes.ModuleName,
|
||||
cdptypes.ModuleName,
|
||||
bep3types.ModuleName,
|
||||
hardtypes.ModuleName,
|
||||
issuancetypes.ModuleName,
|
||||
incentivetypes.ModuleName,
|
||||
ibcexported.ModuleName,
|
||||
// Add all remaining modules with an empty begin blocker below since cosmos 0.45.0 requires it
|
||||
swaptypes.ModuleName,
|
||||
vestingtypes.ModuleName,
|
||||
pricefeedtypes.ModuleName,
|
||||
validatorvestingtypes.ModuleName,
|
||||
authtypes.ModuleName,
|
||||
banktypes.ModuleName,
|
||||
@ -898,12 +594,11 @@ func NewApp(
|
||||
paramstypes.ModuleName,
|
||||
authz.ModuleName,
|
||||
evmutiltypes.ModuleName,
|
||||
savingstypes.ModuleName,
|
||||
liquidtypes.ModuleName,
|
||||
earntypes.ModuleName,
|
||||
routertypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
|
||||
committeetypes.ModuleName,
|
||||
dastypes.ModuleName,
|
||||
)
|
||||
|
||||
// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
|
||||
@ -914,22 +609,12 @@ func NewApp(
|
||||
evmtypes.ModuleName,
|
||||
// fee market module must go after evm module in order to retrieve the block gas used.
|
||||
feemarkettypes.ModuleName,
|
||||
pricefeedtypes.ModuleName,
|
||||
// Add all remaining modules with an empty end blocker below since cosmos 0.45.0 requires it
|
||||
capabilitytypes.ModuleName,
|
||||
incentivetypes.ModuleName,
|
||||
issuancetypes.ModuleName,
|
||||
slashingtypes.ModuleName,
|
||||
distrtypes.ModuleName,
|
||||
auctiontypes.ModuleName,
|
||||
bep3types.ModuleName,
|
||||
cdptypes.ModuleName,
|
||||
hardtypes.ModuleName,
|
||||
committeetypes.ModuleName,
|
||||
upgradetypes.ModuleName,
|
||||
evidencetypes.ModuleName,
|
||||
kavadisttypes.ModuleName,
|
||||
swaptypes.ModuleName,
|
||||
vestingtypes.ModuleName,
|
||||
ibcexported.ModuleName,
|
||||
validatorvestingtypes.ModuleName,
|
||||
@ -940,15 +625,11 @@ func NewApp(
|
||||
paramstypes.ModuleName,
|
||||
authz.ModuleName,
|
||||
evmutiltypes.ModuleName,
|
||||
savingstypes.ModuleName,
|
||||
liquidtypes.ModuleName,
|
||||
earntypes.ModuleName,
|
||||
routertypes.ModuleName,
|
||||
minttypes.ModuleName,
|
||||
communitytypes.ModuleName,
|
||||
metricstypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
committeetypes.ModuleName,
|
||||
dastypes.ModuleName,
|
||||
)
|
||||
|
||||
// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
|
||||
@ -967,32 +648,18 @@ func NewApp(
|
||||
ibctransfertypes.ModuleName,
|
||||
evmtypes.ModuleName,
|
||||
feemarkettypes.ModuleName,
|
||||
kavadisttypes.ModuleName,
|
||||
auctiontypes.ModuleName,
|
||||
issuancetypes.ModuleName,
|
||||
savingstypes.ModuleName,
|
||||
bep3types.ModuleName,
|
||||
pricefeedtypes.ModuleName,
|
||||
swaptypes.ModuleName,
|
||||
cdptypes.ModuleName, // reads market prices, so must run after pricefeed genesis
|
||||
hardtypes.ModuleName,
|
||||
incentivetypes.ModuleName, // reads cdp params, so must run after cdp genesis
|
||||
committeetypes.ModuleName,
|
||||
evmutiltypes.ModuleName,
|
||||
earntypes.ModuleName,
|
||||
communitytypes.ModuleName,
|
||||
genutiltypes.ModuleName, // runs arbitrary txs included in genisis state, so run after modules have been initialized
|
||||
// Add all remaining modules with an empty InitGenesis below since cosmos 0.45.0 requires it
|
||||
vestingtypes.ModuleName,
|
||||
paramstypes.ModuleName,
|
||||
upgradetypes.ModuleName,
|
||||
validatorvestingtypes.ModuleName,
|
||||
liquidtypes.ModuleName,
|
||||
routertypes.ModuleName,
|
||||
metricstypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
|
||||
committeetypes.ModuleName,
|
||||
dastypes.ModuleName,
|
||||
)
|
||||
|
||||
app.mm.RegisterInvariants(&app.crisisKeeper)
|
||||
@ -1031,8 +698,6 @@ func NewApp(
|
||||
if options.MempoolEnableAuth {
|
||||
fetchers = append(fetchers,
|
||||
func(sdk.Context) []sdk.AccAddress { return options.MempoolAuthAddresses },
|
||||
app.bep3Keeper.GetAuthorizedAddresses,
|
||||
app.pricefeedKeeper.GetAuthorizedAddresses,
|
||||
)
|
||||
}
|
||||
|
||||
@ -1094,7 +759,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Store current module versions in kava-10 to setup future in-place upgrades.
|
||||
// Store current module versions in 0gChain-10 to setup future in-place upgrades.
|
||||
// During in-place migrations, the old module versions in the store will be referenced to determine which migrations to run.
|
||||
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
||||
|
||||
@ -1133,9 +798,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
|
||||
// Register custom REST routes
|
||||
validatorvestingrest.RegisterRoutes(clientCtx, apiSvr.Router)
|
||||
|
||||
// Register rewrite routes
|
||||
RegisterAPIRouteRewrites(apiSvr.Router)
|
||||
|
||||
// Register GRPC Gateway routes
|
||||
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
||||
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
||||
@ -1145,33 +807,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
|
||||
// Swagger API configuration is ignored
|
||||
}
|
||||
|
||||
// RegisterAPIRouteRewrites registers overwritten API routes that are
|
||||
// registered after this function is called. This must be called before any
|
||||
// other route registrations on the router in order for rewrites to take effect.
|
||||
// The first route that matches in the mux router wins, so any registrations
|
||||
// here will be prioritized over the later registrations in modules.
|
||||
func RegisterAPIRouteRewrites(router *mux.Router) {
|
||||
// Mapping of client path to backend path. Similar to nginx rewrite rules,
|
||||
// but does not return a 301 or 302 redirect.
|
||||
// Eg: querying /cosmos/distribution/v1beta1/community_pool will return
|
||||
// the same response as querying /kava/community/v1beta1/total_balance
|
||||
routeMap := map[string]string{
|
||||
"/cosmos/distribution/v1beta1/community_pool": "/kava/community/v1beta1/total_balance",
|
||||
}
|
||||
|
||||
for clientPath, backendPath := range routeMap {
|
||||
router.HandleFunc(
|
||||
clientPath,
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
r.URL.Path = backendPath
|
||||
|
||||
// Use handler of the new path
|
||||
router.ServeHTTP(w, r)
|
||||
},
|
||||
).Methods("GET")
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterTxService implements the Application.RegisterTxService method.
|
||||
// It registers transaction related endpoints on the app's grpc server.
|
||||
func (app *App) RegisterTxService(clientCtx client.Context) {
|
||||
@ -1196,19 +831,7 @@ func (app *App) RegisterNodeService(clientCtx client.Context) {
|
||||
// loadBlockedMaccAddrs returns a map indicating the blocked status of each module account address
|
||||
func (app *App) loadBlockedMaccAddrs() map[string]bool {
|
||||
modAccAddrs := app.ModuleAccountAddrs()
|
||||
allowedMaccs := map[string]bool{
|
||||
// kavadist
|
||||
app.accountKeeper.GetModuleAddress(kavadisttypes.ModuleName).String(): true,
|
||||
// earn
|
||||
app.accountKeeper.GetModuleAddress(earntypes.ModuleName).String(): true,
|
||||
// liquid
|
||||
app.accountKeeper.GetModuleAddress(liquidtypes.ModuleName).String(): true,
|
||||
// kavadist fund
|
||||
app.accountKeeper.GetModuleAddress(kavadisttypes.FundModuleAccount).String(): true,
|
||||
// community
|
||||
app.accountKeeper.GetModuleAddress(communitytypes.ModuleAccountName).String(): true,
|
||||
// NOTE: if adding evmutil, adjust the cosmos-coins-fully-backed-invariant accordingly.
|
||||
}
|
||||
allowedMaccs := map[string]bool{}
|
||||
|
||||
for addr := range modAccAddrs {
|
||||
// Set allowed module accounts as unblocked
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
db "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
@ -25,11 +26,11 @@ import (
|
||||
)
|
||||
|
||||
func TestNewApp(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
NewApp(
|
||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||
db.NewMemDB(),
|
||||
DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
MakeEncodingConfig(),
|
||||
DefaultOptions,
|
||||
@ -37,9 +38,9 @@ func TestNewApp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExport(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
db := db.NewMemDB()
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, chaincfg.DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
|
||||
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
package app
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
const (
|
||||
// Bech32MainPrefix defines the Bech32 prefix for account addresses
|
||||
Bech32MainPrefix = "kava"
|
||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||
Bech32PrefixAccPub = Bech32MainPrefix + "pub"
|
||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||
Bech32PrefixValAddr = Bech32MainPrefix + "val" + "oper"
|
||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||
Bech32PrefixValPub = Bech32MainPrefix + "val" + "oper" + "pub"
|
||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||
Bech32PrefixConsAddr = Bech32MainPrefix + "val" + "cons"
|
||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||
Bech32PrefixConsPub = Bech32MainPrefix + "val" + "cons" + "pub"
|
||||
|
||||
Bip44CoinType = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||
)
|
||||
|
||||
// SetSDKConfig configures the global config with kava app specific parameters.
|
||||
// It does not seal the config to allow modification in tests.
|
||||
func SetSDKConfig() *sdk.Config {
|
||||
config := sdk.GetConfig()
|
||||
SetBech32AddressPrefixes(config)
|
||||
SetBip44CoinType(config)
|
||||
return config
|
||||
}
|
||||
|
||||
// SetBech32AddressPrefixes sets the global prefix to be used when serializing addresses to bech32 strings.
|
||||
func SetBech32AddressPrefixes(config *sdk.Config) {
|
||||
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||
}
|
||||
|
||||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||
func SetBip44CoinType(config *sdk.Config) {
|
||||
config.SetCoinType(Bip44CoinType)
|
||||
}
|
@ -3,7 +3,7 @@ package app
|
||||
import (
|
||||
enccodec "github.com/evmos/ethermint/encoding/codec"
|
||||
|
||||
"github.com/kava-labs/kava/app/params"
|
||||
"github.com/0glabs/0g-chain/app/params"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates an EncodingConfig and registers the app's types on it.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Package params defines the simulation parameters for the Kava app.
|
||||
Package params defines the simulation parameters for the 0gChain app.
|
||||
|
||||
It contains the default weights used for each transaction used on the module's
|
||||
simulation. These weights define the chance for a transaction to be simulated at
|
||||
|
@ -1,256 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
earnkeeper "github.com/kava-labs/kava/x/earn/keeper"
|
||||
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
|
||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
||||
savingskeeper "github.com/kava-labs/kava/x/savings/keeper"
|
||||
)
|
||||
|
||||
var _ govv1.TallyHandler = TallyHandler{}
|
||||
|
||||
// TallyHandler is the tally handler for kava
|
||||
type TallyHandler struct {
|
||||
gk govkeeper.Keeper
|
||||
stk stakingkeeper.Keeper
|
||||
svk savingskeeper.Keeper
|
||||
ek earnkeeper.Keeper
|
||||
lk liquidkeeper.Keeper
|
||||
bk bankkeeper.Keeper
|
||||
}
|
||||
|
||||
// NewTallyHandler creates a new tally handler.
|
||||
func NewTallyHandler(
|
||||
gk govkeeper.Keeper, stk stakingkeeper.Keeper, svk savingskeeper.Keeper,
|
||||
ek earnkeeper.Keeper, lk liquidkeeper.Keeper, bk bankkeeper.Keeper,
|
||||
) TallyHandler {
|
||||
return TallyHandler{
|
||||
gk: gk,
|
||||
stk: stk,
|
||||
svk: svk,
|
||||
ek: ek,
|
||||
lk: lk,
|
||||
bk: bk,
|
||||
}
|
||||
}
|
||||
|
||||
func (th TallyHandler) Tally(
|
||||
ctx sdk.Context,
|
||||
proposal govv1.Proposal,
|
||||
) (passes bool, burnDeposits bool, tallyResults govv1.TallyResult) {
|
||||
results := make(map[govv1.VoteOption]sdk.Dec)
|
||||
results[govv1.OptionYes] = sdk.ZeroDec()
|
||||
results[govv1.OptionAbstain] = sdk.ZeroDec()
|
||||
results[govv1.OptionNo] = sdk.ZeroDec()
|
||||
results[govv1.OptionNoWithVeto] = sdk.ZeroDec()
|
||||
|
||||
totalVotingPower := sdk.ZeroDec()
|
||||
currValidators := make(map[string]govv1.ValidatorGovInfo)
|
||||
|
||||
// fetch all the bonded validators, insert them into currValidators
|
||||
th.stk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
|
||||
currValidators[validator.GetOperator().String()] = govv1.NewValidatorGovInfo(
|
||||
validator.GetOperator(),
|
||||
validator.GetBondedTokens(),
|
||||
validator.GetDelegatorShares(),
|
||||
sdk.ZeroDec(),
|
||||
govv1.WeightedVoteOptions{},
|
||||
)
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
th.gk.IterateVotes(ctx, proposal.Id, func(vote govv1.Vote) bool {
|
||||
// if validator, just record it in the map
|
||||
voter, err := sdk.AccAddressFromBech32(vote.Voter)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
valAddrStr := sdk.ValAddress(voter.Bytes()).String()
|
||||
if val, ok := currValidators[valAddrStr]; ok {
|
||||
val.Vote = vote.Options
|
||||
currValidators[valAddrStr] = val
|
||||
}
|
||||
|
||||
// iterate over all delegations from voter, deduct from any delegated-to validators
|
||||
th.stk.IterateDelegations(ctx, voter, func(index int64, delegation stakingtypes.DelegationI) (stop bool) {
|
||||
valAddrStr := delegation.GetValidatorAddr().String()
|
||||
|
||||
if val, ok := currValidators[valAddrStr]; ok {
|
||||
// There is no need to handle the special case that validator address equal to voter address.
|
||||
// Because voter's voting power will tally again even if there will deduct voter's voting power from validator.
|
||||
val.DelegatorDeductions = val.DelegatorDeductions.Add(delegation.GetShares())
|
||||
currValidators[valAddrStr] = val
|
||||
|
||||
// delegation shares * bonded / total shares
|
||||
votingPower := delegation.GetShares().MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
||||
|
||||
for _, option := range vote.Options {
|
||||
subPower := votingPower.Mul(sdk.MustNewDecFromStr(option.Weight))
|
||||
results[option.Option] = results[option.Option].Add(subPower)
|
||||
}
|
||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
// get voter bkava and update total voting power and results
|
||||
addrBkava := th.getAddrBkava(ctx, voter).toCoins()
|
||||
for _, coin := range addrBkava {
|
||||
valAddr, err := liquidtypes.ParseLiquidStakingTokenDenom(coin.Denom)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// reduce delegator shares by the amount of voter bkava for the validator
|
||||
valAddrStr := valAddr.String()
|
||||
if val, ok := currValidators[valAddrStr]; ok {
|
||||
val.DelegatorDeductions = val.DelegatorDeductions.Add(sdk.NewDecFromInt(coin.Amount))
|
||||
currValidators[valAddrStr] = val
|
||||
}
|
||||
|
||||
// votingPower = amount of ukava coin
|
||||
stakedCoins, err := th.lk.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(coin))
|
||||
if err != nil {
|
||||
// error is returned only if the bkava denom is incorrect, which should never happen here.
|
||||
panic(err)
|
||||
}
|
||||
votingPower := sdk.NewDecFromInt(stakedCoins.Amount)
|
||||
|
||||
for _, option := range vote.Options {
|
||||
subPower := votingPower.Mul(sdk.MustNewDecFromStr(option.Weight))
|
||||
results[option.Option] = results[option.Option].Add(subPower)
|
||||
}
|
||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||
}
|
||||
|
||||
th.gk.DeleteVote(ctx, vote.ProposalId, voter)
|
||||
return false
|
||||
})
|
||||
|
||||
// iterate over the validators again to tally their voting power
|
||||
for _, val := range currValidators {
|
||||
if len(val.Vote) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
sharesAfterDeductions := val.DelegatorShares.Sub(val.DelegatorDeductions)
|
||||
votingPower := sharesAfterDeductions.MulInt(val.BondedTokens).Quo(val.DelegatorShares)
|
||||
|
||||
for _, option := range val.Vote {
|
||||
subPower := votingPower.Mul(sdk.MustNewDecFromStr(option.Weight))
|
||||
results[option.Option] = results[option.Option].Add(subPower)
|
||||
}
|
||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||
}
|
||||
|
||||
tallyParams := th.gk.GetParams(ctx)
|
||||
tallyResults = govv1.NewTallyResultFromMap(results)
|
||||
|
||||
// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
|
||||
// If there is no staked coins, the proposal fails
|
||||
if th.stk.TotalBondedTokens(ctx).IsZero() {
|
||||
return false, false, tallyResults
|
||||
}
|
||||
|
||||
// If there is not enough quorum of votes, the proposal fails
|
||||
percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(th.stk.TotalBondedTokens(ctx)))
|
||||
if percentVoting.LT(sdk.MustNewDecFromStr(tallyParams.Quorum)) {
|
||||
return false, tallyParams.BurnVoteQuorum, tallyResults
|
||||
}
|
||||
|
||||
// If no one votes (everyone abstains), proposal fails
|
||||
if totalVotingPower.Sub(results[govv1.OptionAbstain]).Equal(sdk.ZeroDec()) {
|
||||
return false, false, tallyResults
|
||||
}
|
||||
|
||||
// If more than 1/3 of voters veto, proposal fails
|
||||
if results[govv1.OptionNoWithVeto].Quo(totalVotingPower).GT(sdk.MustNewDecFromStr(tallyParams.VetoThreshold)) {
|
||||
return false, tallyParams.BurnVoteVeto, tallyResults
|
||||
}
|
||||
|
||||
// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
|
||||
if results[govv1.OptionYes].Quo(totalVotingPower.Sub(results[govv1.OptionAbstain])).GT(sdk.MustNewDecFromStr(tallyParams.Threshold)) {
|
||||
return true, false, tallyResults
|
||||
}
|
||||
|
||||
// If more than 1/2 of non-abstaining voters vote No, proposal fails
|
||||
return false, false, tallyResults
|
||||
}
|
||||
|
||||
// bkavaByDenom a map of the bkava denom and the amount of bkava for that denom.
|
||||
type bkavaByDenom map[string]sdkmath.Int
|
||||
|
||||
func (bkavaMap bkavaByDenom) add(coin sdk.Coin) {
|
||||
_, found := bkavaMap[coin.Denom]
|
||||
if !found {
|
||||
bkavaMap[coin.Denom] = sdk.ZeroInt()
|
||||
}
|
||||
bkavaMap[coin.Denom] = bkavaMap[coin.Denom].Add(coin.Amount)
|
||||
}
|
||||
|
||||
func (bkavaMap bkavaByDenom) toCoins() sdk.Coins {
|
||||
coins := sdk.Coins{}
|
||||
for denom, amt := range bkavaMap {
|
||||
coins = coins.Add(sdk.NewCoin(denom, amt))
|
||||
}
|
||||
return coins.Sort()
|
||||
}
|
||||
|
||||
// getAddrBkava returns a map of validator address & the amount of bkava
|
||||
// of the addr for each validator.
|
||||
func (th TallyHandler) getAddrBkava(ctx sdk.Context, addr sdk.AccAddress) bkavaByDenom {
|
||||
results := make(bkavaByDenom)
|
||||
th.addBkavaFromWallet(ctx, addr, results)
|
||||
th.addBkavaFromSavings(ctx, addr, results)
|
||||
th.addBkavaFromEarn(ctx, addr, results)
|
||||
return results
|
||||
}
|
||||
|
||||
// addBkavaFromWallet adds all addr balances of bkava in x/bank.
|
||||
func (th TallyHandler) addBkavaFromWallet(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||
coins := th.bk.GetAllBalances(ctx, addr)
|
||||
for _, coin := range coins {
|
||||
if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
||||
bkava.add(coin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// addBkavaFromSavings adds all addr deposits of bkava in x/savings.
|
||||
func (th TallyHandler) addBkavaFromSavings(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||
deposit, found := th.svk.GetDeposit(ctx, addr)
|
||||
if !found {
|
||||
return
|
||||
}
|
||||
for _, coin := range deposit.Amount {
|
||||
if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
||||
bkava.add(coin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// addBkavaFromEarn adds all addr deposits of bkava in x/earn.
|
||||
func (th TallyHandler) addBkavaFromEarn(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||
shares, found := th.ek.GetVaultAccountShares(ctx, addr)
|
||||
if !found {
|
||||
return
|
||||
}
|
||||
for _, share := range shares {
|
||||
if th.lk.IsDerivativeDenom(ctx, share.Denom) {
|
||||
if coin, err := th.ek.ConvertToAssets(ctx, share); err == nil {
|
||||
bkava.add(coin)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,415 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
earntypes "github.com/kava-labs/kava/x/earn/types"
|
||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
||||
)
|
||||
|
||||
// d is an alias for sdk.MustNewDecFromStr
|
||||
var d = sdk.MustNewDecFromStr
|
||||
|
||||
type tallyHandlerSuite struct {
|
||||
suite.Suite
|
||||
app TestApp
|
||||
ctx sdk.Context
|
||||
|
||||
staking stakingHelper
|
||||
|
||||
tallier TallyHandler
|
||||
}
|
||||
|
||||
func TestTallyHandlerSuite(t *testing.T) {
|
||||
suite.Run(t, new(tallyHandlerSuite))
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) SetupTest() {
|
||||
suite.app = NewTestApp()
|
||||
suite.app.InitializeFromGenesisStates()
|
||||
genesisTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
suite.ctx = suite.app.NewContext(false, tmproto.Header{Height: 1, Time: genesisTime})
|
||||
|
||||
stakingKeeper := *suite.app.GetStakingKeeper()
|
||||
suite.staking = stakingHelper{stakingKeeper}
|
||||
suite.staking.setBondDenom(suite.ctx, "ukava")
|
||||
|
||||
suite.tallier = NewTallyHandler(
|
||||
suite.app.GetGovKeeper(),
|
||||
stakingKeeper,
|
||||
suite.app.GetSavingsKeeper(),
|
||||
suite.app.GetEarnKeeper(),
|
||||
suite.app.GetLiquidKeeper(),
|
||||
suite.app.GetBankKeeper(),
|
||||
)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) TestVotePower_AllSourcesCounted() {
|
||||
user := suite.createAccount(suite.newBondCoin(sdkmath.NewInt(1e9)))
|
||||
|
||||
validator := suite.delegateToNewBondedValidator(user.GetAddress(), sdkmath.NewInt(1e9))
|
||||
|
||||
derivatives := suite.mintDerivative(user.GetAddress(), validator.GetOperator(), sdkmath.NewInt(500e6))
|
||||
|
||||
suite.allowBKavaEarnDeposits()
|
||||
suite.earnDeposit(
|
||||
user.GetAddress(),
|
||||
sdk.NewCoin(derivatives.Denom, sdkmath.NewInt(250e6)),
|
||||
)
|
||||
|
||||
proposal := suite.createProposal()
|
||||
suite.voteOnProposal(user.GetAddress(), proposal.Id, govv1beta1.OptionYes)
|
||||
|
||||
_, _, results := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Equal(sdkmath.NewInt(500e6+250e6+250e6).String(), results.YesCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.NoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.NoWithVetoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.AbstainCount)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) TestVotePower_UserOverridesValidator() {
|
||||
user := suite.createAccount(suite.newBondCoin(sdkmath.NewInt(1e9)))
|
||||
|
||||
delegated := sdkmath.NewInt(1e9)
|
||||
validator := suite.delegateToNewBondedValidator(user.GetAddress(), delegated)
|
||||
selfDelegated := validator.GetTokens().Sub(delegated)
|
||||
|
||||
derivatives := suite.mintDerivative(user.GetAddress(), validator.GetOperator(), sdkmath.NewInt(500e6))
|
||||
|
||||
suite.allowBKavaEarnDeposits()
|
||||
suite.earnDeposit(
|
||||
user.GetAddress(),
|
||||
sdk.NewCoin(derivatives.Denom, sdkmath.NewInt(250e6)),
|
||||
)
|
||||
|
||||
proposal := suite.createProposal()
|
||||
|
||||
// Validator votes, inheriting user's stake and bkava.
|
||||
suite.voteOnProposal(validator.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionYes)
|
||||
|
||||
// use wrapped context to discard the state changes
|
||||
readOnlyCtx, _ := suite.ctx.CacheContext()
|
||||
_, _, results := suite.tallier.Tally(readOnlyCtx, proposal)
|
||||
userPower := sdkmath.NewInt(500e6 + 250e6 + 250e6)
|
||||
suite.Equal(
|
||||
selfDelegated.Add(userPower).String(),
|
||||
results.YesCount,
|
||||
)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.NoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.NoWithVetoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.AbstainCount)
|
||||
|
||||
// User votes, taking power away from validator.
|
||||
suite.voteOnProposal(user.GetAddress(), proposal.Id, govv1beta1.OptionNo)
|
||||
|
||||
_, _, results = suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Equal(selfDelegated.String(), results.YesCount)
|
||||
suite.Equal(userPower.String(), results.NoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.NoWithVetoCount)
|
||||
suite.Equal(sdk.ZeroInt().String(), results.AbstainCount)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) TestTallyOutcomes() {
|
||||
suite.Run("VotedPowerBelowQuorumFails", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
v1 := suite.createNewBondedValidator(sdkmath.NewInt(399_999_999))
|
||||
suite.createNewBondedValidator(sdkmath.NewInt(600_000_001))
|
||||
|
||||
suite.voteOnProposal(v1.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionYes)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Falsef(passes, "expected proposal to fail, tally: %v", tally)
|
||||
suite.Truef(burns, "expected desposit to be burned, tally: %v", tally)
|
||||
})
|
||||
suite.Run("VetoedFails", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
v1 := suite.createNewBondedValidator(sdkmath.NewInt(334_000_001))
|
||||
v2 := suite.createNewBondedValidator(sdkmath.NewInt(665_999_999))
|
||||
|
||||
suite.voteOnProposal(v1.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionNoWithVeto)
|
||||
suite.voteOnProposal(v2.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionYes)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Falsef(passes, "expected proposal to fail, tally: %v", tally)
|
||||
suite.Truef(burns, "expected desposit to be burned, tally: %v", tally)
|
||||
})
|
||||
suite.Run("UnvetoedAndYesAboveThresholdPasses", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
v1 := suite.createNewBondedValidator(sdkmath.NewInt(900_000_000))
|
||||
v2 := suite.createNewBondedValidator(sdkmath.NewInt(50_000_001))
|
||||
v3 := suite.createNewBondedValidator(sdkmath.NewInt(49_999_999))
|
||||
|
||||
suite.voteOnProposal(v1.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionAbstain)
|
||||
suite.voteOnProposal(v2.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionYes)
|
||||
suite.voteOnProposal(v3.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionNo)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Truef(passes, "expected proposal to pass, tally: %v", tally)
|
||||
suite.Falsef(burns, "expected desposit to not burn, tally: %v", tally)
|
||||
})
|
||||
suite.Run("UnvetoedAndYesBelowThresholdFails", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
v1 := suite.createNewBondedValidator(sdkmath.NewInt(900_000_000))
|
||||
v2 := suite.createNewBondedValidator(sdkmath.NewInt(49_999_999))
|
||||
v3 := suite.createNewBondedValidator(sdkmath.NewInt(50_000_001))
|
||||
|
||||
suite.voteOnProposal(v1.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionAbstain)
|
||||
suite.voteOnProposal(v2.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionYes)
|
||||
suite.voteOnProposal(v3.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionNo)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Falsef(passes, "expected proposal to pass, tally: %v", tally)
|
||||
suite.Falsef(burns, "expected desposit to not burn, tally: %v", tally)
|
||||
})
|
||||
suite.Run("NotEnoughStakeFails", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
// no stake
|
||||
suite.app.DeleteGenesisValidator(suite.T(), suite.ctx)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Falsef(passes, "expected proposal to pass, tally: %v", tally)
|
||||
suite.Falsef(burns, "expected desposit to not burn, tally: %v", tally)
|
||||
})
|
||||
suite.Run("UnvetoedAndAllAbstainedFails", func() {
|
||||
suite.SetupTest()
|
||||
suite.setTallyParams(d("0.4"), d("0.5"), d("0.334"))
|
||||
proposal := suite.createProposal()
|
||||
|
||||
v1 := suite.createNewBondedValidator(sdkmath.NewInt(1e9))
|
||||
|
||||
suite.voteOnProposal(v1.GetOperator().Bytes(), proposal.Id, govv1beta1.OptionAbstain)
|
||||
|
||||
passes, burns, tally := suite.tallier.Tally(suite.ctx, proposal)
|
||||
suite.Falsef(passes, "expected proposal to pass, tally: %v", tally)
|
||||
suite.Falsef(burns, "expected desposit to not burn, tally: %v", tally)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) setTallyParams(quorum, threshold, veto sdk.Dec) {
|
||||
params := suite.app.GetGovKeeper().GetParams(suite.ctx)
|
||||
params.Quorum = quorum.String()
|
||||
params.Threshold = threshold.String()
|
||||
params.VetoThreshold = veto.String()
|
||||
params.BurnVoteQuorum = true
|
||||
suite.app.GetGovKeeper().SetParams(suite.ctx, params)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) voteOnProposal(
|
||||
voter sdk.AccAddress,
|
||||
proposalID uint64,
|
||||
option govv1beta1.VoteOption,
|
||||
) {
|
||||
gk := suite.app.GetGovKeeper()
|
||||
|
||||
err := gk.AddVote(suite.ctx,
|
||||
proposalID,
|
||||
voter,
|
||||
govv1.NewNonSplitVoteOption(govv1.VoteOption(option)),
|
||||
"",
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) createProposal() govv1.Proposal {
|
||||
gk := suite.app.GetGovKeeper()
|
||||
deposit := gk.GetParams(suite.ctx).MinDeposit
|
||||
proposer := suite.createAccount(deposit...)
|
||||
|
||||
msg, err := govv1beta1.NewMsgSubmitProposal(
|
||||
govv1beta1.NewTextProposal("a title", "a description"),
|
||||
deposit,
|
||||
proposer.GetAddress(),
|
||||
)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
msgServerv1 := govkeeper.NewMsgServerImpl(&gk)
|
||||
|
||||
govAcct := gk.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||
msgServer := govkeeper.NewLegacyMsgServerImpl(govAcct.String(), msgServerv1)
|
||||
res, err := msgServer.SubmitProposal(sdk.WrapSDKContext(suite.ctx), msg)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
proposal, found := gk.GetProposal(suite.ctx, res.ProposalId)
|
||||
if !found {
|
||||
panic("proposal not found")
|
||||
}
|
||||
return proposal
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) newBondCoin(amount sdkmath.Int) sdk.Coin {
|
||||
return suite.staking.newBondCoin(suite.ctx, amount)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) allowBKavaEarnDeposits() {
|
||||
ek := suite.app.GetEarnKeeper()
|
||||
earnParams := ek.GetParams(suite.ctx)
|
||||
|
||||
vault := earntypes.NewAllowedVault(
|
||||
liquidtypes.DefaultDerivativeDenom,
|
||||
earntypes.StrategyTypes{earntypes.STRATEGY_TYPE_SAVINGS},
|
||||
false,
|
||||
nil,
|
||||
)
|
||||
|
||||
earnParams.AllowedVaults = append(earnParams.AllowedVaults, vault)
|
||||
ek.SetParams(suite.ctx, earnParams)
|
||||
|
||||
sk := suite.app.GetSavingsKeeper()
|
||||
savingsParams := sk.GetParams(suite.ctx)
|
||||
savingsParams.SupportedDenoms = append(savingsParams.SupportedDenoms, liquidtypes.DefaultDerivativeDenom)
|
||||
sk.SetParams(suite.ctx, savingsParams)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) earnDeposit(owner sdk.AccAddress, derivative sdk.Coin) {
|
||||
ek := suite.app.GetEarnKeeper()
|
||||
|
||||
err := ek.Deposit(suite.ctx, owner, derivative, earntypes.STRATEGY_TYPE_SAVINGS)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) mintDerivative(owner sdk.AccAddress, validator sdk.ValAddress, amount sdkmath.Int) sdk.Coin {
|
||||
lk := suite.app.GetLiquidKeeper()
|
||||
|
||||
minted, err := lk.MintDerivative(suite.ctx, owner, validator, suite.newBondCoin(amount))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
return minted
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) delegateToNewBondedValidator(delegator sdk.AccAddress, amount sdkmath.Int) stakingtypes.ValidatorI {
|
||||
valAcc := suite.createAccount(suite.newBondCoin(sdkmath.NewInt(1e9)))
|
||||
validator, err := suite.staking.createUnbondedValidator(suite.ctx, valAcc.GetAddress().Bytes(), sdkmath.NewInt(1e9))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
_, err = suite.staking.delegate(suite.ctx, delegator, validator.GetOperator(), amount)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// bond the validator
|
||||
sk := suite.app.GetStakingKeeper()
|
||||
staking.EndBlocker(suite.ctx, sk)
|
||||
|
||||
validator, found := sk.GetValidator(suite.ctx, validator.GetOperator())
|
||||
if !found {
|
||||
panic("validator not found")
|
||||
}
|
||||
return validator
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) createNewBondedValidator(selfDelegation sdkmath.Int) stakingtypes.ValidatorI {
|
||||
valAcc := suite.createAccount(suite.newBondCoin(selfDelegation))
|
||||
validator, err := suite.staking.createUnbondedValidator(suite.ctx, valAcc.GetAddress().Bytes(), selfDelegation)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// bond the validator
|
||||
sk := suite.app.GetStakingKeeper()
|
||||
staking.EndBlocker(suite.ctx, sk)
|
||||
|
||||
validator, found := sk.GetValidator(suite.ctx, validator.GetOperator())
|
||||
if !found {
|
||||
panic("validator not found")
|
||||
}
|
||||
return validator
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) createAccount(initialBalance ...sdk.Coin) authtypes.AccountI {
|
||||
ak := suite.app.GetAccountKeeper()
|
||||
|
||||
acc := ak.NewAccountWithAddress(suite.ctx, RandomAddress())
|
||||
ak.SetAccount(suite.ctx, acc)
|
||||
|
||||
err := suite.app.FundAccount(suite.ctx, acc.GetAddress(), initialBalance)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
// stakingHelper wraps the staking keeper with helper functions for testing.
|
||||
type stakingHelper struct {
|
||||
keeper stakingkeeper.Keeper
|
||||
}
|
||||
|
||||
func (h stakingHelper) createUnbondedValidator(ctx sdk.Context, address sdk.ValAddress, selfDelegation sdkmath.Int) (stakingtypes.ValidatorI, error) {
|
||||
msg, err := stakingtypes.NewMsgCreateValidator(
|
||||
address,
|
||||
ed25519.GenPrivKey().PubKey(),
|
||||
h.newBondCoin(ctx, selfDelegation),
|
||||
stakingtypes.Description{},
|
||||
stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||
sdkmath.NewInt(1e6),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msgServer := stakingkeeper.NewMsgServerImpl(&h.keeper)
|
||||
_, err = msgServer.CreateValidator(sdk.WrapSDKContext(ctx), msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
validator, found := h.keeper.GetValidator(ctx, address)
|
||||
if !found {
|
||||
panic("validator not found")
|
||||
}
|
||||
return validator, nil
|
||||
}
|
||||
|
||||
func (h stakingHelper) delegate(ctx sdk.Context, delegator sdk.AccAddress, validator sdk.ValAddress, amount sdkmath.Int) (sdk.Dec, error) {
|
||||
msg := stakingtypes.NewMsgDelegate(
|
||||
delegator,
|
||||
validator,
|
||||
h.newBondCoin(ctx, amount),
|
||||
)
|
||||
|
||||
msgServer := stakingkeeper.NewMsgServerImpl(&h.keeper)
|
||||
_, err := msgServer.Delegate(sdk.WrapSDKContext(ctx), msg)
|
||||
if err != nil {
|
||||
return sdk.Dec{}, err
|
||||
}
|
||||
|
||||
del, found := h.keeper.GetDelegation(ctx, delegator, validator)
|
||||
if !found {
|
||||
panic("delegation not found")
|
||||
}
|
||||
return del.Shares, nil
|
||||
}
|
||||
|
||||
func (h stakingHelper) newBondCoin(ctx sdk.Context, amount sdkmath.Int) sdk.Coin {
|
||||
return sdk.NewCoin(h.keeper.BondDenom(ctx), amount)
|
||||
}
|
||||
|
||||
func (h stakingHelper) setBondDenom(ctx sdk.Context, denom string) {
|
||||
params := h.keeper.GetParams(ctx)
|
||||
params.BondDenom = denom
|
||||
h.keeper.SetParams(ctx, params)
|
||||
}
|
@ -41,22 +41,8 @@ import (
|
||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
auctionkeeper "github.com/kava-labs/kava/x/auction/keeper"
|
||||
bep3keeper "github.com/kava-labs/kava/x/bep3/keeper"
|
||||
cdpkeeper "github.com/kava-labs/kava/x/cdp/keeper"
|
||||
committeekeeper "github.com/kava-labs/kava/x/committee/keeper"
|
||||
communitykeeper "github.com/kava-labs/kava/x/community/keeper"
|
||||
earnkeeper "github.com/kava-labs/kava/x/earn/keeper"
|
||||
evmutilkeeper "github.com/kava-labs/kava/x/evmutil/keeper"
|
||||
hardkeeper "github.com/kava-labs/kava/x/hard/keeper"
|
||||
incentivekeeper "github.com/kava-labs/kava/x/incentive/keeper"
|
||||
issuancekeeper "github.com/kava-labs/kava/x/issuance/keeper"
|
||||
kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper"
|
||||
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
|
||||
pricefeedkeeper "github.com/kava-labs/kava/x/pricefeed/keeper"
|
||||
routerkeeper "github.com/kava-labs/kava/x/router/keeper"
|
||||
savingskeeper "github.com/kava-labs/kava/x/savings/keeper"
|
||||
swapkeeper "github.com/kava-labs/kava/x/swap/keeper"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -64,7 +50,7 @@ var (
|
||||
defaultInitialHeight int64 = 1
|
||||
)
|
||||
|
||||
const TestChainId = "kavatest_2221-1"
|
||||
const TestChainId = "0gchaintest_2221-1"
|
||||
|
||||
// TestApp is a simple wrapper around an App. It exposes internal keepers for use in integration tests.
|
||||
// This file also contains test helpers. Ideally they would be in separate package.
|
||||
@ -89,7 +75,7 @@ type TestApp struct {
|
||||
//
|
||||
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
||||
func NewTestApp() TestApp {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
return NewTestAppFromSealed()
|
||||
}
|
||||
@ -101,7 +87,7 @@ func NewTestAppFromSealed() TestApp {
|
||||
encCfg := MakeEncodingConfig()
|
||||
|
||||
app := NewApp(
|
||||
log.NewNopLogger(), db, DefaultNodeHome, nil,
|
||||
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||
)
|
||||
return TestApp{App: *app}
|
||||
@ -117,24 +103,11 @@ func (tApp TestApp) GetDistrKeeper() distkeeper.Keeper { return tApp.di
|
||||
func (tApp TestApp) GetGovKeeper() govkeeper.Keeper { return tApp.govKeeper }
|
||||
func (tApp TestApp) GetCrisisKeeper() crisiskeeper.Keeper { return tApp.crisisKeeper }
|
||||
func (tApp TestApp) GetParamsKeeper() paramskeeper.Keeper { return tApp.paramsKeeper }
|
||||
func (tApp TestApp) GetKavadistKeeper() kavadistkeeper.Keeper { return tApp.kavadistKeeper }
|
||||
func (tApp TestApp) GetAuctionKeeper() auctionkeeper.Keeper { return tApp.auctionKeeper }
|
||||
func (tApp TestApp) GetIssuanceKeeper() issuancekeeper.Keeper { return tApp.issuanceKeeper }
|
||||
func (tApp TestApp) GetBep3Keeper() bep3keeper.Keeper { return tApp.bep3Keeper }
|
||||
func (tApp TestApp) GetPriceFeedKeeper() pricefeedkeeper.Keeper { return tApp.pricefeedKeeper }
|
||||
func (tApp TestApp) GetSwapKeeper() swapkeeper.Keeper { return tApp.swapKeeper }
|
||||
func (tApp TestApp) GetCDPKeeper() cdpkeeper.Keeper { return tApp.cdpKeeper }
|
||||
func (tApp TestApp) GetHardKeeper() hardkeeper.Keeper { return tApp.hardKeeper }
|
||||
func (tApp TestApp) GetCommitteeKeeper() committeekeeper.Keeper { return tApp.committeeKeeper }
|
||||
func (tApp TestApp) GetIncentiveKeeper() incentivekeeper.Keeper { return tApp.incentiveKeeper }
|
||||
func (tApp TestApp) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
||||
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
||||
func (tApp TestApp) GetSavingsKeeper() savingskeeper.Keeper { return tApp.savingsKeeper }
|
||||
|
||||
func (tApp TestApp) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
||||
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
||||
|
||||
func (tApp TestApp) GetFeeMarketKeeper() feemarketkeeper.Keeper { return tApp.feeMarketKeeper }
|
||||
func (tApp TestApp) GetLiquidKeeper() liquidkeeper.Keeper { return tApp.liquidKeeper }
|
||||
func (tApp TestApp) GetEarnKeeper() earnkeeper.Keeper { return tApp.earnKeeper }
|
||||
func (tApp TestApp) GetRouterKeeper() routerkeeper.Keeper { return tApp.routerKeeper }
|
||||
func (tApp TestApp) GetCommunityKeeper() communitykeeper.Keeper { return tApp.communityKeeper }
|
||||
|
||||
func (tApp TestApp) GetKVStoreKey(key string) *storetypes.KVStoreKey {
|
||||
return tApp.keys[key]
|
||||
@ -174,7 +147,7 @@ func GenesisStateWithSingleValidator(
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -237,7 +210,7 @@ func genesisStateWithValSet(
|
||||
}
|
||||
// set validators and delegations
|
||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||
|
||||
stakingGenesis := stakingtypes.NewGenesisState(
|
||||
currentStakingGenesis.Params,
|
||||
@ -257,13 +230,13 @@ func genesisStateWithValSet(
|
||||
|
||||
for range delegations {
|
||||
// add delegated tokens to total supply
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin("ukava", bondAmt))
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, bondAmt))
|
||||
}
|
||||
|
||||
// add bonded amount to bonded pool module account
|
||||
balances = append(balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||
Coins: sdk.Coins{sdk.NewCoin("ukava", bondAmt)},
|
||||
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||
})
|
||||
|
||||
bankGenesis := banktypes.NewGenesisState(
|
||||
|
@ -7,7 +7,7 @@ proto-lint check-proto-lint: install-build-deps
|
||||
proto-gen: install-build-deps
|
||||
@echo "Generating go proto files"
|
||||
@$(BUF) generate --template proto/buf.gen.gogo.yaml proto
|
||||
@cp -r out/github.com/kava-labs/kava/* ./
|
||||
@cp -r out/github.com/0glabs/0g-chain/* ./
|
||||
@rm -rf out/github.com
|
||||
|
||||
.PHONY: check-proto-gen
|
||||
|
22
chaincfg/coin.go
Normal file
22
chaincfg/coin.go
Normal file
@ -0,0 +1,22 @@
|
||||
package chaincfg
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info.
|
||||
Bip44CoinType uint32 = 459 // TODO: need new coin type for 0g-chain (a0gi)
|
||||
// eth = 60
|
||||
// kava = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||
// BIP44HDPath is the default BIP44 HD path used on Ethereum.
|
||||
//BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String()
|
||||
)
|
||||
|
||||
// TODO: Implement BIP44CoinType and BIP44HDPath
|
||||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||
func setBip44CoinType(config *sdk.Config) {
|
||||
config.SetCoinType(Bip44CoinType)
|
||||
//config.SetPurpose(sdk.Purpose) // Shared
|
||||
//config.SetFullFundraiserPath(BIP44HDPath) //nolint: staticcheck
|
||||
}
|
15
chaincfg/config.go
Normal file
15
chaincfg/config.go
Normal file
@ -0,0 +1,15 @@
|
||||
package chaincfg
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
const (
|
||||
AppName = "0gchain"
|
||||
EnvPrefix = "0GCHAIN"
|
||||
)
|
||||
|
||||
func SetSDKConfig() *sdk.Config {
|
||||
config := sdk.GetConfig()
|
||||
setBech32Prefixes(config)
|
||||
setBip44CoinType(config)
|
||||
return config
|
||||
}
|
28
chaincfg/denoms.go
Normal file
28
chaincfg/denoms.go
Normal file
@ -0,0 +1,28 @@
|
||||
package chaincfg
|
||||
|
||||
import (
|
||||
"cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// DisplayDenom defines the denomination displayed to users in client applications.
|
||||
DisplayDenom = "a0gi"
|
||||
// BaseDenom defines to the default denomination used in 0g-chain
|
||||
BaseDenom = "neuron"
|
||||
|
||||
BaseDenomUnit = 18
|
||||
|
||||
ConversionMultiplier = 1e18
|
||||
)
|
||||
|
||||
// RegisterDenoms registers the base and display denominations to the SDK.
|
||||
func RegisterDenoms() {
|
||||
if err := sdk.RegisterDenom(DisplayDenom, math.LegacyOneDec()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := sdk.RegisterDenom(BaseDenom, math.LegacyNewDecWithPrec(1, BaseDenomUnit)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
25
chaincfg/homedir.go
Normal file
25
chaincfg/homedir.go
Normal file
@ -0,0 +1,25 @@
|
||||
package chaincfg
|
||||
|
||||
import (
|
||||
stdlog "log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
HomeDirName = ".0gchain"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultNodeHome default home directories for the application daemon
|
||||
DefaultNodeHome string
|
||||
)
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
stdlog.Printf("Failed to get home dir %v", err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, HomeDirName)
|
||||
}
|
44
chaincfg/prefix.go
Normal file
44
chaincfg/prefix.go
Normal file
@ -0,0 +1,44 @@
|
||||
package chaincfg
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// Bech32Prefix defines the Bech32 prefix used for EthAccounts
|
||||
Bech32Prefix = "0g"
|
||||
|
||||
// PrefixAccount is the prefix for account keys
|
||||
PrefixAccount = "acc"
|
||||
// PrefixValidator is the prefix for validator keys
|
||||
PrefixValidator = "val"
|
||||
// PrefixConsensus is the prefix for consensus keys
|
||||
PrefixConsensus = "cons"
|
||||
// PrefixPublic is the prefix for public keys
|
||||
PrefixPublic = "pub"
|
||||
// PrefixOperator is the prefix for operator keys
|
||||
PrefixOperator = "oper"
|
||||
|
||||
// PrefixAddress is the prefix for addresses
|
||||
PrefixAddress = "addr"
|
||||
|
||||
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
|
||||
Bech32PrefixAccAddr = Bech32Prefix
|
||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||
Bech32PrefixAccPub = Bech32Prefix + PrefixPublic
|
||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||
Bech32PrefixValAddr = Bech32Prefix + PrefixValidator + PrefixOperator
|
||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||
Bech32PrefixValPub = Bech32Prefix + PrefixValidator + PrefixOperator + PrefixPublic
|
||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||
Bech32PrefixConsAddr = Bech32Prefix + PrefixValidator + PrefixConsensus
|
||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||
Bech32PrefixConsPub = Bech32Prefix + PrefixValidator + PrefixConsensus + PrefixPublic
|
||||
)
|
||||
|
||||
// setBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
|
||||
func setBech32Prefixes(config *sdk.Config) {
|
||||
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||
}
|
@ -62,36 +62,36 @@ func TestKvCLIKeysAddRecover(t *testing.T) {
|
||||
|
||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||
require.True(t, exitSuccess)
|
||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||
|
||||
// test old bip44 coin type
|
||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
||||
require.True(t, exitSuccess)
|
||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||
|
||||
// Cleanup testing directories
|
||||
f.Cleanup()
|
||||
}
|
||||
|
||||
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := InitFixtures(t)
|
||||
|
||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||
|
||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
||||
require.Equal(t, "kava1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||
require.Equal(t, "0g1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||
|
||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
||||
require.Equal(t, "kava1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||
require.Equal(t, "0g1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||
|
||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||
|
||||
// test old bip44 coin type
|
||||
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
||||
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||
require.Equal(t, "0g1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||
|
||||
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
||||
require.False(t, exitSuccess)
|
||||
@ -99,11 +99,11 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
// test -hd-path flag
|
||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
||||
require.True(t, exitSuccess)
|
||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
||||
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
||||
|
||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
||||
require.True(t, exitSuccess)
|
||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
||||
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
||||
|
||||
// Cleanup testing directories
|
||||
f.Cleanup()
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -92,7 +92,7 @@ type Fixtures struct {
|
||||
|
||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||
func NewFixtures(t *testing.T) *Fixtures {
|
||||
tmpDir, err := ioutil.TempDir("", "kava_integration_"+t.Name()+"_")
|
||||
tmpDir, err := ioutil.TempDir("", "0gchain_integration_"+t.Name()+"_")
|
||||
require.NoError(t, err)
|
||||
|
||||
servAddr, port, err := server.FreeTCPAddr()
|
||||
@ -201,9 +201,9 @@ func (f *Fixtures) Flags() string {
|
||||
}
|
||||
|
||||
//___________________________________________________________________________________
|
||||
// kavad
|
||||
// 0gchaind
|
||||
|
||||
// UnsafeResetAll is kavad unsafe-reset-all
|
||||
// UnsafeResetAll is 0gchaind unsafe-reset-all
|
||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||
executeWrite(f.T, addFlags(cmd, flags))
|
||||
@ -211,7 +211,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
require.NoError(f.T, err)
|
||||
}
|
||||
|
||||
// KvInit is kavad init
|
||||
// KvInit is 0gchaind init
|
||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
||||
@ -229,25 +229,25 @@ func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
f.ChainID = chainID
|
||||
}
|
||||
|
||||
// AddGenesisAccount is kavad add-genesis-account
|
||||
// AddGenesisAccount is 0gchaind add-genesis-account
|
||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GenTx is kavad gentx
|
||||
// GenTx is 0gchaind gentx
|
||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// CollectGenTxs is kavad collect-gentxs
|
||||
// CollectGenTxs is 0gchaind collect-gentxs
|
||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GDStart runs kavad start with the appropriate flags and returns a process
|
||||
// GDStart runs 0gchaind start with the appropriate flags and returns a process
|
||||
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
||||
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||
@ -256,7 +256,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
return proc
|
||||
}
|
||||
|
||||
// GDTendermint returns the results of kavad tendermint [query]
|
||||
// GDTendermint returns the results of 0gchaind tendermint [query]
|
||||
func (f *Fixtures) GDTendermint(query string) string {
|
||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||
@ -265,7 +265,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
||||
return strings.TrimSpace(stdout)
|
||||
}
|
||||
|
||||
// ValidateGenesis runs kavad validate-genesis
|
||||
// ValidateGenesis runs 0gchaind validate-genesis
|
||||
func (f *Fixtures) ValidateGenesis() {
|
||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, cmd)
|
||||
|
@ -2,14 +2,14 @@
|
||||
swagger: "2.0"
|
||||
info:
|
||||
version: "3.0"
|
||||
title: Kava Light Client RPC
|
||||
title: 0g-chain Light Client RPC
|
||||
description: A REST interface for state queries, transaction generation and broadcasting.
|
||||
tags:
|
||||
- name: Vesting
|
||||
description: Validator vesting module APIs
|
||||
schemes:
|
||||
- https
|
||||
host: api.data.kava.io
|
||||
host: api.data.0g-chain.io
|
||||
securityDefinitions:
|
||||
kms:
|
||||
type: basic
|
||||
@ -17,14 +17,14 @@ paths:
|
||||
/vesting/circulatingsupply:
|
||||
get:
|
||||
deprecated: true
|
||||
summary: Get the current circulating supply of KAVA
|
||||
summary: Get the current circulating supply of 0g-chain
|
||||
tags:
|
||||
- Vesting
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
200:
|
||||
description: KAVA circulating supply
|
||||
description: 0g-chain circulating supply
|
||||
schema:
|
||||
properties:
|
||||
height:
|
||||
@ -38,14 +38,14 @@ paths:
|
||||
/vesting/totalsupply:
|
||||
get:
|
||||
deprecated: true
|
||||
summary: Get the total supply of KAVA
|
||||
summary: Get the total supply of 0g-chain
|
||||
tags:
|
||||
- Vesting
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
200:
|
||||
description: KAVA total supply
|
||||
description: 0g-chain total supply
|
||||
schema:
|
||||
properties:
|
||||
height:
|
||||
|
@ -16,7 +16,7 @@ The Kava gRPC client is a tool for making gRPC queries on a Kava chain.
|
||||
package main
|
||||
|
||||
import (
|
||||
kavaGrpc "github.com/kava-labs/kava/client/grpc"
|
||||
kavaGrpc "github.com/0glabs/0g-chain/client/grpc"
|
||||
)
|
||||
grpcUrl := "https://grpc.kava.io:443"
|
||||
client, err := kavaGrpc.NewClient(grpcUrl)
|
||||
@ -46,7 +46,7 @@ Example: Query Kava module `x/evmutil` for params
|
||||
|
||||
```go
|
||||
import (
|
||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
rsp, err := client.Query.Evmutil.Params(
|
||||
|
@ -3,33 +3,33 @@ package grpc
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/kava-labs/kava/client/grpc/query"
|
||||
"github.com/kava-labs/kava/client/grpc/util"
|
||||
"github.com/0glabs/0g-chain/client/grpc/query"
|
||||
"github.com/0glabs/0g-chain/client/grpc/util"
|
||||
)
|
||||
|
||||
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
|
||||
type KavaGrpcClient struct {
|
||||
config KavaGrpcClientConfig
|
||||
// ZgChainGrpcClient enables the usage of 0gChain grpc query clients and query utils
|
||||
type ZgChainGrpcClient struct {
|
||||
config ZgChainGrpcClientConfig
|
||||
|
||||
// Query clients for cosmos and kava modules
|
||||
// Query clients for cosmos and 0gChain modules
|
||||
Query *query.QueryClient
|
||||
|
||||
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
||||
*util.Util
|
||||
}
|
||||
|
||||
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
|
||||
type KavaGrpcClientConfig struct {
|
||||
// ZgChainGrpcClientConfig is a configuration struct for a ZgChainGrpcClient
|
||||
type ZgChainGrpcClientConfig struct {
|
||||
// note: add future config options here
|
||||
}
|
||||
|
||||
// NewClient creates a new KavaGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
|
||||
// NewClient creates a new ZgChainGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*ZgChainGrpcClient, error) {
|
||||
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
||||
}
|
||||
|
||||
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
|
||||
// NewClientWithConfig creates a new ZgChainGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config ZgChainGrpcClientConfig) (*ZgChainGrpcClient, error) {
|
||||
if grpcUrl == "" {
|
||||
return nil, errors.New("grpc url cannot be empty")
|
||||
}
|
||||
@ -37,7 +37,7 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
if error != nil {
|
||||
return nil, error
|
||||
}
|
||||
client := &KavaGrpcClient{
|
||||
client := &ZgChainGrpcClient{
|
||||
Query: query,
|
||||
Util: util.NewUtil(query),
|
||||
config: config,
|
||||
@ -45,6 +45,6 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func NewDefaultConfig() KavaGrpcClientConfig {
|
||||
return KavaGrpcClientConfig{}
|
||||
func NewDefaultConfig() ZgChainGrpcClientConfig {
|
||||
return ZgChainGrpcClientConfig{}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package grpc_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kava-labs/kava/client/grpc"
|
||||
"github.com/0glabs/0g-chain/client/grpc"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
The query package includes Cosmos and Kava gRPC query clients.
|
||||
The query package includes Cosmos and 0gChain gRPC query clients.
|
||||
|
||||
To ensure that the `QueryClient` stays updated, add new module query clients
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the Kava app.
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the 0gChain app.
|
||||
*/
|
||||
package query
|
||||
|
@ -24,24 +24,12 @@ import (
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
|
||||
auctiontypes "github.com/kava-labs/kava/x/auction/types"
|
||||
bep3types "github.com/kava-labs/kava/x/bep3/types"
|
||||
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
||||
committeetypes "github.com/kava-labs/kava/x/committee/types"
|
||||
communitytypes "github.com/kava-labs/kava/x/community/types"
|
||||
earntypes "github.com/kava-labs/kava/x/earn/types"
|
||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
||||
hardtypes "github.com/kava-labs/kava/x/hard/types"
|
||||
incentivetypes "github.com/kava-labs/kava/x/incentive/types"
|
||||
issuancetypes "github.com/kava-labs/kava/x/issuance/types"
|
||||
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
|
||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
||||
savingstypes "github.com/kava-labs/kava/x/savings/types"
|
||||
swaptypes "github.com/kava-labs/kava/x/swap/types"
|
||||
committeetypes "github.com/0glabs/0g-chain/x/committee/v1/types"
|
||||
dastypes "github.com/0glabs/0g-chain/x/das/v1/types"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
// QueryClient is a wrapper with all Cosmos and Kava grpc query clients
|
||||
// QueryClient is a wrapper with all Cosmos and 0gChain grpc query clients
|
||||
type QueryClient struct {
|
||||
// cosmos-sdk query clients
|
||||
|
||||
@ -68,23 +56,11 @@ type QueryClient struct {
|
||||
IbcClient ibcclienttypes.QueryClient
|
||||
IbcTransfer ibctransfertypes.QueryClient
|
||||
|
||||
// kava module query clients
|
||||
// 0g-chain module query clients
|
||||
|
||||
Auction auctiontypes.QueryClient
|
||||
Bep3 bep3types.QueryClient
|
||||
Cdp cdptypes.QueryClient
|
||||
Committee committeetypes.QueryClient
|
||||
Community communitytypes.QueryClient
|
||||
Earn earntypes.QueryClient
|
||||
Das dastypes.QueryClient
|
||||
Evmutil evmutiltypes.QueryClient
|
||||
Hard hardtypes.QueryClient
|
||||
Incentive incentivetypes.QueryClient
|
||||
Issuance issuancetypes.QueryClient
|
||||
Kavadist kavadisttypes.QueryClient
|
||||
Liquid liquidtypes.QueryClient
|
||||
Pricefeed pricefeedtypes.QueryClient
|
||||
Savings savingstypes.QueryClient
|
||||
Swap swaptypes.QueryClient
|
||||
}
|
||||
|
||||
// NewQueryClient creates a new QueryClient and initializes all the module query clients
|
||||
@ -115,21 +91,9 @@ func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
|
||||
IbcClient: ibcclienttypes.NewQueryClient(conn),
|
||||
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
|
||||
|
||||
Auction: auctiontypes.NewQueryClient(conn),
|
||||
Bep3: bep3types.NewQueryClient(conn),
|
||||
Cdp: cdptypes.NewQueryClient(conn),
|
||||
Committee: committeetypes.NewQueryClient(conn),
|
||||
Community: communitytypes.NewQueryClient(conn),
|
||||
Earn: earntypes.NewQueryClient(conn),
|
||||
Das: dastypes.NewQueryClient(conn),
|
||||
Evmutil: evmutiltypes.NewQueryClient(conn),
|
||||
Hard: hardtypes.NewQueryClient(conn),
|
||||
Incentive: incentivetypes.NewQueryClient(conn),
|
||||
Issuance: issuancetypes.NewQueryClient(conn),
|
||||
Kavadist: kavadisttypes.NewQueryClient(conn),
|
||||
Liquid: liquidtypes.NewQueryClient(conn),
|
||||
Pricefeed: pricefeedtypes.NewQueryClient(conn),
|
||||
Savings: savingstypes.NewQueryClient(conn),
|
||||
Swap: swaptypes.NewQueryClient(conn),
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package query_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kava-labs/kava/client/grpc/query"
|
||||
"github.com/0glabs/0g-chain/client/grpc/query"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -54,21 +54,9 @@ func TestNewQueryClient_ValidClient(t *testing.T) {
|
||||
require.NotNil(t, client.IbcClient)
|
||||
require.NotNil(t, client.IbcTransfer)
|
||||
|
||||
// validate kava clients
|
||||
require.NotNil(t, client.Auction)
|
||||
require.NotNil(t, client.Bep3)
|
||||
require.NotNil(t, client.Cdp)
|
||||
require.NotNil(t, client.Committee)
|
||||
require.NotNil(t, client.Community)
|
||||
require.NotNil(t, client.Earn)
|
||||
// validate 0gChain clients
|
||||
require.NotNil(t, client.Evmutil)
|
||||
require.NotNil(t, client.Hard)
|
||||
require.NotNil(t, client.Incentive)
|
||||
require.NotNil(t, client.Issuance)
|
||||
require.NotNil(t, client.Kavadist)
|
||||
require.NotNil(t, client.Liquid)
|
||||
require.NotNil(t, client.Pricefeed)
|
||||
require.NotNil(t, client.Savings)
|
||||
require.NotNil(t, client.Swap)
|
||||
require.NotNil(t, client.Committee)
|
||||
require.NotNil(t, client.Das)
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
The util package contains utility functions for the Kava gRPC client.
|
||||
The util package contains utility functions for the 0gChain gRPC client.
|
||||
|
||||
For example, `account.go` includes account-related query helpers.
|
||||
In this file, utilities such as `client.Util.BaseAccount(addr)` is exposed to
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/params"
|
||||
query "github.com/kava-labs/kava/client/grpc/query"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/params"
|
||||
query "github.com/0glabs/0g-chain/client/grpc/query"
|
||||
)
|
||||
|
||||
// Util contains utility functions for the Kava gRPC client
|
||||
// Util contains utility functions for the 0gChain gRPC client
|
||||
type Util struct {
|
||||
query *query.QueryClient
|
||||
encodingConfig params.EncodingConfig
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
simappparams "cosmossdk.io/simapp/params"
|
||||
"github.com/0glabs/0g-chain/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@ -20,7 +21,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/kava-labs/kava/client/rest"
|
||||
)
|
||||
|
||||
func TestBaseReq_Sanitize(t *testing.T) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -23,9 +23,8 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/params"
|
||||
metricstypes "github.com/kava-labs/kava/x/metrics/types"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/params"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -34,7 +33,7 @@ const (
|
||||
flagSkipLoadLatest = "skip-load-latest"
|
||||
)
|
||||
|
||||
// appCreator holds functions used by the sdk server to control the kava app.
|
||||
// appCreator holds functions used by the sdk server to control the 0g-chain app.
|
||||
// The methods implement types in cosmos-sdk/server/types
|
||||
type appCreator struct {
|
||||
encodingConfig params.EncodingConfig
|
||||
@ -118,7 +117,7 @@ func (ac appCreator) newApp(
|
||||
MempoolAuthAddresses: mempoolAuthAddresses,
|
||||
EVMTrace: cast.ToString(appOpts.Get(ethermintflags.EVMTracer)),
|
||||
EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)),
|
||||
TelemetryOptions: metricstypes.TelemetryOptionsFromAppOpts(appOpts),
|
||||
// TelemetryOptions: metricstypes.TelemetryOptionsFromAppOpts(appOpts),
|
||||
},
|
||||
baseapp.SetPruning(pruningOpts),
|
||||
baseapp.SetMinGasPrices(strings.Replace(cast.ToString(appOpts.Get(server.FlagMinGasPrices)), ";", ",", -1)),
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -9,8 +9,8 @@ import (
|
||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/params"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/params"
|
||||
)
|
||||
|
||||
func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
|
@ -1,5 +1,5 @@
|
||||
// Sourced from https://github.com/evmos/ethermint/blob/main/cmd/ethermintd/genaccounts.go
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
@ -6,14 +6,16 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/cmd/kava/cmd"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd := cmd.NewRootCmd()
|
||||
chaincfg.SetSDKConfig().Seal()
|
||||
chaincfg.RegisterDenoms()
|
||||
|
||||
if err := svrcmd.Execute(rootCmd, cmd.EnvPrefix, app.DefaultNodeHome); err != nil {
|
||||
rootCmd := NewRootCmd()
|
||||
|
||||
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil {
|
||||
switch e := err.(type) {
|
||||
case server.ErrorCode:
|
||||
os.Exit(e.Code)
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -7,7 +7,7 @@ import (
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
)
|
||||
|
||||
// newQueryCmd creates all the commands for querying blockchain state.
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -23,21 +23,16 @@ import (
|
||||
servercfg "github.com/evmos/ethermint/server/config"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/app/params"
|
||||
"github.com/kava-labs/kava/cmd/kava/cmd/rocksdb"
|
||||
"github.com/kava-labs/kava/cmd/kava/opendb"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/cmd/opendb"
|
||||
"github.com/0glabs/0g-chain/cmd/rocksdb"
|
||||
)
|
||||
|
||||
// EnvPrefix is the prefix environment variables must have to configure the app.
|
||||
const EnvPrefix = "KAVA"
|
||||
|
||||
// NewRootCmd creates a new root command for the kava blockchain.
|
||||
// NewRootCmd creates a new root command for the 0g-chain blockchain.
|
||||
func NewRootCmd() *cobra.Command {
|
||||
app.SetSDKConfig().Seal()
|
||||
|
||||
encodingConfig := app.MakeEncodingConfig()
|
||||
|
||||
initClientCtx := client.Context{}.
|
||||
WithCodec(encodingConfig.Marshaler).
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
@ -46,13 +41,12 @@ func NewRootCmd() *cobra.Command {
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(types.AccountRetriever{}).
|
||||
WithBroadcastMode(flags.FlagBroadcastMode).
|
||||
WithHomeDir(app.DefaultNodeHome).
|
||||
WithHomeDir(chaincfg.DefaultNodeHome).
|
||||
WithKeyringOptions(hd.EthSecp256k1Option()).
|
||||
WithViper(EnvPrefix)
|
||||
|
||||
WithViper(chaincfg.EnvPrefix)
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "kava",
|
||||
Short: "Daemon and CLI for the Kava blockchain.",
|
||||
Use: chaincfg.AppName,
|
||||
Short: "Daemon and CLI for the 0g-chain blockchain.",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.SetErr(cmd.ErrOrStderr())
|
||||
@ -71,7 +65,7 @@ func NewRootCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig("ukava")
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.BaseDenom)
|
||||
|
||||
return server.InterceptConfigsPreRunHandler(
|
||||
cmd,
|
||||
@ -82,12 +76,12 @@ func NewRootCmd() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
addSubCmds(rootCmd, encodingConfig, app.DefaultNodeHome)
|
||||
addSubCmds(rootCmd, encodingConfig, chaincfg.DefaultNodeHome)
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
// addSubCmds registers all the sub commands used by kava.
|
||||
// addSubCmds registers all the sub commands used by 0g-chain.
|
||||
func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, defaultNodeHome string) {
|
||||
gentxModule, ok := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
|
||||
if !ok {
|
||||
@ -116,7 +110,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
|
||||
|
||||
opts := ethermintserver.StartOptions{
|
||||
AppCreator: ac.newApp,
|
||||
DefaultNodeHome: app.DefaultNodeHome,
|
||||
DefaultNodeHome: chaincfg.DefaultNodeHome,
|
||||
DBOpener: opendb.OpenDB,
|
||||
}
|
||||
// ethermintserver adds additional flags to start the JSON-RPC server for evm support
|
||||
@ -131,7 +125,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
|
||||
rootCmd.AddCommand(
|
||||
newQueryCmd(),
|
||||
newTxCmd(),
|
||||
keyCommands(app.DefaultNodeHome),
|
||||
keyCommands(chaincfg.DefaultNodeHome),
|
||||
rocksdb.RocksDBCmd,
|
||||
newShardCmd(opts),
|
||||
)
|
@ -1,10 +1,10 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
@ -39,7 +39,7 @@ func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state] [--only-cometbft-state] [--force-app-version <app-version>]",
|
||||
Short: "Strip all blocks from the database outside of a given range",
|
||||
Long: `shard opens a local kava home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
Long: `shard opens a local 0g-chainhome directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
|
||||
It works by first rolling back the latest state to the block before the end block, and then by pruning all state before the start block.
|
||||
|
||||
@ -54,14 +54,14 @@ Similarly, the --only-cometbft-state flag skips pruning app state. This can be u
|
||||
The shard command only flags the iavl tree nodes for deletion. Actual removal from the databases will be performed when each database is compacted.
|
||||
|
||||
WARNING: this is a destructive action.`,
|
||||
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
||||
Example: `Create a 1M block data shard (keeps blocks a0gi 1,000,000 to 2,000,000)
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 1000000 --end 2000000
|
||||
|
||||
Prune all blocks up to 5,000,000:
|
||||
$ kava shard --home path/to/.kava --start 5000000 --end -1
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 5000000 --end -1
|
||||
|
||||
Prune first 1M blocks _without_ affecting blockstore or cometBFT state:
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 1000000 --end -1 --only-app-state`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//////////////////////////
|
||||
// parse & validate flags
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
)
|
||||
|
||||
// newTxCmd creates all commands for submitting blockchain transactions.
|
@ -1,7 +1,7 @@
|
||||
//go:build rocksdb
|
||||
// +build rocksdb
|
||||
|
||||
// Copyright 2023 Kava Labs, Inc.
|
||||
// Copyright 2024 0glabs Labs, Inc.
|
||||
// Copyright 2023 Cronos Labs, Inc.
|
||||
//
|
||||
// Derived from https://github.com/crypto-org-chain/cronos@496ce7e
|
@ -14,9 +14,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/cmd/opendb"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/kava-labs/kava/cmd/kava/opendb"
|
||||
"github.com/linxGnu/grocksdb"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/exp/slices"
|
@ -4,11 +4,11 @@ pragma solidity ^0.8.18;
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of Kava.
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of 0g-chain.
|
||||
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
||||
/// @author Kava Labs, LLC
|
||||
/// @custom:security-contact security@kava.io
|
||||
contract ERC20KavaWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @author 0g Labs, LLC
|
||||
/// @custom:security-contact security@0g.ai
|
||||
contract ERC200gChainWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @notice The decimals places of the token. For display purposes only.
|
||||
uint8 private immutable _decimals;
|
||||
|
||||
|
@ -5,7 +5,7 @@ const config: HardhatUserConfig = {
|
||||
solidity: {
|
||||
version: "0.8.18",
|
||||
settings: {
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with kava's evm
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with 0g-chain's evm
|
||||
evmVersion: "istanbul",
|
||||
// optimize build for deployment to mainnet!
|
||||
optimizer: {
|
||||
@ -16,21 +16,21 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
networks: {
|
||||
// kvtool's local network
|
||||
kava: {
|
||||
chain: {
|
||||
url: "http://127.0.0.1:8545",
|
||||
accounts: [
|
||||
// kava keys unsafe-export-eth-key whale2
|
||||
// 0g-chain keys unsafe-export-eth-key whale2
|
||||
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
||||
],
|
||||
},
|
||||
protonet: {
|
||||
url: "https://evm.app.protonet.us-east.production.kava.io:443",
|
||||
url: "https://evm.app.protonet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
},
|
||||
internal_testnet: {
|
||||
url: "https://evm.data.internal.testnet.us-east.production.kava.io:443",
|
||||
url: "https://evm.data.internal.testnet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
|
4
contracts/package-lock.json
generated
4
contracts/package-lock.json
generated
@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"author": "Kava Labs",
|
||||
"author": "0g Labs",
|
||||
"private": true,
|
||||
"description": "Solidity contracts for Kava Blockchain",
|
||||
"description": "Solidity contracts for 0g Blockchain",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@ -12,7 +12,7 @@
|
||||
"clean": "hardhat clean",
|
||||
"compile": "hardhat compile",
|
||||
"coverage": "hardhat coverage",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC20KavaWrappedCosmosCoin.sol/ERC20KavaWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC20KavaWrappedCosmosCoin.json",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC200gChainWrappedCosmosCoin.sol/ERC200gChainWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC200gChainWrappedCosmosCoin.json",
|
||||
"gen-ts-types": "hardhat typechain",
|
||||
"lint": "eslint '**/*.{js,ts}'",
|
||||
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
const tokenName = "Kava-wrapped ATOM";
|
||||
const tokenName = "0g-chain-wrapped ATOM";
|
||||
const tokenSymbol = "kATOM";
|
||||
const tokenDecimals = 6;
|
||||
|
||||
const ERC20KavaWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
const ERC200gChainWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC200gChainWrappedCosmosCoin"
|
||||
);
|
||||
const token = await ERC20KavaWrappedCosmosCoin.deploy(
|
||||
const token = await ERC200gChainWrappedCosmosCoin.deploy(
|
||||
tokenName,
|
||||
tokenSymbol,
|
||||
tokenDecimals
|
||||
|
@ -2,21 +2,21 @@ import { expect } from "chai";
|
||||
import { Signer } from "ethers";
|
||||
import { ethers } from "hardhat";
|
||||
import {
|
||||
ERC20KavaWrappedCosmosCoin,
|
||||
ERC20KavaWrappedCosmosCoin__factory as ERC20KavaWrappedCosmosCoinFactory,
|
||||
ERC200gChainWrappedCosmosCoin,
|
||||
ERC200gChainWrappedCosmosCoin__factory as ERC200gChainWrappedCosmosCoinFactory,
|
||||
} from "../typechain-types";
|
||||
|
||||
const decimals = 6n;
|
||||
|
||||
describe("ERC20KavaWrappedCosmosCoin", function () {
|
||||
let erc20: ERC20KavaWrappedCosmosCoin;
|
||||
let erc20Factory: ERC20KavaWrappedCosmosCoinFactory;
|
||||
describe("ERC200gChainWrappedCosmosCoin", function () {
|
||||
let erc20: ERC200gChainWrappedCosmosCoin;
|
||||
let erc20Factory: ERC200gChainWrappedCosmosCoinFactory;
|
||||
let owner: Signer;
|
||||
let sender: Signer;
|
||||
|
||||
beforeEach(async function () {
|
||||
erc20Factory = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
"ERC200gChainWrappedCosmosCoin"
|
||||
);
|
||||
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
||||
[owner, sender] = await ethers.getSigners();
|
||||
|
58
crypto/vrf/algorithm.go
Normal file
58
crypto/vrf/algorithm.go
Normal file
@ -0,0 +1,58 @@
|
||||
package vrf
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// SupportedAlgorithms defines the list of signing algorithms used on Evmos:
|
||||
// - eth_secp256k1 (Ethereum)
|
||||
// - secp256k1 (Tendermint)
|
||||
SupportedAlgorithms = keyring.SigningAlgoList{VrfAlgo}
|
||||
// SupportedAlgorithmsLedger defines the list of signing algorithms used on Evmos for the Ledger device:
|
||||
// - eth_secp256k1 (Ethereum)
|
||||
// - secp256k1 (Tendermint)
|
||||
SupportedAlgorithmsLedger = keyring.SigningAlgoList{VrfAlgo}
|
||||
)
|
||||
|
||||
func VrfOption() keyring.Option {
|
||||
return func(options *keyring.Options) {
|
||||
options.SupportedAlgos = SupportedAlgorithms
|
||||
options.SupportedAlgosLedger = SupportedAlgorithmsLedger
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
VrfType = hd.PubKeyType(KeyType)
|
||||
)
|
||||
|
||||
var (
|
||||
_ keyring.SignatureAlgo = VrfAlgo
|
||||
VrfAlgo = vrfAlgo{}
|
||||
)
|
||||
|
||||
type vrfAlgo struct{}
|
||||
|
||||
func (s vrfAlgo) Name() hd.PubKeyType {
|
||||
return VrfType
|
||||
}
|
||||
|
||||
func (s vrfAlgo) Derive() hd.DeriveFn {
|
||||
return func(mnemonic, bip39Passphrase, path string) ([]byte, error) {
|
||||
key, err := GenerateKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return key.Bytes(), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s vrfAlgo) Generate() hd.GenerateFn {
|
||||
return func(bz []byte) cryptotypes.PrivKey {
|
||||
key, _ := GenerateKey()
|
||||
return key
|
||||
}
|
||||
}
|
496
crypto/vrf/keys.pb.go
Normal file
496
crypto/vrf/keys.pb.go
Normal file
@ -0,0 +1,496 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: crypto/vrf/keys.proto
|
||||
|
||||
package vrf
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// PubKey defines a type alias for an vrf.PublicKey that implements
|
||||
// Vrf's PubKey interface. It represents the 32-byte compressed public
|
||||
// key format.
|
||||
type PubKey struct {
|
||||
// key is the public key in byte form
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PubKey) Reset() { *m = PubKey{} }
|
||||
func (*PubKey) ProtoMessage() {}
|
||||
func (*PubKey) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_eae59d1af27f5957, []int{0}
|
||||
}
|
||||
func (m *PubKey) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *PubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_PubKey.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *PubKey) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PubKey.Merge(m, src)
|
||||
}
|
||||
func (m *PubKey) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *PubKey) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PubKey.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PubKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PubKey) GetKey() []byte {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrivKey defines a type alias for an vrf.PrivateKey that implements
|
||||
// Vrf's PrivateKey interface.
|
||||
type PrivKey struct {
|
||||
// key is the private key in byte form
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PrivKey) Reset() { *m = PrivKey{} }
|
||||
func (m *PrivKey) String() string { return proto.CompactTextString(m) }
|
||||
func (*PrivKey) ProtoMessage() {}
|
||||
func (*PrivKey) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_eae59d1af27f5957, []int{1}
|
||||
}
|
||||
func (m *PrivKey) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *PrivKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_PrivKey.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *PrivKey) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PrivKey.Merge(m, src)
|
||||
}
|
||||
func (m *PrivKey) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *PrivKey) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PrivKey.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PrivKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PrivKey) GetKey() []byte {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*PubKey)(nil), "crypto.vrf.PubKey")
|
||||
proto.RegisterType((*PrivKey)(nil), "crypto.vrf.PrivKey")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("crypto/vrf/keys.proto", fileDescriptor_eae59d1af27f5957) }
|
||||
|
||||
var fileDescriptor_eae59d1af27f5957 = []byte{
|
||||
// 174 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x2e, 0xaa, 0x2c,
|
||||
0x28, 0xc9, 0xd7, 0x2f, 0x2b, 0x4a, 0xd3, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f,
|
||||
0xc9, 0x17, 0xe2, 0x82, 0x08, 0xeb, 0x95, 0x15, 0xa5, 0x49, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83,
|
||||
0x85, 0xf5, 0x41, 0x2c, 0x88, 0x0a, 0x25, 0x05, 0x2e, 0xb6, 0x80, 0xd2, 0x24, 0xef, 0xd4, 0x4a,
|
||||
0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, 0x4a, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x10, 0xd3,
|
||||
0x8a, 0x65, 0xc6, 0x02, 0x79, 0x06, 0x25, 0x69, 0x2e, 0xf6, 0x80, 0xa2, 0xcc, 0x32, 0xac, 0x4a,
|
||||
0x9c, 0xec, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09,
|
||||
0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x35, 0x3d, 0xb3,
|
||||
0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xdf, 0x20, 0x3d, 0x27, 0x31, 0xa9, 0x58, 0xdf,
|
||||
0x20, 0x5d, 0x37, 0x39, 0x23, 0x31, 0x33, 0x4f, 0x1f, 0xe1, 0xd8, 0x24, 0x36, 0xb0, 0x33, 0x8c,
|
||||
0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdb, 0xb8, 0x32, 0x07, 0xc1, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *PubKey) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *PubKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *PubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Key) > 0 {
|
||||
i -= len(m.Key)
|
||||
copy(dAtA[i:], m.Key)
|
||||
i = encodeVarintKeys(dAtA, i, uint64(len(m.Key)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *PrivKey) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *PrivKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *PrivKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Key) > 0 {
|
||||
i -= len(m.Key)
|
||||
copy(dAtA[i:], m.Key)
|
||||
i = encodeVarintKeys(dAtA, i, uint64(len(m.Key)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintKeys(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovKeys(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *PubKey) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Key)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovKeys(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *PrivKey) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Key)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovKeys(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovKeys(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozKeys(x uint64) (n int) {
|
||||
return sovKeys(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *PubKey) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: PubKey: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: PubKey: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Key == nil {
|
||||
m.Key = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipKeys(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *PrivKey) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: PrivKey: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: PrivKey: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Key == nil {
|
||||
m.Key = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipKeys(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipKeys(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthKeys
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupKeys
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthKeys
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthKeys = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowKeys = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupKeys = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
194
crypto/vrf/vrf.go
Normal file
194
crypto/vrf/vrf.go
Normal file
@ -0,0 +1,194 @@
|
||||
package vrf
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
tmcrypto "github.com/cometbft/cometbft/crypto"
|
||||
vrfalgo "github.com/coniks-sys/coniks-go/crypto/vrf"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
const (
|
||||
// PrivKeySize defines the size of the PrivKey bytes
|
||||
PrivKeySize = 64
|
||||
// PubKeySize defines the size of the PubKey bytes
|
||||
PubKeySize = 32
|
||||
// KeyType is the string constant for the vrf algorithm
|
||||
KeyType = "vrf"
|
||||
)
|
||||
|
||||
// Amino encoding names
|
||||
const (
|
||||
// PrivKeyName defines the amino encoding name for the vrf private key
|
||||
PrivKeyName = "vrf/PrivKey"
|
||||
// PubKeyName defines the amino encoding name for the vrf public key
|
||||
PubKeyName = "vrf/PubKey"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// vrf Private Key
|
||||
|
||||
var (
|
||||
_ cryptotypes.PrivKey = &PrivKey{}
|
||||
_ codec.AminoMarshaler = &PrivKey{}
|
||||
)
|
||||
|
||||
// GenerateKey generates a new random private key. It returns an error upon
|
||||
// failure.
|
||||
func GenerateKey() (*PrivKey, error) {
|
||||
priv, err := vrfalgo.GenerateKey(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PrivKey{
|
||||
Key: priv,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (privKey PrivKey) getVrfPrivateKey() vrfalgo.PrivateKey {
|
||||
return vrfalgo.PrivateKey(privKey.Key)
|
||||
}
|
||||
|
||||
// Bytes returns the byte representation of the Private Key.
|
||||
func (privKey PrivKey) Bytes() []byte {
|
||||
bz := make([]byte, len(privKey.Key))
|
||||
copy(bz, privKey.Key)
|
||||
|
||||
return bz
|
||||
}
|
||||
|
||||
// PubKey returns the private key's public key. If the privkey is not valid
|
||||
// it returns a nil value.
|
||||
func (privKey PrivKey) PubKey() cryptotypes.PubKey {
|
||||
pk, _ := vrfalgo.PrivateKey(privKey.Key).Public()
|
||||
|
||||
return &PubKey{
|
||||
Key: pk,
|
||||
}
|
||||
}
|
||||
|
||||
// Equals returns true if two private keys are equal and false otherwise.
|
||||
func (privKey PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool {
|
||||
return privKey.Type() == other.Type() && subtle.ConstantTimeCompare(privKey.Bytes(), other.Bytes()) == 1
|
||||
}
|
||||
|
||||
// Type returns vrf
|
||||
func (privKey PrivKey) Type() string {
|
||||
return KeyType
|
||||
}
|
||||
|
||||
// Compute generates the vrf value for the byte slice m using the
|
||||
// underlying private key sk.
|
||||
func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) {
|
||||
sk := privKey.getVrfPrivateKey()
|
||||
|
||||
return sk.Compute(digestBz), nil
|
||||
}
|
||||
|
||||
// MarshalAmino overrides Amino binary marshaling.
|
||||
func (privKey PrivKey) MarshalAmino() ([]byte, error) {
|
||||
return privKey.Key, nil
|
||||
}
|
||||
|
||||
// UnmarshalAmino overrides Amino binary marshaling.
|
||||
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
|
||||
if len(bz) != PrivKeySize {
|
||||
return fmt.Errorf("invalid privkey size, expected %d got %d", PrivKeySize, len(bz))
|
||||
}
|
||||
privKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalAminoJSON overrides Amino JSON marshaling.
|
||||
func (privKey PrivKey) MarshalAminoJSON() ([]byte, error) {
|
||||
// When we marshal to Amino JSON, we don't marshal the "key" field itself,
|
||||
// just its contents (i.e. the key bytes).
|
||||
return privKey.MarshalAmino()
|
||||
}
|
||||
|
||||
// UnmarshalAminoJSON overrides Amino JSON marshaling.
|
||||
func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error {
|
||||
return privKey.UnmarshalAmino(bz)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// vrf Public Key
|
||||
|
||||
var (
|
||||
_ cryptotypes.PubKey = &PubKey{}
|
||||
_ codec.AminoMarshaler = &PubKey{}
|
||||
)
|
||||
|
||||
// func (pubKey PubKey) getVrfPublicKey() vrfalgo.PublicKey {
|
||||
// return vrfalgo.PublicKey(pubKey.Key)
|
||||
// }
|
||||
|
||||
// Address returns the address of the ECDSA public key.
|
||||
// The function will return an empty address if the public key is invalid.
|
||||
func (pubKey PubKey) Address() tmcrypto.Address {
|
||||
return tmcrypto.Address(common.BytesToAddress(pubKey.Key).Bytes())
|
||||
}
|
||||
|
||||
// Bytes returns the raw bytes of the ECDSA public key.
|
||||
func (pubKey PubKey) Bytes() []byte {
|
||||
bz := make([]byte, len(pubKey.Key))
|
||||
copy(bz, pubKey.Key)
|
||||
|
||||
return bz
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer interface.
|
||||
func (pubKey PubKey) String() string {
|
||||
return fmt.Sprintf("vrf{%X}", pubKey.Key)
|
||||
}
|
||||
|
||||
// Type returns vrf
|
||||
func (pubKey PubKey) Type() string {
|
||||
return KeyType
|
||||
}
|
||||
|
||||
// Equals returns true if the pubkey type is the same and their bytes are deeply equal.
|
||||
func (pubKey PubKey) Equals(other cryptotypes.PubKey) bool {
|
||||
return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes())
|
||||
}
|
||||
|
||||
// Verify returns true iff vrf=Compute(m) for the sk that
|
||||
// corresponds to pk.
|
||||
func (pubKey PubKey) VerifySignature(msg, sig []byte) bool {
|
||||
panic("not implement")
|
||||
}
|
||||
|
||||
// MarshalAmino overrides Amino binary marshaling.
|
||||
func (pubKey PubKey) MarshalAmino() ([]byte, error) {
|
||||
return pubKey.Key, nil
|
||||
}
|
||||
|
||||
// UnmarshalAmino overrides Amino binary marshaling.
|
||||
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
|
||||
if len(bz) != PubKeySize {
|
||||
return errorsmod.Wrapf(errortypes.ErrInvalidPubKey, "invalid pubkey size, expected %d, got %d", PubKeySize, len(bz))
|
||||
}
|
||||
pubKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalAminoJSON overrides Amino JSON marshaling.
|
||||
func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) {
|
||||
// When we marshal to Amino JSON, we don't marshal the "key" field itself,
|
||||
// just its contents (i.e. the key bytes).
|
||||
return pubKey.MarshalAmino()
|
||||
}
|
||||
|
||||
// UnmarshalAminoJSON overrides Amino JSON marshaling.
|
||||
func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error {
|
||||
return pubKey.UnmarshalAmino(bz)
|
||||
}
|
96
crypto/vrf/vrf_test.go
Normal file
96
crypto/vrf/vrf_test.go
Normal file
@ -0,0 +1,96 @@
|
||||
package vrf
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
func TestPrivKey(t *testing.T) {
|
||||
// validate type and equality
|
||||
privKey, err := GenerateKey()
|
||||
require.NoError(t, err)
|
||||
require.Implements(t, (*cryptotypes.PrivKey)(nil), privKey)
|
||||
|
||||
// validate inequality
|
||||
privKey2, err := GenerateKey()
|
||||
require.NoError(t, err)
|
||||
require.False(t, privKey.Equals(privKey2))
|
||||
}
|
||||
|
||||
func TestPrivKey_PubKey(t *testing.T) {
|
||||
privKey, err := GenerateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
// validate type and equality
|
||||
pubKey := &PubKey{
|
||||
Key: privKey.PubKey().Bytes(),
|
||||
}
|
||||
require.Implements(t, (*cryptotypes.PubKey)(nil), pubKey)
|
||||
|
||||
// validate inequality
|
||||
privKey2, err := GenerateKey()
|
||||
require.NoError(t, err)
|
||||
require.False(t, pubKey.Equals(privKey2.PubKey()))
|
||||
}
|
||||
|
||||
func TestMarshalAmino(t *testing.T) {
|
||||
aminoCdc := codec.NewLegacyAmino()
|
||||
privKey, err := GenerateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
pubKey := privKey.PubKey().(*PubKey)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
msg codec.AminoMarshaler
|
||||
typ interface{}
|
||||
expBinary []byte
|
||||
expJSON string
|
||||
}{
|
||||
{
|
||||
"vrf private key",
|
||||
privKey,
|
||||
&PrivKey{},
|
||||
append([]byte{64}, privKey.Bytes()...), // Length-prefixed.
|
||||
"\"" + base64.StdEncoding.EncodeToString(privKey.Bytes()) + "\"",
|
||||
},
|
||||
{
|
||||
"vrf public key",
|
||||
pubKey,
|
||||
&PubKey{},
|
||||
append([]byte{32}, pubKey.Bytes()...), // Length-prefixed.
|
||||
"\"" + base64.StdEncoding.EncodeToString(pubKey.Bytes()) + "\"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Do a round trip of encoding/decoding binary.
|
||||
bz, err := aminoCdc.Marshal(tc.msg)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expBinary, bz)
|
||||
|
||||
err = aminoCdc.Unmarshal(bz, tc.typ)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.msg, tc.typ)
|
||||
|
||||
// Do a round trip of encoding/decoding JSON.
|
||||
bz, err = aminoCdc.MarshalJSON(tc.msg)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expJSON, string(bz))
|
||||
|
||||
err = aminoCdc.UnmarshalJSON(bz, tc.typ)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.msg, tc.typ)
|
||||
})
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ version: '3'
|
||||
services:
|
||||
kvdnode0:
|
||||
container_name: kvdnode0
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
ports:
|
||||
- "26656-26657:26656-26657"
|
||||
environment:
|
||||
@ -17,7 +17,7 @@ services:
|
||||
|
||||
kvdnode1:
|
||||
container_name: kvdnode1
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
ports:
|
||||
- "26659-26660:26656-26657"
|
||||
environment:
|
||||
@ -31,7 +31,7 @@ services:
|
||||
|
||||
kvdnode2:
|
||||
container_name: kvdnode2
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
environment:
|
||||
- ID=2
|
||||
- LOG=${LOG:-kvd.log}
|
||||
@ -45,7 +45,7 @@ services:
|
||||
|
||||
kvdnode3:
|
||||
container_name: kvdnode3
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
environment:
|
||||
- ID=3
|
||||
- LOG=${LOG:-kvd.log}
|
||||
|
6
go.mod
6
go.mod
@ -1,4 +1,4 @@
|
||||
module github.com/kava-labs/kava
|
||||
module github.com/0glabs/0g-chain
|
||||
|
||||
go 1.21
|
||||
|
||||
@ -9,6 +9,7 @@ require (
|
||||
github.com/cenkalti/backoff/v4 v4.1.3
|
||||
github.com/cometbft/cometbft v0.37.4
|
||||
github.com/cometbft/cometbft-db v0.9.1
|
||||
github.com/coniks-sys/coniks-go v0.0.0-20180722014011-11acf4819b71
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.4
|
||||
github.com/cosmos/cosmos-sdk v0.47.10
|
||||
github.com/cosmos/go-bip39 v1.0.0
|
||||
@ -18,7 +19,6 @@ require (
|
||||
github.com/ethereum/go-ethereum v1.10.26
|
||||
github.com/evmos/ethermint v0.21.0
|
||||
github.com/go-kit/kit v0.12.0
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/protobuf v1.5.3
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||
@ -111,6 +111,7 @@ require (
|
||||
github.com/go-stack/stack v1.8.1 // indirect
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
|
||||
github.com/gogo/googleapis v1.4.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/glog v1.1.2 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
@ -183,7 +184,6 @@ require (
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/status-im/keycard-go v0.2.0 // indirect
|
||||
github.com/stretchr/objx v0.5.0 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
|
||||
github.com/tendermint/go-amino v0.16.0 // indirect
|
||||
github.com/tidwall/btree v1.6.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -396,6 +396,8 @@ github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZ
|
||||
github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M=
|
||||
github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4=
|
||||
github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak=
|
||||
github.com/coniks-sys/coniks-go v0.0.0-20180722014011-11acf4819b71 h1:MFLTqgfJclmtaQ1SRUrWwmDX/1UBok3XWUethkJ2swQ=
|
||||
github.com/coniks-sys/coniks-go v0.0.0-20180722014011-11acf4819b71/go.mod h1:TrHYHH4Wze7v7Hkwu1MH1W+mCPQKM+gs+PicdEV14o8=
|
||||
github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ=
|
||||
github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
|
||||
github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q=
|
||||
|
61
helper/da/client/client.go
Normal file
61
helper/da/client/client.go
Normal file
@ -0,0 +1,61 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-evmos/helper/da/light"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type DaLightRpcClient interface {
|
||||
Sample(ctx context.Context, streamId, headerHash []byte, blobIdx, times uint32) (bool, error)
|
||||
Destroy()
|
||||
GetInstanceCount() int
|
||||
}
|
||||
|
||||
type daLightClient struct {
|
||||
maxInstance int
|
||||
pool ConnectionPool
|
||||
}
|
||||
|
||||
func NewDaLightClient(address string, instanceLimit int) DaLightRpcClient {
|
||||
return &daLightClient{
|
||||
maxInstance: instanceLimit,
|
||||
pool: NewConnectionPool(address, instanceLimit, 10*time.Minute),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *daLightClient) Sample(ctx context.Context, streamId, headerHash []byte, blobIdx, times uint32) (bool, error) {
|
||||
connection, err := c.pool.GetConnection()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to connect to da light server")
|
||||
}
|
||||
defer c.pool.ReleaseConnection(connection)
|
||||
|
||||
req := &light.SampleRequest{
|
||||
StreamId: streamId,
|
||||
BatchHeaderHash: headerHash,
|
||||
BlobIndex: blobIdx,
|
||||
Times: times,
|
||||
}
|
||||
client := light.NewLightClient(connection)
|
||||
reply, err := client.Sample(ctx, req)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to sample from da light server")
|
||||
}
|
||||
|
||||
return reply.Success, nil
|
||||
}
|
||||
|
||||
func (c *daLightClient) Destroy() {
|
||||
if c.pool != nil {
|
||||
c.pool.Close()
|
||||
c.pool = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *daLightClient) GetInstanceCount() int {
|
||||
return c.maxInstance
|
||||
}
|
101
helper/da/client/pool.go
Normal file
101
helper/da/client/pool.go
Normal file
@ -0,0 +1,101 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type ConnectionPool interface {
|
||||
GetConnection() (*grpc.ClientConn, error)
|
||||
ReleaseConnection(*grpc.ClientConn)
|
||||
Close()
|
||||
}
|
||||
|
||||
type connectionPoolImpl struct {
|
||||
address string
|
||||
maxSize int
|
||||
timeout time.Duration
|
||||
param grpc.ConnectParams
|
||||
|
||||
mu sync.Mutex
|
||||
pool []*grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewConnectionPool(address string, maxSize int, timeout time.Duration) ConnectionPool {
|
||||
return &connectionPoolImpl{
|
||||
address: address,
|
||||
maxSize: maxSize,
|
||||
timeout: timeout,
|
||||
param: grpc.ConnectParams{
|
||||
Backoff: backoff.Config{
|
||||
BaseDelay: 1.0 * time.Second,
|
||||
Multiplier: 1.5,
|
||||
Jitter: 0.2,
|
||||
MaxDelay: 30 * time.Second,
|
||||
},
|
||||
MinConnectTimeout: 30 * time.Second,
|
||||
},
|
||||
pool: make([]*grpc.ClientConn, 0, maxSize),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *connectionPoolImpl) GetConnection() (*grpc.ClientConn, error) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.pool == nil {
|
||||
return nil, errors.New("connection pool is closed")
|
||||
}
|
||||
|
||||
// Check if there's any available connection in the pool
|
||||
if len(p.pool) > 0 {
|
||||
conn := p.pool[0]
|
||||
p.pool = p.pool[1:]
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// If the pool is empty, create a new connection
|
||||
conn, err := grpc.Dial(p.address, grpc.WithBlock(),
|
||||
grpc.WithConnectParams(p.param),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (p *connectionPoolImpl) ReleaseConnection(conn *grpc.ClientConn) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.pool != nil {
|
||||
// If the pool is full, close the connection
|
||||
if len(p.pool) >= p.maxSize {
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// Add the connection back to the pool
|
||||
p.pool = append(p.pool, conn)
|
||||
} else {
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (p *connectionPoolImpl) Close() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.pool != nil {
|
||||
for _, conn := range p.pool {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
p.pool = nil
|
||||
}
|
||||
}
|
26
helper/da/go.mod
Normal file
26
helper/da/go.mod
Normal file
@ -0,0 +1,26 @@
|
||||
module github.com/0glabs/0g-evmos/helper/da
|
||||
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/lesismal/nbio v1.5.4
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rs/zerolog v1.32.0
|
||||
google.golang.org/grpc v1.63.2
|
||||
google.golang.org/protobuf v1.33.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/lesismal/llib v1.1.13 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
|
||||
)
|
60
helper/da/go.sum
Normal file
60
helper/da/go.sum
Normal file
@ -0,0 +1,60 @@
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/lesismal/llib v1.1.13 h1:+w1+t0PykXpj2dXQck0+p6vdC9/mnbEXHgUy/HXDGfE=
|
||||
github.com/lesismal/llib v1.1.13/go.mod h1:70tFXXe7P1FZ02AU9l8LgSOK7d7sRrpnkUr3rd3gKSg=
|
||||
github.com/lesismal/nbio v1.5.4 h1:fZ6FOVZOBm7nFuudYsq+WyHJuM2UNuPdlvF/1LVa6lo=
|
||||
github.com/lesismal/nbio v1.5.4/go.mod h1:mvfYBAA1jmrafXf2XvkM28jWkMTfA5jGks+HKDBMmOc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
|
||||
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
golang.org/x/crypto v0.0.0-20210513122933-cd7d49e622d5/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
|
||||
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
|
||||
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
397
helper/da/light/light.pb.go
Normal file
397
helper/da/light/light.pb.go
Normal file
@ -0,0 +1,397 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc v4.25.3
|
||||
// source: light/light.proto
|
||||
|
||||
package light
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// SampleRequest contains the blob to sample (by batch and blob index) and required sample times
|
||||
type SampleRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
StreamId []byte `protobuf:"bytes,1,opt,name=stream_id,json=streamId,proto3" json:"stream_id,omitempty"`
|
||||
BatchHeaderHash []byte `protobuf:"bytes,2,opt,name=batch_header_hash,json=batchHeaderHash,proto3" json:"batch_header_hash,omitempty"`
|
||||
BlobIndex uint32 `protobuf:"varint,3,opt,name=blob_index,json=blobIndex,proto3" json:"blob_index,omitempty"`
|
||||
Times uint32 `protobuf:"varint,4,opt,name=times,proto3" json:"times,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SampleRequest) Reset() {
|
||||
*x = SampleRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_light_light_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SampleRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SampleRequest) ProtoMessage() {}
|
||||
|
||||
func (x *SampleRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_light_light_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SampleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*SampleRequest) Descriptor() ([]byte, []int) {
|
||||
return file_light_light_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *SampleRequest) GetStreamId() []byte {
|
||||
if x != nil {
|
||||
return x.StreamId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SampleRequest) GetBatchHeaderHash() []byte {
|
||||
if x != nil {
|
||||
return x.BatchHeaderHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SampleRequest) GetBlobIndex() uint32 {
|
||||
if x != nil {
|
||||
return x.BlobIndex
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SampleRequest) GetTimes() uint32 {
|
||||
if x != nil {
|
||||
return x.Times
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// SampleReply contains the sample result
|
||||
type SampleReply struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SampleReply) Reset() {
|
||||
*x = SampleReply{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_light_light_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *SampleReply) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SampleReply) ProtoMessage() {}
|
||||
|
||||
func (x *SampleReply) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_light_light_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SampleReply.ProtoReflect.Descriptor instead.
|
||||
func (*SampleReply) Descriptor() ([]byte, []int) {
|
||||
return file_light_light_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *SampleReply) GetSuccess() bool {
|
||||
if x != nil {
|
||||
return x.Success
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type RetrieveRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
BatchHeaderHash []byte `protobuf:"bytes,1,opt,name=batch_header_hash,json=batchHeaderHash,proto3" json:"batch_header_hash,omitempty"`
|
||||
BlobIndex uint32 `protobuf:"varint,2,opt,name=blob_index,json=blobIndex,proto3" json:"blob_index,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RetrieveRequest) Reset() {
|
||||
*x = RetrieveRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_light_light_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RetrieveRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RetrieveRequest) ProtoMessage() {}
|
||||
|
||||
func (x *RetrieveRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_light_light_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use RetrieveRequest.ProtoReflect.Descriptor instead.
|
||||
func (*RetrieveRequest) Descriptor() ([]byte, []int) {
|
||||
return file_light_light_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *RetrieveRequest) GetBatchHeaderHash() []byte {
|
||||
if x != nil {
|
||||
return x.BatchHeaderHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *RetrieveRequest) GetBlobIndex() uint32 {
|
||||
if x != nil {
|
||||
return x.BlobIndex
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type RetrieveReply struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Status bool `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
|
||||
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RetrieveReply) Reset() {
|
||||
*x = RetrieveReply{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_light_light_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RetrieveReply) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RetrieveReply) ProtoMessage() {}
|
||||
|
||||
func (x *RetrieveReply) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_light_light_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use RetrieveReply.ProtoReflect.Descriptor instead.
|
||||
func (*RetrieveReply) Descriptor() ([]byte, []int) {
|
||||
return file_light_light_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *RetrieveReply) GetStatus() bool {
|
||||
if x != nil {
|
||||
return x.Status
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *RetrieveReply) GetData() []byte {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_light_light_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_light_light_proto_rawDesc = []byte{
|
||||
0x0a, 0x11, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x05, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x22, 0x8d, 0x01, 0x0a, 0x0d, 0x53,
|
||||
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09,
|
||||
0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52,
|
||||
0x08, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x11, 0x62, 0x61, 0x74,
|
||||
0x63, 0x68, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0f, 0x62, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65,
|
||||
0x72, 0x48, 0x61, 0x73, 0x68, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x62, 0x5f, 0x69, 0x6e,
|
||||
0x64, 0x65, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x62, 0x49,
|
||||
0x6e, 0x64, 0x65, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x0d, 0x52, 0x05, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x22, 0x27, 0x0a, 0x0b, 0x53, 0x61,
|
||||
0x6d, 0x70, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63,
|
||||
0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63,
|
||||
0x65, 0x73, 0x73, 0x22, 0x5c, 0x0a, 0x0f, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x11, 0x62, 0x61, 0x74, 0x63, 0x68, 0x5f,
|
||||
0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x0c, 0x52, 0x0f, 0x62, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x48, 0x61,
|
||||
0x73, 0x68, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x62, 0x5f, 0x69, 0x6e, 0x64, 0x65, 0x78,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x62, 0x49, 0x6e, 0x64, 0x65,
|
||||
0x78, 0x22, 0x3b, 0x0a, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x52, 0x65, 0x70,
|
||||
0x6c, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x08, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61,
|
||||
0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0x79,
|
||||
0x0a, 0x05, 0x4c, 0x69, 0x67, 0x68, 0x74, 0x12, 0x34, 0x0a, 0x06, 0x53, 0x61, 0x6d, 0x70, 0x6c,
|
||||
0x65, 0x12, 0x14, 0x2e, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e,
|
||||
0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x3a, 0x0a,
|
||||
0x08, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x12, 0x16, 0x2e, 0x6c, 0x69, 0x67, 0x68,
|
||||
0x74, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x14, 0x2e, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65,
|
||||
0x76, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74,
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x30, 0x67, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x30,
|
||||
0x67, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x2d, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x2f, 0x72, 0x75, 0x6e,
|
||||
0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_light_light_proto_rawDescOnce sync.Once
|
||||
file_light_light_proto_rawDescData = file_light_light_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_light_light_proto_rawDescGZIP() []byte {
|
||||
file_light_light_proto_rawDescOnce.Do(func() {
|
||||
file_light_light_proto_rawDescData = protoimpl.X.CompressGZIP(file_light_light_proto_rawDescData)
|
||||
})
|
||||
return file_light_light_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_light_light_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_light_light_proto_goTypes = []interface{}{
|
||||
(*SampleRequest)(nil), // 0: light.SampleRequest
|
||||
(*SampleReply)(nil), // 1: light.SampleReply
|
||||
(*RetrieveRequest)(nil), // 2: light.RetrieveRequest
|
||||
(*RetrieveReply)(nil), // 3: light.RetrieveReply
|
||||
}
|
||||
var file_light_light_proto_depIdxs = []int32{
|
||||
0, // 0: light.Light.Sample:input_type -> light.SampleRequest
|
||||
2, // 1: light.Light.Retrieve:input_type -> light.RetrieveRequest
|
||||
1, // 2: light.Light.Sample:output_type -> light.SampleReply
|
||||
3, // 3: light.Light.Retrieve:output_type -> light.RetrieveReply
|
||||
2, // [2:4] is the sub-list for method output_type
|
||||
0, // [0:2] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_light_light_proto_init() }
|
||||
func file_light_light_proto_init() {
|
||||
if File_light_light_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_light_light_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SampleRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_light_light_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SampleReply); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_light_light_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RetrieveRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_light_light_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RetrieveReply); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_light_light_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 4,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_light_light_proto_goTypes,
|
||||
DependencyIndexes: file_light_light_proto_depIdxs,
|
||||
MessageInfos: file_light_light_proto_msgTypes,
|
||||
}.Build()
|
||||
File_light_light_proto = out.File
|
||||
file_light_light_proto_rawDesc = nil
|
||||
file_light_light_proto_goTypes = nil
|
||||
file_light_light_proto_depIdxs = nil
|
||||
}
|
141
helper/da/light/light_grpc.pb.go
Normal file
141
helper/da/light/light_grpc.pb.go
Normal file
@ -0,0 +1,141 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v4.25.3
|
||||
// source: light/light.proto
|
||||
|
||||
package light
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// LightClient is the client API for Light service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type LightClient interface {
|
||||
Sample(ctx context.Context, in *SampleRequest, opts ...grpc.CallOption) (*SampleReply, error)
|
||||
Retrieve(ctx context.Context, in *RetrieveRequest, opts ...grpc.CallOption) (*RetrieveReply, error)
|
||||
}
|
||||
|
||||
type lightClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewLightClient(cc grpc.ClientConnInterface) LightClient {
|
||||
return &lightClient{cc}
|
||||
}
|
||||
|
||||
func (c *lightClient) Sample(ctx context.Context, in *SampleRequest, opts ...grpc.CallOption) (*SampleReply, error) {
|
||||
out := new(SampleReply)
|
||||
err := c.cc.Invoke(ctx, "/light.Light/Sample", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *lightClient) Retrieve(ctx context.Context, in *RetrieveRequest, opts ...grpc.CallOption) (*RetrieveReply, error) {
|
||||
out := new(RetrieveReply)
|
||||
err := c.cc.Invoke(ctx, "/light.Light/Retrieve", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// LightServer is the server API for Light service.
|
||||
// All implementations must embed UnimplementedLightServer
|
||||
// for forward compatibility
|
||||
type LightServer interface {
|
||||
Sample(context.Context, *SampleRequest) (*SampleReply, error)
|
||||
Retrieve(context.Context, *RetrieveRequest) (*RetrieveReply, error)
|
||||
mustEmbedUnimplementedLightServer()
|
||||
}
|
||||
|
||||
// UnimplementedLightServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedLightServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedLightServer) Sample(context.Context, *SampleRequest) (*SampleReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Sample not implemented")
|
||||
}
|
||||
func (UnimplementedLightServer) Retrieve(context.Context, *RetrieveRequest) (*RetrieveReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Retrieve not implemented")
|
||||
}
|
||||
func (UnimplementedLightServer) mustEmbedUnimplementedLightServer() {}
|
||||
|
||||
// UnsafeLightServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to LightServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeLightServer interface {
|
||||
mustEmbedUnimplementedLightServer()
|
||||
}
|
||||
|
||||
func RegisterLightServer(s grpc.ServiceRegistrar, srv LightServer) {
|
||||
s.RegisterService(&Light_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Light_Sample_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SampleRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LightServer).Sample(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/light.Light/Sample",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LightServer).Sample(ctx, req.(*SampleRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Light_Retrieve_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RetrieveRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LightServer).Retrieve(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/light.Light/Retrieve",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LightServer).Retrieve(ctx, req.(*RetrieveRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Light_ServiceDesc is the grpc.ServiceDesc for Light service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Light_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "light.Light",
|
||||
HandlerType: (*LightServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Sample",
|
||||
Handler: _Light_Sample_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Retrieve",
|
||||
Handler: _Light_Retrieve_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "light/light.proto",
|
||||
}
|
89
helper/da/main.go
Normal file
89
helper/da/main.go
Normal file
@ -0,0 +1,89 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-evmos/helper/da/service"
|
||||
"github.com/0glabs/0g-evmos/helper/da/types"
|
||||
|
||||
"github.com/lesismal/nbio/nbhttp"
|
||||
"github.com/lesismal/nbio/nbhttp/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
subscribeMsg = "{\"jsonrpc\":\"2.0\",\"method\":\"subscribe\",\"id\":1,\"params\":{\"query\":\"tm.event='Tx'\"}}"
|
||||
)
|
||||
|
||||
var (
|
||||
rpcAddress = flag.String("rpc-address", "34.214.2.28:32001", "address of da-light rpc server")
|
||||
wsAddress = flag.String("ws-address", "127.0.0.1:26657", "address of emvos ws server")
|
||||
relativePath = flag.String("relative-path", "", "relative path of evmosd")
|
||||
account = flag.String("account", "", "account to run evmosd cli")
|
||||
keyring = flag.String("keyring", "", "keyring to run evmosd cli")
|
||||
homePath = flag.String("home", "", "home path of evmosd node")
|
||||
)
|
||||
|
||||
func newUpgrader() *websocket.Upgrader {
|
||||
u := websocket.NewUpgrader()
|
||||
u.OnMessage(func(c *websocket.Conn, messageType websocket.MessageType, data []byte) {
|
||||
log.Println("onEcho:", string(data))
|
||||
ctx := context.WithValue(context.Background(), types.DA_RPC_ADDRESS, *rpcAddress)
|
||||
ctx = context.WithValue(ctx, types.NODE_CLI_RELATIVE_PATH, *relativePath)
|
||||
ctx = context.WithValue(ctx, types.NODE_CLI_EXEC_ACCOUNT, *account)
|
||||
ctx = context.WithValue(ctx, types.NODE_CLI_EXEC_KEYRING, *keyring)
|
||||
ctx = context.WithValue(ctx, types.NODE_HOME_PATH, *homePath)
|
||||
go func() { service.OnMessage(ctx, c, messageType, data) }()
|
||||
})
|
||||
|
||||
u.OnClose(func(c *websocket.Conn, err error) {
|
||||
fmt.Println("OnClose:", c.RemoteAddr().String(), err)
|
||||
service.OnClose()
|
||||
})
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
engine := nbhttp.NewEngine(nbhttp.Config{})
|
||||
err := engine.Start()
|
||||
if err != nil {
|
||||
fmt.Printf("nbio.Start failed: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
u := url.URL{Scheme: "ws", Host: *wsAddress, Path: "/websocket"}
|
||||
dialer := &websocket.Dialer{
|
||||
Engine: engine,
|
||||
Upgrader: newUpgrader(),
|
||||
DialTimeout: time.Second * 3,
|
||||
}
|
||||
c, res, err := dialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
if res != nil && res.Body != nil {
|
||||
bReason, _ := io.ReadAll(res.Body)
|
||||
fmt.Printf("dial failed: %v, reason: %v\n", err, string(bReason))
|
||||
} else {
|
||||
fmt.Printf("dial failed: %v\n", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
c.WriteMessage(websocket.TextMessage, []byte(subscribeMsg))
|
||||
}()
|
||||
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt, os.Interrupt)
|
||||
<-interrupt
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
engine.Shutdown(ctx)
|
||||
}
|
33
helper/da/proto/light.proto
Normal file
33
helper/da/proto/light.proto
Normal file
@ -0,0 +1,33 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package light;
|
||||
|
||||
option go_package = "proto/light";
|
||||
|
||||
service Light {
|
||||
rpc Sample(SampleRequest) returns (SampleReply) {}
|
||||
rpc Retrieve(RetrieveRequest) returns (RetrieveReply) {}
|
||||
}
|
||||
|
||||
// SampleRequest contains the blob to sample (by batch and blob index) and required sample times
|
||||
message SampleRequest {
|
||||
bytes stream_id = 1;
|
||||
bytes batch_header_hash = 2;
|
||||
uint32 blob_index = 3;
|
||||
uint32 times = 4;
|
||||
}
|
||||
|
||||
// SampleReply contains the sample result
|
||||
message SampleReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message RetrieveRequest {
|
||||
bytes batch_header_hash = 1;
|
||||
uint32 blob_index = 2;
|
||||
}
|
||||
|
||||
message RetrieveReply {
|
||||
bool status = 1;
|
||||
bytes data = 2;
|
||||
}
|
186
helper/da/service/handler.go
Normal file
186
helper/da/service/handler.go
Normal file
@ -0,0 +1,186 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/0glabs/0g-evmos/helper/da/client"
|
||||
"github.com/0glabs/0g-evmos/helper/da/types"
|
||||
"github.com/0glabs/0g-evmos/helper/da/utils/sizedw8grp"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/lesismal/nbio/nbhttp/websocket"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultClientInstance = 10
|
||||
)
|
||||
|
||||
var rpcClient client.DaLightRpcClient
|
||||
|
||||
func OnMessage(ctx context.Context, c *websocket.Conn, messageType websocket.MessageType, data []byte) {
|
||||
if messageType == websocket.TextMessage {
|
||||
rawMsg := unwrapJsonRpc(data)
|
||||
if verifyQuery(rawMsg) {
|
||||
eventStr := jsoniter.Get(rawMsg, "events").ToString()
|
||||
events := map[string][]string{}
|
||||
if err := jsoniter.UnmarshalFromString(eventStr, &events); err == nil {
|
||||
dasRequestMap := make(map[string]string, 4)
|
||||
for key, val := range events {
|
||||
if strings.HasPrefix(key, "das_request.") {
|
||||
dasRequestMap[strings.ReplaceAll(key, "das_request.", "")] = val[0]
|
||||
}
|
||||
}
|
||||
if len(dasRequestMap) == 4 {
|
||||
rid, _ := strconv.ParseUint(dasRequestMap["request_id"], 10, 64)
|
||||
numBlobs, _ := strconv.ParseUint(dasRequestMap["num_blobs"], 10, 64)
|
||||
req := types.DASRequest{
|
||||
RequestId: rid,
|
||||
StreamId: dasRequestMap["stream_id"],
|
||||
BatchHeaderHash: dasRequestMap["batch_header_hash"],
|
||||
NumBlobs: numBlobs,
|
||||
}
|
||||
err := handleDasRequest(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
log.Err(err).Msgf("failed to handle das request: %v, %v", req, err)
|
||||
} else {
|
||||
log.Info().Msgf("successfully handled das request: %v", req)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: handle other message
|
||||
}
|
||||
}
|
||||
|
||||
func OnClose() {
|
||||
if rpcClient != nil {
|
||||
rpcClient.Destroy()
|
||||
rpcClient = nil
|
||||
}
|
||||
}
|
||||
|
||||
func unwrapJsonRpc(data []byte) []byte {
|
||||
result := jsoniter.Get(data, "result")
|
||||
if 0 < len(result.Keys()) {
|
||||
return []byte(result.ToString())
|
||||
}
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
func verifyQuery(data []byte) bool {
|
||||
if len(data) > 0 {
|
||||
return jsoniter.Get(data, "query").ToString() == "tm.event='Tx'"
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func handleDasRequest(ctx context.Context, request types.DASRequest) error {
|
||||
if rpcClient == nil {
|
||||
addrVal := ctx.Value(types.DA_RPC_ADDRESS)
|
||||
if addrVal == nil {
|
||||
return errors.New("da light service address not found in context")
|
||||
}
|
||||
|
||||
limit := ctx.Value(types.INSTANCE_LIMIT)
|
||||
if limit == nil {
|
||||
limit = defaultClientInstance
|
||||
}
|
||||
|
||||
rpcClient = client.NewDaLightClient(addrVal.(string), limit.(int))
|
||||
}
|
||||
|
||||
streamID, err := hex.DecodeString(request.StreamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
batchHeaderHash, err := hex.DecodeString(request.BatchHeaderHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result := make(chan bool, request.NumBlobs)
|
||||
taskCnt := min(rpcClient.GetInstanceCount(), int(request.NumBlobs))
|
||||
wg := sizedw8grp.New(taskCnt)
|
||||
|
||||
for i := uint64(0); i < request.NumBlobs; i++ {
|
||||
wg.Add()
|
||||
go func(idx uint64) {
|
||||
defer wg.Done()
|
||||
ret, err := rpcClient.Sample(ctx, streamID, batchHeaderHash, uint32(idx), 1)
|
||||
if err != nil {
|
||||
log.Err(err).Msgf("failed to sample data availability with blob index %d", idx)
|
||||
result <- false
|
||||
} else {
|
||||
log.Info().Msgf("sample result for blob index %d: %v", idx, ret)
|
||||
result <- ret
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
close(result)
|
||||
|
||||
finalResult := true
|
||||
for val := range result {
|
||||
if !val {
|
||||
finalResult = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return runEvmosdCliReportDasResult(ctx, request.RequestId, finalResult)
|
||||
}
|
||||
|
||||
func runEvmosdCliReportDasResult(ctx context.Context, requestId uint64, result bool) error {
|
||||
relativePath := ctx.Value(types.NODE_CLI_RELATIVE_PATH)
|
||||
if relativePath == nil {
|
||||
return errors.New("relativePath not found in context")
|
||||
}
|
||||
|
||||
account := ctx.Value(types.NODE_CLI_EXEC_ACCOUNT)
|
||||
if account == nil {
|
||||
return errors.New("account not found in context")
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"tx",
|
||||
"das",
|
||||
"report-das-result",
|
||||
strconv.FormatUint(requestId, 10),
|
||||
strconv.FormatBool(result),
|
||||
"--from", account.(string),
|
||||
"--gas-prices", "767812500aevmos", // TODO: use args to set gas prices
|
||||
}
|
||||
|
||||
homePath := ctx.Value(types.NODE_HOME_PATH)
|
||||
if homePath != nil {
|
||||
args = append(args, "--home", homePath.(string))
|
||||
}
|
||||
|
||||
keyring := ctx.Value(types.NODE_CLI_EXEC_KEYRING)
|
||||
if keyring != nil {
|
||||
args = append(args, "--keyring-backend", keyring.(string))
|
||||
}
|
||||
|
||||
cmdStr := relativePath.(string) + "evmosd"
|
||||
cmd := exec.Command(cmdStr, append(args, "-y")...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
}
|
8
helper/da/types/dasreq.go
Normal file
8
helper/da/types/dasreq.go
Normal file
@ -0,0 +1,8 @@
|
||||
package types
|
||||
|
||||
type DASRequest struct {
|
||||
RequestId uint64 `json:"request_id"`
|
||||
StreamId string `json:"stream_id"`
|
||||
BatchHeaderHash string `json:"batch_header_hash"`
|
||||
NumBlobs uint64 `json:"num_blobs"`
|
||||
}
|
10
helper/da/types/keys.go
Normal file
10
helper/da/types/keys.go
Normal file
@ -0,0 +1,10 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
DA_RPC_ADDRESS = "rpc_address"
|
||||
INSTANCE_LIMIT = "instance_limit"
|
||||
NODE_CLI_RELATIVE_PATH = "relative_path"
|
||||
NODE_CLI_EXEC_ACCOUNT = "node_exec_account"
|
||||
NODE_CLI_EXEC_KEYRING = "node_exec_keyring"
|
||||
NODE_HOME_PATH = "home_path"
|
||||
)
|
51
helper/da/utils/sizedw8grp/sizedw8grp.go
Normal file
51
helper/da/utils/sizedw8grp/sizedw8grp.go
Normal file
@ -0,0 +1,51 @@
|
||||
package sizedw8grp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type SizedWaitGroup struct {
|
||||
Size int
|
||||
|
||||
current chan struct{}
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func New(limit int) SizedWaitGroup {
|
||||
size := math.MaxInt32
|
||||
if limit > 0 {
|
||||
size = limit
|
||||
}
|
||||
return SizedWaitGroup{
|
||||
Size: size,
|
||||
|
||||
current: make(chan struct{}, size),
|
||||
wg: sync.WaitGroup{},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SizedWaitGroup) Add() {
|
||||
_ = s.AddWithContext(context.Background())
|
||||
}
|
||||
|
||||
func (s *SizedWaitGroup) AddWithContext(ctx context.Context) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case s.current <- struct{}{}:
|
||||
break
|
||||
}
|
||||
s.wg.Add(1)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SizedWaitGroup) Done() {
|
||||
<-s.current
|
||||
s.wg.Done()
|
||||
}
|
||||
|
||||
func (s *SizedWaitGroup) Wait() {
|
||||
s.wg.Wait()
|
||||
}
|
@ -20,11 +20,11 @@ relayerMnemonic="never reject sniff east arctic funny twin feed upper series sta
|
||||
# 0xa2F728F997f62F47D4262a70947F6c36885dF9fa
|
||||
# kava15tmj37vh7ch504px9fcfglmvx6y9m70646ev8t
|
||||
|
||||
DATA=~/.kava
|
||||
DATA=~/.0gchain
|
||||
# remove any old state and config
|
||||
rm -rf $DATA
|
||||
|
||||
BINARY=kava
|
||||
BINARY=0gchaind
|
||||
|
||||
# Create new data directory, overwriting any that alread existed
|
||||
chainID="zgchain_8888-1"
|
||||
@ -49,37 +49,37 @@ $BINARY config keyring-backend test
|
||||
# Create validator keys and add account to genesis
|
||||
validatorKeyName="validator"
|
||||
printf "$validatorMnemonic\n" | $BINARY keys add $validatorKeyName --recover
|
||||
$BINARY add-genesis-account $validatorKeyName 2000000000ukava
|
||||
$BINARY add-genesis-account $validatorKeyName 2000000000000000000000neuron
|
||||
|
||||
# Create faucet keys and add account to genesis
|
||||
faucetKeyName="faucet"
|
||||
printf "$faucetMnemonic\n" | $BINARY keys add $faucetKeyName --recover
|
||||
$BINARY add-genesis-account $faucetKeyName 1000000000ukava
|
||||
$BINARY add-genesis-account $faucetKeyName 1000000000000000000000neuron
|
||||
|
||||
evmFaucetKeyName="evm-faucet"
|
||||
printf "$evmFaucetMnemonic\n" | $BINARY keys add $evmFaucetKeyName --eth --recover
|
||||
$BINARY add-genesis-account $evmFaucetKeyName 1000000000ukava
|
||||
$BINARY add-genesis-account $evmFaucetKeyName 1000000000000000000000neuron
|
||||
|
||||
userKeyName="user"
|
||||
printf "$userMnemonic\n" | $BINARY keys add $userKeyName --eth --recover
|
||||
$BINARY add-genesis-account $userKeyName 1000000000ukava,1000000000usdx
|
||||
$BINARY add-genesis-account $userKeyName 1000000000000000000000neuron,1000000000usdx
|
||||
|
||||
relayerKeyName="relayer"
|
||||
printf "$relayerMnemonic\n" | $BINARY keys add $relayerKeyName --eth --recover
|
||||
$BINARY add-genesis-account $relayerKeyName 1000000000ukava
|
||||
$BINARY add-genesis-account $relayerKeyName 1000000000000000000000neuron
|
||||
|
||||
storageContractAcc="kava1l0j9dqdvd3fatfqywhm4y6avrln4jracrfy9hk"
|
||||
$BINARY add-genesis-account $storageContractAcc 1000000000ukava
|
||||
storageContractAcc="0g1vsjpjgw8p5f4x0nwp8ernl9lkszewcqqss7r5d"
|
||||
$BINARY add-genesis-account $storageContractAcc 1000000000000000000000neuron
|
||||
|
||||
# Create a delegation tx for the validator and add to genesis
|
||||
$BINARY gentx $validatorKeyName 1000000000ukava --keyring-backend test --chain-id $chainID
|
||||
$BINARY gentx $validatorKeyName 1000000000000000000000neuron --keyring-backend test --chain-id $chainID
|
||||
$BINARY collect-gentxs
|
||||
|
||||
# Replace stake with ukava
|
||||
sed -in-place='' 's/stake/ukava/g' $DATA/config/genesis.json
|
||||
sed -in-place='' 's/stake/neuron/g' $DATA/config/genesis.json
|
||||
|
||||
# Replace the default evm denom of aphoton with ukava
|
||||
sed -in-place='' 's/aphoton/akava/g' $DATA/config/genesis.json
|
||||
# Replace the default evm denom of aphoton with neuron
|
||||
sed -in-place='' 's/aphoton/neuron/g' $DATA/config/genesis.json
|
||||
|
||||
GENESIS=$DATA/config/genesis.json
|
||||
TMP_GENESIS=$DATA/config/tmp_genesis.json
|
||||
@ -101,17 +101,17 @@ cat $GENESIS | jq '.app_state.evm.params.chain_config.shanghai_block = null' >$T
|
||||
cat $GENESIS | jq '.app_state.evm.params.chain_config.cancun_block = null' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
|
||||
|
||||
# Add earn vault
|
||||
cat $GENESIS | jq '.app_state.earn.params.allowed_vaults = [
|
||||
{
|
||||
denom: "usdx",
|
||||
strategies: ["STRATEGY_TYPE_HARD"],
|
||||
},
|
||||
{
|
||||
denom: "bkava",
|
||||
strategies: ["STRATEGY_TYPE_SAVINGS"],
|
||||
}]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
|
||||
# cat $GENESIS | jq '.app_state.earn.params.allowed_vaults = [
|
||||
# {
|
||||
# denom: "usdx",
|
||||
# strategies: ["STRATEGY_TYPE_HARD"],
|
||||
# },
|
||||
# {
|
||||
# denom: "bkava",
|
||||
# strategies: ["STRATEGY_TYPE_SAVINGS"],
|
||||
# }]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
|
||||
|
||||
cat $GENESIS | jq '.app_state.savings.params.supported_denoms = ["bkava-kavavaloper1ffv7nhd3z6sych2qpqkk03ec6hzkmufyz4scd0"]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
|
||||
# cat $GENESIS | jq '.app_state.savings.params.supported_denoms = ["bkava-kavavaloper1ffv7nhd3z6sych2qpqkk03ec6hzkmufyz4scd0"]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
|
||||
|
||||
|
||||
$BINARY config broadcast-mode sync
|
||||
|
@ -11,8 +11,8 @@ There are two types of migration:
|
||||
Genesis migration starts a whole new blockchain (with new chain-id) for the new software version.
|
||||
In-Place upgrade keeps the blockchain (and chain-id) the same for the new software version.
|
||||
|
||||
We only support migrations between mainnet kava releases.
|
||||
We only support migrations from the previous mainnet kava version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations between mainnet 0g-chain releases.
|
||||
We only support migrations from the previous mainnet 0g-chain version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations from old to new versions, not the other way around.
|
||||
|
||||
Genesis Migration
|
||||
@ -22,7 +22,7 @@ The process is:
|
||||
- marshal it to json (using current codec)
|
||||
|
||||
On each release we can delete the previous releases migration and old GenesisState type.
|
||||
eg kava-3 migrates `auth.GenesisState` from kava-2 to `auth.GenesisState` from kava-3,
|
||||
but for kava-4 we don't need to keep around kava-2's `auth.GenesisState` type.
|
||||
eg 0g-chain-3 migrates `auth.GenesisState` from 0g-chain-2 to `auth.GenesisState` from 0g-chain-3,
|
||||
but for 0g-chain-4 we don't need to keep around 0g-chain-2's `auth.GenesisState` type.
|
||||
*/
|
||||
package migrate
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(4e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(4e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -159,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
expectedPeriods := []vestingtypes.Period{
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
||||
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -198,35 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))))
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))))
|
||||
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
all:
|
||||
docker build --tag kava/kavanode kavanode
|
||||
docker build --tag 0glabs/0g-chain-node 0g-chain-node
|
||||
|
||||
.PHONY: all
|
||||
|
25
proto/crypto/vrf/keys.proto
Normal file
25
proto/crypto/vrf/keys.proto
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright Tharsis Labs Ltd.(Evmos)
|
||||
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)
|
||||
syntax = "proto3";
|
||||
package crypto.vrf;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option go_package = "github.com/0glabs/0g-chain/crypto/vrf";
|
||||
|
||||
// PubKey defines a type alias for an vrf.PublicKey that implements
|
||||
// Vrf's PubKey interface. It represents the 32-byte compressed public
|
||||
// key format.
|
||||
message PubKey {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
|
||||
// key is the public key in byte form
|
||||
bytes key = 1;
|
||||
}
|
||||
|
||||
// PrivKey defines a type alias for an vrf.PrivateKey that implements
|
||||
// Vrf's PrivateKey interface.
|
||||
message PrivKey {
|
||||
// key is the private key in byte form
|
||||
bytes key = 1;
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.auction.v1beta1;
|
||||
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/auction/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// BaseAuction defines common attributes of all auctions
|
||||
message BaseAuction {
|
||||
option (cosmos_proto.implements_interface) = "Auction";
|
||||
|
||||
uint64 id = 1 [(gogoproto.customname) = "ID"];
|
||||
|
||||
string initiator = 2;
|
||||
|
||||
cosmos.base.v1beta1.Coin lot = 3 [(gogoproto.nullable) = false];
|
||||
|
||||
bytes bidder = 4 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
|
||||
];
|
||||
|
||||
cosmos.base.v1beta1.Coin bid = 5 [(gogoproto.nullable) = false];
|
||||
|
||||
bool has_received_bids = 6;
|
||||
|
||||
google.protobuf.Timestamp end_time = 7 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdtime) = true
|
||||
];
|
||||
|
||||
google.protobuf.Timestamp max_end_time = 8 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdtime) = true
|
||||
];
|
||||
}
|
||||
|
||||
// SurplusAuction is a forward auction that burns what it receives from bids.
|
||||
// It is normally used to sell off excess pegged asset acquired by the CDP system.
|
||||
message SurplusAuction {
|
||||
option (cosmos_proto.implements_interface) = "Auction";
|
||||
|
||||
BaseAuction base_auction = 1 [
|
||||
(gogoproto.embed) = true,
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// DebtAuction is a reverse auction that mints what it pays out.
|
||||
// It is normally used to acquire pegged asset to cover the CDP system's debts that were not covered by selling
|
||||
// collateral.
|
||||
message DebtAuction {
|
||||
option (cosmos_proto.implements_interface) = "Auction";
|
||||
|
||||
BaseAuction base_auction = 1 [
|
||||
(gogoproto.embed) = true,
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
cosmos.base.v1beta1.Coin corresponding_debt = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// CollateralAuction is a two phase auction.
|
||||
// Initially, in forward auction phase, bids can be placed up to a max bid.
|
||||
// Then it switches to a reverse auction phase, where the initial amount up for auction is bid down.
|
||||
// Unsold Lot is sent to LotReturns, being divided among the addresses by weight.
|
||||
// Collateral auctions are normally used to sell off collateral seized from CDPs.
|
||||
message CollateralAuction {
|
||||
option (cosmos_proto.implements_interface) = "Auction";
|
||||
|
||||
BaseAuction base_auction = 1 [
|
||||
(gogoproto.embed) = true,
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
cosmos.base.v1beta1.Coin corresponding_debt = 2 [(gogoproto.nullable) = false];
|
||||
|
||||
cosmos.base.v1beta1.Coin max_bid = 3 [(gogoproto.nullable) = false];
|
||||
|
||||
WeightedAddresses lot_returns = 4 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// WeightedAddresses is a type for storing some addresses and associated weights.
|
||||
message WeightedAddresses {
|
||||
repeated bytes addresses = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
|
||||
];
|
||||
|
||||
repeated bytes weights = 2 [
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.auction.v1beta1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/auction/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// GenesisState defines the auction module's genesis state.
|
||||
message GenesisState {
|
||||
uint64 next_auction_id = 1;
|
||||
|
||||
Params params = 2 [(gogoproto.nullable) = false];
|
||||
|
||||
// Genesis auctions
|
||||
repeated google.protobuf.Any auctions = 3 [(cosmos_proto.accepts_interface) = "GenesisAuction"];
|
||||
}
|
||||
|
||||
// Params defines the parameters for the issuance module.
|
||||
message Params {
|
||||
reserved 2;
|
||||
reserved "bid_duration";
|
||||
|
||||
google.protobuf.Duration max_auction_duration = 1 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
|
||||
google.protobuf.Duration forward_bid_duration = 6 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
google.protobuf.Duration reverse_bid_duration = 7 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
|
||||
bytes increment_surplus = 3 [
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
bytes increment_debt = 4 [
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
bytes increment_collateral = 5 [
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.auction.v1beta1;
|
||||
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
import "kava/auction/v1beta1/genesis.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/auction/types";
|
||||
|
||||
// Query defines the gRPC querier service for auction module
|
||||
service Query {
|
||||
// Params queries all parameters of the auction module.
|
||||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
|
||||
option (google.api.http).get = "/kava/auction/v1beta1/params";
|
||||
}
|
||||
|
||||
// Auction queries an individual Auction by auction ID
|
||||
rpc Auction(QueryAuctionRequest) returns (QueryAuctionResponse) {
|
||||
option (google.api.http).get = "/kava/auction/v1beta1/auctions/{auction_id}";
|
||||
}
|
||||
|
||||
// Auctions queries auctions filtered by asset denom, owner address, phase, and auction type
|
||||
rpc Auctions(QueryAuctionsRequest) returns (QueryAuctionsResponse) {
|
||||
option (google.api.http).get = "/kava/auction/v1beta1/auctions";
|
||||
}
|
||||
|
||||
// NextAuctionID queries the next auction ID
|
||||
rpc NextAuctionID(QueryNextAuctionIDRequest) returns (QueryNextAuctionIDResponse) {
|
||||
option (google.api.http).get = "/kava/auction/v1beta1/next-auction-id";
|
||||
}
|
||||
}
|
||||
|
||||
// QueryParamsRequest defines the request type for querying x/auction parameters.
|
||||
message QueryParamsRequest {}
|
||||
|
||||
// QueryParamsResponse defines the response type for querying x/auction parameters.
|
||||
message QueryParamsResponse {
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryAuctionRequest is the request type for the Query/Auction RPC method.
|
||||
message QueryAuctionRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
uint64 auction_id = 1;
|
||||
}
|
||||
|
||||
// QueryAuctionResponse is the response type for the Query/Auction RPC method.
|
||||
message QueryAuctionResponse {
|
||||
google.protobuf.Any auction = 1;
|
||||
}
|
||||
|
||||
// QueryAuctionsRequest is the request type for the Query/Auctions RPC method.
|
||||
message QueryAuctionsRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string type = 1;
|
||||
string owner = 2;
|
||||
string denom = 3;
|
||||
string phase = 4;
|
||||
|
||||
// pagination defines an optional pagination for the request.
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 5;
|
||||
}
|
||||
|
||||
// QueryAuctionsResponse is the response type for the Query/Auctions RPC method.
|
||||
message QueryAuctionsResponse {
|
||||
repeated google.protobuf.Any auctions = 1;
|
||||
|
||||
// pagination defines the pagination in the response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
}
|
||||
|
||||
// QueryNextAuctionIDRequest defines the request type for querying x/auction next auction ID.
|
||||
message QueryNextAuctionIDRequest {}
|
||||
|
||||
// QueryNextAuctionIDResponse defines the response type for querying x/auction next auction ID.
|
||||
message QueryNextAuctionIDResponse {
|
||||
uint64 id = 1;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.auction.v1beta1;
|
||||
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/auction/types";
|
||||
|
||||
// Msg defines the auction Msg service.
|
||||
service Msg {
|
||||
// PlaceBid message type used by bidders to place bids on auctions
|
||||
rpc PlaceBid(MsgPlaceBid) returns (MsgPlaceBidResponse);
|
||||
}
|
||||
|
||||
// MsgPlaceBid represents a message used by bidders to place bids on auctions
|
||||
message MsgPlaceBid {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
uint64 auction_id = 1;
|
||||
|
||||
string bidder = 2;
|
||||
|
||||
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// MsgPlaceBidResponse defines the Msg/PlaceBid response type.
|
||||
message MsgPlaceBidResponse {}
|
Binary file not shown.
@ -1,160 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.bep3.v1beta1;
|
||||
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/bep3/types";
|
||||
|
||||
// Params defines the parameters for the bep3 module.
|
||||
message Params {
|
||||
// asset_params define the parameters for each bep3 asset
|
||||
repeated AssetParam asset_params = 1 [
|
||||
(gogoproto.castrepeated) = "AssetParams",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// AssetParam defines parameters for each bep3 asset.
|
||||
message AssetParam {
|
||||
// denom represents the denominatin for this asset
|
||||
string denom = 1;
|
||||
// coin_id represents the registered coin type to use (https://github.com/satoshilabs/slips/blob/master/slip-0044.md)
|
||||
int64 coin_id = 2 [(gogoproto.customname) = "CoinID"];
|
||||
// supply_limit defines the maximum supply allowed for the asset - a total or time based rate limit
|
||||
SupplyLimit supply_limit = 3 [(gogoproto.nullable) = false];
|
||||
// active specifies if the asset is live or paused
|
||||
bool active = 4;
|
||||
// deputy_address the kava address of the deputy
|
||||
bytes deputy_address = 5 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
|
||||
];
|
||||
// fixed_fee defines the fee for incoming swaps
|
||||
string fixed_fee = 6 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// min_swap_amount defines the minimum amount able to be swapped in a single message
|
||||
string min_swap_amount = 7 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// max_swap_amount defines the maximum amount able to be swapped in a single message
|
||||
string max_swap_amount = 8 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// min_block_lock defined the minimum blocks to lock
|
||||
uint64 min_block_lock = 9;
|
||||
// min_block_lock defined the maximum blocks to lock
|
||||
uint64 max_block_lock = 10;
|
||||
}
|
||||
|
||||
// SupplyLimit define the absolute and time-based limits for an assets's supply.
|
||||
message SupplyLimit {
|
||||
// limit defines the total supply allowed
|
||||
string limit = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// time_limited enables or disables time based supply limiting
|
||||
bool time_limited = 2;
|
||||
// time_period specifies the duration that time_based_limit is evalulated
|
||||
google.protobuf.Duration time_period = 3 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
// time_based_limit defines the maximum supply that can be swapped within time_period
|
||||
string time_based_limit = 4 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// SwapStatus is the status of an AtomicSwap
|
||||
enum SwapStatus {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
|
||||
// SWAP_STATUS_UNSPECIFIED represents an unspecified status
|
||||
SWAP_STATUS_UNSPECIFIED = 0;
|
||||
// SWAP_STATUS_OPEN represents an open swap
|
||||
SWAP_STATUS_OPEN = 1;
|
||||
// SWAP_STATUS_COMPLETED represents a completed swap
|
||||
SWAP_STATUS_COMPLETED = 2;
|
||||
// SWAP_STATUS_EXPIRED represents an expired swap
|
||||
SWAP_STATUS_EXPIRED = 3;
|
||||
}
|
||||
|
||||
// SwapDirection is the direction of an AtomicSwap
|
||||
enum SwapDirection {
|
||||
option (gogoproto.goproto_enum_prefix) = false;
|
||||
|
||||
// SWAP_DIRECTION_UNSPECIFIED represents unspecified or invalid swap direcation
|
||||
SWAP_DIRECTION_UNSPECIFIED = 0;
|
||||
// SWAP_DIRECTION_INCOMING represents is incoming swap (to the kava chain)
|
||||
SWAP_DIRECTION_INCOMING = 1;
|
||||
// SWAP_DIRECTION_OUTGOING represents an outgoing swap (from the kava chain)
|
||||
SWAP_DIRECTION_OUTGOING = 2;
|
||||
}
|
||||
|
||||
// AtomicSwap defines an atomic swap between chains for the pricefeed module.
|
||||
message AtomicSwap {
|
||||
// amount represents the amount being swapped
|
||||
repeated cosmos.base.v1beta1.Coin amount = 1 [
|
||||
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// random_number_hash represents the hash of the random number
|
||||
bytes random_number_hash = 2 [(gogoproto.casttype) = "github.com/cometbft/cometbft/libs/bytes.HexBytes"];
|
||||
// expire_height represents the height when the swap expires
|
||||
uint64 expire_height = 3;
|
||||
// timestamp represents the timestamp of the swap
|
||||
int64 timestamp = 4;
|
||||
// sender is the kava chain sender of the swap
|
||||
bytes sender = 5 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
|
||||
];
|
||||
// recipient is the kava chain recipient of the swap
|
||||
bytes recipient = 6 [
|
||||
(cosmos_proto.scalar) = "cosmos.AddressBytes",
|
||||
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
|
||||
];
|
||||
// sender_other_chain is the sender on the other chain
|
||||
string sender_other_chain = 7;
|
||||
// recipient_other_chain is the recipient on the other chain
|
||||
string recipient_other_chain = 8;
|
||||
// closed_block is the block when the swap is closed
|
||||
int64 closed_block = 9;
|
||||
// status represents the current status of the swap
|
||||
SwapStatus status = 10;
|
||||
// cross_chain identifies whether the atomic swap is cross chain
|
||||
bool cross_chain = 11;
|
||||
// direction identifies if the swap is incoming or outgoing
|
||||
SwapDirection direction = 12;
|
||||
}
|
||||
|
||||
// AssetSupply defines information about an asset's supply.
|
||||
message AssetSupply {
|
||||
// incoming_supply represents the incoming supply of an asset
|
||||
cosmos.base.v1beta1.Coin incoming_supply = 1 [(gogoproto.nullable) = false];
|
||||
// outgoing_supply represents the outgoing supply of an asset
|
||||
cosmos.base.v1beta1.Coin outgoing_supply = 2 [(gogoproto.nullable) = false];
|
||||
// current_supply represents the current on-chain supply of an asset
|
||||
cosmos.base.v1beta1.Coin current_supply = 3 [(gogoproto.nullable) = false];
|
||||
// time_limited_current_supply represents the time limited current supply of an asset
|
||||
cosmos.base.v1beta1.Coin time_limited_current_supply = 4 [(gogoproto.nullable) = false];
|
||||
// time_elapsed represents the time elapsed
|
||||
google.protobuf.Duration time_elapsed = 5 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.bep3.v1beta1;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "kava/bep3/v1beta1/bep3.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/bep3/types";
|
||||
|
||||
// GenesisState defines the pricefeed module's genesis state.
|
||||
message GenesisState {
|
||||
// params defines all the parameters of the module.
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
|
||||
// atomic_swaps represents the state of stored atomic swaps
|
||||
repeated AtomicSwap atomic_swaps = 2 [
|
||||
(gogoproto.castrepeated) = "AtomicSwaps",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
// supplies represents the supply information of each atomic swap
|
||||
repeated AssetSupply supplies = 3 [
|
||||
(gogoproto.castrepeated) = "AssetSupplies",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
|
||||
// previous_block_time represents the time of the previous block
|
||||
google.protobuf.Timestamp previous_block_time = 4 [
|
||||
(gogoproto.stdtime) = true,
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.bep3.v1beta1;
|
||||
|
||||
import "cosmos/base/query/v1beta1/pagination.proto";
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "kava/bep3/v1beta1/bep3.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/bep3/types";
|
||||
|
||||
// Query defines the gRPC querier service for bep3 module
|
||||
service Query {
|
||||
// Params queries module params
|
||||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
|
||||
option (google.api.http).get = "/kava/bep3/v1beta1/params";
|
||||
}
|
||||
|
||||
// AssetSupply queries info about an asset's supply
|
||||
rpc AssetSupply(QueryAssetSupplyRequest) returns (QueryAssetSupplyResponse) {
|
||||
option (google.api.http).get = "/kava/bep3/v1beta1/assetsupply/{denom}";
|
||||
}
|
||||
|
||||
// AssetSupplies queries a list of asset supplies
|
||||
rpc AssetSupplies(QueryAssetSuppliesRequest) returns (QueryAssetSuppliesResponse) {
|
||||
option (google.api.http).get = "/kava/bep3/v1beta1/assetsupplies";
|
||||
}
|
||||
|
||||
// AtomicSwap queries info about an atomic swap
|
||||
rpc AtomicSwap(QueryAtomicSwapRequest) returns (QueryAtomicSwapResponse) {
|
||||
option (google.api.http).get = "/kava/bep3/v1beta1/atomicswap/{swap_id}";
|
||||
}
|
||||
|
||||
// AtomicSwaps queries a list of atomic swaps
|
||||
rpc AtomicSwaps(QueryAtomicSwapsRequest) returns (QueryAtomicSwapsResponse) {
|
||||
option (google.api.http).get = "/kava/bep3/v1beta1/atomicswaps";
|
||||
}
|
||||
}
|
||||
|
||||
// QueryParamsRequest defines the request type for querying x/bep3 parameters.
|
||||
message QueryParamsRequest {}
|
||||
|
||||
// QueryParamsResponse defines the response type for querying x/bep3 parameters.
|
||||
message QueryParamsResponse {
|
||||
// params represents the parameters of the module
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryAssetSupplyRequest is the request type for the Query/AssetSupply RPC method.
|
||||
message QueryAssetSupplyRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
// denom filters the asset response for the specified denom
|
||||
string denom = 1;
|
||||
}
|
||||
|
||||
// AssetSupplyResponse defines information about an asset's supply.
|
||||
message AssetSupplyResponse {
|
||||
// incoming_supply represents the incoming supply of an asset
|
||||
cosmos.base.v1beta1.Coin incoming_supply = 1 [(gogoproto.nullable) = false];
|
||||
// outgoing_supply represents the outgoing supply of an asset
|
||||
cosmos.base.v1beta1.Coin outgoing_supply = 2 [(gogoproto.nullable) = false];
|
||||
// current_supply represents the current on-chain supply of an asset
|
||||
cosmos.base.v1beta1.Coin current_supply = 3 [(gogoproto.nullable) = false];
|
||||
// time_limited_current_supply represents the time limited current supply of an asset
|
||||
cosmos.base.v1beta1.Coin time_limited_current_supply = 4 [(gogoproto.nullable) = false];
|
||||
// time_elapsed represents the time elapsed
|
||||
google.protobuf.Duration time_elapsed = 5 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true
|
||||
];
|
||||
}
|
||||
|
||||
// QueryAssetSupplyResponse is the response type for the Query/AssetSupply RPC method.
|
||||
message QueryAssetSupplyResponse {
|
||||
// asset_supply represents the supply of the asset
|
||||
AssetSupplyResponse asset_supply = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryAssetSuppliesRequest is the request type for the Query/AssetSupplies RPC method.
|
||||
message QueryAssetSuppliesRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
}
|
||||
|
||||
// QueryAssetSuppliesResponse is the response type for the Query/AssetSupplies RPC method.
|
||||
message QueryAssetSuppliesResponse {
|
||||
// asset_supplies represents the supplies of returned assets
|
||||
repeated AssetSupplyResponse asset_supplies = 1 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// QueryAtomicSwapRequest is the request type for the Query/AtomicSwap RPC method.
|
||||
message QueryAtomicSwapRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
// swap_id represents the id of the swap to query
|
||||
string swap_id = 1;
|
||||
}
|
||||
|
||||
// QueryAtomicSwapResponse is the response type for the Query/AtomicSwap RPC method.
|
||||
message QueryAtomicSwapResponse {
|
||||
AtomicSwapResponse atomic_swap = 2 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
// AtomicSwapResponse represents the returned atomic swap properties
|
||||
message AtomicSwapResponse {
|
||||
// id represents the id of the atomic swap
|
||||
string id = 1;
|
||||
// amount represents the amount being swapped
|
||||
repeated cosmos.base.v1beta1.Coin amount = 2 [
|
||||
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
// random_number_hash represents the hash of the random number
|
||||
string random_number_hash = 3;
|
||||
// expire_height represents the height when the swap expires
|
||||
uint64 expire_height = 4;
|
||||
// timestamp represents the timestamp of the swap
|
||||
int64 timestamp = 5;
|
||||
// sender is the kava chain sender of the swap
|
||||
string sender = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
// recipient is the kava chain recipient of the swap
|
||||
string recipient = 7 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
// sender_other_chain is the sender on the other chain
|
||||
string sender_other_chain = 8;
|
||||
// recipient_other_chain is the recipient on the other chain
|
||||
string recipient_other_chain = 9;
|
||||
// closed_block is the block when the swap is closed
|
||||
int64 closed_block = 10;
|
||||
// status represents the current status of the swap
|
||||
SwapStatus status = 11;
|
||||
// cross_chain identifies whether the atomic swap is cross chain
|
||||
bool cross_chain = 12;
|
||||
// direction identifies if the swap is incoming or outgoing
|
||||
SwapDirection direction = 13;
|
||||
}
|
||||
|
||||
// QueryAtomicSwapsRequest is the request type for the Query/AtomicSwaps RPC method.
|
||||
message QueryAtomicSwapsRequest {
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
// involve filters by address
|
||||
string involve = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
// expiration filters by expiration block height
|
||||
uint64 expiration = 2;
|
||||
// status filters by swap status
|
||||
SwapStatus status = 3;
|
||||
// direction fitlers by swap direction
|
||||
SwapDirection direction = 4;
|
||||
|
||||
cosmos.base.query.v1beta1.PageRequest pagination = 5;
|
||||
}
|
||||
|
||||
// QueryAtomicSwapsResponse is the response type for the Query/AtomicSwaps RPC method.
|
||||
message QueryAtomicSwapsResponse {
|
||||
// atomic_swap represents the returned atomic swaps for the request
|
||||
repeated AtomicSwapResponse atomic_swaps = 1 [(gogoproto.nullable) = false];
|
||||
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 3;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
syntax = "proto3";
|
||||
package kava.bep3.v1beta1;
|
||||
|
||||
import "cosmos/base/v1beta1/coin.proto";
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/bep3/types";
|
||||
|
||||
// Msg defines the bep3 Msg service.
|
||||
service Msg {
|
||||
// CreateAtomicSwap defines a method for creating an atomic swap
|
||||
rpc CreateAtomicSwap(MsgCreateAtomicSwap) returns (MsgCreateAtomicSwapResponse);
|
||||
|
||||
// ClaimAtomicSwap defines a method for claiming an atomic swap
|
||||
rpc ClaimAtomicSwap(MsgClaimAtomicSwap) returns (MsgClaimAtomicSwapResponse);
|
||||
|
||||
// RefundAtomicSwap defines a method for refunding an atomic swap
|
||||
rpc RefundAtomicSwap(MsgRefundAtomicSwap) returns (MsgRefundAtomicSwapResponse);
|
||||
}
|
||||
|
||||
// MsgCreateAtomicSwap defines the Msg/CreateAtomicSwap request type.
|
||||
message MsgCreateAtomicSwap {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string from = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string to = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string recipient_other_chain = 3;
|
||||
string sender_other_chain = 4;
|
||||
string random_number_hash = 5;
|
||||
int64 timestamp = 6;
|
||||
repeated cosmos.base.v1beta1.Coin amount = 7 [
|
||||
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
uint64 height_span = 8;
|
||||
}
|
||||
|
||||
// MsgCreateAtomicSwapResponse defines the Msg/CreateAtomicSwap response type.
|
||||
message MsgCreateAtomicSwapResponse {}
|
||||
|
||||
// MsgClaimAtomicSwap defines the Msg/ClaimAtomicSwap request type.
|
||||
message MsgClaimAtomicSwap {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string from = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string swap_id = 2 [(gogoproto.customname) = "SwapID"];
|
||||
string random_number = 3;
|
||||
}
|
||||
|
||||
// MsgClaimAtomicSwapResponse defines the Msg/ClaimAtomicSwap response type.
|
||||
message MsgClaimAtomicSwapResponse {}
|
||||
|
||||
// MsgRefundAtomicSwap defines the Msg/RefundAtomicSwap request type.
|
||||
message MsgRefundAtomicSwap {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
option (gogoproto.equal) = false;
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string from = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
string swap_id = 2 [(gogoproto.customname) = "SwapID"];
|
||||
}
|
||||
|
||||
// MsgRefundAtomicSwapResponse defines the Msg/RefundAtomicSwap response type.
|
||||
message MsgRefundAtomicSwapResponse {}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user