Skip to content

Commit 5c46e88

Browse files
committed
Add new RPC methods to interface
1 parent c459efe commit 5c46e88

13 files changed

+601
-287
lines changed

solend-sdk/src/core/actions.ts

+134-120
Large diffs are not rendered by default.

solend-sdk/src/core/margin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class Margin {
415415
environment: "production",
416416
customObligationAddress: this.obligationAddress,
417417
customObligationSeed: this.obligationSeed,
418-
lookupTableAddress: lookupTableAccount?.key
418+
lookupTableAddress: lookupTableAccount?.key,
419419
}
420420
);
421421
const { preLendingTxn, lendingTxn } =

solend-sdk/src/core/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ export type InputReserveConfigParams = {
7373
extraOracle?: PublicKey;
7474
attributedBorrowLimitOpen: BN;
7575
attributedBorrowLimitClose: BN;
76-
}
76+
};

solend-sdk/src/core/utils/obligations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type ObligationType = ReturnType<typeof formatObligation>;
1010

1111
export function formatObligation(
1212
obligation: { pubkey: PublicKey; info: Obligation },
13-
reserveMap: {[key: string]: ReserveType}
13+
reserveMap: { [key: string]: ReserveType }
1414
) {
1515
const poolAddress = obligation.info.lendingMarket.toBase58();
1616
let minPriceUserTotalSupply = new BigNumber(0);

solend-sdk/src/core/utils/pools.ts

+23-15
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export function formatReserve(
6666
name?: string;
6767
},
6868
config?: {
69-
showApy: boolean,
70-
avgSlotTime: number,
69+
showApy: boolean;
70+
avgSlotTime: number;
7171
}
7272
) {
7373
const decimals = reserve.info.liquidity.mintDecimals;
@@ -101,16 +101,18 @@ export function formatReserve(
101101

102102
const lstPatch = priceData?.lstAdjustmentRatio
103103
? {
104-
loanToValueRatio: Number(
105-
new BigNumber(reserve.info.config.loanToValueRatio)
106-
.div(priceData.lstAdjustmentRatio)
107-
.toString(),
108-
) / 100,
109-
liquidationThreshold: Number(
110-
new BigNumber(reserve.info.config.liquidationThreshold)
111-
.div(priceData.lstAdjustmentRatio)
112-
.toString(),
113-
) / 100,
104+
loanToValueRatio:
105+
Number(
106+
new BigNumber(reserve.info.config.loanToValueRatio)
107+
.div(priceData.lstAdjustmentRatio)
108+
.toString()
109+
) / 100,
110+
liquidationThreshold:
111+
Number(
112+
new BigNumber(reserve.info.config.liquidationThreshold)
113+
.div(priceData.lstAdjustmentRatio)
114+
.toString()
115+
) / 100,
114116
}
115117
: {};
116118

@@ -146,8 +148,14 @@ export function formatReserve(
146148
minBorrowApr: reserve.info.config.minBorrowRate / 100,
147149
maxBorrowApr: reserve.info.config.maxBorrowRate / 100,
148150
superMaxBorrowRate: reserve.info.config.superMaxBorrowRate.toNumber() / 100,
149-
supplyInterest: calculateSupplyInterest(reserve.info, Boolean(config?.showApy)).times((0.5 / (config?.avgSlotTime ?? 0.5))),
150-
borrowInterest: calculateBorrowInterest(reserve.info, Boolean(config?.showApy)).times((0.5 / (config?.avgSlotTime ?? 0.5))),
151+
supplyInterest: calculateSupplyInterest(
152+
reserve.info,
153+
Boolean(config?.showApy)
154+
).times(0.5 / (config?.avgSlotTime ?? 0.5)),
155+
borrowInterest: calculateBorrowInterest(
156+
reserve.info,
157+
Boolean(config?.showApy)
158+
).times(0.5 / (config?.avgSlotTime ?? 0.5)),
151159
totalSupply,
152160
totalBorrow,
153161
availableAmount,
@@ -193,7 +201,7 @@ export function formatReserve(
193201
attributedBorrowValue: reserve.info.config.attributedBorrowValue,
194202
attributedBorrowLimitOpen: reserve.info.config.attributedBorrowLimitOpen,
195203
attributedBorrowLimitClose: reserve.info.config.attributedBorrowLimitClose,
196-
...lstPatch
204+
...lstPatch,
197205
};
198206
}
199207

solend-sdk/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./lib";
22
export * from "./core";
3-
export * from "./transaction";
3+
export * from "./transaction";

solend-sdk/src/rpc/cached.ts

+79
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import {
2121
RpcResponseAndContext,
2222
SendOptions,
2323
SignatureResult,
24+
SignaturesForAddressOptions,
25+
SignatureStatus,
26+
SignatureStatusConfig,
2427
SimulatedTransactionResponse,
2528
SimulateTransactionConfig,
2629
TokenAmount,
2730
TransactionResponse,
2831
TransactionSignature,
32+
VersionedMessage,
2933
VersionedTransaction,
3034
VersionedTransactionResponse,
3135
} from "@solana/web3.js";
@@ -300,4 +304,79 @@ export class CachedConnection implements SolendRPCConnection {
300304
))
301305
);
302306
}
307+
async getSignatureStatus(
308+
signature: TransactionSignature,
309+
config?: SignatureStatusConfig
310+
): Promise<RpcResponseAndContext<SignatureStatus | null>> {
311+
const key = `getSignatureStatus_${signature}_${JSON.stringify(config)}`;
312+
return (
313+
(await this.cache.get(key)) ||
314+
(await this.cache.set(
315+
key,
316+
this.connection.getSignatureStatus(signature, config)
317+
))
318+
);
319+
}
320+
321+
async getSignatureStatuses(
322+
signatures: Array<TransactionSignature>,
323+
config?: SignatureStatusConfig
324+
): Promise<RpcResponseAndContext<Array<SignatureStatus | null>>> {
325+
const key = `getSignatureStatuses_${signatures
326+
.map((sig) => sig)
327+
.join("_")}_${JSON.stringify(config)}`;
328+
return (
329+
(await this.cache.get(key)) ||
330+
(await this.cache.set(
331+
key,
332+
this.connection.getSignatureStatuses(signatures, config)
333+
))
334+
);
335+
}
336+
337+
async getSignaturesForAddress(
338+
address: PublicKey,
339+
options?: SignaturesForAddressOptions,
340+
commitment?: Finality
341+
): Promise<Array<ConfirmedSignatureInfo>> {
342+
const key = `getSignaturesForAddress_${address.toBase58()}_${JSON.stringify(
343+
options
344+
)}_${commitment}`;
345+
return (
346+
(await this.cache.get(key)) ||
347+
(await this.cache.set(
348+
key,
349+
this.connection.getSignaturesForAddress(address, options, commitment)
350+
))
351+
);
352+
}
353+
354+
async getBlocks(
355+
startSlot: number,
356+
endSlot?: number,
357+
commitment?: Finality
358+
): Promise<Array<number>> {
359+
const key = `getBlocks_${startSlot}_${endSlot}_${commitment}`;
360+
return (
361+
(await this.cache.get(key)) ||
362+
(await this.cache.set(
363+
key,
364+
this.connection.getBlocks(startSlot, endSlot, commitment)
365+
))
366+
);
367+
}
368+
369+
async getFeeForMessage(
370+
message: VersionedMessage,
371+
commitment?: Commitment
372+
): Promise<RpcResponseAndContext<number | null>> {
373+
const key = `getFeeForMessage_${JSON.stringify(message)}_${commitment}`;
374+
return (
375+
(await this.cache.get(key)) ||
376+
(await this.cache.set(
377+
key,
378+
this.connection.getFeeForMessage(message, commitment)
379+
))
380+
);
381+
}
303382
}

