Skip to content

Commit

Permalink
Merge pull request #57 from solendprotocol/v2.0.2-liquidator-changes
Browse files Browse the repository at this point in the history
liquidator changes for v2.0.2
  • Loading branch information
0xripleys authored Aug 8, 2023
2 parents df622fe + 976b639 commit 11fef04
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 108 deletions.
2 changes: 1 addition & 1 deletion liquidator/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'react', 'import'],
extends: [
'eslint:recommended',
'airbnb-typescript',
Expand Down
17 changes: 9 additions & 8 deletions liquidator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
],
"license": "ISC",
"dependencies": {
"@hubbleprotocol/hubble-config": "^1.0.127",
"@hubbleprotocol/kamino-sdk": "^1.0.131",
"@hubbleprotocol/hubble-config": "=1.0.127",
"@hubbleprotocol/kamino-sdk": "=1.0.131",
"@jup-ag/core": "=1.0.0-beta.22",
"@project-serum/anchor": "^0.25.0",
"@project-serum/sol-wallet-adapter": "^0.2.0",
Expand All @@ -39,6 +39,7 @@
"bs58": "^4.0.1",
"buffer-layout": "^1.2.1",
"dotenv": "^10.0.0",
"eslint-config-airbnb": "^19.0.4",
"ggoldca-sdk": "^0.0.17",
"got": "^9.6.0",
"hot-shots": "^8.5.0",
Expand All @@ -53,12 +54,12 @@
"devDependencies": {
"@types/jest": "^24.9.1",
"@types/node": "^14.0.14",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"eslint": "^5.16.0",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"eslint": "^8.46.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.18.2",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^22.21.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.0",
Expand All @@ -68,6 +69,6 @@
"nodemon": "^1.19.4",
"supertest": "^4.0.2",
"ts-jest": "^26.3.0",
"typescript": "^4.4.4"
"typescript": "^5.1.6"
}
}
10 changes: 6 additions & 4 deletions liquidator/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-loop-func */
import got from 'got';
import { MarketConfig } from 'global';
import dotenv from 'dotenv';
Expand Down Expand Up @@ -35,10 +34,13 @@ export async function getMarkets(): Promise<MarketConfig[]> {
const maxAttempt = 10;
const marketUrl = getMarketsUrl();

do {
// Function to wait for a certain amount of time
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

while (attemptCount < maxAttempt) {
try {
if (attemptCount > 0) {
await new Promise((resolve) => setTimeout(resolve, backoffFactor * 10));
await wait(backoffFactor * 10);
backoffFactor *= 2;
}
attemptCount += 1;
Expand All @@ -48,7 +50,7 @@ export async function getMarkets(): Promise<MarketConfig[]> {
} catch (error) {
console.error('error fetching /v1/markets/configs ', error);
}
} while (attemptCount < maxAttempt);
}

throw new Error('failed to fetch /v1/markets/configs');
}
Expand Down
4 changes: 2 additions & 2 deletions liquidator/src/libs/rebalanceWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function rebalanceWallet(connection, payer, jupiter, tokensOracle,
function aggregateInfo(tokensOracle, walletBalances, connection, wallet, target) {
const info: any = [];
target.forEach(async (tokenDistribution: TokenCount) => {
const { symbol, target } = tokenDistribution;
const { symbol, target: tokenTarget } = tokenDistribution;
const tokenOracle = findWhere(tokensOracle, { symbol });
const walletBalance = findWhere(walletBalances, { symbol });

Expand All @@ -90,7 +90,7 @@ function aggregateInfo(tokensOracle, walletBalances, connection, wallet, target)
const usdValue = new BigNumber(walletBalance.balance).multipliedBy(tokenOracle.price);
info.push({
symbol,
target,
target: tokenTarget,
mintAddress: tokenOracle.mintAddress,
ata: walletBalance.ata?.toString(),
balance: walletBalance.balance,
Expand Down
4 changes: 3 additions & 1 deletion liquidator/src/libs/refreshObligation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function calculateRefreshedObligation(
mintAddress,
marketValue,
symbol,
addedBorrowWeightBPS: reserve.config.addedBorrowWeightBPS,
});
});

Expand Down Expand Up @@ -132,12 +133,13 @@ function getBorrrowedAmountWadsWithInterest(
}
}

type Borrow = {
export type Borrow = {
borrowReserve: PublicKey;
borrowAmountWads: BN;
marketValue: BigNumber;
mintAddress: string,
symbol: string;
addedBorrowWeightBPS: BN;
};

type Deposit = {
Expand Down
Loading

0 comments on commit 11fef04

Please sign in to comment.