diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3d9d9c90..4d49cd09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,19 +61,33 @@ jobs: shell: bash run: sleep 45s - - name: Generate graphql types + - name: Generate Isolated Pools graphql types run: | - docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run prepare:docker - docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run codegen - docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run create:docker - docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run deploy:docker + docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run prepare:docker + docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run codegen + docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run create:docker + docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run deploy:docker sleep 5s - docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run generate-subgraph-types + docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run generate-subgraph-types - - name: Run integration tests + - name: Run Isolated Pools integration integration tests run: | docker exec -i subgraph-hardhat-node yarn workspace isolated-pools-subgraph run test:integration + - name: Generate Governance graphql types + run: | + docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run prepare:local + docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run codegen + docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run create:docker + docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run deploy:docker + sleep 5s + docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run generate-subgraph-types + + # @TODO - turn on once the integration tests pass + # - name: Run Governance integration integration tests + # run: | + # docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run test:integration + - name: Stop containers if: always() run: | diff --git a/copy_contracts.sh b/copy_contracts.sh index 3e67f45d..bb342a3b 100755 --- a/copy_contracts.sh +++ b/copy_contracts.sh @@ -1,5 +1,7 @@ #! /bin/sh -# For convience we are going to copy contracts and artifacts locally so they can be +# For convience we are going to copy contracts and artifacts locally so they can be +# Make sure packages are patched properly +yarn patch-package rm -rf ./contracts mkdir -p ./contracts/isolated-pools @@ -14,5 +16,10 @@ mkdir -p ./contracts/protocol cp -rf ./node_modules/@venusprotocol/venus-protocol/contracts/ ./contracts/protocol/contracts rm -rf contracts/protocol/contracts/test +rm contracts/protocol/contracts/Governance/GovernorBravoDelegate.sol +rm contracts/protocol/contracts/Governance/GovernorBravoDelegator.sol +rm contracts/protocol/contracts/Governance/Timelock.sol +rm -rf contracts/protocol/contracts/Lens/VenusLens.sol + mkdir -p ./contracts/mocks cp -rf ./mocks/ ./contracts/mocks/contracts diff --git a/deploy/000-governance-access-control.ts b/deploy/000-governance-access-control.ts new file mode 100644 index 00000000..593a6cb1 --- /dev/null +++ b/deploy/000-governance-access-control.ts @@ -0,0 +1,20 @@ +import accessControl from '@venusprotocol/governance-contracts/dist/deploy/001-access-control'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployments, getNamedAccounts } = hre; + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + await deploy('Timelock', { + from: deployer, + args: [deployer, 3600], + log: true, + autoMine: true, + }); + + await accessControl(hre); +}; + +export default func; diff --git a/deploy/001-deploy-mock-tokens.ts b/deploy/001-deploy-mock-tokens.ts index 2609d3d9..7d33bd18 100644 --- a/deploy/001-deploy-mock-tokens.ts +++ b/deploy/001-deploy-mock-tokens.ts @@ -1,5 +1,3 @@ import deployMockTokens from '@venusprotocol/isolated-pools/dist/deploy/001-deploy-mock-tokens'; -deployMockTokens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployMockTokens; diff --git a/deploy/002-deploy-oracles.ts b/deploy/002-deploy-oracles.ts index f8fd6daa..b4bff90e 100644 --- a/deploy/002-deploy-oracles.ts +++ b/deploy/002-deploy-oracles.ts @@ -1,5 +1,3 @@ import deployOracle from '@venusprotocol/oracle/dist/deploy/1-deploy-oracles'; -deployOracle.skip = async () => process.env.PACKAGE == 'venus-governance'; - export default deployOracle; diff --git a/deploy/003-configure-feeds.ts b/deploy/003-configure-feeds.ts index d9d68035..7d1796ea 100644 --- a/deploy/003-configure-feeds.ts +++ b/deploy/003-configure-feeds.ts @@ -1,5 +1,3 @@ import configureFeeds from '@venusprotocol/oracle/dist/deploy/2-configure-feeds'; -configureFeeds.skip = async () => process.env.PACKAGE == 'venus-governance'; - export default configureFeeds; diff --git a/deploy/004-swap-router.ts b/deploy/004-swap-router.ts index f9f0978f..bff4eb12 100644 --- a/deploy/004-swap-router.ts +++ b/deploy/004-swap-router.ts @@ -1,5 +1,3 @@ import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/004-swap-router'; -deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployPoolLens; diff --git a/deploy/005-access-control.ts b/deploy/005-access-control.ts index 06533a57..763d7556 100644 --- a/deploy/005-access-control.ts +++ b/deploy/005-access-control.ts @@ -1,5 +1,3 @@ import accessControl from '@venusprotocol/isolated-pools/dist/deploy/005-access-control'; -accessControl.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default accessControl; diff --git a/deploy/006-deploy-pool-registry.ts b/deploy/006-deploy-pool-registry.ts index b6ea070f..24e77069 100644 --- a/deploy/006-deploy-pool-registry.ts +++ b/deploy/006-deploy-pool-registry.ts @@ -1,5 +1,3 @@ import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/006-deploy-pool-registry'; -deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployPoolLens; diff --git a/deploy/007-deploy-pool-lens.ts b/deploy/007-deploy-pool-lens.ts index 56e3aa6d..be183330 100644 --- a/deploy/007-deploy-pool-lens.ts +++ b/deploy/007-deploy-pool-lens.ts @@ -1,5 +1,3 @@ import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/007-deploy-pool-lens'; -deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployPoolLens; diff --git a/deploy/008-deploy-comptrollers.ts b/deploy/008-deploy-comptrollers.ts index 7b30d832..e1f09c1a 100644 --- a/deploy/008-deploy-comptrollers.ts +++ b/deploy/008-deploy-comptrollers.ts @@ -1,5 +1,3 @@ import accessControlConfigure from '@venusprotocol/isolated-pools/dist/deploy/008-deploy-comptrollers'; -accessControlConfigure.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default accessControlConfigure; diff --git a/deploy/009-deploy-vtokens.ts b/deploy/009-deploy-vtokens.ts index 25bfc500..c2bd90df 100644 --- a/deploy/009-deploy-vtokens.ts +++ b/deploy/009-deploy-vtokens.ts @@ -1,5 +1,3 @@ import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/009-deploy-vtokens'; -deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployPoolLens; diff --git a/deploy/010-deploy-reward-distributors.ts b/deploy/010-deploy-reward-distributors.ts index ad55b177..ccff235a 100644 --- a/deploy/010-deploy-reward-distributors.ts +++ b/deploy/010-deploy-reward-distributors.ts @@ -1,5 +1,3 @@ import deployPoolLens from '@venusprotocol/isolated-pools/dist/deploy/010-deploy-reward-distributors'; -deployPoolLens.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default deployPoolLens; diff --git a/deploy/011-initial-liquidity.ts b/deploy/011-initial-liquidity.ts index d3ffedc3..c1766a66 100644 --- a/deploy/011-initial-liquidity.ts +++ b/deploy/011-initial-liquidity.ts @@ -1,5 +1,3 @@ import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/011-initial-liquidity'; -upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default upgradeComptroller; diff --git a/deploy/012-transfer-pools-ownership.ts b/deploy/012-transfer-pools-ownership.ts index 18b56c44..5055aafe 100644 --- a/deploy/012-transfer-pools-ownership.ts +++ b/deploy/012-transfer-pools-ownership.ts @@ -1,5 +1,3 @@ import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/012-transfer-pools-ownership'; -upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default upgradeComptroller; diff --git a/deploy/013-vip-based-config.ts b/deploy/013-vip-based-config.ts index 5cc97bff..bd1d51fd 100644 --- a/deploy/013-vip-based-config.ts +++ b/deploy/013-vip-based-config.ts @@ -1,5 +1,3 @@ import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/013-vip-based-config'; -upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default upgradeComptroller; diff --git a/deploy/014-riskfund-protocolshare.ts b/deploy/014-riskfund-protocolshare.ts index 699c06a0..f6b04573 100644 --- a/deploy/014-riskfund-protocolshare.ts +++ b/deploy/014-riskfund-protocolshare.ts @@ -1,5 +1,3 @@ import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/014-riskfund-protocolshare'; -upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default upgradeComptroller; diff --git a/deploy/015-transfer-funds-ownership.ts b/deploy/015-transfer-funds-ownership.ts index d0295bd4..068e3d5a 100644 --- a/deploy/015-transfer-funds-ownership.ts +++ b/deploy/015-transfer-funds-ownership.ts @@ -1,5 +1,3 @@ import upgradeComptroller from '@venusprotocol/isolated-pools/dist/deploy/015-funds-config'; -upgradeComptroller.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default upgradeComptroller; diff --git a/deploy/016-scenario.ts b/deploy/016-scenario.ts index ac593dc5..5bb182ab 100644 --- a/deploy/016-scenario.ts +++ b/deploy/016-scenario.ts @@ -16,6 +16,4 @@ const scenarios: DeployFunction = async function (hre: HardhatRuntimeEnvironment await pool1Comptroller.connect(addressSigner).enterMarkets(pools[0].vTokens.map(m => m.vToken)); }; -scenarios.skip = async () => process.env.PACKAGE !== 'isolated-pools'; - export default scenarios; diff --git a/deploy/017-vaults.ts b/deploy/017-vaults.ts new file mode 100644 index 00000000..e2bf9dd3 --- /dev/null +++ b/deploy/017-vaults.ts @@ -0,0 +1,64 @@ +import { ethers } from 'hardhat'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployments, getNamedAccounts } = hre; + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + const xvsDeployment = await deploy('XVS', { + from: deployer, + args: [deployer], + log: true, + autoMine: true, + }); + const xvsAddress = xvsDeployment.address; + + const xvsVaultDeployment = await deploy('XVSVault', { + from: deployer, + args: [], + log: true, + autoMine: true, + }); + + const xvsVaultAddress = xvsVaultDeployment.address; + + const xvsVaultProxyDeployment = await deploy('XVSVaultProxy', { + from: deployer, + args: [], + log: true, + autoMine: true, + }); + + const xvsVaultProxyAddress = xvsVaultProxyDeployment.address; + + await deploy('XVSStore', { + from: deployer, + args: [], + log: true, + autoMine: true, + }); + + const xvsVault = await ethers.getContract('XVSVault'); + const xvsStore = await ethers.getContract('XVSStore'); + const xvsVaultProxy = await ethers.getContract('XVSVaultProxy'); + const accessControlManager = await ethers.getContract('AccessControlManager'); + + let txn = await xvsVault.setXvsStore(xvsAddress, xvsStore.address); + await txn.wait(1); + + txn = await xvsVault.setAccessControl(accessControlManager.address); + await txn.wait(1); + + // Become Implementation of XVSVaultProxy + await xvsVaultProxy._setPendingImplementation(xvsVaultAddress); + await xvsVault._become(xvsVaultProxyAddress); + + // Set new owner to xvs store + await xvsStore.setNewOwner(xvsVaultAddress); +}; + +func.tags = ['XVS vault']; + +export default func; diff --git a/deploy/018-governance.ts b/deploy/018-governance.ts new file mode 100644 index 00000000..dd25cc7f --- /dev/null +++ b/deploy/018-governance.ts @@ -0,0 +1,78 @@ +import { ethers } from 'hardhat'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployments, getNamedAccounts } = hre; + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + const timelock = await ethers.getContract('Timelock'); + const xvsVault = await ethers.getContract('XVSVault'); + + await deploy('GovernorAlpha', { + from: deployer, + args: [timelock.address, xvsVault.address, deployer], + log: true, + autoMine: true, + }); + + await deploy('GovernorAlpha2', { + from: deployer, + args: [timelock.address, xvsVault.address, deployer, 20], + log: true, + autoMine: true, + }); + + const governorBravoDelegateDeployment = await deploy('GovernorBravoDelegate', { + from: deployer, + args: [], + log: true, + autoMine: true, + }); + + const governorBravoDelegate = await ethers.getContractAt( + 'GovernorBravoDelegate', + governorBravoDelegateDeployment.address, + ); + const minVotingDelay = await governorBravoDelegate.MIN_VOTING_DELAY(); + const minVotingPeriod = await governorBravoDelegate.MIN_VOTING_PERIOD(); + const minProposalThreshold = await governorBravoDelegate.MIN_PROPOSAL_THRESHOLD(); + const proposalConfigs = [ + { + votingDelay: minVotingDelay.add(3), + votingPeriod: minVotingPeriod.add(3), + proposalThreshold: minProposalThreshold.add(3), + }, + { + votingDelay: minVotingDelay.add(2), + votingPeriod: minVotingPeriod.add(2), + proposalThreshold: minProposalThreshold.add(2), + }, + { + votingDelay: minVotingDelay.add(1), + votingPeriod: minVotingPeriod.add(1), + proposalThreshold: minProposalThreshold.add(1), + }, + ]; + + const timelocks = [timelock.address, timelock.address, timelock.address]; + + await deploy('GovernorBravoDelegator', { + from: deployer, + args: [ + xvsVault.address, + deployer, + governorBravoDelegate.address, + proposalConfigs, + timelocks, + deployer, + ], + log: true, + autoMine: true, + }); +}; + +func.tags = ['Governance']; + +export default func; diff --git a/deploy/019-configure-vaults.ts b/deploy/019-configure-vaults.ts new file mode 100644 index 00000000..f911ecda --- /dev/null +++ b/deploy/019-configure-vaults.ts @@ -0,0 +1,31 @@ +import { ethers } from 'hardhat'; +import { DeployFunction } from 'hardhat-deploy/types'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { getNamedAccounts } = hre; + const { deployer } = await getNamedAccounts(); + + const accessControlManager = await ethers.getContract('AccessControlManager'); + const xvsVault = await ethers.getContract('XVSVault'); + const xvs = await ethers.getContract('XVS'); + + const tx = await accessControlManager.giveCallPermission( + ethers.constants.AddressZero, + 'add(address,uint256,address,uint256,uint256)', + deployer, + ); + await tx.wait(); + // Add token pool to xvs vault + const allocPoint = 100; + const token = xvs.address; + const rewardToken = xvs.address; + const rewardPerBlock = ethers.BigNumber.from(10).pow(16).toString(); + const lockPeriod = 300; + + await xvsVault.add(rewardToken, allocPoint, token, rewardPerBlock, lockPeriod); +}; + +func.tags = ['Configure XVS Vault']; + +export default func; diff --git a/docker-compose.yaml b/docker-compose.yaml index 03468141..a7bcee46 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,7 +16,7 @@ services: postgres: condition: service_started healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8000"] + test: ["CMD", "curl", "-f", "http://graph-node:8000"] interval: 30s timeout: 12s retries: 10 @@ -45,7 +45,6 @@ services: volumes: - ./:/usr/app - /usr/app/node_modules - - /usr/app/contracts restart: always healthcheck: test: ["CMD", "node", "./hardhat-healthcheck.js"] diff --git a/hardhat.config.ts b/hardhat.config.ts index 6f9126c6..f9770971 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,8 +1,8 @@ import 'module-alias/register'; import '@nomicfoundation/hardhat-toolbox'; import 'hardhat-deploy'; +import 'hardhat-dependency-compiler'; import { HardhatUserConfig } from 'hardhat/config'; -import 'module-alias/register'; const compilers = { compilers: [ @@ -88,6 +88,13 @@ const config: HardhatUserConfig = { sources: `${__dirname}/contracts`, artifacts: `${__dirname}/artifacts`, }, + dependencyCompiler: { + paths: [ + '@venusprotocol/governance-contracts/contracts/Governance/Timelock.sol', + '@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegate.sol', + '@venusprotocol/governance-contracts/contracts/Governance/GovernorBravoDelegator.sol', + ], + }, // Hardhat deploy namedAccounts: { deployer: 0, // here this will by default take the first account as deployer diff --git a/package.json b/package.json index 19d4caa5..79230496 100644 --- a/package.json +++ b/package.json @@ -48,10 +48,10 @@ "@types/mustache": "^4.2.1", "@typescript-eslint/eslint-plugin": "^5.40.1", "@typescript-eslint/parser": "^5.40.1", - "@venusprotocol/governance-contracts": "^1.0.0", + "@venusprotocol/governance-contracts": "^1.1.0-dev.1", "@venusprotocol/isolated-pools": "2.1.0-dev.2", "@venusprotocol/oracle": "^1.7.2", - "@venusprotocol/venus-protocol": "^3.1.0", + "@venusprotocol/venus-protocol": "3.1.0", "assemblyscript": "0.19.23", "chai": "^4.3.6", "eslint": "^8.25.0", @@ -61,6 +61,7 @@ "graphql": "16.6.0", "graphql-tag": "2.12.6", "hardhat": "^2.10.2", + "hardhat-dependency-compiler": "^1.1.3", "hardhat-deploy": "^0.11.15", "hardhat-deploy-ethers": "^0.3.0-beta.13", "hardhat-gas-reporter": "^1.0.8", @@ -84,7 +85,6 @@ }, "packageManager": "yarn@3.2.2", "_moduleAliases": { - "@nomiclabs/hardhat-ethers": "node_modules/hardhat-deploy-ethers", - "@nomiclabs/hardhat-ethers/types": "hardhat-deploy-ethers/types" + "@nomiclabs/hardhat-ethers": "node_modules/hardhat-deploy-ethers" } } diff --git a/packages/utils/src/subgraph.ts b/packages/utils/src/subgraph.ts index 34b4ce18..5b3fe5a6 100644 --- a/packages/utils/src/subgraph.ts +++ b/packages/utils/src/subgraph.ts @@ -97,10 +97,10 @@ export const deploy = async ({ console.log('Build and deploy subgraph...'); exec(`yarn workspace ${packageName} run prepare:local`, root); exec(`yarn workspace ${packageName} run codegen`, root); - exec(`yarn workspace ${packageName} run build:local`, root); - exec(`yarn workspace ${packageName} run create:local`, root); + exec(`yarn workspace ${packageName} run build:docker`, root); + exec(`yarn workspace ${packageName} run create:docker`, root); exec( - `npx graph deploy ${subgraphAccount}/${subgraphName} --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://ipfs:5001 --node http://graph-node:8020/ --version-label ${Date.now().toString()}`, root, ); await waitForSubgraphToBeSynced(syncDelay); diff --git a/subgraphs/isolated-pools/config/local.json b/subgraphs/isolated-pools/config/local.json index a7b116d4..efffadde 100644 --- a/subgraphs/isolated-pools/config/local.json +++ b/subgraphs/isolated-pools/config/local.json @@ -1,6 +1,6 @@ { "network": "hardhat", - "poolRegistryAddress": "0x3155755b79aA083bd953911C92705B7aA82a18F9", - "poolLensAddress": "0x5bf5b11053e734690269C6B9D438F8C9d48F528A", + "poolRegistryAddress": "0xffa7CA1AEEEbBc30C874d32C7e22F052BbEa0429", + "poolLensAddress": "0x3aade2dcd2df6a8cac689ee797591b2913658659", "startBlock": 0 } diff --git a/subgraphs/isolated-pools/tests/integration/constants.ts b/subgraphs/isolated-pools/tests/integration/constants.ts index 08eae525..ef7ac529 100644 --- a/subgraphs/isolated-pools/tests/integration/constants.ts +++ b/subgraphs/isolated-pools/tests/integration/constants.ts @@ -6,9 +6,9 @@ export const SYNC_DELAY = 2000; export const defaultMarkets = [ { - id: '0x2a810409872afc346f9b5b26571fd6ec42ea4849', + id: '0x8a93d247134d91e0de6f96547cb0204e5be8e5d8', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -16,16 +16,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '700000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', + interestRateModelAddress: '0x2a810409872afc346f9b5b26571fd6ec42ea4849', name: 'Venus ANKR', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vANKR', - underlyingAddress: '0x36c02da8a0983159322a80ffe9f24b1acff8b570', + underlyingAddress: '0x1291be112d480055dafd8a610b7d1e203891c274', underlyingName: 'MockANKR', underlyingSymbol: 'MockANKR', borrowCapMantissa: '3000000000000000000000000', - accrualBlockNumber: 246, + accrualBlockNumber: 249, blockTimestamp: 1694785699, borrowIndexMantissa: '1000000000000000000', reserveFactorMantissa: '250000000000000000', @@ -39,9 +39,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0x38a024c0b412b9d1db8bc398140d00f5af3093d4', + id: '0xb82008565fdc7e44609fa118a4a681e92581e680', pool: { - id: '0xab16a69a5a8c12c732e0deff4be56a70bb64c926', + id: '0x1f10f3ba7acb61b2f50b9d6ddcf91a6f787c0e82', __typename: 'Pool', }, badDebtMantissa: '0', @@ -49,16 +49,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '600000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x525c7063e7c20997baae9bda922159152d0e8417', + interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', name: 'Venus BNX', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vBNX', - underlyingAddress: '0x1613beb3b2c4f22ee086b2b38c1476a3ce7f78e8', + underlyingAddress: '0x95401dc811bb5740090279ba06cfa8fcf6113778', underlyingName: 'MockBNX', underlyingSymbol: 'MockBNX', borrowCapMantissa: '478980000000000000000000', - accrualBlockNumber: 240, + accrualBlockNumber: 243, blockTimestamp: 1694785693, borrowIndexMantissa: '1000000058980213058', reserveFactorMantissa: '250000000000000000', @@ -72,9 +72,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0x40918ba7f132e0acba2ce4de4c4baf9bd2d7d849', + id: '0xd6e1afe5ca8d00a2efc01b89997abe2de47fdfaf', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -82,16 +82,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '600000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x525c7063e7c20997baae9bda922159152d0e8417', + interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', name: 'Venus NFT', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vNFT', - underlyingAddress: '0x7969c5ed335650692bc04293b07f5bf2e7a673c0', + underlyingAddress: '0xfd471836031dc5108809d173a067e8486b9047a3', underlyingName: 'MockNFT', underlyingSymbol: 'MockNFT', borrowCapMantissa: '24654278679000000000000000000', - accrualBlockNumber: 255, + accrualBlockNumber: 258, blockTimestamp: 1694785708, borrowIndexMantissa: '1000000061834094335', reserveFactorMantissa: '250000000000000000', @@ -105,9 +105,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0x8a93d247134d91e0de6f96547cb0204e5be8e5d8', + id: '0xf32d39ff9f6aa7a7a64d7a4f00a54826ef791a55', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -115,16 +115,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '700000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', + interestRateModelAddress: '0x2a810409872afc346f9b5b26571fd6ec42ea4849', name: 'Venus MBOX', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vMBOX', - underlyingAddress: '0xcd8a1c3ba11cf5ecfa6267617243239504a98d90', + underlyingAddress: '0x7969c5ed335650692bc04293b07f5bf2e7a673c0', underlyingName: 'MockMBOX', underlyingSymbol: 'MockMBOX', borrowCapMantissa: '3184294000000000000000000', - accrualBlockNumber: 252, + accrualBlockNumber: 255, blockTimestamp: 1694785705, borrowIndexMantissa: '1000000000000000000', reserveFactorMantissa: '250000000000000000', @@ -138,9 +138,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0x99dbe4aea58e518c50a1c04ae9b48c9f6354612f', + id: '0xca8c8688914e0f7096c920146cd0ad85cd7ae8b9', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -148,16 +148,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '700000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', + interestRateModelAddress: '0x2a810409872afc346f9b5b26571fd6ec42ea4849', name: 'Venus USDD', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vUSDD', - underlyingAddress: '0x5081a39b8a5f0e35a8d959395a630b68b74dd30f', + underlyingAddress: '0x04c89607413713ec9775e14b954286519d836fef', underlyingName: 'MockUSDD', underlyingSymbol: 'MockUSDD', borrowCapMantissa: '1698253000000000000000000', - accrualBlockNumber: 264, + accrualBlockNumber: 267, blockTimestamp: 1694785717, borrowIndexMantissa: '1000000000000000000', reserveFactorMantissa: '100000000000000000', @@ -171,9 +171,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0xb82008565fdc7e44609fa118a4a681e92581e680', + id: '0xb9beecd1a582768711de1ee7b0a1d582d9d72a6c', pool: { - id: '0xab16a69a5a8c12c732e0deff4be56a70bb64c926', + id: '0x1f10f3ba7acb61b2f50b9d6ddcf91a6f787c0e82', __typename: 'Pool', }, badDebtMantissa: '0', @@ -181,16 +181,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '700000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', + interestRateModelAddress: '0x2a810409872afc346f9b5b26571fd6ec42ea4849', name: 'Venus BTCB', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vBTCB', - underlyingAddress: '0x95401dc811bb5740090279ba06cfa8fcf6113778', + underlyingAddress: '0x4826533b4897376654bb4d4ad88b7fafd0c98528', underlyingName: 'MockBTCB', underlyingSymbol: 'MockBTCB', borrowCapMantissa: '1000000000000000000000', - accrualBlockNumber: 243, + accrualBlockNumber: 246, blockTimestamp: 1694785696, borrowIndexMantissa: '1000000000000000000', reserveFactorMantissa: '250000000000000000', @@ -204,9 +204,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0xb9beecd1a582768711de1ee7b0a1d582d9d72a6c', + id: '0x40918ba7f132e0acba2ce4de4c4baf9bd2d7d849', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -214,16 +214,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '600000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x525c7063e7c20997baae9bda922159152d0e8417', + interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', name: 'Venus ankrBNB', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vankrBNB', - underlyingAddress: '0x1291be112d480055dafd8a610b7d1e203891c274', + underlyingAddress: '0xcd8a1c3ba11cf5ecfa6267617243239504a98d90', underlyingName: 'MockankrBNB', underlyingSymbol: 'MockankrBNB', borrowCapMantissa: '100000000000000000000', - accrualBlockNumber: 249, + accrualBlockNumber: 252, blockTimestamp: 1694785702, borrowIndexMantissa: '1000000059931506817', reserveFactorMantissa: '250000000000000000', @@ -237,9 +237,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0xd6e1afe5ca8d00a2efc01b89997abe2de47fdfaf', + id: '0x6f6f570f45833e249e27022648a26f4076f48f78', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -247,16 +247,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '600000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x525c7063e7c20997baae9bda922159152d0e8417', + interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', name: 'Venus stkBNB', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vstkBNB', - underlyingAddress: '0xb0d4afd8879ed9f52b28595d31b441d079b2ca07', + underlyingAddress: '0x5081a39b8a5f0e35a8d959395a630b68b74dd30f', underlyingName: 'MockstkBNB', underlyingSymbol: 'MockstkBNB', borrowCapMantissa: '324000000000000000000', - accrualBlockNumber: 261, + accrualBlockNumber: 264, blockTimestamp: 1694785714, borrowIndexMantissa: '1000000063736681853', reserveFactorMantissa: '250000000000000000', @@ -270,9 +270,9 @@ export const defaultMarkets = [ __typename: 'Market', }, { - id: '0xf32d39ff9f6aa7a7a64d7a4f00a54826ef791a55', + id: '0x99dbe4aea58e518c50a1c04ae9b48c9f6354612f', pool: { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', __typename: 'Pool', }, badDebtMantissa: '0', @@ -280,16 +280,16 @@ export const defaultMarkets = [ cashMantissa: '10000000000000000000', collateralFactorMantissa: '600000000000000000', exchangeRateMantissa: '10000000000000000000000000000', - interestRateModelAddress: '0x525c7063e7c20997baae9bda922159152d0e8417', + interestRateModelAddress: '0x5fc748f1feb28d7b76fa1c6b07d8ba2d5535177c', name: 'Venus RACA', reservesMantissa: '0', supplyRateMantissa: '0', symbol: 'vRACA', - underlyingAddress: '0xfd471836031dc5108809d173a067e8486b9047a3', + underlyingAddress: '0xb0d4afd8879ed9f52b28595d31b441d079b2ca07', underlyingName: 'MockRACA', underlyingSymbol: 'MockRACA', borrowCapMantissa: '3805812642000000000000000000', - accrualBlockNumber: 258, + accrualBlockNumber: 261, blockTimestamp: 1694785711, borrowIndexMantissa: '1000000062785388094', reserveFactorMantissa: '250000000000000000', @@ -303,17 +303,18 @@ export const defaultMarkets = [ __typename: 'Market', }, ]; + export const defaultPools = [ { - id: '0xab16a69a5a8c12c732e0deff4be56a70bb64c926', + id: '0x1f10f3ba7acb61b2f50b9d6ddcf91a6f787c0e82', name: 'Pool 1', creator: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', - blockPosted: '235', + blockPosted: '238', timestampPosted: '1694787800', category: '', logoUrl: '', description: '', - priceOracleAddress: '0x68b1d87f95878fe05b998f19b66f4baba5de1aed', + priceOracleAddress: '0x59b670e9fa9d0a427751af201d676719a970857b', closeFactorMantissa: '500000000000000000', liquidationIncentiveMantissa: '3000000000000000000', minLiquidatableCollateralMantissa: '200000000000000000000', @@ -321,15 +322,15 @@ export const defaultPools = [ __typename: 'Pool', }, { - id: '0xe3011a37a904ab90c8881a99bd1f6e21401f1522', + id: '0x457ccf29090fe5a24c19c1bc95f492168c0eafdb', name: 'Pool 2', creator: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', - blockPosted: '237', + blockPosted: '240', timestampPosted: '1694787802', category: '', logoUrl: '', description: '', - priceOracleAddress: '0x68b1d87f95878fe05b998f19b66f4baba5de1aed', + priceOracleAddress: '0x59b670e9fa9d0a427751af201d676719a970857b', closeFactorMantissa: '50000000000000000', liquidationIncentiveMantissa: '1000000000000000000', minLiquidatableCollateralMantissa: '100000000000000000000', diff --git a/subgraphs/isolated-pools/tests/integration/pool.ts b/subgraphs/isolated-pools/tests/integration/pool.ts index cd3b361a..714a67d0 100644 --- a/subgraphs/isolated-pools/tests/integration/pool.ts +++ b/subgraphs/isolated-pools/tests/integration/pool.ts @@ -6,21 +6,19 @@ import { scaleValue, waitForSubgraphToBeSynced } from 'venus-subgraph-utils'; import subgraphClient from '../../subgraph-client'; import { defaultMarkets } from './constants'; -import deploy from './utils/deploy'; describe('Pools', function () { let acc1: Signer; let root: SignerWithAddress; let accessControlManager: Contract; - const syncDelay = 3000; + const syncDelay = 6000; before(async function () { this.timeout(500000); // sometimes it takes a long time const signers = await ethers.getSigners(); [root] = await ethers.getSigners(); acc1 = signers[1]; - await deploy(); accessControlManager = await ethers.getContract('AccessControlManager'); @@ -72,51 +70,48 @@ describe('Pools', function () { root.address, ); tx.wait(); - const { data: marketsData } = await subgraphClient.getMarkets(); - const { markets } = marketsData!; - markets.forEach(async m => { - const comptrollerProxy = await ethers.getContractAt('Comptroller', m.pool.id); - comptrollerProxy.supportMarket(m.id); - }); + await waitForSubgraphToBeSynced(syncDelay); }); it('handles MarketAdded event', async function () { // check markets const { data: marketsData } = await subgraphClient.getMarkets(); const { markets } = marketsData!; + expect(markets.length).to.equal(9); - markets.forEach((m, idx) => { - const defaultMarket = defaultMarkets[idx]; - expect(m.pool.id).to.equal(defaultMarket.pool.id); - expect(m.borrowRateMantissa).to.equal(defaultMarket.borrowRateMantissa); - expect(m.cashMantissa).to.equal(defaultMarket.cashMantissa); - expect(m.collateralFactorMantissa).to.equal(defaultMarket.collateralFactorMantissa); - expect(m.exchangeRateMantissa).to.equal(defaultMarket.exchangeRateMantissa); - expect(m.interestRateModelAddress).to.equal(defaultMarket.interestRateModelAddress); - expect(m.name).to.equal(defaultMarket.name); - expect(m.reservesMantissa).to.equal(defaultMarket.reservesMantissa); - expect(m.supplyRateMantissa).to.equal(defaultMarket.supplyRateMantissa); - expect(m.symbol).to.equal(defaultMarket.symbol); - expect(m.underlyingAddress).to.equal(defaultMarket.underlyingAddress); - expect(m.underlyingName).to.equal(defaultMarket.underlyingName); - expect(m.underlyingSymbol).to.equal(defaultMarket.underlyingSymbol); - expect(m.borrowCapMantissa).to.equal(defaultMarket.borrowCapMantissa); - expect(m.supplyCapMantissa).to.equal(defaultMarket.supplyCapMantissa); - expect(m.accrualBlockNumber).to.equal(defaultMarket.accrualBlockNumber); - expect(m.blockTimestamp).to.not.be.equal(defaultMarket.blockTimestamp); - expect(m.borrowIndexMantissa).to.equal(defaultMarket.borrowIndexMantissa); - expect(m.reserveFactorMantissa).to.equal(defaultMarket.reserveFactorMantissa); - expect(m.underlyingPriceCents).to.equal(defaultMarket.underlyingPriceCents); - expect(m.underlyingDecimals).to.equal(defaultMarket.underlyingDecimals); - expect(m.supplierCount).to.equal(defaultMarket.supplierCount); - expect(m.borrowerCount).to.equal(defaultMarket.borrowerCount); + markets.forEach(m => { + const defaultMarket = defaultMarkets.find(dm => m.id === dm.id); + + expect(m.pool.id).to.equal(defaultMarket?.pool.id); + expect(m.borrowRateMantissa).to.equal(defaultMarket?.borrowRateMantissa); + expect(m.cashMantissa).to.equal(defaultMarket?.cashMantissa); + expect(m.collateralFactorMantissa).to.equal(defaultMarket?.collateralFactorMantissa); + expect(m.exchangeRateMantissa).to.equal(defaultMarket?.exchangeRateMantissa); + expect(m.interestRateModelAddress).to.equal(defaultMarket?.interestRateModelAddress); + expect(m.name).to.equal(defaultMarket?.name); + expect(m.reservesMantissa).to.equal(defaultMarket?.reservesMantissa); + expect(m.supplyRateMantissa).to.equal(defaultMarket?.supplyRateMantissa); + expect(m.symbol).to.equal(defaultMarket?.symbol); + expect(m.underlyingAddress).to.equal(defaultMarket?.underlyingAddress); + expect(m.underlyingName).to.equal(defaultMarket?.underlyingName); + expect(m.underlyingSymbol).to.equal(defaultMarket?.underlyingSymbol); + expect(m.borrowCapMantissa).to.equal(defaultMarket?.borrowCapMantissa); + expect(m.supplyCapMantissa).to.equal(defaultMarket?.supplyCapMantissa); + expect(m.accrualBlockNumber).to.equal(defaultMarket?.accrualBlockNumber); + expect(m.blockTimestamp).to.not.be.equal(defaultMarket?.blockTimestamp); + expect(m.borrowIndexMantissa).to.equal(defaultMarket?.borrowIndexMantissa); + expect(m.reserveFactorMantissa).to.equal(defaultMarket?.reserveFactorMantissa); + expect(m.underlyingPriceCents).to.equal(defaultMarket?.underlyingPriceCents); + expect(m.underlyingDecimals).to.equal(defaultMarket?.underlyingDecimals); + expect(m.supplierCount).to.equal(defaultMarket?.supplierCount); + expect(m.borrowerCount).to.equal(defaultMarket?.borrowerCount); }); }); it('handles MarketEntered and MarketExited events', async function () { const account1Address = await acc1.getAddress(); - await waitForSubgraphToBeSynced(syncDelay * 2); + await waitForSubgraphToBeSynced(syncDelay); // check account const { data } = await subgraphClient.getAccountById(account1Address.toLowerCase()); @@ -268,7 +263,7 @@ describe('Pools', function () { const { data } = await subgraphClient.getMarkets(); const { markets: marketsBeforeUpdate } = data!; - expect(marketsBeforeUpdate[0].borrowCapMantissa).to.equal('3000000000000000000000000'); + expect(marketsBeforeUpdate[0].borrowCapMantissa).to.equal('100000000000000000000'); const comptrollerProxy = await ethers.getContractAt( 'Comptroller', @@ -308,7 +303,7 @@ describe('Pools', function () { const { data } = await subgraphClient.getMarkets(); const { markets: marketsBeforeUpdate } = data!; - expect(marketsBeforeUpdate[0].supplyCapMantissa).to.equal('3000000000000000000000000'); + expect(marketsBeforeUpdate[0].supplyCapMantissa).to.equal('100000000000000000000'); const comptrollerProxy = await ethers.getContractAt( 'Comptroller', diff --git a/subgraphs/isolated-pools/tests/integration/poolRegistry.ts b/subgraphs/isolated-pools/tests/integration/poolRegistry.ts index 79ccfa9b..1c85eac0 100644 --- a/subgraphs/isolated-pools/tests/integration/poolRegistry.ts +++ b/subgraphs/isolated-pools/tests/integration/poolRegistry.ts @@ -6,6 +6,7 @@ import { waitForSubgraphToBeSynced } from 'venus-subgraph-utils'; import subgraphClient from '../../subgraph-client'; import { defaultPools } from './constants'; +import deploy from './utils/deploy'; describe('Pool Registry', function () { let root: SignerWithAddress; @@ -21,6 +22,8 @@ describe('Pool Registry', function () { before(async function () { this.timeout(500000); // sometimes it takes a long time + await deploy(); + [root] = await ethers.getSigners(); poolRegistry = await ethers.getContract('PoolRegistry'); @@ -45,19 +48,22 @@ describe('Pool Registry', function () { it('indexes pool registry events', async function () { const { data } = await subgraphClient.getPools(); const { pools } = data!; + expect(pools.length).to.equal(2); - pools.forEach((pool, idx) => { - expect(pool.id).to.be.equal(defaultPools[idx].id); - expect(pool.name).to.be.equal(defaultPools[idx].name); - expect(pool.creator).to.be.equal(defaultPools[idx].creator); + + pools.forEach(pool => { + const defaultPool = defaultPools.find(dp => pool.id === dp.id); + expect(pool.id).to.be.equal(defaultPool?.id); + expect(pool.name).to.be.equal(defaultPool?.name); + expect(pool.creator).to.be.equal(defaultPool?.creator); expect(pool.blockPosted).to.be.string; - expect(pool.category).to.be.equal(defaultPools[idx].category); - expect(pool.logoUrl).to.be.equal(defaultPools[idx].logoUrl); - expect(pool.description).to.be.equal(defaultPools[idx].description); - expect(pool.priceOracleAddress).to.be.equal(defaultPools[idx].priceOracleAddress); - expect(pool.closeFactorMantissa).to.be.equal(defaultPools[idx].closeFactorMantissa); + expect(pool.category).to.be.equal(defaultPool?.category); + expect(pool.logoUrl).to.be.equal(defaultPool?.logoUrl); + expect(pool.description).to.be.equal(defaultPool?.description); + expect(pool.priceOracleAddress).to.be.equal(defaultPool?.priceOracleAddress); + expect(pool.closeFactorMantissa).to.be.equal(defaultPool?.closeFactorMantissa); expect(pool.liquidationIncentiveMantissa).to.be.equal( - defaultPools[idx].liquidationIncentiveMantissa, + defaultPool?.liquidationIncentiveMantissa, ); }); }); diff --git a/subgraphs/venus-governance/config/mainnet.json b/subgraphs/venus-governance/config/bsc.json similarity index 75% rename from subgraphs/venus-governance/config/mainnet.json rename to subgraphs/venus-governance/config/bsc.json index 2faf29db..692e5e72 100644 --- a/subgraphs/venus-governance/config/mainnet.json +++ b/subgraphs/venus-governance/config/bsc.json @@ -8,10 +8,6 @@ "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/chapel.json similarity index 70% rename from subgraphs/venus-governance/config/testnet.json rename to subgraphs/venus-governance/config/chapel.json index ce91b182..cdbb9e43 100644 --- a/subgraphs/venus-governance/config/testnet.json +++ b/subgraphs/venus-governance/config/chapel.json @@ -7,11 +7,7 @@ "governorAlpha2Address": "0x7116894ed34FC4B27D5b84f46B70Af48397a6C24", "governorAlpha2StartBlock": "13584539", "governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegateStartBlock": "16002994 ", - "governorBravoDelegate2Address": "", - "governorBravoDelegate2StartBlock": "", - "xvsTokenAddress": "0xB9e0E753630434d7863528cc73CB7AC638a7c8ff", - "xvsTokenStartBlock": "2802593", + "governorBravoDelegateStartBlock": "16002994", "xvsVaultAddress": "0xa4Fd54cACdA379FB7CaA783B83Cc846f8ac0Faa6", "xvsVaultStartBlock": "13937802" } diff --git a/subgraphs/venus-governance/config/local.json b/subgraphs/venus-governance/config/local.json index 29e429ef..62654900 100644 --- a/subgraphs/venus-governance/config/local.json +++ b/subgraphs/venus-governance/config/local.json @@ -1,17 +1,13 @@ { - "network": "bsc", + "network": "hardhat", "accessControlManagerAddress": "0xc5a5C42992dECbae36851359345FE25997F5C42d", "accessControlManagerStartBlock": "0", - "governorAlphaAddress": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", + "governorAlphaAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A", "governorAlphaStartBlock": "0", - "governorAlpha2Address": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE", + "governorAlpha2Address": "0x0fe4223AD99dF788A6Dcad148eB4086E6389cEB6", "governorAlpha2StartBlock": "0", - "governorBravoDelegateAddress": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegateStartBlock": "16002994", - "governorBravoDelegate2Address": "0x5573422a1a59385c247ec3a66b93b7c08ec2f8f2", - "governorBravoDelegate2StartBlock": "16002994", - "xvsTokenAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3", - "xvsTokenStartBlock": "0", - "xvsVaultAddress": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", + "governorBravoDelegateAddress": "0x1c9fD50dF7a4f066884b58A05D91e4b55005876A", + "governorBravoDelegateStartBlock": "0", + "xvsVaultAddress": "0xe1708FA6bb2844D5384613ef0846F9Bc1e8eC55E", "xvsVaultStartBlock": "0" } diff --git a/subgraphs/venus-governance/package.json b/subgraphs/venus-governance/package.json index c938be6f..f0fa4300 100644 --- a/subgraphs/venus-governance/package.json +++ b/subgraphs/venus-governance/package.json @@ -1,5 +1,5 @@ { - "name": "venus-governance", + "name": "venus-governance-subgraph", "version": "0.0.0", "license": "MIT", "repository": { @@ -10,17 +10,20 @@ "generated" ], "scripts": { - "codegen": "graph codegen", + "codegen": "npx graph codegen", "create:local": "graph create venusprotocol/venus-governance --node http://127.0.0.1:8020", + "create:docker": "npx graph create venusprotocol/venus-governance --node http://graph-node:8020/", + "build:docker": "npx graph build --ipfs http://ipfs:5001", "build:local": "graph build --ipfs http://localhost:5001", - "build:mainnet": "graph build --ipfs https://api.thegraph.com/ipfs/ ", + "build:bsc": "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", + "deploy:local": "npx mustache config/local.json template.yaml > subgraph.yaml && npx mustache config/local.json src/constants/config-template > src/constants/config.ts && yarn deploy:integration", + "deploy:docker": "npx mustache config/local.json template.yaml > subgraph.yaml && npx mustache config/local.json src/constants/config-template > src/constants/config.ts && npx graph deploy venusprotocol/venus-governance --ipfs http://ipfs:5001 --node http://graph-node:8020/ --version-label ci", + "deploy:chapel": "npx mustache config/chapel.json template.yaml > subgraph.yaml && npx mustache config/chapel.json src/constants/config-template > src/constants/config.ts && graph deploy venusprotocol/venus-governance-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 mustache config/bsc.json src/constants/config-template > src/constants/config.ts && 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 && 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", "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-governance/schema.graphql b/subgraphs/venus-governance/schema.graphql index 0fb61acc..56af7659 100644 --- a/subgraphs/venus-governance/schema.graphql +++ b/subgraphs/venus-governance/schema.graphql @@ -6,31 +6,21 @@ enum ProposalStatus { EXECUTED } -type TokenHolder @entity { - "A TokenHolder is any address that holds any amount of Venus Tokens, the id used is the blockchain address." - id: ID! - - "Delegate address of the token holder which will participate in votings. Delegates don't need to hold any tokens and can even be the token holder itself." - delegate: Delegate - - "Venus Token balance of this address expressed in the smallest unit of the XVS Token" - tokenBalance: BigInt! - - "Total amount of Venus Token ever held by this address expressed in the smallest unit of the XVS Token" - totalTokensHeld: BigInt! -} - type Delegate @entity { "A Delegate is any address that has been delegated with voting tokens by a token holder, id is the blockchain address of said delegate" id: ID! - "Amount of votes delegated to this delegate to be used on proposal votings expressed in the smallest unit of the XVS Token" - delegatedVotes: BigInt! + "Amount of XVS this user has staked" + stakedXvsMantissa: BigInt! + + "Total amount of votes via delegation and staking" + totalVotesMantissa: BigInt! - tokenHoldersRepresentedAmount: Int! + "Accounts delegating to this voter" + delegateCount: Int! - "Token holders that this delegate represents" - tokenHoldersRepresented: [TokenHolder!]! @derivedFrom(field: "delegate") + "Accounts delegating to this voter" + delegates: [Delegate!]! "Votes that a delegate has made in different proposals" votes: [Vote!]! @derivedFrom(field: "voter") @@ -116,35 +106,23 @@ type Governance @entity { "Number of proposals created" proposals: BigInt! - "Total number of token holders currently" - currentTokenHolders: BigInt! - - "Total number of delegates participating on the governance currently" - currentDelegates: BigInt! - - "Total number of token holders" - totalTokenHolders: BigInt! - - "Total number of delegates that held delegated votes" + "Total number of accounts delegates that can participate in governance by voting or creating proposals" totalDelegates: BigInt! + + "Total number of accounts participating in governance as delegates or by delegating" + totalVoters: BigInt! - "Total number of votes delegated expressed in the smallest unit of the Venus Token" - delegatedVotes: BigInt! + "Total number of votes delegated expressed in the smallest unit of XVS" + totalVotesMantissa: BigInt! "Number of proposals currently queued for execution" proposalsQueued: BigInt! - - "The delay before voting on a proposal may take place, once proposed, in blocks" - votingDelay: BigInt! - - "The duration of voting on a proposal, in blocks" - votingPeriod: BigInt! + + "The number of votes required to reach quorum" + quorumVotesMantissa: BigInt! "Active brains of Governor" implementation: Bytes! - - "The number of votes required in order for a voter to become a proposer" - proposalThreshold: BigInt! "Pending administrator for this contract" pendingAdmin: Bytes @@ -157,7 +135,23 @@ type Governance @entity { "The maximum number of actions that can be included in a proposal" proposalMaxOperations: BigInt! +} +type GovernanceRoute @entity { + "Index of the governance route" + id: ID! + "Governor implementation the route belongs to" + governor: Bytes! + "Address of timelock contract for route" + timelock: Bytes! + "Queue execution delay in blocks" + queueDelayBlocks: BigInt! + "The delay before voting on a proposal may take place, once proposed, in blocks" + votingDelayBlocks: BigInt! + "The duration of voting on a proposal, in blocks" + votingPeriodBlocks: BigInt! + "The number of votes required in order for a voter to become a proposer" + proposalThresholdMantissa: BigInt! } enum PermissionStatus { diff --git a/subgraphs/venus-governance/src/constants/addresses.ts b/subgraphs/venus-governance/src/constants/addresses.ts new file mode 100644 index 00000000..4631b68e --- /dev/null +++ b/subgraphs/venus-governance/src/constants/addresses.ts @@ -0,0 +1,7 @@ +import { Address } from '@graphprotocol/graph-ts'; + +import { governorBravoDelegateAddress as governorBravoDelegateAddressString } from './config'; + +export const governorBravoDelegateAddress = Address.fromString(governorBravoDelegateAddressString); + +export const nullAddress = Address.fromString('0x0000000000000000000000000000000000000000'); diff --git a/subgraphs/venus-governance/src/constants/config-template b/subgraphs/venus-governance/src/constants/config-template new file mode 100644 index 00000000..f6c7395a --- /dev/null +++ b/subgraphs/venus-governance/src/constants/config-template @@ -0,0 +1,3 @@ +// Use yarn prepare commands to generate config typescript file per env + +export const governorBravoDelegateAddress = '{{ governorBravoDelegateAddress }}'; diff --git a/subgraphs/venus-governance/src/constants/index.ts b/subgraphs/venus-governance/src/constants/index.ts index 3e71edce..da672190 100644 --- a/subgraphs/venus-governance/src/constants/index.ts +++ b/subgraphs/venus-governance/src/constants/index.ts @@ -1,6 +1,6 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'; -export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; + export const BIGINT_ZERO = BigInt.fromI32(0); export const BIGINT_ONE = BigInt.fromI32(1); export const BIGDECIMAL_ZERO = new BigDecimal(BIGINT_ZERO); @@ -10,9 +10,6 @@ export const EXECUTED = 'EXECUTED'; export const QUEUED = 'QUEUED'; export const ACTIVE = 'ACTIVE'; -// Ids -export const GOVERNANCE = 'GOVERNANCE'; - // Vote support export const FOR = 'FOR'; export const AGAINST = 'AGAINST'; diff --git a/subgraphs/venus-governance/src/mappings/bravo.ts b/subgraphs/venus-governance/src/mappings/bravo.ts index 062745d5..90c12dba 100644 --- a/subgraphs/venus-governance/src/mappings/bravo.ts +++ b/subgraphs/venus-governance/src/mappings/bravo.ts @@ -9,10 +9,7 @@ import { ProposalExecuted, ProposalMaxOperationsUpdated, ProposalQueued, - ProposalThresholdSet, VoteCast, - VotingDelaySet, - VotingPeriodSet, } from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; import { ACTIVE, CANCELLED, CRITICAL, FAST_TRACK, NORMAL, PENDING } from '../constants'; import { createProposal, createVoteBravo } from '../operations/create'; @@ -50,7 +47,7 @@ export function handleProposalExecuted(event: ProposalExecuted): void { updateProposalExecuted(event); } -export function handleVoteCast(event: VoteCast): void { +export function handleBravoVoteCast(event: VoteCast): void { createVoteBravo(event); const proposalId = event.params.proposalId.toString(); const proposal = getProposal(proposalId); @@ -59,30 +56,12 @@ export function handleVoteCast(event: VoteCast): void { } } -export function handleVotingDelaySet(event: VotingDelaySet): void { - const governance = getGovernanceEntity(); - governance.votingDelay = event.params.newVotingDelay; - governance.save(); -} - -export function handleVotingPeriodSet(event: VotingPeriodSet): void { - const governance = getGovernanceEntity(); - governance.votingPeriod = event.params.newVotingPeriod; - governance.save(); -} - export function handleNewImplementation(event: NewImplementation): void { const governance = getGovernanceEntity(); governance.implementation = event.params.newImplementation; governance.save(); } -export function handleProposalThresholdSet(event: ProposalThresholdSet): void { - const governance = getGovernanceEntity(); - governance.proposalThreshold = event.params.newProposalThreshold; - governance.save(); -} - export function handleNewPendingAdmin(event: NewPendingAdmin): void { const governance = getGovernanceEntity(); governance.pendingAdmin = event.params.newPendingAdmin; diff --git a/subgraphs/venus-governance/src/mappings/xvsToken.ts b/subgraphs/venus-governance/src/mappings/xvsToken.ts deleted file mode 100644 index 6c8d8a3a..00000000 --- a/subgraphs/venus-governance/src/mappings/xvsToken.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { DelegateChanged, DelegateVotesChanged, Transfer } from '../../generated/XVSToken/XVSToken'; -import { ZERO_ADDRESS } from '../constants'; -import { - updateDelegateChanged, - updateDelegateVoteChanged, - updateReceivedXvs, - updateSentXvs, -} from '../operations/update'; - -// - event: DelegateChanged(indexed address,indexed address,indexed address) -// handler: handleDelegateChanged - -export function handleDelegateChanged(event: DelegateChanged): void { - updateDelegateChanged(event); -} - -// - event: DelegateVotesChanged(indexed address,uint256,uint256) -// handler: handleDelegateVotesChanged - -export function handleDelegateVotesChanged(event: DelegateVotesChanged): void { - updateDelegateVoteChanged(event); -} - -// - event: Transfer(indexed address,indexed address,uint256) -// handler: handleTransfer - -export function handleTransfer(event: Transfer): void { - const params = event.params; - - if (params.from.toHexString() != ZERO_ADDRESS) { - updateSentXvs(params.from, params.amount); - } - - updateReceivedXvs(params.to, params.amount); -} diff --git a/subgraphs/venus-governance/src/operations/create.ts b/subgraphs/venus-governance/src/operations/create.ts index 28476e4e..1d825cf5 100644 --- a/subgraphs/venus-governance/src/operations/create.ts +++ b/subgraphs/venus-governance/src/operations/create.ts @@ -4,7 +4,7 @@ import { VoteCast as VoteCastAlpha } from '../../generated/GovernorAlpha/Governo import { VoteCast as VoteCastBravo } from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; import { Proposal, Vote } from '../../generated/schema'; import { ABSTAIN, ACTIVE, AGAINST, BIGINT_ONE, FOR, NORMAL, PENDING } from '../constants'; -import { getVoteId } from '../utils/ids'; +import { getVoteId } from '../utilities/ids'; import { getDelegate, getGovernanceEntity, getProposal } from './get'; export function createProposal(event: E): Proposal { diff --git a/subgraphs/venus-governance/src/operations/createOrUpdate.ts b/subgraphs/venus-governance/src/operations/createOrUpdate.ts index d13836b0..986e7f75 100644 --- a/subgraphs/venus-governance/src/operations/createOrUpdate.ts +++ b/subgraphs/venus-governance/src/operations/createOrUpdate.ts @@ -1,7 +1,7 @@ import { PermissionGranted } from '../../generated/AccessControlManager/AccessControlManger'; import { Permission } from '../../generated/schema'; import { GRANTED, REVOKED } from '../constants'; -import { getPermissionId } from '../utils/ids'; +import { getPermissionId } from '../utilities/ids'; export function createOrUpdatePermission(event: E): Permission { const id = getPermissionId( diff --git a/subgraphs/venus-governance/src/operations/get.ts b/subgraphs/venus-governance/src/operations/get.ts index 8bf38ba9..28e8e252 100644 --- a/subgraphs/venus-governance/src/operations/get.ts +++ b/subgraphs/venus-governance/src/operations/get.ts @@ -1,31 +1,70 @@ -import { Address, BigInt, log } from '@graphprotocol/graph-ts'; +import { BigInt, log } from '@graphprotocol/graph-ts'; -import { Delegate, Governance, Proposal } from '../../generated/schema'; -import { BIGINT_ONE, BIGINT_ZERO, GOVERNANCE } from '../constants'; +import { GovernorBravoDelegate2 } from '../../generated/GovernorBravoDelegate2/GovernorBravoDelegate2'; +import { Timelock } from '../../generated/GovernorBravoDelegate2/Timelock'; +import { Delegate, Governance, GovernanceRoute, Proposal } from '../../generated/schema'; +import { BIGINT_ZERO } from '../constants'; +import { governorBravoDelegateAddress } from '../constants/addresses'; /** - * While techinically this function does also create, we don't care because it only happens once as the id is a constant. + * While technically this function does also create, we don't care because it only happens once as the id is a constant. * @returns Governance */ export const getGovernanceEntity = (): Governance => { - let governance = Governance.load(GOVERNANCE); + let governance = Governance.load(governorBravoDelegateAddress.toHex()); if (!governance) { - governance = new Governance(GOVERNANCE); + const governorBravoDelegate2 = GovernorBravoDelegate2.bind(governorBravoDelegateAddress); + governance = new Governance(governorBravoDelegateAddress.toHex()); governance.proposals = BIGINT_ZERO; - governance.totalTokenHolders = BIGINT_ZERO; - governance.currentTokenHolders = BIGINT_ZERO; - governance.currentDelegates = BIGINT_ZERO; governance.totalDelegates = BIGINT_ZERO; - governance.delegatedVotes = BIGINT_ZERO; + governance.totalVoters = BIGINT_ZERO; + governance.totalVotesMantissa = BIGINT_ZERO; governance.proposalsQueued = BIGINT_ZERO; - // defaulting to Governor Bravo constructor defaults - governance.votingDelay = BIGINT_ONE; - governance.votingPeriod = BigInt.fromI64(86400); - governance.implementation = Address.fromString('0x18df46ec843e79d9351b57f85af7d69aec0d7eff'); - governance.proposalThreshold = BigInt.fromI64(300000000000000000000000); - governance.admin = Address.fromString('0x1c2cac6ec528c20800b2fe734820d87b581eaa6b'); - governance.guardian = Address.fromString('0x1c2cac6ec528c20800b2fe734820d87b581eaa6b'); - governance.proposalMaxOperations = BigInt.fromI32(10); + + governance.admin = governorBravoDelegate2.admin(); + governance.implementation = governorBravoDelegate2.implementation(); + governance.guardian = governorBravoDelegate2.guardian(); + governance.quorumVotesMantissa = governorBravoDelegate2.quorumVotes(); + governance.proposalMaxOperations = governorBravoDelegate2.proposalMaxOperations(); + // Governance Routes are set in initialization + // Normal + const normalProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(0)); + const normalTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(0)); + const normalTimelock = Timelock.bind(normalTimelockAddress); + const normalGovernanceRoute = new GovernanceRoute('0'); + normalGovernanceRoute.governor = governorBravoDelegateAddress; + normalGovernanceRoute.timelock = normalTimelockAddress; + normalGovernanceRoute.queueDelayBlocks = normalTimelock.delay(); + normalGovernanceRoute.votingDelayBlocks = normalProposalConfig.getVotingDelay(); + normalGovernanceRoute.votingPeriodBlocks = normalProposalConfig.getVotingPeriod(); + normalGovernanceRoute.proposalThresholdMantissa = normalProposalConfig.getProposalThreshold(); + normalGovernanceRoute.save(); + // Fast track + const fastTrackProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(1)); + const fastTrackTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(1)); + const fastTrackTimelock = Timelock.bind(normalTimelockAddress); + const fastTrackGovernanceRoute = new GovernanceRoute('1'); + fastTrackGovernanceRoute.governor = governorBravoDelegateAddress; + fastTrackGovernanceRoute.timelock = fastTrackTimelockAddress; + fastTrackGovernanceRoute.queueDelayBlocks = fastTrackTimelock.delay(); + fastTrackGovernanceRoute.votingDelayBlocks = fastTrackProposalConfig.getVotingDelay(); + fastTrackGovernanceRoute.votingPeriodBlocks = fastTrackProposalConfig.getVotingPeriod(); + fastTrackGovernanceRoute.proposalThresholdMantissa = + fastTrackProposalConfig.getProposalThreshold(); + fastTrackGovernanceRoute.save(); + // Critical + const criticalProposalConfig = governorBravoDelegate2.proposalConfigs(new BigInt(2)); + const criticalTimelockAddress = governorBravoDelegate2.proposalTimelocks(new BigInt(2)); + const criticalTimelock = Timelock.bind(normalTimelockAddress); + const criticalGovernanceRoute = new GovernanceRoute('2'); + criticalGovernanceRoute.governor = governorBravoDelegateAddress; + criticalGovernanceRoute.timelock = criticalTimelockAddress; + criticalGovernanceRoute.queueDelayBlocks = criticalTimelock.delay(); + criticalGovernanceRoute.votingDelayBlocks = criticalProposalConfig.getVotingDelay(); + criticalGovernanceRoute.votingPeriodBlocks = criticalProposalConfig.getVotingPeriod(); + criticalGovernanceRoute.proposalThresholdMantissa = + criticalProposalConfig.getProposalThreshold(); + criticalGovernanceRoute.save(); } return governance as Governance; diff --git a/subgraphs/venus-governance/src/operations/getOrCreate.ts b/subgraphs/venus-governance/src/operations/getOrCreate.ts index db185575..054711a7 100644 --- a/subgraphs/venus-governance/src/operations/getOrCreate.ts +++ b/subgraphs/venus-governance/src/operations/getOrCreate.ts @@ -1,34 +1,8 @@ -import { Delegate, TokenHolder } from '../../generated/schema'; -import { BIGINT_ONE, BIGINT_ZERO, ZERO_ADDRESS } from '../constants'; +import { Delegate } from '../../generated/schema'; +import { BIGINT_ONE, BIGINT_ZERO } from '../constants'; +import { nullAddress } from '../constants/addresses'; import { getGovernanceEntity } from './get'; -export class GetOrCreateTokenHolderReturn { - entity: TokenHolder; - created: boolean; -} - -export const getOrCreateTokenHolder = (id: string): GetOrCreateTokenHolderReturn => { - let created = false; - let tokenHolder = TokenHolder.load(id); - - if (!tokenHolder) { - tokenHolder = new TokenHolder(id); - tokenHolder.tokenBalance = BIGINT_ZERO; - tokenHolder.totalTokensHeld = BIGINT_ZERO; - - if (id != ZERO_ADDRESS) { - const governance = getGovernanceEntity(); - governance.totalTokenHolders = governance.totalTokenHolders.plus(BIGINT_ONE); - governance.save(); - } - - tokenHolder.save(); - created = true; - } - - return { entity: tokenHolder as TokenHolder, created }; -}; - export class GetOrCreateDelegateReturn { entity: Delegate; created: boolean; @@ -37,15 +11,17 @@ export class GetOrCreateDelegateReturn { export const getOrCreateDelegate = (id: string): GetOrCreateDelegateReturn => { let created = false; let delegate = Delegate.load(id); - if (!delegate) { delegate = new Delegate(id); - delegate.delegatedVotes = BIGINT_ZERO; - delegate.tokenHoldersRepresentedAmount = 0; + delegate.stakedXvsMantissa = BIGINT_ZERO; + delegate.totalVotesMantissa = BIGINT_ZERO; + delegate.delegateCount = 0; + delegate.delegates = []; - if (id != ZERO_ADDRESS) { + if (id != nullAddress.toString()) { const governance = getGovernanceEntity(); governance.totalDelegates = governance.totalDelegates.plus(BIGINT_ONE); + governance.totalVoters = governance.totalVoters.plus(BIGINT_ONE); governance.save(); } diff --git a/subgraphs/venus-governance/src/operations/update.ts b/subgraphs/venus-governance/src/operations/update.ts index e805e9d9..0b4e1a3e 100644 --- a/subgraphs/venus-governance/src/operations/update.ts +++ b/subgraphs/venus-governance/src/operations/update.ts @@ -1,8 +1,6 @@ -import { Address, BigInt, log } from '@graphprotocol/graph-ts'; - import { BIGINT_ONE, BIGINT_ZERO, CANCELLED, EXECUTED, QUEUED } from '../constants'; import { getGovernanceEntity, getProposal } from './get'; -import { getOrCreateDelegate, getOrCreateTokenHolder } from './getOrCreate'; +import { getOrCreateDelegate } from './getOrCreate'; export const updateProposalStatus = (id: string, status: string): void => { const proposal = getProposal(id); @@ -46,18 +44,14 @@ export function updateProposalExecuted(event: E): void { export function updateDelegateChanged(event: E): void { const params = event.params; - const tokenHolderResult = getOrCreateTokenHolder(params.delegator.toHexString()); - const tokenHolder = tokenHolderResult.entity; const oldDelegateResult = getOrCreateDelegate(params.fromDelegate.toHexString()); const oldDelegate = oldDelegateResult.entity; const newDelegateResult = getOrCreateDelegate(params.toDelegate.toHexString()); const newDelegate = newDelegateResult.entity; - tokenHolder.delegate = newDelegate.id; - tokenHolder.save(); - oldDelegate.tokenHoldersRepresentedAmount = oldDelegate.tokenHoldersRepresentedAmount - 1; - newDelegate.tokenHoldersRepresentedAmount = newDelegate.tokenHoldersRepresentedAmount + 1; + oldDelegate.delegateCount = oldDelegate.delegateCount - 1; oldDelegate.save(); + newDelegate.delegateCount = newDelegate.delegateCount + 1; newDelegate.save(); } @@ -71,59 +65,15 @@ export function updateDelegateVoteChanged(event: E): void { const newBalance = params.newBalance; const votesDifference = newBalance.minus(previousBalance); - delegate.delegatedVotes = newBalance; + delegate.totalVotesMantissa = newBalance; delegate.save(); if (previousBalance == BIGINT_ZERO && newBalance > BIGINT_ZERO) { - governance.currentDelegates = governance.currentDelegates.plus(BIGINT_ONE); + governance.totalDelegates = governance.totalDelegates.plus(BIGINT_ONE); } if (newBalance == BIGINT_ZERO) { - governance.currentDelegates = governance.currentDelegates.minus(BIGINT_ONE); + governance.totalDelegates = governance.totalDelegates.minus(BIGINT_ONE); } - governance.delegatedVotes = governance.delegatedVotes.plus(votesDifference); + governance.totalVotesMantissa = governance.totalVotesMantissa.plus(votesDifference); governance.save(); } - -export const updateSentXvs = (from: Address, amount: BigInt): void => { - const governance = getGovernanceEntity(); - const fromHolderResult = getOrCreateTokenHolder(from.toHexString()); - const fromHolder = fromHolderResult.entity; - const fromHolderPreviousBalance = fromHolder.tokenBalance; - fromHolder.tokenBalance = fromHolder.tokenBalance.minus(amount); - - if (fromHolder.tokenBalance < BIGINT_ZERO) { - log.error('Negative balance on holder {} with balance {}', [ - fromHolder.id, - fromHolder.tokenBalance.toString(), - ]); - } - - if (fromHolder.tokenBalance == BIGINT_ZERO && fromHolderPreviousBalance > BIGINT_ZERO) { - governance.currentTokenHolders = governance.currentTokenHolders.minus(BIGINT_ONE); - governance.save(); - } else if (fromHolder.tokenBalance > BIGINT_ZERO && fromHolderPreviousBalance == BIGINT_ZERO) { - governance.currentTokenHolders = governance.currentTokenHolders.plus(BIGINT_ONE); - governance.save(); - } - - fromHolder.save(); -}; - -export const updateReceivedXvs = (to: Address, amount: BigInt): void => { - const governance = getGovernanceEntity(); - const toHolderResult = getOrCreateTokenHolder(to.toHexString()); - const toHolder = toHolderResult.entity; - const toHolderPreviousBalance = toHolder.tokenBalance; - toHolder.tokenBalance = toHolder.tokenBalance.plus(amount); - toHolder.totalTokensHeld = toHolder.totalTokensHeld.plus(amount); - - if (toHolder.tokenBalance == BIGINT_ZERO && toHolderPreviousBalance > BIGINT_ZERO) { - governance.currentTokenHolders = governance.currentTokenHolders.minus(BIGINT_ONE); - governance.save(); - } else if (toHolder.tokenBalance > BIGINT_ZERO && toHolderPreviousBalance == BIGINT_ZERO) { - governance.currentTokenHolders = governance.currentTokenHolders.plus(BIGINT_ONE); - governance.save(); - } - - toHolder.save(); -}; diff --git a/subgraphs/venus-governance/src/utils/decimals.ts b/subgraphs/venus-governance/src/utilities/decimals.ts similarity index 100% rename from subgraphs/venus-governance/src/utils/decimals.ts rename to subgraphs/venus-governance/src/utilities/decimals.ts diff --git a/subgraphs/venus-governance/src/utils/ids.ts b/subgraphs/venus-governance/src/utilities/ids.ts similarity index 100% rename from subgraphs/venus-governance/src/utils/ids.ts rename to subgraphs/venus-governance/src/utilities/ids.ts diff --git a/subgraphs/venus-governance/subgraph-client/.graphclientrc.yml b/subgraphs/venus-governance/subgraph-client/.graphclientrc.yml index 0986405f..543a58b8 100644 --- a/subgraphs/venus-governance/subgraph-client/.graphclientrc.yml +++ b/subgraphs/venus-governance/subgraph-client/.graphclientrc.yml @@ -2,7 +2,7 @@ sources: - name: venus-governance handler: graphql: - endpoint: http://127.0.0.1:8000/subgraphs/name/venusprotocol/venus-governance + endpoint: http://graph-node:8000/subgraphs/name/venusprotocol/venus-governance documents: - '../**/*.graphql' diff --git a/subgraphs/venus-governance/subgraph-client/index.ts b/subgraphs/venus-governance/subgraph-client/index.ts index 83303c3d..e2cdadab 100644 --- a/subgraphs/venus-governance/subgraph-client/index.ts +++ b/subgraphs/venus-governance/subgraph-client/index.ts @@ -39,5 +39,5 @@ class SubgraphClient { } export default new SubgraphClient( - 'http://127.0.0.1:8000/subgraphs/name/venusprotocol/venus-governance', + 'http://graph-node:8000/subgraphs/name/venusprotocol/venus-governance', ); diff --git a/subgraphs/venus-governance/template.yaml b/subgraphs/venus-governance/template.yaml index a539ef11..e844a18d 100644 --- a/subgraphs/venus-governance/template.yaml +++ b/subgraphs/venus-governance/template.yaml @@ -13,12 +13,11 @@ dataSources: startBlock: {{ governorAlphaStartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/alpha.ts entities: - Delegate - - TokenHolder - Proposal - Vote - Governance @@ -45,12 +44,11 @@ dataSources: startBlock: {{ governorAlpha2StartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/alpha.ts entities: - Delegate - - TokenHolder - Proposal - Vote - Governance @@ -77,12 +75,11 @@ dataSources: startBlock: {{ governorBravoDelegateStartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/bravo.ts entities: - Delegate - - TokenHolder - Proposal - Vote - Governance @@ -100,14 +97,8 @@ dataSources: handler: handleProposalExecuted - event: VoteCast(indexed address,uint256,uint8,uint256,string) handler: handleBravoVoteCast - - event: VotingDelaySet(uint256,uint256) - handler: handleVotingDelaySet - - event: VotingPeriodSet(uint256,uint256) - handler: handleVotingPeriodSet - event: NewImplementation(address,address) handler: handleNewImplementation - - event: ProposalThresholdSet(uint256,uint256) - handler: handleProposalThresholdSet - event: NewPendingAdmin(address,address) handler: handleNewPendingAdmin - event: NewAdmin(address,address) @@ -120,75 +111,27 @@ dataSources: name: GovernorBravoDelegate2 network: {{ network }} source: - address: "{{ governorBravoDelegate2Address }}" + address: "{{ governorBravoDelegateAddress }}" abi: GovernorBravoDelegate2 - startBlock: {{ governorBravoDelegate2StartBlock }} + startBlock: {{ governorBravoDelegateStartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/bravo.ts entities: - Delegate - - TokenHolder - Proposal - Vote - Governance abis: - name: GovernorBravoDelegate2 file: ../../packages/venus-governance-abis/GovernorBravoDelegate2.json + - name: Timelock + file: ../../node_modules/@venusprotocol/governance-contracts/artifacts/contracts/Governance/Timelock.sol/Timelock.json eventHandlers: - event: ProposalCreated(uint256,address,address[],uint256[],string[],bytes[],uint256,uint256,string,uint8) handler: handleProposalCreatedV2 - - event: ProposalCanceled(uint256) - handler: handleProposalCanceled - - event: ProposalQueued(uint256,uint256) - handler: handleProposalQueued - - event: ProposalExecuted(uint256) - handler: handleProposalExecuted - - event: VoteCast(indexed address,uint256,uint8,uint256,string) - handler: handleBravoVoteCast - - event: VotingDelaySet(uint256,uint256) - handler: handleVotingDelaySet - - event: VotingPeriodSet(uint256,uint256) - handler: handleVotingPeriodSet - - event: NewImplementation(address,address) - handler: handleNewImplementation - - event: ProposalThresholdSet(uint256,uint256) - handler: handleProposalThresholdSet - - event: NewPendingAdmin(address,address) - handler: handleNewPendingAdmin - - event: NewAdmin(address,address) - handler: handleNewAdmin - - event: NewGuardian(address,address) - handler: handleNewGuardian - - event: ProposalMaxOperationsUpdated(uint256,uint256) - handler: handleProposalMaxOperationsUpdated - - kind: ethereum/contract - name: XVSToken - network: {{ network }} - source: - address: "{{ xvsTokenAddress }}" - abi: XVSToken - startBlock: {{ xvsTokenStartBlock }} - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - file: ./src/mappings/xvsToken.ts - entities: - - Delegate - - TokenHolder - abis: - - name: XVSToken - file: ../../packages/venus-governance-abis/XVSToken.json - eventHandlers: - - event: DelegateChanged(indexed address,indexed address,indexed address) - handler: handleDelegateChanged - - event: DelegateVotesChanged(indexed address,uint256,uint256) - handler: handleDelegateVotesChanged - - event: Transfer(indexed address,indexed address,uint256) - handler: handleTransfer - kind: ethereum/contract name: XVSVault network: {{ network }} @@ -198,12 +141,11 @@ dataSources: startBlock: {{ xvsVaultStartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/xvsVault.ts entities: - Delegate - - TokenHolder abis: - name: XVSVault file: ../../packages/venus-governance-abis/XVSVault.json @@ -221,7 +163,7 @@ dataSources: startBlock: {{ accessControlManagerStartBlock }} mapping: kind: ethereum/events - apiVersion: 0.0.6 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/accessControlManager.ts entities: diff --git a/subgraphs/venus-governance/tests/Alpha/xvsToken.test.ts b/subgraphs/venus-governance/tests/Alpha/xvsToken.test.ts deleted file mode 100644 index c9d2bddd..00000000 --- a/subgraphs/venus-governance/tests/Alpha/xvsToken.test.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { BigInt } from '@graphprotocol/graph-ts'; -import { - afterEach, - assert, - beforeEach, - clearStore, - describe, - test, -} from 'matchstick-as/assembly/index'; - -import { DelegateChanged, DelegateVotesChanged } from '../../generated/XVSToken/XVSToken'; -import { GOVERNANCE } from '../../src/constants'; -import { handleDelegateChanged, handleDelegateVotesChanged } from '../../src/mappings/xvsToken'; -import { getGovernanceEntity } from '../../src/operations/get'; -import { user1, user2, user3 } from '../common/constants'; -import { createDelegateChangedEvent, createDelegateVotesChangedEvent } from '../common/events'; - -const originalBalance = BigInt.fromI64(700000000000000000000000000000); - -const cleanup = (): void => { - clearStore(); -}; - -beforeEach(() => { - /** setup test */ - const governance = getGovernanceEntity(); - governance.delegatedVotes = originalBalance; - governance.save(); -}); - -afterEach(() => { - cleanup(); -}); - -describe('XVS Token', () => { - test('delegate changed', () => { - const delegator = user1; - const fromDelegate = user2; - const toDelegate = user3; - /** run handler */ - const delegateChangedEvent = createDelegateChangedEvent( - delegator, - fromDelegate, - toDelegate, - ); - handleDelegateChanged(delegateChangedEvent); - // OldDelegate - const assertOldDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user2.toHex(), key, value); - }; - assertOldDelegateDocument('tokenHoldersRepresentedAmount', '-1'); - - // New Delegate - const assertNewDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user3.toHex(), key, value); - }; - assertNewDelegateDocument('tokenHoldersRepresentedAmount', '1'); - - // TokenHolder - const assertTokenHolderDocument = (key: string, value: string): void => { - assert.fieldEquals('TokenHolder', user1.toHex(), key, value); - }; - assertTokenHolderDocument('delegate', user3.toHexString()); - }); - - test('delegate votes - new delegate', () => { - /** setup tests */ - const delegate = user3; - const previousBalance = BigInt.fromI64(0); - const newBalance = BigInt.fromI64(500000000000000000000000000000); - /** run handler */ - const delegateVotesChangedEvent = createDelegateVotesChangedEvent( - delegate, - previousBalance, - newBalance, - ); - handleDelegateVotesChanged(delegateVotesChangedEvent); - const votesDifference = newBalance.minus(previousBalance); - // Delegate - const assertDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user3.toHex(), key, value); - }; - assertDelegateDocument('delegatedVotes', newBalance.toString()); - - // Governance - const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); - }; - assertGovernanceDocument('delegatedVotes', originalBalance.plus(votesDifference).toString()); - assertGovernanceDocument('currentDelegates', '1'); - }); - - test('delegate votes - lost delegate', () => { - /** setup tests */ - const delegate = user3; - const previousBalance = BigInt.fromI64(300000000000000000000000000000); - const newBalance = BigInt.fromI64(0); - /** run handler */ - const delegateVotesChangedEvent = createDelegateVotesChangedEvent( - delegate, - previousBalance, - newBalance, - ); - handleDelegateVotesChanged(delegateVotesChangedEvent); - - const votesDifference = newBalance.minus(previousBalance); - // Delegate - const assertDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user3.toHex(), key, value); - }; - assertDelegateDocument('delegatedVotes', newBalance.toString()); - - // Governance - const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); - }; - assertGovernanceDocument('delegatedVotes', originalBalance.plus(votesDifference).toString()); - assertGovernanceDocument('currentDelegates', '-1'); - }); -}); diff --git a/subgraphs/venus-governance/tests/Bravo/xvsVault.test.ts b/subgraphs/venus-governance/tests/Bravo/xvsVault.test.ts deleted file mode 100644 index 7ca11e2f..00000000 --- a/subgraphs/venus-governance/tests/Bravo/xvsVault.test.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { BigInt } from '@graphprotocol/graph-ts'; -import { - afterEach, - assert, - beforeEach, - clearStore, - describe, - test, -} from 'matchstick-as/assembly/index'; - -import { ProposalCreated } from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; -import { DelegateChangedV2 } from '../../generated/XVSVault/XVSVault'; -import { handleProposalCreated } from '../../src/mappings/bravo'; -import { handleDelegateChanged } from '../../src/mappings/xvsVault'; -import { getOrCreateDelegate } from '../../src/operations/getOrCreate'; -import { user1, user2, user3 } from '../common/constants'; -import { createDelegateChangedEvent, createProposalCreatedEvent } from '../common/events'; - -const cleanup = (): void => { - clearStore(); -}; - -const startBlock = 4563820; -const endBlock = 4593820; -const description = 'Very creative Proposal'; - -beforeEach(() => { - /** setup test */ - getOrCreateDelegate(user1.toHexString()); - const proposalCreatedEvent = createProposalCreatedEvent( - 1, - user1, - [], - [], - [], - [], - BigInt.fromI64(startBlock), - BigInt.fromI64(endBlock), - description, - ); - handleProposalCreated(proposalCreatedEvent); -}); - -afterEach(() => { - cleanup(); -}); - -describe('XVS Vault', () => { - test('delegate changed', () => { - const delegator = user1; - const fromDelegate = user2; - const toDelegate = user3; - /** run handler */ - const delegateChangedEvent = createDelegateChangedEvent( - delegator, - fromDelegate, - toDelegate, - ); - handleDelegateChanged(delegateChangedEvent); - // OldDelegate - const assertOldDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user2.toHex(), key, value); - }; - assertOldDelegateDocument('tokenHoldersRepresentedAmount', '-1'); - - // New Delegate - const assertNewDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user3.toHex(), key, value); - }; - assertNewDelegateDocument('tokenHoldersRepresentedAmount', '1'); - - // TokenHolder - const assertTokenHolderDocument = (key: string, value: string): void => { - assert.fieldEquals('TokenHolder', user1.toHex(), key, value); - }; - assertTokenHolderDocument('delegate', user3.toHexString()); - }); - - test('delegate changed', () => { - const delegator = user1; - const fromDelegate = user2; - const toDelegate = user3; - /** run handler */ - const delegateChangedEvent = createDelegateChangedEvent( - delegator, - fromDelegate, - toDelegate, - ); - handleDelegateChanged(delegateChangedEvent); - // OldDelegate - const assertOldDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user2.toHex(), key, value); - }; - assertOldDelegateDocument('tokenHoldersRepresentedAmount', '-1'); - - // New Delegate - const assertNewDelegateDocument = (key: string, value: string): void => { - assert.fieldEquals('Delegate', user3.toHex(), key, value); - }; - assertNewDelegateDocument('tokenHoldersRepresentedAmount', '1'); - - // TokenHolder - const assertTokenHolderDocument = (key: string, value: string): void => { - assert.fieldEquals('TokenHolder', user1.toHex(), key, value); - }; - assertTokenHolderDocument('delegate', user3.toHexString()); - }); -}); diff --git a/subgraphs/venus-governance/tests/common/constants.ts b/subgraphs/venus-governance/tests/common/constants.ts index e8214b0a..f9c7478a 100644 --- a/subgraphs/venus-governance/tests/common/constants.ts +++ b/subgraphs/venus-governance/tests/common/constants.ts @@ -6,3 +6,11 @@ export const user3 = Address.fromString('0x0000000000000000000000000000000000000 export const mockContractAddress = Address.fromString('0x0000000000000000000000000000000000000999'); export const mockFunctionSig = 'mockFunc()'; + +// Mocked Governor return values +export const mockImplementationAddress = Address.fromString('0x000000000000000000000000000000000000c0DE'); +export const mockAdminAddress = Address.fromString('0x000000000000000000000000000000000000ad53'); +export const mockGuardianAddress = Address.fromString('0x000000000000000000000000000000000000536d'); +export const timelockAddress0 = Address.fromString('0x0000000000000000000000000000000000070c50'); +export const timelockAddress1 = Address.fromString('0x0000000000000000000000000000000000070c51'); +export const timelockAddress2 = Address.fromString('0x0000000000000000000000000000000000070c52'); diff --git a/subgraphs/venus-governance/tests/common/mocks.ts b/subgraphs/venus-governance/tests/common/mocks.ts new file mode 100644 index 00000000..be906743 --- /dev/null +++ b/subgraphs/venus-governance/tests/common/mocks.ts @@ -0,0 +1,108 @@ +import { BigInt, ethereum } from '@graphprotocol/graph-ts'; +import { createMockedFunction } from 'matchstick-as'; + +import { governorBravoDelegateAddress } from '../../src/constants/addresses'; +import { + mockAdminAddress, + mockGuardianAddress, + mockImplementationAddress, + timelockAddress0, + timelockAddress1, + timelockAddress2, +} from './constants'; + +export const createGovernorBravoMocks = (): void => { + createMockedFunction( + governorBravoDelegateAddress, + 'implementation', + 'implementation():(address)', + ).returns([ethereum.Value.fromAddress(mockImplementationAddress)]); + + createMockedFunction(governorBravoDelegateAddress, 'admin', 'admin():(address)').returns([ + ethereum.Value.fromAddress(mockAdminAddress), + ]); + + createMockedFunction(governorBravoDelegateAddress, 'guardian', 'guardian():(address)').returns([ + ethereum.Value.fromAddress(mockGuardianAddress), + ]); + + createMockedFunction( + governorBravoDelegateAddress, + 'quorumVotes', + 'quorumVotes():(uint256)', + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + + createMockedFunction( + governorBravoDelegateAddress, + 'proposalMaxOperations', + 'proposalMaxOperations():(uint256)', + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + + // Proposal Configs + createMockedFunction( + governorBravoDelegateAddress, + 'proposalConfigs', + 'proposalConfigs(uint256):(uint256,uint256,uint256)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('28800')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + createMockedFunction( + governorBravoDelegateAddress, + 'proposalConfigs', + 'proposalConfigs(uint256):(uint256,uint256,uint256)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('28800')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + createMockedFunction( + governorBravoDelegateAddress, + 'proposalConfigs', + 'proposalConfigs(uint256):(uint256,uint256,uint256)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('2'))]) + .returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('7200')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000000')), + ]); + + createMockedFunction( + governorBravoDelegateAddress, + 'proposalTimelocks', + 'proposalTimelocks(uint256):(address)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]) + .returns([ethereum.Value.fromAddress(timelockAddress0)]); + createMockedFunction( + governorBravoDelegateAddress, + 'proposalTimelocks', + 'proposalTimelocks(uint256):(address)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1'))]) + .returns([ethereum.Value.fromAddress(timelockAddress1)]); + createMockedFunction( + governorBravoDelegateAddress, + 'proposalTimelocks', + 'proposalTimelocks(uint256):(address)', + ) + .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('2'))]) + .returns([ethereum.Value.fromAddress(timelockAddress2)]); + + // Timelocks + createMockedFunction(timelockAddress0, 'delay', 'delay():(uint256)').returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('172800')), + ]); + createMockedFunction(timelockAddress1, 'delay', 'delay():(uint256)').returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('21600')), + ]); + createMockedFunction(timelockAddress2, 'delay', 'delay():(uint256)').returns([ + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('3600')), + ]); +}; diff --git a/subgraphs/venus-governance/tests/integration/index.ts b/subgraphs/venus-governance/tests/integration/index.ts index 82b56e30..629cca99 100644 --- a/subgraphs/venus-governance/tests/integration/index.ts +++ b/subgraphs/venus-governance/tests/integration/index.ts @@ -8,7 +8,7 @@ import { deploy, exec, normalizeMantissa, waitForSubgraphToBeSynced } from 'venu import subgraphClient from '../../subgraph-client/index'; import { SUBGRAPH_ACCOUNT, SUBGRAPH_NAME, SYNC_DELAY } from './utils/constants'; -import deployFixtures from './utils/deploy'; +import deployFixtures from './utils/fixtures'; import { enfranchiseAccount } from './utils/voter'; describe('Governance', function () { @@ -25,7 +25,7 @@ describe('Governance', function () { const root = `${__dirname}/../..`; await deploy({ root, - packageName: 'venus-governance', + packageName: 'venus-governance-subgraph', subgraphAccount: SUBGRAPH_ACCOUNT, subgraphName: SUBGRAPH_NAME, syncDelay: SYNC_DELAY, diff --git a/subgraphs/venus-governance/tests/integration/queries/delegateByIdQuery.graphql b/subgraphs/venus-governance/tests/integration/queries/delegateByIdQuery.graphql index 7a6c9685..3ba02acc 100644 --- a/subgraphs/venus-governance/tests/integration/queries/delegateByIdQuery.graphql +++ b/subgraphs/venus-governance/tests/integration/queries/delegateByIdQuery.graphql @@ -1,8 +1,10 @@ query DelegateById($id: ID!) { delegate(id: $id) { id - delegatedVotes - tokenHoldersRepresented { + stakedXvsMantissa + totalVotesMantissa + delegateCount + delegates { id } votes { diff --git a/subgraphs/venus-governance/tests/integration/utils/deploy.ts b/subgraphs/venus-governance/tests/integration/utils/deploy.ts deleted file mode 100644 index fb4506e2..00000000 --- a/subgraphs/venus-governance/tests/integration/utils/deploy.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { Contract } from 'ethers'; -import { ethers } from 'hardhat'; - -const xvsVaultFixture = async () => { - const [deployer, acc1] = await ethers.getSigners(); - const XvsContract = await ethers.getContractFactory('XVS'); - const xvs = await XvsContract.deploy(deployer.address); - const xvsAddress = xvs.address; - - const xvsVaultFactory = await ethers.getContractFactory('XVSVault'); - const xvsVault = await xvsVaultFactory.deploy(); - await xvsVault.deployed(); - - const xvsVaultAddress = xvsVault.address; - - const xvsVaultProxyFactory = await ethers.getContractFactory('XVSVaultProxy'); - const xvsVaultProxy = await xvsVaultProxyFactory.deploy(); - await xvsVaultProxy.deployed(); - const xvsVaultProxyAddress = xvsVaultProxy.address; - - const xvsStoreFactory = await ethers.getContractFactory('XVSStore'); - const xvsStore = await xvsStoreFactory.deploy(); - await xvsStore.deployed(); - const xvsStoreAddress = xvsStore.address; - const txn = await xvsVault.setXvsStore(xvsAddress, xvsStore.address); - await txn.wait(1); - - // Become Implementation of XVSVaultProxy - await xvsVaultProxy._setPendingImplementation(xvsVaultAddress); - await xvsVault._become(xvsVaultProxyAddress); - - // Set implementation for xvs vault proxy - await xvsVaultProxy._setPendingImplementation(xvsVaultAddress); - - // Set new owner to xvs store - await xvsStore.setNewOwner(xvsVaultAddress); - - // Set xvs store to xvs vault - await xvsVault.setXvsStore(xvsAddress, xvsStoreAddress); - - // Delegate voting power to xvs vault - await xvsVault.delegate(acc1.address); - - // Add token pool to xvs vault - const _allocPoint = 100; - const _token = xvsAddress; - const _rewardToken = xvsAddress; - const _rewardPerBlock = ethers.BigNumber.from(10).pow(16).toString(); - const _lockPeriod = 300; - - await xvsVault.add(_rewardToken, _allocPoint, _token, _rewardPerBlock, _lockPeriod); - - // Set timelock as admin to xvs store - const TimelockContract = await ethers.getContractFactory('Timelock'); - const timelock = await TimelockContract.deploy(deployer.address, 86400 * 2); - - const timelockAddress = timelock.address; - - // Set timelock as admin to xvs vault proxy - await xvsVaultProxy._setPendingAdmin(timelockAddress); - - // approve xvs spending to xvs vault - const approvalAmount = ethers.BigNumber.from(ethers.BigNumber.from(10).pow(10)) - .mul(ethers.BigNumber.from(10).pow(18)) - .toString(); - await xvs.approve(xvsVaultAddress, approvalAmount); - - // deposit xvs to xvs vault - const amount = ethers.BigNumber.from(ethers.BigNumber.from(7).pow(5)) - .mul(ethers.BigNumber.from(10).pow(18)) - .toString(); - await xvsVault.deposit(xvsAddress, 0, amount); - return { - xvsVault, - xvsVaultProxy, - xvs, - xvsStore, - timelock, - }; -}; -const governorFixture = async ({ - timelock, - xvsVaultAddress, -}: { - timelock: Contract; - xvsVaultAddress: string; -}) => { - const [deployer] = await ethers.getSigners(); - const timelockAddress = timelock.address; - const GovernorAlphaDelegateFactory = await ethers.getContractFactory('GovernorAlpha'); - const governorAlpha = await GovernorAlphaDelegateFactory.deploy( - timelockAddress, - xvsVaultAddress, - deployer.address, - ); - await governorAlpha.deployed(); - - const GovernorAlpha2Factory = await ethers.getContractFactory('GovernorAlpha2'); - const governorAlpha2 = await GovernorAlpha2Factory.deploy( - timelockAddress, - xvsVaultAddress, - deployer.address, - 20, - ); - - await governorAlpha2.deployed(); - - return { - governorAlpha, - governorAlpha2, - }; -}; - -async function deploy() { - const { timelock, xvsVault, xvs } = await xvsVaultFixture(); - const { governorAlpha, governorAlpha2 } = await governorFixture({ - timelock: timelock, - xvsVaultAddress: xvsVault.address, - }); - return { - governorAlpha, - governorAlpha2, - timelock, - xvs, - xvsVault, - }; -} - -export default deploy; diff --git a/subgraphs/venus-governance/tests/integration/utils/fixtures.ts b/subgraphs/venus-governance/tests/integration/utils/fixtures.ts new file mode 100644 index 00000000..0fe9047c --- /dev/null +++ b/subgraphs/venus-governance/tests/integration/utils/fixtures.ts @@ -0,0 +1,53 @@ +import { ethers } from 'hardhat'; + +const xvsVaultFixture = async () => { + const xvs = await ethers.getContract('XVS'); + const xvsVault = await ethers.getContract('XVSVault'); + const xvsVaultProxy = await ethers.getContract('XVSVaultProxy'); + const xvsStore = await ethers.getContract('XVSStore'); + const timelock = await ethers.getContract('Timelock'); + + // approve xvs spending to xvs vault + const approvalAmount = ethers.BigNumber.from(ethers.BigNumber.from(10).pow(10)) + .mul(ethers.BigNumber.from(10).pow(18)) + .toString(); + await xvs.approve(xvsVault.address, approvalAmount); + + // deposit xvs to xvs vault + const amount = ethers.BigNumber.from(ethers.BigNumber.from(7).pow(5)) + .mul(ethers.BigNumber.from(10).pow(18)) + .toString(); + await xvsVault.deposit(xvs.address, 0, amount); + return { + xvsVault, + xvsVaultProxy, + xvs, + xvsStore, + timelock, + }; +}; + +const governorFixture = async () => { + const governorAlpha = await ethers.getContract('GovernorAlpha'); + + const governorAlpha2 = await ethers.getContract('GovernorAlpha2'); + + return { + governorAlpha, + governorAlpha2, + }; +}; + +async function deploy() { + const { timelock, xvsVault, xvs } = await xvsVaultFixture(); + const { governorAlpha, governorAlpha2 } = await governorFixture(); + return { + governorAlpha, + governorAlpha2, + timelock, + xvs, + xvsVault, + }; +} + +export default deploy; diff --git a/subgraphs/venus-governance/tests/Alpha/index.test.ts b/subgraphs/venus-governance/tests/unit/Alpha/index.test.ts similarity index 84% rename from subgraphs/venus-governance/tests/Alpha/index.test.ts rename to subgraphs/venus-governance/tests/unit/Alpha/index.test.ts index 2741010f..576c06c2 100644 --- a/subgraphs/venus-governance/tests/Alpha/index.test.ts +++ b/subgraphs/venus-governance/tests/unit/Alpha/index.test.ts @@ -2,6 +2,7 @@ import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'; import { afterEach, assert, + beforeAll, beforeEach, clearStore, describe, @@ -13,25 +14,26 @@ import { ProposalCreated, ProposalExecuted, ProposalQueued, -} from '../../generated/GovernorAlpha/GovernorAlpha'; -import { GOVERNANCE } from '../../src/constants'; +} from '../../../generated/GovernorAlpha/GovernorAlpha'; +import { governorBravoDelegateAddress } from '../../../src/constants/addresses'; import { handleProposalCanceled, handleProposalCreated, handleProposalExecuted, handleProposalQueued, handleVoteCast, -} from '../../src/mappings/alpha'; -import { getOrCreateDelegate } from '../../src/operations/getOrCreate'; -import { getVoteId } from '../../src/utils/ids'; -import { user1 } from '../common/constants'; +} from '../../../src/mappings/alpha'; +import { getOrCreateDelegate } from '../../../src/operations/getOrCreate'; +import { getVoteId } from '../../../src/utilities/ids'; +import { user1 } from '../../common/constants'; import { createProposalCanceledEvent, createProposalCreatedEvent, createProposalExecutedEvent, createProposalQueuedEvent, createVoteCastAlphaEvent, -} from '../common/events'; +} from '../../common/events'; +import { createGovernorBravoMocks } from '../../common/mocks'; const cleanup = (): void => { clearStore(); @@ -41,6 +43,10 @@ const startBlock = 4563820; const endBlock = 4593820; const description = 'Very creative Proposal'; +beforeAll(() => { + createGovernorBravoMocks(); +}); + beforeEach(() => { getOrCreateDelegate(user1.toHexString()); const proposalCreatedEvent = createProposalCreatedEvent( @@ -68,8 +74,10 @@ describe('Alpha', () => { assert.fieldEquals('Delegate', user1.toHex(), key, value); }; assertDelegateDocument('id', user1.toHexString()); - assertDelegateDocument('delegatedVotes', '0'); - assertDelegateDocument('tokenHoldersRepresentedAmount', '0'); + assertDelegateDocument('totalVotesMantissa', '0'); + assertDelegateDocument('delegateCount', '0'); + assertDelegateDocument('proposals', '[1]'); + assertDelegateDocument('delegates', '[]'); // Proposal const assertProposalDocument = (key: string, value: string): void => { @@ -111,7 +119,7 @@ describe('Alpha', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'QUEUED'); @@ -134,7 +142,7 @@ describe('Alpha', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'EXECUTED'); diff --git a/subgraphs/venus-governance/tests/Bravo/events.ts b/subgraphs/venus-governance/tests/unit/Bravo/events.ts similarity index 60% rename from subgraphs/venus-governance/tests/Bravo/events.ts rename to subgraphs/venus-governance/tests/unit/Bravo/events.ts index 2b6e9d34..9f8c5571 100644 --- a/subgraphs/venus-governance/tests/Bravo/events.ts +++ b/subgraphs/venus-governance/tests/unit/Bravo/events.ts @@ -7,58 +7,7 @@ import { NewImplementation, NewPendingAdmin, ProposalMaxOperationsUpdated, - ProposalThresholdSet, - VotingDelaySet, - VotingPeriodSet, -} from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; - -export function createNewVotingDelayEvent( - governanceAddress: Address, - oldVotingDelay: BigInt, - newVotingDelay: BigInt, -): VotingDelaySet { - const event = changetype(newMockEvent()); - event.address = governanceAddress; - event.parameters = []; - - const oldVotingDelayParam = new ethereum.EventParam( - 'oldVotingDelay', - ethereum.Value.fromUnsignedBigInt(oldVotingDelay), - ); - event.parameters.push(oldVotingDelayParam); - - const newVotingDelayParam = new ethereum.EventParam( - 'newVotingDelay', - ethereum.Value.fromUnsignedBigInt(newVotingDelay), - ); - event.parameters.push(newVotingDelayParam); - - return event; -} - -export function createNewVotingPeriodEvent( - governanceAddress: Address, - oldVotingPeriod: BigInt, - newVotingPeriod: BigInt, -): VotingPeriodSet { - const event = changetype(newMockEvent()); - event.address = governanceAddress; - event.parameters = []; - - const oldVotingPeriodParam = new ethereum.EventParam( - 'oldVotingPeriod', - ethereum.Value.fromUnsignedBigInt(oldVotingPeriod), - ); - event.parameters.push(oldVotingPeriodParam); - - const newVotingPeriodParam = new ethereum.EventParam( - 'newVotingPeriod', - ethereum.Value.fromUnsignedBigInt(newVotingPeriod), - ); - event.parameters.push(newVotingPeriodParam); - - return event; -} +} from '../../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; export function createNewImplementationEvent( governanceAddress: Address, @@ -84,30 +33,6 @@ export function createNewImplementationEvent( return event; } -export function createNewProposalThresholdEvent( - governanceAddress: Address, - oldProposalThreshold: BigInt, - newProposalThreshold: BigInt, -): ProposalThresholdSet { - const event = changetype(newMockEvent()); - event.address = governanceAddress; - event.parameters = []; - - const oldProposalThresholdParam = new ethereum.EventParam( - 'oldProposalThreshold', - ethereum.Value.fromUnsignedBigInt(oldProposalThreshold), - ); - event.parameters.push(oldProposalThresholdParam); - - const newProposalThresholdParam = new ethereum.EventParam( - 'newProposalThreshold', - ethereum.Value.fromUnsignedBigInt(newProposalThreshold), - ); - event.parameters.push(newProposalThresholdParam); - - return event; -} - export function createNewPendingAdminEvent( governanceAddress: Address, oldPendingAdmin: Address, diff --git a/subgraphs/venus-governance/tests/Bravo/index.test.ts b/subgraphs/venus-governance/tests/unit/Bravo/index.test.ts similarity index 76% rename from subgraphs/venus-governance/tests/Bravo/index.test.ts rename to subgraphs/venus-governance/tests/unit/Bravo/index.test.ts index f069abaf..88c03f93 100644 --- a/subgraphs/venus-governance/tests/Bravo/index.test.ts +++ b/subgraphs/venus-governance/tests/unit/Bravo/index.test.ts @@ -2,21 +2,23 @@ import { Address, BigInt } from '@graphprotocol/graph-ts'; import { afterEach, assert, + beforeAll, beforeEach, clearStore, describe, test, } from 'matchstick-as/assembly/index'; -import { ProposalCreated as ProposalCreatedV2 } from '../../generated/GovernorBravoDelegate2/GovernorBravoDelegate2'; +import { ProposalCreated as ProposalCreatedV2 } from '../../../generated/GovernorBravoDelegate2/GovernorBravoDelegate2'; import { ProposalCanceled, ProposalCreated, ProposalExecuted, ProposalQueued, -} from '../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; -import { GOVERNANCE } from '../../src/constants/index'; +} from '../../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; +import { governorBravoDelegateAddress } from '../../../src/constants/addresses'; import { + handleBravoVoteCast, handleNewAdmin, handleNewGuardian, handleNewImplementation, @@ -27,14 +29,10 @@ import { handleProposalExecuted, handleProposalMaxOperationsUpdated, handleProposalQueued, - handleProposalThresholdSet, - handleVoteCast, - handleVotingDelaySet, - handleVotingPeriodSet, -} from '../../src/mappings/bravo'; -import { getOrCreateDelegate } from '../../src/operations/getOrCreate'; -import { getVoteId } from '../../src/utils/ids'; -import { user1 } from '../common/constants'; +} from '../../../src/mappings/bravo'; +import { getOrCreateDelegate } from '../../../src/operations/getOrCreate'; +import { getVoteId } from '../../../src/utilities/ids'; +import { user1 } from '../../common/constants'; import { createProposalCanceledEvent, createProposalCreatedEvent, @@ -42,16 +40,14 @@ import { createProposalExecutedEvent, createProposalQueuedEvent, createVoteCastBravoEvent, -} from '../common/events'; +} from '../../common/events'; +import { createGovernorBravoMocks } from '../../common/mocks'; import { createNewAdminEvent, createNewGuardianEvent, createNewImplementationEvent, createNewPendingAdminEvent, createNewProposalMaxOperationsEvent, - createNewProposalThresholdEvent, - createNewVotingDelayEvent, - createNewVotingPeriodEvent, } from './events'; const startBlock = 4563820; @@ -63,6 +59,10 @@ const cleanup = (): void => { clearStore(); }; +beforeAll(() => { + createGovernorBravoMocks(); +}); + beforeEach(() => { /** setup test */ getOrCreateDelegate(user1.toHexString()); @@ -107,8 +107,10 @@ describe('Bravo', () => { assert.fieldEquals('Delegate', user1.toHex(), key, value); }; assertDelegateDocument('id', user1.toHexString()); - assertDelegateDocument('delegatedVotes', '0'); - assertDelegateDocument('tokenHoldersRepresentedAmount', '0'); + assertDelegateDocument('totalVotesMantissa', '0'); + assertDelegateDocument('delegateCount', '0'); + assertDelegateDocument('proposals', '[1]'); + assertDelegateDocument('delegates', '[]'); // Proposal const assertProposalDocument = (key: string, value: string): void => { @@ -149,8 +151,10 @@ describe('Bravo', () => { assert.fieldEquals('Delegate', user1.toHex(), key, value); }; assertDelegateDocument('id', user1.toHexString()); - assertDelegateDocument('delegatedVotes', '0'); - assertDelegateDocument('tokenHoldersRepresentedAmount', '0'); + assertDelegateDocument('totalVotesMantissa', '0'); + assertDelegateDocument('delegateCount', '0'); + assertDelegateDocument('proposals', '[1]'); + assertDelegateDocument('delegates', '[]'); // Proposal const assertProposalDocument = (key: string, value: string): void => { @@ -209,7 +213,7 @@ describe('Bravo', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'QUEUED'); @@ -232,7 +236,7 @@ describe('Bravo', () => { }; const assertGovernanceDocument = (key: string, value: string): void => { - assert.fieldEquals('Governance', GOVERNANCE, key, value); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), key, value); }; assertProposalDocument('status', 'EXECUTED'); @@ -246,7 +250,7 @@ describe('Bravo', () => { const reason = 'Good idea!'; /** run handler */ const voteCastEvent = createVoteCastBravoEvent(user1, 1, 1, BigInt.fromI64(votes), reason); - handleVoteCast(voteCastEvent); + handleBravoVoteCast(voteCastEvent); // Vote const assertVoteDocument = (key: string, value: string): void => { @@ -263,32 +267,6 @@ describe('Bravo', () => { assert.fieldEquals('Proposal', '1', 'status', 'ACTIVE'); }); - test('registers new voting delay', () => { - const oldVotingDelay = BigInt.fromI32(1); - const newVotingDelay = BigInt.fromI32(2); - const votingDelayEvent = createNewVotingDelayEvent( - governanceAddress, - oldVotingDelay, - newVotingDelay, - ); - - handleVotingDelaySet(votingDelayEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'votingDelay', newVotingDelay.toString()); - }); - - test('registers new voting period', () => { - const oldVotingPeriod = BigInt.fromI32(1); - const newVotingPeriod = BigInt.fromI32(2); - const votingPeriodEvent = createNewVotingPeriodEvent( - governanceAddress, - oldVotingPeriod, - newVotingPeriod, - ); - - handleVotingPeriodSet(votingPeriodEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'votingPeriod', newVotingPeriod.toString()); - }); - test('registers new implementation', () => { const oldImplementation = Address.fromString('0x0a00000000000000000000000000000000000000'); const newImplementation = Address.fromString('0x0b00000000000000000000000000000000000000'); @@ -299,24 +277,11 @@ describe('Bravo', () => { ); handleNewImplementation(newImplementationEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'implementation', newImplementation.toHexString()); - }); - - test('registers new proposal threshold', () => { - const oldProposalThreshold = BigInt.fromI64(300000000000000000000000); - const newProposalThreshold = BigInt.fromI64(500000000000000000000000); - const proposalThresholdEvent = createNewProposalThresholdEvent( - governanceAddress, - oldProposalThreshold, - newProposalThreshold, - ); - - handleProposalThresholdSet(proposalThresholdEvent); assert.fieldEquals( 'Governance', - GOVERNANCE, - 'proposalThreshold', - newProposalThreshold.toString(), + governorBravoDelegateAddress.toHex(), + 'implementation', + newImplementation.toHexString(), ); }); @@ -330,7 +295,12 @@ describe('Bravo', () => { ); handleNewPendingAdmin(pendingAdminEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'pendingAdmin', newPendingAdmin.toHexString()); + assert.fieldEquals( + 'Governance', + governorBravoDelegateAddress.toHex(), + 'pendingAdmin', + newPendingAdmin.toHexString(), + ); }); test('registers new admin', () => { @@ -339,8 +309,13 @@ describe('Bravo', () => { const newAdminEvent = createNewAdminEvent(governanceAddress, oldAdmin, newAdmin); handleNewAdmin(newAdminEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'admin', newAdmin.toHexString()); - assert.fieldEquals('Governance', GOVERNANCE, 'pendingAdmin', 'null'); + assert.fieldEquals( + 'Governance', + governorBravoDelegateAddress.toHex(), + 'admin', + newAdmin.toHexString(), + ); + assert.fieldEquals('Governance', governorBravoDelegateAddress.toHex(), 'pendingAdmin', 'null'); }); test('registers new guardian', () => { @@ -349,7 +324,12 @@ describe('Bravo', () => { const newGuardianEvent = createNewGuardianEvent(governanceAddress, oldGuardian, newGuardian); handleNewGuardian(newGuardianEvent); - assert.fieldEquals('Governance', GOVERNANCE, 'guardian', newGuardian.toHexString()); + assert.fieldEquals( + 'Governance', + governorBravoDelegateAddress.toHex(), + 'guardian', + newGuardian.toHexString(), + ); }); test('registers new proposal max operations', () => { @@ -364,7 +344,7 @@ describe('Bravo', () => { handleProposalMaxOperationsUpdated(newProposalMaxOperationsEvent); assert.fieldEquals( 'Governance', - GOVERNANCE, + governorBravoDelegateAddress.toHex(), 'proposalMaxOperations', newProposalMaxOperations.toString(), ); diff --git a/subgraphs/venus-governance/tests/unit/Bravo/xvsVault.test.ts b/subgraphs/venus-governance/tests/unit/Bravo/xvsVault.test.ts new file mode 100644 index 00000000..1ce76ff1 --- /dev/null +++ b/subgraphs/venus-governance/tests/unit/Bravo/xvsVault.test.ts @@ -0,0 +1,78 @@ +import { BigInt } from '@graphprotocol/graph-ts'; +import { + afterEach, + assert, + beforeAll, + beforeEach, + clearStore, + describe, + test, +} from 'matchstick-as/assembly/index'; + +import { ProposalCreated } from '../../../generated/GovernorBravoDelegate/GovernorBravoDelegate'; +import { DelegateChangedV2 } from '../../../generated/XVSVault/XVSVault'; +import { handleProposalCreated } from '../../../src/mappings/bravo'; +import { handleDelegateChanged } from '../../../src/mappings/xvsVault'; +import { getOrCreateDelegate } from '../../../src/operations/getOrCreate'; +import { user1, user2, user3 } from '../../common/constants'; +import { createDelegateChangedEvent, createProposalCreatedEvent } from '../../common/events'; +import { createGovernorBravoMocks } from '../../common/mocks'; + +const cleanup = (): void => { + clearStore(); +}; + +const startBlock = 4563820; +const endBlock = 4593820; +const description = 'Very creative Proposal'; + +beforeAll(() => { + createGovernorBravoMocks(); +}); + +beforeEach(() => { + /** setup test */ + getOrCreateDelegate(user1.toHexString()); + const proposalCreatedEvent = createProposalCreatedEvent( + 1, + user1, + [], + [], + [], + [], + BigInt.fromI64(startBlock), + BigInt.fromI64(endBlock), + description, + ); + handleProposalCreated(proposalCreatedEvent); +}); + +afterEach(() => { + cleanup(); +}); + +describe('XVS Vault', () => { + test('delegate changed', () => { + const delegator = user1; + const fromDelegate = user2; + const toDelegate = user3; + /** run handler */ + const delegateChangedEvent = createDelegateChangedEvent( + delegator, + fromDelegate, + toDelegate, + ); + handleDelegateChanged(delegateChangedEvent); + // OldDelegate + const assertOldDelegateDocument = (key: string, value: string): void => { + assert.fieldEquals('Delegate', user2.toHex(), key, value); + }; + assertOldDelegateDocument('delegateCount', '-1'); + + // New Delegate + const assertNewDelegateDocument = (key: string, value: string): void => { + assert.fieldEquals('Delegate', user3.toHex(), key, value); + }; + assertNewDelegateDocument('delegateCount', '1'); + }); +}); diff --git a/subgraphs/venus-governance/tests/Permisson/index.test.ts b/subgraphs/venus-governance/tests/unit/Permisson/index.test.ts similarity index 91% rename from subgraphs/venus-governance/tests/Permisson/index.test.ts rename to subgraphs/venus-governance/tests/unit/Permisson/index.test.ts index 1867b213..d33b8c44 100644 --- a/subgraphs/venus-governance/tests/Permisson/index.test.ts +++ b/subgraphs/venus-governance/tests/unit/Permisson/index.test.ts @@ -3,15 +3,15 @@ import { afterEach, assert, clearStore, describe, test } from 'matchstick-as/ass import { PermissionGranted, PermissionRevoked, -} from '../../generated/AccessControlManager/AccessControlManger'; -import { GRANTED, REVOKED } from '../../src/constants'; +} from '../../../generated/AccessControlManager/AccessControlManger'; +import { GRANTED, REVOKED } from '../../../src/constants'; import { handlePermissionGranted, handlePermissionRevoked, -} from '../../src/mappings/accessControlManager'; -import { getPermissionId } from '../../src/utils/ids'; -import { mockContractAddress, mockFunctionSig, user1 } from '../common/constants'; -import { createPermission } from '../common/events'; +} from '../../../src/mappings/accessControlManager'; +import { getPermissionId } from '../../../src/utilities/ids'; +import { mockContractAddress, mockFunctionSig, user1 } from '../../common/constants'; +import { createPermission } from '../../common/events'; const cleanup = (): void => { clearStore(); diff --git a/yarn.lock b/yarn.lock index dcffaa35..c9f9ab93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5062,10 +5062,10 @@ __metadata: languageName: node linkType: hard -"@venusprotocol/governance-contracts@npm:^1.0.0": - version: 1.0.0 - resolution: "@venusprotocol/governance-contracts@npm:1.0.0" - checksum: 8df88f2e702da976861f6e409ab109dec24f8ac4e4e049da505ee36d36af6c2478bb4b6a2f3401f360578bd167512cb016227526bf81ebfdf3ca91ef473e7f87 +"@venusprotocol/governance-contracts@npm:^1.1.0-dev.1": + version: 1.1.0-dev.1 + resolution: "@venusprotocol/governance-contracts@npm:1.1.0-dev.1" + checksum: 314335686f1073dfff01ecf761a79ef64e9ee0c7451780a55bc66866336f1295735f24eb1e9ac11da120a12f50d9a5d1c7f831f92231c9468db695818dc15a5b languageName: node linkType: hard @@ -5116,7 +5116,7 @@ __metadata: languageName: node linkType: hard -"@venusprotocol/venus-protocol@npm:^3.1.0": +"@venusprotocol/venus-protocol@npm:3.1.0": version: 3.1.0 resolution: "@venusprotocol/venus-protocol@npm:3.1.0" dependencies: @@ -10102,6 +10102,15 @@ __metadata: languageName: node linkType: hard +"hardhat-dependency-compiler@npm:^1.1.3": + version: 1.1.3 + resolution: "hardhat-dependency-compiler@npm:1.1.3" + peerDependencies: + hardhat: ^2.0.0 + checksum: f32bd10ef259f5b316d0dbb1ab20257e0f59780d7e374d3f71efb0c550666a400575f7acfd755cc3e9ad1adcf8a1dc72cb52f7a9d984d15f4d8f6e6d1b2e480f + languageName: node + linkType: hard + "hardhat-deploy-ethers@npm:^0.3.0-beta.13": version: 0.3.0-beta.13 resolution: "hardhat-deploy-ethers@npm:0.3.0-beta.13" @@ -15760,10 +15769,10 @@ __metadata: "@types/mustache": ^4.2.1 "@typescript-eslint/eslint-plugin": ^5.40.1 "@typescript-eslint/parser": ^5.40.1 - "@venusprotocol/governance-contracts": ^1.0.0 + "@venusprotocol/governance-contracts": ^1.1.0-dev.1 "@venusprotocol/isolated-pools": 2.1.0-dev.2 "@venusprotocol/oracle": ^1.7.2 - "@venusprotocol/venus-protocol": ^3.1.0 + "@venusprotocol/venus-protocol": 3.1.0 assemblyscript: 0.19.23 chai: ^4.3.6 eslint: ^8.25.0 @@ -15773,6 +15782,7 @@ __metadata: graphql: 16.6.0 graphql-tag: 2.12.6 hardhat: ^2.10.2 + hardhat-dependency-compiler: ^1.1.3 hardhat-deploy: ^0.11.15 hardhat-deploy-ethers: ^0.3.0-beta.13 hardhat-gas-reporter: ^1.0.8 @@ -16881,9 +16891,9 @@ __metadata: languageName: unknown linkType: soft -"venus-governance@workspace:subgraphs/venus-governance": +"venus-governance-subgraph@workspace:subgraphs/venus-governance": version: 0.0.0-use.local - resolution: "venus-governance@workspace:subgraphs/venus-governance" + resolution: "venus-governance-subgraph@workspace:subgraphs/venus-governance" dependencies: "@graphprotocol/client-cli": ^3.0.0 apollo-fetch: ^0.7.0