-
Notifications
You must be signed in to change notification settings - Fork 2
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
chore(ui): evm to solana swap #461
base: master
Are you sure you want to change the base?
Conversation
21ff312
to
f9e37fb
Compare
Deploying with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
packages/solana/src/client.ts
Outdated
sourceChainConfig, | ||
); | ||
const setComputeUnitLimitIx = ComputeBudgetProgram.setComputeUnitLimit({ | ||
units: 900_000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this been optimized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, just copying from solana-contracts
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you check with Ricky what the best value for this is in each case?
apps/ui/src/hooks/interaction/useCrossChainEvmToSolanaSwapInteractionMutation.ts
Outdated
Show resolved
Hide resolved
apps/ui/src/hooks/interaction/useCrossChainEvmToSolanaSwapInteractionMutation.ts
Show resolved
Hide resolved
const crossChainInitiateTx = await evmClient.getTx( | ||
crossChainInitiateResponse, | ||
); | ||
crossChainInitiateTxId = crossChainInitiateTx.id; | ||
updateInteractionState(interaction.id, (draft) => { | ||
if ( | ||
draft.interactionType !== InteractionType.SwapV2 || | ||
draft.swapType !== SwapType.CrossChainEvmToSolana | ||
) { | ||
throw new Error("Interaction type mismatch"); | ||
} | ||
draft.crossChainInitiateTxId = crossChainInitiateTx.id; | ||
}); | ||
} | ||
const crossChainInitiateTx = await evmClient.getTx( | ||
crossChainInitiateTxId, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be DRYer.
apps/ui/src/hooks/interaction/useCrossChainEvmToSolanaSwapInteractionMutation.ts
Outdated
Show resolved
Hide resolved
3828add
to
fa7bfd2
Compare
fa7bfd2
to
1c76651
Compare
apps/ui/src/hooks/interaction/useCrossChainEvmToSolanaSwapInteractionMutation.ts
Outdated
Show resolved
Hide resolved
apps/ui/src/hooks/interaction/useCrossChainEvmToSolanaSwapInteractionMutation.ts
Outdated
Show resolved
Hide resolved
af975cd
to
22d5e54
Compare
const completeTransferTxGenerator = | ||
solanaClient.generateCompleteSwimSwapTxs({ | ||
wallet: toWallet, | ||
interactionId: interaction.id, | ||
signedVaa: Buffer.from(signedVaa), | ||
sourceChainConfig: fromChainConfig, | ||
sourceWormholeChainId: ecosystems[fromEcosystem].wormholeChainId, | ||
targetTokenNumber: tokenProject.tokenNumber, | ||
minimumOutputAmount, | ||
}); | ||
for await (const result of completeTransferTxGenerator) { | ||
updateInteractionState(interaction.id, (draft) => { | ||
if ( | ||
draft.interactionType !== InteractionType.SwapV2 || | ||
draft.swapType !== SwapType.CrossChainEvmToSolana | ||
) { | ||
throw new Error("Interaction type mismatch"); | ||
} | ||
switch (result.type) { | ||
case SolanaTxType.SwimCreateSplTokenAccount: { | ||
const mint = result.tx.original.meta?.preTokenBalances?.[0].mint; | ||
if (!mint) { | ||
throw new Error("Token account mint not found"); | ||
} | ||
draft.requiredSplTokenAccounts[mint].txId = result.tx.id; | ||
break; | ||
} | ||
case SolanaTxType.WormholeVerifySignatures: | ||
draft.verifySignaturesTxIds.push(result.tx.id); | ||
break; | ||
case SolanaTxType.WormholePostVaa: | ||
draft.postVaaOnSolanaTxId = result.tx.id; | ||
draft.auxiliarySignerPublicKey = | ||
auxiliarySigner.publicKey.toBase58(); | ||
break; | ||
case SolanaTxType.SwimCompleteNativeWithPayload: | ||
draft.completeNativeWithPayloadTxId = result.tx.id; | ||
break; | ||
case SolanaTxType.SwimProcessSwimPayload: | ||
draft.processSwimPayloadTxId = result.tx.id; | ||
break; | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved all the SolanaTx to SDK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
22d5e54
to
75a19f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking so good!
} | ||
switch (result.type) { | ||
case SolanaTxType.SwimCreateSplTokenAccount: { | ||
const mint = result.tx.original.meta?.preTokenBalances?.[0].mint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for now but Ricky says we can create multiple accounts in one tx.
const completeTransferTxGenerator = | ||
solanaClient.generateCompleteSwimSwapTxs({ | ||
wallet: toWallet, | ||
interactionId: interaction.id, | ||
signedVaa: Buffer.from(signedVaa), | ||
sourceChainConfig: fromChainConfig, | ||
sourceWormholeChainId: ecosystems[fromEcosystem].wormholeChainId, | ||
targetTokenNumber: tokenProject.tokenNumber, | ||
minimumOutputAmount, | ||
}); | ||
for await (const result of completeTransferTxGenerator) { | ||
updateInteractionState(interaction.id, (draft) => { | ||
if ( | ||
draft.interactionType !== InteractionType.SwapV2 || | ||
draft.swapType !== SwapType.CrossChainEvmToSolana | ||
) { | ||
throw new Error("Interaction type mismatch"); | ||
} | ||
switch (result.type) { | ||
case SolanaTxType.SwimCreateSplTokenAccount: { | ||
const mint = result.tx.original.meta?.preTokenBalances?.[0].mint; | ||
if (!mint) { | ||
throw new Error("Token account mint not found"); | ||
} | ||
draft.requiredSplTokenAccounts[mint].txId = result.tx.id; | ||
break; | ||
} | ||
case SolanaTxType.WormholeVerifySignatures: | ||
draft.verifySignaturesTxIds.push(result.tx.id); | ||
break; | ||
case SolanaTxType.WormholePostVaa: | ||
draft.postVaaOnSolanaTxId = result.tx.id; | ||
draft.auxiliarySignerPublicKey = | ||
auxiliarySigner.publicKey.toBase58(); | ||
break; | ||
case SolanaTxType.SwimCompleteNativeWithPayload: | ||
draft.completeNativeWithPayloadTxId = result.tx.id; | ||
break; | ||
case SolanaTxType.SwimProcessSwimPayload: | ||
draft.processSwimPayloadTxId = result.tx.id; | ||
break; | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, let's send to manual testing then I'll publish.
Testing
evm_to_solana.mov
Checklist