Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hedgey vesting #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions contracts/EasyRPGFStrategyHedgey.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {BaseStrategy} from "allo-v2/contracts/strategies/BaseStrategy.sol";
import {IAllo} from "allo-v2/contracts/core/interfaces/IAllo.sol";

interface ITokenVestingPlans {
function createPlan(
address recipient,
address token,
uint256 amount,
uint256 start,
uint256 cliff,
uint256 rate,
uint256 period,
address vestingAdmin,
bool adminTransferOBO
) external returns (uint256 newPlanId);
}

contract EasyRPGFStrategyHedgey is BaseStrategy {
error INPUT_LENGTH_MISMATCH();
error NOOP();

struct HedgeyParams {
address adminAddress;
address contractAddress;
uint256 duration;
uint256 cliff;
uint256 period;
bool adminTransferOBO;
}
HedgeyParams public hedgey;

constructor(
address _allo,
string memory _name
) BaseStrategy(_allo, _name) {}

function initialize(
uint256 _poolId,
bytes memory _data
) external virtual override {
__BaseStrategy_init(_poolId);

hedgey = abi.decode(_data, (HedgeyParams));

emit Initialized(_poolId, _data);
}

/// @notice Withdraw pool funds
/// @param _token Token address
/// @param _recipient Address to send the funds to
function withdraw(
address _token,
address _recipient
) external onlyPoolManager(msg.sender) {
uint256 _poolAmount = poolAmount;
poolAmount = 0;
_transferAmount(_token, _recipient, _poolAmount);
}

/// @notice Distribute pool funds
/// @param _recipientIds Array of addresses to send the funds to
/// @param _recipientAmounts Array of amounts that maps to _recipientIds array
function _distribute(
address[] memory _recipientIds,
bytes memory _recipientAmounts,
address _sender
) internal virtual override onlyPoolManager(_sender) {
// Decode amounts from memory param
uint256[] memory amounts = abi.decode(_recipientAmounts, (uint256[]));

uint256 payoutLength = _recipientIds.length;

// Assert at least one recipient
if (payoutLength == 0) {
revert INPUT_LENGTH_MISMATCH();
}
// Assert recipient and amounts length are equal
if (payoutLength != amounts.length) {
revert INPUT_LENGTH_MISMATCH();
}

IAllo.Pool memory pool = allo.getPool(poolId);
IERC20(pool.token).approve(hedgey.contractAddress, poolAmount);
for (uint256 i; i < payoutLength; ) {
uint256 amount = amounts[i];
address recipientAddress = _recipientIds[i];

poolAmount -= amount;

uint256 rate = amount / hedgey.duration;

ITokenVestingPlans(hedgey.contractAddress).createPlan(
recipientAddress,
pool.token,
amount,
block.timestamp,
hedgey.cliff,
rate,
hedgey.period,
hedgey.adminAddress,
hedgey.adminTransferOBO
);
emit Distributed(
recipientAddress,
recipientAddress,
amount,
_sender
);
unchecked {
++i;
}
}
}

receive() external payable {}

// Not used in this Strategy
function _allocate(bytes memory, address) internal virtual override {
revert NOOP();
}

function _getRecipientStatus(
address
) internal view virtual override returns (Status) {
revert NOOP();
}

function _isValidAllocator(
address _allocator
) internal view virtual override returns (bool) {}

function _registerRecipient(
bytes memory _data,
address _sender
) internal virtual override returns (address) {}

function _getPayout(
address _recipientId,
bytes memory _data
) internal view virtual override returns (PayoutSummary memory) {}
}
47 changes: 47 additions & 0 deletions contracts/Hedgey.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract LocalHedgey {
event PlanCreated(
uint256 indexed id,
address indexed recipient,
address indexed token,
uint256 amount,
uint256 start,
uint256 cliff,
uint256 end,
uint256 rate,
uint256 period,
address vestingAdmin,
bool adminTransferOBO
);

function createPlan(
address recipient,
address token,
uint256 amount,
uint256 start,
uint256 cliff,
uint256 rate,
uint256 period,
address vestingAdmin,
bool adminTransferOBO
) external returns (uint256 newPlanId) {
uint256 end = start + period;
uint256 planId = 1;
emit PlanCreated(
planId,
recipient,
token,
amount,
start,
cliff,
end,
rate,
period,
vestingAdmin,
adminTransferOBO
);
return planId;
}
}
4 changes: 4 additions & 0 deletions scripts/args-hedgey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
"0x1133eA7Af70876e64665ecD07C0A0476d09465a1",
"EasyRPGFStrategyHedgey",
];
8 changes: 7 additions & 1 deletion scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ async function main() {
"EasyRPGFStrategy",
]);

console.log(`Strategy deployed to ${strategy.address}`);
const hedgeyStrategy = await hre.viem.deployContract(
"EasyRPGFStrategyHedgey",
[alloAddress, "EasyRPGFStrategyHedgey"]
);

console.log(`EasyRPGFStrategy deployed to ${strategy.address}`);
console.log(`EasyRPGFStrategyHedgey deployed to ${hedgeyStrategy.address}`);
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
Loading