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

SOV-4106 Feat: Fee sharing collector with direct transfer #548

Open
wants to merge 15 commits into
base: bobDevelopment
Choose a base branch
from

Conversation

cwsnt
Copy link
Contributor

@cwsnt cwsnt commented Jun 14, 2024

No description provided.

@cwsnt cwsnt requested a review from tjcloa June 14, 2024 23:20
@cwsnt cwsnt changed the title Feat: Fee sharing collector with direct transfer SOV-4106 Feat: Fee sharing collector with direct transfer Jun 24, 2024
Copy link
Contributor

@koirikivi koirikivi left a comment

Choose a reason for hiding this comment

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

Generally LGTM, added a couple of comments about concerns:

  • Changing the native token address constant value is a possible footgun if the contract is updated on RSK
  • Make sure changing the ABI doesn't break frontend / backend!
  • I don't understand how it worked before the onlyExecution modifier was added, but I probably just missed something

Copy link
Contributor

@tjcloa tjcloa left a comment

Choose a reason for hiding this comment

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

pls see inline comments

// We will change, so that feeSharingCollector will directly burn then loanToken (IWRBTC) to rbtc and send to the user --- by call burnToBTC function
ILoanTokenWRBTC(_token).burnToBTC(_receiver, amount, false);
if (loanWrappedNativeTokenAddress == _token) {
// We will change, so that feeSharingCollector will directly burn then loanWrappedNativeToken (IWrappedNativeToken) to nativeToken and send to the user --- by call burnToBTC function
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// We will change, so that feeSharingCollector will directly burn then loanWrappedNativeToken (IWrappedNativeToken) to nativeToken and send to the user --- by call burnToBTC function
// We will change, so that feeSharingCollector will directly burn then loanWrappedNativeToken (IWrappedNativeToken) to nativeToken and send to the user --- by call burnToBTC function which is burning to a native token - to be renamed to burnedToNativeToken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in this commit

} else {
// Previously it directly send the loanToken to the user
// Previously it directly send the loanWrappedNativeToken to the user
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the loanToken renamed to loanWrappedNativeToken?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was accidentally replaced, reverted back in this addressed in this commit

Comment on lines 160 to 161
* the fees (except SOV) will be converted in wRBTC form, and then will be transferred to wRBTC loan pool.
* For SOV, it will be directly deposited into the FeeSharingCollectorMultipleToken from the protocol.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* the fees (except SOV) will be converted in wRBTC form, and then will be transferred to wRBTC loan pool.
* For SOV, it will be directly deposited into the FeeSharingCollectorMultipleToken from the protocol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

);
}

uint256 wrbtcAmountWithdrawn = protocol.withdrawFees(_tokens, address(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this multitoken implementation doesn't have RBTC mentions renamed to native token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

}

/**
* @notice Withdraw fees from sovryn dex:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @notice Withdraw fees from sovryn dex:
* @notice Withdraw fees from Sovryn DEX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no longer valid


if (loanWrappedNativeToken == _token) {
// We will change, so that FeeSharingCollectorMultipleToken will directly burn then loanToken (IWRBTC) to rbtc and send to the user --- by call burnToBTC function
uint256 loanAmountPaid = ILoanWrappedNativeToken(_token).burnToBTC(
Copy link
Contributor

Choose a reason for hiding this comment

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

unused variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

false
);
} else {
// Previously it directly send the token to the user
Copy link
Contributor

Choose a reason for hiding this comment

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

that's what it does now

Suggested change
// Previously it directly send the token to the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

*
* @param _tokens array addresses of the tokens
* */
function withdrawFeesFromDex(address[] memory _tokens) public {
Copy link
Contributor

Choose a reason for hiding this comment

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

missing tests for this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no longer valid

require(_amount > 0, "FeeSharingCollectorMultipleToken::transferTokens: invalid amount");

/// @notice Transfer tokens from msg.sender
bool success = IERC20(_token).transferFrom(address(msg.sender), address(this), _amount);
Copy link
Contributor

@tjcloa tjcloa Jun 26, 2024

Choose a reason for hiding this comment

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

it will fail when processing the native token - should check the value payload and process separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't think the initial function of transferTokens here is supporting native token?


/**
* @notice Transfer tokens to this contract.
* @dev We just update amount of tokens here and write checkpoint in a separate methods
Copy link
Contributor

Choose a reason for hiding this comment

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

pls add a @dev note that the caller should take care of setting allowance for the token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

contract FeeSharingCollectorMultiToken is
SafeMath96,
IFeeSharingCollectorMultiToken,
Ownable,
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Ownable instead of OwnableUpgradeable, but I discussed with Cowsant that this has been the norm for upgradeable contracts.

*
* @param _tokens array address of the token
* */
function withdrawFees(address[] memory _tokens) public {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any risk in this being public and re-entrant? Also this function doesn't validate _tokens, but maybe it happens in protocol.withdrawFees?

* the fees will be converted in wrappedNativeToken form, and then will be transferred to wrappedNativeToken loan pool
*
* */
function withdrawFeesFromLBDex() public {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any risk with this being public and re-entrant?


/// @notice Transfer tokens from msg.sender
bool success = IERC20(_token).transferFrom(address(msg.sender), address(this), _amount);
require(success, "Staking::transferTokens: token transfer failed");
Copy link
Contributor

Choose a reason for hiding this comment

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

Staking::transferTokens? Should this be FeeSharingCollectorMultiToken::transferTokens?

sender: root,
token: loanWrappedNativeToken.address,
amount: new BN(0),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

@cwsnt this test seems weird: shouldn't we have an "expectRevert" checking here, instead of an event of a successful tx?

);
});

it("Shouldn't be able to withdraw zero amount", async () => {
Copy link
Contributor

@jjmr007 jjmr007 Oct 7, 2024

Choose a reason for hiding this comment

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

@cwsnt Wrong test description. Instead of "Shouldn't be able to withdraw zero amount", should say: "Shouldn't be able to withdraw above available"

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

Successfully merging this pull request may close these issues.

4 participants