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

chore(ui): evm to solana swap #461

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

ramenuncle
Copy link
Contributor

@ramenuncle ramenuncle commented Oct 25, 2022

  • Add manual redeem method to SDK
  • Complete EVM => Solana swap on UI
  • Fix some UI bugs

Testing

evm_to_solana.mov

Checklist

  • Github project and label have been assigned
  • Tests have been added or are unnecessary
  • Docs have been updated or are unnecessary
  • Preview deployment works (visit the Cloudflare preview URL)
  • Manual testing in #product-testing completed or unnecessary
  • New i18n strings do not contain any security vulnerabilities (e.g. should not allow translator to update email/url)
  • When fetching new translations from external sources, do a sanity check (e.g. get people who speak the language to check, shove all new translations into Google translate)

@ramenuncle ramenuncle added the feature New feature or request label Oct 25, 2022
@ramenuncle ramenuncle requested review from wormat and swimthor October 25, 2022 10:26
@ramenuncle ramenuncle self-assigned this Oct 25, 2022
@ramenuncle ramenuncle force-pushed the ui/evm-to-solana-swap branch from 21ff312 to f9e37fb Compare October 25, 2022 10:30
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 25, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: dd428fb
Status: ✅  Deploy successful!
Preview URL: https://5611cb7f.swim-ui.pages.dev
Branch Preview URL: https://ui-evm-to-solana-swap.swim-ui.pages.dev

View logs

@ramenuncle ramenuncle marked this pull request as ready for review October 25, 2022 10:31
packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/getAccounts.ts Show resolved Hide resolved
Copy link
Collaborator

@wormat wormat left a comment

Choose a reason for hiding this comment

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

Nice work

sourceChainConfig,
);
const setComputeUnitLimitIx = ComputeBudgetProgram.setComputeUnitLimit({
units: 900_000,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has this been optimized?

Copy link
Contributor Author

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

Copy link
Collaborator

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?

packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
apps/ui/src/models/swim/interactionStateV2.ts Outdated Show resolved Hide resolved
Comment on lines 178 to 194
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,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be DRYer.

@ramenuncle ramenuncle force-pushed the ui/evm-to-solana-swap branch from 3828add to fa7bfd2 Compare October 25, 2022 14:25
@ramenuncle ramenuncle force-pushed the ui/evm-to-solana-swap branch from fa7bfd2 to 1c76651 Compare October 25, 2022 14:31
@ramenuncle ramenuncle requested a review from wormat October 25, 2022 16:11
packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
@ramenuncle ramenuncle force-pushed the ui/evm-to-solana-swap branch from af975cd to 22d5e54 Compare October 26, 2022 09:33
Comment on lines 177 to 220
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;
}
});
}
Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks great!

@ramenuncle ramenuncle force-pushed the ui/evm-to-solana-swap branch from 22d5e54 to 75a19f3 Compare October 26, 2022 09:48
Copy link
Collaborator

@wormat wormat left a 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;
Copy link
Collaborator

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.

Comment on lines 177 to 220
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;
}
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks great!

packages/solana/src/protocol.ts Outdated Show resolved Hide resolved
packages/solana/src/client.ts Show resolved Hide resolved
packages/solana/src/client.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@wormat wormat left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants