Skip to content

Commit

Permalink
Mp 3015 add in build scripts for mars params contract (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
brimigs authored and pacmanifold committed Jul 19, 2023
1 parent 3eb8b60 commit 2a564bf
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 469 deletions.
2 changes: 1 addition & 1 deletion contracts/oracle/base/src/pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn query_pyth_price_for_default(
return Err(InvalidPrice {
reason: "price can't be <= 0".to_string(),
});
};
}

let current_price_dec = scale_to_exponent(current_price.price as u128, current_price.expo)?;
let ema_price_dec = scale_to_exponent(ema_price.price as u128, ema_price.expo)?;
Expand Down
12 changes: 7 additions & 5 deletions scripts/deploy/addresses/osmo-test-5.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"address-provider": "osmo1wlm6dc0vnncu2v5z26rv97plmlkmalm84uwqatrlftc4gmp8ahgqs6r4py",
"red-bank": "osmo1dl4rylasnd7mtfzlkdqn2gr0ss4gvyykpvr6d7t5ylzf6z535n9s5jjt8u",
"incentives": "osmo1zyz57xf82963mcsgqu3hq5y0h9mrltm4ttq2qe5mjth9ezp3375qe0sm7d",
"oracle": "osmo1khe29uw3t85nmmp3mtr8dls7v2qwsfk3tndu5h4w5g2r5tzlz5qqarq2e2",
"rewards-collector": "osmo1u5pcjue4grmg8lh7xrz2nvpy79xlzknwqkczfkyeyx9zzzj76tpq4tgrcs"
"address-provider": "osmo1xlf93me2979mvgj0gmluzuw22zxwd9rt2jaafzymw7d8kghkhwsqlwgh2r",
"red-bank": "osmo1r9ks824qewvpa9sqgzs3w2ylxx582c6d0hrnzqf3csufchqneydq60hgrv",
"incentives": "osmo1uq2y7h5sw8xtzhluhh7m9l3h9jdv5zjz7jhvavc3sgq0ps8ggq9s39qgcf",
"oracle": "osmo1vae2gsgeqw8q2x5ycvcrspsuqrnydveqgca03v8k9p4uvl2fgdlqp5r8fc",
"rewards-collector": "osmo1uw8g8mxlfk4at27xq26vqzttddtae7fgup4sd59ndrh0ymk99prsezh896",
"swapper": "osmo1q97xatqr3c0zrlgck60yd6f6nqvvtcg5772pngthzrkmdxkc6kqqdj56v2",
"params": "osmo1et0qv7acfv0wv3wlqmjtyflw5dectct24nuwjeqdkfzm9fznfunste0hnc"
}
111 changes: 69 additions & 42 deletions scripts/deploy/base/deployer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AssetConfig, DeploymentConfig, OracleConfig, isAstroportRoute } from '../../types/config'
import {
AssetConfig,
DeploymentConfig,
OracleConfig,
isAstroportRoute,
VaultConfig,
} from '../../types/config'
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import * as fs from 'fs'
import { printBlue, printGreen, printRed, printYellow } from '../../utils/chalk'
Expand All @@ -12,6 +18,7 @@ import { SwapperExecuteMsg } from '../../types/config'
import { InstantiateMsg as AstroportSwapperInstantiateMsg } from '../../types/generated/mars-swapper-astroport/MarsSwapperAstroport.types'
import { InstantiateMsg as OsmosisSwapperInstantiateMsg } from '../../types/generated/mars-swapper-osmosis/MarsSwapperOsmosis.types'
import { InstantiateMsg as ParamsInstantiateMsg } from '../../types/generated/mars-params/MarsParams.types'
import { ExecuteMsg as ParamsExecuteMsg } from '../../types/generated/mars-params/MarsParams.types'
import {
InstantiateMsg as RedBankInstantiateMsg,
QueryMsg as RedBankQueryMsg,
Expand Down Expand Up @@ -52,7 +59,7 @@ export class Deployer {
Number(accountBalance.amount) / 1e6
} ${this.config.chainPrefix})`,
)
if (Number(accountBalance.amount) < 1_000_000 && this.config.chainId === 'osmo-test-4') {
if (Number(accountBalance.amount) < 1_000_000 && this.config.chainId === 'osmo-test-5') {
printRed(
`not enough ${this.config.chainPrefix} tokens to complete action, you may need to go to a test faucet to get more tokens.`,
)
Expand Down Expand Up @@ -173,6 +180,66 @@ export class Deployer {
await this.instantiate('params', this.storage.codeIds.params!, msg)
}

async updateAssetParams(assetConfig: AssetConfig) {
if (this.storage.execute.assetsUpdated.includes(assetConfig.denom)) {
printBlue(`${assetConfig.symbol} already updated in Params contract`)
return
}
printBlue(`Updating ${assetConfig.symbol}...`)

const msg: ParamsExecuteMsg = {
update_asset_params: {
add_or_update: {
params: {
credit_manager: {
hls: assetConfig.credit_manager.hls,
whitelisted: assetConfig.credit_manager.whitelisted,
},
denom: assetConfig.denom,
liquidation_bonus: assetConfig.liquidation_bonus,
liquidation_threshold: assetConfig.liquidation_threshold,
protocol_liquidation_fee: assetConfig.protocol_liquidation_fee,
max_loan_to_value: assetConfig.max_loan_to_value,
red_bank: {
borrow_enabled: assetConfig.red_bank.borrow_enabled,
deposit_enabled: assetConfig.red_bank.borrow_enabled,
deposit_cap: assetConfig.red_bank.deposit_cap,
},
},
},
},
}

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

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

async updateVaultConfig(vaultConfig: VaultConfig) {
if (this.storage.execute.vaultsUpdated.includes(vaultConfig.addr)) {
printBlue(`${vaultConfig.symbol} already updated in Params contract`)
return
}
printBlue(`Updating ${vaultConfig.symbol}...`)

const msg: ParamsExecuteMsg = {
update_vault_config: {
add_or_update: {
config: {
addr: vaultConfig.addr,
deposit_cap: vaultConfig.deposit_cap,
liquidation_threshold: vaultConfig.liquidation_threshold,
whitelisted: vaultConfig.whitelisted,
max_loan_to_value: vaultConfig.max_loan_to_value,
},
},
},
}

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

printYellow(`${vaultConfig.symbol} updated.`)
}
async setRoutes() {
printBlue('Setting Swapper Routes')
for (const route of this.config.swapRoutes) {
Expand Down Expand Up @@ -256,46 +323,6 @@ export class Deployer {
printGreen('Address Provider update completed')
}

async initializeAsset(assetConfig: AssetConfig) {
if (this.storage.execute.assetsInitialized.includes(assetConfig.denom)) {
printBlue(`${assetConfig.symbol} already initialized.`)
return
}
printBlue(`Initializing ${assetConfig.symbol}...`)

const msg = {
init_asset: {
denom: assetConfig.denom,
params: {
max_loan_to_value: assetConfig.max_loan_to_value,
reserve_factor: assetConfig.reserve_factor,
liquidation_threshold: assetConfig.liquidation_threshold,
liquidation_bonus: assetConfig.liquidation_bonus,
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,
},
deposit_cap: assetConfig.deposit_cap,
deposit_enabled: assetConfig.deposit_enabled,
borrow_enabled: assetConfig.borrow_enabled,
},
},
}

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

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

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

async recordTwapSnapshots(denoms: string[]) {
const msg: WasmOracleExecuteMsg = {
custom: {
Expand Down
7 changes: 5 additions & 2 deletions scripts/deploy/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ export const taskRunner = async (config: DeploymentConfig) => {

// setup
await deployer.updateAddressProvider()
await deployer.setRoutes()
for (const asset of config.assets) {
await deployer.initializeAsset(asset)
await deployer.updateAssetParams(asset)
}
for (const vault of config.vaults) {
await deployer.updateVaultConfig(vault)
}
await deployer.setRoutes()
for (const oracleConfig of config.oracleConfigs) {
await deployer.setOracle(oracleConfig)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy/base/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Storage implements StorageItems {
return new this(chainId, {
addresses: {},
codeIds: {},
execute: { assetsInitialized: [], addressProviderUpdated: {} },
execute: { assetsUpdated: [], vaultsUpdated: [], addressProviderUpdated: {} },
})
}
}
Expand Down
91 changes: 52 additions & 39 deletions scripts/deploy/neutron/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeploymentConfig, AssetConfig, OracleConfig } from '../../types/config'
import { AssetConfig, OracleConfig } from '../../types/config'

const axlUSDCTestnet = 'ibc/EFB00E728F98F0C4BBE8CA362123ACAB466EDA2826DC6837E49F4C1902F21BBA' // TODO: This is actually ASTRO since there is no pool for axlUSDC on testnet
const atomTestnet = 'ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9'
Expand All @@ -7,62 +7,74 @@ const protocolAdminAddrTestnet = 'neutron1ke0vqqzyymlp5esr8gjwuzh94ysnpvj8er5hm7
const astroportFactoryTestnet = 'neutron1jj0scx400pswhpjes589aujlqagxgcztw04srynmhf0f6zplzn2qqmhwj7'
const astroportRouterTestnet = 'neutron12jm24l9lr9cupufqjuxpdjnnweana4h66tsx5cl800mke26td26sq7m05p'

// note the following three addresses are all 'mars' bech32 prefix
// note the following addresses are all 'mars' bech32 prefix
const safetyFundAddr = 'mars1s4hgh56can3e33e0zqpnjxh0t5wdf7u3pze575'
const feeCollectorAddr = 'mars17xpfvakm2amg962yls6f84z3kell8c5ldy6e7x'

export const ntrnAsset: AssetConfig = {
credit_manager: {
whitelisted: true,
},
symbol: 'NTRM',
denom: 'untrn',
max_loan_to_value: '0.59',
reserve_factor: '0.2',
liquidation_bonus: {
max_lb: '0.05',
min_lb: '0',
slope: '2',
starting_lb: '0',
},
protocol_liquidation_fee: '0.5',
liquidation_threshold: '0.61',
liquidation_bonus: '0.15',
interest_rate_model: {
optimal_utilization_rate: '0.6',
base: '0',
slope_1: '0.15',
slope_2: '3',
max_loan_to_value: '0.59',
red_bank: {
borrow_enabled: true,
deposit_cap: '2500000000000',
deposit_enabled: true,
},
deposit_cap: '2500000000000',
deposit_enabled: true,
borrow_enabled: true,
symbol: 'NTRN',
}

export const atomAsset: AssetConfig = {
credit_manager: {
whitelisted: true,
},
symbol: 'ATOM',
denom: atomTestnet,
max_loan_to_value: '0.68',
reserve_factor: '0.2',
liquidation_bonus: {
max_lb: '0.05',
min_lb: '0',
slope: '2',
starting_lb: '0',
},
protocol_liquidation_fee: '0.5',
liquidation_threshold: '0.7',
liquidation_bonus: '0.15',
interest_rate_model: {
optimal_utilization_rate: '0.6',
base: '0',
slope_1: '0.15',
slope_2: '3',
max_loan_to_value: '0.68',
red_bank: {
borrow_enabled: true,
deposit_cap: '100000000000',
deposit_enabled: true,
},
deposit_cap: '100000000000',
deposit_enabled: true,
borrow_enabled: true,
symbol: 'ATOM',
}

export const axlUSDCAsset: AssetConfig = {
denom: axlUSDCTestnet,
max_loan_to_value: '0.74',
reserve_factor: '0.2',
liquidation_threshold: '0.75',
liquidation_bonus: '0.1',
interest_rate_model: {
optimal_utilization_rate: '0.8',
base: '0',
slope_1: '0.2',
slope_2: '2',
credit_manager: {
whitelisted: true,
},
deposit_cap: '500000000000',
deposit_enabled: true,
borrow_enabled: true,
symbol: 'axlUSDC',
liquidation_bonus: {
max_lb: '0.05',
min_lb: '0',
slope: '2',
starting_lb: '0',
},
protocol_liquidation_fee: '0.5',
liquidation_threshold: '0.75',
max_loan_to_value: '0.74',
red_bank: {
borrow_enabled: true,
deposit_cap: '500000000000',
deposit_enabled: true,
},
}

export const ntrnOracleTestnet: OracleConfig = {
Expand Down Expand Up @@ -98,7 +110,7 @@ export const axlUSDCOracleTestnet: OracleConfig = {
},
}

export const neutronTestnetConfig: DeploymentConfig = {
export const neutronTestnetConfig = {
oracleName: 'wasm',
atomDenom: atomTestnet,
baseAssetDenom: 'untrn',
Expand Down Expand Up @@ -200,6 +212,7 @@ export const neutronTestnetConfig: DeploymentConfig = {
feeCollectorAddr: feeCollectorAddr,
swapperDexName: 'astroport',
assets: [ntrnAsset, atomAsset],
vaults: [],
oracleConfigs: [axlUSDCOracleTestnet, ntrnOracleTestnet, atomOracleTestnet],
targetHealthFactor: '1.2',
oracleCustomInitParams: {
Expand Down
Loading

0 comments on commit 2a564bf

Please sign in to comment.