Skip to content

Commit b70bbfb

Browse files
authored
update sort rank (#178)
* update sort rank * fix lint issues
1 parent a6888d0 commit b70bbfb

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

hub/providers/Defi/plans/save.tsx

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import {
1010
createAssociatedTokenAccountIdempotentInstruction,
1111
getAssociatedTokenAddressSync,
1212
} from '@solana/spl-token-new';
13-
import { Connection, Keypair, PublicKey, AccountInfo, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
13+
import {
14+
Connection,
15+
Keypair,
16+
PublicKey,
17+
AccountInfo,
18+
TransactionMessage,
19+
VersionedTransaction,
20+
} from '@solana/web3.js';
1421
import { parseReserve, SolendActionCore } from '@solendprotocol/solend-sdk';
1522
import {
1623
InstructionWithSigners,
@@ -43,7 +50,6 @@ function simulatedToAccountInfo(simulatedAccount: any): AccountInfo<Buffer> {
4350
};
4451
}
4552

46-
4753
export const PROTOCOL_SLUG = 'Save';
4854

4955
const SAVE_TRANSACTIONS_ENDPOINT = 'https://api.save.finance/transactions';
@@ -370,8 +376,7 @@ export const useSavePlans = (
370376
},
371377
);
372378

373-
const solendIxs = await solendAction.getInstructions();
374-
379+
const solendIxs = await solendAction.getInstructions();
375380

376381
const ixs = [
377382
...solendIxs.oracleIxs,
@@ -380,53 +385,54 @@ export const useSavePlans = (
380385
...solendIxs.postLendingIxs,
381386
] as InstructionWithSigners[];
382387

383-
// Get Transaction Message
388+
// Get Transaction Message
384389
const message = new TransactionMessage({
385390
payerKey: wallet.publicKey,
386-
recentBlockhash: (await connection.current.getLatestBlockhash()).blockhash,
391+
recentBlockhash: (await connection.current.getLatestBlockhash())
392+
.blockhash,
387393
instructions: ixs.map((ix) => ix.instruction),
388394
}).compileToV0Message();
389-
395+
390396
// Get Versioned Transaction
391397
const vtx = new VersionedTransaction(message);
392398

393-
const res = await connection.current.simulateTransaction(
394-
vtx,
395-
{
396-
commitment: 'processed',
397-
sigVerify: false,
398-
accounts: {
399-
encoding: 'base64',
400-
addresses: [reserveAddress],
401-
}
402-
}
403-
);
399+
const res = await connection.current.simulateTransaction(vtx, {
400+
commitment: 'processed',
401+
sigVerify: false,
402+
accounts: {
403+
encoding: 'base64',
404+
addresses: [reserveAddress],
405+
},
406+
});
404407

405408
const accountInfo = res?.value.accounts?.map(simulatedToAccountInfo);
406409
let cTokenExchangeRate = new BigNumber(reserve.cTokenExchangeRate);
407410
let buffer = 0.02;
408411
if (accountInfo?.[0]) {
409-
const simulatedReserve = parseReserve(new PublicKey(reserveAddress), accountInfo?.[0], 'base64');
410-
411-
412-
const decimals = simulatedReserve.info.liquidity.mintDecimals;
413-
const availableAmount = new BigNumber(
414-
simulatedReserve.info.liquidity.availableAmount.toString()
415-
).shiftedBy(-decimals);
416-
const totalBorrow = new BigNumber(
417-
simulatedReserve.info.liquidity.borrowedAmountWads.toString()
418-
).shiftedBy(-18 - decimals);
419-
const accumulatedProtocolFees = new BigNumber(
420-
simulatedReserve.info.liquidity.accumulatedProtocolFeesWads.toString()
421-
).shiftedBy(-18 - decimals);
422-
const totalSupply = totalBorrow
423-
.plus(availableAmount)
424-
.minus(accumulatedProtocolFees);
412+
const simulatedReserve = parseReserve(
413+
new PublicKey(reserveAddress),
414+
accountInfo?.[0],
415+
'base64',
416+
);
417+
418+
const decimals = simulatedReserve.info.liquidity.mintDecimals;
419+
const availableAmount = new BigNumber(
420+
simulatedReserve.info.liquidity.availableAmount.toString(),
421+
).shiftedBy(-decimals);
422+
const totalBorrow = new BigNumber(
423+
simulatedReserve.info.liquidity.borrowedAmountWads.toString(),
424+
).shiftedBy(-18 - decimals);
425+
const accumulatedProtocolFees = new BigNumber(
426+
simulatedReserve.info.liquidity.accumulatedProtocolFeesWads.toString(),
427+
).shiftedBy(-18 - decimals);
428+
const totalSupply = totalBorrow
429+
.plus(availableAmount)
430+
.minus(accumulatedProtocolFees);
425431

426432
cTokenExchangeRate = new BigNumber(totalSupply).dividedBy(
427-
new BigNumber(simulatedReserve.info.collateral.mintTotalSupply.toString()).shiftedBy(
428-
-decimals
429-
)
433+
new BigNumber(
434+
simulatedReserve.info.collateral.mintTotalSupply.toString(),
435+
).shiftedBy(-decimals),
430436
);
431437
buffer = 0;
432438
}
@@ -448,7 +454,7 @@ export const useSavePlans = (
448454

449455
const transferAmountBase = new BigNumber(amount)
450456
.shiftedBy(reserve.mintDecimals)
451-
.times(1-buffer)
457+
.times(1 - buffer)
452458
.div(cTokenExchangeRate)
453459
.dp(0, BigNumber.ROUND_DOWN)
454460
.toNumber();

public/realms/mainnet-beta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
{
7272
"symbol": "IslandDAO",
7373
"programId": "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw",
74-
"realmId": "F9V4Lwo49aUe8fFujMbU6uhdFyDRqKY54WpzdpncUSk9"
74+
"realmId": "F9V4Lwo49aUe8fFujMbU6uhdFyDRqKY54WpzdpncUSk9",
75+
"sortRank": 991
7576
},
7677
{
7778
"symbol": "Dean's List Solarplex State",

0 commit comments

Comments
 (0)