Skip to content

Commit

Permalink
#35 Fixed liquidation not triggering after there's a closed loan, #34
Browse files Browse the repository at this point in the history
…Cleaned up code space
  • Loading branch information
anilhelvaci committed Sep 22, 2022
1 parent eb4b197 commit e6c4ff4
Show file tree
Hide file tree
Showing 34 changed files with 219 additions and 1,132 deletions.
99 changes: 0 additions & 99 deletions .github/workflows/deploy-treasury.yml

This file was deleted.

75 changes: 0 additions & 75 deletions .github/workflows/lint-test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion api/setVanPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const setVanPrice = async homeP => {
const home = await homeP;
const { scratch, board } = home;

const NEW_PRICE_VAL = 300n;
const NEW_PRICE_VAL = 100n;

const {
VAN_ISSUER_BOARD_ID,
Expand Down
14 changes: 8 additions & 6 deletions contract/src/lendingPool/liquidationObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export const makeLiquidationObserver = (
}
},
fail: reason => {

console.log(`ColPriceObserver failed with the reason ${reason}`);
},
finish: done => {

console.log(`ColPriceObserver finished with ${done}`);
},
};

Expand All @@ -135,15 +135,17 @@ export const makeLiquidationObserver = (
}
},
fail: reason => {

console.log(`DebtPriceObserver failed with the reason ${reason}`);
},
finish: done => {

console.log(`DebtPriceObserver finished with ${done}`);
},
};

observeNotifier(wrappedCollateralPriceAuthority.notifier, colPriceObserver);
observeNotifier(wrappedDebtPriceAuthority.notifier, debtPriceObserver);
observeNotifier(wrappedCollateralPriceAuthority.notifier, colPriceObserver)
.catch(err => console.log(`Error observing colPriceObserver: ${err}`));
observeNotifier(wrappedDebtPriceAuthority.notifier, debtPriceObserver)
.catch(err => console.log(`Error observing debtPriceObserver: ${err}`));

/**
* Called from the debtsPerCollateral when there's a new loan with a closer
Expand Down
1 change: 1 addition & 0 deletions contract/src/lendingPool/loan.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ export const makeInnerLoan = (
/** @type Loan */
const innerLoan = Far('innerLoan', {
getLoanSeat: () => state.loanSeat,
getPhase: () => state.phase,
initLoanKit: (seat, poolSeat, exchangeRate, loanKey) => initLoanKit(seat, poolSeat, innerLoan, exchangeRate, loanKey),
liquidating,
liquidated,
Expand Down
10 changes: 8 additions & 2 deletions contract/src/lendingPool/loanStoreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { keyEQ, keyLT } from '@agoric/store';
import { AmountMath } from '@agoric/ertp';
import { toVaultKey } from '@agoric/run-protocol/src/vaultFactory/storeUtils.js';
import { makeOrderedVaultStore } from '@agoric/run-protocol/src/vaultFactory/orderedVaultStore.js';
import { LoanPhase } from './loan.js'

/**
* This module is somehow similar to the ~/run-protocol/vaultFactory/prioritizedVaults.js.
Expand Down Expand Up @@ -107,7 +108,7 @@ export const makeLoanStoreUtils = () => {
*/
const refreshLoanPriorityByAttributes = (oldDebt, oldCollateral, loanId) => {
const loan = removeLoanByAttributes(oldDebt, oldCollateral, loanId);
addLoan(loanId, loan);
return addIfActive(loanId, loan);
};

/**
Expand All @@ -118,9 +119,14 @@ export const makeLoanStoreUtils = () => {
*/
const refreshLoanPriorityByKey = (key, loanId) => {
const loan = removeLoan(key);
return addLoan(loanId, loan);
return addIfActive(loanId, loan);
}

const addIfActive = (loanId, loan) => {
if (loan.getPhase() !== LoanPhase.ACTIVE) return 'Not exist';
return addLoan(loanId, loan);
};

return harden({
addLoan,
refreshLoanPriorityByAttributes,
Expand Down
1 change: 1 addition & 0 deletions contract/src/lendingPool/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
* @typedef {Object} Loan
* @property {() => ZCFSeat} getLoanSeat
* @property {() => string} getPhase
* @property {() => void} liquidating
* @property {(amount: Amount<'nat'>) => void} liquidated
* @property {(seat: ZCFSeat, poolSeat: ZCFSeat, exchangeRate: Ratio, loanKey: string) => Promise<LoanKit>} initLoanKit
Expand Down
Loading

0 comments on commit e6c4ff4

Please sign in to comment.