raydium amm
1.0.0
환경 | 프로그램 |
---|---|
메인 넷 | 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 |
데넷 | HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 |
solana-keygen new
실행하여 기본 위치에서 키어를 만듭니다. 저장소를 복제하고 소스 코드 디렉토리를 입력하십시오.
git clone https://github.com/raydium-io/raydium-amm
cd raydium-amm/program
cargo build-bpf
cargo build-bpf --features devnet
빌드하기 전에 로컬 넷 기능을 통해 "config_feature"에서이 pubkeys를 업데이트해야합니다.
cargo build-bpf --features localnet
구축 후 스마트 계약 파일은 모두 대상 디렉토리에 있습니다.
solana deploy
주의, 구성을 확인하고 배포하려는 환경을 확인하십시오.
새 AMM 풀을 초기화하려는 경우 AMM 풀과 연관되지 않은 오픈 북 시장이 있어야합니다. 그리고 새로운 시장을 만들기 위해 ListMarket을 참조 할 수 있습니다.
Cargo.toml에 종속성을 추가하십시오
[ dependencies ]
[ features ]
# default is mainnet
devnet = [
"amm-cli/devnet" ,
"common/devnet" ,
]
[ dependencies ]
amm-cli = { git = "https://github.com/raydium-io/raydium-library" }
common = { git = "https://github.com/raydium-io/raydium-library" }
spl-token = { version = "4.0.0" , features = [ "no-entrypoint" ] }
spl-associated-token-account = { version = "2.2.0" , features = [
"no-entrypoint" ,
] }
spl-token- 2022 = { version = "0.9.0" , features = [ "no-entrypoint" ] }
solana-client = "<1.17.0"
solana-sdk = "<1.17.0"
anyhow = "1.0.53"
clap = { version = "4.1.8" , features = [ "derive" ] }
#! [ allow ( dead_code ) ]
use anyhow :: { Ok , Result } ;
use clap :: Parser ;
use solana_client :: rpc_client :: RpcClient ;
use solana_sdk :: { commitment_config :: CommitmentConfig , signer :: Signer } ;
use std :: sync :: Arc ;
use {
amm_cli :: { self , AmmCommands } ,
common :: { common_types , common_utils , rpc } ,
} ;
// default config
let mut config = common_types :: CommonConfig :: default ( ) ;
// Replace the default configuration parameters you need
config . set_cluster ( "http" , "ws" ) ;
config . set_wallet ( "your wallet path" ) ;
config . set_amm_program ( "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8" ) ;
config . set_openbook_program ( "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX" ) ;
config . set_slippage ( 50 ) ;
let payer = common_utils :: read_keypair_file ( & config . wallet ( ) ) ? ;
let fee_payer = payer . pubkey ( ) ;
let mut signing_keypairs : Vec < Arc < dyn Signer > > = Vec :: new ( ) ;
let payer : Arc < dyn Signer > = Arc :: new ( payer ) ;
if !signing_keypairs . contains ( & payer ) {
signing_keypairs . push ( payer ) ;
}
// build initialize pool instruction
let subcmd = AmmCommands :: CreatePool {
market : Pubkey :: from_str ( "The amm associated with openbook market" ) . unwrap ( ) ,
coin_mint : Pubkey :: from_str ( "The openbook market's coin_mint" ) . unwrap ( ) ,
pc_mint : Pubkey :: from_str ( "The openbook market's pc_mint" ) . unwrap ( ) ,
user_token_coin : Pubkey :: from_str ( "User's token coin" ) . unwrap ( ) ,
user_token_pc : Pubkey :: from_str ( "User's token pc" ) . unwrap ( ) ,
init_coin_amount : 100000u64 ,
init_pc_amount : 100000u64 ,
open_time : 0 ,
} ;
let instruction = amm_cli :: process_amm_commands ( subcmd , & config ) . unwrap ( ) ;
// build deposit instruction
let subcmd = AmmCommands :: Deposit {
pool_id : Pubkey :: from_str ( "The specified pool of the assets deposite to" ) . unwrap ( ) ,
deposit_token_coin : Some ( Pubkey :: from_str ( "The specified token coin of the user deposit" ) . unwrap ( ) ) ,
deposit_token_pc : Some ( Pubkey :: from_str ( "The specified token pc of the user deposit" ) . unwrap ( ) ) ,
recipient_token_lp : Some ( Pubkey :: from_str ( "The specified lp token of the user will receive" ) . unwrap ( ) ) ,
amount_specified : 100000u64 ,
another_min_limit : false ,
base_coin : false ,
} ;
let instruction = amm_cli :: process_amm_commands ( subcmd , & config ) . unwrap ( ) ;
예금 _token_coin의 매개 변수, 예금 _token_pc 또는 Recepitient_token_lp의 매개 변수가 없으면 기본적으로 ATA 토큰이됩니다.
// build withdraw instruction
let subcmd = AmmCommands :: Withdraw {
pool_id : Pubkey :: from_str ( "The specified pool of the assets withdraw from" ) . unwrap ( ) ,
withdraw_token_lp : Some ( Pubkey :: from_str ( "The specified lp token of the user withdraw" ) . unwrap ( ) ) ,
recipient_token_coin : Some ( Pubkey :: from_str ( "The specified token coin of the user will receive" ) . unwrap ( ) ) ,
recipient_token_pc : Some ( Pubkey :: from_str ( "The specified token pc of the user will receive" ) . unwrap ( ) ) ,
input_lp_amount : 100000u64 ,
slippage_limit : false ,
} ;
let instruction = amm_cli :: process_amm_commands ( subcmd , & config ) . unwrap ( ) ;
enthe_token_lp의 매개 변수, Recepitient_Token_Coin 또는 Recepient_Token_PC의 매개 변수가 없으면 기본적으로 ATA 토큰이됩니다.
// build swap instruction
let subcmd = AmmCommands :: Swap {
pool_id : Pubkey :: from_str ( " The specified pool of trading" ) . unwrap ( ) ,
user_input_token : Pubkey :: from_str ( "The token of user want to swap from" ) . unwrap ( ) ,
user_output_token : Some ( Pubkey :: from_str ( "The token of user want to swap to" ) . unwrap ( ) ) ,
amount_specified : 100000u64 ,
base_out : false ,
} ;
let instruction = amm_cli :: process_amm_commands ( subcmd , & config ) . unwrap ( ) ;
user_output_token의 매개 변수가 없으면 기본적으로 ATA 토큰이됩니다.
자세한 내용은 Repo Raydium-Library를 참조하십시오