-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from paltalabs/feat/blend-soroswap-setup
Blend Soroswap setup
- Loading branch information
Showing
6 changed files
with
114 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod success; | ||
mod success; | ||
mod soroswap_setup; |
60 changes: 60 additions & 0 deletions
60
apps/contracts/strategies/blend/src/test/blend/soroswap_setup.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,60 @@ | ||
use soroban_sdk::{ | ||
Env, BytesN, Address, | ||
testutils::{Address as _} | ||
}; | ||
|
||
fn pair_contract_wasm(e: &Env) -> BytesN<32> { | ||
soroban_sdk::contractimport!( | ||
file = "../external_wasms/soroswap/soroswap_pair.optimized.wasm" | ||
); | ||
e.deployer().upload_contract_wasm(WASM) | ||
} | ||
|
||
// SoroswapFactory Contract | ||
mod factory { | ||
soroban_sdk::contractimport!(file = "../external_wasms/soroswap/soroswap_factory.optimized.wasm"); | ||
pub type SoroswapFactoryClient<'a> = Client<'a>; | ||
} | ||
use factory::SoroswapFactoryClient; | ||
|
||
pub fn create_soroswap_factory<'a>(e: &Env, setter: &Address) -> SoroswapFactoryClient<'a> { | ||
let pair_hash = pair_contract_wasm(&e); | ||
let factory_address = &e.register(factory::WASM, ()); | ||
let factory = SoroswapFactoryClient::new(e, factory_address); | ||
factory.initialize(&setter, &pair_hash); | ||
factory | ||
} | ||
|
||
// SoroswapRouter Contract | ||
mod router { | ||
soroban_sdk::contractimport!(file = "../external_wasms/soroswap/soroswap_router.optimized.wasm"); | ||
pub type SoroswapRouterClient<'a> = Client<'a>; | ||
} | ||
pub use router::SoroswapRouterClient; | ||
|
||
// SoroswapRouter Contract | ||
pub fn create_soroswap_router<'a>(e: &Env, factory: &Address) -> SoroswapRouterClient<'a> { | ||
let router_address = &e.register(router::WASM, ()); | ||
let router = SoroswapRouterClient::new(e, router_address); | ||
router.initialize(factory); | ||
router | ||
} | ||
|
||
pub fn create_soroswap_pool<'a>(e: &Env, to: &Address, token_a: &Address, token_b: &Address, amount_a: &i128, amount_b: &i128) -> SoroswapRouterClient<'a> { | ||
let soroswap_admin = Address::generate(&e); | ||
let factory = create_soroswap_factory(&e, &soroswap_admin); | ||
let router = create_soroswap_router(&e, &factory.address); | ||
|
||
router.add_liquidity( | ||
token_a, | ||
token_b, | ||
&amount_a, | ||
&amount_b, | ||
&0i128, | ||
&0i128, | ||
&to, | ||
&(e.ledger().timestamp() + 3600) | ||
); | ||
|
||
router | ||
} |
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