Skip to content

Commit

Permalink
✨ vote: get power from beefy
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Oct 16, 2023
1 parent 8df5ddc commit 4e319bf
Show file tree
Hide file tree
Showing 7 changed files with 606 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-dolls-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

✨ vote: get power from beefy
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,4 @@ SwapperTest:testSwapWithKeepEqualToValue() (gas: 41783)
SwapperTest:testSwapWithKeepHigherThanValue() (gas: 41804)
SwapperTest:testSwapWithPermit() (gas: 566299)
SwapperTest:testSwapWithPermit2() (gas: 560666)
VotePreviewerTest:testExternalVotes() (gas: 97572)
VotePreviewerTest:testExternalVotes() (gas: 243041)
27 changes: 26 additions & 1 deletion contracts/periphery/VotePreviewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,44 @@ contract VotePreviewer {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IERC20 public immutable gauge;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IBeefyVault public immutable beefyVault;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IERC20 public immutable beefyBoost;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IExtraLending public immutable extraLending;
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
uint256 public immutable extraReserveId;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address exa_, IPool pool_, IERC20 gauge_, IExtraLending extraLending_, uint256 extraReserveId_) {
constructor(
address exa_,
IPool pool_,
IERC20 gauge_,
IBeefyVault beefyVault_,
IERC20 beefyBoost_,
IExtraLending extraLending_,
uint256 extraReserveId_
) {
exa = exa_;
pool = pool_;
gauge = gauge_;
beefyVault = beefyVault_;
beefyBoost = beefyBoost_;
extraLending = extraLending_;
extraReserveId = extraReserveId_;
}

function externalVotes(address account) external view returns (uint256 votes) {
// velodrome
uint256 liquidity = pool.balanceOf(account) + gauge.balanceOf(account);
votes += liquidity.mulDivDown(exa == pool.token0() ? pool.reserve0() : pool.reserve1(), pool.totalSupply());

// beefy
votes += beefyVault.getPricePerFullShare().mulWadDown(
beefyVault.balanceOf(account) + beefyBoost.balanceOf(account)
);

// extra
uint256[] memory reserveIds = new uint256[](1);
reserveIds[0] = extraReserveId;
IExtraLending.PositionStatus[] memory e = extraLending.getPositionStatus(reserveIds, account);
Expand All @@ -48,6 +69,10 @@ interface IPool is IERC20 {
function reserve1() external view returns (uint256);
}

interface IBeefyVault is IERC20 {
function getPricePerFullShare() external view returns (uint256);
}

interface IExtraLending {
struct PositionStatus {
uint256 reserveId;
Expand Down
9 changes: 8 additions & 1 deletion deploy/Previewers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const func: DeployFunction = async ({
{ address: exa },
{ address: exaPool },
{ address: exaGauge },
{ address: beefyEXA },
{ address: beefyEXABoost },
{ address: priceFeedETH },
{ address: extraLending },
{ deployer },
Expand All @@ -28,6 +30,8 @@ const func: DeployFunction = async ({
get("EXA"),
getOrNull("EXAPool").then((d) => d ?? { address: AddressZero }),
getOrNull("EXAGauge").then((d) => d ?? { address: AddressZero }),
getOrNull("BeefyEXA").then((d) => d ?? { address: AddressZero }),
getOrNull("BeefyEXABoost").then((d) => d ?? { address: AddressZero }),
getOrNull("PriceFeedETH").then((d) => d ?? { address: AddressZero }),
getOrNull("ExtraLending").then((d) => d ?? { address: AddressZero }),
getNamedAccounts(),
Expand All @@ -47,7 +51,10 @@ const func: DeployFunction = async ({
if (periphery.extraReserve == null) return;
await validateUpgrade(
"VotePreviewer",
{ args: [exa, exaPool, exaGauge, extraLending, periphery.extraReserve], envKey: "VOTE_PREVIEWER" },
{
args: [exa, exaPool, exaGauge, beefyEXA, beefyEXABoost, extraLending, periphery.extraReserve],
envKey: "VOTE_PREVIEWER",
},
async (name, opts) =>
deploy(name, { ...opts, proxy: { proxyContract: "TransparentUpgradeableProxy" }, from: deployer, log: true }),
);
Expand Down
259 changes: 259 additions & 0 deletions deployments/optimism/BeefyEXA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{
"address": "0xdD84190aF336Ee2831eea88B6783958e8F269de9",
"abi": [
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "spender", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Approval",
"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": "implementation", "type": "address" }],
"name": "NewStratCandidate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "address", "name": "implementation", "type": "address" }],
"name": "UpgradeStrat",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "approvalDelay",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "available",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "balance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "account", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "subtractedValue", "type": "uint256" }
],
"name": "decreaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }],
"name": "deposit",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "depositAll", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{ "inputs": [], "name": "earn", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [],
"name": "getPricePerFullShare",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_token", "type": "address" }],
"name": "inCaseTokensGetStuck",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "addedValue", "type": "uint256" }
],
"name": "increaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "contract IStrategyV7", "name": "_strategy", "type": "address" },
{ "internalType": "string", "name": "_name", "type": "string" },
{ "internalType": "string", "name": "_symbol", "type": "string" },
{ "internalType": "uint256", "name": "_approvalDelay", "type": "uint256" }
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_implementation", "type": "address" }],
"name": "proposeStrat",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [],
"name": "stratCandidate",
"outputs": [
{ "internalType": "address", "name": "implementation", "type": "address" },
{ "internalType": "uint256", "name": "proposedTime", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "strategy",
"outputs": [{ "internalType": "contract IStrategyV7", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "upgradeStrat", "outputs": [], "stateMutability": "nonpayable", "type": "function" },
{
"inputs": [],
"name": "want",
"outputs": [{ "internalType": "contract IERC20Upgradeable", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_shares", "type": "uint256" }],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{ "inputs": [], "name": "withdrawAll", "outputs": [], "stateMutability": "nonpayable", "type": "function" }
]
}

0 comments on commit 4e319bf

Please sign in to comment.