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

Upgrade celo deps #227

Merged
merged 27 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ jobs:

steps:
- name: 'Check out the repo'
uses: 'actions/checkout@v3'
uses: 'actions/checkout@v4'

- name: Setup Node.js
- uses: pnpm/action-setup@v3
with:
version: 8

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.11
node-version: 20.x
cache: 'pnpm'

- name: Install dependencies
run: 'yarn install --immutable'
run: pnpm install --frozen-lockfile

- name: Build packages
run: yarn build
run: pnpm run build

- name: Run lint checks
run: |
yarn run prettify:diff
yarn run lint
yarn run lint:tests
pnpm run prettify:diff
pnpm run lint
pnpm run lint:tests

- name: Run tests
run: yarn run test --maxWorkers 2
run: pnpm run test --maxWorkers 2
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
"typescript.preferences.importModuleSpecifier": "non-relative",
"typescript.updateImportsOnFileMove.enabled": "always",
"editor.codeActionsOnSave": {
"source.organizeImports": false
"source.organizeImports": "never"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": false
"source.organizeImports": "never"
}
},
"[javascriptreact]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
}
},
"[typescript]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.organizeImports": false
"source.organizeImports": "never"
}
},
"javascript.format.enable": false,
Expand Down
25 changes: 13 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@
# First stage, builder to install devDependencies to build TypeScript
FROM node:20.11 as BUILDER

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

RUN apt-get update
RUN apt-get install -y libusb-1.0-0-dev

WORKDIR /celo-oracle

# ensure yarn.lock is evaluated by kaniko cache diff
COPY package.json yarn.lock ./
# ensure pnpm-lock.yaml is evaluated by kaniko cache diff
COPY package.json pnpm-lock.yaml ./

RUN yarn install --frozen-lockfile --network-timeout 100000 && yarn cache clean
RUN pnpm install --frozen-lockfile

COPY tsconfig.json ./

# copy contents
COPY src src

# build contents
RUN yarn build
RUN pnpm run build

# Second stage, create slimmed down production-ready image
FROM node:20.11
ARG COMMIT_SHA

RUN apt-get update
RUN apt-get install -y libusb-1.0-0-dev

WORKDIR /celo-oracle
ENV NODE_ENV production
RUN corepack enable
WORKDIR /celo-oracle

COPY package.json package.json yarn.lock tsconfig.json readinessProbe.sh ./
COPY package.json package.json pnpm-lock.yaml tsconfig.json readinessProbe.sh ./

COPY --from=BUILDER /celo-oracle/lib ./lib

RUN yarn install --production --frozen-lockfile --network-timeout 100000 && yarn cache clean
RUN pnpm install --frozen-lockfile
RUN echo $COMMIT_SHA > /version
RUN ["chmod", "+x", "/celo-oracle/readinessProbe.sh"]

USER 1000:1000

CMD yarn start
CMD pnpm run start
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

