Repository navigation
fix: add native flavor for token-swap example - #778
SuperPiIot wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Every commit in a Solana Foundation repository needs signature verification, and these are unverified:
1a0283ffix: add native flavor for token-swap example
Set up signing, then sign the existing commits (git rebase --exec 'git commit --amend --no-edit -S' main) and force-push. This review is dismissed automatically once every commit verifies.
|
Hi @SuperPiIot, Thanks for the pull request. We ask that every change references an issue a maintainer has accepted, and there isn't one linked here. These examples are a teaching resource and each one has to stay small enough to read in one sitting, so whether a new example or framework flavor belongs here is worth settling before anyone writes it. Agreeing on the approach in an issue first means nobody writes code that can't be merged. See CONTRIBUTING.md for the full workflow. Please open an issue describing the change, or comment on the existing one. Once a maintainer has labelled it |
[Low impact] The changes are contained to the new native token-swap example. This PR is not ready to merge because the native program cannot be built, its operations do nothing, and the tests cannot load. Findings
SummaryThis PR adds the starting files for a native token-swap example.
Reviews (1) · Last reviewed commit: "fix: add native flavor for token-swap ex..." · Reviewed by Greptile |
| msg!("Token Swap Program Entry"); | ||
| // Aqui você adiciona a lógica para processar as instruções | ||
| Ok(()) |
There was a problem hiding this comment.
| use solana_program::{ | ||
| account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey, | ||
| }; | ||
|
|
||
| entrypoint!(process_instruction); |
| import { | ||
| createCreateAmmInstruction, | ||
| createCreatePoolInstruction, | ||
| createDepositLiquidityInstruction, | ||
| createSwapExactTokensForTokensInstruction, | ||
| createWithdrawLiquidityInstruction, | ||
| } from '../ts'; |
There was a problem hiding this comment.
| tokenMintKeypair1 = await generateKeyPairSigner(); | ||
| tokenMintKeypair2 = await generateKeyPairSigner(); | ||
| ammKeypair = await generateKeyPairSigner(); | ||
| poolKeypair = await generateKeyPairSigner(); |
There was a problem hiding this comment.
The setup generates mint keypairs but never creates or initializes the mints, creates the payer's token accounts, or gives the payer tokens. The SOL airdrop cannot fund token deposits. Add this setup so the deposit and swap cases can exercise real token transfers once the handlers are implemented.
| const poolInfo = svm.getAccount(poolKeypair.address); | ||
| assert(poolInfo.exists, 'pool account not updated'); |
There was a problem hiding this comment.
The deposit, swap, and withdrawal tests only check that the pool still exists. Once the pool is created, these assertions also pass when an operation returns success without doing anything. Check the payer and pool token balances, plus liquidity tokens minted or burned, after each operation.
Summary
This PR adds a native implementation of the
token-swapexample, following the structure of the existing anchor implementation. This allows learners to compare the same operations across different frameworks and understand the costs associated with each.Closes #755
/claim #755