Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions contracts/swapper/osmosis/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mars_osmosis::helpers::{query_arithmetic_twap_price, query_pool, CommonPoolD
use mars_red_bank_types::swapper::EstimateExactInSwapResponse;
use mars_swapper_base::{ContractError, ContractResult, Route};
use osmosis_std::types::osmosis::gamm::v1beta1::MsgSwapExactAmountIn;
pub use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
pub use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute as OsmosisSwapAmountInRoute;

use crate::helpers::hashset;

Expand All @@ -16,6 +16,17 @@ const TWAP_WINDOW_SIZE_SECONDS: u64 = 600u64;
#[cw_serde]
pub struct OsmosisRoute(pub Vec<SwapAmountInRoute>);

/// SwapAmountInRoute instead of using `osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute`
/// to keep consistency for pool_id representation as u64.
///
/// SwapAmountInRoute from osmosis package uses as_str serializer/deserializer, so it expects pool_id
/// as a String, but JSON schema doesn't correctly represent it.
#[cw_serde]
pub struct SwapAmountInRoute {
pub pool_id: u64,
pub token_out_denom: String,
}

impl fmt::Display for OsmosisRoute {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = self
Expand Down Expand Up @@ -118,9 +129,17 @@ impl Route<Empty, Empty> for OsmosisRoute {
let out_amount = query_out_amount(querier, &env.block, coin_in, steps)?;
let min_out_amount = (Decimal::one() - slippage) * out_amount;

let routes: Vec<_> = steps
.iter()
.map(|step| OsmosisSwapAmountInRoute {
pool_id: step.pool_id,
token_out_denom: step.token_out_denom.clone(),
})
.collect();

let swap_msg: CosmosMsg = MsgSwapExactAmountIn {
sender: env.contract.address.to_string(),
routes: steps.to_vec(),
routes,
token_in: Some(osmosis_std::types::cosmos::base::v1beta1::Coin {
denom: coin_in.denom.clone(),
amount: coin_in.amount.to_string(),
Expand Down
3 changes: 1 addition & 2 deletions contracts/swapper/osmosis/tests/test_enumerate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::collections::HashMap;
use cosmwasm_std::coin;
use cw_it::osmosis_test_tube::{Gamm, Module, OsmosisTestApp, SigningAccount, Wasm};
use mars_red_bank_types::swapper::{ExecuteMsg, QueryMsg, RouteResponse};
use mars_swapper_osmosis::route::OsmosisRoute;
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use mars_swapper_osmosis::route::{OsmosisRoute, SwapAmountInRoute};

use crate::helpers::instantiate_contract;

Expand Down
4 changes: 3 additions & 1 deletion schemas/mars-swapper-osmosis/mars-swapper-osmosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
]
},
"SwapAmountInRoute": {
"description": "SwapAmountInRoute instead of using `osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute` to keep consistency for pool_id representation as u64.\n\nSwapAmountInRoute from osmosis package uses as_str serializer/deserializer, so it expects pool_id as a String, but JSON schema doesn't correctly represent it.",
"type": "object",
"required": [
"pool_id",
Expand All @@ -246,7 +247,8 @@
"token_out_denom": {
"type": "string"
}
}
},
"additionalProperties": false
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
Expand Down
14 changes: 7 additions & 7 deletions scripts/deploy/addresses/osmo-test-5.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"address-provider": "osmo1xlf93me2979mvgj0gmluzuw22zxwd9rt2jaafzymw7d8kghkhwsqlwgh2r",
"red-bank": "osmo1r9ks824qewvpa9sqgzs3w2ylxx582c6d0hrnzqf3csufchqneydq60hgrv",
"incentives": "osmo1uq2y7h5sw8xtzhluhh7m9l3h9jdv5zjz7jhvavc3sgq0ps8ggq9s39qgcf",
"oracle": "osmo1vae2gsgeqw8q2x5ycvcrspsuqrnydveqgca03v8k9p4uvl2fgdlqp5r8fc",
"rewards-collector": "osmo1uw8g8mxlfk4at27xq26vqzttddtae7fgup4sd59ndrh0ymk99prsezh896",
"swapper": "osmo1q97xatqr3c0zrlgck60yd6f6nqvvtcg5772pngthzrkmdxkc6kqqdj56v2",
"params": "osmo1et0qv7acfv0wv3wlqmjtyflw5dectct24nuwjeqdkfzm9fznfunste0hnc"
"address-provider": "osmo1sm42690a2836cy0ufzaffvsc5e29xagm267ef7jm7acn82f7f4nsh320uv",
"red-bank": "osmo1hs4sm0fah9rk4mz8e56v4n76g0q9fffdkkjm3f8tjagkdx78pqcq75pk0a",
"incentives": "osmo1nu0k6g294jela67vyth6nwr3l42gutq2m07pg9927f7v7tuv0d4sre9fr7",
"oracle": "osmo1dxu93scjdnx42txdp9d4hm3snffvnzmkp4jpc9sml8xlu3ncgamsl2lx58",
"rewards-collector": "osmo1q8gsh9ugl68yx03as3se8w7yegzcpdggy56zxt0mxsjxjvsggyqqedj03f",
"swapper": "osmo1ee9cq8dcknmw43znznx6vuupx5ku0tt505agccgaz5gn48mhe45s3kwwfm",
"params": "osmo1h334tvddn82m4apm08rm9k6kt32ws7vy0c4n30ngrvu6h6yxh8eq9l9jfh"
}
79 changes: 69 additions & 10 deletions scripts/deploy/base/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ import { InstantiateMsg as ParamsInstantiateMsg } from '../../types/generated/ma
import { ExecuteMsg as ParamsExecuteMsg } from '../../types/generated/mars-params/MarsParams.types'
import {
InstantiateMsg as RedBankInstantiateMsg,
ExecuteMsg as RedBankExecuteMsg,
QueryMsg as RedBankQueryMsg,
} from '../../types/generated/mars-red-bank/MarsRedBank.types'
import { InstantiateMsg as AddressProviderInstantiateMsg } from '../../types/generated/mars-address-provider/MarsAddressProvider.types'
import {
AddressResponseItem,
InstantiateMsg as AddressProviderInstantiateMsg,
} from '../../types/generated/mars-address-provider/MarsAddressProvider.types'
import { InstantiateMsg as IncentivesInstantiateMsg } from '../../types/generated/mars-incentives/MarsIncentives.types'
import { InstantiateMsg as RewardsInstantiateMsg } from '../../types/generated/mars-rewards-collector-base/MarsRewardsCollectorBase.types'
import {
Expand Down Expand Up @@ -217,6 +221,40 @@ export class Deployer {
printYellow(`${assetConfig.symbol} updated.`)
}

async initializeMarket(assetConfig: AssetConfig) {
if (this.storage.execute.marketsUpdated.includes(assetConfig.denom)) {
printBlue(`${assetConfig.symbol} already initialized in red-bank contract`)
return
}
printBlue(`Initializing ${assetConfig.symbol}...`)

const msg: RedBankExecuteMsg = {
init_asset: {
denom: assetConfig.denom,
params: {
reserve_factor: assetConfig.reserve_factor,
interest_rate_model: {
optimal_utilization_rate: assetConfig.interest_rate_model.optimal_utilization_rate,
base: assetConfig.interest_rate_model.base,
slope_1: assetConfig.interest_rate_model.slope_1,
slope_2: assetConfig.interest_rate_model.slope_2,
},
},
},
}

await this.client.execute(
this.deployerAddress,
this.storage.addresses['red-bank']!,
msg,
'auto',
)

printYellow(`${assetConfig.symbol} initialized`)

this.storage.execute.marketsUpdated.push(assetConfig.denom)
}

async updateVaultConfig(vaultConfig: VaultConfig) {
if (this.storage.execute.vaultsUpdated.includes(vaultConfig.addr)) {
printBlue(`${vaultConfig.symbol} already updated in Params contract`)
Expand Down Expand Up @@ -273,38 +311,42 @@ export class Deployer {

async updateAddressProvider() {
printBlue('Updating addresses in Address Provider...')
const addressesToSet = [
const addressesToSet: AddressResponseItem[] = [
{
address: this.storage.addresses['rewards-collector']!,
address_type: 'rewards_collector',
address: this.storage.addresses['rewards-collector'],
},
{
address: this.storage.addresses.incentives!,
address_type: 'incentives',
address: this.storage.addresses.incentives,
},
{
address: this.storage.addresses.oracle!,
address_type: 'oracle',
address: this.storage.addresses.oracle,
},
{
address: this.storage.addresses['red-bank']!,
address_type: 'red_bank',
address: this.storage.addresses['red-bank'],
},
{
address_type: 'fee_collector',
address: this.config.feeCollectorAddr,
address_type: 'fee_collector',
},
{
address_type: 'safety_fund',
address: this.config.safetyFundAddr,
address_type: 'safety_fund',
},
{
address_type: 'protocol_admin',
address: this.config.protocolAdminAddr,
address_type: 'protocol_admin',
},
{
address: this.storage.addresses.swapper!,
address_type: 'swapper',
address: this.storage.addresses.swapper,
},
{
address: this.storage.addresses.params!,
address_type: 'params',
},
]

Expand Down Expand Up @@ -635,6 +677,23 @@ export class Deployer {
assert.equal(swapperConfig.proposed, this.config.multisigAddr)
}

async updateParamsContractOwner() {
const msg = {
update_owner: {
propose_new_owner: {
proposed: this.storage.owner,
},
},
}
await this.client.execute(this.deployerAddress, this.storage.addresses.params!, msg, 'auto')
printYellow('Owner updated to Mutlisig for Params')
const paramsConfig = (await this.client.queryContractSmart(this.storage.addresses.params!, {
owner: {},
})) as { proposed: string }

assert.equal(paramsConfig.proposed, this.config.multisigAddr)
}

async updateAddressProviderContractOwner() {
const msg = {
update_owner: {
Expand Down
5 changes: 4 additions & 1 deletion scripts/deploy/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const taskRunner = async (config: DeploymentConfig) => {
`mars_rewards_collector_${config.rewardsCollectorName}.wasm`,
)
await deployer.upload('swapper', `mars_swapper_${config.swapperDexName}.wasm`)
await deployer.upload('params', `mars_params.wasm`)

// Instantiate contracts
deployer.setOwnerAddr()
Expand All @@ -32,9 +33,10 @@ export const taskRunner = async (config: DeploymentConfig) => {
await deployer.saveDeploymentAddrsToFile()

// setup
await deployer.updateAddressProvider()
await deployer.updateAddressProvider() // CreditManager address in address-provider should be set once known
for (const asset of config.assets) {
await deployer.updateAssetParams(asset)
await deployer.initializeMarket(asset)
}
for (const vault of config.vaults) {
await deployer.updateVaultConfig(vault)
Expand All @@ -59,6 +61,7 @@ export const taskRunner = async (config: DeploymentConfig) => {
await deployer.updateOracleContractOwner()
await deployer.updateRewardsContractOwner()
await deployer.updateSwapperContractOwner()
await deployer.updateParamsContractOwner()
await deployer.updateAddressProviderContractOwner()
printGreen('It is confirmed that all contracts have transferred ownership to the Multisig')
} else {
Expand Down
7 changes: 6 additions & 1 deletion scripts/deploy/base/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export class Storage implements StorageItems {
return new this(chainId, {
addresses: {},
codeIds: {},
execute: { assetsUpdated: [], vaultsUpdated: [], addressProviderUpdated: {} },
execute: {
assetsUpdated: [],
marketsUpdated: [],
vaultsUpdated: [],
addressProviderUpdated: {},
},
})
}
}
Expand Down
42 changes: 21 additions & 21 deletions scripts/deploy/neutron/config_mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,6 @@ export const ntrnAsset: AssetConfig = {
},
protocol_liquidation_fee: '0.5',
// liquidation_bonus: '0.15',
// reserve_factor: '0.1',
// interest_rate_model: {
// optimal_utilization_rate: '0.6',
// base: '0',
// slope_1: '0.15',
// slope_2: '3',
// },
symbol: 'NTRN',
credit_manager: {
whitelisted: false,
Expand All @@ -293,6 +286,13 @@ export const ntrnAsset: AssetConfig = {
deposit_enabled: true,
},
deposit_cap: '5000000000000',
reserve_factor: '0.1',
interest_rate_model: {
optimal_utilization_rate: '0.6',
base: '0',
slope_1: '0.15',
slope_2: '3',
},
}

export const atomAsset: AssetConfig = {
Expand All @@ -307,13 +307,6 @@ export const atomAsset: AssetConfig = {
},
protocol_liquidation_fee: '0.5',
// liquidation_bonus: '0.1',
// reserve_factor: '0.1',
// interest_rate_model: {
// optimal_utilization_rate: '0.7',
// base: '0',
// slope_1: '0.2',
// slope_2: '3',
// },
symbol: 'ATOM',
credit_manager: {
whitelisted: false,
Expand All @@ -323,6 +316,13 @@ export const atomAsset: AssetConfig = {
deposit_enabled: true,
},
deposit_cap: '150000000000',
reserve_factor: '0.1',
interest_rate_model: {
optimal_utilization_rate: '0.7',
base: '0',
slope_1: '0.2',
slope_2: '3',
},
}

export const axlUSDCAsset: AssetConfig = {
Expand All @@ -337,13 +337,6 @@ export const axlUSDCAsset: AssetConfig = {
},
protocol_liquidation_fee: '0.5',
// liquidation_bonus: '0.1',
// reserve_factor: '0.1',
// interest_rate_model: {
// optimal_utilization_rate: '0.8',
// base: '0',
// slope_1: '0.125',
// slope_2: '2',
// },
symbol: 'axlUSDC',
credit_manager: {
whitelisted: false,
Expand All @@ -353,6 +346,13 @@ export const axlUSDCAsset: AssetConfig = {
deposit_enabled: true,
},
deposit_cap: '500000000000',
reserve_factor: '0.1',
interest_rate_model: {
optimal_utilization_rate: '0.8',
base: '0',
slope_1: '0.125',
slope_2: '2',
},
}

export const neutronMainnetConfig: DeploymentConfig = {
Expand Down
Loading