Skip to content

Commit 647d66c

Browse files
Merge pull request #76 from Trustless-Work/refactor/fix-repeated-parameters
Refactor/fix repeated parameters
2 parents ee0da5b + 09c2d8b commit 647d66c

File tree

8 files changed

+77
-67
lines changed

8 files changed

+77
-67
lines changed

apps/smart-contracts/contracts/deployer/src/deployer.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub struct DeployAllParams {
2323
pub vault_salt: BytesN<32>,
2424
pub token_name: String,
2525
pub token_symbol: String,
26-
pub escrow_id: String,
2726
pub decimal: u32,
2827
pub escrow_contract: Address,
2928
pub vault_admin: Address,
@@ -75,15 +74,15 @@ impl DeployerContract {
7574
/// * `salt` - Unique salt for deterministic address derivation
7675
/// * `name` - Token name
7776
/// * `symbol` - Token symbol
78-
/// * `escrow_id` - Escrow contract ID (immutable after init)
77+
/// * `escrow_contract` - Escrow contract address (immutable after init)
7978
/// * `decimal` - Token decimals (max 18)
8079
/// * `mint_authority` - Address authorized to mint tokens
8180
pub fn deploy_participation_token(
8281
env: Env,
8382
salt: BytesN<32>,
8483
name: String,
8584
symbol: String,
86-
escrow_id: String,
85+
escrow_contract: Address,
8786
decimal: u32,
8887
mint_authority: Address,
8988
) -> Address {
@@ -99,7 +98,7 @@ impl DeployerContract {
9998
let constructor_args: Vec<Val> = (
10099
name,
101100
symbol,
102-
escrow_id,
101+
escrow_contract,
103102
decimal,
104103
mint_authority,
105104
)
@@ -225,7 +224,7 @@ impl DeployerContract {
225224
// Step 1: Deploy token-sale with deployer as temporary admin
226225
// (allows deployer to call set_token and set_admin in steps 3-4)
227226
let token_sale_args: Vec<Val> = (
228-
params.escrow_contract,
227+
params.escrow_contract.clone(),
229228
deployer_addr.clone(),
230229
params.hard_cap,
231230
params.max_per_investor,
@@ -240,7 +239,7 @@ impl DeployerContract {
240239
let participation_token_args: Vec<Val> = (
241240
params.token_name,
242241
params.token_symbol,
243-
params.escrow_id,
242+
params.escrow_contract,
244243
params.decimal,
245244
token_sale_addr.clone(),
246245
)

apps/smart-contracts/contracts/deployer/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ fn test_deploy_participation_token() {
5151
let deployer = setup_deployer(&env, &admin);
5252

5353
let salt = BytesN::from_array(&env, &[1u8; 32]);
54+
let escrow_contract = Address::generate(&env);
5455

5556
let token_addr = deployer.deploy_participation_token(
5657
&salt,
5758
&String::from_str(&env, "TestToken"),
5859
&String::from_str(&env, "TST"),
59-
&String::from_str(&env, "escrow-001"),
60+
&escrow_contract,
6061
&7u32,
6162
&mint_authority,
6263
);
@@ -130,7 +131,6 @@ fn test_deploy_all() {
130131
vault_salt,
131132
token_name: String::from_str(&env, "CampaignToken"),
132133
token_symbol: String::from_str(&env, "CAMP"),
133-
escrow_id: String::from_str(&env, "escrow-001"),
134134
decimal: 7u32,
135135
escrow_contract,
136136
vault_admin,

apps/smart-contracts/contracts/participation-token/src/contract.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use crate::allowance::{read_allowance, spend_allowance, write_allowance};
55
use crate::balance::{read_balance, receive_balance, spend_balance};
66
use crate::metadata::{
7-
read_decimal, read_escrow_id, read_mint_authority, read_name, read_symbol,
8-
write_escrow_id, write_mint_authority, write_metadata,
7+
read_decimal, read_escrow_contract, read_mint_authority, read_name, read_symbol,
8+
write_escrow_contract, write_mint_authority, write_metadata,
99
};
1010
use crate::storage_types::{INSTANCE_BUMP_AMOUNT, INSTANCE_LIFETIME_THRESHOLD};
1111
use soroban_sdk::{
@@ -32,14 +32,14 @@ impl Token {
3232
/// # Arguments
3333
/// * `name` - Token name
3434
/// * `symbol` - Token symbol
35-
/// * `escrow_id` - Escrow contract ID (as String)
35+
/// * `escrow_contract` - Escrow contract address
3636
/// * `decimal` - Token decimals (default: 7, max: 18)
3737
/// * `mint_authority` - Address authorized to mint tokens (Participation Token contract)
3838
pub fn __constructor(
3939
e: Env,
4040
name: String,
4141
symbol: String,
42-
escrow_id: String,
42+
escrow_contract: Address,
4343
decimal: u32,
4444
mint_authority: Address,
4545
) {
@@ -57,9 +57,9 @@ impl Token {
5757
},
5858
);
5959

60-
// Write immutable metadata (escrow_id, mint_authority)
60+
// Write immutable metadata (escrow_contract, mint_authority)
6161
// These functions will panic if called twice (immutability enforced)
62-
write_escrow_id(&e, &escrow_id);
62+
write_escrow_contract(&e, &escrow_contract);
6363
write_mint_authority(&e, &mint_authority);
6464
}
6565

@@ -202,13 +202,13 @@ impl TokenInterface for Token {
202202
// Additional getters for T-REX-aligned metadata
203203
#[contractimpl]
204204
impl Token {
205-
/// Get the escrow contract ID associated with this token.
205+
/// Get the escrow contract address associated with this token.
206206
/// This is immutable metadata set at initialization.
207-
pub fn escrow_id(e: Env) -> String {
207+
pub fn escrow_contract(e: Env) -> Address {
208208
e.storage()
209209
.instance()
210210
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
211-
read_escrow_id(&e)
211+
read_escrow_contract(&e)
212212
}
213213

214214
/// Transfer the mint authority to a new admin address.

apps/smart-contracts/contracts/participation-token/src/metadata.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ pub fn write_metadata(e: &Env, metadata: TokenMetadata) {
2424
util.metadata().set_metadata(&metadata);
2525
}
2626

27-
// Immutable metadata (escrow_id, mint_authority) - set only once at initialization
28-
pub fn read_escrow_id(e: &Env) -> String {
29-
let key = DataKey::EscrowId;
27+
// Immutable metadata (escrow_contract, mint_authority) - set only once at initialization
28+
pub fn read_escrow_contract(e: &Env) -> Address {
29+
let key = DataKey::EscrowContract;
3030
e.storage()
3131
.instance()
3232
.get(&key)
33-
.expect("Escrow ID not initialized")
33+
.expect("Escrow contract not initialized")
3434
}
3535

36-
pub fn write_escrow_id(e: &Env, escrow_id: &String) {
37-
let key = DataKey::EscrowId;
36+
pub fn write_escrow_contract(e: &Env, escrow_contract: &Address) {
37+
let key = DataKey::EscrowContract;
3838
// Check if already set (immutable - can only be set once)
3939
if e.storage().instance().has(&key) {
40-
panic!("Escrow ID already set - cannot modify");
40+
panic!("Escrow contract already set - cannot modify");
4141
}
42-
e.storage().instance().set(&key, escrow_id);
42+
e.storage().instance().set(&key, escrow_contract);
4343
}
4444

4545
pub fn read_mint_authority(e: &Env) -> Address {

apps/smart-contracts/contracts/participation-token/src/storage_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pub enum DataKey {
2727
Balance(Address),
2828
State(Address),
2929
// Immutable metadata keys (set only once at initialization)
30-
EscrowId,
30+
EscrowContract,
3131
MintAuthority,
3232
}

0 commit comments

Comments
 (0)