Skip to content

Commit

Permalink
Merge branch 'main' into backoffRetrier
Browse files Browse the repository at this point in the history
  • Loading branch information
mhluongo authored Aug 23, 2024
2 parents cb10ef4 + e0a0bd4 commit 91464c1
Show file tree
Hide file tree
Showing 105 changed files with 5,760 additions and 2,077 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14.x"
node-version: "18.x"
cache: "yarn"
cache-dependency-path: monitoring/yarn.lock

Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "14.x"
node-version: "18.x"
cache: "yarn"
cache-dependency-path: monitoring/yarn.lock

Expand Down
33 changes: 31 additions & 2 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
anyone, and even the smallest of fixes is appreciated!

The following is a set of guidelines for contributing to Keep and its packages.
These are mostly guidelines, not rules. Use your best judgment, and feel free to
propose changes to this document in a pull request.
Feel free to propose changes to this document in a pull request.

== Getting started

Expand Down Expand Up @@ -55,3 +54,33 @@ Solidity linting, please propose these changes to our
https://github.com/keep-network/solium-config-keep[solium-config-keep] and
https://github.com/keep-network/eslint-config-keep[eslint-config-keep] packages.
All other packages have it as a dependency.

== Commit Messages

When composing commit messages, please follow the general guidelines listed in
https://cbea.ms/git-commit/[Chris Beams’s How to Write a Git Commit Message].
Many editors have git modes that will highlight overly long first lines of
commit messages, etc. The GitHub UI itself will warn you if your commit summary
is too long, and will auto-wrap commit messages made through the UI to 72
characters.

The above goes into good commit style. Some additional guidelines do apply,
however:

* The target audience of your commit messages is always "some person 10 years
from now who never got a chance to talk to present you" (that person could be
future you!).
* Commit messages with a summary and no description should be very rare. This
means you should probably break any habit of using `git commit -m`.
* A fundamental principle that informs our use of GitHub: assume GitHub will
someday go away, and ensure git has captured all important information about
the development of the code. Commit messages are the piece of knowledge that
is second most likely to survive tool transitions (the first is the code
itself); as such, they must stand alone. Do not reference tickets or issues
in your commit messages. Summarize any conclusions from the issue or ticket
that inform the commit itself, and capture any additional reasoning or context
in the merge commit.
* Make your commits as atomic as you can manage. This means each commit contains
a single logical unit of work.
* Run a quick `git log --graph --all --oneline --decorate` before pushing.
It’s much easier to fix typos and minor mistakes locally.
6 changes: 2 additions & 4 deletions monitoring/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:14-alpine as builder
FROM node:18-alpine as builder

# Add packages necessary to perform the build process.
RUN apk add --update --no-cache \
Expand All @@ -25,20 +25,18 @@ COPY tsconfig.json ./
COPY src ./src

RUN yarn install --frozen-lockfile --ignore-scripts
RUN yarn run postinstall

RUN yarn build

# Prune development dependencies.
RUN rm -rf ./node_modules
RUN rm -rf ./external
RUN yarn install --production --frozen-lockfile --ignore-scripts
RUN yarn run postinstall

# Prune other unnecessary files from dependencies using node-prune.
RUN node-prune

FROM node:14-alpine as runner
FROM node:18-alpine as runner

WORKDIR /monitoring

Expand Down
9 changes: 3 additions & 6 deletions monitoring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
"format": "yarn run lint && prettier --check .",
"format:fix": "yarn run lint:fix && prettier --write .",
"lint": "eslint . --ext .js,.ts",
"lint:fix": "eslint . --ext .js,.ts --fix",
"postinstall": "npm rebuild bcrypto"
"lint:fix": "eslint . --ext .js,.ts --fix"
},
"dependencies": {
"@keep-network/tbtc-v2-mainnet": "npm:@keep-network/tbtc-v2@mainnet",
"@keep-network/tbtc-v2-testnet": "npm:@keep-network/tbtc-v2@sepolia",
"@keep-network/tbtc-v2.ts": "1.4.0-dev.1",
"@keep-network/tbtc-v2.ts": "v2.5.0-dev.5",
"@sentry/node": "^7.33.0",
"axios": "^1.3.2",
"ethers": "^5.5.2",
Expand All @@ -29,6 +26,6 @@
"typescript": "^4.9.5"
},
"engines": {
"node": ">=14 <15"
"node": ">=16"
}
}
4 changes: 2 additions & 2 deletions monitoring/src/block-explorer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { context, Environment } from "./context"

