-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add instructions * improve swap * seems to work * add helper function for decimal amonts * works * set non-zero platform fee * add token quantity assertions * add deadline test * default setup * default setup * clippy * checkpoitn * checkpoint * works * works * works * use old lock * missing assert * add to CI * add test * pr comments: make split parameters explicit when asserting * use initialize * 10f64 * pr comments: rename to create mint * make aidrop amount an arg * go * refactor into two functions * remove f64 notation
- Loading branch information
Showing
19 changed files
with
1,006 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Test SVM contracts | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- contracts/svm/** | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- contracts/svm/** | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: contracts/svm | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: 1.75.0 | ||
override: true | ||
- name: Install Solana | ||
run: | | ||
sh -c "$(curl -sSfL https://release.solana.com/v1.18.16/install)" | ||
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH | ||
- name: Build | ||
run: cargo-build-sbf | ||
- name: Run tests | ||
run: cargo-test-sbf && cargo test -p testing |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
contracts/svm/testing/src/express_relay/set_swap_platform_fee.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::SetSplits, | ||
SetSwapPlatformFeeArgs, | ||
}, | ||
solana_sdk::{ | ||
instruction::Instruction, | ||
signature::Keypair, | ||
signer::Signer, | ||
}, | ||
}; | ||
|
||
pub fn set_swap_platform_fee_instruction( | ||
admin: &Keypair, | ||
swap_platform_fee_bps: u64, | ||
) -> Instruction { | ||
let express_relay_metadata = get_express_relay_metadata_key(); | ||
|
||
Instruction { | ||
program_id: express_relay::id(), | ||
data: express_relay::instruction::SetSwapPlatformFee { | ||
data: SetSwapPlatformFeeArgs { | ||
swap_platform_fee_bps, | ||
}, | ||
} | ||
.data(), | ||
accounts: SetSplits { | ||
admin: admin.pubkey(), | ||
express_relay_metadata, | ||
} | ||
.to_account_metas(None), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
use { | ||
super::helpers::get_express_relay_metadata_key, | ||
anchor_lang::{ | ||
InstructionData, | ||
ToAccountMetas, | ||
}, | ||
anchor_spl::{ | ||
associated_token::{ | ||
get_associated_token_address_with_program_id, | ||
spl_associated_token_account::instruction::create_associated_token_account_idempotent, | ||
}, | ||
token::spl_token, | ||
}, | ||
express_relay::{ | ||
accounts::{ | ||
self, | ||
}, | ||
instruction::Swap, | ||
FeeToken, | ||
SwapArgs, | ||
}, | ||
solana_sdk::{ | ||
instruction::Instruction, | ||
pubkey::Pubkey, | ||
}, | ||
}; | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn create_swap_instruction( | ||
searcher: Pubkey, | ||
trader: Pubkey, | ||
searcher_input_ta: Option<Pubkey>, | ||
searcher_output_ta: Option<Pubkey>, | ||
router_fee_receiver_ta: Pubkey, | ||
fee_receiver_relayer: Pubkey, | ||
mint_input: Pubkey, | ||
mint_output: Pubkey, | ||
token_program_input: Option<Pubkey>, | ||
token_program_output: Option<Pubkey>, | ||
swap_args: SwapArgs, | ||
) -> Instruction { | ||
let express_relay_metadata = get_express_relay_metadata_key(); | ||
|
||
let mint_fee = match swap_args.fee_token { | ||
FeeToken::Input => mint_input, | ||
FeeToken::Output => mint_output, | ||
}; | ||
|
||
let token_program_input = token_program_input.unwrap_or(spl_token::ID); | ||
let token_program_output = token_program_output.unwrap_or(spl_token::ID); | ||
|
||
let token_program_fee = match swap_args.fee_token { | ||
FeeToken::Input => token_program_input, | ||
FeeToken::Output => token_program_output, | ||
}; | ||
let accounts_submit_bid = accounts::Swap { | ||
searcher, | ||
trader, | ||
searcher_input_ta: searcher_input_ta.unwrap_or( | ||
get_associated_token_address_with_program_id( | ||
&searcher, | ||
&mint_input, | ||
&token_program_input, | ||
), | ||
), | ||
searcher_output_ta: searcher_output_ta.unwrap_or( | ||
get_associated_token_address_with_program_id( | ||
&searcher, | ||
&mint_output, | ||
&token_program_output, | ||
), | ||
), | ||
trader_input_ata: get_associated_token_address_with_program_id( | ||
&trader, | ||
&mint_input, | ||
&token_program_input, | ||
), | ||
trader_output_ata: get_associated_token_address_with_program_id( | ||
&trader, | ||
&mint_output, | ||
&token_program_output, | ||
), | ||
router_fee_receiver_ta, | ||
relayer_fee_receiver_ata: get_associated_token_address_with_program_id( | ||
&fee_receiver_relayer, | ||
&mint_fee, | ||
&token_program_fee, | ||
), | ||
express_relay_fee_receiver_ata: get_associated_token_address_with_program_id( | ||
&express_relay_metadata, | ||
&mint_fee, | ||
&token_program_fee, | ||
), | ||
mint_input, | ||
mint_output, | ||
mint_fee, | ||
token_program_input, | ||
token_program_output, | ||
token_program_fee, | ||
express_relay_metadata, | ||
} | ||
.to_account_metas(None); | ||
|
||
Instruction { | ||
program_id: express_relay::ID, | ||
accounts: accounts_submit_bid, | ||
data: Swap { data: swap_args }.data(), | ||
} | ||
} | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn build_swap_instructions( | ||
searcher: Pubkey, | ||
trader: Pubkey, | ||
searcher_input_ta: Option<Pubkey>, | ||
searcher_output_ta: Option<Pubkey>, | ||
router_fee_receiver_ta: Pubkey, | ||
fee_receiver_relayer: Pubkey, | ||
mint_input: Pubkey, | ||
mint_output: Pubkey, | ||
token_program_input: Option<Pubkey>, | ||
token_program_output: Option<Pubkey>, | ||
swap_args: SwapArgs, | ||
) -> Vec<Instruction> { | ||
let mut instructions: Vec<Instruction> = vec![]; | ||
|
||
let token_program_input = token_program_input.unwrap_or(spl_token::ID); | ||
let token_program_output = token_program_output.unwrap_or(spl_token::ID); | ||
let mint_fee = match swap_args.fee_token { | ||
FeeToken::Input => mint_input, | ||
FeeToken::Output => mint_output, | ||
}; | ||
let token_program_fee = match swap_args.fee_token { | ||
FeeToken::Input => token_program_input, | ||
FeeToken::Output => token_program_output, | ||
}; | ||
|
||
if searcher_output_ta.is_none() { | ||
instructions.push(create_associated_token_account_idempotent( | ||
&searcher, | ||
&searcher, | ||
&mint_output, | ||
&token_program_output, | ||
)); | ||
} | ||
instructions.push(create_associated_token_account_idempotent( | ||
&searcher, | ||
&trader, | ||
&mint_input, | ||
&token_program_input, | ||
)); | ||
instructions.push(create_associated_token_account_idempotent( | ||
&searcher, | ||
&fee_receiver_relayer, | ||
&mint_fee, | ||
&token_program_fee, | ||
)); | ||
instructions.push(create_associated_token_account_idempotent( | ||
&searcher, | ||
&get_express_relay_metadata_key(), | ||
&mint_fee, | ||
&token_program_fee, | ||
)); | ||
|
||
|
||
instructions.push(create_swap_instruction( | ||
searcher, | ||
trader, | ||
searcher_input_ta, | ||
searcher_output_ta, | ||
router_fee_receiver_ta, | ||
fee_receiver_relayer, | ||
mint_input, | ||
mint_output, | ||
Some(token_program_input), | ||
Some(token_program_output), | ||
swap_args, | ||
)); | ||
|
||
instructions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.