Skip to content

Commit

Permalink
Merge pull request #399 from Phoenix-Protocol-Group/398-upgrade-contr…
Browse files Browse the repository at this point in the history
…acts-to-soroban-sdk-v2200

All: upgrades all contracts to latest soroban-sdk 22.0.0-rc.3.2
  • Loading branch information
ueco-jb authored Dec 4, 2024
2 parents 77742b0 + b66b2b4 commit ddf8a1e
Show file tree
Hide file tree
Showing 26 changed files with 830 additions and 652 deletions.
334 changes: 226 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ phoenix = { path = "./packages/phoenix" }
num-integer = { version = "0.1.45", default-features = false, features = [
"i128",
] }
soroban-sdk = "21.7.7"
soroban-token-sdk = "21.7.7"
soroban-sdk = "22.0.0-rc.3.2"
soroban-token-sdk = "22.0.0-rc.3.2"
test-case = "3.3"
pretty_assertions = "1.4.0"

Expand Down
2 changes: 1 addition & 1 deletion contracts/factory/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fmt:
cargo fmt --all

clippy: build
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets -- -D warnings -A clippy::too_many_arguments

clean:
cargo clean
50 changes: 25 additions & 25 deletions contracts/factory/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ fn factory_successfully_inits_stable_pool() {

let mut token1 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "EURO Coin"),
&String::from_str(&env, "EURC"),
token_admin.clone(),
7,
String::from_str(&env, "EURO Coin"),
String::from_str(&env, "EURC"),
);
let mut token2 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "USD Coin"),
&String::from_str(&env, "USDC"),
token_admin.clone(),
7,
String::from_str(&env, "USD Coin"),
String::from_str(&env, "USDC"),
);

if token2.address < token1.address {
Expand Down Expand Up @@ -234,7 +234,7 @@ fn factory_fails_to_init_lp_when_no_whitelisted_accounts() {
env.mock_all_auths();
env.budget().reset_unlimited();

let factory = FactoryClient::new(&env, &env.register_contract(None, Factory {}));
let factory = FactoryClient::new(&env, &env.register(Factory, ()));
let multihop_wasm_hash = install_multihop_wasm(&env);
let whitelisted_accounts = vec![&env];

Expand Down Expand Up @@ -378,17 +378,17 @@ fn factory_stable_pool_creation_should_fail_early_without_amp() {

let mut token1 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "EURO Coin"),
&String::from_str(&env, "EURC"),
token_admin.clone(),
7,
String::from_str(&env, "EURO Coin"),
String::from_str(&env, "EURC"),
);
let mut token2 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "USD Coin"),
&String::from_str(&env, "USDC"),
token_admin.clone(),
7,
String::from_str(&env, "USD Coin"),
String::from_str(&env, "USDC"),
);

if token2.address < token1.address {
Expand Down Expand Up @@ -431,17 +431,17 @@ fn factory_create_xyk_pool_with_amp_parameter_should_still_succeed() {

let mut token1 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "Phoenix"),
&String::from_str(&env, "PHO"),
token_admin.clone(),
7,
String::from_str(&env, "Phoenix"),
String::from_str(&env, "PHO"),
);
let mut token2 = install_and_deploy_token_contract(
&env,
&token_admin.clone(),
&7,
&String::from_str(&env, "USD Coin"),
&String::from_str(&env, "USDC"),
token_admin.clone(),
7,
String::from_str(&env, "USD Coin"),
String::from_str(&env, "USDC"),
);

