Skip to content

Commit

Permalink
Resolve conflicts in economy/indicators.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaFlores committed Jun 9, 2023
2 parents 257220c + fd3c154 commit 9aa9ed5
Show file tree
Hide file tree
Showing 110 changed files with 24,541 additions and 1,342 deletions.
4 changes: 4 additions & 0 deletions .env.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PRIVATE_KEY: ENCRYPTED|fZVIsiQxfRN9PKKDS2IZjCYPmDd67F0tA1MqACVN4pBAQd9U8yGMajY/kJCGS6E5JKatvTScQfBN/DfbxHSUBVa1lYhv89I89uuOYNI4Cp02JxaIJ5svQwxPMkH8H8e/ShYdGxlsbTYaPMYdlrMtcQ==
COINMARKETCAP_API_KEY: ENCRYPTED|FGjF9y6BRs2CP7DJGjVREWmVjy00EuX7LgvskRhHIqYMu2yL0lRxXbCj7SavCnHpga2s6nTTNKopgKWd872GEyJj3d2IpdZxMzQTakGchwNWac+R
SEPOLIA_RPC_URL: ENCRYPTED|NIzCmv7sxfpHJZQp45qyqMIOW9G3so2l3/1ReYoHLjqPdsNUvLfhgr5bgPKnJNYmTU5BxYm0g/ETkr1E+iSdqb8h+GhCdQ9GoulAC8BP/Xl8/SEUuFZV/JZLBckoN+H7wLSCyc1clnwnDFVgoGqrk6Fdm1e9
ETHERSCAN_API_KEY: ENCRYPTED|kBTjB8iCPlKygsp62Tm6+4nKnaBHleki/B4BmmiY3FE1FS1ieEokOd61itGXKJbQu+Jq5FCaGLdXWOSFZLLfPgim6B27oBGEy5WCDsSulD61pA==
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MUMBAI_RPC_URL="https://polygon-mumbai.g.alchemy.com/v2/ExampleKey"
SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/ExampleKey"

PRIVATE_KEY="ExampleKey"
SECOND_PRIVATE_KEY="SECONDWALLET KEY HERE"

ETHERSCAN_API_KEY="ETHERSCAN API key (Get a free one: https://etherscan.io/)"
POLYGONSCAN_API_KEY="POLYGONSCAN API key (Get a free one: https://polygonscan.com/)"

ALPA_VANTANGE_API_key="PRIVATE_KEY"
FRED_API_KEY="PRIVATE_KEY"
BLS_API_KEY="PRIVATE_KEY"



11 changes: 11 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Setup
description: Runs basic commands to install dependencies
runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version: 18
- name: npm install
run: npm install
shell: bash
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test & build

on:
push:
branches:
- main
pull_request: ~

concurrency:
group: main-${{ github.ref }}
cancel-in-progress: true

jobs:
run-unit-tests:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- run: npm run test:unit

run-basic-checks:
name: Run linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- run: npm run lint
118 changes: 113 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,119 @@
# vscode
.vscode

# hardhat
artifacts
cache
deployments
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts
# don't push the environment vars!
*.env

# These environment variables are encrypted, but should not be pushed unless a secure password is used
.env.enc

# Built application files
.DS*
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

gas-report.txt

contracts/test/fuzzing/crytic-export

Functions-request.json
offchain-secrets.json

allowlist.csv
invalidUsers.csv
updatedAllowlist.csv

# OpenZeppelin Upgrades local network artifacts
.openzeppelin

# Chainlink Functions request artifacts
.chainlink_functions
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hardhat.config.js
scripts
test
.env
17 changes: 3 additions & 14 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"no-unused-vars": "error",
"payable-fallback": "error",
"quotes": ["error","single"],
"const-name-snakecase": "error",
"contract-name-camelcase": "error",
"event-name-camelcase": "error",
"func-name-mixedcase": "error",
"func-param-name-mixedcase": "warn",
"private-vars-leading-underscore": "off",
"var-name-mixedcase": "error",
"imports-on-top": "error",
"compiler-version": "off",
"func-visibility": ["warn",{"ignoreConstructors":true}]
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["warn", { "ignoreConstructors": true }]
}
}
}
4 changes: 1 addition & 3 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
deploy
scripts
test
contracts/test
94 changes: 94 additions & 0 deletions API-request-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// This example shows how to make a decentralized price feed using multiple APIs

// Arguments can be provided when a request is initated on-chain and used in the request source code as shown below
const coinMarketCapCoinId = args[0]
const coinGeckoCoinId = args[1]
const coinPaprikaCoinId = args[2]
const badApiCoinId = args[3]

if (
secrets.apiKey == "" ||
secrets.apiKey === "Your coinmarketcap API key (get a free one: https://coinmarketcap.com/api/)"
) {
throw Error(
"COINMARKETCAP_API_KEY environment variable not set for CoinMarketCap API. Get a free key from https://coinmarketcap.com/api/"
)
}

