Skip to content
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

Soroban sdk upgrade to stable #394

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.6.0"
soroban-token-sdk = "21.6.0"
soroban-sdk = "21.7.7"
soroban-token-sdk = "21.7.7"
test-case = "3.3"
pretty_assertions = "1.4.0"

Expand Down
7 changes: 4 additions & 3 deletions contracts/factory/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::{
error::ContractError,
stake_contract::StakedResponse,
storage::{
get_config, get_lp_vec, get_stable_wasm_hash, is_initialized, save_config, save_lp_vec,
save_lp_vec_with_tuple_as_key, save_stable_wasm_hash, set_initialized, Asset, Config,
LiquidityPoolInfo, LpPortfolio, PairTupleKey, StakePortfolio, StakedResponse,
UserPortfolio,
LiquidityPoolInfo, LpPortfolio, PairTupleKey, StakePortfolio, UserPortfolio,
},
utils::{deploy_and_initialize_multihop_contract, deploy_lp_contract},
ConvertVec,
};
use phoenix::{
ttl::{INSTANCE_BUMP_AMOUNT, INSTANCE_LIFETIME_THRESHOLD},
Expand Down Expand Up @@ -477,7 +478,7 @@ impl FactoryTrait for Factory {
if !stake_response.stakes.is_empty() {
stake_portfolio.push_back(StakePortfolio {
staking_contract: response.pool_response.stake_address,
stakes: stake_response.stakes,
stakes: stake_response.stakes.convert_vec(),
})
}
}
Expand Down
27 changes: 27 additions & 0 deletions contracts/factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,30 @@ pub mod token_contract {
file = "../../target/wasm32-unknown-unknown/release/soroban_token_contract.wasm"
);
}

#[allow(clippy::too_many_arguments)]
pub mod stake_contract {
soroban_sdk::contractimport!(
file = "../../target/wasm32-unknown-unknown/release/phoenix_stake.wasm"
);
}

pub trait ConvertVec<T, U> {
fn convert_vec(&self) -> soroban_sdk::Vec<U>;
}

impl ConvertVec<stake_contract::Stake, storage::Stake> for soroban_sdk::Vec<stake_contract::Stake> {
fn convert_vec(&self) -> soroban_sdk::Vec<storage::Stake> {
let env = self.env(); // Get the environment
let mut result = soroban_sdk::Vec::new(env);

for stake in self.iter() {
result.push_back(storage::Stake {
stake: stake.stake,
stake_timestamp: stake.stake_timestamp,
});
}

result
}
}
22 changes: 19 additions & 3 deletions contracts/stake/src/tests/bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use pretty_assertions::assert_eq;
use soroban_sdk::{
symbol_short,
testutils::{Address as _, AuthorizedFunction, AuthorizedInvocation, Ledger},
vec, Address, Env, IntoVal, Symbol,
vec, Address, Env, IntoVal, Symbol, Vec,
};

use super::setup::{deploy_staking_contract, deploy_token_contract};

use crate::{
contract::{Staking, StakingClient},
msg::ConfigResponse,
msg::{ConfigResponse, StakedResponse},
storage::{Config, Stake},
tests::setup::{ONE_DAY, ONE_WEEK},
};
Expand Down Expand Up @@ -380,9 +380,25 @@ fn pay_rewards_during_unbond() {
20_000
);
assert_eq!(reward_token.balance(&user), 0);

// we first have to withdraw_rewards _before_ unbonding
// as this messes up with the reward calculation
// if we unbond first then we get no rewards
staking.withdraw_rewards(&user);
assert_eq!(reward_token.balance(&user), 20_000);

// user bonded at timestamp 0
staking.unbond(&user, &staked, &0);
assert_eq!(reward_token.balance(&user), 20_000);
assert_eq!(lp_token.balance(&staking.address), 0);
assert_eq!(lp_token.balance(&user), 9000 + staked);
assert_eq!(
staking.query_staked(&user),
StakedResponse {
stakes: Vec::new(&env),
total_stake: 0i128,
last_reward_time: 6_912_000
}
);
}

#[should_panic(
Expand Down
2 changes: 1 addition & 1 deletion contracts/vesting/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test: build

build:
$(MAKE) -C ../token build || break;
cargo build --target wasm32-unknown-unknown --release
cargo build --all-features --target wasm32-unknown-unknown --release

lint: fmt clippy

Expand Down
Loading