From e6c713b937bcb5b433a57c1f2bca0ad79ebbcb95 Mon Sep 17 00:00:00 2001 From: Grezle <4310551+grezle@users.noreply.github.com> Date: Wed, 29 Jun 2022 23:39:42 +0100 Subject: [PATCH] feat: Implement stakingPoolMediator (#21) * feat: implement StakingPoolMediator and update mappings * chore: update renovate config --- .gitignore | 2 + abis/BondFactory.json | 13 + abis/BondMediator.json | 13 + abis/SingleCollateralMultiRewardBond.json | 13 + abis/StakingPool.json | 484 ++----- abis/StakingPoolFactory.json | 357 +----- abis/StakingPoolMediator.json | 1384 +++++++++++++++++++++ config/goerli.json | 4 + config/local.json | 4 + config/mainnet.json | 4 + config/polygon.json | 4 + config/rinkeby.json | 4 + contracts.cfg | 2 +- renovate.json | 10 +- schema.graphql | 389 ++++-- src/bond.ts | 2 + src/bondFactory.ts | 30 +- src/bondMediator.ts | 31 +- src/stakingPool.ts | 121 +- src/stakingPoolFactory.ts | 128 +- src/stakingPoolMediator.ts | 400 ++++++ subgraph.template.yaml | 146 ++- tests/bondFactory.test.ts | 49 +- tests/bondMediator.test.ts | 43 +- tests/stakingPool.test.ts | 250 ++-- tests/stakingPoolFactory.test.ts | 205 ++- tests/stakingPoolMediator.test.ts | 784 ++++++++++++ tests/utils.ts | 19 +- 28 files changed, 3667 insertions(+), 1228 deletions(-) create mode 100644 abis/StakingPoolMediator.json create mode 100644 src/stakingPoolMediator.ts create mode 100644 tests/stakingPoolMediator.test.ts diff --git a/.gitignore b/.gitignore index 00abf93..0d634c4 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ yarn-error.log *.tsbuildinfo *.log .bin +.coverage +matchstick diff --git a/abis/BondFactory.json b/abis/BondFactory.json index 24c8c1f..be19239 100644 --- a/abis/BondFactory.json +++ b/abis/BondFactory.json @@ -159,6 +159,19 @@ "name": "ERC20Sweep", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, { "anonymous": false, "inputs": [ diff --git a/abis/BondMediator.json b/abis/BondMediator.json index e3636c4..486ce07 100644 --- a/abis/BondMediator.json +++ b/abis/BondMediator.json @@ -287,6 +287,19 @@ "name": "GrantGlobalRole", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, { "anonymous": false, "inputs": [ diff --git a/abis/SingleCollateralMultiRewardBond.json b/abis/SingleCollateralMultiRewardBond.json index b2bab7b..134781b 100644 --- a/abis/SingleCollateralMultiRewardBond.json +++ b/abis/SingleCollateralMultiRewardBond.json @@ -224,6 +224,19 @@ "name": "FullCollateral", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, { "anonymous": false, "inputs": [ diff --git a/abis/StakingPool.json b/abis/StakingPool.json index 611db71..6001d0c 100644 --- a/abis/StakingPool.json +++ b/abis/StakingPool.json @@ -5,17 +5,17 @@ { "indexed": true, "internalType": "address", - "name": "user", + "name": "beneficiary", "type": "address" }, { - "indexed": false, - "internalType": "uint256", - "name": "depositAmount", - "type": "uint256" + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" } ], - "name": "Deposit", + "name": "BeneficiaryUpdate", "type": "event" }, { @@ -24,11 +24,17 @@ { "indexed": true, "internalType": "address", - "name": "admin", + "name": "user", "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "depositAmount", + "type": "uint256" } ], - "name": "EmergencyMode", + "name": "Deposit", "type": "event" }, { @@ -36,21 +42,21 @@ "inputs": [ { "indexed": true, - "internalType": "uint256", - "name": "daoId", - "type": "uint256" + "internalType": "address", + "name": "beneficiary", + "type": "address" }, { "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" + "internalType": "address", + "name": "tokens", + "type": "address" }, { "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { "indexed": true, @@ -59,32 +65,20 @@ "type": "address" } ], - "name": "GrantDaoRole", + "name": "ERC20Sweep", "type": "event" }, { "anonymous": false, "inputs": [ - { - "indexed": false, - "internalType": "bytes32", - "name": "indexedrole", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - }, { "indexed": true, "internalType": "address", - "name": "instigator", + "name": "admin", "type": "address" } ], - "name": "GrantGlobalRole", + "name": "EmergencyMode", "type": "event" }, { @@ -110,26 +104,26 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "user", - "type": "address" + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" } ], - "name": "NoRewards", + "name": "Initialized", "type": "event" }, { "anonymous": false, "inputs": [ { - "indexed": false, + "indexed": true, "internalType": "address", - "name": "account", + "name": "user", "type": "address" } ], - "name": "Paused", + "name": "NoRewards", "type": "event" }, { @@ -137,55 +131,31 @@ "inputs": [ { "indexed": true, - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": false, "internalType": "address", - "name": "account", + "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", - "name": "instigator", + "name": "newOwner", "type": "address" } ], - "name": "RevokeDaoRole", + "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, { "indexed": false, "internalType": "address", "name": "account", "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "instigator", - "type": "address" } ], - "name": "RevokeGlobalRole", + "name": "Paused", "type": "event" }, { @@ -406,239 +376,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantDaoAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantDaoCreatorRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantDaoMeepleRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantSuperUserRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantSysAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoAdminAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoCreatorAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoMeepleAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoRole", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasGlobalRole", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasSuperUserAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasSysAdminAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -724,6 +461,11 @@ "internalType": "uint32", "name": "rewardsTimestamp", "type": "uint32" + }, + { + "internalType": "address", + "name": "beneficiary", + "type": "address" } ], "name": "initialize", @@ -807,95 +549,40 @@ }, { "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", + "name": "owner", "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeDaoAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ { "internalType": "address", - "name": "account", + "name": "", "type": "address" } ], - "name": "revokeDaoCreatorRole", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeDaoMeepleRole", + "inputs": [], + "name": "pause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "paused", + "outputs": [ { - "internalType": "address", - "name": "account", - "type": "address" + "internalType": "bool", + "name": "", + "type": "bool" } ], - "name": "revokeSuperUserRole", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeSysAdminRole", + "inputs": [], + "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -1008,6 +695,37 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokens", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "sweepERC20Tokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "tokenSweepBeneficiary", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "totalStakedAmount", @@ -1021,6 +739,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "unpause", @@ -1028,6 +759,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "newBeneficiary", + "type": "address" + } + ], + "name": "updateTokenSweepBeneficiary", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "withdraw", diff --git a/abis/StakingPoolFactory.json b/abis/StakingPoolFactory.json index e469e64..be858a0 100644 --- a/abis/StakingPoolFactory.json +++ b/abis/StakingPoolFactory.json @@ -4,20 +4,8 @@ "inputs": [ { "indexed": true, - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": false, "internalType": "address", - "name": "account", + "name": "beneficiary", "type": "address" }, { @@ -27,24 +15,30 @@ "type": "address" } ], - "name": "GrantDaoRole", + "name": "BeneficiaryUpdate", "type": "event" }, { "anonymous": false, "inputs": [ { - "indexed": false, - "internalType": "bytes32", - "name": "indexedrole", - "type": "bytes32" + "indexed": true, + "internalType": "address", + "name": "beneficiary", + "type": "address" }, { - "indexed": false, + "indexed": true, "internalType": "address", - "name": "account", + "name": "tokens", "type": "address" }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, { "indexed": true, "internalType": "address", @@ -52,7 +46,7 @@ "type": "address" } ], - "name": "GrantGlobalRole", + "name": "ERC20Sweep", "type": "event" }, { @@ -60,12 +54,12 @@ "inputs": [ { "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" + "internalType": "uint8", + "name": "version", + "type": "uint8" } ], - "name": "Paused", + "name": "Initialized", "type": "event" }, { @@ -73,55 +67,31 @@ "inputs": [ { "indexed": true, - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "indexed": false, "internalType": "address", - "name": "account", + "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", - "name": "instigator", + "name": "newOwner", "type": "address" } ], - "name": "RevokeDaoRole", + "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, { "indexed": false, "internalType": "address", "name": "account", "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "instigator", - "type": "address" } ], - "name": "RevokeGlobalRole", + "name": "Paused", "type": "event" }, { @@ -326,95 +296,42 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantDaoAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { "internalType": "address", - "name": "account", + "name": "beneficiary", "type": "address" } ], - "name": "grantDaoCreatorRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantDaoMeepleRole", + "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "owner", + "outputs": [ { "internalType": "address", - "name": "account", + "name": "", "type": "address" } ], - "name": "grantSuperUserRole", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "grantSysAdminRole", + "inputs": [], + "name": "pause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoAdminAccess", + "inputs": [], + "name": "paused", "outputs": [ { "internalType": "bool", @@ -426,224 +343,59 @@ "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoCreatorAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, { "internalType": "address", - "name": "account", + "name": "tokens", "type": "address" - } - ], - "name": "hasDaoMeepleAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ + }, { "internalType": "uint256", - "name": "daoId", + "name": "amount", "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasDaoRole", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "role", - "type": "bytes32" - }, - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasGlobalRole", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "hasSuperUserAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" } ], - "name": "hasSysAdminAccess", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "initialize", + "name": "sweepERC20Tokens", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", + "name": "tokenSweepBeneficiary", "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, { "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeDaoAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "account", + "name": "", "type": "address" } ], - "name": "revokeDaoCreatorRole", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "uint256", - "name": "daoId", - "type": "uint256" - }, { "internalType": "address", - "name": "account", + "name": "newOwner", "type": "address" } ], - "name": "revokeDaoMeepleRole", + "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "revokeSuperUserRole", + "inputs": [], + "name": "unpause", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -652,18 +404,11 @@ "inputs": [ { "internalType": "address", - "name": "account", + "name": "newBeneficiary", "type": "address" } ], - "name": "revokeSysAdminRole", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", + "name": "updateTokenSweepBeneficiary", "outputs": [], "stateMutability": "nonpayable", "type": "function" diff --git a/abis/StakingPoolMediator.json b/abis/StakingPoolMediator.json new file mode 100644 index 0000000..6776b5f --- /dev/null +++ b/abis/StakingPoolMediator.json @@ -0,0 +1,1384 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "collateralTokens", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "AddCollateralWhitelist", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "stakingPool", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "AddStakingPool", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beacon", + "type": "address" + } + ], + "name": "BeaconUpgraded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beneficiary", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "BeneficiaryUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "id", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "treasury", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "CreateDao", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "data", + "type": "string" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "DaoMetaDataUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "treasury", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "DaoTreasuryUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "beneficiary", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokens", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "ERC20Sweep", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "GrantDaoRole", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "indexedrole", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "GrantGlobalRole", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "collateralTokens", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "RemoveCollateralWhitelist", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "RevokeDaoRole", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "RevokeGlobalRole", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousCreator", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "updateCreator", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "instigator", + "type": "address" + } + ], + "name": "StakingPoolCreatorUpdate", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "erc20CapableTreasury", + "type": "address" + } + ], + "name": "createDao", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "minTotalPoolStake", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "maxTotalPoolStake", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "minimumContribution", + "type": "uint128" + }, + { + "internalType": "uint32", + "name": "epochDuration", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "epochStartTimestamp", + "type": "uint32" + }, + { + "internalType": "address", + "name": "treasury", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "stakeToken", + "type": "address" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "tokens", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ratio", + "type": "uint256" + } + ], + "internalType": "struct StakingPoolLib.Reward[]", + "name": "rewardTokens", + "type": "tuple[]" + }, + { + "internalType": "enum StakingPoolLib.RewardType", + "name": "rewardType", + "type": "uint8" + } + ], + "internalType": "struct StakingPoolLib.Config", + "name": "config", + "type": "tuple" + }, + { + "internalType": "bool", + "name": "launchPaused", + "type": "bool" + }, + { + "internalType": "uint32", + "name": "rewardsAvailableTimestamp", + "type": "uint32" + } + ], + "name": "createManagedStakingPool", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + } + ], + "name": "daoCollateralSymbolWhitelist", + "outputs": [ + { + "internalType": "string[]", + "name": "", + "type": "string[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + } + ], + "name": "daoMetaData", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + } + ], + "name": "daoTreasury", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantDaoAdminRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantDaoCreatorRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantDaoMeepleRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantSuperUserRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantSysAdminRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasDaoAdminAccess", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasDaoCreatorAccess", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasDaoMeepleAccess", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasDaoRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasGlobalRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasSuperUserAccess", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasSysAdminAccess", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "highestDaoId", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract StakingPoolCreator", + "name": "factory", + "type": "address" + }, + { + "internalType": "address", + "name": "treasury", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "erc20CollateralTokens", + "type": "address" + } + ], + "name": "isAllowedDaoCollateral", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeDaoAdminRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeDaoCreatorRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeDaoMeepleRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeSuperUserRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeSysAdminRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "replacement", + "type": "address" + } + ], + "name": "setDaoTreasury", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "factory", + "type": "address" + } + ], + "name": "setStakingPoolCreator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + } + ], + "name": "stakingPoolAdminEmergencyRewardSweep", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "stakingPoolAt", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + } + ], + "name": "stakingPoolCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "stakingPoolCreator", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + } + ], + "name": "stakingPoolEnableEmergencyMode", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + }, + { + "internalType": "address", + "name": "benefactor", + "type": "address" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "tokens", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ratio", + "type": "uint256" + } + ], + "internalType": "struct StakingPoolLib.Reward[]", + "name": "rewards", + "type": "tuple[]" + } + ], + "name": "stakingPoolInitializeRewardTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + } + ], + "name": "stakingPoolPause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + }, + { + "internalType": "uint32", + "name": "timestamp", + "type": "uint32" + } + ], + "name": "stakingPoolSetRewardsAvailableTimestamp", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + }, + { + "internalType": "address", + "name": "tokens", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "stakingPoolSweepERC20Tokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + } + ], + "name": "stakingPoolUnpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "stakingPool", + "type": "address" + }, + { + "internalType": "address", + "name": "newBeneficiary", + "type": "address" + } + ], + "name": "stakingPoolUpdateTokenSweepBeneficiary", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokens", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "sweepERC20Tokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "tokenSweepBeneficiary", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newBeneficiary", + "type": "address" + } + ], + "name": "updateTokenSweepBeneficiary", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "daoId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "erc20CollateralTokens", + "type": "address" + } + ], + "name": "whitelistCollateral", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/config/goerli.json b/config/goerli.json index 84b84e8..c897113 100644 --- a/config/goerli.json +++ b/config/goerli.json @@ -9,6 +9,10 @@ "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "startBlock": 0 }, + "stakingPoolMediator": { + "address": "0xE8D2bEd7fC319be6D75FeDff3Ca56166850E35d5", + "startBlock": 0 + }, "stakingPoolFactory": { "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", "startBlock": 0 diff --git a/config/local.json b/config/local.json index 09e8a6e..a83eff9 100644 --- a/config/local.json +++ b/config/local.json @@ -9,6 +9,10 @@ "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "startBlock": 0 }, + "stakingPoolMediator": { + "address": "0xE8D2bEd7fC319be6D75FeDff3Ca56166850E35d5", + "startBlock": 0 + }, "stakingPoolFactory": { "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", "startBlock": 0 diff --git a/config/mainnet.json b/config/mainnet.json index f0a7425..35a0a8f 100644 --- a/config/mainnet.json +++ b/config/mainnet.json @@ -9,6 +9,10 @@ "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "startBlock": 0 }, + "stakingPoolMediator": { + "address": "0xE8D2bEd7fC319be6D75FeDff3Ca56166850E35d5", + "startBlock": 0 + }, "stakingPoolFactory": { "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", "startBlock": 0 diff --git a/config/polygon.json b/config/polygon.json index d877bb2..cc32bd4 100644 --- a/config/polygon.json +++ b/config/polygon.json @@ -9,6 +9,10 @@ "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "startBlock": 0 }, + "stakingPoolMediator": { + "address": "0xE8D2bEd7fC319be6D75FeDff3Ca56166850E35d5", + "startBlock": 0 + }, "stakingPoolFactory": { "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", "startBlock": 0 diff --git a/config/rinkeby.json b/config/rinkeby.json index 4342768..e99d467 100644 --- a/config/rinkeby.json +++ b/config/rinkeby.json @@ -9,6 +9,10 @@ "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "startBlock": 0 }, + "stakingPoolMediator": { + "address": "0xE8D2bEd7fC319be6D75FeDff3Ca56166850E35d5", + "startBlock": 0 + }, "stakingPoolFactory": { "address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", "startBlock": 0 diff --git a/contracts.cfg b/contracts.cfg index ef43b43..6cc9a3e 100644 --- a/contracts.cfg +++ b/contracts.cfg @@ -2,4 +2,4 @@ CONTRACT_REPO=https://github.com/windranger-io/windranger-treasury.git # csv list of contracts being mapped by this graph -CONTRACT_FILES="bond/BondFactory, bond/BondMediator, bond/SingleCollateralMultiRewardBond, staking/StakingPool, staking/StakingPoolFactory" +CONTRACT_FILES="bond/BondFactory, bond/BondMediator, bond/SingleCollateralMultiRewardBond, staking/StakingPoolFactory, staking/StakingPoolMediator, staking/StakingPool" diff --git a/renovate.json b/renovate.json index f45d8f1..64a085a 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,11 @@ { - "extends": [ - "config:base" + "extends": ["config:base"], + "rangeStrategy": "pin", + "baseBranches": ["main"], + "packageRules": [ + { + "matchUpdateTypes": ["minor", "patch", "pin", "digest"], + "automerge": false + } ] } diff --git a/schema.graphql b/schema.graphql index dcfdf39..b864544 100644 --- a/schema.graphql +++ b/schema.graphql @@ -19,10 +19,10 @@ type BondMediator @entity { factories: [BondFactory!]! @derivedFrom(field: "mediator") bonds: [Bond!]! @derivedFrom(field: "mediator") - daos: [DAO!]! @derivedFrom(field: "mediator") - daoRoles: [DAO__Role!]! @derivedFrom(field: "mediator") + daos: [Bond__DAO!]! @derivedFrom(field: "mediator") + daoRoles: [Bond__DAO__Role!]! @derivedFrom(field: "mediator") - roles: [Role!]! @derivedFrom(field: "mediator") + roles: [Bond__Role!]! @derivedFrom(field: "mediator") sweeps: [BondMediator__Sweep!]! @derivedFrom(field: "mediator") @@ -43,60 +43,19 @@ type BondMediator__Sweep @entity { createdAtTimestamp: BigInt! } -# id = `${role.toHex()}-${account.toHex()}` -type Role @entity { - id: ID! - - role: Bytes! - account: Bytes! - - mediator: BondMediator! - - lastUpdatedTimestamp: BigInt! - createdAtTimestamp: BigInt! -} - -# id = `${dao.toHex()}` -type DAO @entity { +# id = `${bondFactoryAddress.toHex()}` +type BondFactory @entity { id: ID! - dao: BigInt! + factory: Bytes! - treasury: Bytes! owner: Bytes! + beneficiary: Bytes! - mediator: BondMediator! - - metadata: DAO__Metadata! @derivedFrom(field: "dao") - - bonds: [Bond!]! @derivedFrom(field: "dao") - roles: [DAO__Role!]! @derivedFrom(field: "dao") - - collateralWhitelist: [DAO__CollateralWhitelist!]! @derivedFrom(field: "dao") - - lastUpdatedTimestamp: BigInt! - createdAtTimestamp: BigInt! -} - -# id = `${daoId.toHex()}` -type DAO__Metadata @entity { - id: ID! - - dao: DAO! - data: String! - - mediator: BondMediator! - - lastUpdatedTimestamp: BigInt! - createdAtTimestamp: BigInt! -} + bonds: [Bond!]! @derivedFrom(field: "factory") -# id = `${daoId.toHex()}-${role.toHex()}-${account.toHex()}`; -type DAO__Role @entity { - id: ID! + sweeps: [BondFactory__Sweep!]! @derivedFrom(field: "factory") - dao: DAO! - account: Bytes! - role: Bytes! + paused: Boolean! mediator: BondMediator! @@ -104,34 +63,16 @@ type DAO__Role @entity { createdAtTimestamp: BigInt! } -# id = `${daoId.toHex()}-${token.toHex()}`; -type DAO__CollateralWhitelist @entity { +# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; +type BondFactory__Sweep @entity { id: ID! - dao: DAO! token: Bytes! - - mediator: BondMediator! - - lastUpdatedTimestamp: BigInt! - createdAtTimestamp: BigInt! -} - -# id = `${bondFactoryAddress.toHex()}` -type BondFactory @entity { - id: ID! - factory: Bytes! - - owner: Bytes! + amount: BigInt! beneficiary: Bytes! - bonds: [Bond!]! @derivedFrom(field: "factory") - - paused: Boolean! - - mediator: BondMediator! + factory: BondFactory! - lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } @@ -144,7 +85,7 @@ type Bond @entity { treasury: Bytes! beneficiary: Bytes! - dao: DAO! + dao: Bond__DAO! factory: BondFactory! mediator: BondMediator! @@ -181,61 +122,84 @@ type Bond @entity { } # id = `${bondAddress.toHex()}` -type Bond__Metadata @entity { +type Bond__Configuration @entity { id: ID! bond: Bond! - name: String! - symbol: String! - data: String! + + debtTokenAmount: BigInt! + collateralTokens: Bytes! + expiryTimestamp: BigInt! + minimumDeposit: BigInt! lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } -# id = `${bondAddress.toHex()}` -type Bond__Configuration @entity { +# id = `${dao.toHex()}` +type Bond__DAO @entity { id: ID! + dao: BigInt! - bond: Bond! + treasury: Bytes! + owner: Bytes! + + metadata: Bond__DAO__Metadata! @derivedFrom(field: "dao") - debtTokenAmount: BigInt! - collateralTokens: Bytes! - expiryTimestamp: BigInt! - minimumDeposit: BigInt! + bonds: [Bond!]! @derivedFrom(field: "dao") + roles: [Bond__DAO__Role!]! @derivedFrom(field: "dao") + + collateralWhitelist: [Bond__DAO__CollateralWhitelist!]! @derivedFrom(field: "dao") + + mediator: BondMediator! lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } -# id = `${bondAddress.toHex()}-${tokens.toHex()}`; -type Bond__RewardPool @entity { +# id = `${daoId.toHex()}` +type Bond__DAO__Metadata @entity { id: ID! - bond: Bond! + dao: Bond__DAO! + data: String! - tokens: Bytes! - amount: BigInt! - timeLock: BigInt! - collateralAmount: BigInt! + mediator: BondMediator! + stakingPoolMediator: StakingPoolMediator! lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } -# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; -type Bond__Sweep @entity { +# id = `${daoId.toHex()}-${role.toHex()}-${account.toHex()}`; +type Bond__DAO__Role @entity { id: ID! - bond: Bond! + dao: Bond__DAO! + account: Bytes! + role: Bytes! + mediator: BondMediator! + stakingPoolMediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${daoId.toHex()}-${token.toHex()}`; +type Bond__DAO__CollateralWhitelist @entity { + id: ID! + + dao: Bond__DAO! token: Bytes! - amount: BigInt! - beneficiary: Bytes! + mediator: BondMediator! + stakingPoolMediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } - + # id = `${bondAddress.toHex()}-${depositor.toHex()}-${collateralTokens.toHex()}`; type Bond__Deposit @entity { id: ID! @@ -250,6 +214,19 @@ type Bond__Deposit @entity { createdAtTimestamp: BigInt! } +# id = `${bondAddress.toHex()}` +type Bond__Metadata @entity { + id: ID! + + bond: Bond! + name: String! + symbol: String! + data: String! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + # id = `${bondAddress.toHex()}-${redeemer.toHex()}-${debtTokens.toHex()}`; type Bond__Redemption @entity { id: ID! @@ -267,28 +244,57 @@ type Bond__Redemption @entity { } # id = `${transactionHash.toHex()}-${logIndex.toHex()}`; -type Bond__RewardDebt @entity { +type Bond__RewardClaimed @entity { id: ID! bond: Bond! - rewardDebt: BigInt! claimant: Bytes! tokens: Bytes! + amount: BigInt! createdAtTimestamp: BigInt! } # id = `${transactionHash.toHex()}-${logIndex.toHex()}`; -type Bond__RewardClaimed @entity { +type Bond__RewardDebt @entity { id: ID! bond: Bond! + rewardDebt: BigInt! claimant: Bytes! + tokens: Bytes! + + createdAtTimestamp: BigInt! +} + +# id = `${bondAddress.toHex()}-${tokens.toHex()}`; +type Bond__RewardPool @entity { + id: ID! + + bond: Bond! + tokens: Bytes! amount: BigInt! + timeLock: BigInt! + collateralAmount: BigInt! + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${role.toHex()}-${account.toHex()}` +type Bond__Role @entity { + id: ID! + + role: Bytes! + account: Bytes! + + mediator: BondMediator! + stakingPoolMediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } @@ -318,12 +324,33 @@ type Bond__Transfer @entity { createdAtTimestamp: BigInt! } +# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; +type Bond__Sweep @entity { + id: ID! + + bond: Bond! + + token: Bytes! + amount: BigInt! + beneficiary: Bytes! + + createdAtTimestamp: BigInt! +} + # id = `${stakingPoolFactoryAddress.toHex()}`; type StakingPoolFactory @entity { id: ID! factory: Bytes! + dao: StakingPool__DAO! + mediator: StakingPoolMediator! + paused: Boolean! + + owner: Bytes! + beneficiary: Bytes! + + sweeps: [StakingPoolFactory__Sweep!]! @derivedFrom(field: "factory") stakingPools: [StakingPool!]! @derivedFrom(field: "factory") @@ -331,23 +358,80 @@ type StakingPoolFactory @entity { createdAtTimestamp: BigInt! } +# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; +type StakingPoolFactory__Sweep @entity { + id: ID! + + token: Bytes! + amount: BigInt! + beneficiary: Bytes! + + factory: StakingPoolFactory! + + createdAtTimestamp: BigInt! +} + +# id = `${stakingPoolMediator.toHex()}` +type StakingPoolMediator @entity { + id: ID! + mediator: Bytes! + + admin: Bytes! + beacon: Bytes! + beneficiary: Bytes! + implementation: Bytes! + paused: Boolean! + + factory: StakingPoolFactory! + + stakingPools: [StakingPool!]! @derivedFrom(field: "mediator") + sweeps: [StakingPoolMediator__Sweep!]! @derivedFrom(field: "mediator") + + factories: [StakingPoolFactory!]! @derivedFrom(field: "mediator") + + daos: [StakingPool__DAO!]! @derivedFrom(field: "mediator") + daoRoles: [StakingPool__DAO__Role!]! @derivedFrom(field: "mediator") + + roles: [StakingPool__Role!]! @derivedFrom(field: "mediator") + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; +type StakingPoolMediator__Sweep @entity { + id: ID! + + token: Bytes! + amount: BigInt! + beneficiary: Bytes! + + mediator: StakingPoolMediator! + + createdAtTimestamp: BigInt! +} + # id = `${stakingPoolAddress.toHex()}`; type StakingPool @entity { id: ID! pool: Bytes! + dao: StakingPool__DAO! + mediator: StakingPoolMediator! factory: StakingPoolFactory! paused: Boolean! emergencyMode: Boolean! creator: Bytes! + owner: Bytes! treasury: Bytes! + beneficiary: Bytes! stakeToken: Bytes! amount: BigInt! minimumContribution: BigInt! - + epochStartTimestamp: BigInt! epochDuration: BigInt! @@ -356,6 +440,7 @@ type StakingPool @entity { rewardType: Int! + sweeps: [StakingPool__Sweep!]! @derivedFrom(field: "pool") rewards: [StakingPool__Reward!]! @derivedFrom(field: "pool") deposits: [StakingPool__Deposit!]! @derivedFrom(field: "pool") withdrawals: [StakingPool__Withdrawal!]! @derivedFrom(field: "pool") @@ -364,20 +449,56 @@ type StakingPool @entity { createdAtTimestamp: BigInt! } -# id = `${stakingPoolAddress.toHex()}-${user.toHex()}`; -type StakingPool__Deposit @entity { +# id = `${dao.toHex()}` +type StakingPool__DAO @entity { id: ID! - pool: StakingPool! + dao: BigInt! - user: Bytes! - amount: BigInt! + treasury: Bytes! + owner: Bytes! + + metadata: StakingPool__DAO__Metadata! @derivedFrom(field: "dao") + + roles: [StakingPool__DAO__Role!]! @derivedFrom(field: "dao") + + stakingPools: [StakingPool!]! @derivedFrom(field: "dao") + + collateralWhitelist: [StakingPool__DAO__CollateralWhitelist!]! @derivedFrom(field: "dao") + + mediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${daoId.toHex()}-${token.toHex()}`; +type StakingPool__DAO__CollateralWhitelist @entity { + id: ID! + + dao: StakingPool__DAO! + token: Bytes! + + mediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${daoId.toHex()}` +type StakingPool__DAO__Metadata @entity { + id: ID! + + dao: StakingPool__DAO! + data: String! + + mediator: StakingPoolMediator! lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } # id = `${stakingPoolAddress.toHex()}-${user.toHex()}`; -type StakingPool__Withdrawal @entity { +type StakingPool__Deposit @entity { id: ID! pool: StakingPool! @@ -419,3 +540,55 @@ type StakingPool__RewardWithdrawal @entity { lastUpdatedTimestamp: BigInt! createdAtTimestamp: BigInt! } + +# id = `${daoId.toHex()}-${role.toHex()}-${account.toHex()}`; +type StakingPool__DAO__Role @entity { + id: ID! + + dao: StakingPool__DAO! + account: Bytes! + role: Bytes! + + mediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${role.toHex()}-${account.toHex()}` +type StakingPool__Role @entity { + id: ID! + + role: Bytes! + account: Bytes! + + mediator: StakingPoolMediator! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} + +# id = `${transactionHash.toHex()}-${logIndex.toHex()}`; +type StakingPool__Sweep @entity { + id: ID! + + token: Bytes! + amount: BigInt! + beneficiary: Bytes! + + pool: StakingPool! + + createdAtTimestamp: BigInt! +} + +# id = `${stakingPoolAddress.toHex()}-${user.toHex()}`; +type StakingPool__Withdrawal @entity { + id: ID! + pool: StakingPool! + + user: Bytes! + amount: BigInt! + + lastUpdatedTimestamp: BigInt! + createdAtTimestamp: BigInt! +} diff --git a/src/bond.ts b/src/bond.ts index 0809ccf..a0d7477 100644 --- a/src/bond.ts +++ b/src/bond.ts @@ -1,4 +1,5 @@ import { BigInt } from '@graphprotocol/graph-ts'; + import { Bond, Bond__Metadata as Metadata, @@ -11,6 +12,7 @@ import { Bond__SlashDeposit as SlashDeposit, Bond__Transfer as Transfer } from '../generated/schema'; + import { AllowRedemption, BeneficiaryUpdate, diff --git a/src/bondFactory.ts b/src/bondFactory.ts index dd0ea82..1e4fef5 100644 --- a/src/bondFactory.ts +++ b/src/bondFactory.ts @@ -1,17 +1,21 @@ import { - BondFactory, Bond, Bond__Metadata as Metadata, Bond__Configuration as Configuration, - Bond__RewardPool as RewardPool + Bond__RewardPool as RewardPool, + BondFactory, + BondFactory__Sweep as Sweep } from '../generated/schema'; + import { BeneficiaryUpdate, CreateBond, + ERC20Sweep, OwnershipTransferred, Paused, Unpaused } from '../generated/BondFactory/BondFactory'; + import { SingleCollateralMultiRewardBond as SingleCollateralMultiRewardBondTemplate } from '../generated/templates'; // - CreateBond(indexed address,(string,string,string),(uint256,address,uint256,uint256),(address,uint128,uint128)[],indexed address,indexed address) @@ -108,6 +112,28 @@ export function handleBeneficiaryUpdate(event: BeneficiaryUpdate): void { bondFactory.save(); } +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +export function handleERC20Sweep(event: ERC20Sweep): void { + const sweepId = `${event.transaction.hash.toHex()}-${event.logIndex.toHex()}`; + + let bondFactory = BondFactory.load(event.address.toHex()); + bondFactory = + bondFactory === null ? new BondFactory(event.address.toHex()) : bondFactory; + + let sweep = Sweep.load(sweepId); + sweep = sweep === null ? new Sweep(sweepId) : sweep; + + sweep.token = event.params.tokens; + sweep.amount = event.params.amount; + sweep.beneficiary = event.params.beneficiary; + + sweep.factory = bondFactory.id; + + sweep.createdAtTimestamp = event.block.timestamp; + + sweep.save(); +} + // - OwnershipTransferred(indexed address,indexed address) export function handleOwnershipTransferred(event: OwnershipTransferred): void { let bondFactory = BondFactory.load(event.address.toHex()); diff --git a/src/bondMediator.ts b/src/bondMediator.ts index a6d0387..721d909 100644 --- a/src/bondMediator.ts +++ b/src/bondMediator.ts @@ -1,4 +1,17 @@ import { store } from '@graphprotocol/graph-ts'; + +import { + Bond, + Bond__DAO as DAO, + Bond__DAO__CollateralWhitelist as DAOCollateralWhitelist, + Bond__DAO__Metadata as DAOMetadata, + Bond__DAO__Role as DAORole, + Bond__Role as Role, + BondFactory, + BondMediator, + BondMediator__Sweep as Sweep +} from '../generated/schema'; + import { AddBond, AddCollateralWhitelist, @@ -19,17 +32,7 @@ import { Unpaused, Upgraded } from '../generated/BondMediator/BondMediator'; -import { - Bond, - BondFactory, - BondMediator, - BondMediator__Sweep as Sweep, - DAO, - DAO__CollateralWhitelist as DAOCollateralWhitelist, - DAO__Metadata as DAOMetadata, - DAO__Role as DAORole, - Role -} from '../generated/schema'; + import { BondFactory as BondFactoryTemplate } from '../generated/templates'; // - AddBond(indexed uint256,indexed address,indexed address) @@ -314,7 +317,7 @@ export function handleRemoveCollateralWhitelist(event: RemoveCollateralWhitelist let whitelist = DAOCollateralWhitelist.load(whitelistId); whitelist = whitelist === null ? new DAOCollateralWhitelist(whitelistId) : whitelist; - store.remove('DAO__CollateralWhitelist', whitelist.id); + store.remove('Bond__DAO__CollateralWhitelist', whitelist.id); } // - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) @@ -324,7 +327,7 @@ export function handleRevokeDaoRole(event: RevokeDaoRole): void { let role = DAORole.load(roleId); role = role === null ? new DAORole(roleId) : role; - store.remove('DAO__Role', role.id); + store.remove('Bond__DAO__Role', role.id); } // - RevokeGlobalRole(indexed bytes32,address,indexed address) @@ -334,7 +337,7 @@ export function handleRevokeGlobalRole(event: RevokeGlobalRole): void { let role = Role.load(roleId); role = role === null ? new Role(roleId) : role; - store.remove('Role', role.id); + store.remove('Bond__Role', role.id); } // - Unpaused(address) diff --git a/src/stakingPool.ts b/src/stakingPool.ts index 6c36f45..a8c86bb 100644 --- a/src/stakingPool.ts +++ b/src/stakingPool.ts @@ -1,29 +1,43 @@ -import { BigInt, store } from '@graphprotocol/graph-ts'; +import { BigInt } from '@graphprotocol/graph-ts'; + import { - DAO, - DAO__Role as DAORole, - Role, StakingPool, StakingPool__Deposit as StakingPoolDeposit, StakingPool__Withdrawal as StakingPoolWithdrawl, StakingPool__Reward as StakingPoolReward, - StakingPool__RewardWithdrawal as StakingPoolRewardWithdrawal + StakingPool__RewardWithdrawal as StakingPoolRewardWithdrawal, + StakingPool__Sweep as Sweep } from '../generated/schema'; + import { + BeneficiaryUpdate, Deposit as DepositFilter, EmergencyMode, - GrantDaoRole, - GrantGlobalRole, + ERC20Sweep, InitializeRewards, + OwnershipTransferred, Paused, - RevokeDaoRole, - RevokeGlobalRole, RewardsAvailableTimestamp, Unpaused, WithdrawRewards, WithdrawStake } from '../generated/templates/StakingPool/StakingPool'; +// - BeneficiaryUpdate(indexed address,indexed address) +export function handleBeneficiaryUpdate(event: BeneficiaryUpdate): void { + let stakingPool = StakingPool.load(event.address.toHex()); + stakingPool = + stakingPool === null ? new StakingPool(event.address.toHex()) : stakingPool; + + stakingPool.beneficiary = event.params.beneficiary; + + stakingPool.createdAtTimestamp = + stakingPool.createdAtTimestamp || event.block.timestamp; + stakingPool.lastUpdatedTimestamp = event.block.timestamp; + + stakingPool.save(); +} + // - Deposit(indexed address,uint256) export function handleDeposit(event: DepositFilter): void { let stakingPool = StakingPool.load(event.address.toHex()); @@ -56,53 +70,45 @@ export function handleDeposit(event: DepositFilter): void { deposit.save(); } -// - EmergencyMode(indexed address) -export function handleEmergencyMode(event: EmergencyMode): void { - let stakingPool = StakingPool.load(event.address.toHex()); - stakingPool = - stakingPool === null ? new StakingPool(event.address.toHex()) : stakingPool; +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +export function handleERC20Sweep(event: ERC20Sweep): void { + const sweepId = `${event.transaction.hash.toHex()}-${event.logIndex.toHex()}`; - stakingPool.emergencyMode = true; + let stakingpool = StakingPool.load(event.address.toHex()); + stakingpool = + stakingpool === null ? new StakingPool(event.address.toHex()) : stakingpool; - stakingPool.lastUpdatedTimestamp = event.block.timestamp; + stakingpool.lastUpdatedTimestamp = event.block.timestamp; - stakingPool.save(); -} + stakingpool.save(); -// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) -export function handleGrantDaoRole(event: GrantDaoRole): void { - const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; + // -- - let dao = DAO.load(event.params.daoId.toHex()); - dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + let sweep = Sweep.load(sweepId); + sweep = sweep === null ? new Sweep(sweepId) : sweep; - let role = DAORole.load(roleId); - role = role === null ? new DAORole(roleId) : role; + sweep.pool = stakingpool.id; - role.dao = dao.id; - role.role = event.params.role; - role.account = event.params.account; + sweep.token = event.params.tokens; + sweep.amount = event.params.amount; + sweep.beneficiary = event.params.beneficiary; - role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; - role.lastUpdatedTimestamp = event.block.timestamp; + sweep.createdAtTimestamp = event.block.timestamp; - role.save(); + sweep.save(); } -// - GrantGlobalRole(bytes32,address,indexed address) -export function handleGrantGlobalRole(event: GrantGlobalRole): void { - const roleId = `${event.params.indexedrole.toHex()}-${event.params.account.toHex()}`; - - let role = Role.load(roleId); - role = role === null ? new Role(roleId) : role; +// - EmergencyMode(indexed address) +export function handleEmergencyMode(event: EmergencyMode): void { + let stakingPool = StakingPool.load(event.address.toHex()); + stakingPool = + stakingPool === null ? new StakingPool(event.address.toHex()) : stakingPool; - role.role = event.params.indexedrole; - role.account = event.params.account; + stakingPool.emergencyMode = true; - role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; - role.lastUpdatedTimestamp = event.block.timestamp; + stakingPool.lastUpdatedTimestamp = event.block.timestamp; - role.save(); + stakingPool.save(); } // - InitializeRewards(address,uint256) @@ -132,37 +138,32 @@ export function handleInitializeRewards(event: InitializeRewards): void { reward.save(); } -// - Paused(address) -export function handlePaused(event: Paused): void { +// - OwnershipTransferred(indexed address,indexed address) +export function handleOwnershipTransferred(event: OwnershipTransferred): void { let stakingPool = StakingPool.load(event.address.toHex()); stakingPool = stakingPool === null ? new StakingPool(event.address.toHex()) : stakingPool; - stakingPool.paused = true; + stakingPool.owner = event.params.newOwner; + stakingPool.createdAtTimestamp = + stakingPool.createdAtTimestamp || event.block.timestamp; stakingPool.lastUpdatedTimestamp = event.block.timestamp; stakingPool.save(); } -// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) -export function handleRevokeDaoRole(event: RevokeDaoRole): void { - const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; - - let role = DAORole.load(roleId); - role = role === null ? new DAORole(roleId) : role; - - store.remove('DAO__Role', role.id); -} +// - Paused(address) +export function handlePaused(event: Paused): void { + let stakingPool = StakingPool.load(event.address.toHex()); + stakingPool = + stakingPool === null ? new StakingPool(event.address.toHex()) : stakingPool; -// - RevokeGlobalRole(indexed bytes32,address,indexed address) -export function handleRevokeGlobalRole(event: RevokeGlobalRole): void { - const roleId = `${event.params.role.toHex()}-${event.params.account.toHex()}`; + stakingPool.paused = true; - let role = Role.load(roleId); - role = role === null ? new Role(roleId) : role; + stakingPool.lastUpdatedTimestamp = event.block.timestamp; - store.remove('Role', role.id); + stakingPool.save(); } // - RewardsAvailableTimestamp(uint32) diff --git a/src/stakingPoolFactory.ts b/src/stakingPoolFactory.ts index 5ed3b88..c6d46c5 100644 --- a/src/stakingPoolFactory.ts +++ b/src/stakingPoolFactory.ts @@ -1,23 +1,70 @@ -import { BigInt, store } from '@graphprotocol/graph-ts'; +import { BigInt } from '@graphprotocol/graph-ts'; + import { - DAO, - DAO__Role as DAORole, - Role, StakingPool, + StakingPool__Reward as StakingPoolReward, StakingPoolFactory, - StakingPool__Reward as StakingPoolReward + StakingPoolFactory__Sweep as Sweep } from '../generated/schema'; + import { - GrantDaoRole, - GrantGlobalRole, + BeneficiaryUpdate, + ERC20Sweep, + OwnershipTransferred, Paused, - RevokeDaoRole, - RevokeGlobalRole, StakingPoolCreated, Unpaused } from '../generated/StakingPoolFactory/StakingPoolFactory'; + import { StakingPool as StakingPoolTemplate } from '../generated/templates'; +// - BeneficiaryUpdate(indexed address,indexed address) +export function handleBeneficiaryUpdate(event: BeneficiaryUpdate): void { + let stakingPoolFactory = StakingPoolFactory.load(event.address.toHex()); + stakingPoolFactory = + stakingPoolFactory === null + ? new StakingPoolFactory(event.address.toHex()) + : stakingPoolFactory; + + stakingPoolFactory.beneficiary = event.params.beneficiary; + + stakingPoolFactory.createdAtTimestamp = + stakingPoolFactory.createdAtTimestamp || event.block.timestamp; + stakingPoolFactory.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolFactory.save(); +} + +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +export function handleERC20Sweep(event: ERC20Sweep): void { + const sweepId = `${event.transaction.hash.toHex()}-${event.logIndex.toHex()}`; + + let stakingPoolFactory = StakingPoolFactory.load(event.address.toHex()); + stakingPoolFactory = + stakingPoolFactory === null + ? new StakingPoolFactory(event.address.toHex()) + : stakingPoolFactory; + + stakingPoolFactory.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolFactory.save(); + + // -- + + let sweep = Sweep.load(sweepId); + sweep = sweep === null ? new Sweep(sweepId) : sweep; + + sweep.factory = stakingPoolFactory.id; + + sweep.token = event.params.tokens; + sweep.amount = event.params.amount; + sweep.beneficiary = event.params.beneficiary; + + sweep.createdAtTimestamp = event.block.timestamp; + + sweep.save(); +} + // - StakingPoolCreated(indexed address,address,indexed address,(address,uint256,uint256)[],address,uint128,uint128,uint128,uint8) export function handleStakingPoolCreated(event: StakingPoolCreated): void { let stakingPoolFactory = StakingPoolFactory.load(event.address.toHex()); @@ -80,40 +127,21 @@ export function handleStakingPoolCreated(event: StakingPoolCreated): void { StakingPoolTemplate.create(event.params.stakingPool); } -// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) -export function handleGrantDaoRole(event: GrantDaoRole): void { - const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; - - let dao = DAO.load(event.params.daoId.toHex()); - dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; - - let role = DAORole.load(roleId); - role = role === null ? new DAORole(roleId) : role; - - role.dao = dao.id; - role.role = event.params.role; - role.account = event.params.account; - - role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; - role.lastUpdatedTimestamp = event.block.timestamp; - - role.save(); -} - -// - GrantGlobalRole(bytes32,address,indexed address) -export function handleGrantGlobalRole(event: GrantGlobalRole): void { - const roleId = `${event.params.indexedrole.toHex()}-${event.params.account.toHex()}`; - - let role = Role.load(roleId); - role = role === null ? new Role(roleId) : role; +// - OwnershipTransferred(indexed address,indexed address) +export function handleOwnershipTransferred(event: OwnershipTransferred): void { + let stakingPoolFactory = StakingPoolFactory.load(event.address.toHex()); + stakingPoolFactory = + stakingPoolFactory === null + ? new StakingPoolFactory(event.address.toHex()) + : stakingPoolFactory; - role.role = event.params.indexedrole; - role.account = event.params.account; + stakingPoolFactory.owner = event.params.newOwner; - role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; - role.lastUpdatedTimestamp = event.block.timestamp; + stakingPoolFactory.createdAtTimestamp = + stakingPoolFactory.createdAtTimestamp || event.block.timestamp; + stakingPoolFactory.lastUpdatedTimestamp = event.block.timestamp; - role.save(); + stakingPoolFactory.save(); } // - Paused(address) @@ -131,26 +159,6 @@ export function handlePaused(event: Paused): void { stakingPoolFactory.save(); } -// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) -export function handleRevokeDaoRole(event: RevokeDaoRole): void { - const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; - - let role = DAORole.load(roleId); - role = role === null ? new DAORole(roleId) : role; - - store.remove('DAO__Role', role.id); -} - -// - RevokeGlobalRole(indexed bytes32,address,indexed address) -export function handleRevokeGlobalRole(event: RevokeGlobalRole): void { - const roleId = `${event.params.role.toHex()}-${event.params.account.toHex()}`; - - let role = Role.load(roleId); - role = role === null ? new Role(roleId) : role; - - store.remove('Role', role.id); -} - // - Unpaused(address) export function handleUnpaused(event: Unpaused): void { let stakingPoolFactory = StakingPoolFactory.load(event.address.toHex()); diff --git a/src/stakingPoolMediator.ts b/src/stakingPoolMediator.ts new file mode 100644 index 0000000..a1a7a14 --- /dev/null +++ b/src/stakingPoolMediator.ts @@ -0,0 +1,400 @@ +import { store } from '@graphprotocol/graph-ts'; + +import { + StakingPool, + StakingPool__DAO as DAO, + StakingPool__DAO__CollateralWhitelist as DAOCollateralWhitelist, + StakingPool__DAO__Metadata as DAOMetadata, + StakingPool__DAO__Role as DAORole, + StakingPool__Role as StakingPoolRole, + StakingPoolFactory, + StakingPoolMediator, + StakingPoolMediator__Sweep as Sweep +} from '../generated/schema'; + +import { + AddCollateralWhitelist, + AddStakingPool, + AdminChanged, + BeaconUpgraded, + BeneficiaryUpdate, + CreateDao, + DaoMetaDataUpdate, + DaoTreasuryUpdate, + ERC20Sweep, + GrantDaoRole, + GrantGlobalRole, + Paused, + RemoveCollateralWhitelist, + RevokeDaoRole, + RevokeGlobalRole, + StakingPoolCreatorUpdate, + Unpaused, + Upgraded +} from '../generated/StakingPoolMediator/StakingPoolMediator'; + +import { StakingPoolFactory as StakingPoolFactoryTemplate } from '../generated/templates'; + +// - AddCollateralWhitelist(indexed uint256,indexed address,indexed address) +export function handleAddCollateralWhitelist(event: AddCollateralWhitelist): void { + const whitelistId = `${event.params.daoId.toHex()}-${event.params.collateralTokens.toHex()}`; + + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let dao = DAO.load(event.params.daoId.toHex()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + dao.lastUpdatedTimestamp = event.block.timestamp; + + dao.save(); + + let whitelist = DAOCollateralWhitelist.load(whitelistId); + whitelist = whitelist === null ? new DAOCollateralWhitelist(whitelistId) : whitelist; + + whitelist.dao = dao.id; + whitelist.token = event.params.collateralTokens; + whitelist.mediator = stakingPoolMediator.id; + + whitelist.createdAtTimestamp = whitelist.createdAtTimestamp || event.block.timestamp; + whitelist.lastUpdatedTimestamp = event.block.timestamp; + + whitelist.save(); +} + +// - AddStakingPool(indexed uint256,indexed address,indexed address) +export function handleAddStakingPool(event: AddStakingPool): void { + let dao = DAO.load(event.params.daoId.toString()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let stakingPool = StakingPool.load(event.params.stakingPool.toHex()); + stakingPool = + stakingPool === null + ? new StakingPool(event.params.stakingPool.toHex()) + : stakingPool; + + stakingPool.dao = dao.id; + stakingPool.mediator = stakingPoolMediator.id; + + stakingPool.createdAtTimestamp = + stakingPool.createdAtTimestamp || event.block.timestamp; + stakingPool.lastUpdatedTimestamp = event.block.timestamp; + + stakingPool.save(); +} + +// - AdminChanged(address,address) +export function handleAdminChanged(event: AdminChanged): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.admin = event.params.newAdmin; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} + +// - BeaconUpgraded(indexed address) +export function handleBeaconUpgraded(event: BeaconUpgraded): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.beacon = event.params.beacon; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} + +// - BeneficiaryUpdate(indexed address,indexed address) +export function handleBeneficiaryUpdate(event: BeneficiaryUpdate): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.beneficiary = event.params.beneficiary; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} + +// - CreateDao(indexed uint256,indexed address,indexed address) +export function handleCreateDao(event: CreateDao): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let dao = DAO.load(event.params.id.toHex()); + dao = dao === null ? new DAO(event.params.id.toHex()) : dao; + + dao.dao = event.params.id; + dao.mediator = stakingPoolMediator.id; + dao.treasury = event.params.treasury; + dao.owner = event.params.instigator; + + dao.createdAtTimestamp = dao.createdAtTimestamp || event.block.timestamp; + dao.lastUpdatedTimestamp = event.block.timestamp; + + dao.save(); +} + +// - DaoMetaDataUpdate(indexed uint256,string,indexed address) +export function handleDaoMetaDataUpdate(event: DaoMetaDataUpdate): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let dao = DAO.load(event.params.daoId.toHex()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + dao.lastUpdatedTimestamp = event.block.timestamp; + + dao.save(); + + let metadata = DAOMetadata.load(event.params.daoId.toHex()); + metadata = metadata === null ? new DAOMetadata(event.params.daoId.toHex()) : metadata; + + metadata.data = event.params.data; + metadata.dao = dao.id; + metadata.mediator = stakingPoolMediator.id; + + metadata.createdAtTimestamp = metadata.createdAtTimestamp || event.block.timestamp; + metadata.lastUpdatedTimestamp = event.block.timestamp; + + metadata.save(); +} + +// - DaoTreasuryUpdate(indexed uint256,indexed address,indexed address) +export function handleDaoTreasuryUpdate(event: DaoTreasuryUpdate): void { + let dao = DAO.load(event.params.daoId.toHex()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + dao.treasury = event.params.treasury; + + dao.createdAtTimestamp = dao.createdAtTimestamp || event.block.timestamp; + dao.lastUpdatedTimestamp = event.block.timestamp; + + dao.save(); +} + +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +export function handleERC20Sweep(event: ERC20Sweep): void { + const sweepId = `${event.transaction.hash.toHex()}-${event.logIndex.toHex()}`; + + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let sweep = Sweep.load(sweepId); + sweep = sweep === null ? new Sweep(sweepId) : sweep; + + sweep.token = event.params.tokens; + sweep.amount = event.params.amount; + sweep.beneficiary = event.params.beneficiary; + + sweep.mediator = stakingPoolMediator.id; + + sweep.createdAtTimestamp = event.block.timestamp; + + sweep.save(); +} + +// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) +export function handleGrantDaoRole(event: GrantDaoRole): void { + const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; + + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let dao = DAO.load(event.params.daoId.toHex()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + let role = DAORole.load(roleId); + role = role === null ? new DAORole(roleId) : role; + + role.dao = dao.id; + role.mediator = stakingPoolMediator.id; + role.role = event.params.role; + role.account = event.params.account; + + role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; + role.lastUpdatedTimestamp = event.block.timestamp; + + role.save(); +} + +// - GrantGlobalRole(bytes32,address,indexed address) +export function handleGrantGlobalRole(event: GrantGlobalRole): void { + const roleId = `${event.params.indexedrole.toHex()}-${event.params.account.toHex()}`; + + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let role = StakingPoolRole.load(roleId); + role = role === null ? new StakingPoolRole(roleId) : role; + + role.mediator = stakingPoolMediator.id; + role.role = event.params.indexedrole; + role.account = event.params.account; + + role.createdAtTimestamp = role.createdAtTimestamp || event.block.timestamp; + role.lastUpdatedTimestamp = event.block.timestamp; + + role.save(); +} + +// - Paused(address) +export function handlePaused(event: Paused): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.paused = true; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} + +// - RemoveCollateralWhitelist(indexed uint256,indexed address,indexed address) +export function handleRemoveCollateralWhitelist(event: RemoveCollateralWhitelist): void { + const whitelistId = `${event.params.daoId.toHex()}-${event.params.collateralTokens.toHex()}`; + + let dao = DAO.load(event.params.daoId.toHex()); + dao = dao === null ? new DAO(event.params.daoId.toHex()) : dao; + + dao.lastUpdatedTimestamp = event.block.timestamp; + + dao.save(); + + let whitelist = DAOCollateralWhitelist.load(whitelistId); + whitelist = whitelist === null ? new DAOCollateralWhitelist(whitelistId) : whitelist; + + store.remove('StakingPool__DAO__CollateralWhitelist', whitelist.id); +} + +// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) +export function handleRevokeDaoRole(event: RevokeDaoRole): void { + const roleId = `${event.params.daoId.toHex()}-${event.params.role.toHex()}-${event.params.account.toHex()}`; + + let role = DAORole.load(roleId); + role = role === null ? new DAORole(roleId) : role; + + store.remove('StakingPool__DAO__Role', role.id); +} + +// - RevokeGlobalRole(indexed bytes32,address,indexed address) +export function handleRevokeGlobalRole(event: RevokeGlobalRole): void { + const roleId = `${event.params.role.toHex()}-${event.params.account.toHex()}`; + + let role = StakingPoolRole.load(roleId); + role = role === null ? new StakingPoolRole(roleId) : role; + + store.remove('StakingPool__Role', role.id); +} + +// - StakingPoolCreatorUpdate(indexed address,indexed address,indexed address) +export function handleStakingPoolCreatorUpdate(event: StakingPoolCreatorUpdate): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + let stakingPoolFactory = StakingPoolFactory.load(event.params.updateCreator.toHex()); + stakingPoolFactory = + stakingPoolFactory === null + ? new StakingPoolFactory(event.params.updateCreator.toHex()) + : stakingPoolFactory; + + stakingPoolMediator.factory = stakingPoolFactory.id; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); + + stakingPoolFactory.mediator = stakingPoolMediator.id; + stakingPoolFactory.factory = event.params.updateCreator; + stakingPoolFactory.createdAtTimestamp = event.block.timestamp; + stakingPoolFactory.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolFactory.save(); + + // Bind to new template to capture events on the new StakingPoolFactory + StakingPoolFactoryTemplate.create(event.params.updateCreator); +} + +// - Unpaused(address) +export function handleUnpaused(event: Unpaused): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.paused = false; + + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} + +// - Upgraded(indexed address) +export function handleUpgraded(event: Upgraded): void { + let stakingPoolMediator = StakingPoolMediator.load(event.address.toHex()); + stakingPoolMediator = + stakingPoolMediator === null + ? new StakingPoolMediator(event.address.toHex()) + : stakingPoolMediator; + + stakingPoolMediator.implementation = event.params.implementation; + + stakingPoolMediator.createdAtTimestamp = + stakingPoolMediator.createdAtTimestamp || event.block.timestamp; + stakingPoolMediator.lastUpdatedTimestamp = event.block.timestamp; + + stakingPoolMediator.save(); +} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index c49a4ed..bb7d8b1 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -15,14 +15,14 @@ dataSources: language: wasm/assemblyscript entities: - Bond + - Bond__DAO + - Bond__DAO__CollateralWhitelist + - Bond__DAO__Metadata + - Bond__DAO__Role + - Bond__Role - BondFactory - BondMediator - BondMediator__Sweep - - DAO - - DAO__CollateralWhitelist - - DAO__Metadata - - DAO__Role - - Role abis: - name: BondMediator file: ./abis/BondMediator.json @@ -45,6 +45,8 @@ dataSources: handler: handleDaoMetaDataUpdate - event: DaoTreasuryUpdate(indexed uint256,indexed address,indexed address) handler: handleDaoTreasuryUpdate + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep - event: GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) handler: handleGrantDaoRole - event: GrantGlobalRole(bytes32,address,indexed address) @@ -74,11 +76,12 @@ dataSources: apiVersion: 0.0.5 language: wasm/assemblyscript entities: - - BondFactory - Bond - Bond__Metadata - Bond__Configuration - Bond__RewardPool + - BondFactory + - BondFactory__Sweep abis: - name: BondFactory file: ./abis/BondFactory.json @@ -87,6 +90,8 @@ dataSources: handler: handleBeneficiaryUpdate - event: CreateBond(indexed address,(string,string,string),(uint256,address,uint256,uint256),(address,uint128,uint128)[],indexed address,indexed address) handler: handleCreateBond + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - event: Paused(address) @@ -95,37 +100,95 @@ dataSources: handler: handleUnpaused file: ./src/bondFactory.ts - kind: ethereum/contract - name: StakingPoolFactory + name: StakingPoolMediator network: {{ network }} source: - address: "{{ contracts.stakingPoolFactory.address }}" - abi: StakingPoolFactory - startBlock: {{ contracts.stakingPoolFactory.startBlock }} + address: "{{ contracts.stakingPoolMediator.address }}" + abi: StakingPoolMediator + startBlock: {{ contracts.stakingPoolMediator.startBlock }} mapping: kind: ethereum/events apiVersion: 0.0.5 language: wasm/assemblyscript entities: - StakingPool - - StakingPool__Deposit - - StakingPool__Reward - - StakingPool__RewardWithdrawal - - StakingPool__Withdrawal + - StakingPool__DAO + - StakingPool__DAO__CollateralWhitelist + - StakingPool__DAO__Metadata + - StakingPool__DAO__Role + - StakingPool__Role - StakingPoolFactory + - StakingPoolMediator + - StakingPoolMediator__Sweep abis: - - name: StakingPoolFactory - file: ./abis/StakingPoolFactory.json + - name: StakingPoolMediator + file: ./abis/StakingPoolMediator.json eventHandlers: + - event: AddCollateralWhitelist(indexed uint256,indexed address,indexed address) + handler: handleAddCollateralWhitelist + - event: AddStakingPool(indexed uint256,indexed address,indexed address) + handler: handleAddStakingPool + - event: AdminChanged(address,address) + handler: handleAdminChanged + - event: BeaconUpgraded(indexed address) + handler: handleBeaconUpgraded + - event: BeneficiaryUpdate(indexed address,indexed address) + handler: handleBeneficiaryUpdate + - event: CreateDao(indexed uint256,indexed address,indexed address) + handler: handleCreateDao + - event: DaoMetaDataUpdate(indexed uint256,string,indexed address) + handler: handleDaoMetaDataUpdate + - event: DaoTreasuryUpdate(indexed uint256,indexed address,indexed address) + handler: handleDaoTreasuryUpdate + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep - event: GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) handler: handleGrantDaoRole - event: GrantGlobalRole(bytes32,address,indexed address) handler: handleGrantGlobalRole - event: Paused(address) handler: handlePaused + - event: RemoveCollateralWhitelist(indexed uint256,indexed address,indexed address) + handler: handleRemoveCollateralWhitelist - event: RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) handler: handleRevokeDaoRole - event: RevokeGlobalRole(indexed bytes32,address,indexed address) handler: handleRevokeGlobalRole + - event: StakingPoolCreatorUpdate(indexed address,indexed address,indexed address) + handler: handleStakingPoolCreatorUpdate + - event: Unpaused(address) + handler: handleUnpaused + - event: Upgraded(indexed address) + handler: handleUpgraded + file: ./src/stakingPoolMediator.ts + - kind: ethereum/contract + name: StakingPoolFactory + network: {{ network }} + source: + address: "{{ contracts.stakingPoolFactory.address }}" + abi: StakingPoolFactory + startBlock: {{ contracts.stakingPoolFactory.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - StakingPool + - StakingPoolFactory + - StakingPoolFactory__Sweep + - StakingPool__Reward + abis: + - name: StakingPoolFactory + file: ./abis/StakingPoolFactory.json + eventHandlers: + - event: BeneficiaryUpdate(indexed address,indexed address) + handler: handleBeneficiaryUpdate + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: Paused(address) + handler: handlePaused - event: StakingPoolCreated(indexed address,address,indexed address,(address,uint256,uint256)[],address,uint128,uint128,uint128,uint8) handler: handleStakingPoolCreated - event: Unpaused(address) @@ -143,11 +206,12 @@ templates: language: wasm/assemblyscript file: ./src/bondFactory.ts entities: - - BondFactory - Bond - Bond__Metadata - Bond__Configuration - Bond__RewardPool + - BondFactory + - BondFactory__Sweep abis: - name: BondFactory file: ./abis/BondFactory.json @@ -156,6 +220,8 @@ templates: handler: handleBeneficiaryUpdate - event: CreateBond(indexed address,(string,string,string),(uint256,address,uint256,uint256),(address,uint128,uint128)[],indexed address,indexed address) handler: handleCreateBond + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - event: Paused(address) @@ -228,6 +294,37 @@ templates: handler: handleUnpaused - event: WithdrawCollateral(indexed address,indexed address,uint256,indexed address) handler: handleWithdrawCollateral + - kind: ethereum/contract + name: StakingPoolFactory + network: {{ network }} + source: + abi: StakingPoolFactory + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - StakingPool + - StakingPool__Reward + - StakingPoolFactory + - StakingPoolFactory__Sweep + abis: + - name: StakingPoolFactory + file: ./abis/StakingPoolFactory.json + eventHandlers: + - event: BeneficiaryUpdate(indexed address,indexed address) + handler: handleBeneficiaryUpdate + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: Paused(address) + handler: handlePaused + - event: StakingPoolCreated(indexed address,address,indexed address,(address,uint256,uint256)[],address,uint128,uint128,uint128,uint8) + handler: handleStakingPoolCreated + - event: Unpaused(address) + handler: handleUnpaused + file: ./src/stakingPoolFactory.ts - kind: ethereum/contract name: StakingPool network: {{ network }} @@ -243,27 +340,26 @@ templates: - StakingPool__Deposit - StakingPool__Reward - StakingPool__RewardWithdrawal + - StakingPool__Sweep - StakingPool__Withdrawal abis: - name: StakingPool file: ./abis/StakingPool.json eventHandlers: + - event: BeneficiaryUpdate(indexed address,indexed address) + handler: handleBeneficiaryUpdate - event: Deposit(indexed address,uint256) handler: handleDeposit + - event: ERC20Sweep(indexed address,indexed address,uint256,indexed address) + handler: handleERC20Sweep - event: EmergencyMode(indexed address) handler: handleEmergencyMode - - event: GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) - handler: handleGrantDaoRole - - event: GrantGlobalRole(bytes32,address,indexed address) - handler: handleGrantGlobalRole - event: InitializeRewards(address,uint256) handler: handleInitializeRewards + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred - event: Paused(address) handler: handlePaused - - event: RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) - handler: handleRevokeDaoRole - - event: RevokeGlobalRole(indexed bytes32,address,indexed address) - handler: handleRevokeGlobalRole - event: RewardsAvailableTimestamp(uint32) handler: handleRewardsAvailableTimestamp - event: Unpaused(address) diff --git a/tests/bondFactory.test.ts b/tests/bondFactory.test.ts index 5d429ba..a8dc47e 100644 --- a/tests/bondFactory.test.ts +++ b/tests/bondFactory.test.ts @@ -4,6 +4,7 @@ import { assert, clearStore, test } from 'matchstick-as/assembly/index'; import { BOND_FACTORY_ADDRESS, createBondFactory, + defaultAddress, defaultBigInt, defaultLogType, newBlock, @@ -13,13 +14,16 @@ import { import { BeneficiaryUpdate, CreateBond, + ERC20Sweep, OwnershipTransferred, Paused, Unpaused } from '../generated/BondFactory/BondFactory'; + import { handleBeneficiaryUpdate, handleCreateBond, + handleERC20Sweep, handleOwnershipTransferred, handlePaused, handleUnpaused @@ -182,6 +186,49 @@ test('Will handle BeneficiaryUpdate event', () => { clearStore(); }); +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +test('Will handle ERC20Sweep event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const beneficiary = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const tokens = Address.fromString('0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199'); + const amount = 100; + + const sweepId = `${defaultAddress.toHex()}-${defaultBigInt.toHex()}`; + + createBondFactory(); + + handleERC20Sweep( + new ERC20Sweep( + Address.fromString(BOND_FACTORY_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('beneficiary', ethereum.Value.fromAddress(beneficiary)), + new ethereum.EventParam('tokens', ethereum.Value.fromAddress(tokens)), + new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('BondFactory', BOND_FACTORY_ADDRESS, 'sweeps', `[${sweepId}]`); + + assert.fieldEquals('BondFactory__Sweep', sweepId, 'amount', `${amount}`); + assert.fieldEquals('BondFactory__Sweep', sweepId, 'token', `${tokens.toHex()}`); + assert.fieldEquals( + 'BondFactory__Sweep', + sweepId, + 'beneficiary', + `${beneficiary.toHex()}` + ); + + clearStore(); +}); + // - OwnershipTransferred(indexed address,indexed address) test('Will handle OwnershipTransferred event', () => { const newOwner = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); @@ -243,7 +290,7 @@ test('Will handle Paused event', () => { }); // - Unpaused(address) -test('Will handle Paused event', () => { +test('Will handle Unpaused event', () => { const bondFactory = createBondFactory(); bondFactory.paused = true; bondFactory.save(); diff --git a/tests/bondMediator.test.ts b/tests/bondMediator.test.ts index 530dd3b..2c2feef 100644 --- a/tests/bondMediator.test.ts +++ b/tests/bondMediator.test.ts @@ -18,9 +18,9 @@ import { } from './utils'; import { - DAO__CollateralWhitelist as DAOCollateralWhitelist, - DAO__Role as DAORole, - Role + Bond__DAO__CollateralWhitelist as DAOCollateralWhitelist, + Bond__DAO__Role as DAORole, + Bond__Role as Role } from '../generated/schema'; import { @@ -43,6 +43,7 @@ import { Unpaused, Upgraded } from '../generated/BondMediator/BondMediator'; + import { handleAddBond, handleAddCollateralWhitelist, @@ -93,7 +94,7 @@ test('Will handle AddBond event', () => { assert.fieldEquals('Bond', BOND_ADDRESS, 'dao', DAO_ID_HEX); assert.fieldEquals('Bond', BOND_ADDRESS, 'mediator', BOND_MEDIATOR_ADDRESS); - assert.fieldEquals('DAO', DAO_ID_HEX, 'bonds', `[${BOND_ADDRESS}]`); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'bonds', `[${BOND_ADDRESS}]`); assert.fieldEquals('BondMediator', BOND_MEDIATOR_ADDRESS, 'bonds', `[${BOND_ADDRESS}]`); clearStore(); @@ -130,11 +131,11 @@ test('Will handle AddCollateralWhitelist event', () => { const whitelistId = `${DAO_ID_HEX}-${treasuryAddress.toHex()}`; - assert.fieldEquals('DAO', DAO_ID_HEX, 'collateralWhitelist', `[${whitelistId}]`); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'collateralWhitelist', `[${whitelistId}]`); - assert.fieldEquals('DAO__CollateralWhitelist', whitelistId, 'dao', DAO_ID_HEX); + assert.fieldEquals('Bond__DAO__CollateralWhitelist', whitelistId, 'dao', DAO_ID_HEX); assert.fieldEquals( - 'DAO__CollateralWhitelist', + 'Bond__DAO__CollateralWhitelist', whitelistId, 'token', `${treasuryAddress.toHex()}` @@ -299,7 +300,7 @@ test('Will handle CreateDao event', () => { ) ); - assert.fieldEquals('DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); assert.fieldEquals('BondMediator', BOND_MEDIATOR_ADDRESS, 'daos', `[${DAO_ID_HEX}]`); clearStore(); @@ -330,8 +331,8 @@ test('Will handle DaoMetaDataUpdate event', () => { ) ); - assert.fieldEquals('DAO', DAO_ID_HEX, 'metadata', `[${DAO_ID_HEX}]`); - assert.fieldEquals('DAO__Metadata', DAO_ID_HEX, 'data', data); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'metadata', `[${DAO_ID_HEX}]`); + assert.fieldEquals('Bond__DAO__Metadata', DAO_ID_HEX, 'data', data); clearStore(); }); @@ -361,7 +362,7 @@ test('Will handle DaoTreasuryUpdate event', () => { ) ); - assert.fieldEquals('DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); clearStore(); }); @@ -440,8 +441,8 @@ test('Will handle GrantDaoRole event', () => { assert.fieldEquals('BondMediator', BOND_MEDIATOR_ADDRESS, 'daoRoles', `[${roleId}]`); - assert.fieldEquals('DAO__Role', roleId, 'account', account.toHex()); - assert.fieldEquals('DAO__Role', roleId, 'role', role.toHex()); + assert.fieldEquals('Bond__DAO__Role', roleId, 'account', account.toHex()); + assert.fieldEquals('Bond__DAO__Role', roleId, 'role', role.toHex()); clearStore(); }); @@ -476,8 +477,8 @@ test('Will handle GrantGlobalRole event', () => { assert.fieldEquals('BondMediator', BOND_MEDIATOR_ADDRESS, 'roles', `[${roleId}]`); - assert.fieldEquals('Role', roleId, 'account', account.toHex()); - assert.fieldEquals('Role', roleId, 'role', role.toHex()); + assert.fieldEquals('Bond__Role', roleId, 'account', account.toHex()); + assert.fieldEquals('Bond__Role', roleId, 'role', role.toHex()); clearStore(); }); @@ -524,7 +525,7 @@ test('Will handle RemoveCollateralWhitelist event', () => { whitelist.save(); - assert.fieldEquals('DAO', DAO_ID_HEX, 'collateralWhitelist', `[${whitelistId}]`); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'collateralWhitelist', `[${whitelistId}]`); handleRemoveCollateralWhitelist( new RemoveCollateralWhitelist( @@ -546,8 +547,8 @@ test('Will handle RemoveCollateralWhitelist event', () => { ) ); - assert.fieldEquals('DAO', DAO_ID_HEX, 'collateralWhitelist', `[]`); - assert.notInStore('DAO__CollateralWhitelist', whitelistId); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'collateralWhitelist', `[]`); + assert.notInStore('Bond__DAO__CollateralWhitelist', whitelistId); clearStore(); }); @@ -569,7 +570,7 @@ test('Will handle RevokeDaoRole event', () => { daoRole.save(); - assert.fieldEquals('DAO', DAO_ID_HEX, 'roles', `[${roleId}]`); + assert.fieldEquals('Bond__DAO', DAO_ID_HEX, 'roles', `[${roleId}]`); handleRevokeDaoRole( new RevokeDaoRole( @@ -589,7 +590,7 @@ test('Will handle RevokeDaoRole event', () => { ) ); - assert.notInStore('DAO__Role', roleId); + assert.notInStore('Bond__DAO__Role', roleId); clearStore(); }); @@ -625,7 +626,7 @@ test('Will handle RevokeGlobalRole event', () => { ) ); - assert.notInStore('Role', roleId); + assert.notInStore('Bond__Role', roleId); clearStore(); }); diff --git a/tests/stakingPool.test.ts b/tests/stakingPool.test.ts index 4d99902..069893c 100644 --- a/tests/stakingPool.test.ts +++ b/tests/stakingPool.test.ts @@ -1,13 +1,10 @@ -import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; +import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts'; import { assert, clearStore, test } from 'matchstick-as/assembly/index'; -import { Role, DAO__Role as DAORole } from '../generated/schema'; import { - createDAO, createStakingPool, createStakingPoolReward, - DAO_ID, - DAO_ID_HEX, + defaultAddress, defaultBigInt, defaultLogType, newBlock, @@ -17,103 +14,85 @@ import { } from './utils'; import { + BeneficiaryUpdate, Deposit, EmergencyMode, - GrantDaoRole, - GrantGlobalRole, + ERC20Sweep, InitializeRewards, + OwnershipTransferred, Paused, - RevokeDaoRole, - RevokeGlobalRole, RewardsAvailableTimestamp, Unpaused, WithdrawRewards, WithdrawStake } from '../generated/templates/StakingPool/StakingPool'; + import { + handleBeneficiaryUpdate, handleDeposit, handleEmergencyMode, - handleGrantDaoRole, - handleGrantGlobalRole, + handleERC20Sweep, handleInitializeRewards, + handleOwnershipTransferred, handlePaused, - handleRevokeDaoRole, - handleRevokeGlobalRole, handleRewardsAvailableTimestamp, handleUnpaused, handleWithdrawRewards, handleWithdrawStake } from '../src/stakingPool'; -// - Deposit(indexed address,uint256) -test('Will handle Deposit event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const amount = 100; +// - BeneficiaryUpdate(indexed address,indexed address) +test('Will handle BeneficiaryUpdate event', () => { + const instigatorAddress = Address.fromString( + '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' + ); + const beneficiaryAddress = Address.fromString( + '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' + ); createStakingPool(); - handleDeposit( - new Deposit( + handleBeneficiaryUpdate( + new BeneficiaryUpdate( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), - newTransaction(), + newTransaction(instigatorAddress.toHex()), [ - new ethereum.EventParam('user', ethereum.Value.fromAddress(instigator)), - new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)) + new ethereum.EventParam( + 'beneficiary', + ethereum.Value.fromAddress(beneficiaryAddress) + ), + new ethereum.EventParam( + 'instigator', + ethereum.Value.fromAddress(instigatorAddress) + ) ], null ) ); - const depositId = `${STAKINGPOOL_ADDRESS}-${instigator.toHex()}`; - - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'deposits', `[${depositId}]`); - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'amount', '100'); - - assert.fieldEquals('StakingPool__Deposit', depositId, 'user', `${instigator.toHex()}`); - assert.fieldEquals('StakingPool__Deposit', depositId, 'amount', '100'); - - clearStore(); -}); - -// - EmergencyMode(indexed address) -test('Will handle EmergencyMode event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - - createStakingPool(); - - handleEmergencyMode( - new EmergencyMode( - Address.fromString(STAKINGPOOL_ADDRESS), - defaultBigInt, - defaultBigInt, - defaultLogType, - newBlock(), - newTransaction(), - [new ethereum.EventParam('admin', ethereum.Value.fromAddress(instigator))], - null - ) + assert.fieldEquals( + 'StakingPool', + STAKINGPOOL_ADDRESS, + 'beneficiary', + beneficiaryAddress.toHex() ); - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'emergencyMode', 'true'); - clearStore(); }); -// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) -test('Will handle GrantDaoRole event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); +// - OwnershipTransferred(indexed address,indexed address) +test('Will handle OwnershipTransferred event', () => { + const newOwner = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const previousOwner = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); - createDAO(); createStakingPool(); - handleGrantDaoRole( - new GrantDaoRole( + handleOwnershipTransferred( + new OwnershipTransferred( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, @@ -121,34 +100,34 @@ test('Will handle GrantDaoRole event', () => { newBlock(), newTransaction(), [ - new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), - new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + new ethereum.EventParam( + 'previousOwner', + ethereum.Value.fromAddress(previousOwner) + ), + new ethereum.EventParam('newOwner', ethereum.Value.fromAddress(newOwner)) ], null ) ); - const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; - - assert.fieldEquals('DAO__Role', roleId, 'account', account.toHex()); - assert.fieldEquals('DAO__Role', roleId, 'role', role.toHex()); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'owner', newOwner.toHex()); clearStore(); }); -// - GrantGlobalRole(bytes32,address,indexed address) -test('Will handle GrantGlobalRole event', () => { +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +test('Will handle ERC20Sweep event', () => { const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); + const beneficiary = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const tokens = Address.fromString('0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199'); + const amount = 100; + + const sweepId = `${defaultAddress.toHex()}-${defaultBigInt.toHex()}`; - createDAO(); createStakingPool(); - handleGrantGlobalRole( - new GrantGlobalRole( + handleERC20Sweep( + new ERC20Sweep( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, @@ -156,31 +135,38 @@ test('Will handle GrantGlobalRole event', () => { newBlock(), newTransaction(instigator.toHex()), [ - new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('beneficiary', ethereum.Value.fromAddress(beneficiary)), + new ethereum.EventParam('tokens', ethereum.Value.fromAddress(tokens)), + new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)), new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) ], null ) ); - const roleId = `${role.toHex()}-${account.toHex()}`; + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'sweeps', `[${sweepId}]`); - assert.fieldEquals('Role', roleId, 'account', account.toHex()); - assert.fieldEquals('Role', roleId, 'role', role.toHex()); + assert.fieldEquals('StakingPool__Sweep', sweepId, 'amount', `${amount}`); + assert.fieldEquals('StakingPool__Sweep', sweepId, 'token', `${tokens.toHex()}`); + assert.fieldEquals( + 'StakingPool__Sweep', + sweepId, + 'beneficiary', + `${beneficiary.toHex()}` + ); clearStore(); }); -// - InitializeRewards(address,uint256) -test('Will handle InitializeRewards event', () => { - const token = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); +// - Deposit(indexed address,uint256) +test('Will handle Deposit event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); const amount = 100; createStakingPool(); - handleInitializeRewards( - new InitializeRewards( + handleDeposit( + new Deposit( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, @@ -188,123 +174,103 @@ test('Will handle InitializeRewards event', () => { newBlock(), newTransaction(), [ - new ethereum.EventParam('rewardTokens', ethereum.Value.fromAddress(token)), + new ethereum.EventParam('user', ethereum.Value.fromAddress(instigator)), new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)) ], null ) ); - const rewardId = `${STAKINGPOOL_ADDRESS}-${token.toHex()}`; + const depositId = `${STAKINGPOOL_ADDRESS}-${instigator.toHex()}`; - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'rewards', `[${rewardId}]`); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'deposits', `[${depositId}]`); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'amount', '100'); - assert.fieldEquals('StakingPool__Reward', rewardId, 'token', `${token.toHex()}`); - assert.fieldEquals('StakingPool__Reward', rewardId, 'amount', '100'); + assert.fieldEquals('StakingPool__Deposit', depositId, 'user', `${instigator.toHex()}`); + assert.fieldEquals('StakingPool__Deposit', depositId, 'amount', '100'); clearStore(); }); -// - Paused(address) -test('Will handle Paused event', () => { +// - EmergencyMode(indexed address) +test('Will handle EmergencyMode event', () => { const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); createStakingPool(); - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'paused', 'false'); - - handlePaused( - new Paused( + handleEmergencyMode( + new EmergencyMode( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), - newTransaction(instigator.toHex()), - [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], + newTransaction(), + [new ethereum.EventParam('admin', ethereum.Value.fromAddress(instigator))], null ) ); - assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'paused', 'true'); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'emergencyMode', 'true'); clearStore(); }); -// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) -test('Will handle RevokeDaoRole event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); - - const dao = createDAO(); - - const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; - const daoRole = new DAORole(roleId); - - daoRole.dao = dao.id; - daoRole.role = role; - daoRole.account = account; - - daoRole.save(); +// - InitializeRewards(address,uint256) +test('Will handle InitializeRewards event', () => { + const token = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const amount = 100; - assert.fieldEquals('DAO', DAO_ID_HEX, 'roles', `[${roleId}]`); + createStakingPool(); - handleRevokeDaoRole( - new RevokeDaoRole( + handleInitializeRewards( + new InitializeRewards( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), - newTransaction(instigator.toHex()), + newTransaction(), [ - new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), - new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + new ethereum.EventParam('rewardTokens', ethereum.Value.fromAddress(token)), + new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)) ], null ) ); - assert.notInStore('DAO__Role', roleId); + const rewardId = `${STAKINGPOOL_ADDRESS}-${token.toHex()}`; + + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'rewards', `[${rewardId}]`); + + assert.fieldEquals('StakingPool__Reward', rewardId, 'token', `${token.toHex()}`); + assert.fieldEquals('StakingPool__Reward', rewardId, 'amount', '100'); clearStore(); }); -// - RevokeGlobalRole(indexed bytes32,address,indexed address) -test('Will handle RevokeGlobalRole event', () => { +// - Paused(address) +test('Will handle Paused event', () => { const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); - const roleId = `${role.toHex()}-${account.toHex()}`; - const roleEntity = new Role(roleId); - - roleEntity.role = role; - roleEntity.account = account; + createStakingPool(); - roleEntity.save(); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'paused', 'false'); - handleRevokeGlobalRole( - new RevokeGlobalRole( + handlePaused( + new Paused( Address.fromString(STAKINGPOOL_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), newTransaction(instigator.toHex()), - [ - new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) - ], + [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], null ) ); - assert.notInStore('Role', roleId); + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'paused', 'true'); clearStore(); }); diff --git a/tests/stakingPoolFactory.test.ts b/tests/stakingPoolFactory.test.ts index 61ed0eb..a54d1a5 100644 --- a/tests/stakingPoolFactory.test.ts +++ b/tests/stakingPoolFactory.test.ts @@ -1,4 +1,4 @@ -import { Address, Bytes, ethereum } from '@graphprotocol/graph-ts'; +import { Address, ethereum } from '@graphprotocol/graph-ts'; import { assert, clearStore, test } from 'matchstick-as/assembly/index'; import { @@ -8,153 +8,119 @@ import { newTransaction, createStakingPoolFactory, STAKINGPOOL_FACTORY_ADDRESS, - createDAO, - DAO_ID, - DAO_ID_HEX + defaultAddress } from './utils'; -import { DAO__Role as DAORole, Role } from '../generated/schema'; - import { - GrantDaoRole, - GrantGlobalRole, - RevokeDaoRole, - RevokeGlobalRole, Paused, Unpaused, - StakingPoolCreated + StakingPoolCreated, + BeneficiaryUpdate, + OwnershipTransferred, + ERC20Sweep } from '../generated/StakingPoolFactory/StakingPoolFactory'; + import { - handleGrantDaoRole, - handleGrantGlobalRole, - handleRevokeDaoRole, - handleRevokeGlobalRole, handlePaused, handleUnpaused, - handleStakingPoolCreated + handleStakingPoolCreated, + handleBeneficiaryUpdate, + handleOwnershipTransferred, + handleERC20Sweep } from '../src/stakingPoolFactory'; -// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) -test('Will handle GrantDaoRole event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); +// - BeneficiaryUpdate(indexed address,indexed address) +test('Will handle BeneficiaryUpdate event', () => { + const instigatorAddress = Address.fromString( + '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' + ); + const beneficiaryAddress = Address.fromString( + '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' + ); - createDAO(); createStakingPoolFactory(); - handleGrantDaoRole( - new GrantDaoRole( + handleBeneficiaryUpdate( + new BeneficiaryUpdate( Address.fromString(STAKINGPOOL_FACTORY_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), - newTransaction(), + newTransaction(instigatorAddress.toHex()), [ - new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), - new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + new ethereum.EventParam( + 'beneficiary', + ethereum.Value.fromAddress(beneficiaryAddress) + ), + new ethereum.EventParam( + 'instigator', + ethereum.Value.fromAddress(instigatorAddress) + ) ], null ) ); - const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; - - assert.fieldEquals('DAO__Role', roleId, 'account', account.toHex()); - assert.fieldEquals('DAO__Role', roleId, 'role', role.toHex()); + assert.fieldEquals( + 'StakingPoolFactory', + STAKINGPOOL_FACTORY_ADDRESS, + 'beneficiary', + beneficiaryAddress.toHex() + ); clearStore(); }); -// - GrantGlobalRole(bytes32,address,indexed address) -test('Will handle GrantGlobalRole event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); +// - OwnershipTransferred(indexed address,indexed address) +test('Will handle OwnershipTransferred event', () => { + const newOwner = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const previousOwner = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); - createDAO(); createStakingPoolFactory(); - handleGrantGlobalRole( - new GrantGlobalRole( + handleOwnershipTransferred( + new OwnershipTransferred( Address.fromString(STAKINGPOOL_FACTORY_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), - newTransaction(instigator.toHex()), + newTransaction(), [ - new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + new ethereum.EventParam( + 'previousOwner', + ethereum.Value.fromAddress(previousOwner) + ), + new ethereum.EventParam('newOwner', ethereum.Value.fromAddress(newOwner)) ], null ) ); - const roleId = `${role.toHex()}-${account.toHex()}`; - - assert.fieldEquals('Role', roleId, 'account', account.toHex()); - assert.fieldEquals('Role', roleId, 'role', role.toHex()); - - clearStore(); -}); - -// - Paused(address) -test('Will handle Paused event', () => { - const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - - createStakingPoolFactory(); - assert.fieldEquals( 'StakingPoolFactory', STAKINGPOOL_FACTORY_ADDRESS, - 'paused', - 'false' + 'owner', + newOwner.toHex() ); - handlePaused( - new Paused( - Address.fromString(STAKINGPOOL_FACTORY_ADDRESS), - defaultBigInt, - defaultBigInt, - defaultLogType, - newBlock(), - newTransaction(instigator.toHex()), - [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], - null - ) - ); - - assert.fieldEquals('StakingPoolFactory', STAKINGPOOL_FACTORY_ADDRESS, 'paused', 'true'); - clearStore(); }); -// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) -test('Will handle RevokeDaoRole event', () => { +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +test('Will handle ERC20Sweep event', () => { const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); + const beneficiary = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const tokens = Address.fromString('0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199'); + const amount = 100; - const dao = createDAO(); + const sweepId = `${defaultAddress.toHex()}-${defaultBigInt.toHex()}`; - const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; - const daoRole = new DAORole(roleId); - - daoRole.dao = dao.id; - daoRole.role = role; - daoRole.account = account; - - daoRole.save(); - - assert.fieldEquals('DAO', DAO_ID_HEX, 'roles', `[${roleId}]`); + createStakingPoolFactory(); - handleRevokeDaoRole( - new RevokeDaoRole( + handleERC20Sweep( + new ERC20Sweep( Address.fromString(STAKINGPOOL_FACTORY_ADDRESS), defaultBigInt, defaultBigInt, @@ -162,52 +128,61 @@ test('Will handle RevokeDaoRole event', () => { newBlock(), newTransaction(instigator.toHex()), [ - new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), - new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('beneficiary', ethereum.Value.fromAddress(beneficiary)), + new ethereum.EventParam('tokens', ethereum.Value.fromAddress(tokens)), + new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)), new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) ], null ) ); - assert.notInStore('DAO__Role', roleId); + assert.fieldEquals( + 'StakingPoolFactory', + STAKINGPOOL_FACTORY_ADDRESS, + 'sweeps', + `[${sweepId}]` + ); + + assert.fieldEquals('StakingPoolFactory__Sweep', sweepId, 'amount', `${amount}`); + assert.fieldEquals('StakingPoolFactory__Sweep', sweepId, 'token', `${tokens.toHex()}`); + assert.fieldEquals( + 'StakingPoolFactory__Sweep', + sweepId, + 'beneficiary', + `${beneficiary.toHex()}` + ); clearStore(); }); -// - RevokeGlobalRole(indexed bytes32,address,indexed address) -test('Will handle RevokeGlobalRole event', () => { +// - Paused(address) +test('Will handle Paused event', () => { const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); - const role = Bytes.fromI32(1); - - const roleId = `${role.toHex()}-${account.toHex()}`; - const roleEntity = new Role(roleId); - roleEntity.role = role; - roleEntity.account = account; + createStakingPoolFactory(); - roleEntity.save(); + assert.fieldEquals( + 'StakingPoolFactory', + STAKINGPOOL_FACTORY_ADDRESS, + 'paused', + 'false' + ); - handleRevokeGlobalRole( - new RevokeGlobalRole( + handlePaused( + new Paused( Address.fromString(STAKINGPOOL_FACTORY_ADDRESS), defaultBigInt, defaultBigInt, defaultLogType, newBlock(), newTransaction(instigator.toHex()), - [ - new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), - new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), - new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) - ], + [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], null ) ); - assert.notInStore('Role', roleId); + assert.fieldEquals('StakingPoolFactory', STAKINGPOOL_FACTORY_ADDRESS, 'paused', 'true'); clearStore(); }); diff --git a/tests/stakingPoolMediator.test.ts b/tests/stakingPoolMediator.test.ts new file mode 100644 index 0000000..38dde9e --- /dev/null +++ b/tests/stakingPoolMediator.test.ts @@ -0,0 +1,784 @@ +import { Address, Bytes, ethereum } from '@graphprotocol/graph-ts'; +import { assert, clearStore, test } from 'matchstick-as/assembly/index'; + +import { + createStakingPool, + createStakingPoolFactory, + createStakingPoolMediator, + createStakingPoolDAO, + DAO_ID, + DAO_ID_HEX, + defaultAddress, + defaultBigInt, + defaultLogType, + newBlock, + newTransaction, + STAKINGPOOL_MEDIATOR_ADDRESS, + STAKINGPOOL_ADDRESS +} from './utils'; + +import { + StakingPool__DAO__CollateralWhitelist as DAOCollateralWhitelist, + StakingPool__DAO__Role as DAORole, + StakingPool__Role as Role +} from '../generated/schema'; + +import { + AddStakingPool, + AddCollateralWhitelist, + AdminChanged, + BeaconUpgraded, + BeneficiaryUpdate, + StakingPoolCreatorUpdate, + CreateDao, + DaoMetaDataUpdate, + DaoTreasuryUpdate, + ERC20Sweep, + GrantDaoRole, + GrantGlobalRole, + Paused, + RemoveCollateralWhitelist, + RevokeDaoRole, + RevokeGlobalRole, + Unpaused, + Upgraded +} from '../generated/StakingPoolMediator/StakingPoolMediator'; + +import { + handleAddStakingPool, + handleAddCollateralWhitelist, + handleAdminChanged, + handleBeaconUpgraded, + handleBeneficiaryUpdate, + handleStakingPoolCreatorUpdate, + handleCreateDao, + handleDaoMetaDataUpdate, + handleDaoTreasuryUpdate, + handleERC20Sweep, + handleGrantDaoRole, + handleGrantGlobalRole, + handlePaused, + handleRemoveCollateralWhitelist, + handleRevokeDaoRole, + handleRevokeGlobalRole, + handleUnpaused, + handleUpgraded +} from '../src/stakingPoolMediator'; + +// - AddStakingPool(indexed uint256,indexed address,indexed address) +test('Will handle AddStakingPool event', () => { + const stakingPoolAddress = Address.fromString(STAKINGPOOL_ADDRESS); + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + + createStakingPoolMediator(); + createStakingPoolDAO(); + createStakingPool(); + + handleAddStakingPool( + new AddStakingPool( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam( + 'stakingPool', + ethereum.Value.fromAddress(stakingPoolAddress) + ), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('StakingPool', STAKINGPOOL_ADDRESS, 'dao', DAO_ID_HEX); + assert.fieldEquals( + 'StakingPool', + STAKINGPOOL_ADDRESS, + 'mediator', + STAKINGPOOL_MEDIATOR_ADDRESS + ); + + assert.fieldEquals( + 'StakingPool__DAO', + DAO_ID_HEX, + 'stakingPools', + `[${STAKINGPOOL_ADDRESS}]` + ); + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'stakingPools', + `[${STAKINGPOOL_ADDRESS}]` + ); + + clearStore(); +}); + +// - AddCollateralWhitelist(indexed uint256,indexed address,indexed address) +test('Will handle AddCollateralWhitelist event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const treasuryAddress = Address.fromString( + '0x7B4f352Cd40114f12e82fC675b5BA8C7582FC513' + ); + + createStakingPoolDAO(); + + handleAddCollateralWhitelist( + new AddCollateralWhitelist( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam( + 'collateralTokens', + ethereum.Value.fromAddress(treasuryAddress) + ), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + const whitelistId = `${DAO_ID_HEX}-${treasuryAddress.toHex()}`; + + assert.fieldEquals( + 'StakingPool__DAO', + DAO_ID_HEX, + 'collateralWhitelist', + `[${whitelistId}]` + ); + + assert.fieldEquals( + 'StakingPool__DAO__CollateralWhitelist', + whitelistId, + 'dao', + DAO_ID_HEX + ); + assert.fieldEquals( + 'StakingPool__DAO__CollateralWhitelist', + whitelistId, + 'token', + `${treasuryAddress.toHex()}` + ); + + clearStore(); +}); + +// - AdminChanged(address,address) +test('Will handle AdminChanged event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const newAdmin = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const previousAdmin = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + + createStakingPoolMediator(); + + handleAdminChanged( + new AdminChanged( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam( + 'previousAdmin', + ethereum.Value.fromAddress(previousAdmin) + ), + new ethereum.EventParam('newAdmin', ethereum.Value.fromAddress(newAdmin)) + ], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'admin', + newAdmin.toHex() + ); + + clearStore(); +}); + +// - BeaconUpgraded(indexed address) +test('Will handle BeaconUpgraded event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const beacon = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolMediator(); + + handleBeaconUpgraded( + new BeaconUpgraded( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [new ethereum.EventParam('beacon', ethereum.Value.fromAddress(beacon))], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'beacon', + beacon.toHex() + ); + + clearStore(); +}); + +// - BeneficiaryUpdate(indexed address,indexed address) +test('Will handle BeneficiaryUpdate event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const beneficiary = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolMediator(); + + handleBeneficiaryUpdate( + new BeneficiaryUpdate( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('beneficiary', ethereum.Value.fromAddress(beneficiary)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'beneficiary', + beneficiary.toHex() + ); + + clearStore(); +}); + +// - StakingPoolCreatorUpdate(indexed address,indexed address,indexed address) +test('Will handle StakingPoolCreatorUpdate event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const prevFactory = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const factory = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolFactory(); + createStakingPoolMediator(); + + assert.fieldEquals('StakingPoolMediator', STAKINGPOOL_MEDIATOR_ADDRESS, 'factory', ''); + + handleStakingPoolCreatorUpdate( + new StakingPoolCreatorUpdate( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam( + 'previousCreator', + ethereum.Value.fromAddress(prevFactory) + ), + new ethereum.EventParam('updateCreator', ethereum.Value.fromAddress(factory)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'factory', + factory.toHex() + ); + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'factories', + `[${factory.toHex()}]` + ); + + clearStore(); +}); + +// - CreateDao(indexed uint256,indexed address,indexed address) +test('Will handle CreateDao event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const treasury = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolMediator(); + + handleCreateDao( + new CreateDao( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('id', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam('treasury', ethereum.Value.fromAddress(treasury)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('StakingPool__DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'daos', + `[${DAO_ID_HEX}]` + ); + + clearStore(); +}); + +// - DaoMetaDataUpdate(indexed uint256,string,indexed address) +test('Will handle DaoMetaDataUpdate event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const data = 'sample data;'; + + createStakingPoolDAO(); + createStakingPoolMediator(); + + handleDaoMetaDataUpdate( + new DaoMetaDataUpdate( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam('data', ethereum.Value.fromString(data)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('StakingPool__DAO', DAO_ID_HEX, 'metadata', `[${DAO_ID_HEX}]`); + assert.fieldEquals('StakingPool__DAO__Metadata', DAO_ID_HEX, 'data', data); + + clearStore(); +}); + +// - DaoTreasuryUpdate(indexed uint256,indexed address,indexed address) +test('Will handle DaoTreasuryUpdate event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const treasury = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolDAO(); + createStakingPoolMediator(); + + handleDaoTreasuryUpdate( + new DaoTreasuryUpdate( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam('treasury', ethereum.Value.fromAddress(treasury)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('StakingPool__DAO', DAO_ID_HEX, 'treasury', treasury.toHex()); + + clearStore(); +}); + +// - ERC20Sweep(indexed address,indexed address,uint256,indexed address) +test('Will handle ERC20Sweep event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const beneficiary = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + const tokens = Address.fromString('0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199'); + const amount = 100; + + const sweepId = `${defaultAddress.toHex()}-${defaultBigInt.toHex()}`; + + createStakingPoolMediator(); + + handleERC20Sweep( + new ERC20Sweep( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('beneficiary', ethereum.Value.fromAddress(beneficiary)), + new ethereum.EventParam('tokens', ethereum.Value.fromAddress(tokens)), + new ethereum.EventParam('amount', ethereum.Value.fromI32(amount)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'sweeps', + `[${sweepId}]` + ); + + assert.fieldEquals('StakingPoolMediator__Sweep', sweepId, 'amount', `${amount}`); + assert.fieldEquals('StakingPoolMediator__Sweep', sweepId, 'token', `${tokens.toHex()}`); + assert.fieldEquals( + 'StakingPoolMediator__Sweep', + sweepId, + 'beneficiary', + `${beneficiary.toHex()}` + ); + + clearStore(); +}); + +// - GrantDaoRole(indexed uint256,indexed bytes32,address,indexed address) +test('Will handle GrantDaoRole event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const role = Bytes.fromI32(1); + + createStakingPoolDAO(); + createStakingPoolMediator(); + + handleGrantDaoRole( + new GrantDaoRole( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), + new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'daoRoles', + `[${roleId}]` + ); + + assert.fieldEquals('StakingPool__DAO__Role', roleId, 'account', account.toHex()); + assert.fieldEquals('StakingPool__DAO__Role', roleId, 'role', role.toHex()); + + clearStore(); +}); + +// - GrantGlobalRole(bytes32,address,indexed address) +test('Will handle GrantGlobalRole event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const role = Bytes.fromI32(1); + + createStakingPoolDAO(); + createStakingPoolMediator(); + + handleGrantGlobalRole( + new GrantGlobalRole( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), + new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + const roleId = `${role.toHex()}-${account.toHex()}`; + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'roles', + `[${roleId}]` + ); + + assert.fieldEquals('StakingPool__Role', roleId, 'account', account.toHex()); + assert.fieldEquals('StakingPool__Role', roleId, 'role', role.toHex()); + + clearStore(); +}); + +// - Paused(address) +test('Will handle Paused event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + + createStakingPoolMediator(); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'paused', + 'false' + ); + + handlePaused( + new Paused( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'paused', + 'true' + ); + + clearStore(); +}); + +// - RemoveCollateralWhitelist(indexed uint256,indexed address,indexed address) +test('Will handle RemoveCollateralWhitelist event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const treasuryAddress = Address.fromString( + '0x7B4f352Cd40114f12e82fC675b5BA8C7582FC513' + ); + + const dao = createStakingPoolDAO(); + + const whitelistId = `${DAO_ID_HEX}-${treasuryAddress.toHex()}`; + const whitelist = new DAOCollateralWhitelist(whitelistId); + + whitelist.dao = dao.id; + + whitelist.save(); + + assert.fieldEquals( + 'StakingPool__DAO', + DAO_ID_HEX, + 'collateralWhitelist', + `[${whitelistId}]` + ); + + handleRemoveCollateralWhitelist( + new RemoveCollateralWhitelist( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam( + 'collateralTokens', + ethereum.Value.fromAddress(treasuryAddress) + ), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.fieldEquals('StakingPool__DAO', DAO_ID_HEX, 'collateralWhitelist', `[]`); + assert.notInStore('StakingPool__DAO__CollateralWhitelist', whitelistId); + + clearStore(); +}); + +// - RevokeDaoRole(indexed uint256,indexed bytes32,address,indexed address) +test('Will handle RevokeDaoRole event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const role = Bytes.fromI32(1); + + const dao = createStakingPoolDAO(); + + const roleId = `${DAO_ID_HEX}-${role.toHex()}-${account.toHex()}`; + const daoRole = new DAORole(roleId); + + daoRole.dao = dao.id; + daoRole.role = role; + daoRole.account = account; + + daoRole.save(); + + assert.fieldEquals('StakingPool__DAO', DAO_ID_HEX, 'roles', `[${roleId}]`); + + handleRevokeDaoRole( + new RevokeDaoRole( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('daoId', ethereum.Value.fromI32(DAO_ID)), + new ethereum.EventParam('role', ethereum.Value.fromBytes(role)), + new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.notInStore('StakingPool__DAO__Role', roleId); + + clearStore(); +}); + +// - RevokeGlobalRole(indexed bytes32,address,indexed address) +test('Will handle RevokeGlobalRole event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const account = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const role = Bytes.fromI32(1); + + const roleId = `${role.toHex()}-${account.toHex()}`; + const roleEntity = new Role(roleId); + + roleEntity.role = role; + roleEntity.account = account; + + roleEntity.save(); + + handleRevokeGlobalRole( + new RevokeGlobalRole( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam('indexedrole', ethereum.Value.fromBytes(role)), + new ethereum.EventParam('account', ethereum.Value.fromAddress(account)), + new ethereum.EventParam('instigator', ethereum.Value.fromAddress(instigator)) + ], + null + ) + ); + + assert.notInStore('StakingPool__Role', roleId); + + clearStore(); +}); + +// - Unpaused(address) +test('Will handle Unpaused event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + + const stakingPoolMediator = createStakingPoolMediator(); + stakingPoolMediator.paused = true; + + stakingPoolMediator.save(); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'paused', + 'true' + ); + + handleUnpaused( + new Unpaused( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [new ethereum.EventParam('account', ethereum.Value.fromAddress(instigator))], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'paused', + 'false' + ); + + clearStore(); +}); + +// - Upgraded(indexed address) +test('Will handle Upgraded event', () => { + const instigator = Address.fromString('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); + const implementation = Address.fromString('0x70997970c51812dc3a010c7d01b50e0d17dc79c8'); + + createStakingPoolMediator(); + + handleUpgraded( + new Upgraded( + Address.fromString(STAKINGPOOL_MEDIATOR_ADDRESS), + defaultBigInt, + defaultBigInt, + defaultLogType, + newBlock(), + newTransaction(instigator.toHex()), + [ + new ethereum.EventParam( + 'implementation', + ethereum.Value.fromAddress(implementation) + ) + ], + null + ) + ); + + assert.fieldEquals( + 'StakingPoolMediator', + STAKINGPOOL_MEDIATOR_ADDRESS, + 'implementation', + implementation.toHex() + ); + + clearStore(); +}); diff --git a/tests/utils.ts b/tests/utils.ts index 35fe34a..2efa38b 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -3,10 +3,12 @@ import { Address, BigInt, Bytes, ethereum } from '@graphprotocol/graph-ts'; import { BondMediator, BondFactory, - DAO, + Bond__DAO as DAO, Bond, + StakingPoolMediator, StakingPoolFactory, StakingPool, + StakingPool__DAO as StakingPoolDAO, StakingPool__Reward as StakingPoolReward } from '../generated/schema'; @@ -16,10 +18,25 @@ export const TOKEN_ADDESS = '0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc'; export const BOND_ADDRESS = '0xa0ee7a142d267c1f36714e4a8f75612f20a79720'; export const BOND_FACTORY_ADDRESS = '0x97226ae60a3fb891e61e8a6b6c069b97852ab6c7'; export const BOND_MEDIATOR_ADDRESS = '0x7b4f352cd40114f12e82fc675b5ba8c7582fc513'; +export const STAKINGPOOL_MEDIATOR_ADDRESS = '0x48fea11299cb25d8ae3451d6ed9a9d288fdc94ff'; export const STAKINGPOOL_FACTORY_ADDRESS = '0x14dc79964da2c08b23698b3d3cc7ca32193d9955'; export const STAKINGPOOL_ADDRESS = '0x15d34aaf54267db7d7c367839aaf71a00a2c6a65'; export const STAKINGPOOL_REWARD_ADDRESS = `${STAKINGPOOL_ADDRESS}-${TOKEN_ADDESS}`; +export const createStakingPoolMediator = (): StakingPoolMediator => { + const stakingPoolMediator = new StakingPoolMediator(STAKINGPOOL_MEDIATOR_ADDRESS); + stakingPoolMediator.save(); + + return stakingPoolMediator; +}; + +export const createStakingPoolDAO = (): StakingPoolDAO => { + const stakingPoolDAO = new StakingPoolDAO(DAO_ID_HEX); + stakingPoolDAO.save(); + + return stakingPoolDAO; +}; + export const createBondMediator = (): BondMediator => { const bondMediator = new BondMediator(BOND_MEDIATOR_ADDRESS); bondMediator.save();