Skip to content

Commit

Permalink
added extended interface
Browse files Browse the repository at this point in the history
  • Loading branch information
padoc-cloud committed Jan 8, 2023
1 parent e346103 commit 03d23fb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/MeijiMasterChefExtended.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.8.14;

import "./MeijiMasterChef.sol";

// Functions which would otherwise Clutter Masterchef for multi-actions
contract MeijiMasterChefExtended is MeijiMasterChef {
function multiWithdraw(uint256[] calldata positionIds, uint256[] calldata amounts) external {
// Update summations only once.
_updateRewardSummations();

// Ensure array lengths match.
uint256 length = positionIds.length;
if (length != amounts.length) revert MismatchedArrayLengths();

for (uint256 i = 0; i < length; ) {
_withdraw(positionIds[i], amounts[i]);

// Counter realistically cannot overflow.
unchecked {
++i;
}
}
}

function multiStake(uint256[] calldata positionIds, uint256[] calldata amounts) external {
// Update summations only once. Note that rewards accumulated when there is no one
// staking will be lost. But this is only a small risk of value loss if a reward period
// during no one staking is followed by staking.
_updateRewardSummations();

// Ensure array lengths match.
uint256 length = positionIds.length;
if (length != amounts.length) revert MismatchedArrayLengths();

for (uint256 i = 0; i < length; ) {
_stake(positionIds[i], amounts[i]);

// Counter realistically cannot overflow.
unchecked {
++i;
}
}
}
}

0 comments on commit 03d23fb

Please sign in to comment.