Skip to content

Commit

Permalink
Merge pull request Uniswap#28 from royalaid/main
Browse files Browse the repository at this point in the history
Add fallback token check github action
  • Loading branch information
publu authored Nov 8, 2022
2 parents 7c53263 + 491139b commit 91572f4
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 27 deletions.
29 changes: 8 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,26 @@ env:
on:
pull_request:
branches:
- v2
- main
push:
branches:
- v2
- main

jobs:
test:
strategy:
matrix:
node: ['10.x', '12.x']
node: ['16.x']
os: [ubuntu-latest, macOS-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- run: npm install -g yarn

- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
node-version: '16'
cache: 'yarn'
- run: yarn

- run: yarn lint
- run: yarn build
- run: yarn test
- run: yarn run checkTokens
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"repository": "https://github.com/royalaid/sushiswap-sdk",
"keywords": [],
"scripts": {
"build": "microbundle",
"start": "microbundle watch",
"prepack": "typechain --discriminate-types --target ethers-v5 --out-dir src/contracts \"src/abis/toGenerate/**/*.json\" && microbundle"
"checkTokens": "node src/scripts/validateCoinGeckoFallbackTokens.mjs",
"build": "typechain --discriminate-types --target ethers-v5 --out-dir src/contracts \"src/abis/toGenerate/**/*.json\" && microbundle",
"start": "microbundle watch"
},
"dependencies": {
"big.js": "5.2.2",
Expand Down Expand Up @@ -52,7 +52,9 @@
"@types/jest": "28.1.6",
"@types/lodash": "^4.14.185",
"ethers": "5.7.0",
"isomorphic-fetch":" ^3.0.0",
"microbundle": "0.15.1",
"p-queue": "^7.3.0",
"typechain": "8.1.0",
"typescript": "4.7.4"
},
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export const MULTICALL_NETWORKS: { [chainId in ChainId]: string } = {
export const WFTM_ADDRESS = '0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83'
export const STETH_ADDRESS = '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84'
export const METIS_WBTC_ADDRESS = '0xa5B55ab1dAF0F8e1EFc0eB1931a957fd89B918f4';
export const AAVE_ADDRESS = '0xD6DF932A45C0f255f85145f286eA0b292B21C90B';

//CAM Vaults
export const CAMWMATIC_VAULT_ADDRESS = '0x88d84a85A87ED12B8f098e8953B322fF789fCD1a'
export const CAMWETH_VAULT_ADDRESS = '0x11A33631a5B5349AF3F165d2B7901A4d67e561ad'
Expand Down
59 changes: 59 additions & 0 deletions src/scripts/validateCoinGeckoFallbackTokens.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! /usr/bin/env node
import {ChainId, COLLATERALS} from "../../dist/index.modern.mjs";
import PQueue from 'p-queue';
import _ from 'lodash';
import fetch from 'isomorphic-fetch';
const {isEmpty} = _;

const COINGECKO_ID = {
[ChainId.MATIC]: 'polygon-pos',
[ChainId.FANTOM]: 'fantom',
[ChainId.AVALANCHE]: 'avalanche',
[ChainId.METIS]: 'metis-andromeda',
[ChainId.XDAI]: 'xdai',
[ChainId.OPTIMISM]: 'optimistic-ethereum',
[ChainId.ARBITRUM]: 'arbitrum-one',
[ChainId.BSC]: 'binance-smart-chain',
[ChainId.MAINNET]: 'ethereum',
[ChainId.MOONRIVER]: 'moonriver',
[ChainId.MOONBEAM]: 'moonbeam',
[ChainId.HARMONY]: 'harmony-shard-0',
}

function collateralName(c) {
return c?.snapshotName || c?.token?.name + ' on ' + c?.chainId;
}

const main = async () => {
const queue = new PQueue({concurrency: 1, interval: 1200, intervalCap: 1});

const fallBackCollaterals = Object.values(COLLATERALS).flat().filter(c => c.fallbackUnderlyingAddress)

const failingTokens = []
await Promise.all(fallBackCollaterals.map(async c => {
const contractAddress = c.fallbackUnderlyingAddress
const assetPlatform = COINGECKO_ID[c.chainId]
let res = await queue.add(() => fetch(`https://api.coingecko.com/api/v3/coins/${assetPlatform}/contract/${contractAddress?.toLowerCase()}`))
while(res.type === 'error'){
console.log('Fetch Failed')

res = await queue.add(() => fetch(`https://api.coingecko.com/api/v3/coins/${assetPlatform}/contract/${contractAddress?.toLowerCase()}`))
}
const json = await res.json()
if(!json.name){
failingTokens.push({c,json})
}
console.log(`Checked ${collateralName(c)}`)
}))

if(!isEmpty(failingTokens)){
console.log('Failing Tokens')
failingTokens.forEach((c) => {
console.log(collateralName(c))
})
process.exit(1)
}

}

void main()
5 changes: 3 additions & 2 deletions src/vaultInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from './contracts'
import { Token } from './entities'
import {
AAVE_ADDRESS,
CAMAAVE_VAULT_ADDRESS, CAMDAI_VAULT_ADDRESS, CAMWBTC_VAULT_ADDRESS,
CAMWETH_VAULT_ADDRESS,
CAMWMATIC_VAULT_ADDRESS,
Expand Down Expand Up @@ -1180,7 +1181,7 @@ export const COLLATERALS: { [chainId in ChainId]?: (COLLATERAL | GAUGE_VALID_COL
chainId: ChainId.MATIC,
subgraph: 'https://api.thegraph.com/subgraphs/name/0xlaozi/mai-finance-cam-aave-vaults',
vaultAddress: CAMAAVE_VAULT_ADDRESS,
fallbackUnderlyingAddress: "0x87ee36f780ae843A78D5735867bc1c13792b7b11",
fallbackUnderlyingAddress: AAVE_ADDRESS,
token: new Token(
ChainId.MATIC,
'0xeA4040B21cb68afb94889cB60834b13427CFc4EB',
Expand All @@ -1204,7 +1205,7 @@ export const COLLATERALS: { [chainId in ChainId]?: (COLLATERAL | GAUGE_VALID_COL
vaultAddress: '0x87ee36f780ae843A78D5735867bc1c13792b7b11',
contractAbi: Erc20Stablecoin__factory.abi,
connect: Erc20Stablecoin__factory.connect,
token: new Token(ChainId.MATIC, '0xD6DF932A45C0f255f85145f286eA0b292B21C90B', 18, 'AAVE', 'Aave'),
token: new Token(ChainId.MATIC, AAVE_ADDRESS, 18, 'AAVE', 'Aave'),
minimumCDR: 130,
frontend: FRONTEND.MAI,
version: 1,
Expand Down
53 changes: 52 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ [email protected]:
"@ethersproject/web" "5.7.0"
"@ethersproject/wordlists" "5.7.0"

eventemitter3@^4.0.4:
eventemitter3@^4.0.4, eventemitter3@^4.0.7:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==
Expand Down Expand Up @@ -2659,6 +2659,14 @@ is-wsl@^2.2.0:
dependencies:
is-docker "^2.0.0"

"isomorphic-fetch@ ^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
dependencies:
node-fetch "^2.6.1"
whatwg-fetch "^3.4.1"

jake@^10.8.5:
version "10.8.5"
resolved "https://registry.yarnpkg.com/jake/-/jake-10.8.5.tgz#f2183d2c59382cb274226034543b9c03b8164c46"
Expand Down Expand Up @@ -2937,6 +2945,13 @@ nanoid@^3.3.4:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==

node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-releases@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.6.tgz#8a7088c63a55e493845683ebf3c828d8c51c5503"
Expand Down Expand Up @@ -3032,13 +3047,26 @@ p-queue@^6.6.2:
eventemitter3 "^4.0.4"
p-timeout "^3.2.0"

p-queue@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-7.3.0.tgz#90dfa104894b286dc2f3638961380fb6dc262e55"
integrity sha512-5fP+yVQ0qp0rEfZoDTlP2c3RYBgxvRsw30qO+VtPPc95lyvSG+x6USSh1TuLB4n96IO6I8/oXQGsTgtna4q2nQ==
dependencies:
eventemitter3 "^4.0.7"
p-timeout "^5.0.2"

p-timeout@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-3.2.0.tgz#c7e17abc971d2a7962ef83626b35d635acf23dfe"
integrity sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==
dependencies:
p-finally "^1.0.0"

p-timeout@^5.0.2:
version "5.1.0"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-5.1.0.tgz#b3c691cf4415138ce2d9cfe071dba11f0fee085b"
integrity sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew==

p-try@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
Expand Down Expand Up @@ -3828,6 +3856,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/toformat/-/toformat-2.0.0.tgz#7a043fd2dfbe9021a4e36e508835ba32056739d8"
integrity sha512-03SWBVop6nU8bpyZCx7SodpYznbZF5R4ljwNLBcTQzKOD9xuihRo/psX58llS1BMFhhAI08H3luot5GoXJz2pQ==

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==

ts-command-line-args@^2.2.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/ts-command-line-args/-/ts-command-line-args-2.3.1.tgz#b6188e42efc6cf7a8898e438a873fbb15505ddd6"
Expand Down Expand Up @@ -3935,6 +3968,24 @@ util-deprecate@^1.0.2:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

whatwg-fetch@^3.4.1:
version "3.6.2"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c"
integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which-boxed-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"
Expand Down

0 comments on commit 91572f4

Please sign in to comment.