From 9f4dc32e00d98e84f853c3b8cc76368802f71007 Mon Sep 17 00:00:00 2001 From: mootz12 Date: Fri, 19 Apr 2024 09:03:25 -0400 Subject: [PATCH] chore: swap symbol for string in pool name --- mocks/mock-pool-factory/src/pool_factory.rs | 7 ++++--- pool-factory/src/pool_factory.rs | 6 +++--- pool-factory/src/test.rs | 14 +++++++------- pool/src/contract.rs | 6 +++--- pool/src/pool/config.rs | 12 ++++++------ pool/src/storage.rs | 6 +++--- test-suites/src/setup.rs | 4 ++-- test-suites/src/test_fixture.rs | 4 ++-- .../tests/test_backstop_inflation_attack.rs | 4 ++-- test-suites/tests/test_emitter.rs | 4 ++-- test-suites/tests/test_pool.rs | 4 ++-- test-suites/tests/test_pool_inflation_attack.rs | 4 ++-- 12 files changed, 38 insertions(+), 37 deletions(-) diff --git a/mocks/mock-pool-factory/src/pool_factory.rs b/mocks/mock-pool-factory/src/pool_factory.rs index 233f882e..d7a0f653 100644 --- a/mocks/mock-pool-factory/src/pool_factory.rs +++ b/mocks/mock-pool-factory/src/pool_factory.rs @@ -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; @@ -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, @@ -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, diff --git a/pool-factory/src/pool_factory.rs b/pool-factory/src/pool_factory.rs index c282e01f..a07900c0 100644 --- a/pool-factory/src/pool_factory.rs +++ b/pool-factory/src/pool_factory.rs @@ -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; @@ -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, @@ -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, diff --git a/pool-factory/src/test.rs b/pool-factory/src/test.rs index acdfa473..1f8c2d02 100644 --- a/pool-factory/src/test.rs +++ b/pool-factory/src/test.rs @@ -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}; @@ -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( @@ -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( @@ -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( @@ -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 diff --git a/pool/src/contract.rs b/pool/src/contract.rs index d0566c60..1041f053 100644 --- a/pool/src/contract.rs +++ b/pool/src/contract.rs @@ -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 /// @@ -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, @@ -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, diff --git a/pool/src/pool/config.rs b/pool/src/pool/config.rs index acec63e6..7d1da91a 100644 --- a/pool/src/pool/config.rs +++ b/pool/src/pool/config.rs @@ -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; @@ -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, @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/pool/src/storage.rs b/pool/src/storage.rs index cb9947d8..38f64392 100644 --- a/pool/src/storage.rs +++ b/pool/src/storage.rs @@ -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}; @@ -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::new(e, NAME_KEY), name); + .set::(&Symbol::new(e, NAME_KEY), name); } /********** Backstop **********/ diff --git a/test-suites/src/setup.rs b/test-suites/src/setup.rs index 3912cb06..6c62b0fb 100644 --- a/test-suites/src/setup.rs +++ b/test-suites/src/setup.rs @@ -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, @@ -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; diff --git a/test-suites/src/test_fixture.rs b/test-suites/src/test_fixture.rs index 5e96a179..59b9104f 100644 --- a/test-suites/src/test_fixture.rs +++ b/test-suites/src/test_fixture.rs @@ -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; @@ -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, diff --git a/test-suites/tests/test_backstop_inflation_attack.rs b/test-suites/tests/test_backstop_inflation_attack.rs index 799aa601..7af555ec 100644 --- a/test-suites/tests/test_backstop_inflation_attack.rs +++ b/test-suites/tests/test_backstop_inflation_attack.rs @@ -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}, @@ -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); diff --git a/test-suites/tests/test_emitter.rs b/test-suites/tests/test_emitter.rs index dee2c598..7b3e8cd4 100644 --- a/test-suites/tests/test_emitter.rs +++ b/test-suites/tests/test_emitter.rs @@ -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, @@ -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; diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 384aeba8..c8a14e91 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -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, @@ -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, diff --git a/test-suites/tests/test_pool_inflation_attack.rs b/test-suites/tests/test_pool_inflation_attack.rs index efa2a142..14b7fb95 100644 --- a/test-suites/tests/test_pool_inflation_attack.rs +++ b/test-suites/tests/test_pool_inflation_attack.rs @@ -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}, @@ -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);