-
Notifications
You must be signed in to change notification settings - Fork 0
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
BNBx integration #2
base: add-masterVault
Are you sure you want to change the base?
Conversation
function claimFundsforUsers(){ | ||
// iterate over user requests | ||
// check if 15 days have passed after user has triggered requestWithdraw | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to find a way to provide funds back to users
|
||
// uint256 batchId = | ||
_stakeManager.claimWithdraw(claimableIdx); | ||
// _distributeFunds(batchId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we distribute rewards in FIFO order of user requests ?
/// @dev deposits the given amount of BNB into Stader stakeManager through bnbxRouter | ||
function deposit() external payable onlyVault returns (uint256) { | ||
uint256 amount = msg.value; | ||
require(amount <= address(this).balance, "insufficient balance"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required. added it as it was there in ceros samples
.
return _deposit(amount); | ||
} | ||
|
||
/// @dev deposits all the available BNB into Stader stakeManager through bnbxRouter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...available BNB on router into stader ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed changing comments
should be
/// @dev deposits all the available BNB in this strategy contract to Stader stakeManager
Will check with Helio devs as well for its use case.
as it will deposit back the users funds. (unstaked funds)
Accordingly will have to update _bnbToDistribute
_bnbToDistribute = _bnbToDistribute - address(this).balance + msg.value
?
but there could be bnb transferred to this contract as well. as it contains a receive function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
require(canDeposit(amount), "invalid amount"); | ||
|
||
_bnbDepositBalance += amount; | ||
_bnbxHoldingBalance += _stakeManager.convertBnbToBnbX(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dulguun-staderlabs Should we instead calculate the difference of pre and post balances of BNBx than relying on the computed value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@galacticminter Yes. Otherwise this contract is depending on the external contract output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not relevant now. as we have removed the _bnbxHoldingBalance
variable.
_bnbDepositBalance += amount; | ||
_bnbxHoldingBalance += _stakeManager.convertBnbToBnbX(amount); | ||
_stakeManager.deposit{value: amount}(); | ||
return amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are not planning to return BNBx to user or master strategy, can we add that to documentation? If we are, we have to transfer it to msg.sender, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sending BNBx to user is not a requirement. Discussed with Dheeraj.
internal | ||
returns (uint256 value) | ||
{ | ||
require(amount > 0, "invalid amount"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this check over a uint256?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes not required. solidity will automatically handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (isClaimable) { | ||
foundClaimableReq = true; | ||
claimableIdx = idx; | ||
_bnbToDistribute += amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move stakeManager.claimWithdraw(idx) here?
Return true instead of break.
Return false at the end of fn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return the Claim_amount - amount (as funds queued for undelegation will keep accruing rewards until actually unstaked?) to Stader treasury? Otherwise slowly leads to BNB buildup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean,
after funds are sent back to this strategy contract, we will transfer it to stader treasury?
It would be better to handle in our contract (stakeManager
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
uint256 triggerTime; | ||
} | ||
mapping(uint256 => UserWithdrawRequest) private _withdrawRequests; | ||
uint256 private _firstWithdrawIdx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firstDistributeIdx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
{ | ||
reqCount = 0; | ||
|
||
while ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
for (uint256 idx = 0; idx < requests.length; idx++) { | ||
(bool isClaimable, uint256 amount) = _stakeManager | ||
.getUserRequestStatus(address(this), idx); | ||
if (isClaimable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this structure less nested.
if (!claimable) continue;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
external | ||
returns (uint256 reqCount) | ||
{ | ||
reqCount = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you incrementing reqCount?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, missed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// @dev withdraws everything from Stader's stakeManager | ||
function panic() external onlyStrategist returns (uint256) { | ||
(, , uint256 debt) = _vault.strategyParams(address(this)); | ||
return _withdraw(address(_vault), debt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we give away the power to withdraw any BNB to the strategist when all BNB incoming to this contract from the stakeManager has to be distributed to individual recipients?
Consider the following cases
- Any BNB deposited immediately gets converted to BNBx.
- Any BNB that gets transferred gets rejected (as there's no receive fn)
if debt is tracked by the master vault, why then are we tracking bnbDeposited?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the expectation that this panicked BNB will not be distributed to users later?
Does the master vault have bookkeeping to track this intervention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any BNB that gets transferred gets rejected (as there's no receive fn)
This contract contains a receive
fn
if debt is tracked by the master vault, why then are we tracking bnbDeposited?
master has the ability to update debt i.e. debt = any number
updateDebt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the expectation that this panicked BNB will not be distributed to users later?
I don't think so. We can check with Helio folks while PR review.
Does the master vault have bookkeeping to track this intervention?
Couldn't find any bookkeeping for this. Will check with Helios folks during PR review again.
But they do have a waiting pool contract
which has ability to maually add withdraw entries and pay off users debts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pstake and Helio discussion over this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with Dheeraj,
This is okay as it is not messing with bnbToDistribute or our book-keeping
Whereas it would just create a entry in our book-keeping for masterVault.
uint256 private _firstWithdrawIdx; | ||
uint256 private _nextWithdrawIdx; | ||
|
||
uint256 private _bnbxHoldingBalance; // amount of bnbx held by this strategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to keep track of this balance?
This is always bnbXtoken.balanceOf(address.of(this)) - bnbxToUnstake
, isn't it?
We only track bnbxToUnstake and only bnbDeposited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes the above should work unless
someone transfers bnbx token to this contract ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return _withdraw(recipient, amount); | ||
} | ||
|
||
/// @dev withdraws everything from Stader's stakeManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pstake and Helio discussion over this.
everything = bnb in strategy (users' unstaked funds + extraBNB if any)
+ bnb still deposited in stakeManager
And as per master vault's code, it is bnbDepositBalance
i.e. bnb still deposited in stakeManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here everything will be bnbDepositBalance
…contracts into bnbx-integrate
triggerTime: block.timestamp | ||
}); | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will have to return amount here. checked masterVault's code.
They are using this to update debt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
/// @dev deposits all the available BNB into Stader stakeManager through bnbxRouter | ||
function depositAll() external payable onlyVault returns (uint256) { | ||
return _deposit(address(this).balance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be _deposit(address(this).balance - _bnbToDistribute)
;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return 0; | ||
} | ||
|
||
// actual withdraw request to stader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@galacticminter
Do we need to add any restriction on this function to be callable only after 24 hours?
This reverts commit 96cc305.
No description provided.