if token2.address < token1.address {
Expand Down
27 changes: 9 additions & 18 deletions contracts/factory/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use crate::{
token_contract,
};
use phoenix::utils::{LiquidityPoolInitInfo, StakeInitInfo, TokenInitInfo};
use soroban_sdk::{testutils::Address as _, vec, xdr::ToXdr, Address, Bytes, BytesN, Env, String};
use soroban_sdk::{testutils::Address as _, vec, Address, BytesN, Env, String};
pub const ONE_DAY: u64 = 86400;
const TOKEN_WASM: &[u8] =
include_bytes!("../../../../target/wasm32-unknown-unknown/release/soroban_token_contract.wasm");

#[allow(clippy::too_many_arguments)]
pub mod lp_contract {
Expand Down Expand Up @@ -60,7 +62,7 @@ pub fn deploy_factory_contract<'a>(
admin: impl Into<Option<Address>>,
) -> FactoryClient<'a> {
let admin = admin.into().unwrap_or(Address::generate(env));
let factory = FactoryClient::new(env, &env.register_contract(None, Factory {}));
let factory = FactoryClient::new(env, &env.register(Factory, ()));
let multihop_wasm_hash = install_multihop_wasm(env);
let whitelisted_accounts = vec![env, admin.clone()];

Expand Down Expand Up @@ -114,24 +116,13 @@ pub fn generate_lp_init_info(

pub fn install_and_deploy_token_contract<'a>(
env: &Env,
admin: &Address,
decimal: &u32,
name: &String,
symbol: &String,
admin: Address,
decimal: u32,
name: String,
symbol: String,
) -> token_contract::Client<'a> {
let token_wasm = install_token_wasm(env);

let mut salt = Bytes::new(env);
salt.append(&name.clone().to_xdr(env));
let salt = env.crypto().sha256(&salt);
let token_addr = env
.deployer()
.with_address(admin.clone(), salt)
.deploy(token_wasm);

let token_addr = env.register(TOKEN_WASM, (admin, decimal, name, symbol));
let token_client = token_contract::Client::new(env, &token_addr);

token_client.initialize(admin, decimal, name, symbol);

token_client
}
6 changes: 4 additions & 2 deletions contracts/factory/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub fn deploy_lp_contract(
salt.append(&token_b.to_xdr(env));
let salt = env.crypto().sha256(&salt);

env.deployer().with_current_contract(salt).deploy(wasm_hash)
env.deployer()
.with_current_contract(salt)
.deploy_v2(wasm_hash, ())
}

pub fn deploy_and_initialize_multihop_contract(
Expand All @@ -26,7 +28,7 @@ pub fn deploy_and_initialize_multihop_contract(
let multihop_address = env
.deployer()
.with_current_contract(salt)
.deploy(multihop_wasm_hash);
.deploy_v2(multihop_wasm_hash, ());

let init_fn = Symbol::new(&env, "initialize");
let init_args: Vec<Val> = (admin, env.current_contract_address()).into_val(&env);
Expand Down
2 changes: 1 addition & 1 deletion contracts/multihop/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_deploy_multihop_twice_should_fail() {

let admin = Address::generate(&env);

let multihop = MultihopClient::new(&env, &env.register_contract(None, Multihop {}));
let multihop = MultihopClient::new(&env, &env.register(Multihop, ()));
let factory = deploy_factory_contract(&env, admin.clone());
multihop.initialize(&admin, &factory);
multihop.initialize(&admin, &factory);
Expand Down
15 changes: 9 additions & 6 deletions contracts/multihop/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use soroban_sdk::{
testutils::{arbitrary::std, Address as _},
Address, Bytes, BytesN, Env,
};
use soroban_sdk::{vec, IntoVal, String};
use soroban_sdk::{vec, String};
pub fn create_token_contract_with_metadata<'a>(
env: &Env,
admin: &Address,
Expand All @@ -15,9 +15,10 @@ pub fn create_token_contract_with_metadata<'a>(
symbol: String,
amount: i128,
) -> token_contract::Client<'a> {
let token =
token_contract::Client::new(env, &env.register_contract_wasm(None, token_contract::WASM));
token.initialize(admin, &decimals, &name.into_val(env), &symbol.into_val(env));
let token = token_contract::Client::new(
env,
&env.register(token_contract::WASM, (admin, decimals, name, symbol)),
);
token.mint(admin, &amount);
token
}
Expand Down Expand Up @@ -63,7 +64,9 @@ pub fn deploy_factory_contract(e: &Env, admin: Address) -> Address {
let salt = Bytes::new(e);
let salt = e.crypto().sha256(&salt);

e.deployer().with_address(admin, salt).deploy(factory_wasm)
e.deployer()
.with_address(admin, salt)
.deploy_v2(factory_wasm, ())
}

pub fn deploy_multihop_contract<'a>(
Expand All @@ -73,7 +76,7 @@ pub fn deploy_multihop_contract<'a>(
) -> MultihopClient<'a> {
let admin = admin.into().unwrap_or(Address::generate(env));

let multihop = MultihopClient::new(env, &env.register_contract(None, Multihop {}));
let multihop = MultihopClient::new(env, &env.register(Multihop, ()));

multihop.initialize(&admin, factory);
multihop
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fmt:
cargo fmt --all

clippy: build
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets -- -D warnings -A clippy::too_many_arguments

clean:
cargo clean
25 changes: 11 additions & 14 deletions contracts/pool/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use soroban_sdk::{
contract, contractimpl, contractmeta, log, panic_with_error, Address, BytesN, Env, IntoVal,
String, U256,
contract, contractimpl, contractmeta, log, panic_with_error, Address, BytesN, Env, String, U256,
};

