fixes from cr
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
03ae43017c
commit
addb12736f
|
@ -75,6 +75,15 @@ pub struct RegisterToken<'info> {
|
|||
pub rent: Sysvar<'info, Rent>,
|
||||
}
|
||||
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Default)]
|
||||
pub struct InterestRateParams {
|
||||
util0: f32,
|
||||
rate0: f32,
|
||||
util1: f32,
|
||||
rate1: f32,
|
||||
max_rate: f32,
|
||||
}
|
||||
|
||||
// TODO: should this be "configure_mint", we pass an explicit index, and allow
|
||||
// overwriting config as long as the mint account stays the same?
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
@ -82,11 +91,7 @@ pub fn register_token(
|
|||
ctx: Context<RegisterToken>,
|
||||
token_index: TokenIndex,
|
||||
name: String,
|
||||
util0: f32,
|
||||
rate0: f32,
|
||||
util1: f32,
|
||||
rate1: f32,
|
||||
max_rate: f32,
|
||||
interest_rate_params: InterestRateParams,
|
||||
maint_asset_weight: f32,
|
||||
init_asset_weight: f32,
|
||||
maint_liab_weight: f32,
|
||||
|
@ -107,11 +112,12 @@ pub fn register_token(
|
|||
indexed_total_deposits: I80F48::ZERO,
|
||||
indexed_total_borrows: I80F48::ZERO,
|
||||
last_updated: Clock::get()?.unix_timestamp,
|
||||
util0: I80F48::from_num(util0),
|
||||
rate0: I80F48::from_num(rate0),
|
||||
util1: I80F48::from_num(util1),
|
||||
rate1: I80F48::from_num(rate1),
|
||||
max_rate: I80F48::from_num(max_rate),
|
||||
// TODO: add a require! verifying relation between the parameters
|
||||
util0: I80F48::from_num(interest_rate_params.util0),
|
||||
rate0: I80F48::from_num(interest_rate_params.rate0),
|
||||
util1: I80F48::from_num(interest_rate_params.util1),
|
||||
rate1: I80F48::from_num(interest_rate_params.rate1),
|
||||
max_rate: I80F48::from_num(interest_rate_params.max_rate),
|
||||
maint_asset_weight: I80F48::from_num(maint_asset_weight),
|
||||
init_asset_weight: I80F48::from_num(init_asset_weight),
|
||||
maint_liab_weight: I80F48::from_num(maint_liab_weight),
|
||||
|
|
|
@ -38,11 +38,7 @@ pub mod mango_v4 {
|
|||
ctx: Context<RegisterToken>,
|
||||
token_index: TokenIndex,
|
||||
name: String,
|
||||
util0: f32,
|
||||
rate0: f32,
|
||||
util1: f32,
|
||||
rate1: f32,
|
||||
max_rate: f32,
|
||||
interest_rate_params: InterestRateParams,
|
||||
maint_asset_weight: f32,
|
||||
init_asset_weight: f32,
|
||||
maint_liab_weight: f32,
|
||||
|
@ -53,11 +49,7 @@ pub mod mango_v4 {
|
|||
ctx,
|
||||
token_index,
|
||||
name,
|
||||
util0,
|
||||
rate0,
|
||||
util1,
|
||||
rate1,
|
||||
max_rate,
|
||||
interest_rate_params,
|
||||
maint_asset_weight,
|
||||
init_asset_weight,
|
||||
maint_liab_weight,
|
||||
|
|
|
@ -176,12 +176,11 @@ impl Bank {
|
|||
let interest_rate = self.compute_interest_rate(utilization);
|
||||
|
||||
let diff_ts = I80F48::from_num(now_ts - self.last_updated);
|
||||
self.last_updated = now_ts;
|
||||
|
||||
let borrow_interest: I80F48 = cm!(interest_rate * diff_ts);
|
||||
let deposit_interest = cm!(borrow_interest * utilization);
|
||||
|
||||
self.last_updated = Clock::get()?.unix_timestamp;
|
||||
|
||||
if borrow_interest <= I80F48::ZERO || deposit_interest <= I80F48::ZERO {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -225,9 +224,9 @@ impl Bank {
|
|||
let slope = cm!((rate1 - rate0) / (util1 - util0));
|
||||
cm!(rate0 + slope * extra_util)
|
||||
} else {
|
||||
let extra_util = utilization - util1;
|
||||
let slope = (max_rate - rate1) / (I80F48::ONE - util1);
|
||||
rate1 + slope * extra_util
|
||||
let extra_util = cm!(utilization - util1);
|
||||
let slope = cm!((max_rate - rate1) / (I80F48::ONE - util1));
|
||||
cm!(rate1 + slope * extra_util)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,11 +92,7 @@ export class MangoClient {
|
|||
.registerToken(
|
||||
tokenIndex,
|
||||
name,
|
||||
util0,
|
||||
rate0,
|
||||
util1,
|
||||
rate1,
|
||||
maxRate,
|
||||
{ util0, rate0, util1, rate1, maxRate },
|
||||
maintAssetWeight,
|
||||
initAssetWeight,
|
||||
maintLiabWeight,
|
||||
|
|
100
ts/mango_v4.ts
100
ts/mango_v4.ts
|
@ -169,24 +169,10 @@ export type MangoV4 = {
|
|||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "util0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "util1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "maxRate",
|
||||
"type": "f32"
|
||||
"name": "interestRateParams",
|
||||
"type": {
|
||||
"defined": "InterestRateParams"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "maintAssetWeight",
|
||||
|
@ -2154,6 +2140,34 @@ export type MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "InterestRateParams",
|
||||
"type": {
|
||||
"kind": "struct",
|
||||
"fields": [
|
||||
{
|
||||
"name": "util0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "util1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "maxRate",
|
||||
"type": "f32"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "TokenIndex",
|
||||
"type": {
|
||||
|
@ -2671,24 +2685,10 @@ export const IDL: MangoV4 = {
|
|||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "util0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "util1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "maxRate",
|
||||
"type": "f32"
|
||||
"name": "interestRateParams",
|
||||
"type": {
|
||||
"defined": "InterestRateParams"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "maintAssetWeight",
|
||||
|
@ -4656,6 +4656,34 @@ export const IDL: MangoV4 = {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "InterestRateParams",
|
||||
"type": {
|
||||
"kind": "struct",
|
||||
"fields": [
|
||||
{
|
||||
"name": "util0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate0",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "util1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "rate1",
|
||||
"type": "f32"
|
||||
},
|
||||
{
|
||||
"name": "maxRate",
|
||||
"type": "f32"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "TokenIndex",
|
||||
"type": {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e pipefail
|
||||
|
||||
anchor build --skip-lint
|
||||
./idl-fixup.sh
|
||||
cp -v ./target/types/mango_v4.ts ./ts/mango_v4.ts
|
||||
tsc
|
Loading…
Reference in New Issue