Skip to content

Commit

Permalink
collateralization
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahilgill24 committed Jun 28, 2024
1 parent dca9804 commit 45229fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
14 changes: 5 additions & 9 deletions contracts/vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<QueryResponse, StdE
match msg {
QueryMsg::GetTotalSupply {} => query::get_total_supply(deps),
QueryMsg::GetBalanceOf { address } => query::get_balance_of(deps, address),
QueryMsg::GetDynamicInterstRates { address } => {
query::get_dyanamic_interest_rates(deps, address)
QueryMsg::GetDynamicInterstRates { address ,amount} => {
query::get_dyanamic_interest_rates(deps, address,amount)
}
QueryMsg::GetFixedInterstRates {} => query::get_fixed_interest_ratio(deps),
QueryMsg::GetTotalDebt { address } => query::get_total_debt(deps, address),
Expand All @@ -232,11 +232,7 @@ pub mod query {

use super::*;

pub fn get_dyanamic_interest_rates(deps: Deps, addr: Addr) -> Result<QueryResponse, StdError> {
let token_info = TOKEN_INFO.load(deps.storage)?;
let mut balance = BALANCE_OF
.load(deps.storage, addr.clone())
.unwrap_or((Uint128::zero(), Uint128::zero()));
pub fn get_dyanamic_interest_rates(deps: Deps, addr: Addr,amount:Uint128) -> Result<QueryResponse, StdError> {
// let contribution = balance / TOTAL_SUPPLY.load(deps.storage)?;
// this represents the contribution of the user in the total balance of the vault
// from this contribution we can calcualte the dyanamic rate , and it will change with the time period(each month simply)
Expand All @@ -251,14 +247,14 @@ pub mod query {
//where the lambda would be replaced by the contribution value of the user
// this wont be applicable for the starting users though as we would have to take the average of the contribution of the users in the vault
// and then we can give the interest rate to the users based on the curve we have chosen
let contrib_inverse = TOTAL_SUPPLY.load(deps.storage)? / balance.0;
let contrib_inverse = TOTAL_SUPPLY.load(deps.storage)? / amount;
let dynamic_interest =
ONE_INT + Uint128::from(contrib_inverse) + contrib_inverse * contrib_inverse;
to_binary(&dynamic_interest)
}

pub fn get_fixed_interest_ratio(deps: Deps) -> Result<QueryResponse, StdError> {
to_binary(&FIXED_RATE.load(deps.storage).unwrap_or(Uint128::new(10)))
to_binary(&FIXED_RATE.load(deps.storage).unwrap_or(Uint128::new(150)))
}

pub fn get_total_supply(deps: Deps) -> Result<QueryResponse, StdError> {
Expand Down
2 changes: 1 addition & 1 deletion contracts/vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum QueryMsg {
GetBalanceOf { address: Addr },

#[returns(Uint128)]
GetDynamicInterstRates { address: Addr },
GetDynamicInterstRates { address: Addr ,amount:Uint128},

#[returns(Uint128)]
GetFixedInterstRates {},
Expand Down
48 changes: 45 additions & 3 deletions ui/src/components/dashboard/header/get-loan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,48 @@ export default function GetLoan() {
const [ArchAmount, setArchAmount] = useState(0)
const { walletAddress } = useWalletStore()

const dynamic_collaterizatoin_value = async () => {
if (window.keplr && walletAddress) {
const offlineSigner = window.keplr.getOfflineSigner(ChainInfo.chainId);
const CosmWasmClient = await SigningArchwayClient.connectWithSigner(ChainInfo.rpc, offlineSigner);
const CONTRACT_ADDRESS = import.meta.env.VITE_VAULT_CONTRACT;

let entrypoint = {
get_dyanamic_interest_rates: {
address: walletAddress,
amount: USDAmount
}
}

let tx = await CosmWasmClient.queryContractSmart(CONTRACT_ADDRESS, entrypoint);
console.log(tx);
setArchAmount(tx);


}

}

const fixed_collaterizatoin_value = async () => {
if (window.keplr && walletAddress) {
const offlineSigner = window.keplr.getOfflineSigner(ChainInfo.chainId);
const CosmWasmClient = await SigningArchwayClient.connectWithSigner(ChainInfo.rpc, offlineSigner);
const CONTRACT_ADDRESS = import.meta.env.VITE_VAULT_CONTRACT;

let entrypoint = {
get_fixed_interest_ratio: {
address: walletAddress

}
}

let tx = await CosmWasmClient.queryContractSmart(CONTRACT_ADDRESS, entrypoint);
setArchAmount(tx);
console.log(tx);

}
}

useEffect(() => {
const delayDebounceFn = setTimeout(async () => {
const data = await dataFetch()
Expand Down Expand Up @@ -145,7 +187,7 @@ export default function GetLoan() {
const stakingReward: ExecuteInstruction = {
contractAddress: STAKING_CONTRCAT,
msg: stake_reward,
funds:funds_my
funds: funds_my
}


Expand Down Expand Up @@ -193,8 +235,8 @@ export default function GetLoan() {
/>
<p className="text-xs mt-2 text-muted-foreground">Select the loan type</p>
<div className="flex flex-row gap-2">
<Button variant="secondary" className="flex-1">Fixed</Button>
<Button variant="secondary" className="flex-1">Dynamic</Button>
<Button variant="secondary" className="flex-1" onClick={fixed_collaterizatoin_value}>Fixed</Button>
<Button variant="secondary" className="flex-1" onClick={dynamic_collaterizatoin_value}>Dynamic</Button>
</div>

<div className="flex flex-row gap-2">
Expand Down

0 comments on commit 45229fd

Please sign in to comment.