Skip to content

Commit

Permalink
Added the StakeInspector contract
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaniza committed Oct 23, 2024
1 parent d1db1e9 commit 2ed22cd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ ft-sepolia-fork :; forge test --match-contract TestE2EV2 \

#### Deployments ####

stakeinspector-preview-mode :; forge script DeployStakeInspector \
--rpc-url https://mainnet.mode.network \
-vvvvv

stakeinspector-mode :; forge script DeployStakeInspector \
--rpc-url https://mainnet.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
--broadcast \
--verify \
--verifier blockscout \
--verifier-url https://explorer.mode.network/api\? \
-vvvvv

deploy-preview-mode-sepolia :; forge script script/Deploy.s.sol:Deploy \
--rpc-url https://sepolia.mode.network \
--private-key $(DEPLOYMENT_PRIVATE_KEY) \
Expand Down
21 changes: 21 additions & 0 deletions script/DeployStakeInspector.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {Script, console2 as console} from "forge-std/Script.sol";

import {StakeInspector} from "src/helpers/StakeInspector.sol";

contract DeployStakeInspector is Script {
address escrowMode = 0xff8AB822b8A853b01F9a9E9465321d6Fe77c9D2F;
address escrowBPT = 0x9c2eFe2a1FBfb601125Bb07a3D5bC6EC91F91e01;

function run() public {
vm.startBroadcast(vm.addr(vm.envUint("DEPLOYMENT_PRIVATE_KEY")));
StakeInspector stakeInspectorMode = new StakeInspector(escrowMode);
StakeInspector stakeInspectorBPT = new StakeInspector(escrowBPT);

vm.stopBroadcast();
console.log("StakeInspector for Mode deployed at: ", address(stakeInspectorMode));
console.log("StakeInspector for BPT deployed at: ", address(stakeInspectorBPT));
}
}
29 changes: 29 additions & 0 deletions src/helpers/StakeInspector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {IVotingEscrowIncreasing} from "@escrow-interfaces/IVotingEscrowIncreasing.sol";

interface IVotingEscrowIncreasingExtended is IVotingEscrowIncreasing {
function ownedTokens(address _account) external view returns (uint256[] memory tokenIds);
}

/// @notice Aggregate staked balances for an address given multiple veNFTs
contract StakeInspector {
/// @notice The staking contract
IVotingEscrowIncreasingExtended public escrow;

constructor(address _escrow) {
escrow = IVotingEscrowIncreasingExtended(_escrow);
}

/// @notice Fetch the total underlying tokens staked across all the veNFTs owned by an account
function getTotalStaked(address _account) external view returns (uint256) {
uint256 totalStaked = 0;

uint256[] memory veNFTs = escrow.ownedTokens(_account);
for (uint256 i = 0; i < veNFTs.length; i++) {
totalStaked += escrow.locked(veNFTs[i]).amount;
}
return totalStaked;
}
}

0 comments on commit 2ed22cd

Please sign in to comment.