Skip to content

Commit

Permalink
Fix ibc transfer and update scripts (#175)
Browse files Browse the repository at this point in the history
* Fix IBC transfer params.

* Update deployment scripts.

* Update mainnet config.

* Update the mainnet config to have correct multisig addr

* downtime detector update

---------

Co-authored-by: dancreee <[email protected]>
Co-authored-by: brimigs <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2023
1 parent 710a6c7 commit 13fcc44
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 212 deletions.
16 changes: 2 additions & 14 deletions contracts/rewards-collector/base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::marker::PhantomData;

use cosmwasm_std::{
to_binary, Addr, Binary, Coin, CosmosMsg, CustomMsg, CustomQuery, Deps, DepsMut, Env, IbcMsg,
IbcTimeout, IbcTimeoutBlock, MessageInfo, Order, Response, StdResult, Uint128, WasmMsg,
IbcTimeout, MessageInfo, Order, Response, StdResult, Uint128, WasmMsg,
};
use cw_storage_plus::{Bound, Item, Map};
use mars_owner::{Owner, OwnerInit::SetInitialOwner, OwnerUpdate};
Expand Down Expand Up @@ -156,8 +156,6 @@ where
safety_fund_denom,
fee_collector_denom,
channel_id,
timeout_revision,
timeout_blocks,
timeout_seconds,
slippage_tolerance,
} = new_cfg;
Expand All @@ -168,8 +166,6 @@ where
cfg.safety_fund_denom = safety_fund_denom.unwrap_or(cfg.safety_fund_denom);
cfg.fee_collector_denom = fee_collector_denom.unwrap_or(cfg.fee_collector_denom);
cfg.channel_id = channel_id.unwrap_or(cfg.channel_id);
cfg.timeout_revision = timeout_revision.unwrap_or(cfg.timeout_revision);
cfg.timeout_blocks = timeout_blocks.unwrap_or(cfg.timeout_blocks);
cfg.timeout_seconds = timeout_seconds.unwrap_or(cfg.timeout_seconds);
cfg.slippage_tolerance = slippage_tolerance.unwrap_or(cfg.slippage_tolerance);

Expand Down Expand Up @@ -351,13 +347,7 @@ where
denom: denom.clone(),
amount: amount_to_distribute,
},
timeout: IbcTimeout::with_both(
IbcTimeoutBlock {
revision: cfg.timeout_revision,
height: env.block.height + cfg.timeout_blocks,
},
env.block.time.plus_seconds(cfg.timeout_seconds),
),
timeout: IbcTimeout::with_timestamp(env.block.time.plus_seconds(cfg.timeout_seconds)),
});

Ok(Response::new()
Expand All @@ -379,8 +369,6 @@ where
safety_fund_denom: cfg.safety_fund_denom,
fee_collector_denom: cfg.fee_collector_denom,
channel_id: cfg.channel_id,
timeout_revision: cfg.timeout_revision,
timeout_blocks: cfg.timeout_blocks,
timeout_seconds: cfg.timeout_seconds,
slippage_tolerance: cfg.slippage_tolerance,
})
Expand Down
2 changes: 0 additions & 2 deletions contracts/rewards-collector/osmosis/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub fn mock_instantiate_msg() -> InstantiateMsg {
safety_fund_denom: "uusdc".to_string(),
fee_collector_denom: "umars".to_string(),
channel_id: "channel-69".to_string(),
timeout_revision: 1,
timeout_blocks: 50,
timeout_seconds: 300,
slippage_tolerance: Decimal::percent(3),
}
Expand Down
50 changes: 0 additions & 50 deletions contracts/rewards-collector/osmosis/tests/test_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ fn instantiating() {
safety_fund_denom: config.safety_fund_denom,
fee_collector_denom: config.fee_collector_denom,
channel_id: config.channel_id,
timeout_revision: config.timeout_revision,
timeout_blocks: config.timeout_blocks,
timeout_seconds: config.timeout_seconds,
slippage_tolerance: config.slippage_tolerance,
}
Expand Down Expand Up @@ -123,54 +121,6 @@ fn updating_config() {
assert_eq!(cfg.safety_tax_rate, Decimal::percent(69));
}