solend-sdk/src/rpc/instrumented.ts

+56
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import {
2121
RpcResponseAndContext,
2222
SendOptions,
2323
SignatureResult,
24+
SignaturesForAddressOptions,
25+
SignatureStatus,
26+
SignatureStatusConfig,
2427
SimulatedTransactionResponse,
2528
SimulateTransactionConfig,
2629
TokenAmount,
2730
TransactionResponse,
2831
TransactionSignature,
32+
VersionedMessage,
2933
VersionedTransaction,
3034
VersionedTransactionResponse,
3135
} from "@solana/web3.js";
@@ -196,6 +200,58 @@ export class InstrumentedConnection implements SolendRPCConnection {
196200
);
197201
}
198202

203+
async getSignatureStatus(
204+
signature: TransactionSignature,
205+
config?: SignatureStatusConfig
206+
): Promise<RpcResponseAndContext<SignatureStatus | null>> {
207+
return this.withStats(
208+
this.connection.getSignatureStatus(signature, config),
209+
"getSignatureStatus"
210+
);
211+
}
212+
213+
async getSignatureStatuses(
214+
signatures: Array<TransactionSignature>,
215+
config?: SignatureStatusConfig
216+
): Promise<RpcResponseAndContext<Array<SignatureStatus | null>>> {
217+
return this.withStats(
218+
this.connection.getSignatureStatuses(signatures, config),
219+
"getSignatureStatuses"
220+
);
221+
}
222+
223+
async getSignaturesForAddress(
224+
address: PublicKey,
225+
options?: SignaturesForAddressOptions,
226+
commitment?: Finality
227+
): Promise<Array<ConfirmedSignatureInfo>> {
228+
return this.withStats(
229+
this.connection.getSignaturesForAddress(address, options, commitment),
230+
"getSignaturesForAddress"
231+
);
232+
}
233+
234+
async getBlocks(
235+
startSlot: number,
236+
endSlot?: number,
237+
commitment?: Finality
238+
): Promise<Array<number>> {
239+
return this.withStats(
240+
this.connection.getBlocks(startSlot, endSlot, commitment),
241+
"getBlocks"
242+
);
243+
}
244+
245+
async getFeeForMessage(
246+
message: VersionedMessage,
247+
commitment?: Commitment
248+
): Promise<RpcResponseAndContext<number | null>> {
249+
return this.withStats(
250+
this.connection.getFeeForMessage(message, commitment),
251+
"getFeeForMessage"
252+
);
253+
}
254+
199255
async withStats(fn: Promise<any>, fnName: string) {
200256
const tags = [`rpc:${this.prefix}`, `function:${fnName}`];
201257
this.statsd.increment("rpc_method_call", tags);

solend-sdk/src/rpc/interface.ts

+26
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import {
2121
RpcResponseAndContext,
2222
SendOptions,
2323
SignatureResult,
24+
SignaturesForAddressOptions,
25+
SignatureStatus,
26+
SignatureStatusConfig,
2427
SimulatedTransactionResponse,
2528
SimulateTransactionConfig,
2629
TokenAmount,
2730
TransactionResponse,
2831
TransactionSignature,
32+
VersionedMessage,
2933
VersionedTransaction,
3034
VersionedTransactionResponse,
3135
} from "@solana/web3.js";
@@ -92,4 +96,26 @@ export interface SolendRPCConnection {
9296
strategy: BlockheightBasedTransactionConfirmationStrategy,
9397
commitment?: Commitment
9498
): Promise<RpcResponseAndContext<SignatureResult>>;
99+
getSignatureStatus(
100+
signature: TransactionSignature,
101+
config?: SignatureStatusConfig
102+
): Promise<RpcResponseAndContext<SignatureStatus | null>>;
103+
getSignatureStatuses(
104+
signatures: Array<TransactionSignature>,
105+
config?: SignatureStatusConfig
106+
): Promise<RpcResponseAndContext<Array<SignatureStatus | null>>>;
107+
getSignaturesForAddress(
108+
address: PublicKey,
109+
options?: SignaturesForAddressOptions,
110+
commitment?: Finality
111+
): Promise<Array<ConfirmedSignatureInfo>>;
112+
getBlocks(
113+
startSlot: number,
114+
endSlot?: number,
115+
commitment?: Finality
116+
): Promise<Array<number>>;
117+
getFeeForMessage(
118+
message: VersionedMessage,
119+
commitment?: Commitment
120+
): Promise<RpcResponseAndContext<number | null>>;
95121
}

0 commit comments

Comments
 (0)