8000 Paycall by cwang25 · Pull Request #170 · compound-finance/quark · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Paycall #170

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

Merged
merged 13 commits into from
Mar 1, 2024
Merged

Paycall #170

merged 13 commits into from
Mar 1, 2024

Conversation

cwang25
Copy link
Contributor
@cwang25 cwang25 commented Feb 28, 2024
  • Paycall will work like multicall
  • Paycall will accept callConatract and callData, and in paycall it will invoke via delegatecall so at the end it can direclty call transfer() to pay for gas without requiring user to approve the contract
  • Although using constructor can set the price feed data, but it's hard for the script to access those storages when being deletecalled by the caller (since it's running in the caller's context). The run() function will require user to pass in the actual Paycall's script address


/// @notice Constant buffer for gas overhead
/// This is a constant to accounted for the gas used by the Paycall contract itself that's not tracked by gasleft()
uint256 internal constant GAS_OVERHEAD = 75000;
Copy link
Contributor Author
@cwang25 cwang25 Feb 28, 2024

Choose a reason for hiding this comment

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

After several testing in forge test and tried to figure out the proper buffer for the gas estimate for the final payment at the end of the call. I found the gas overhead is hovering around 50k ~ 60k depends on the function that's get executed underneath. And in forge test, the first transaction is hovering around 100k ~ 110k. (So if repeatedly running same operations it's like 109139, 56839, 56839)

So I decided to put 75000 as gas overhead to find the middle ground of it.
(We might also want to add couple more buffer to account for price slippages and the risk we have during converting the asset back to ETH ?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the first transaction cheaper simply because of how forge works? IIRC, forge executes the entire test in a single transaction, so the subsequent calls are only cheaper because of warm loads. If that's the case, than the 56k numbers aren't really realistic for us to consider.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, this sounds really high, right? Like it should be 21K + some small overhead like 5K? The first creation is pretty meaningless since that only happens once ever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see. Then unfortunately :( looks like the gas_overhead is higher than we expected.
Yeah I was only using 21K, then realized some numbers are off between forge reported gas 😓


/// @notice Constant buffer for gas overhead
/// This is a constant to accounted for the gas used by the Paycall contract itself that's not tracked by gasleft()
uint256 internal constant GAS_OVERHEAD = 75000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the first transaction cheaper simply because of how forge works? IIRC, forge executes the entire test in a single transaction, so the subsequent calls are only cheaper because of warm loads. If that's the case, than the 56k numbers aren't really realistic for us to consider.

@cwang25 cwang25 requested a review from kevincheng96 February 29, 2024 07:24
Copy link
Collaborator
@kevincheng96 kevincheng96 left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@@ -79,8 +83,13 @@ contract PaycallTest is Test {
ethcallAddress = codeJar.saveCode(ethcall);
multicallAddress = codeJar.saveCode(multicall);
paycall = abi.encodePacked(type(Paycall).creationCode, abi.encode(ETH_PRICE_FEED, USDC));
paycallUSDT = abi.encodePacked(type(Paycall).creationCode, abi.encode(ETH_PRICE_FEED, USDT));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong price feed?

Also nit: ETH_USD_PRICE_FEED/ETH_USDT_PRICE_FEED

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 🤣 I was too lazy on this particular one, that I assumed USDT is 1:1 pegg in this test lol.
But yeah I will update to the USDT price feed then. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably going to stay with USD price list.
Found out chainlink only has USDT / ETH but not ETH / USDT.
So if we want to use USDT pricefeed, we need some solidity code to inverse it. :(

cwang25 and others added 5 commits February 29, 2024 16:58
Co-authored-by: Kevin Cheng <kevincheng96@hotmail.com>
Co-authored-by: Kevin Cheng <kevincheng96@hotmail.com>
Co-authored-by: Kevin Cheng <kevincheng96@hotmail.com>
@cwang25 cwang25 merged commit a3e63b7 into main Mar 1, 2024
@cwang25 cwang25 deleted the hans/paycall branch March 1, 2024 03:01
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.

3 participants
0