Skip to content

Commit dee4191

Browse files
committed
better wallet types
1 parent c436e09 commit dee4191

File tree

5 files changed

+48
-28
lines changed

5 files changed

+48
-28
lines changed

solend-sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solendprotocol/solend-sdk",
3-
"version": "0.13.23",
3+
"version": "0.13.29",
44
"private": true,
55
"main": "src/index.ts",
66
"module": "src/index.ts",

solend-sdk/src/core/actions.ts

+36-19
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,23 @@ import {
5959
PullFeed,
6060
ON_DEMAND_MAINNET_PID,
6161
} from "@switchboard-xyz/on-demand";
62-
import { Wallet } from "@coral-xyz/anchor";
6362
import {
6463
createDepositAndMintWrapperTokensInstruction,
6564
createWithdrawAndBurnWrapperTokensInstruction,
6665
} from "@solendprotocol/token2022-wrapper-sdk";
6766
import { ReserveType } from "./utils";
67+
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
68+
69+
export type SaveWallet = {
70+
publicKey: PublicKey;
71+
name: string;
72+
signTransaction<T extends Transaction | VersionedTransaction>(
73+
tx: T
74+
): Promise<T>;
75+
signAllTransactions<T extends Transaction | VersionedTransaction>(
76+
txs: T[]
77+
): Promise<T[]>;
78+
};
6879

6980
const SOL_PADDING_FOR_INTEREST = "1000000";
7081

@@ -153,6 +164,9 @@ type InputPoolType = {
153164
reserves: Array<ReserveType>;
154165
};
155166

