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

Token Paymaster - Add Swapping Feature #11

Merged
merged 11 commits into from
Sep 25, 2024
Merged

Conversation

ShivaanshK
Copy link
Contributor

No description provided.

IOracle _nativeAssetToUsdOracle,
ISwapRouter _uniswapRouter,
address _wrappedNative,
address[] memory _tokens, // Array of token addresses supported by the paymaster
Copy link
Contributor

Choose a reason for hiding this comment

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

these are like the bucket of tokens which are supported in independent mode. think of corresponding name or maybe just comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. Needs a better name.

address _wrappedNative,
address[] memory _tokens, // Array of token addresses supported by the paymaster
IOracle[] memory _oracles, // Array of corresponding oracle addresses
address[] memory _swappableTokens, // Array of tokens that you want swappable by the uniswapper
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need to pass another array of addresses which is subset of above token addresses?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm to think of it, some tokens from another bucket (External mode) could also be swappable by uniswap.

Copy link
Contributor

Choose a reason for hiding this comment

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

also maybe we should create some read method to retrieve token bucket supported by this paymaster for independent mode (and external mode? tricky bc signing service decides that and keeps mapping)

Copy link
Contributor Author

@ShivaanshK ShivaanshK Sep 12, 2024

Choose a reason for hiding this comment

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

Addressing the last comment. For independent mode, it would use the tokens that are added by the owner through the public function. For external, the owner could add tokens just like for independent or it would auto add those tokens through the signed data on validation. The latter is impractical imo, since adding a token and corresponding pool is a one time job while the latter would require a change to the data that is signed by the verifyingSigner on every userop plus an additional check in the contract.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I think only retrieving independent mode tokens makes sense through the contract. for other we can keep public gated repo
cc Nishant

address[] memory _tokens, // Array of token addresses supported by the paymaster
IOracle[] memory _oracles, // Array of corresponding oracle addresses
address[] memory _swappableTokens, // Array of tokens that you want swappable by the uniswapper
uint24[] memory _swappableTokenPoolFeeTiers // Array of uniswap pool fee tiers for each swappable token
Copy link
Contributor

Choose a reason for hiding this comment

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

this is required by the swapper?

Copy link
Contributor Author

@ShivaanshK ShivaanshK Sep 12, 2024

Choose a reason for hiding this comment

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

yes. need to specify which fee tier pool to swap through. Some tokens have multiple supported tiers causing a difference in liquidity depth, and consequently, potential for price impact.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it

}
}

function _setTokenPool(address _token, uint24 _poolFeeTier) internal {
Copy link
Contributor

Choose a reason for hiding this comment

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

two methods to add and remove from swappable tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is internal

tokenToPools[_token] = _poolFeeTier; // set mapping of token to uniswap pool to use for swap
}

function _swapTokenToWeth(address _tokenIn, uint256 _amountIn) internal returns (uint256 amountOut) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should write test for this to run on couple of tokens on few mainnets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

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

review i

@livingrockrises livingrockrises marked this pull request as ready for review September 23, 2024 08:53
/// It also allows updating price configuration and withdrawing tokens by the contract owner.
/// The contract uses an Oracle to fetch the latest token prices.
/// @dev Inherits from BasePaymaster.
contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
Copy link
Contributor

Choose a reason for hiding this comment

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

this reference is from infinitism?

/// @param requiredPreFund The maximum cost (in native token) the paymaster has to prefund.
/// @return context The context containing the token amount and user sender address (if applicable).
/// @return validationResult A uint256 value indicating the result of the validation (always 0 in this implementation).
function _validatePaymasterUserOp(PackedUserOperation calldata userOp, bytes32, uint256 requiredPreFund)
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, let's discuss here. @ShivaanshK

Q. Does unaccountedGas need to be used at all in calculating precharge?

the maxCost that is being passed into validatePaymasterUserOp is calculated using the limits and the userop can’t use more gas than that

yes, true. it can only deviate by 10% otherwise there is penalty. so requiredPrefund would have paymasterPostOpGasLimit component? (todo: cross verify)
then this is really on how well paymaster service does it's job.

and in _postOp you will get actualGasCost. although diff may be very low in requiredPrefund and actualGasCost there is no harm in keeping unaccountedGasCost [ we should find out this value being set and used in live paymaster and see how off is it / or in our test case ] although we might have to keep it on token config basis but common global can't hurt.

then we shall keep these below lines too

uint256 refundPostopCost = tokenPaymasterConfig.refundPostopCost;
require(refundPostopCost < userOp.unpackPostOpGasLimit(), "TPM: postOpGasLimit too low");

Copy link
Contributor

Choose a reason for hiding this comment

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

"My intuition is that even if postOp revert due to exceeding the gas limit, the paymaster still needs to pay the gas used during postOp"
also didn't get this @ShivaanshK

}

/**
* @dev Set a new priceMarkup value.
Copy link
Contributor

Choose a reason for hiding this comment

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

check natspecs


address constant WRAPPED_NATIVE_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

address constant SWAP_ROUTER_ADDRESS = address(0xE592427A0AEce92De3Edee1F18E0157C05861564);
Copy link
Contributor

Choose a reason for hiding this comment

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

which chain addresses are these? does this run on a fork?

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

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

review ii

@livingrockrises
Copy link
Contributor

check lint.
I think back merge is needed, in this PR view BiconomyTokenPaymaster seems like a brand new file.

@livingrockrises livingrockrises changed the title Draft - Token Paymaster Token Paymaster - Add Swapping Feature Sep 23, 2024
@livingrockrises livingrockrises merged commit acc0dca into develop Sep 25, 2024
1 of 3 checks passed
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