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

posm: add staking through subscribers #229

Merged
merged 22 commits into from
Aug 2, 2024
Merged

posm: add staking through subscribers #229

merged 22 commits into from
Aug 2, 2024

Conversation

snreynolds
Copy link
Member

@snreynolds snreynolds commented Jul 30, 2024

TODO:

  • Test ETH, I think we may want to make these functions payable to enable multicall with them
  • Test malicious subscriber, token can still unsubscribe

@snreynolds snreynolds changed the title compiling posm: add staking through subscribers Jul 31, 2024
@snreynolds snreynolds marked this pull request as ready for review August 1, 2024 01:13
BaseActionsRouter(_poolManager)
Notifier(_subscriberGasLimit)
Copy link
Contributor

Choose a reason for hiding this comment

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

i said this on slack but i think it got lost in that giant thread lol

Do we need a gas limit at all? If it’s to protect users from malicious subscribers, a user could just unstake before removing liquidity if they end up in that scenario right? We just need to make sure that unstake is safe always, and then we don’t need a gas limit on the subscriber imo

thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhh i see youve just moved it to unsubscribe - nice. Do you think we should do this as a % of block gas limit?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah sure, happy to do that. But should it still be a constructor param (the percentage?)

Copy link
Contributor

Choose a reason for hiding this comment

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

oh i think it would be to remove constructor params entirely - if we dont care about the constructor having params then keep it as is!

src/PositionManager.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/base/Notifier.sol Show resolved Hide resolved
src/libraries/PositionConfig.sol Outdated Show resolved Hide resolved
src/libraries/PositionConfig.sol Outdated Show resolved Hide resolved
src/libraries/PositionConfig.sol Show resolved Hide resolved
src/libraries/PositionConfig.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
src/base/Notifier.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Show resolved Hide resolved
src/base/Notifier.sol Show resolved Hide resolved
src/base/Notifier.sol Outdated Show resolved Hide resolved

/// @dev Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.
function _unsubscribe(uint256 tokenId, PositionConfig memory config) internal {
ISubscriber _subscriber = subscriber[tokenId];
Copy link
Contributor

Choose a reason for hiding this comment

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

should it revert if they arent already subscribed? I believe currently if you call _unsubscribe and youre not subscribed it would succeed? Because contract calls to EOAs (like address(0)) succeed. Maybe add a test to check

Copy link
Member Author

Choose a reason for hiding this comment

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

it reverts in the test I wrote with no code changes

src/interfaces/INotifier.sol Show resolved Hide resolved
src/PositionManager.sol Show resolved Hide resolved
src/PositionManager.sol Show resolved Hide resolved
test/mocks/MockBadSubscribers.sol Show resolved Hide resolved
test/position-managers/NativeToken.t.sol Outdated Show resolved Hide resolved
src/PositionManager.sol Outdated Show resolved Hide resolved
abstract contract Notifier is INotifier {
using GasLimitCalculator for uint256;

error SubscriberCannotBeNotified();
Copy link
Contributor

Choose a reason for hiding this comment

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

subscriber address?

Copy link
Member Author

Choose a reason for hiding this comment

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

actually we dont even throw this anymore, removed

src/PositionManager.sol Outdated Show resolved Hide resolved
src/interfaces/IERC721Permit.sol Outdated Show resolved Hide resolved
configId = positionConfigs[tokenId] & MASK_UPPER_BIT;
}

function setConfigId(
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be called in mint? or removed? it currently isnt called anywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

oh ya.. I think merge conflicts got the best of me here

@@ -402,4 +407,35 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
assertEq(currency0.balanceOfSelf() - balance0Before, uint128(delta.amount0()));
assertEq(currency1.balanceOfSelf() - balance1Before, uint128(delta.amount1()));
}

// this test fails unless subscribe is payable
function test_mutlicall_mint_subscribe_native() public {
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
function test_mutlicall_mint_subscribe_native() public {
function test_multicall_mint_subscribe_native() public {

@@ -338,4 +337,12 @@ contract PositionManager is
super.transferFrom(from, to, id);
if (positionConfigs.hasSubscriber(id)) _notifyTransfer(id, from, to);
}

function getPositionConfigId(uint256 tokenId) external view returns (bytes32) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@inheritdoc and both these 2 functions in interface with natspec

Copy link
Contributor

Choose a reason for hiding this comment

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

oh theyre in with natspec - just inheritdoc!

@snreynolds snreynolds merged commit e764aec into main Aug 2, 2024
3 checks passed
@snreynolds snreynolds deleted the posm-staking branch August 2, 2024 22:23
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.

2 participants