167+
export const CROSSBAR_URL1 = "https://crossbar.save.finance";
168+
export const CROSSBAR_URL2 = "https://crossbar.switchboard.xyz";
169+
156170
export class SolendActionCore {
157171
programId: PublicKey;
158172

@@ -201,7 +215,7 @@ export class SolendActionCore {
201215

202216
jitoTipAmount: number;
203217

204-
wallet: Wallet;
218+
wallet: SaveWallet;
205219

206220
debug: boolean;
207221

@@ -224,12 +238,14 @@ export class SolendActionCore {
224238

225239
computeUnitLimit?: number;
226240

241+
errors: Array<any> = [];
242+
227243
private constructor(
228244
programId: PublicKey,
229245
connection: Connection,
230246
reserve: ReserveType,
231247
pool: InputPoolType,
232-
wallet: Wallet,
248+
wallet: SaveWallet,
233249
obligationAddress: PublicKey,
234250
obligationAccountInfo: Obligation | null,
235251
userTokenAccountAddress: PublicKey,
@@ -298,7 +314,7 @@ export class SolendActionCore {
298314
reserve: ReserveType,
299315
action: ActionType,
300316
amount: BN,
301-
wallet: Wallet,
317+
wallet: SaveWallet,
302318
connection: Connection,
303319
config: ActionConfigType
304320
) {
@@ -348,7 +364,10 @@ export class SolendActionCore {
348364
])
349365
).length;
350366

351-
if (distinctReserveCount > POSITION_LIMIT) {
367+
if (
368+
distinctReserveCount > POSITION_LIMIT &&
369+
["deposit", "borrow"].includes(action)
370+
) {
352371
throw Error(
353372
`Obligation already has max number of positions: ${POSITION_LIMIT}`
354373
);
@@ -448,7 +467,7 @@ export class SolendActionCore {
448467
reserve: ReserveType,
449468
connection: Connection,
450469
amount: string,
451-
wallet: Wallet,
470+
wallet: SaveWallet,
452471
obligationAddress: PublicKey,
453472
config: ActionConfigType
454473
) {
@@ -476,7 +495,7 @@ export class SolendActionCore {
476495
reserve: ReserveType,
477496
connection: Connection,
478497
amount: string,
479-
wallet: Wallet,
498+
wallet: SaveWallet,
480499
config: ActionConfigType
481500
) {
482501
const axn = await SolendActionCore.initialize(
@@ -500,7 +519,7 @@ export class SolendActionCore {
500519
reserve: ReserveType,
501520
connection: Connection,
502521
amount: string,
503-
wallet: Wallet,
522+
wallet: SaveWallet,
504523
config: ActionConfigType
505524
) {
506525
const axn = await SolendActionCore.initialize(
@@ -523,7 +542,7 @@ export class SolendActionCore {
523542
reserve: ReserveType,
524543
connection: Connection,
525544
amount: string,
526-
wallet: Wallet,
545+
wallet: SaveWallet,
527546
config: ActionConfigType
528547
) {
529548
const axn = await SolendActionCore.initialize(
@@ -545,7 +564,7 @@ export class SolendActionCore {
545564
reserve: ReserveType,
546565
connection: Connection,
547566
amount: string,
548-
wallet: Wallet,
567+
wallet: SaveWallet,
549568
config: ActionConfigType
550569
) {
551570
const axn = await SolendActionCore.initialize(
@@ -567,7 +586,7 @@ export class SolendActionCore {
567586
reserve: ReserveType,
568587
connection: Connection,
569588
amount: string,
570-
wallet: Wallet,
589+
wallet: SaveWallet,
571590
config: ActionConfigType
572591
) {
573592
const axn = await SolendActionCore.initialize(
@@ -589,7 +608,7 @@ export class SolendActionCore {
589608
reserve: ReserveType,
590609
connection: Connection,
591610
amount: string,
592-
wallet: Wallet,
611+
wallet: SaveWallet,
593612
config: ActionConfigType
594613
) {
595614
const axn = await SolendActionCore.initialize(
@@ -613,7 +632,7 @@ export class SolendActionCore {
613632
reserve: ReserveType,
614633
connection: Connection,
615634
amount: string,
616-
wallet: Wallet,
635+
wallet: SaveWallet,
617636
config: ActionConfigType
618637
) {
619638
const axn = await SolendActionCore.initialize(
@@ -637,7 +656,7 @@ export class SolendActionCore {
637656
reserve: ReserveType,
638657
connection: Connection,
639658
amount: string,
640-
wallet: Wallet,
659+
wallet: SaveWallet,
641660
config: ActionConfigType
642661
) {
643662
const axn = await SolendActionCore.initialize(
@@ -661,7 +680,7 @@ export class SolendActionCore {
661680
withdrawReserve: ReserveType,
662681
connection: Connection,
663682
amount: string,
664-
wallet: Wallet,
683+
wallet: SaveWallet,
665684
config: ActionConfigType
666685
) {
667686
const axn = await SolendActionCore.initialize(
@@ -1220,9 +1239,7 @@ export class SolendActionCore {
12201239
1
12211240
);
12221241

1223-
const crossbar = new CrossbarClient(
1224-
"https://crossbar.switchboard.xyz/"
1225-
);
1242+
const crossbar = new CrossbarClient("https://crossbar.save.finance");
12261243

12271244
const res = sbPulledOracles.reduce((acc, _curr, i) => {
12281245
if (!(i % 3)) {
@@ -1282,7 +1299,7 @@ export class SolendActionCore {
12821299
);
12831300
const pythSolanaReceiver = new PythSolanaReceiver({
12841301
connection: this.connection,
1285-
wallet: this.wallet,
1302+
wallet: this.wallet as any as NodeWallet,
12861303
});
12871304
const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({
12881305
closeUpdateAccounts: true,

solend-sdk/src/core/margin.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ import {
3737
import BigNumber from "bignumber.js";
3838
import BN from "bn.js";
3939
import JSBI from "jsbi";
40-
import { Wallet } from "@coral-xyz/anchor";
41-
import { SolendActionCore } from "./actions";
40+
import { SaveWallet, SolendActionCore } from "./actions";
4241
import { repayMaxObligationLiquidityInstruction } from "../instructions/repayMaxObligationLiquidity";
4342
import { depositMaxReserveLiquidityAndObligationCollateralInstruction } from "../instructions/depositMaxReserveLiquidityAndObligationCollateral";
4443

@@ -54,7 +53,7 @@ export class Margin {
5453

5554
obligation?: ObligationType;
5655

57-
wallet: Wallet;
56+
wallet: SaveWallet;
5857

5958
obligationAddress: PublicKey;
6059

@@ -84,7 +83,7 @@ export class Margin {
8483

8584
constructor(
8685
connection: Connection,
87-
wallet: Wallet,
86+
wallet: SaveWallet,
8887
longReserve: ReserveType,
8988
shortReserve: ReserveType,
9089
pool: PoolType,

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

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export async function fetchPrices(
4343
pythOracleData.owner.toBase58() ===
4444
pythSolanaReceiver.receiver.programId.toBase58()
4545
) {
46-
// pythData = pythSolanaReceiver.receiver.coder.accounts.decode(
47-
// 'priceUpdateV2',
48-
// pythOracleData.data,
49-
// );
5046
const priceUpdate =
5147
pythSolanaReceiver.receiver.account.priceUpdateV2.coder.accounts.decode(
5248
"priceUpdateV2",

solend-sdk/src/instructions/initReserve.ts

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ export const initReserveInstruction = (
121121
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
122122
];
123123

124+
if (config.extraOracle) {
125+
keys.push({
126+
pubkey: config.extraOracle,
127+
isSigner: false,
128+
isWritable: false,
129+
});
130+
}
131+
124132
return new TransactionInstruction({
125133
keys,
126134
programId: lendingProgramId,

0 commit comments

Comments
 (0)