#[test]
fn updating_config_if_invalid_timeout_revision() {
let mut deps = helpers::setup_test();

let invalid_cfg = UpdateConfig {
timeout_revision: Some(0),
..Default::default()
};

let info = mock_info("owner");
let msg = ExecuteMsg::UpdateConfig {
new_cfg: invalid_cfg,
};
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Validation(ValidationError::InvalidParam {
param_name: "timeout_revision".to_string(),
invalid_value: "0".to_string(),
predicate: "> 0".to_string(),
})
);
}

#[test]
fn updating_config_if_invalid_timeout_blocks() {
let mut deps = helpers::setup_test();

let invalid_cfg = UpdateConfig {
timeout_blocks: Some(0),
..Default::default()
};

let info = mock_info("owner");
let msg = ExecuteMsg::UpdateConfig {
new_cfg: invalid_cfg,
};
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
assert_eq!(
err,
ContractError::Validation(ValidationError::InvalidParam {
param_name: "timeout_blocks".to_string(),
invalid_value: "0".to_string(),
predicate: "> 0".to_string(),
})
);
}

#[test]
fn updating_config_if_invalid_timeout_seconds() {
let mut deps = helpers::setup_test();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cosmwasm_std::{
coin, testing::mock_env, CosmosMsg, IbcMsg, IbcTimeout, IbcTimeoutBlock, SubMsg, Timestamp,
Uint128,
coin, testing::mock_env, CosmosMsg, IbcMsg, IbcTimeout, SubMsg, Timestamp, Uint128,
};
use mars_rewards_collector_base::ContractError;
use mars_rewards_collector_osmosis::{contract::entry::execute, msg::ExecuteMsg};
Expand Down Expand Up @@ -35,13 +34,7 @@ fn distributing_rewards() {
channel_id: "channel-69".to_string(),
to_address: "safety_fund".to_string(),
amount: coin(123, "uusdc"),
timeout: IbcTimeout::with_both(
IbcTimeoutBlock {
revision: 1,
height: 10050,
},
Timestamp::from_seconds(17000300)
)
timeout: IbcTimeout::with_timestamp(Timestamp::from_seconds(17000300))
}))
);

Expand All @@ -63,13 +56,7 @@ fn distributing_rewards() {
channel_id: "channel-69".to_string(),
to_address: "fee_collector".to_string(),
amount: coin(8964, "umars"),
timeout: IbcTimeout::with_both(
IbcTimeoutBlock {
revision: 1,
height: 10050,
},
Timestamp::from_seconds(17000300)
)
timeout: IbcTimeout::with_timestamp(Timestamp::from_seconds(17000300))
}))
);

