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

feat: build cross swap tx #1274

Merged
merged 12 commits into from
Nov 20, 2024
Merged

feat: build cross swap tx #1274

merged 12 commits into from
Nov 20, 2024

Conversation

dohaki
Copy link
Contributor

@dohaki dohaki commented Nov 14, 2024

Closes ACX-3286

This adds cross swap tx building. Here are some example tx for the different cases:

type deposit tx fill tx
B2B Tx Tx
B2A tx tx
A2B tx tx
A2A tx tx

Copy link

linear bot commented Nov 14, 2024

Copy link

vercel bot commented Nov 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app-frontend-v3 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 3:24am
sepolia-frontend-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 20, 2024 3:24am

api/_dexes/cross-swap.ts Outdated Show resolved Hide resolved
? getMultiCallHandlerAddress(destinationChainId)
: crossSwapQuotes.crossSwap.recipient,
inputToken: crossSwapQuotes.bridgeQuote.inputToken.address,
outputToken: crossSwapQuotes.bridgeQuote.outputToken.address,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case of outputToken bridged USDC on a CCTP chain, would we short-circuit the destination swap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, we do the check here https://github.com/across-protocol/frontend-v2/blob/8ac1e952dee670245ffd52501e469f6b6b5e2c49/api/_dexes/cross-swap.ts#L129

and if it's a normal bridge route we don't populate a destination swap quote

api/_dexes/cross-swap.ts Outdated Show resolved Hide resolved
Comment on lines +236 to +245
async function getFillDeadline(spokePool: SpokePool): Promise<number> {
const calls = [
spokePool.interface.encodeFunctionData("getCurrentTime"),
spokePool.interface.encodeFunctionData("fillDeadlineBuffer"),
];

const [currentTime, fillDeadlineBuffer] =
await spokePool.callStatic.multicall(calls);
return Number(currentTime) + Number(fillDeadlineBuffer);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This also exists in src/utils/bridge.ts - is there anywhere common for generic utilities to be placed here, or do we have to upstream that to the sdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, we are currently in a weird state with API and FE source code... We can not share unfortunately because our current folder structure is not optimized for sharing utilities between API and FE without blowing up the bundle size.

So upstreaming to the SDK would prob make sense

api/_dexes/uniswap.ts Outdated Show resolved Hide resolved
amount: destinationSwapQuote.maximumAmountIn
.mul(
ethers.utils.parseEther(
(1 + Number(crossSwap.slippageTolerance) / 100).toString()
Copy link

Choose a reason for hiding this comment

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

Do we round off slippage tolerance? It seems like it is less than 100, since we pass in some number (default 1) here which is passed into getCrossSwapQuotes here, eventually ending up on a getUniswapCrossSwapQuotesFor* , and being divided by 100 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.

This is still some old design decision from our original swap implementation. There the 1inch API required slippage to be set like that, e.g. 1 = 1%. So what I am doing here is parsing that to our internal BigNumber percent representation.

I agree though that this is a bit confusing 🤔 The parsing should probably already happen at a higher level. Will refactor this

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 will tackle that in a separate PR though... Because the required changes are a bit more than expected

@dohaki dohaki merged commit b245827 into swap-endpoint Nov 20, 2024
9 checks passed
@dohaki dohaki deleted the bulild-cross-swap-tx branch November 20, 2024 13:10
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