// To make an HTTP request, use the Functions.makeHttpRequest function
// Functions.makeHttpRequest function parameters:
// - url
// - method (optional, defaults to 'GET')
// - headers: headers supplied as an object (optional)
// - params: URL query parameters supplied as an object (optional)
// - data: request body supplied as an object (optional)
// - timeout: maximum request duration in ms (optional, defaults to 10000ms)
// - responseType: expected response type (optional, defaults to 'json')

// Use multiple APIs & aggregate the results to enhance decentralization
const coinMarketCapRequest = Functions.makeHttpRequest({
url: `https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?convert=USD&id=${coinMarketCapCoinId}`,
// Get a free API key from https://coinmarketcap.com/api/
headers: { "X-CMC_PRO_API_KEY": secrets.apiKey },
})
const coinGeckoRequest = Functions.makeHttpRequest({
url: `https://api.coingecko.com/api/v3/simple/price?ids=${coinGeckoCoinId}&vs_currencies=usd`,
})
const coinPaprikaRequest = Functions.makeHttpRequest({
url: `https://api.coinpaprika.com/v1/tickers/${coinPaprikaCoinId}`,
})
// This dummy request simulates a failed API request
const badApiRequest = Functions.makeHttpRequest({
url: `https://badapi.com/price/symbol/${badApiCoinId}`,
})

// First, execute all the API requests are executed concurrently, then wait for the responses
const [coinMarketCapResponse, coinGeckoResponse, coinPaprikaResponse, badApiResponse] = await Promise.all([
coinMarketCapRequest,
coinGeckoRequest,
coinPaprikaRequest,
badApiRequest,
])

const prices = []

if (!coinMarketCapResponse.error) {
prices.push(coinMarketCapResponse.data.data[coinMarketCapCoinId].quote.USD.price)
} else {
console.log("CoinMarketCap Error")
}
if (!coinGeckoResponse.error) {
prices.push(coinGeckoResponse.data[coinGeckoCoinId].usd)
} else {
console.log("CoinGecko Error")
}
if (!coinPaprikaResponse.error) {
prices.push(coinPaprikaResponse.data.quotes.USD.price)
} else {
console.log("CoinPaprika Error")
}
// A single failed API request does not cause the whole request to fail
if (!badApiResponse.error) {
prices.push(httpResponses[3].data.price.usd)
} else {
console.log(
"Bad API request failed. (This message is expected to demonstrate using console.log for debugging locally with the simulator)"
)
}

// At least 3 out of 4 prices are needed to aggregate the median price
if (prices.length < 3) {
// If an error is thrown, it will be returned back to the smart contract
throw Error("More than 1 API failed")
}

const medianPrice = prices.sort((a, b) => a - b)[Math.round(prices.length / 2)]
console.log(`Median Bitcoin price: $${medianPrice.toFixed(2)}`)

// The source code MUST return a Buffer or the request will return an error message
// Use one of the following functions to convert to a Buffer representing the response bytes that are returned to the client smart contract:
// - Functions.encodeUint256
// - Functions.encodeInt256
// - Functions.encodeString
// Or return a custom Buffer for a custom byte encoding
return Functions.encodeUint256(Math.round(medianPrice * 100))
49 changes: 49 additions & 0 deletions Functions-request-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require("fs")

// Loads environment variables from .env.enc file (if it exists)
require("@chainlink/env-enc").config()

const Location = {
Inline: 0,
Remote: 1,
}

const CodeLanguage = {
JavaScript: 0,
}

const ReturnType = {
uint: "uint256",
uint256: "uint256",
int: "int256",
int256: "int256",
string: "string",
bytes: "Buffer",
Buffer: "Buffer",
}

// Configure the request by setting the fields below
const requestConfig = {
// Location of source code (only Inline is currently supported)
codeLocation: Location.Inline,
// Code language (only JavaScript is currently supported)
codeLanguage: CodeLanguage.JavaScript,
// String containing the source code to be executed
//source: fs.readFileSync("./prove.js").toString(),
source: fs.readFileSync("./fetch-prediction-data.js").toString(),
// source: fs.readFileSync("./fetch-risk.js").toString(),
// Secrets can be accessed within the source code with `secrets.varName` (ie: secrets.apiKey). The secrets object can only contain string values.
//secrets: { apiKey: process.env.COINMARKETCAP_API_KEY ?? "" },
// Per-node secrets objects assigned to each DON member. When using per-node secrets, nodes can only use secrets which they have been assigned.
perNodeSecrets: [],
// ETH wallet key used to sign secrets so they cannot be accessed by a 3rd party
walletPrivateKey: process.env["PRIVATE_KEY"],
// Args (string only array) can be accessed within the source code with `args[index]` (ie: args[0]).
args: [],
// Expected type of the returned value
expectedReturnType: ReturnType.Buffer,
// Redundant URLs which point to encrypted off-chain secrets
secretsURLs: [],
}

module.exports = requestConfig
Loading

0 comments on commit 9aa9ed5

Please sign in to comment.