Skip to content

Commit

Permalink
Merge pull request #220 from blend-capital/pool-name-string
Browse files Browse the repository at this point in the history
chore: swap symbol for string in pool name
  • Loading branch information
mootz12 authored Apr 19, 2024
2 parents 143eeb4 + 9f4dc32 commit 732df4b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 37 deletions.
7 changes: 4 additions & 3 deletions mocks/mock-pool-factory/src/pool_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::{
PoolFactoryError,
};
use soroban_sdk::{
contract, contractimpl, panic_with_error, vec, Address, BytesN, Env, IntoVal, Symbol, Val, Vec,
contract, contractimpl, panic_with_error, vec, Address, BytesN, Env, IntoVal, String, Symbol,
Val, Vec,
};

use pool::PoolContract;
Expand All @@ -28,7 +29,7 @@ pub trait MockPoolFactoryTrait {
fn deploy(
e: Env,
admin: Address,
name: Symbol,
name: String,
salt: BytesN<32>,
oracle: Address,
backstop_take_rate: u32,
Expand Down Expand Up @@ -62,7 +63,7 @@ impl MockPoolFactoryTrait for MockPoolFactory {
fn deploy(
e: Env,
admin: Address,
name: Symbol,
name: String,
_salt: BytesN<32>,
oracle: Address,
backstop_take_rate: u32,
Expand Down
6 changes: 3 additions & 3 deletions pool-factory/src/pool_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use soroban_sdk::{
contract, contractclient, contractimpl, panic_with_error, vec, Address, Bytes, BytesN, Env,
IntoVal, Symbol, Val, Vec,
IntoVal, String, Symbol, Val, Vec,
};

const SCALAR_7: u32 = 1_0000000;
Expand Down Expand Up @@ -32,7 +32,7 @@ pub trait PoolFactory {
fn deploy(
e: Env,
admin: Address,
name: Symbol,
name: String,
salt: BytesN<32>,
oracle: Address,
backstop_take_rate: u32,
Expand Down Expand Up @@ -64,7 +64,7 @@ impl PoolFactory for PoolFactoryContract {
fn deploy(
e: Env,
admin: Address,
name: Symbol,
name: String,
salt: BytesN<32>,
oracle: Address,
backstop_take_rate: u32,
Expand Down
14 changes: 7 additions & 7 deletions pool-factory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use soroban_sdk::{
testutils::{Address as _, BytesN as _, Events},
vec, Address, BytesN, Env, IntoVal, Symbol,
vec, Address, BytesN, Env, IntoVal, String, Symbol,
};

use crate::{PoolFactoryClient, PoolFactoryContract, PoolInitMeta};
Expand Down Expand Up @@ -44,8 +44,8 @@ fn test_pool_factory() {
let result = pool_factory_client.try_initialize(&pool_init_meta);
assert!(result.is_err());

let name1 = Symbol::new(&e, "pool1");
let name2 = Symbol::new(&e, "pool2");
let name1 = String::from_str(&e, "pool1");
let name2 = String::from_str(&e, "pool2");
let salt = BytesN::<32>::random(&e);

let deployed_pool_address_1 = pool_factory_client.deploy(
Expand Down Expand Up @@ -146,7 +146,7 @@ fn test_pool_factory_invalid_pool_init_args_backstop_rate() {
let backstop_rate: u32 = 1_0000000;
let max_positions: u32 = 6;

let name1 = Symbol::new(&e, "pool1");
let name1 = String::from_str(&e, "pool1");
let salt = BytesN::<32>::random(&e);

pool_factory_client.deploy(
Expand Down Expand Up @@ -184,7 +184,7 @@ fn test_pool_factory_invalid_pool_init_args_max_positions() {
let backstop_rate: u32 = 0_1000000;
let max_positions: u32 = 1;

let name1 = Symbol::new(&e, "pool1");
let name1 = String::from_str(&e, "pool1");
let salt = BytesN::<32>::random(&e);

pool_factory_client.deploy(
Expand Down Expand Up @@ -223,8 +223,8 @@ fn test_pool_factory_frontrun_protection() {
};
pool_factory_client.initialize(&pool_init_meta);

let name1 = Symbol::new(&e, "pool1");
let name2 = Symbol::new(&e, "pool_front_run");
let name1 = String::from_str(&e, "pool1");
let name2 = String::from_str(&e, "pool_front_run");
let salt = BytesN::<32>::random(&e);

// verify two different users don't get the same pool address with the same
Expand Down
6 changes: 3 additions & 3 deletions pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
pool::{self, Positions, Request},
storage::{self, ReserveConfig},
};
use soroban_sdk::{contract, contractclient, contractimpl, Address, Env, Symbol, Vec};
use soroban_sdk::{contract, contractclient, contractimpl, Address, Env, String, Symbol, Vec};

/// ### Pool
///
Expand All @@ -31,7 +31,7 @@ pub trait Pool {
fn initialize(
e: Env,
admin: Address,
name: Symbol,
name: String,
oracle: Address,
bstop_rate: u32,
max_positions: u32,
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Pool for PoolContract {
fn initialize(
e: Env,
admin: Address,
name: Symbol,
name: String,
oracle: Address,
bstop_rate: u32,
max_postions: u32,
Expand Down
12 changes: 6 additions & 6 deletions pool/src/pool/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
self, has_queued_reserve_set, PoolConfig, QueuedReserveInit, ReserveConfig, ReserveData,
},
};
use soroban_sdk::{panic_with_error, Address, Env, Symbol};
use soroban_sdk::{panic_with_error, Address, Env, String};

use super::pool::Pool;

Expand All @@ -16,7 +16,7 @@ use super::pool::Pool;
pub fn execute_initialize(
e: &Env,
admin: &Address,
name: &Symbol,
name: &String,
oracle: &Address,
bstop_rate: &u32,
max_positions: &u32,
Expand Down Expand Up @@ -195,7 +195,7 @@ mod tests {
let pool = testutils::create_pool(&e);

let admin = Address::generate(&e);
let name = Symbol::new(&e, "pool_name");
let name = String::from_str(&e, "pool_name");
let oracle = Address::generate(&e);
let bstop_rate: u32 = 0_1000000;
let max_positions = 2;
Expand Down Expand Up @@ -231,7 +231,7 @@ mod tests {
let pool = testutils::create_pool(&e);

let admin = Address::generate(&e);
let name = Symbol::new(&e, "pool_name");
let name = String::from_str(&e, "pool_name");
let oracle = Address::generate(&e);
let bstop_rate: u32 = 0_1000000;
let max_positions = 3;
Expand Down Expand Up @@ -270,7 +270,7 @@ mod tests {
let pool = testutils::create_pool(&e);

let admin = Address::generate(&e);
let name = Symbol::new(&e, "pool_name");
let name = String::from_str(&e, "pool_name");
let oracle = Address::generate(&e);
let bstop_rate = 1_0000000;
let max_positions = 3;
Expand Down Expand Up @@ -298,7 +298,7 @@ mod tests {
let pool = testutils::create_pool(&e);

let admin = Address::generate(&e);
let name = Symbol::new(&e, "pool_name");
let name = String::from_str(&e, "pool_name");
let oracle = Address::generate(&e);
let bstop_rate = 0_1000000;
let max_positions = 1;
Expand Down
6 changes: 3 additions & 3 deletions pool/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use soroban_sdk::{
contracttype, map, panic_with_error, unwrap::UnwrapOptimized, vec, Address, Env, IntoVal, Map,
Symbol, TryFromVal, Val, Vec,
String, Symbol, TryFromVal, Val, Vec,
};

use crate::{auctions::AuctionData, pool::Positions, PoolError};
Expand Down Expand Up @@ -251,10 +251,10 @@ pub fn set_admin(e: &Env, new_admin: &Address) {
///
/// ### Arguments
/// * `name` - The Name of the pool
pub fn set_name(e: &Env, name: &Symbol) {
pub fn set_name(e: &Env, name: &String) {
e.storage()
.instance()
.set::<Symbol, Symbol>(&Symbol::new(e, NAME_KEY), name);
.set::<Symbol, String>(&Symbol::new(e, NAME_KEY), name);
}

/********** Backstop **********/
Expand Down
4 changes: 2 additions & 2 deletions test-suites/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pool::{Request, RequestType, ReserveEmissionMetadata};
use soroban_sdk::{testutils::Address as _, vec as svec, Address, Symbol, Vec as SVec};
use soroban_sdk::{testutils::Address as _, vec as svec, Address, String, Vec as SVec};

use crate::{
pool::default_reserve_metadata,
Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> {
);

// create pool
fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0_1000000, 6);
fixture.create_pool(String::from_str(&fixture.env, "Teapot"), 0_1000000, 6);

let mut stable_config = default_reserve_metadata();
stable_config.decimals = 6;
Expand Down
4 changes: 2 additions & 2 deletions test-suites/src/test_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use pool_factory::{PoolFactoryClient, PoolInitMeta};
use sep_40_oracle::testutils::{Asset, MockPriceOracleClient};
use sep_41_token::testutils::MockTokenClient;
use soroban_sdk::testutils::{Address as _, BytesN as _, Ledger, LedgerInfo};
use soroban_sdk::{vec as svec, Address, BytesN, Env, Map, Symbol};
use soroban_sdk::{vec as svec, Address, BytesN, Env, Map, String, Symbol};

pub const SCALAR_7: i128 = 1_000_0000;
pub const SCALAR_9: i128 = 1_000_000_000;
Expand Down Expand Up @@ -166,7 +166,7 @@ impl TestFixture<'_> {
fixture
}

pub fn create_pool(&mut self, name: Symbol, backstop_take_rate: u32, max_positions: u32) {
pub fn create_pool(&mut self, name: String, backstop_take_rate: u32, max_positions: u32) {
let pool_id = self.pool_factory.deploy(
&self.bombadil,
&name,
Expand Down
4 changes: 2 additions & 2 deletions test-suites/tests/test_backstop_inflation_attack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

use soroban_sdk::{testutils::Address as _, vec, Address, Error, Symbol};
use soroban_sdk::{testutils::Address as _, vec, Address, Error, String};
use test_suites::{
pool::default_reserve_metadata,
test_fixture::{TestFixture, TokenIndex, SCALAR_7},
Expand All @@ -15,7 +15,7 @@ fn test_backstop_inflation_attack() {
let pippen = Address::generate(&fixture.env);

// create pool with 1 new reserve
fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0, 6);
fixture.create_pool(String::from_str(&fixture.env, "Teapot"), 0, 6);

let xlm_config = default_reserve_metadata();
fixture.create_pool_reserve(0, TokenIndex::XLM, &xlm_config);
Expand Down
4 changes: 2 additions & 2 deletions test-suites/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use emitter::Swap;
use pool::{Request, RequestType, ReserveEmissionMetadata};
use soroban_sdk::{
testutils::{Address as _, Events},
vec as svec, Address, IntoVal, Symbol, Vec as SVec,
vec as svec, Address, IntoVal, String, Symbol, Vec as SVec,
};
use test_suites::{
create_fixture_with_data,
Expand Down Expand Up @@ -40,7 +40,7 @@ fn test_emitter_no_reward_zone() {
);

// create pool
fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0_1000000, 6);
fixture.create_pool(String::from_str(&fixture.env, "Teapot"), 0_1000000, 6);

let mut stable_config = default_reserve_metadata();
stable_config.decimals = 6;
Expand Down
4 changes: 2 additions & 2 deletions test-suites/tests/test_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pool::{Request, RequestType, ReserveEmissionMetadata};
use soroban_fixed_point_math::FixedPoint;
use soroban_sdk::{
testutils::{Address as _, AuthorizedFunction, AuthorizedInvocation, Events},
vec, Address, IntoVal, Symbol, Val,
vec, Address, IntoVal, String, Symbol, Val,
};
use test_suites::{
assertions::assert_approx_eq_abs,
Expand Down Expand Up @@ -542,7 +542,7 @@ fn test_pool_config() {
// Verify initialize can't be run again
let result = pool_fixture.pool.try_initialize(
&Address::generate(&fixture.env),
&Symbol::new(&fixture.env, "teapot"),
&String::from_str(&fixture.env, "Teapot"),
&Address::generate(&fixture.env),
&10000,
&4,
Expand Down
4 changes: 2 additions & 2 deletions test-suites/tests/test_pool_inflation_attack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(test)]

use pool::{Request, RequestType};
use soroban_sdk::{testutils::Address as _, vec, Address, Symbol};
use soroban_sdk::{testutils::Address as _, vec, Address, String};
use test_suites::{
pool::default_reserve_metadata,
test_fixture::{TestFixture, TokenIndex, SCALAR_7},
Expand All @@ -16,7 +16,7 @@ fn test_pool_inflation_attack() {
let pippen = Address::generate(&fixture.env);

// create pool with 1 new reserve
fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0, 6);
fixture.create_pool(String::from_str(&fixture.env, "Teapot"), 0, 6);

let xlm_config = default_reserve_metadata();
fixture.create_pool_reserve(0, TokenIndex::XLM, &xlm_config);
Expand Down

0 comments on commit 732df4b

Please sign in to comment.