import type { BitcoinTransactionHash, Hex } from "@keep-network/tbtc-v2.ts"
import type { BitcoinTxHash, Hex } from "@keep-network/tbtc-v2.ts"

const ethTxUrlPrefixMapping = {
[Environment.Mainnet]: "https://etherscan.io/tx",
Expand All @@ -18,6 +18,6 @@ const btcTxUrlPrefixMapping = {
[Environment.Testnet]: "https://mempool.space/testnet/tx",
}

export function createBtcTxUrl(txHash: BitcoinTransactionHash) {
export function createBtcTxUrl(txHash: BitcoinTxHash) {
return `${btcTxUrlPrefixMapping[context.environment]}/${txHash.toString()}`
}
21 changes: 21 additions & 0 deletions monitoring/src/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { providers } from "ethers"

import { context } from "./context"

const resolve = () => {
const provider = new providers.JsonRpcProvider(context.ethereumUrl)

const latestBlock = async () => {
const block = await provider.getBlock("latest")
return block.number
}

const blockTimestamp = async (blockNumber: number): Promise<number> => {
const block = await provider.getBlock(blockNumber)
return block.timestamp
}

return { latestBlock, blockTimestamp }
}

export const blocks = resolve()
14 changes: 14 additions & 0 deletions monitoring/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BitcoinNetwork, Chains } from "@keep-network/tbtc-v2.ts"

// List of environment variables used by the monitoring package.
const {
ENVIRONMENT,
Expand All @@ -15,6 +17,16 @@ export enum Environment {
Testnet = "testnet",
}

const ethereumEnvironmentMapping = {
[Environment.Mainnet]: Chains.Ethereum.Mainnet,
[Environment.Testnet]: Chains.Ethereum.Sepolia,
}

const bitcoinEnvironmentMapping = {
[Environment.Mainnet]: BitcoinNetwork.Mainnet,
[Environment.Testnet]: BitcoinNetwork.Testnet,
}

const resolveEnvironment = () => {
switch (ENVIRONMENT) {
case Environment.Mainnet: {
Expand Down Expand Up @@ -57,4 +69,6 @@ export const context = {
dataDirPath: DATA_DIR_PATH ?? "./data",
sentryDsn: SENTRY_DSN,
discordWebhookUrl: DISCORD_WEBHOOK_URL,
ethereumEnvironmentMapping,
bitcoinEnvironmentMapping,
}
74 changes: 0 additions & 74 deletions monitoring/src/contracts.ts

This file was deleted.

6 changes: 4 additions & 2 deletions monitoring/src/deposit-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { context } from "./context"
import { createBtcTxUrl, createEthTxUrl } from "./block-explorer"

import type { SystemEvent, Monitor as SystemEventMonitor } from "./system-event"
import type { DepositRevealedEvent as DepositRevealedChainEvent } from "@keep-network/tbtc-v2.ts/dist/src/deposit"
import type { Bridge } from "@keep-network/tbtc-v2.ts/dist/src/chain"
import type {
Bridge,
DepositRevealedEvent as DepositRevealedChainEvent,
} from "@keep-network/tbtc-v2.ts"

export const satsToRoundedBTC = (sats: BigNumber): string =>
(sats.div(BigNumber.from(1e6)).toNumber() / 100).toFixed(2)
Expand Down
Loading

0 comments on commit 91464c1

Please sign in to comment.