Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: oracle module #593

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
712746a
feat(modules): add oracle module
SpekalsG3 Oct 1, 2024
b44c2f7
fix(tests): rewire tests to archway framework
SpekalsG3 Oct 3, 2024
0325211
fix(tests): validator accounts
SpekalsG3 Oct 3, 2024
f1df816
feat(collections): replace nibiru with sdk
SpekalsG3 Oct 4, 2024
e0e3021
feat(x/oracle): move assets and denoms from x/common
SpekalsG3 Oct 5, 2024
8886ca1
fix(x/oracle): fix tests
SpekalsG3 Oct 5, 2024
a2a1045
feat(x/oracle): remove omap
SpekalsG3 Oct 5, 2024
c015b77
feat(x/oracle): move set from x/common to types
SpekalsG3 Oct 5, 2024
d948c9a
feat(x/common): remove
SpekalsG3 Oct 5, 2024
785b6f1
chore(setup): go mod tidy
SpekalsG3 Oct 7, 2024
6453834
fix(tests): update dependencies
SpekalsG3 Oct 17, 2024
8f356ab
fix(tests): use specific relayer version
SpekalsG3 Oct 21, 2024
54292f7
fix(tests): fixed assignment
SpekalsG3 Oct 21, 2024
0d81dfc
fix(build): docker, make and github action
SpekalsG3 Oct 31, 2024
2e1bb81
fix(prefixes): move function into app
SpekalsG3 Oct 31, 2024
b9142e3
fix(docker): link statically
SpekalsG3 Oct 31, 2024
5191cdb
feat(docker): improve with goproxy and same versions
SpekalsG3 Nov 7, 2024
8964a00
feat(localnet): set x/oracle min_voters to 1
SpekalsG3 Nov 7, 2024
fd5e966
fix(oracle): module endblocker definition
SpekalsG3 Nov 7, 2024
9f757b0
fix(oracle): IsPeriodLastBlock
SpekalsG3 Nov 7, 2024
cb2210a
fix(oracle): fix pairVotes error and return type
SpekalsG3 Nov 7, 2024
737fec8
fix(oracle): fix UpdateExchangeRates return type
SpekalsG3 Nov 7, 2024
afbe7c9
test(x/oracle): update tests
pyncz Nov 19, 2024
866c106
lint(x/oracle): handle errors (#597)
pyncz Nov 19, 2024
da453f7
feat(x/oracle): store price timestamp (#596)
pyncz Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
Dockerfile.*
docker-compose.yaml
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-deprecated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
file: Dockerfile.deprecated
file: Dockerfile
18 changes: 2 additions & 16 deletions .github/workflows/interchaintest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ jobs:
- name: Load current image
run: docker load --input archway_local

- name: Get last release tag
id: lastrelease
uses: WyriHaximus/github-action-get-previous-tag@v1
with:
prefix: 'v'

- name: Download ${{ steps.lastrelease.outputs.tag }} image
uses: actions/download-artifact@v3
with:
name: action_image_artifact_archway_${{ steps.lastrelease.outputs.tag }}

- name: Load ${{ steps.lastrelease.outputs.tag }} image
run: docker load --input archway_${{ steps.lastrelease.outputs.tag }}

- name: Run chain upgrade test
run: |
cd interchaintest
Expand Down Expand Up @@ -140,7 +126,7 @@ jobs:
- name: Run chain conformance test
run: |
cd interchaintest
go test -v -race -run TestGaiaConformance
go test -v -race -run TestGaiaConformance

cwica_tests:
name: Interchain transactions test
Expand Down Expand Up @@ -173,4 +159,4 @@ jobs:
- name: Run interchain transactions test
run: |
cd interchaintest
go test -v -race -run TestCWICA
go test -v -race -run TestCWICA
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ build/

dist/
data/

.envrc
52 changes: 49 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
FROM scratch
FROM golang:1.23.1-alpine3.19 AS builder

COPY ./archwayd /usr/bin/archwayd
WORKDIR /code

WORKDIR /root/.archway
RUN apk add \
make \
# used by make
git \
# to install GCC
build-base

# ARG arch=x86_64
# ARG libwasmvm_sha=0421ad81247a46bbad6899c49d5081a5a080621ab9432e710152d85ba66c94bc
ARG arch=aarch64
ARG libwasmvm_sha=9429e9ab18f0b2519d9e3344b13fbb3ea339b7f1deedfaa2abc71522d190eaef
ARG libwasmvm_version=v1.5.5

# used to to link wasm
# ADD https://github.com/CosmWasm/wasmvm/releases/download/${libwasmvm_version}/libwasmvm_muslc.${arch}.a /lib/libwasmvm_muslc.a
RUN wget -O /lib/libwasmvm_muslc.a https://github.com/CosmWasm/wasmvm/releases/download/${libwasmvm_version}/libwasmvm_muslc.${arch}.a
RUN sha256sum /lib/libwasmvm_muslc.a > /lib/libwasmvm_checksum
RUN if ! grep -q "${libwasmvm_sha} " /lib/libwasmvm_checksum ; then \
echo "Expected libwasmvm signature: ${libwasmvm_sha}" && \
echo "Actual libwasmvm signature: $(cat /lib/libwasmvm_checksum)" && \
exit 1; fi

ARG GOPROXY=""
ENV GOPROXY=${GOPROXY}

COPY \
go.sum \
go.mod \
./
RUN \
# --mount=type=cache,target=/root/.cache/go \
GOPROXY=${GOPROXY} \
go mod download

COPY . .
# wasm keeper is not implemented for builds without CGO - https://github.com/CosmWasm/wasmd/blob/88cba83a664ead2e99074cc841422809df85a3b4/x/wasm/keeper/keeper_no_cgo.go#L35
# thus we use cgo implementation and have to build with cgo enabled

RUN \
# --mount=type=cache,target=/root/.cache/go-build \
# --mount=type=cache,target=/go/pkg \
CGO_ENABLED=1 LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build

# --------------------------------------------------------
FROM alpine:3.17

COPY --from=builder /code/build/archwayd /usr/bin/archwayd

# rest server
EXPOSE 1317
Expand Down
53 changes: 0 additions & 53 deletions Dockerfile.deprecated

This file was deleted.

6 changes: 2 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM alpine:3.18
FROM alpine:3.17

COPY ./archwayd /usr/bin/archwayd

WORKDIR /root/.archway
COPY ./build/archwayd /usr/bin/archwayd

# Install dev packages
RUN apk add --no-cache bash jq
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ifeq ($(WITH_CLEVELDB),yes)
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
ldflags += -linkmode=external -extldflags "-static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
Expand Down
78 changes: 47 additions & 31 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import (
ibccm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

"github.com/archway-network/archway/app/appconst"
"github.com/archway-network/archway/app/keepers"
"github.com/archway-network/archway/x/cwfees"
"github.com/archway-network/archway/x/genmsg"
Expand Down Expand Up @@ -154,43 +155,19 @@ import (
cwicakeeper "github.com/archway-network/archway/x/cwica/keeper"
cwicatypes "github.com/archway-network/archway/x/cwica/types"

oracle "github.com/archway-network/archway/x/oracle"
oraclekeeper "github.com/archway-network/archway/x/oracle/keeper"
oracletypes "github.com/archway-network/archway/x/oracle/types"

extendedGov "github.com/archway-network/archway/x/gov"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

archwayappparams "github.com/archway-network/archway/app/params"
archway "github.com/archway-network/archway/types"
)

const appName = "Archway"

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".archway"
Bech32Prefix = "archway"
)

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
var (
// DefaultNodeHome default home directories for archwayd
DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir

// 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 + sdk.PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

var (
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
Expand Down Expand Up @@ -229,6 +206,7 @@ var (
cwfees.AppModule{},
cwica.AppModuleBasic{},
cwerrors.AppModuleBasic{},
oracle.AppModuleBasic{},
)

// module account permissions
Expand All @@ -247,6 +225,7 @@ var (
wasmdTypes.ModuleName: {authtypes.Burner},
rewardsTypes.TreasuryCollector: {authtypes.Burner},
callbackTypes.ModuleName: nil,
oracletypes.ModuleName: nil,
}
)

Expand All @@ -255,6 +234,15 @@ var (
_ servertypes.Application = (*ArchwayApp)(nil)
)

func SetPrefixes() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(appconst.Bech32PrefixAccAddr, appconst.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(appconst.Bech32PrefixValAddr, appconst.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(appconst.Bech32PrefixConsAddr, appconst.Bech32PrefixConsPub)
cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen())
cfg.Seal()
}

func init() {
// sets the default power reduction in order to ensure that on high precision numbers, which is a default for archway
// the network does not get stalled due to an integer overflow in some edge cases.
Expand Down Expand Up @@ -317,7 +305,7 @@ func NewArchwayApp(
std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp := baseapp.NewBaseApp(appconst.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand All @@ -335,6 +323,7 @@ func NewArchwayApp(
icacontrollertypes.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, crisistypes.StoreKey, group.StoreKey, nftkeeper.StoreKey, cwicatypes.StoreKey,

trackingTypes.StoreKey, rewardsTypes.StoreKey, callbackTypes.StoreKey, cwfees.ModuleName, cwerrorsTypes.StoreKey,
oracletypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, cwerrorsTypes.TStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -672,8 +661,19 @@ func NewArchwayApp(
logger,
)

app.Keepers.OracleKeeper = oraclekeeper.NewKeeper(
appCodec,
keys[oracletypes.StoreKey],
app.Keepers.AccountKeeper,
app.Keepers.BankKeeper,
app.Keepers.DistrKeeper,
app.Keepers.StakingKeeper,
app.Keepers.SlashingKeeper,
distrtypes.ModuleName,
)

app.Keepers.IBCHooksKeeper = ibchookskeeper.NewKeeper(keys[ibchookstypes.StoreKey])
ics20WasmHooks := ibchooks.NewWasmHooks(&app.Keepers.IBCHooksKeeper, nil, Bech32Prefix)
ics20WasmHooks := ibchooks.NewWasmHooks(&app.Keepers.IBCHooksKeeper, nil, appconst.Bech32Prefix)
hooksIcs4Wrapper := ibchooks.NewICS4Middleware(app.Keepers.IBCKeeper.ChannelKeeper, ics20WasmHooks)

var transferStack porttypes.IBCModule
Expand Down Expand Up @@ -759,6 +759,7 @@ func NewArchwayApp(
cwica.NewAppModule(appCodec, app.Keepers.CWICAKeeper, app.Keepers.AccountKeeper),
cwerrors.NewAppModule(app.appCodec, app.Keepers.CWErrorsKeeper, app.Keepers.WASMKeeper),
crisis.NewAppModule(&app.Keepers.CrisisKeeper, skipGenesisInvariants, app.getSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
oracle.NewAppModule(appCodec, app.Keepers.OracleKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper),
)

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -801,6 +802,7 @@ func NewArchwayApp(
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// additional non simd modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -836,6 +838,7 @@ func NewArchwayApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// wasm
ibchookstypes.ModuleName,
wasmdTypes.ModuleName,
Expand Down Expand Up @@ -876,6 +879,7 @@ func NewArchwayApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// additional non simd modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -1219,5 +1223,17 @@ func getAcceptedStargateQueries() wasmdKeeper.AcceptedStargateQueries {
"/archway.cwerrors.v1.Query/Errors": &cwerrorsTypes.QueryErrorsRequest{},
"/archway.callback.v1.Query/EstimateCallbackFees": &callbackTypes.QueryEstimateCallbackFeesRequest{},
"/archway.callback.v1.Query/Params": &callbackTypes.QueryParamsRequest{},
"/archway.oracle.v1.Query/ExchangeRate": new(oracletypes.QueryExchangeRateResponse),
"/archway.oracle.v1.Query/ExchangeRateTwap": new(oracletypes.QueryExchangeRateResponse),
"/archway.oracle.v1.Query/ExchangeRates": new(oracletypes.QueryExchangeRatesResponse),
"/archway.oracle.v1.Query/Actives": new(oracletypes.QueryActivesResponse),
"/archway.oracle.v1.Query/VoteTargets": new(oracletypes.QueryVoteTargetsResponse),
"/archway.oracle.v1.Query/FeederDelegation": new(oracletypes.QueryFeederDelegationResponse),
"/archway.oracle.v1.Query/MissCounter": new(oracletypes.QueryMissCounterResponse),
"/archway.oracle.v1.Query/AggregatePrevote": new(oracletypes.QueryAggregatePrevoteResponse),
"/archway.oracle.v1.Query/AggregatePrevotes": new(oracletypes.QueryAggregatePrevotesResponse),
"/archway.oracle.v1.Query/AggregateVote": new(oracletypes.QueryAggregateVoteResponse),
"/archway.oracle.v1.Query/AggregateVotes": new(oracletypes.QueryAggregateVotesResponse),
"/archway.oracle.v1.Query/Params": new(oracletypes.QueryParamsResponse),
}
}
4 changes: 3 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
tmdb "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/archway-network/archway/app/appconst"
)

// import (
Expand Down Expand Up @@ -87,7 +89,7 @@ var emptyWasmOpts []wasmkeeper.Option = nil
// ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) {
db := tmdb.NewMemDB()
gapp := NewArchwayApp(log.NewTestLogger(t), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig(), EmptyBaseAppOptions{}, emptyWasmOpts)
gapp := NewArchwayApp(log.NewTestLogger(t), db, nil, true, map[int64]bool{}, appconst.DefaultNodeHome, 0, MakeEncodingConfig(), EmptyBaseAppOptions{}, emptyWasmOpts)

for acc := range BlockedAddresses() {
var addr sdk.AccAddress
Expand Down
Loading