use num_integer::Roots;
Expand Down Expand Up @@ -215,18 +214,16 @@ impl LiquidityPoolTrait for LiquidityPool {
panic_with_error!(&env, ContractError::TokenABiggerThanTokenB);
}

// deploy token contract
let share_token_address =
utils::deploy_token_contract(&env, token_wasm_hash, &token_a, &token_b);
token_contract::Client::new(&env, &share_token_address).initialize(
// admin
&env.current_contract_address(),
// number of decimals on the share token
&share_token_decimals,
// name
&share_token_name.into_val(&env),
// symbol
&share_token_symbol.into_val(&env),
// deploy and initialize token contract
let share_token_address = utils::deploy_token_contract(
&env,
token_wasm_hash.clone(),
&token_a,
&token_b,
env.current_contract_address(),
share_token_decimals,
share_token_name,
share_token_symbol,
);

let stake_contract_address = utils::deploy_stake_contract(&env, stake_wasm_hash);
Expand Down
23 changes: 15 additions & 8 deletions contracts/pool/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,28 @@ pub struct SimulateReverseSwapResponse {
}

pub mod utils {
use soroban_sdk::String;

use super::*;

#[allow(clippy::too_many_arguments)]
pub fn deploy_token_contract(
e: &Env,
env: &Env,
token_wasm_hash: BytesN<32>,
token_a: &Address,
token_b: &Address,
admin: Address,
decimals: u32,
name: String,
symbol: String,
) -> Address {
let mut salt = Bytes::new(e);
salt.append(&token_a.to_xdr(e));
salt.append(&token_b.to_xdr(e));
let salt = e.crypto().sha256(&salt);
e.deployer()
let mut salt = Bytes::new(env);
salt.append(&token_a.clone().to_xdr(env));
salt.append(&token_b.clone().to_xdr(env));
let salt = env.crypto().sha256(&salt);
env.deployer()
.with_current_contract(salt)
.deploy(token_wasm_hash)
.deploy_v2(token_wasm_hash, (admin, decimals, name, symbol))
}

pub fn deploy_stake_contract(e: &Env, stake_wasm_hash: BytesN<32>) -> Address {
Expand All @@ -203,7 +210,7 @@ pub mod utils {

e.deployer()
.with_current_contract(salt)
.deploy(stake_wasm_hash)
.deploy_v2(stake_wasm_hash, ())
}

pub fn save_admin(e: &Env, address: Address) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/pool/src/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn test_initialize_with_bigger_first_token_should_fail() {
std::mem::swap(&mut token1, &mut token2);
}

let pool = LiquidityPoolClient::new(&env, &env.register_contract(None, LiquidityPool {}));
let pool = LiquidityPoolClient::new(&env, &env.register(LiquidityPool, ()));
let fee_recipient = Address::generate(&env);

let token_init_info = TokenInitInfo {
Expand Down Expand Up @@ -454,7 +454,7 @@ fn test_initialize_with_maximum_allowed_swap_fee_bps_over_the_cap_should_fail()
std::mem::swap(&mut token1, &mut token2);
}

let pool = LiquidityPoolClient::new(&env, &env.register_contract(None, LiquidityPool {}));
let pool = LiquidityPoolClient::new(&env, &env.register(LiquidityPool, ()));
let fee_recipient = Address::generate(&env);

let token_init_info = TokenInitInfo {
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn deploy_liquidity_pool_contract<'a>(
stake_owner: Address,
) -> LiquidityPoolClient<'a> {
let admin = admin.into().unwrap_or(Address::generate(env));
let pool = LiquidityPoolClient::new(env, &env.register_contract(None, LiquidityPool {}));
let pool = LiquidityPoolClient::new(env, &env.register(LiquidityPool, ()));
let fee_recipient = fee_recipient
.into()
.unwrap_or_else(|| Address::generate(env));
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/src/tests/stake_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn second_pool_deployment_should_fail() {
std::mem::swap(&mut admin1, &mut admin2);
}

let pool = LiquidityPoolClient::new(&env, &env.register_contract(None, LiquidityPool {}));
let pool = LiquidityPoolClient::new(&env, &env.register(LiquidityPool, ()));

let token_wasm_hash = install_token_wasm(&env);
let stake_wasm_hash = install_stake_wasm(&env);
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool_stable/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fmt:
cargo fmt --all

clippy: build
cargo clippy --all-targets -- -D warnings
cargo clippy --all-targets -- -D warnings -A clippy::too_many_arguments

clean:
cargo clean
Loading

0 comments on commit ddf8a1e

Please sign in to comment.