Skip to content

Commit

Permalink
router upgrade pair endpoint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Jun 11, 2024
1 parent c3d54f0 commit a235b6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 51 deletions.
19 changes: 1 addition & 18 deletions dex/router/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ pub trait Router:
&self,
first_token_id: TokenIdentifier,
second_token_id: TokenIdentifier,
initial_liquidity_adder: ManagedAddress,
total_fee_percent_requested: u64,
special_fee_percent_requested: u64,
) {
require!(self.is_active(), "Not active");

Expand All @@ -175,21 +172,7 @@ pub trait Router:
let pair_address = self.get_pair(first_token_id.clone(), second_token_id.clone());
require!(!pair_address.is_zero(), "Pair does not exists");

require!(
total_fee_percent_requested >= special_fee_percent_requested
&& total_fee_percent_requested < MAX_TOTAL_FEE_PERCENT,
"Bad percents"
);

self.upgrade_pair(
pair_address,
&first_token_id,
&second_token_id,
&self.owner().get(),
&initial_liquidity_adder,
total_fee_percent_requested,
special_fee_percent_requested,
);
self.upgrade_pair(pair_address);
}

#[payable("EGLD")]
Expand Down
36 changes: 10 additions & 26 deletions dex/router/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,16 @@ pub trait FactoryModule: config::ConfigModule + read_pair_storage::ReadPairStora
new_address
}

fn upgrade_pair(
&self,
pair_address: ManagedAddress,
first_token_id: &TokenIdentifier,
second_token_id: &TokenIdentifier,
owner: &ManagedAddress,
_initial_liquidity_adder: &ManagedAddress,
total_fee_percent: u64,
special_fee_percent: u64,
) {
self.pair_contract_deploy_proxy()
.contract(pair_address)
.init(
first_token_id,
second_token_id,
self.blockchain().get_sc_address(),
owner,
total_fee_percent,
special_fee_percent,
ManagedAddress::zero(),
MultiValueEncoded::new(),
)
.upgrade_from_source(
&self.pair_template_address().get(),
CodeMetadata::UPGRADEABLE | CodeMetadata::READABLE | CodeMetadata::PAYABLE_BY_SC,
);
fn upgrade_pair(&self, pair_address: ManagedAddress) {
let pair_template_address = self.pair_template_address().get();
let code_metadata =
CodeMetadata::UPGRADEABLE | CodeMetadata::READABLE | CodeMetadata::PAYABLE_BY_SC;
self.tx()
.to(pair_address)
.raw_upgrade()
.from_source(pair_template_address)
.code_metadata(code_metadata)
.upgrade_async_call_and_exit();
}

#[view(getAllPairsManagedAddresses)]
Expand Down
8 changes: 1 addition & 7 deletions dex/router/tests/router_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,7 @@ fn test_router_upgrade_pair() {
.execute_tx(&owner, &router_wrapper, &rust_zero, |sc| {
let first_token_id = managed_token_id!(CUSTOM_TOKEN_ID);
let second_token_id = managed_token_id!(USDC_TOKEN_ID);
sc.upgrade_pair_endpoint(
first_token_id,
second_token_id,
managed_address!(&user),
300,
50,
);
sc.upgrade_pair_endpoint(first_token_id, second_token_id);
})
.assert_ok();

Expand Down

0 comments on commit a235b6d

Please sign in to comment.