Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from celo-org/aaronmgdr/version2
Browse files Browse the repository at this point in the history
CeloReserve.org V2
  • Loading branch information
aaronmgdr authored Mar 10, 2021
2 parents b0d2a02 + ad50486 commit a9f6b8b
Show file tree
Hide file tree
Showing 86 changed files with 6,191 additions and 6,956 deletions.
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"next/babel",
{
"preset-react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
]
],
"plugins": ["@emotion"]
}
17 changes: 14 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node-defaults: &NODE
working_directory: ~/app
docker:
- image: celohq/node10-gcloud:v3
- image: circleci/node:fermium
environment:
# To avoid ENOMEM problem when running node
NODE_OPTIONS: '--max-old-space-size=4096'
Expand All @@ -21,6 +21,9 @@ workflows:
- next-build:
requires:
- install
- test:
requires:
- install

jobs:

Expand All @@ -43,11 +46,19 @@ jobs:
paths:
- node_modules
- .env.local
# Test
test:
<<: *NODE
steps:
- checkout
- *CHECKOUT-WORKSPACE
- run: yarn test

# Build
# Build
next-build:
<<: *NODE
steps:
- checkout
- *CHECKOUT-WORKSPACE
- run: yarn build:next
- run: yarn build:next

10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# keys with NEXT_PUBLIC_ Prefix are sent to browser
# https://nextjs.org/docs/basic-features/environment-variables

AIRTABLE_API_KEY=AIRTABLE_KEY

NEXT_PUBLIC_FATHOM_KEY=ANALYTICS



ETHERSCAN_KEY=KEY_HERE
Binary file modified .env.local.enc
Binary file not shown.
61 changes: 57 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,69 @@

# Celo Reserve Website

