Skip to content

Commit

Permalink
add exception handling (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
midnight-commit authored Mar 22, 2024
1 parent 7c381a0 commit 28296f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions contracts/interfaces/ILamaPay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ interface ILamaPay {
view
returns (uint256 withdrawableAmount, uint256 lastUpdate, uint256 owed);
function withdraw(address from, address to, uint216 amountPerSec) external;
function modifyStream(address oldTo, uint216 oldAmountPerSec, address to, uint216 amountPerSec) external;
}
19 changes: 14 additions & 5 deletions contracts/strategies/avalanche/traderjoe/MemeRushStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract MemeRushStrategy is BaseStrategy {

event AddStream(address lamaPayInstance, address payer, uint216 amountPerSec, address token);
event RemoveStream(address lamaPayInstance, address payer, uint216 amountPerSec, address token);
event BorkedStream(address lamaPayInstance, address payer, uint216 amountPerSec, address token);

constructor(BaseStrategySettings memory _baseStrategySettings, StrategySettings memory _strategySettings)
BaseStrategy(_baseStrategySettings, _strategySettings)
Expand All @@ -48,14 +49,14 @@ contract MemeRushStrategy is BaseStrategy {
function removeStream(address _lamaPayInstance, address _payer, uint216 _amountPerSec) external onlyDev {
(uint256 index, bool found) = findStream(_lamaPayInstance, _payer, _amountPerSec);
require(found, "MemeRushStrategy::Stream not configured!");
_getRewards();
streams[index] = streams[streams.length - 1];
streams.pop();
emit RemoveStream(_lamaPayInstance, _payer, _amountPerSec, ILamaPay(_lamaPayInstance).token());
}

function findStream(address _lamaPayInstance, address _payer, uint216 _amountPerSec)
internal
view
returns (uint256 index, bool found)
{
for (uint256 i = 0; i < streams.length; i++) {
Expand All @@ -81,17 +82,25 @@ contract MemeRushStrategy is BaseStrategy {
function _pendingRewards() internal view virtual override returns (Reward[] memory) {
Reward[] memory rewards = new Reward[](streams.length);
for (uint256 i = 0; i < streams.length; i++) {
(uint256 withdrawableAmount,,) = ILamaPay(streams[i].lamaPayInstance).withdrawable(
try ILamaPay(streams[i].lamaPayInstance).withdrawable(
streams[i].payer, address(this), streams[i].amountPerSec
);
rewards[i] = Reward({reward: streams[i].token, amount: withdrawableAmount});
) returns (uint256 withdrawableAmount, uint256, uint256) {
rewards[i] = Reward({reward: streams[i].token, amount: withdrawableAmount});
} catch {
rewards[i] = Reward({reward: streams[i].token, amount: 0});
}
}
return rewards;
}

function _getRewards() internal virtual override {
for (uint256 i = 0; i < streams.length; i++) {
ILamaPay(streams[i].lamaPayInstance).withdraw(streams[i].payer, address(this), streams[i].amountPerSec);
try ILamaPay(streams[i].lamaPayInstance).withdraw(streams[i].payer, address(this), streams[i].amountPerSec)
{} catch {
emit BorkedStream(
streams[i].lamaPayInstance, streams[i].payer, streams[i].amountPerSec, streams[i].token
);
}
}
}

Expand Down

0 comments on commit 28296f3

Please sign in to comment.