Oracles bring off-chain information on-chain, making that information accessible to the Smart Contracts. The Celo Protocol contains a Smart Contract called "[SortedOracles](https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/contracts/stability/SortedOracles.sol)". This Smart Contract receives price reports from Oracles, keeps track of the median value of these price reports, and references these price reports against a list of addresses that are permitted to provide price reports. One significant function of Oracles on Celo is supporting the [stability mechanism](https://docs.celo.org/celo-codebase/protocol/stability/doto). Oracles provide the price of CELO in the fiat currency to which a stable value asset is linked, such as cUSD (stable value asset) to the fiat currency to which it is linked (US Dollar).
Oracles bring off-chain information on-chain, making that information accessible to the Smart Contracts. The Celo Protocol contains a Smart Contract called "[SortedOracles](https://github.com/celo-org/celo-monorepo/blob/master/packages/protocol/contracts/stability/SortedOracles.sol)". This Smart Contract receives price reports from Oracles, keeps track of the median value of these price reports, and references these price reports against a list of addresses that are permitted to provide price reports. One significant function of Oracles on Celo is supporting the [stability mechanism](https://docs.celo.org/celo-codebase/protocol/stability/doto). Oracles provide the price of CELO in the fiat currency to which a stable value asset is linked, such as cUSD (stable value asset) to the fiat currency to which it is linked (US Dollar).

This Oracle application does the off-chain work of determining the current exchange rate of a given currency pair. It does this by aggregating data across multiple exchanges where these currencies are traded, and reporting the results of this processing to the aforementioned SortedOracles contract.

Expand All @@ -15,38 +15,38 @@ To run using the defaults, the only thing you will need to set up the Oracle is
There are two ways to do this:

1. When using an HSM (Azure or AWS)\
This method assumes that you're using an HSM (Hardware Security Module) on Azure or AWS, and have already generated a private key and address in that setup.\
Set the relevant EnvVars:\
`ADDRESS`: the address associated with HSM private key\
`AZURE_KEY_VAULT_NAME`: if using Azure, the name of the Azure Key Vault. Omit if using AWS.
This method assumes that you're using an HSM (Hardware Security Module) on Azure or AWS, and have already generated a private key and address in that setup.\
Set the relevant EnvVars:\
`ADDRESS`: the address associated with HSM private key\
`AZURE_KEY_VAULT_NAME`: if using Azure, the name of the Azure Key Vault. Omit if using AWS.
1. Reading a private key from a file (this is not recommended in production)\
Make sure the private key is accessible to the running oracle application, and set the following EnvVar:\
`PRIVATE_KEY_PATH`: path to the file
Make sure the private key is accessible to the running oracle application, and set the following EnvVar:\
`PRIVATE_KEY_PATH`: path to the file

## Running

Dependencies must be installed:

```shell
yarn
pnpm
```

Before running or testing, the TypeScript must be re-built:

```shell
yarn build
pnpm build
```

[Bunyan](https://github.com/trentm/node-bunyan) is used for structured logging. To start the oracle with JSON formatted logs (how it should be run in production), run:

```shell
yarn start
pnpm start
```

For a friendlier developer experience, the bunayn CLI can be used to output prettier logs:

```shell
yarn start | npx bunyan
pnpm start | npx bunyan
```

## Deployment
Expand All @@ -55,7 +55,6 @@ Docker images are pushed to a public container [registry](https://console.cloud.

The recommended configuration at the moment is [6787997](https://github.com/celo-org/celo-monorepo/commit/6787997a0b1f4a20cd1e4083e70bcd7db497c93e).


## Component Overview

<!-- TODO: Add architecture diagram here -->
Expand Down Expand Up @@ -91,6 +90,7 @@ The MetricCollector collects information from a running oracle application insta
### **Circuit Breaker**

<!-- TODO: resolve feedback from Brynly in this section -->

If extreme market volatility is detected, the “circuit breaker” will shut down the Oracle. The current implementation assumes that all participating Oracles are operating with a circuit breaker and using the same configuration. The coordinated shutdown of all Oracles prevents the on-chain exchange rate from being updated. Until the circuit breakers are reset, the on-chain exchange rate adjusts dynamically. One-sided trading with the reserve will push the exchange rate towards the current market price, while limiting the effect on the reserve of having a rate that is "wrong".

### **Minimum Number of Exchanges**
Expand Down
7 changes: 6 additions & 1 deletion build_and_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ fi
echo "Building version $VERSION"
docker buildx build --platform linux/amd64 -t $PACKAGE_NAME .

if [[ $? -ne 0 ]]; then
echo "Build failed"
exit 1
fi

echo "Tagging and pushing"
docker tag $PACKAGE_NAME $REPOSITORY/$PACKAGE_NAME:$COMMIT_HASH
docker push $REPOSITORY/$PACKAGE_NAME:$COMMIT_HASH
Expand All @@ -39,4 +44,4 @@ if [[ $BUILD_ENV == "production" ]]; then
else
docker tag $PACKAGE_NAME $REPOSITORY/$PACKAGE_NAME:latest
docker push $REPOSITORY/$PACKAGE_NAME:latest
fi
fi
32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,35 @@
"build": "tsc -b .",
"clean": "tsc -b . --clean",
"start": "node lib/index.js",
"dev": "yarn build && . .env.dev && yarn start",
"dev": "pnpm run build && . .env.dev && pnpm run start",
"test": "jest",
"lint": "tslint -c tslint.json --project .",
"lint:tests": "tslint -c tslint.json 'test/**/*.test.ts'",
"prettify": "yarn run prettier --config .prettierrc.js --write '**/*.+(ts|tsx|js|jsx|sol|java)'",
"prettify:diff": "yarn run prettier --config .prettierrc.js --list-different '**/*.+(ts|tsx|js|jsx|sol|java)'",
"prettify": "pmpm prettier --config .prettierrc.js --write '**/*.+(ts|tsx|js|jsx|sol|java)'",
"prettify:diff": "pnpm prettier --config .prettierrc.js --list-different '**/*.+(ts|tsx|js|jsx|sol|java)'",
"get-cert": "./scripts/get_cert_fingerprint.sh"
},
"dependencies": {
"@celo/connect": "1.5.2",
"@celo/contractkit": "1.5.2",
"@celo/utils": "1.5.2",
"@celo/wallet-hsm-aws": "1.5.2",
"@celo/wallet-hsm-azure": "1.5.2",
"bignumber.js": "^8.1.1",
"@celo/connect": "5.3.0",
"@celo/contractkit": "8.0.0",
"@celo/utils": "6.0.0",
"@celo/wallet-hsm-aws": "5.2.0",
"@celo/wallet-hsm-azure": "5.2.0",
"bignumber.js": "^9.0.0",
"bunyan": "1.8.15",
"express": "^4.17.1",
"js-yaml": "^3.13.1",
"mathjs": "^7.5.1",
"node-fetch": "^2.6.1",
"prom-client": "^12.0.0",
"tslint-no-focused-test": "^0.5.0",
"web3": "1.3.6"
"web3": "1.10.4",
"web3-core": "1.10.4",
"web3-core-subscriptions": "1.10.4",
"web3-eth": "1.10.4"
},
"devDependencies": {
"@celo/typescript": "^0.0.1",
"@celo/typescript": "^0.0.2",
"@types/bunyan": "^1.8.6",
"@types/express": "^4.17.6",
"@types/jest": "29.5.12",
Expand All @@ -48,8 +51,7 @@
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-microsoft-contrib": "^6.2.0",
"tslint-react": "^4.2.0",
palango marked this conversation as resolved.
Show resolved Hide resolved
"tslint-react-hooks": "^2.2.2",
"typescript": "4.4.3"
}
"typescript": "5.4.2"
},
"packageManager": "[email protected]"
}
Loading
Loading