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

BNBx integration #2

Open
wants to merge 19 commits into
base: add-masterVault
Choose a base branch
from
Open

BNBx integration #2

wants to merge 19 commits into from

Conversation

manoj9april
Copy link
Collaborator

No description provided.

function claimFundsforUsers(){
// iterate over user requests
// check if 15 days have passed after user has triggered requestWithdraw
//
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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 ?

@manoj9april manoj9april self-assigned this Nov 7, 2022
@manoj9april manoj9april added the enhancement New feature or request label Nov 7, 2022
/// @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");

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?

Copy link
Collaborator Author

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

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 ...

Copy link
Collaborator Author

@manoj9april manoj9april Nov 8, 2022

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

Copy link
Collaborator Author

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);

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?

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.

Copy link
Collaborator Author

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;

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?

Copy link
Collaborator Author

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");

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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;

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.

Copy link

@galacticminter galacticminter Nov 8, 2022

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.

Copy link
Collaborator Author

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)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind this.

Copy link
Collaborator Author

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

firstDistributeIdx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
reqCount = 0;

while (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with for.

Copy link
Collaborator Author

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) {

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;

...

Copy link
Collaborator Author

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;

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed it.

Copy link
Collaborator Author

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);

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

  1. Any BNB deposited immediately gets converted to BNBx.
  2. 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?

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?

Copy link
Collaborator Author

@manoj9april manoj9april Nov 8, 2022

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

Copy link
Collaborator Author

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

Copy link
Collaborator Author

@manoj9april manoj9april Nov 8, 2022

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.

Copy link
Collaborator Author

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

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.

Copy link
Collaborator Author

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 ?

Copy link
Collaborator Author

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

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

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

triggerTime: block.timestamp
});

return 0;
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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);
Copy link

@galacticminter galacticminter Nov 9, 2022

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);

Copy link
Collaborator Author

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
Copy link
Collaborator Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants