Skip to content

Commit

Permalink
Merge pull request #2 from arihantbansal/master
Browse files Browse the repository at this point in the history
Add APR to blink title
  • Loading branch information
ChesterSim authored Jul 15, 2024
2 parents 509391c + 4ad35e3 commit 8bfeff9
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
DRIFT_PROGRAM_ID,
DriftClient,
BulkAccountLoader,
calculateDepositRate,
convertToNumber,
} from '@drift-labs/sdk';
import {
clamp,
Expand Down Expand Up @@ -85,8 +87,47 @@ router.get('/blinks/deposit', async (req: Request, res: Response) => {
icon = GENERIC_BLINK_IMAGE;
}

const { oracleInfos, perpMarketIndexes, spotMarketIndexes } =
getMarketsAndOraclesForSubscription(DRIFT_ENV);

const connection = new Connection(ENDPOINT, {
commitment: 'confirmed',
});

const bulkAccountLoader = new BulkAccountLoader(connection, 'confirmed', 0);

const walletWrapper = createThrowawayIWallet();

const driftClient = new DriftClient({
connection: connection,
wallet: walletWrapper,
programID: new PublicKey(DRIFT_PROGRAM_ID),
env: DRIFT_ENV,
txVersion: 0,
userStats: false,
perpMarketIndexes: perpMarketIndexes,
spotMarketIndexes: spotMarketIndexes,
oracleInfos: oracleInfos,
accountSubscription: {
type: 'polling',
accountLoader: bulkAccountLoader,
},
});
await driftClient.subscribe();

let title = `Deposit ${depositToken} into Drift`;

const spotMarket = driftClient.getSpotMarketAccount(spotMarketConfig.marketIndex);

if (spotMarket) {
const apr = convertToNumber(calculateDepositRate(spotMarket), new BN(10000));

if (apr >= 0.1) {
title = `Deposit ${depositToken} into Drift and earn ${apr}% APR`;
}
}

const label = '';
const title = `Deposit ${depositToken} into Drift`;
const description = '';
const disabled = false;
const amountQuery = 'depositAmount';
Expand Down Expand Up @@ -116,7 +157,7 @@ router.get('/blinks/deposit', async (req: Request, res: Response) => {
},
],
};

const response: ActionsSpecGetResponse = {
icon,
label,
Expand All @@ -125,6 +166,8 @@ router.get('/blinks/deposit', async (req: Request, res: Response) => {
disabled,
links,
};

driftClient.unsubscribe();

return res.json(response);
});
Expand Down

0 comments on commit 8bfeff9

Please sign in to comment.