-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add voting for staked apecoin (#21)
* feat: Add voting for staked apecoin * chore: Deploy StakedVoting on Goerli * chore: Deploy voting contract
- Loading branch information
1 parent
c3149b5
commit 56799e7
Showing
8 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "contract ICoinPool", | ||
"name": "coinPool_", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "contract INftPool", | ||
"name": "nftPool_", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "contract IStakeManager", | ||
"name": "staker_", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "contract IBNFTRegistry", | ||
"name": "bnftRegistry_", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "bnftRegistry", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract IBNFTRegistry", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "coinPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract ICoinPool", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "userAddress", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getVotes", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "votes", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "userAddress", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getVotesInAllNftPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "votes", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "userAddress", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getVotesInCoinPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "votes", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "contract IStakedNft", | ||
"name": "stnft_", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "userAddress", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getVotesInOneNftPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "votes", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "nftPool", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract INftPool", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "staker", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract IStakeManager", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.18; | ||
|
||
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; | ||
|
||
import {IBNFTRegistry} from "../interfaces/IBNFTRegistry.sol"; | ||
|
||
import {ICoinPool} from "../interfaces/ICoinPool.sol"; | ||
import {INftPool, IStakedNft} from "../interfaces/INftPool.sol"; | ||
import {IStakeManager} from "../interfaces/IStakeManager.sol"; | ||
|
||
/** | ||
* @title BendDAO Staked ApeCoin's Voting Contract | ||
* @notice Provides a comprehensive vote count across all pools in the ApeCoinStaking contract | ||
*/ | ||
contract BendApeCoinStakedVoting { | ||
ICoinPool public immutable coinPool; | ||
INftPool public immutable nftPool; | ||
IStakeManager public immutable staker; | ||
IBNFTRegistry public immutable bnftRegistry; | ||
|
||
constructor(ICoinPool coinPool_, INftPool nftPool_, IStakeManager staker_, IBNFTRegistry bnftRegistry_) { | ||
coinPool = coinPool_; | ||
nftPool = nftPool_; | ||
staker = staker_; | ||
bnftRegistry = bnftRegistry_; | ||
} | ||
|
||
/** | ||
* @notice Returns a vote count across all pools in the ApeCoinStaking contract for a given address | ||
* @param userAddress The address to return votes for | ||
*/ | ||
function getVotes(address userAddress) public view returns (uint256 votes) { | ||
votes += getVotesInCoinPool(userAddress); | ||
votes += getVotesInAllNftPool(userAddress); | ||
} | ||
|
||
function getVotesInCoinPool(address userAddress) public view returns (uint256 votes) { | ||
votes = coinPool.assetBalanceOf(userAddress); | ||
} | ||
|
||
function getVotesInAllNftPool(address userAddress) public view returns (uint256 votes) { | ||
votes += getVotesInOneNftPool(staker.stBayc(), userAddress); | ||
votes += getVotesInOneNftPool(staker.stMayc(), userAddress); | ||
votes += getVotesInOneNftPool(staker.stBakc(), userAddress); | ||
} | ||
|
||
function getVotesInOneNftPool(IStakedNft stnft_, address userAddress) public view returns (uint256 votes) { | ||
// Check user balance | ||
uint256 stnftBalance = stnft_.balanceOf(userAddress); | ||
uint256 bnftBalance; | ||
(address bnftProxy, ) = bnftRegistry.getBNFTAddresses(address(stnft_)); | ||
if (bnftProxy != address(0)) { | ||
bnftBalance += IERC721Enumerable(bnftProxy).balanceOf(userAddress); | ||
} | ||
if (bnftBalance == 0 && stnftBalance == 0) { | ||
return 0; | ||
} | ||
|
||
// Get all tokenIds | ||
uint256[] memory allTokenIds = new uint256[](stnftBalance + bnftBalance); | ||
uint256 allIdSize = 0; | ||
|
||
for (uint256 i = 0; i < stnftBalance; i++) { | ||
uint256 tokenId = stnft_.tokenOfOwnerByIndex(userAddress, i); | ||
if (stnft_.stakerOf(tokenId) == address(staker)) { | ||
allTokenIds[allIdSize] = tokenId; | ||
allIdSize++; | ||
} | ||
} | ||
|
||
if (bnftProxy != address(0)) { | ||
IERC721Enumerable bnft = IERC721Enumerable(bnftProxy); | ||
for (uint256 i = 0; i < bnftBalance; i++) { | ||
uint256 tokenId = bnft.tokenOfOwnerByIndex(userAddress, i); | ||
if (stnft_.stakerOf(tokenId) == address(staker)) { | ||
allTokenIds[allIdSize] = tokenId; | ||
allIdSize++; | ||
} | ||
} | ||
} | ||
|
||
// Get votes from claimable rewards | ||
address[] memory claimNfts = new address[](1); | ||
claimNfts[0] = stnft_.underlyingAsset(); | ||
|
||
uint256[][] memory claimTokenIds = new uint256[][](1); | ||
claimTokenIds[0] = new uint256[](allIdSize); | ||
for (uint256 i = 0; i < allIdSize; i++) { | ||
claimTokenIds[0][i] = allTokenIds[i]; | ||
} | ||
|
||
votes = nftPool.claimable(claimNfts, claimTokenIds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters