-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9c926f
commit dffd693
Showing
7 changed files
with
458 additions
and
4 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,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
import {INToken} from "../interfaces/INToken.sol"; | ||
import "../dependencies/openzeppelin/contracts//IERC20.sol"; | ||
import "../dependencies/yoga-labs/ApeCoinStaking.sol"; | ||
|
||
contract ParaXApeCoinStakingVoting { | ||
ApeCoinStaking immutable apeCoinStaking; | ||
IERC20 immutable cApe; | ||
INToken immutable nBAYC; | ||
INToken immutable nMAYC; | ||
INToken immutable nBAKC; | ||
|
||
uint256 constant BAYC_POOL_ID = 1; | ||
uint256 constant MAYC_POOL_ID = 2; | ||
uint256 constant BAKC_POOL_ID = 3; | ||
|
||
constructor( | ||
address _cApe, | ||
address _apeCoinStaking, | ||
address _nBAYC, | ||
address _nMAYC, | ||
address _nBAKC | ||
) { | ||
cApe = IERC20(_cApe); | ||
apeCoinStaking = ApeCoinStaking(_apeCoinStaking); | ||
nBAYC = INToken(_nBAYC); | ||
nMAYC = INToken(_nMAYC); | ||
nBAKC = INToken(_nBAKC); | ||
} | ||
|
||
/** | ||
* @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 = getCApeVotes(userAddress); | ||
votes += getVotesInAllNftPool(userAddress); | ||
} | ||
|
||
function getCApeVotes( | ||
address userAddress | ||
) public view returns (uint256 votes) { | ||
votes = cApe.balanceOf(userAddress); | ||
} | ||
|
||
function getVotesInAllNftPool( | ||
address userAddress | ||
) public view returns (uint256 votes) { | ||
votes = getVotesForNToken(nBAYC, BAYC_POOL_ID, userAddress); | ||
votes += getVotesForNToken(nMAYC, MAYC_POOL_ID, userAddress); | ||
votes += getVotesForNToken(nBAKC, BAKC_POOL_ID, userAddress); | ||
} | ||
|
||
function getVotesForNToken( | ||
INToken ntoken, | ||
uint256 poolId, | ||
address userAddress | ||
) public view returns (uint256 votes) { | ||
uint256 balance = ntoken.balanceOf(userAddress); | ||
if (balance == 0) { | ||
return 0; | ||
} | ||
|
||
for (uint256 i = 0; i < balance; i++) { | ||
uint256 tokenId = ntoken.tokenOfOwnerByIndex(userAddress, i); | ||
|
||
(uint256 stakedAmount, ) = apeCoinStaking.nftPosition( | ||
poolId, | ||
tokenId | ||
); | ||
uint256 pendingReward = apeCoinStaking.pendingRewards( | ||
poolId, | ||
address(ntoken), | ||
tokenId | ||
); | ||
votes += (pendingReward + stakedAmount); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.