From f2455ac9f4015c198a0bada413035f496942f5a5 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Wed, 6 Sep 2023 13:49:45 -0300 Subject: [PATCH] refactor: use address from npm packages --- package.json | 15 ++-- packages/utils/src/subgraph.ts | 2 +- subgraphs/isolated-pools/config/bsc.json | 6 -- subgraphs/isolated-pools/config/chapel.json | 6 -- subgraphs/isolated-pools/config/index.ts | 55 ++++++++++++++ subgraphs/isolated-pools/config/local.json | 6 -- subgraphs/isolated-pools/config/sepolia.json | 6 -- subgraphs/isolated-pools/package.json | 18 ++--- .../tests/integration/utils/deploy.ts | 4 +- subgraphs/venus-governance/config/index.ts | 75 +++++++++++++++++++ subgraphs/venus-governance/config/local.json | 17 ----- .../venus-governance/config/mainnet.json | 17 ----- .../venus-governance/config/testnet.json | 17 ----- subgraphs/venus-governance/package.json | 16 ++-- subgraphs/venus/config/index.ts | 46 ++++++++++++ subgraphs/venus/config/local.json | 5 -- subgraphs/venus/config/mainnet.json | 5 -- subgraphs/venus/config/testnet.json | 5 -- subgraphs/venus/package.json | 18 ++--- subgraphs/venus/src/constants/addresses.ts | 9 +-- subgraphs/venus/src/constants/config-template | 3 + subgraphs/venus/src/constants/index.ts | 3 + subgraphs/venus/src/operations/create.ts | 20 ++--- .../venus/src/utilities/getBnbPriceInUsd.ts | 18 ----- subgraphs/venus/src/utilities/index.ts | 1 - subgraphs/venus/template.yaml | 2 +- subgraphs/venus/tests/Comptroller.test.ts | 4 +- subgraphs/venus/tests/constants.ts | 8 ++ subgraphs/venus/tests/mocks.ts | 2 +- tsconfig.json | 5 +- yarn.lock | 13 ++-- 31 files changed, 256 insertions(+), 171 deletions(-) delete mode 100644 subgraphs/isolated-pools/config/bsc.json delete mode 100644 subgraphs/isolated-pools/config/chapel.json create mode 100644 subgraphs/isolated-pools/config/index.ts delete mode 100644 subgraphs/isolated-pools/config/local.json delete mode 100644 subgraphs/isolated-pools/config/sepolia.json create mode 100644 subgraphs/venus-governance/config/index.ts delete mode 100644 subgraphs/venus-governance/config/local.json delete mode 100644 subgraphs/venus-governance/config/mainnet.json delete mode 100644 subgraphs/venus-governance/config/testnet.json create mode 100644 subgraphs/venus/config/index.ts delete mode 100644 subgraphs/venus/config/local.json delete mode 100644 subgraphs/venus/config/mainnet.json delete mode 100644 subgraphs/venus/config/testnet.json create mode 100644 subgraphs/venus/src/constants/config-template delete mode 100644 subgraphs/venus/src/utilities/getBnbPriceInUsd.ts create mode 100644 subgraphs/venus/tests/constants.ts diff --git a/package.json b/package.json index a06137fa..50cfa17c 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,14 @@ "codegen": "yarn workspaces foreach run codegen", "create:local": "yarn workspaces foreach run create:local", "build:local": "yarn workspaces foreach run build:local", - "build:testnet": "yarn workspaces foreach run build:testnet", - "build:mainnet": "yarn workspaces foreach run build:mainnet", + "build:chapel": "yarn workspaces foreach run build:chapel", + "build:bsc": "yarn workspaces foreach run build:bsc", "deploy:local": "yarn workspaces foreach run deploy:local", - "deploy:testnet": "yarn workspaces foreach run deploy:testnet", - "deploy:mainnet": "yarn workspaces foreach run deploy:mainnet", + "deploy:chapel": "yarn workspaces foreach run deploy:chapel", + "deploy:bsc": "yarn workspaces foreach run deploy:bsc", "prepare:local": "yarn workspaces foreach run prepare:local", - "prepare:testnet": "yarn workspaces foreach run prepare:testnet", - "prepare:mainnet": "yarn workspaces foreach run prepare:mainnet", + "prepare:chapel": "yarn workspaces foreach run prepare:chapel", + "prepare:bsc": "yarn workspaces foreach run prepare:bsc", "remove:local": "yarn workspaces foreach run remove:local", "generate-subgraph-types": "yarn workspaces foreach run generate-subgraph-types", "lint": "eslint '**/*.{ts,tsx}'", @@ -46,10 +46,11 @@ "@typechain/hardhat": "^6.1.2", "@types/mocha": "^9.1.1", "@types/mustache": "^4.2.1", + "@types/node": "^20.5.9", "@typescript-eslint/eslint-plugin": "^5.40.1", "@typescript-eslint/parser": "^5.40.1", "@venusprotocol/governance-contracts": "^1.0.0", - "@venusprotocol/isolated-pools": "1.0.0", + "@venusprotocol/isolated-pools": "1.3.0", "@venusprotocol/oracle": "^1.4.1", "@venusprotocol/venus-protocol": "^3.0.0-dev.7", "assemblyscript": "0.19.23", diff --git a/packages/utils/src/subgraph.ts b/packages/utils/src/subgraph.ts index e1591cb0..4bfee625 100644 --- a/packages/utils/src/subgraph.ts +++ b/packages/utils/src/subgraph.ts @@ -102,7 +102,7 @@ export const deploy = async ({ exec(`yarn workspace ${packageName} run build:local`, root); exec(`yarn workspace ${packageName} run create:local`, root); exec( - `npx graph deploy ${subgraphAccount}/${subgraphName} --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/ --version-label ${Date.now().toString()}`, + `npx graph deploy ${subgraphAccount}/${subgraphName} --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/ --version-label ${Date.now().toString()}`, root, ); await waitForSubgraphToBeSynced(syncDelay); diff --git a/subgraphs/isolated-pools/config/bsc.json b/subgraphs/isolated-pools/config/bsc.json deleted file mode 100644 index 561522c3..00000000 --- a/subgraphs/isolated-pools/config/bsc.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "network": "bsc", - "poolRegistryAddress": "0x9F7b01A536aFA00EF10310A162877fd792cD0666", - "poolLensAddress": "0xe12da02820fAD83e0369C6De7Ae30721eaB60E32", - "startBlock": "29300000" -} diff --git a/subgraphs/isolated-pools/config/chapel.json b/subgraphs/isolated-pools/config/chapel.json deleted file mode 100644 index 4137fb4b..00000000 --- a/subgraphs/isolated-pools/config/chapel.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "network": "chapel", - "poolRegistryAddress": "0xC85491616Fa949E048F3aAc39fbf5b0703800667", - "poolLensAddress": "0x559936086C5f65b92240012ae0D2F70C082Ac0b0", - "startBlock": "30870000" -} diff --git a/subgraphs/isolated-pools/config/index.ts b/subgraphs/isolated-pools/config/index.ts new file mode 100644 index 00000000..0c759713 --- /dev/null +++ b/subgraphs/isolated-pools/config/index.ts @@ -0,0 +1,55 @@ +import mainnetDeployments from '@venusprotocol/isolated-pools/deployments/bscmainnet.json'; +import sepoliaDeployments from '@venusprotocol/isolated-pools/deployments/bsctestnet.json'; +import chapelDeployments from '@venusprotocol/isolated-pools/deployments/bsctestnet.json'; +import fs from 'fs'; +import Mustache from 'mustache'; + +export const getNetwork = () => { + const supportedNetworks = ['sepolia', 'chapel', 'bsc', 'local'] as const; + const network = process.env.NETWORK; + // @ts-expect-error network env var is unknown here + if (!supportedNetworks.includes(network)) { + throw new Error(`NETWORK env var must be set to one of ${supportedNetworks}`); + } + return network as typeof supportedNetworks[number]; +}; + +const main = () => { + const network = getNetwork(); + const config = { + local: { + network: 'hardhat', + poolRegistryAddress: '0x95401dc811bb5740090279Ba06cfA8fcF6113778', + poolLensAddress: '0x809d550fca64d94Bd9F66E60752A544199cfAC3D', + startBlock: 0, + }, + sepolia: { + network: 'sepolia', + poolRegistryAddress: sepoliaDeployments.contracts.PoolRegistry.address, + poolLensAddress: sepoliaDeployments.contracts.PoolLens.address, + startBlock: '3930059', + }, + chapel: { + network: 'chapel', + poolRegistryAddress: chapelDeployments.contracts.PoolRegistry.address, + poolLensAddress: chapelDeployments.contracts.PoolLens.address, + startBlock: '30870000', + }, + bsc: { + network: 'bsc', + poolRegistryAddress: mainnetDeployments.contracts.PoolRegistry.address, + poolLensAddress: mainnetDeployments.contracts.PoolLens.address, + startBlock: '29300000', + }, + }; + + const yamlTemplate = fs.readFileSync('template.yaml', 'utf8'); + const yamlOutput = Mustache.render(yamlTemplate, config[network]); + fs.writeFileSync('subgraph.yaml', yamlOutput); + + const configTemplate = fs.readFileSync('src/constants/config-template', 'utf8'); + const tsOutput = Mustache.render(configTemplate, config[network]); + fs.writeFileSync('src/constants/config.ts', tsOutput); +}; + +main(); diff --git a/subgraphs/isolated-pools/config/local.json b/subgraphs/isolated-pools/config/local.json deleted file mode 100644 index e547fbe4..00000000 --- a/subgraphs/isolated-pools/config/local.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "network": "hardhat", - "poolRegistryAddress": "0x95401dc811bb5740090279Ba06cfA8fcF6113778", - "poolLensAddress": "0x809d550fca64d94Bd9F66E60752A544199cfAC3D", - "startBlock": 0 -} diff --git a/subgraphs/isolated-pools/config/sepolia.json b/subgraphs/isolated-pools/config/sepolia.json deleted file mode 100644 index 6b239700..00000000 --- a/subgraphs/isolated-pools/config/sepolia.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "network": "sepolia", - "poolRegistryAddress": "0xe7CE0296D5B0a26fB183ceBf800ECC918eBBD738", - "poolLensAddress": "0x57E0b52dBcC63F5c23fEd947e634aF06Fc20C70b", - "startBlock": "3930059" -} diff --git a/subgraphs/isolated-pools/package.json b/subgraphs/isolated-pools/package.json index 01f8c26a..46eda404 100644 --- a/subgraphs/isolated-pools/package.json +++ b/subgraphs/isolated-pools/package.json @@ -16,15 +16,15 @@ "create:docker": "npx graph create venusprotocol/venus-isolated-pools --node http://graph-node:8020/", "build:docker": "npx graph build --ipfs http://ipfs:5001", "build:bsc": "npx graph build --ipfs https://api.thegraph.com/ipfs/ ", - "deploy:local": "LOCAL=true npx mustache config/local.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/", - "deploy:docker": "npx mustache config/local.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools --debug --ipfs http://ipfs:5001 --node http://graph-node:8020/", - "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools-chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:sepolia": "yarn prepare:sepolia && npx graph deploy --studio venus-isolated-pools-sepolia", - "prepare:local": "npx mustache config/local.json template.yaml > subgraph.yaml && npx mustache config/local.json src/constants/config-template > src/constants/config.ts", - "prepare:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts", - "prepare:bsc": "npx mustache config/bsc.json template.yaml > subgraph.yaml && npx mustache config/bsc.json src/constants/config-template > src/constants/config.ts", - "prepare:sepolia": "npx mustache config/sepolia.json template.yaml > subgraph.yaml && npx mustache config/sepolia.json src/constants/config-template > src/constants/config.ts", + "deploy:local": "LOCAL=true prepare:local && npx graph deploy venusprotocol/venus-isolated-pools --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/", + "deploy:docker": "prepare:local && npx graph deploy venusprotocol/venus-isolated-pools --ipfs http://ipfs:5001 --node http://graph-node:8020/", + "deploy:chapel": "prepare:chapel && npx graph deploy venusprotocol/venus-isolated-pools-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:bsc": "prepare:bsc && npx graph deploy venusprotocol/venus-isolated-pools --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:sepolia": "prepare:sepolia && npx graph deploy --studio venus-isolated-pools-sepolia", + "prepare:local": "NETWORK=local npx ts-node config/index.ts", + "prepare:chapel": "NETWORK=chapel npx ts-node config/index.ts", + "prepare:bsc": "NETWORK=chapel npx ts-node config/index.ts", + "prepare:sepolia": "NETWORK=sepolia npx ts-node config/index.ts", "remove:local": "npx graph remove --node http://127.0.0.1:8020/ venusprotocol/venus-isolated-pools", "remove:docker": "npx graph remove --node http://graph-node:8020/ venusprotocol/venus-isolated-pools", "generate-subgraph-types": "rm -rf /subgraph-client/.graphclient && yarn graphclient build --dir ./subgraph-client", diff --git a/subgraphs/isolated-pools/tests/integration/utils/deploy.ts b/subgraphs/isolated-pools/tests/integration/utils/deploy.ts index cf9681c2..6d81d11d 100644 --- a/subgraphs/isolated-pools/tests/integration/utils/deploy.ts +++ b/subgraphs/isolated-pools/tests/integration/utils/deploy.ts @@ -16,8 +16,8 @@ const deploy = async () => { exec(`yarn workspace isolated-pools-subgraph run build:${env}`, root); exec(`yarn workspace isolated-pools-subgraph run create:${env}`, root); const deployCmd = process.env.LOCAL - ? `npx graph deploy ${SUBGRAPH_ACCOUNT}/${SUBGRAPH_NAME} --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/ --version-label ${Date.now().toString()}` - : `npx graph deploy ${SUBGRAPH_ACCOUNT}/${SUBGRAPH_NAME} --debug --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ${Date.now().toString()}`; + ? `npx graph deploy ${SUBGRAPH_ACCOUNT}/${SUBGRAPH_NAME} --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/ --version-label ${Date.now().toString()}` + : `npx graph deploy ${SUBGRAPH_ACCOUNT}/${SUBGRAPH_NAME} --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ${Date.now().toString()}`; exec(deployCmd, root); exec(`echo "" | yarn workspace isolated-pools-subgraph deploy:${env}`, __dirname); await waitForSubgraphToBeSynced(SYNC_DELAY); diff --git a/subgraphs/venus-governance/config/index.ts b/subgraphs/venus-governance/config/index.ts new file mode 100644 index 00000000..976d75c9 --- /dev/null +++ b/subgraphs/venus-governance/config/index.ts @@ -0,0 +1,75 @@ +import fs from 'fs'; +import Mustache from 'mustache'; + +export const getNetwork = () => { + const supportedNetworks = ['chapel', 'bsc', 'local'] as const; + const network = process.env.NETWORK; + // @ts-expect-error network env var is unknown here + if (!supportedNetworks.includes(network)) { + throw new Error(`NETWORK env var must be set to one of ${supportedNetworks}`); + } + return network as typeof supportedNetworks[number]; +}; + +const main = () => { + const network = getNetwork(); + const config = { + local: { + network: 'bsc', + accessControlManagerAddress: '0xc5a5C42992dECbae36851359345FE25997F5C42d', + accessControlManagerStartBlock: '0', + governorAlphaAddress: '0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1', + governorAlphaStartBlock: '0', + governorAlpha2Address: '0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE', + governorAlpha2StartBlock: '0', + governorBravoDelegateAddress: '0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2', + governorBravoDelegateStartBlock: '16002994', + governorBravoDelegate2Address: '0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2', + governorBravoDelegate2StartBlock: '16002994', + xvsTokenAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3', + xvsTokenStartBlock: '0', + xvsVaultAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0', + xvsVaultStartBlock: '0', + }, + chapel: { + network: 'chapel', + accessControlManagerAddress: '0x4a471468cdABA84CEA885aF72129F2e974C3649B', + accessControlManagerStartBlock: '24711629', + governorAlphaAddress: '0x7df10b2118eb04d9806b15198019f83741a9f8f4', + governorAlphaStartBlock: '8205736', + governorAlpha2Address: '0x7116894ed34FC4B27D5b84f46B70Af48397a6C24', + governorAlpha2StartBlock: '13584539', + governorBravoDelegateAddress: '0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2', + governorBravoDelegateStartBlock: '16002994 ', + governorBravoDelegate2Address: '', + governorBravoDelegate2StartBlock: '', + xvsTokenAddress: '0xB9e0E753630434d7863528cc73CB7AC638a7c8ff', + xvsTokenStartBlock: '2802593', + xvsVaultAddress: '0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6', + xvsVaultStartBlock: '13937802', + }, + bsc: { + network: 'bsc', + accessControlManagerAddress: '', + accessControlManagerStartBlock: '', + governorAlphaAddress: '0x406f48f47d25e9caa29f17e7cfbd1dc6878f078f', + governorAlphaStartBlock: '2474351', + governorAlpha2Address: '0x388313BfEFEE8ddfeAD55b585F62812293Cf3A60', + governorAlpha2StartBlock: '11934064', + governorBravoDelegateAddress: '0x2d56dC077072B53571b8252008C60e945108c75a', + governorBravoDelegateStartBlock: '13729317', + governorBravoDelegate2Address: '', + governorBravoDelegate2StartBlock: '', + xvsTokenAddress: '0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63', + xvsTokenStartBlock: '858561', + xvsVaultAddress: '0x6eF49b4e0772Fe78128F981d42D54172b55eCF9F', + xvsVaultStartBlock: '13018718', + }, + }; + + const yamlTemplate = fs.readFileSync('template.yaml', 'utf8'); + const yamlOutput = Mustache.render(yamlTemplate, config[network]); + fs.writeFileSync('subgraph.yaml', yamlOutput); +}; + +main(); diff --git a/subgraphs/venus-governance/config/local.json b/subgraphs/venus-governance/config/local.json deleted file mode 100644 index 29e429ef..00000000 --- a/subgraphs/venus-governance/config/local.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "network": "bsc", - "accessControlManagerAddress": "0xc5a5C42992dECbae36851359345FE25997F5C42d", - "accessControlManagerStartBlock": "0", - "governorAlphaAddress": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", - "governorAlphaStartBlock": "0", - "governorAlpha2Address": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE", - "governorAlpha2StartBlock": "0", - "governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegateStartBlock": "16002994", - "governorBravoDelegate2Address": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegate2StartBlock": "16002994", - "xvsTokenAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3", - "xvsTokenStartBlock": "0", - "xvsVaultAddress": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", - "xvsVaultStartBlock": "0" -} diff --git a/subgraphs/venus-governance/config/mainnet.json b/subgraphs/venus-governance/config/mainnet.json deleted file mode 100644 index 2faf29db..00000000 --- a/subgraphs/venus-governance/config/mainnet.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "network": "bsc", - "accessControlManagerAddress": "", - "accessControlManagerStartBlock": "", - "governorAlphaAddress": "0x406f48f47d25e9caa29f17e7cfbd1dc6878f078f", - "governorAlphaStartBlock": "2474351", - "governorAlpha2Address": "0x388313BfEFEE8ddfeAD55b585F62812293Cf3A60", - "governorAlpha2StartBlock": "11934064", - "governorBravoDelegateAddress": "0x2d56dC077072B53571b8252008C60e945108c75a", - "governorBravoDelegateStartBlock": "13729317", - "governorBravoDelegate2Address": "", - "governorBravoDelegate2StartBlock": "", - "xvsTokenAddress": "0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63", - "xvsTokenStartBlock": "858561", - "xvsVaultAddress": "0x6eF49b4e0772Fe78128F981d42D54172b55eCF9F", - "xvsVaultStartBlock": "13018718" -} diff --git a/subgraphs/venus-governance/config/testnet.json b/subgraphs/venus-governance/config/testnet.json deleted file mode 100644 index ce91b182..00000000 --- a/subgraphs/venus-governance/config/testnet.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "network": "bsc-testnet", - "accessControlManagerAddress": "0x4a471468cdABA84CEA885aF72129F2e974C3649B", - "accessControlManagerStartBlock": "24711629", - "governorAlphaAddress": "0x7df10b2118eb04d9806b15198019f83741a9f8f4", - "governorAlphaStartBlock": "8205736", - "governorAlpha2Address": "0x7116894ed34FC4B27D5b84f46B70Af48397a6C24", - "governorAlpha2StartBlock": "13584539", - "governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegateStartBlock": "16002994 ", - "governorBravoDelegate2Address": "", - "governorBravoDelegate2StartBlock": "", - "xvsTokenAddress": "0xB9e0E753630434d7863528cc73CB7AC638a7c8ff", - "xvsTokenStartBlock": "2802593", - "xvsVaultAddress": "0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6", - "xvsVaultStartBlock": "13937802" -} diff --git a/subgraphs/venus-governance/package.json b/subgraphs/venus-governance/package.json index c938be6f..794fcb47 100644 --- a/subgraphs/venus-governance/package.json +++ b/subgraphs/venus-governance/package.json @@ -13,14 +13,14 @@ "codegen": "graph codegen", "create:local": "graph create venusprotocol/venus-governance --node http://127.0.0.1:8020", "build:local": "graph build --ipfs http://localhost:5001", - "build:mainnet": "graph build --ipfs https://api.thegraph.com/ipfs/ ", - "deploy:integration": "graph deploy venusprotocol/venus-governance --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", - "deploy:local": "npx mustache config/local.json template.yaml > subgraph.yaml && yarn deploy:integration", - "deploy:testnet": "npx mustache config/testnet.json template.yaml > subgraph.yaml && graph deploy venusprotocol/venus-governance-chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:mainnet": "npx mustache config/mainnet.json template.yaml > subgraph.yaml && graph deploy venusprotocol/venus-governance --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "prepare:local": "npx mustache config/local.json template.yaml > subgraph.yaml", - "prepare:testnet": "npx mustache config/testnet.json template.yaml > subgraph.yaml", - "prepare:mainnet": "npx mustache config/mainnet.json template.yaml > subgraph.yaml", + "build:bsc": "graph build --ipfs https://api.thegraph.com/ipfs/ ", + "deploy:integration": "npx graph deploy venusprotocol/venus-governance --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", + "deploy:local": "prepare:local && yarn deploy:integration", + "deploy:chapel": "prepare:chapel && npx graph deploy venusprotocol/venus-governance-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:bsc": "prepare:bsc && npx graph deploy venusprotocol/venus-governance --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "prepare:local": "NETWORK=local npx ts-node config/index.ts", + "prepare:chapel": "NETWORK=chapel npx ts-node config/index.ts", + "prepare:bsc": "NETWORK=bsc npx ts-node config/index.ts", "remove:local": "graph remove --node http://localhost:8020/ venusprotocol/venus-governance", "generate-subgraph-types": "yarn graphclient build --dir ./subgraph-client", "test": "graph test", diff --git a/subgraphs/venus/config/index.ts b/subgraphs/venus/config/index.ts new file mode 100644 index 00000000..f6b13ff1 --- /dev/null +++ b/subgraphs/venus/config/index.ts @@ -0,0 +1,46 @@ +#!/usr/bin/env ts-node +import bscMainnetCoreDeployments from '@venusprotocol/venus-protocol/networks/mainnet.json'; +import bscTestnetCoreDeployments from '@venusprotocol/venus-protocol/networks/testnet.json'; +import fs from 'fs'; +import Mustache from 'mustache'; + +export const getNetwork = () => { + const supportedNetworks = ['chapel', 'bsc', 'local'] as const; + const network = process.env.NETWORK; + // @ts-expect-error network env var is unknown here + if (!supportedNetworks.includes(network)) { + throw new Error(`NETWORK env var must be set to one of ${supportedNetworks}`); + } + return network as typeof supportedNetworks[number]; +}; + +const main = () => { + const network = getNetwork(); + const config = { + local: { + network: 'hardhat', + comptrollerAddress: '0x94d1820b2D1c7c7452A163983Dc888CEC546b77D', + startBlock: '0', + }, + chapel: { + network: 'chapel', + comptrollerAddress: bscTestnetCoreDeployments.Contracts.Comptroller, + startBlock: '2470000', + }, + bsc: { + network: 'bsc', + comptrollerAddress: bscMainnetCoreDeployments.Contracts.Comptroller, + startBlock: '2470000', + }, + }; + + const yamlTemplate = fs.readFileSync('template.yaml', 'utf8'); + const yamlOutput = Mustache.render(yamlTemplate, config[network]); + fs.writeFileSync('subgraph.yaml', yamlOutput); + + const configTemplate = fs.readFileSync('src/constants/config-template', 'utf8'); + const tsOutput = Mustache.render(configTemplate, config[network]); + fs.writeFileSync('src/constants/config.ts', tsOutput); +}; + +main(); diff --git a/subgraphs/venus/config/local.json b/subgraphs/venus/config/local.json deleted file mode 100644 index 3089b8e5..00000000 --- a/subgraphs/venus/config/local.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "network": "bsc-testnet", - "address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", - "startBlock": "0" -} diff --git a/subgraphs/venus/config/mainnet.json b/subgraphs/venus/config/mainnet.json deleted file mode 100644 index 20b93ee9..00000000 --- a/subgraphs/venus/config/mainnet.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "network": "bsc", - "address": "0xfd36e2c2a6789db23113685031d7f16329158384", - "startBlock": "2470000" -} diff --git a/subgraphs/venus/config/testnet.json b/subgraphs/venus/config/testnet.json deleted file mode 100644 index db884110..00000000 --- a/subgraphs/venus/config/testnet.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "network": "bsc-testnet", - "address": "0x94d1820b2D1c7c7452A163983Dc888CEC546b77D", - "startBlock": "2470000" -} diff --git a/subgraphs/venus/package.json b/subgraphs/venus/package.json index 34a45bbb..d239aec3 100644 --- a/subgraphs/venus/package.json +++ b/subgraphs/venus/package.json @@ -11,15 +11,15 @@ ], "scripts": { "codegen": "graph codegen", - "create:local": "LOCAL=true npx graph create venusprotocol/venus-subgraph --node http://127.0.0.1:8020/", - "build:local": "LOCAL=true npx graph build --ipfs http://127.0.0.1:5001", - "build:mainnet": "npx graph build --ipfs https://api.thegraph.com/ipfs/ ", - "deploy:local": "LOCAL=true npx mustache config/local.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020/", - "deploy:testnet": "npx mustache config/testnet.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools-chapel --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "deploy:mainnet": "npx mustache config/mainnet.json template.yaml > subgraph.yaml && npx graph deploy venusprotocol/venus-isolated-pools --debug --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", - "prepare:local": "npx mustache config/local.json template.yaml > subgraph.yaml", - "prepare:testnet": "npx mustache config/testnet.json template.yaml > subgraph.yaml", - "prepare:mainnet": "npx mustache config/mainnet.json template.yaml > subgraph.yaml", + "create:local": "graph create venusprotocol/venus-subgraph --node http://127.0.0.1:8020", + "build:local": "graph build --ipfs http://localhost:5001", + "build:mainnet": "graph build --ipfs https://api.thegraph.com/ipfs/ ", + "deploy:local": "prepare:local && graph deploy venusprotocol/venus-subgraph --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", + "deploy:chapel": "prepare:chapel && npx graph deploy venusprotocol/venus-subgraph-chapel --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "deploy:bsc": "prepare:bsc && npx graph deploy venusprotocol/venus-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", + "prepare:local": "NETWORK=local npx ts-node config/index.ts", + "prepare:chape": "NETWORK=chapel npx ts-node config/index.ts", + "prepare:bsc": "NETWORK=bsc npx ts-node config/index.ts", "test": "graph test", "test:integration": "true" } diff --git a/subgraphs/venus/src/constants/addresses.ts b/subgraphs/venus/src/constants/addresses.ts index 291e0b8c..746760fe 100644 --- a/subgraphs/venus/src/constants/addresses.ts +++ b/subgraphs/venus/src/constants/addresses.ts @@ -1,8 +1,7 @@ import { Address } from '@graphprotocol/graph-ts'; -export const vBnbAddress = Address.fromString('0xA07c5b74C9B40447a954e1466938b865b6BBea36'); -export const interestRateModelAddress = Address.fromString( - '0x594942C0e62eC577889777424CD367545C796A74', -); -export const comptrollerAddress = Address.fromString('0xfd36e2c2a6789db23113685031d7f16329158384'); +import { comptrollerAddress as comptrollerAddressString } from './config'; + +export const comptrollerAddress = Address.fromString(comptrollerAddressString); + export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); diff --git a/subgraphs/venus/src/constants/config-template b/subgraphs/venus/src/constants/config-template new file mode 100644 index 00000000..e68ec726 --- /dev/null +++ b/subgraphs/venus/src/constants/config-template @@ -0,0 +1,3 @@ +// Use yarn prepare commands to generate config typescript file per env + +export const comptrollerAddress = '{{ comptrollerAddress }}'; diff --git a/subgraphs/venus/src/constants/index.ts b/subgraphs/venus/src/constants/index.ts index ccad98aa..97f22b08 100644 --- a/subgraphs/venus/src/constants/index.ts +++ b/subgraphs/venus/src/constants/index.ts @@ -14,6 +14,9 @@ export const EXIT_MARKET = 'EXIT_MARKET'; export const mantissaFactor = 18; export const mantissaFactorBigDecimal: BigDecimal = exponentToBigDecimal(mantissaFactor); +export const NOT_AVAILABLE_BIG_INT = BigInt.fromString('-1'); +export const NOT_AVAILABLE_BIG_DECIMAL = BigDecimal.fromString('-1'); + export const zeroBigDecimal = BigDecimal.fromString('0'); export const zeroBigInt32 = BigInt.fromString('0'); export const oneBigInt = BigInt.fromString('1'); diff --git a/subgraphs/venus/src/operations/create.ts b/subgraphs/venus/src/operations/create.ts index f975b5be..36201579 100644 --- a/subgraphs/venus/src/operations/create.ts +++ b/subgraphs/venus/src/operations/create.ts @@ -5,7 +5,7 @@ import { BEP20 } from '../../generated/templates/VToken/BEP20'; import { VBep20Storage } from '../../generated/templates/VToken/VBep20Storage'; import { VToken } from '../../generated/templates/VToken/VToken'; import { zeroBigDecimal, zeroBigInt32 } from '../constants'; -import { nullAddress, vBnbAddress } from '../constants/addresses'; +import { nullAddress } from '../constants/addresses'; import { getUnderlyingPrice } from '../utilities/getUnderlyingPrice'; export function createAccountVToken( @@ -46,17 +46,19 @@ export function createAccount(accountId: string): Account { export function createMarket(marketAddress: string): Market { let market: Market; - const contract = VToken.bind(Address.fromString(marketAddress)); + const vTokenContract = VToken.bind(Address.fromString(marketAddress)); const marketBep20Storage = VBep20Storage.bind(Address.fromString(marketAddress)); log.debug('[createMarket] market address: {}', [marketAddress]); + const vTokenSymbol = vTokenContract.symbol(); + // It is vBNB, which has a slightly different interface - if (marketAddress == vBnbAddress.toHexString()) { + if (vTokenSymbol == 'vBNB') { market = new Market(marketAddress); market.underlyingAddress = nullAddress; market.underlyingDecimals = 18; - market.underlyingName = 'Binance Coin'; + market.underlyingName = 'BNB'; market.underlyingSymbol = 'BNB'; market.underlyingPriceCents = zeroBigInt32; // It is all other VBEP20 contracts @@ -75,10 +77,10 @@ export function createMarket(marketAddress: string): Market { market.underlyingPriceCents = underlyingPriceCents; } - market.vTokenDecimals = contract.decimals(); + market.vTokenDecimals = vTokenContract.decimals(); - const interestRateModelAddress = contract.try_interestRateModel(); - const reserveFactor = contract.try_reserveFactorMantissa(); + const interestRateModelAddress = vTokenContract.try_interestRateModel(); + const reserveFactor = vTokenContract.try_reserveFactorMantissa(); market.borrowRateMantissa = zeroBigInt32; market.cashMantissa = zeroBigInt32; @@ -87,10 +89,10 @@ export function createMarket(marketAddress: string): Market { market.interestRateModelAddress = interestRateModelAddress.reverted ? nullAddress : interestRateModelAddress.value; - market.name = contract.name(); + market.name = vTokenContract.name(); market.reservesMantissa = BigInt.fromI32(0); market.supplyRateMantissa = zeroBigInt32; - market.symbol = contract.symbol(); + market.symbol = vTokenContract.symbol(); market.totalBorrowsMantissa = zeroBigInt32; market.totalSupplyMantissa = zeroBigInt32; diff --git a/subgraphs/venus/src/utilities/getBnbPriceInUsd.ts b/subgraphs/venus/src/utilities/getBnbPriceInUsd.ts deleted file mode 100644 index d9d51242..00000000 --- a/subgraphs/venus/src/utilities/getBnbPriceInUsd.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Address, BigDecimal } from '@graphprotocol/graph-ts'; - -import { PriceOracle } from '../../generated/templates/VToken/PriceOracle'; -import { mantissaFactorBigDecimal } from '../constants'; -import { vBnbAddress } from '../constants/addresses'; -import { getOrCreateComptroller } from '../operations/getOrCreate'; - -export function getBnbPriceInUsd(): BigDecimal { - const comptroller = getOrCreateComptroller(); - - const oracleAddress = Address.fromBytes(comptroller.priceOracle); - const oracle = PriceOracle.bind(oracleAddress); - const bnbPriceInUSD = oracle - .getUnderlyingPrice(vBnbAddress) - .toBigDecimal() - .div(mantissaFactorBigDecimal); - return bnbPriceInUSD; -} diff --git a/subgraphs/venus/src/utilities/index.ts b/subgraphs/venus/src/utilities/index.ts index d409e6a1..0397b8fa 100644 --- a/subgraphs/venus/src/utilities/index.ts +++ b/subgraphs/venus/src/utilities/index.ts @@ -1,4 +1,3 @@ -export { getBnbPriceInUsd } from './getBnbPriceInUsd'; export { getTokenPriceCents } from './getTokenPriceCents'; export { exponentToBigDecimal } from './exponentToBigDecimal'; export { ensureComptrollerSynced } from './ensureComptrollerSynced'; diff --git a/subgraphs/venus/template.yaml b/subgraphs/venus/template.yaml index 001f0d8c..04639aaf 100644 --- a/subgraphs/venus/template.yaml +++ b/subgraphs/venus/template.yaml @@ -8,7 +8,7 @@ dataSources: name: Comptroller network: {{ network }} source: - address: "{{ address }}" + address: "{{ comptrollerAddress }}" abi: Comptroller startBlock: {{ startBlock }} mapping: diff --git a/subgraphs/venus/tests/Comptroller.test.ts b/subgraphs/venus/tests/Comptroller.test.ts index 15d9e624..75f3b1bf 100644 --- a/subgraphs/venus/tests/Comptroller.test.ts +++ b/subgraphs/venus/tests/Comptroller.test.ts @@ -8,13 +8,13 @@ import { test, } from 'matchstick-as/assembly/index'; +import { handleMarketListed } from '../src/mappings/comptroller'; import { comptrollerAddress, interestRateModelAddress, nullAddress, vBnbAddress, -} from '../src/constants/addresses'; -import { handleMarketListed } from '../src/mappings/comptroller'; +} from './constants'; import { createMarketListedEvent } from './events'; import { createComptrollerMock, createVBep20AndUnderlyingMock } from './mocks'; diff --git a/subgraphs/venus/tests/constants.ts b/subgraphs/venus/tests/constants.ts new file mode 100644 index 00000000..291e0b8c --- /dev/null +++ b/subgraphs/venus/tests/constants.ts @@ -0,0 +1,8 @@ +import { Address } from '@graphprotocol/graph-ts'; + +export const vBnbAddress = Address.fromString('0xA07c5b74C9B40447a954e1466938b865b6BBea36'); +export const interestRateModelAddress = Address.fromString( + '0x594942C0e62eC577889777424CD367545C796A74', +); +export const comptrollerAddress = Address.fromString('0xfd36e2c2a6789db23113685031d7f16329158384'); +export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); diff --git a/subgraphs/venus/tests/mocks.ts b/subgraphs/venus/tests/mocks.ts index 2d4d5e76..48e6d6d5 100644 --- a/subgraphs/venus/tests/mocks.ts +++ b/subgraphs/venus/tests/mocks.ts @@ -1,7 +1,7 @@ import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts'; import { createMockedFunction } from 'matchstick-as'; -import { vBnbAddress } from '../src/constants/addresses'; +import { vBnbAddress } from './constants'; export const mockPriceOracleAddress = Address.fromString( '0x0000000000000000000000000000000000000001', diff --git a/tsconfig.json b/tsconfig.json index d5c0261a..03778313 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,11 +3,12 @@ "compilerOptions": { "baseUrl": ".", "module": "node16", - "types": ["@graphprotocol/graph-ts"], + "types": ["@graphprotocol/graph-ts", "node"], "noLib": false, "lib": ["es2015"], "forceConsistentCasingInFileNames": true, - "esModuleInterop": true + "esModuleInterop": true, + "resolveJsonModule": true }, "include": ["subgraphs", "hardhat.config.ts"] } diff --git a/yarn.lock b/yarn.lock index 8e438796..686c85b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4321,7 +4321,7 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:>=13.7.0": +"@types/node@npm:>=13.7.0, @types/node@npm:^20.5.9": version: 20.5.9 resolution: "@types/node@npm:20.5.9" checksum: 717490e94131722144878b4ca1a963ede1673bb8f2ef78c2f5b50b918df6dc9b35e7f8283e5c2a7a9f137730f7c08dc6228e53d4494a94c9ee16881e6ce6caed @@ -4567,9 +4567,9 @@ __metadata: languageName: node linkType: hard -"@venusprotocol/isolated-pools@npm:1.0.0": - version: 1.0.0 - resolution: "@venusprotocol/isolated-pools@npm:1.0.0" +"@venusprotocol/isolated-pools@npm:1.3.0": + version: 1.3.0 + resolution: "@venusprotocol/isolated-pools@npm:1.3.0" dependencies: "@openzeppelin/contracts": ^4.8.3 "@openzeppelin/contracts-upgradeable": ^4.8.3 @@ -4578,7 +4578,7 @@ __metadata: ethers: ^5.7.0 hardhat-deploy: ^0.11.14 module-alias: ^2.2.2 - checksum: 113533052d71fd3af7a3b6dac6bbc56c7b979bde9e7811cbe0cc92638ed1e7de5f46ede878b2a345c094a9cfea25ef3e2fd06c572987c67019ba4ce260ac7cd9 + checksum: 6f676d3cbd1bd132db329c429081c10796aa9602c97213e0e625a031e6c39e0b369c88c50b225a7d156eec65c595888b657ef012b1cadf4ab854847f39d9b5c4 languageName: node linkType: hard @@ -14852,10 +14852,11 @@ __metadata: "@typechain/hardhat": ^6.1.2 "@types/mocha": ^9.1.1 "@types/mustache": ^4.2.1 + "@types/node": ^20.5.9 "@typescript-eslint/eslint-plugin": ^5.40.1 "@typescript-eslint/parser": ^5.40.1 "@venusprotocol/governance-contracts": ^1.0.0 - "@venusprotocol/isolated-pools": 1.0.0 + "@venusprotocol/isolated-pools": 1.3.0 "@venusprotocol/oracle": ^1.4.1 "@venusprotocol/venus-protocol": ^3.0.0-dev.7 assemblyscript: 0.19.23