code for [celoreserve.org](https://celoreserve.org)
Code for [celoreserve.org](https://celoreserve.org)

*For more information about the Reserve itself please refer to:*

## Updating Content
To update Content edit the Markdown files in [src/content](src/content)
* [celoreserve.org](https://celoreserve.org)
* [Celo Docs](https://docs.celo.org/developer-guide/sdk-code-reference/summary-2/classes/_wrappers_reserve_.reservewrapper)
* [Stability WhitePaper](https://celo.org/papers/stability)

## Data Integrity
The following is where the numbers displayed on celoreserve.org comes from. These are not used by the reserve itself.

### Update Frequency

| Data | Frequency | Notes |
| --- | --- | --- |
| Reserve Contract | 20 Seconds | |
| Stable Tokens | 20 Seconds | |
| Celo Custody | 30 Minutes | Pratically only change daily |
| BTC, ETH, DAI balances | 30 Minutes | Pratically only change daily |
| euro conversion rate | 4 Hours | source rates updated once a day |
| Asset prices | 5 Minutes | |

### Reserve Holdings

For Celo on chain balances, an instance of `@celo/contractKit` is connected to a node at `forno.celo.org`. See [src/providers/Celo.ts](src/providers/Celo.ts) for how this works.

For ETH and BTC balances we use 2 data providers each: blockchain.com and [blockstreams's esplora](https://github.com/Blockstream/esplora/blob/master/API.md) for BTC and etherscan and ethplorer for Ethereum.


#### For Asset Prices

For CELO the on change exchange price (which itself is an aggregation of the price on several exchanges) is used again via `@celo/contractKit`

For other crypto assets two data providers are used. These are simply averaged if both return correctly. If one provider fails to respond then the other is used and if both fail a cache of the last successful fetch is used until new data is fetched.
For BTC thse are [blockchain.com's getAccountByTypeAndCurrency](https://api.blockchain.com/v3/#/payments/getAccountByTypeAndCurrency) and [Coinbase's Data Api spot price](https://developers.coinbase.com/api/v2#exchange-rates).
For ETH these are [Etherscan.io ETHER Last Price](https://etherscan.io/apis#stats) and [Coinbase's Data Api spot price](https://developers.coinbase.com/api/v2#exchange-rates).

### Stable Assets Outstanding

All stable token amounts are the total amount in circulation. This can be verified with

```typescript
import { newKit } from '@celo/contractkit'
const kit = newKit('forno.celo.org')
const stableToken = await kit.contracts.getStableToken()

stableToken.totalSupply()

#### Currency Conversions
For stable coins other than cUSD exchangeratesapi.io is used to convert value to USD to compare and sum values
```


### Historic Rebalancings
Reserve rebalancings figures are updated manually at the moment. However they can be verified by using a block explorer to check the historic balances of the reserve addresses.

### Updating Content
To update Content edit the Markdown files in [src/content](src/content)
Changes to these require a redeployment and to wait for the page cache to expire (5min)

## Development

next.js with [emotion](http://emotion.sh/) for styles.
next.js with [emotion](http://emotion.sh/) for styles.

`yarn dev`

Expand Down
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
globals: {
"ts-jest": {
isolatedModules: true,
tsconfig: "tsconfig.jest.json",
useBabelrc: true,
},
},
moduleNameMapper: {
"\\.(png|jpg|jpeg|gif|svg)(\\?[a-z]+)?$":
"<rootDir>/src/__mocks__/ImageStub.ts",
"\\.(css|scss)$": "<rootDir>/src/__mocks__/ImageStub.ts",
"^src/(.*)$": "<rootDir>/src/$1",
"^public/(.*)$": "<rootDir>/public/$1",
},
transform: {
"^.+\\.tsx?$": "babel-jest",
},
setupFilesAfterEnv: ["./jestAfterSetup.ts"],
}
26 changes: 26 additions & 0 deletions jestAfterSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { server } from 'src/mocks/server'
import fetch from "node-fetch"
import MockDate from "mockdate"
import AirtableAPI from 'airtable'

// import '@testing-library/jest-dom'
// import { createSerializer } from "@emotion/jest"
// import "@testing-library/jest-dom/extend-expect"
// @ts-ignore
global.fetch = fetch
// expect.addSnapshotSerializer(createSerializer())
AirtableAPI.apiKey = "TEST_AIRTABLE_KEY"
// Establish API mocking before all tests.
beforeAll(() => {
MockDate.set("2020-04-24")
server.listen()

})
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => {
MockDate.reset()
server.close()
})
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="next" />
/// <reference types="next/types/global" />

import { CSSProp } from '@emotion/core'
import { CSSProp } from '@emotion/react'

declare module 'react' {
interface Attributes {
Expand Down
32 changes: 32 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
reactStrictMode: true,
experimental: {
modern: true,
scss: false,
Expand All @@ -17,5 +18,36 @@ module.exports = {
],
})
return config
},
async headers() {
return [
{
source: '/',
headers: [
{
key: "Cache-Control",
value: "public; max-age=60, stale-while-revalidate=600",
},
],
},
{
source: '/:other',
headers: [
{
key: "Cache-Control",
value: "public; max-age=60, stale-while-revalidate=600",
},
],
},
{
source: '/api/:any',
headers: [
{
key: "Cache-Control",
value: "public; max-age=10, stale-while-revalidate=20",
},
],
},
]
}
}
49 changes: 26 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@celo/reserve-web",
"version": "1.0.0",
"version": "2.0.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -15,49 +15,52 @@
"postinstall": "yarn keys:decrypt",
"keys:decrypt": "bash scripts/key_placer.sh decrypt",
"keys:encrypt": "bash scripts/key_placer.sh encrypt",
"start": "next start -p $PORT"
"start": "next start -p $PORT",
"test": "jest"
},
"dependencies": {
"@emotion/core": "^10.0.28",
"@celo/contractkit": "1.1.0-beta.1",
"@emotion/react": "^11.1.5",
"airtable": "^0.8.1",
"bignumber.js": "^9.0.1",
"fathom-client": "^3.0.0",
"front-matter": "^4.0.2",
"markdown-to-jsx": "^6.11.4",
"markdown-to-jsx": "^7.1.1",
"mockdate": "^3.0.2",
"next": "^10.0.5",
"node-cache": "^5.1.2",
"raw-loader": "^4.0.1",
"react": "16.13.1",
"react-dom": "16.13.1"
"react": "^17.0.1",
"react-dom": "^17.0.1",
"swr": "^0.4.2",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@babel/cli": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@babel/runtime": "^7.8.4",
"@types/jest": "^25.1.4",
"@types/node": "^10.12.18",
"@types/react": "^16.9.34",
"babel-jest": "^26.1.0",
"@emotion/babel-plugin": "^11.2.0",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/react": "^17.0.2",
"@types/xml2js": "^0.4.8",
"babel-jest": "^26.6.3",
"codecov": "^3.6.5",
"husky": "^3.0.0",
"jest": "^26.1.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-junit": "^10.0.0",
"jest-snapshot": "^26.1.0",
"lerna": "^3.16.0",
"patch-package": "^6.2.2",
"msw": "^0.27.0",
"node-fetch": "^2.6.1",
"prettier": "1.19.1",
"prettier-plugin-java": "^0.6.0",
"prettier-plugin-solidity": "1.0.0-alpha.35",
"pretty-quick": "^2.0.1",
"solc": "0.5.8",
"ts-jest": "^26.1.1",
"ts-node": "^8.3.0",
"ts-jest": "^26.5.1",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.8.0",
"tslint": "^5.20.0",
"typescript": "^3.8.3",
"typescript-tslint-plugin": "^0.5.4"
"typescript": "^4.2.3"
},
"engines": {
"node": "10"
"node": "14"
}
}
3 changes: 2 additions & 1 deletion production.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
runtime: nodejs10
runtime: nodejs14
env: standard
service: default
instance_class: F4
default_expiration: 366d
env_variables:
NODE_ENV: 'production'
DEPLOY_ENV: 'production'
Expand Down
Binary file removed public/assets/CELO.png
Binary file not shown.
Binary file removed public/assets/CUSD.png
Binary file not shown.
Loading

0 comments on commit a9f6b8b

Please sign in to comment.