Skip to content

Commit

Permalink
chore: ape coin staking voting
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujia6139 committed Nov 15, 2023
1 parent e9c926f commit dffd693
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 4 deletions.
80 changes: 80 additions & 0 deletions contracts/misc/ParaXApeCoinStakingVoting.sol
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);
}
}
}
18 changes: 18 additions & 0 deletions helpers/contracts-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import {
PoolAAPositionMover__factory,
PoolBorrowAndStake__factory,
PoolBorrowAndStake,
ParaXApeCoinStakingVoting,
} from "../types";
import {
getACLManager,
Expand Down Expand Up @@ -3346,6 +3347,23 @@ export const deployDelegationAwarePToken = async (
return instance;
};

export const deployApeCoinStakingVoting = async (
apeCoinStaking: tEthereumAddress,
cApe: tEthereumAddress,
nBAYC: tEthereumAddress,
nMAYC: tEthereumAddress,
nBAKC: tEthereumAddress,
verify?: boolean
) => {
return withSaveAndVerify(
await getContractFactory("ParaXApeCoinStakingVoting"),
eContractid.ParaXApeCoinStakingVoting,
[apeCoinStaking, cApe, nBAYC, nMAYC, nBAKC],
verify,
false
) as Promise<ParaXApeCoinStakingVoting>;
};

export const deployMockVariableDebtToken = async (
args: [
tEthereumAddress,
Expand Down
12 changes: 12 additions & 0 deletions helpers/contracts-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
Account__factory,
AccountFactory__factory,
AccountRegistry__factory,
ParaXApeCoinStakingVoting__factory,
} from "../types";
import {
getEthersSigners,
Expand Down Expand Up @@ -1348,6 +1349,17 @@ export const getAccountFactory = async (address?: tEthereumAddress) =>
await getFirstSigner()
);

export const getApeCoinStakingVoting = async (address?: tEthereumAddress) =>
await ParaXApeCoinStakingVoting__factory.connect(
address ||
(
await getDb()
.get(`${eContractid.ParaXApeCoinStakingVoting}.${DRE.network.name}`)
.value()
).address,
await getFirstSigner()
);

////////////////////////////////////////////////////////////////////////////////
// MOCK
////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions helpers/hardhat-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,5 +498,4 @@ export const XTOKEN_TYPE_UPGRADE_WHITELIST =
.split(/\s?,\s?/)
.map((x) => +x);
export const XTOKEN_SYMBOL_UPGRADE_WHITELIST =
process.env.XTOKEN_SYMBOL_UPGRADE_WHITELIST?.trim()
.split(/\s?,\s?/);
process.env.XTOKEN_SYMBOL_UPGRADE_WHITELIST?.trim().split(/\s?,\s?/);
1 change: 1 addition & 0 deletions helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export enum eContractid {
MockBendDaoLendPool = "MockBendDaoLendPool",
PositionMoverLogic = "PositionMoverLogic",
PoolPositionMoverImpl = "PoolPositionMoverImpl",
ParaXApeCoinStakingVoting = "ParaXApeCoinStakingVoting",
Account = "Account",
AccountFactory = "AccountFactory",
AccountProxy = "AccountProxy",
Expand Down
6 changes: 4 additions & 2 deletions scripts/upgrade/ntoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ export const upgradeNToken = async (verify = false) => {
continue;
}

if (XTOKEN_SYMBOL_UPGRADE_WHITELIST && !XTOKEN_SYMBOL_UPGRADE_WHITELIST.includes(symbol)) {
if (
XTOKEN_SYMBOL_UPGRADE_WHITELIST &&
!XTOKEN_SYMBOL_UPGRADE_WHITELIST.includes(symbol)
) {
console.log(symbol + "not in XTOKEN_SYMBOL_UPGRADE_WHITELIST, skip...");
continue;
}


if (xTokenType == XTokenType.NTokenBAYC) {
if (!nTokenBAYCImplementationAddress) {
console.log("deploy NTokenBAYC implementation");
Expand Down
Loading

0 comments on commit dffd693

Please sign in to comment.