Credit Manager
The Credit Manager Contract is the centerpiece of the Mars Protocol v2. It serves as a proxy between the user, the Red Bank, the liquidation engine, and the Perps contracts.
Deployments
Neutron: neutron1qdzn3l4kn7gsjna2tfpg3g3mwd6kunx4p50lfya59k02846xas6qslgs3r
Osmosis: osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf
Types
The types of the Credit Manager Contract can be found here.
For reference on the Queries and Methods:
type AccountKind =
| ('default' | 'high_levered_strategy')
| {
fund_manager: {
vault_addr: string
}
}
type ActionKind = 'default' | 'liquidation'
type Expiration =
| {
at_height: number
}
| {
at_time: Timestamp
}
| {
never: {}
}
type HealthState =
| 'healthy'
| {
unhealthy: {
max_ltv_health_factor: Decimal
}
}
type Int128 = string
type Uint128 = string
interface Coin {
amount: Uint128
denom: string
[k: string]: unknown
}
interface ActionCoin {
amount: 'account_balance' | { exact: Uint128 }
denom: string
}
Conditions
Conditions are used to create triggers for trigger orders. They are referenced as the Condition type in the Methods below.
health_factor
{
health_factor: {
comparison: 'greater_than' | 'less_than'
threshold: Decimal
}
}
oracle_price
{
oracle_price: {
comparison: 'greater_than' | 'less_than'
denom: string
price: Decimal
}
}
relative_price
{
relative_price: {
base_price_denom: string
comparison: 'greater_than' | 'less_than'
price: Decimal
quote_price_denom: string
}
}
Actions
A central part of the Credit Manager are the Actions. Actions can be combined into powerful sequences by lining them up in an array (they will be executed in a top to down maner). They are referenced via the Action type in the Methods below.
borrow
{
borrow: Coin
}
claim_astro_lp_rewards
{
claim_astro_lp_rewards: {
lp_denom: string
}
}
claim_rewards
{
claim_rewards: {}
}
create_trigger_order
{
create_trigger_order: {
actions: Action[]
conditions: Condition[]
keeper_fee: Coin
}
}
delete_trigger_order
{
delete_trigger_order: {
trigger_order_id: string
}
}
deposit
{
deposit: Coin
}
deposit_to_perp_vault
{
deposit_to_perp_vault: {
coin: ActionCoin
max_receivable_shares?: Uint128 | null
}
}
enter_vault
{
enter_vault: {
coin: ActionCoin
vault: string
}
}
execute_perp_order
{
execute_perp_order: {
denom: string
order_size: Int128
reduce_only?: boolean | null
}
}
exit_vault
{
exit_vault: {
amount: Uint128
vault: string
}
}
exit_vault_unlocked
{
exit_vault_unlocked: {
id: number
vault: VaultBaseForString
}
}
lend
{
lend: ActionCoin
}
liquidate
{
debt_coin: Coin
liquidatee_account_id: string
request: {
deposit: string
} | {
lend: string
} | {
vault: {
position_type: 'u_n_l_o_c_k_e_d' | 'l_o_c_k_e_d' | 'u_n_l_o_c_k_i_n_g'
request_vault: string
}
} | {
staked_astro_lp: string
}
}
provide_liquidity
{
provide_liquidity: {
coins_in: ActionCoin[]
lp_token_out: string
slippage: Decimal
}
}
reclaim
{
reclaim: ActionCoin
}
refund_all_coin_balances
{
refund_all_coin_balances: {}
}
repay
{
repay: {
coin: ActionCoin
recipient_account_id?: string | null
}
}
request_vault_unlock
{
request_vault_unlock: {
amount: Uint128
vault: string
}
}
stake_astro_lp
{
stake_astro_lp: {
lp_token: ActionCoin
}
}
swap_exact_in
swap_exact_in: {
coin_in: ActionCoin
denom_out: string
min_receive: Uint128
route?: {
astro: {
swaps: [
{
from: string
to: string
},
...
]
}
}
| {
osmo: {
swaps: [
{
pool_id: number
to: string
},
...
]
}
} | null
}
unlock_from_perp_vault
{
unlock_from_perp_vault: {
shares: Uint128
}
}
unstake_astro_lp
{
unstake_astro_lp: {
lp_token: ActionCoin
}
}
withdraw
{
withdraw: ActionCoin
}
withdraw_from_perp_vault
{
withdraw_from_perp_vault: {
min_receive?: Uint128 | null
}
}
withdraw_liquidity
{
withdraw_liquidity: {
lp_token: ActionCoin
slippage: Decimal
}
}
withdraw_to_wallet
{
withdraw_to_wallet: {
coin: ActionCoin
recipient: string
}
}
Queries
account_kind
Returns the AccountKind of a specific account_id.
{
account_kind: {
account_id: string
}
}
{
data: AccountKind
}
accounts
{
accounts: {
limit?: number | null
owner: string
start_after?: string | null
}
}
{
data: [
{
id: string
kind: AccountKind
},
...
]
}
all_account_trigger_orders
{
all_account_trigger_orders: {
account_id: string
limit?: number | null
start_after?: string | null
}
}
{
data: {
data: [
{
account_id: string
order: {
actions: Action[]
conditions: Condition[]
keeper_fee: Coin
order_id: string
}
},
...
]
metadata: {
has_more: boolean
}
}
}
all_coin_balances
{
all_coin_balances: {
limit?: number | null
start_after?: [string, string] | null
}
}
{
data: [
{
account_id: string
amount: Uint128
denom: string
},
...
]
}
all_debt_shares
{
all_debt_shares: {
limit?: number | null
start_after?: [string, string] | null
}
}
{
data: [
{
account_id: string
shares: Uint128
denom: string
},
...
]
}
all_total_debt_shares
{
all_total_debt_shares: {
limit?: number | null
start_after?: string | null
}
}
{
data: [
{
shares: Uint128
denom: string
},
...
]
}
all_trigger_orders
{
all_trigger_orders: {
limit?: number | null
start_after?: [string, string] | null
}
}
{
data: {
data: [
{
account_id: string
order: {
actions: Action[]
conditions: Condition[]
keeper_fee: Coin
order_id: string
}
},
...
]
metadata: {
has_more: boolean
}
}
}
all_vault_positions
{
all_vault_positions: {
limit?: number | null
start_after?: [string, string] | null
}
}
{
data: [
{
account_id: string
position: {
vault_position: {
amount: {
unlocked: string
} | {
locking: {
locked: string
unlocking: [
{
coin: Coin
id: number
},
...
]
}
}
vault: string
}
}
},
...
]
}
all_vault_utilizations
{
all_vault_utilizations: {
limit?: number | null
start_after?: string | null
}
}
{
data: {
data: [
{
utilization: Coin
vault: string
},
...
]
metadata: {
has_more: boolean
}
}
}
config
{
config: {}
}
{
data: {
account_nft?: string | null
health_contract: string
incentives: string
keeper_fee_config: {
min_fee: Coin
}
max_slippage: Decimal
max_unlocking_positions: Uint128
oracle: string
ownership: {
abolished: boolean
emergency_owner?: string | null
initialized: boolean
owner?: string | null
proposed?: string | null
}
params: string
perps: string
perps_liquidation_bonus_ratio: Decimal
red_bank: string
rewards_collector?: {
account_id: string
address: string
} | null
swapper: string
zapper: string
}
}
estimate_provide_liquidity
{
estimate_provide_liquidity: {
coins_in: Coin[]
lp_token_out: string
}
}
{
data: Uint128
}
estimate_withdraw_liquidity
{
estimate_withdraw_liquidity: {
lp_token: Coin
}
}
{
data: Coin[]
}
positions
{
positions: {
account_id: string
action?: ActionKind | null
}
}
{
data: {
account_id: string
account_kind: AccountKind
debts: [
{
amount: Uint128
denom: string
shares: Uint128
},
...
]
deposits: Coin[]
lends: Coin[]
perps: [
{
base_denom: string
current_exec_price: Decimal
current_price: Decimal
denom: string
entry_exec_price: Decimal
entry_price: Decimal
realized_pnl: {
accrued_funding: Int128
closing_fee: Int128
opening_fee: Int128
pnl: Int128
price_pnl: Int128
}
size: Int128
unrealized_pnl: {
accrued_funding: Int128
closing_fee: Int128
opening_fee: Int128
pnl: Int128
price_pnl: Int128
}
},
...
]
staked_astro_lps: Coin[]
vaults: [
{
amount: {
unlocked: string
} | {
locking: {
locked: string
unlocking: [
{
coin: Coin
id: number
},
...
]
}
}
vault: string
},
...
]
}
}
total_debt_shares
{
total_debt_shares: string
}
{
data: {
shares: Uint128
denom: string
}
}
vault_bindings
{
vault_bindings: {
limit?: number | null
start_after?: string | null
}
}
{
data: {
data: [
{
account_id: string
vault_address: string
},
...
]
metadata: {
has_more: boolean
}
}
}
vault_position_value
{
vault_position_value: {
vault_position: {
amount: {
unlocked: string
} | {
locking: {
locked: string
unlocking: [
{
coin: Coin
id: number
},
...
]
}
}
vault: string
}
}
}
{
data: {
base_coin: {
amount: Uint128
denom: string
value: Uint128
}
vault_coin: {
amount: Uint128
denom: string
value: Uint128
}
}
}
vault_utilization
{
vault_utilization: {
vault: string
}
}
{
data: {
utilization: Coin
vault: string
}
}
Methods
create_credit_account
{
create_credit_account: AccountKind
}
execute_trigger_order
{
execute_trigger_order: {
account_id: string
trigger_order_id: string
}
}
repay_from_wallet
{
repay_from_wallet: {
account_id: string
}
}
update_balances_after_deleverage
{
update_balance_after_deleverage: {
account_id: string
pnl: 'break_even' | {
profit: Coin
} | {
loss: Coin
}
}
}
update_credit_account
{
update_credit_account: {
account_id?: string | null
account_kind?: AccountKind | null
actions: Action[]
}
}
Last updated