Expand Down
2 changes: 0 additions & 2 deletions integration-tests/tests/test_oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,6 @@ fn setup_redbank(wasm: &Wasm<OsmosisTestApp>, signer: &SigningAccount) -> (Strin
safety_fund_denom: "uosmo".to_string(),
fee_collector_denom: "uosmo".to_string(),
channel_id: "channel-1".to_string(),
timeout_revision: 2,
timeout_blocks: 10,
timeout_seconds: 60,
slippage_tolerance: Decimal::new(Uint128::from(1u128)),
},
Expand Down
6 changes: 0 additions & 6 deletions integration-tests/tests/test_rewards_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ fn swapping_rewards() {
safety_fund_denom: safety_fund_denom.to_string(),
fee_collector_denom: fee_collector_denom.to_string(),
channel_id: "channel-1".to_string(),
timeout_revision: 2,
timeout_blocks: 10,
timeout_seconds: 60,
slippage_tolerance: Decimal::percent(1),
},
Expand Down Expand Up @@ -288,8 +286,6 @@ fn distribute_rewards_if_ibc_channel_invalid() {
safety_fund_denom: safety_fund_denom.to_string(),
fee_collector_denom: fee_collector_denom.to_string(),
channel_id: "".to_string(),
timeout_revision: 1,
timeout_blocks: 10,
timeout_seconds: 60,
slippage_tolerance: Decimal::percent(1),
},
Expand Down Expand Up @@ -330,8 +326,6 @@ fn distribute_rewards_if_ibc_channel_invalid() {
safety_fund_denom: None,
fee_collector_denom: None,
channel_id: Some("channel-1".to_string()),
timeout_revision: None,
timeout_blocks: None,
timeout_seconds: None,
slippage_tolerance: None,
},
Expand Down
2 changes: 0 additions & 2 deletions packages/testing/src/integration/mock_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,6 @@ impl MockEnvBuilder {
safety_fund_denom: self.safety_fund_denom.clone(),
fee_collector_denom: self.fee_collector_denom.clone(),
channel_id: "0".to_string(),
timeout_revision: 1,
timeout_blocks: 150,
timeout_seconds: 900,
slippage_tolerance: self.slippage_tolerance,
},
Expand Down
20 changes: 0 additions & 20 deletions packages/types/src/rewards_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub struct InstantiateMsg {
pub fee_collector_denom: String,
/// The channel ID of the mars hub
pub channel_id: String,
/// Revision number of Mars Hub's IBC client
pub timeout_revision: u64,
/// Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_blocks: u64,
/// Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_seconds: u64,
/// Maximum percentage of price movement (minimum amount you accept to receive during swap)
Expand All @@ -44,10 +40,6 @@ pub struct Config {
pub fee_collector_denom: String,
/// The channel ID of the mars hub
pub channel_id: String,
/// Revision number of Mars Hub's IBC client
pub timeout_revision: u64,
/// Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_blocks: u64,
/// Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_seconds: u64,
/// Maximum percentage of price movement (minimum amount you accept to receive during swap)
Expand All @@ -58,8 +50,6 @@ impl Config {
pub fn validate(&self) -> Result<(), ValidationError> {
decimal_param_le_one(self.safety_tax_rate, "safety_tax_rate")?;

integer_param_gt_zero(self.timeout_revision, "timeout_revision")?;
integer_param_gt_zero(self.timeout_blocks, "timeout_blocks")?;
integer_param_gt_zero(self.timeout_seconds, "timeout_seconds")?;

if self.slippage_tolerance > Decimal::percent(MAX_SLIPPAGE_TOLERANCE_PERCENTAGE) {
Expand All @@ -85,8 +75,6 @@ impl Config {
safety_fund_denom: msg.safety_fund_denom,
fee_collector_denom: msg.fee_collector_denom,
channel_id: msg.channel_id,
timeout_revision: msg.timeout_revision,
timeout_blocks: msg.timeout_blocks,
timeout_seconds: msg.timeout_seconds,
slippage_tolerance: msg.slippage_tolerance,
})
Expand All @@ -106,10 +94,6 @@ pub struct UpdateConfig {
pub fee_collector_denom: Option<String>,
/// The channel id of the mars hub
pub channel_id: Option<String>,
/// Revision number of Mars Hub's IBC light client
pub timeout_revision: Option<u64>,
/// Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_blocks: Option<u64>,
/// Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_seconds: Option<u64>,
/// Maximum percentage of price movement (minimum amount you accept to receive during swap)
Expand Down Expand Up @@ -179,10 +163,6 @@ pub struct ConfigResponse {
pub fee_collector_denom: String,
/// The channel ID of the mars hub
pub channel_id: String,
/// Revision number of Mars Hub's IBC client
pub timeout_revision: u64,
/// Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_blocks: u64,
/// Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received
pub timeout_seconds: u64,
/// Maximum percentage of price movement (minimum amount you accept to receive during swap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"safety_fund_denom",
"safety_tax_rate",
"slippage_tolerance",
"timeout_blocks",
"timeout_revision",
"timeout_seconds"
],
"properties": {
Expand Down Expand Up @@ -55,18 +53,6 @@
}
]
},
"timeout_blocks": {
"description": "Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"timeout_revision": {
"description": "Revision number of Mars Hub's IBC client",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"timeout_seconds": {
"description": "Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": "integer",
Expand Down Expand Up @@ -395,24 +381,6 @@
}
]
},
"timeout_blocks": {
"description": "Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"timeout_revision": {
"description": "Revision number of Mars Hub's IBC light client",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"timeout_seconds": {
"description": "Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": [
Expand Down Expand Up @@ -527,8 +495,6 @@
"safety_fund_denom",
"safety_tax_rate",
"slippage_tolerance",
"timeout_blocks",
"timeout_revision",
"timeout_seconds"
],
"properties": {
Expand Down Expand Up @@ -578,18 +544,6 @@
}
]
},
"timeout_blocks": {
"description": "Number of blocks after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"timeout_revision": {
"description": "Revision number of Mars Hub's IBC client",
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
"timeout_seconds": {
"description": "Number of seconds after which an IBC transfer is to be considered failed, if no acknowledgement is received",
"type": "integer",
Expand Down
10 changes: 5 additions & 5 deletions scripts/deploy/addresses/osmo-test-4.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"address-provider": "osmo1g58d73m4efy0rcv0svvxkyz7x2r43hdf033c66tax5qz6ah5aufs6jgzv8",
"red-bank": "osmo154cy3c8lek6eg84dlvsdrxk6dd5uugv6l85hxcq6nszdaq0n27rquqey26",
"incentives": "osmo1k6jf9lcwyq5q74lsn8z5h08dp4dmm2g7w920r5seda7p5209wy8qjdr6a0",
"oracle": "osmo1qpk6pw0x4urkwcx3txrjsughq2dvgrcjca9xsx3zdl7sg3qt6xkqprtpd9",
"rewards-collector": "osmo1n6f2unqhavdk7ddv9jrepur742zv627lpfc3yjgzpp6qzpewus9qqe30re"
"address-provider": "osmo17dyy6hyzzy6u5khy5lau7afa2y9kwknu0aprwqn8twndw2qhv8ls6msnjr",
"red-bank": "osmo1t0dl6r27phqetfu0geaxrng0u9zn8qgrdwztapt5xr32adtwptaq6vwg36",
"incentives": "osmo1zxs8fry3m8j94pqg7h4muunyx86en27cl0xgk76fc839xg2qnn6qtpjs48",
"oracle": "osmo1dqz2u3c8rs5e7w5fnchsr2mpzzsxew69wtdy0aq4jsd76w7upmsstqe0s8",
"rewards-collector": "osmo14kzsqw5tatdvwlkj383lgkh6gcdetwn7kfqm7488uargyy2lpucqsyv53j"
}
6 changes: 2 additions & 4 deletions scripts/deploy/base/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ export class Deployer {
owner: this.deployerAddress,
address_provider: this.storage.addresses['address-provider']!,
safety_tax_rate: this.config.safetyFundFeeShare,
safety_fund_denom: this.config.baseAssetDenom,
fee_collector_denom: this.config.baseAssetDenom,
safety_fund_denom: this.config.safetyFundDenom,
fee_collector_denom: this.config.feeCollectorDenom,
channel_id: this.config.channelId,
timeout_revision: this.config.timeoutRevision,
timeout_blocks: this.config.rewardCollectorTimeoutBlocks,
timeout_seconds: this.config.rewardCollectorTimeoutSeconds,
slippage_tolerance: this.config.slippage_tolerance,
}
Expand Down
Loading

0 comments on commit 13fcc44

Please sign in to comment.