From 8f2213e71f7f15432a40e40c5a4fb7bbb54d799a 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 | 42 +++++++++++ subgraphs/venus/config/local.json | 5 -- subgraphs/venus/config/mainnet.json | 5 -- subgraphs/venus/config/testnet.json | 5 -- subgraphs/venus/package.json | 12 +-- subgraphs/venus/src/constants/addresses.ts | 8 -- subgraphs/venus/src/constants/index.ts | 3 - tsconfig.json | 5 +- yarn.lock | 13 ++-- 23 files changed, 216 insertions(+), 142 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 delete mode 100644 subgraphs/venus/src/constants/addresses.ts delete mode 100644 subgraphs/venus/src/constants/index.ts diff --git a/package.json b/package.json index 0677faf9..4ea92567 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": "^0.6.0", "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..808f46c4 --- /dev/null +++ b/subgraphs/venus/config/index.ts @@ -0,0 +1,42 @@ +#!/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', + address: '0x94d1820b2D1c7c7452A163983Dc888CEC546b77D', + startBlock: '0', + }, + chapel: { + network: 'chapel', + address: bscTestnetCoreDeployments.Contracts.Comptroller, + startBlock: '2470000', + }, + bsc: { + network: 'bsc', + address: bscMainnetCoreDeployments.Contracts.Comptroller, + startBlock: '2470000', + }, + }; + + 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/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 942ed3c8..d239aec3 100644 --- a/subgraphs/venus/package.json +++ b/subgraphs/venus/package.json @@ -14,12 +14,12 @@ "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": "npx mustache config/local.json template.yaml > subgraph.yaml && graph deploy venusprotocol/venus-subgraph --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020/", - "deploy:testnet": "npx mustache config/testnet.json template.yaml > subgraph.yaml && graph deploy venusprotocol/venus-subgraph-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-subgraph --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", + "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 deleted file mode 100644 index 291e0b8c..00000000 --- a/subgraphs/venus/src/constants/addresses.ts +++ /dev/null @@ -1,8 +0,0 @@ -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/src/constants/index.ts b/subgraphs/venus/src/constants/index.ts deleted file mode 100644 index 1672fa9f..00000000 --- a/subgraphs/venus/src/constants/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { BigInt } from '@graphprotocol/graph-ts'; - -export const zeroBigInt32 = BigInt.fromString('0'); 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 2aed9ec9..db7bb2a7 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 @@ -14917,10 +14917,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": ^0.6.0 assemblyscript: 0.19.23