-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add withdraw spl fees ix #584
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ jobs: | |
| - uses: actions/checkout@v2 | ||
| - name: Install Solana Verify CLI | ||
| run: | | ||
| cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 5ff03e0 | ||
| cargo install --locked solana-verify --git https://github.com/solana-foundation/solana-verifiable-build --rev 5ff03e0 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 CI: In Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| - name: Build | ||
| run: solana-verify build | ||
| - name: Run tests | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| use { | ||
| super::helpers::get_express_relay_metadata_key, | ||
| anchor_lang::{ | ||
| InstructionData, | ||
| ToAccountMetas, | ||
| }, | ||
| express_relay::accounts::WithdrawSplFees, | ||
| solana_sdk::{ | ||
| instruction::Instruction, | ||
| pubkey::Pubkey, | ||
| signature::Keypair, | ||
| signer::Signer, | ||
| }, | ||
| }; | ||
|
|
||
| pub fn withdraw_spl_fees_instruction( | ||
| admin: &Keypair, | ||
| express_relay_fee_receiver_ata: Pubkey, | ||
| fee_receiver_admin_ta: Pubkey, | ||
| mint_fee: Pubkey, | ||
| token_program_fee: Pubkey, | ||
| ) -> Instruction { | ||
| let express_relay_metadata = get_express_relay_metadata_key(); | ||
|
|
||
| Instruction { | ||
| program_id: express_relay::id(), | ||
| data: express_relay::instruction::WithdrawSplFees {}.data(), | ||
| accounts: WithdrawSplFees { | ||
| admin: admin.pubkey(), | ||
| express_relay_metadata, | ||
| express_relay_fee_receiver_ata, | ||
| fee_receiver_admin_ta, | ||
| mint_fee, | ||
| token_program_fee, | ||
| } | ||
| .to_account_metas(None), | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| use { | ||
| anchor_lang::error::ErrorCode as AnchorErrorCode, | ||
| anchor_spl::{ | ||
| associated_token::{ | ||
| get_associated_token_address_with_program_id, | ||
| spl_associated_token_account::instruction::create_associated_token_account_idempotent, | ||
| }, | ||
| token::spl_token, | ||
| }, | ||
| solana_sdk::{ | ||
| instruction::InstructionError, | ||
| signature::Keypair, | ||
| signer::Signer, | ||
| }, | ||
| testing::{ | ||
| express_relay::{ | ||
| helpers::get_express_relay_metadata_key, | ||
| withdraw_spl_fees::withdraw_spl_fees_instruction, | ||
| }, | ||
| helpers::{ | ||
| assert_custom_error, | ||
| generate_and_fund_key, | ||
| submit_transaction, | ||
| }, | ||
| setup::{ | ||
| setup, | ||
| SetupResult, | ||
| }, | ||
| token::Token, | ||
| }, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn test_withdraw_spl_fees() { | ||
| let SetupResult { mut svm, admin, .. } = setup(None).expect("setup failed"); | ||
|
|
||
| let express_relay_metadata = get_express_relay_metadata_key(); | ||
| let fee_receiver_admin = generate_and_fund_key(&mut svm); | ||
| let fee_token = Token::create_mint(&mut svm, spl_token::ID, 6); | ||
|
|
||
| let express_relay_fee_receiver_ata = get_associated_token_address_with_program_id( | ||
| &express_relay_metadata, | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
| let fee_receiver_admin_ata = get_associated_token_address_with_program_id( | ||
| &fee_receiver_admin.pubkey(), | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
|
|
||
| fee_token.airdrop(&mut svm, &express_relay_metadata, 3.5); | ||
|
|
||
| let create_admin_ata_ix = create_associated_token_account_idempotent( | ||
| &admin.pubkey(), | ||
| &fee_receiver_admin.pubkey(), | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
| let withdraw_ix = withdraw_spl_fees_instruction( | ||
| &admin, | ||
| express_relay_fee_receiver_ata, | ||
| fee_receiver_admin_ata, | ||
| fee_token.mint, | ||
| fee_token.token_program, | ||
| ); | ||
| submit_transaction( | ||
| &mut svm, | ||
| &[create_admin_ata_ix, withdraw_ix], | ||
| &admin, | ||
| &[&admin], | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert!(Token::token_balance_matches( | ||
| &mut svm, | ||
| &express_relay_fee_receiver_ata, | ||
| 0, | ||
| )); | ||
| assert!(Token::token_balance_matches( | ||
| &mut svm, | ||
| &fee_receiver_admin_ata, | ||
| fee_token.get_amount_with_decimals(3.5), | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_withdraw_spl_fees_fail_wrong_admin() { | ||
| let SetupResult { mut svm, .. } = setup(None).expect("setup failed"); | ||
| let wrong_admin = generate_and_fund_key(&mut svm); | ||
|
|
||
| let express_relay_metadata = get_express_relay_metadata_key(); | ||
| let fee_receiver_admin = Keypair::new(); | ||
| let fee_token = Token::create_mint(&mut svm, spl_token::ID, 6); | ||
| let express_relay_fee_receiver_ata = get_associated_token_address_with_program_id( | ||
| &express_relay_metadata, | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
| let fee_receiver_admin_ata = get_associated_token_address_with_program_id( | ||
| &fee_receiver_admin.pubkey(), | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
| fee_token.airdrop(&mut svm, &express_relay_metadata, 1.0); | ||
| let create_admin_ata_ix = create_associated_token_account_idempotent( | ||
| &wrong_admin.pubkey(), | ||
| &fee_receiver_admin.pubkey(), | ||
| &fee_token.mint, | ||
| &fee_token.token_program, | ||
| ); | ||
| submit_transaction( | ||
| &mut svm, | ||
| &[create_admin_ata_ix], | ||
| &wrong_admin, | ||
| &[&wrong_admin], | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let withdraw_ix = withdraw_spl_fees_instruction( | ||
| &wrong_admin, | ||
| express_relay_fee_receiver_ata, | ||
| fee_receiver_admin_ata, | ||
| fee_token.mint, | ||
| fee_token.token_program, | ||
| ); | ||
| let tx_result = submit_transaction(&mut svm, &[withdraw_ix], &wrong_admin, &[&wrong_admin]) | ||
| .expect_err("Transaction should have failed"); | ||
|
|
||
| assert_custom_error( | ||
| tx_result.err, | ||
| 0, | ||
| InstructionError::Custom(AnchorErrorCode::ConstraintHasOne.into()), | ||
| ); | ||
| } |
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.
needed to lock to the local lockfile to prevent issues with our toolchain rust version