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

Support recurring swaps in QuarkBuilder #65

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

kevincheng96
Copy link
Contributor

@kevincheng96 kevincheng96 commented Aug 22, 2024

This implements the QuarkBuilder logic to construct Quark Operations for recurring swaps. We introduce a few new libraries that hardcode some addresses: PriceFeeds.sol and UniswapRouter.sol.

@kevincheng96 kevincheng96 force-pushed the kevin/recurring-purchase-quark-builder branch from 24d4434 to e94f6ae Compare August 22, 2024 08:38
Comment on lines +1216 to +1244
return balanceOnChain;
}

function getAmountNeededOnChain(
string memory assetSymbol,
uint256 amount,
uint256 chainId,
PaymentInfo.Payment memory payment
) internal pure returns (uint256) {
// If action is paid for with tokens and the payment token is the transfer token, then add the payment max cost for the target chain to the amount needed
uint256 amountNeededOnChain = amount;
if (payment.isToken && Strings.stringEqIgnoreCase(payment.currency, assetSymbol)) {
amountNeededOnChain += PaymentInfo.findMaxCost(payment, chainId);
}

return amountNeededOnChain;
}

function needsBridgedFunds(
string memory assetSymbol,
uint256 amount,
uint256 chainId,
Accounts.ChainAccounts[] memory chainAccountsList,
PaymentInfo.Payment memory payment
) internal pure returns (bool) {
uint256 balanceOnChain = getBalanceOnChain(assetSymbol, chainId, chainAccountsList, payment);
uint256 amountNeededOnChain = getAmountNeededOnChain(assetSymbol, amount, chainId, payment);

return balanceOnChain < amountNeededOnChain;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These diffs are just pulling out the logic in needsBridgedFunds into two separate helper functions.

@kevincheng96 kevincheng96 force-pushed the kevin/recurring-purchase-quark-builder branch from e94f6ae to dba1bcd Compare August 23, 2024 05:25
Base automatically changed from kevin/recurring-purchase to main August 26, 2024 17:18
Copy link
Contributor

@banky banky left a comment

Choose a reason for hiding this comment

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

Looks good ✅


// Mainnet
function knownPriceFeeds_1() internal pure returns (PriceFeed[] memory) {
PriceFeed[] memory priceFeeds = new PriceFeed[](4);
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 plan to add every price feed for all supported tokens here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we'll have to hardcode all the price feeds for tokens we care about. 🧇 is working on a crawler that will output a Solidity config file that will replace this file.

@kevincheng96 kevincheng96 force-pushed the kevin/recurring-purchase-quark-builder branch from dba1bcd to 9d7c5e1 Compare August 28, 2024 22:35
@kevincheng96 kevincheng96 force-pushed the kevin/recurring-purchase-quark-builder branch from b0d0e0f to d073399 Compare August 29, 2024 18:12
@kevincheng96 kevincheng96 merged commit 2659a11 into main Aug 29, 2024
4 checks passed
@kevincheng96 kevincheng96 deleted the kevin/recurring-purchase-quark-builder branch August 29, 2024 21:53
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