From dee4191d2d11ee8324db96cf86c3c2e526016f60 Mon Sep 17 00:00:00 2001 From: 0xodia <0xodia@solend.fi> Date: Thu, 21 Nov 2024 14:04:22 -0500 Subject: [PATCH] better wallet types --- solend-sdk/package.json | 2 +- solend-sdk/src/core/actions.ts | 55 ++++++++++++++-------- solend-sdk/src/core/margin.ts | 7 ++- solend-sdk/src/core/utils/prices.ts | 4 -- solend-sdk/src/instructions/initReserve.ts | 8 ++++ 5 files changed, 48 insertions(+), 28 deletions(-) diff --git a/solend-sdk/package.json b/solend-sdk/package.json index 9c304094..16d5b1e5 100644 --- a/solend-sdk/package.json +++ b/solend-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@solendprotocol/solend-sdk", - "version": "0.13.23", + "version": "0.13.29", "private": true, "main": "src/index.ts", "module": "src/index.ts", diff --git a/solend-sdk/src/core/actions.ts b/solend-sdk/src/core/actions.ts index cb6eb939..5c37a5d4 100644 --- a/solend-sdk/src/core/actions.ts +++ b/solend-sdk/src/core/actions.ts @@ -59,12 +59,23 @@ import { PullFeed, ON_DEMAND_MAINNET_PID, } from "@switchboard-xyz/on-demand"; -import { Wallet } from "@coral-xyz/anchor"; import { createDepositAndMintWrapperTokensInstruction, createWithdrawAndBurnWrapperTokensInstruction, } from "@solendprotocol/token2022-wrapper-sdk"; import { ReserveType } from "./utils"; +import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; + +export type SaveWallet = { + publicKey: PublicKey; + name: string; + signTransaction( + tx: T + ): Promise; + signAllTransactions( + txs: T[] + ): Promise; +}; const SOL_PADDING_FOR_INTEREST = "1000000"; @@ -153,6 +164,9 @@ type InputPoolType = { reserves: Array; }; +export const CROSSBAR_URL1 = "https://crossbar.save.finance"; +export const CROSSBAR_URL2 = "https://crossbar.switchboard.xyz"; + export class SolendActionCore { programId: PublicKey; @@ -201,7 +215,7 @@ export class SolendActionCore { jitoTipAmount: number; - wallet: Wallet; + wallet: SaveWallet; debug: boolean; @@ -224,12 +238,14 @@ export class SolendActionCore { computeUnitLimit?: number; + errors: Array = []; + private constructor( programId: PublicKey, connection: Connection, reserve: ReserveType, pool: InputPoolType, - wallet: Wallet, + wallet: SaveWallet, obligationAddress: PublicKey, obligationAccountInfo: Obligation | null, userTokenAccountAddress: PublicKey, @@ -298,7 +314,7 @@ export class SolendActionCore { reserve: ReserveType, action: ActionType, amount: BN, - wallet: Wallet, + wallet: SaveWallet, connection: Connection, config: ActionConfigType ) { @@ -348,7 +364,10 @@ export class SolendActionCore { ]) ).length; - if (distinctReserveCount > POSITION_LIMIT) { + if ( + distinctReserveCount > POSITION_LIMIT && + ["deposit", "borrow"].includes(action) + ) { throw Error( `Obligation already has max number of positions: ${POSITION_LIMIT}` ); @@ -448,7 +467,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, obligationAddress: PublicKey, config: ActionConfigType ) { @@ -476,7 +495,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -500,7 +519,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -523,7 +542,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -545,7 +564,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -567,7 +586,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -589,7 +608,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -613,7 +632,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -637,7 +656,7 @@ export class SolendActionCore { reserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -661,7 +680,7 @@ export class SolendActionCore { withdrawReserve: ReserveType, connection: Connection, amount: string, - wallet: Wallet, + wallet: SaveWallet, config: ActionConfigType ) { const axn = await SolendActionCore.initialize( @@ -1220,9 +1239,7 @@ export class SolendActionCore { 1 ); - const crossbar = new CrossbarClient( - "https://crossbar.switchboard.xyz/" - ); + const crossbar = new CrossbarClient("https://crossbar.save.finance"); const res = sbPulledOracles.reduce((acc, _curr, i) => { if (!(i % 3)) { @@ -1282,7 +1299,7 @@ export class SolendActionCore { ); const pythSolanaReceiver = new PythSolanaReceiver({ connection: this.connection, - wallet: this.wallet, + wallet: this.wallet as any as NodeWallet, }); const transactionBuilder = pythSolanaReceiver.newTransactionBuilder({ closeUpdateAccounts: true, diff --git a/solend-sdk/src/core/margin.ts b/solend-sdk/src/core/margin.ts index f6b86b06..a1920e03 100644 --- a/solend-sdk/src/core/margin.ts +++ b/solend-sdk/src/core/margin.ts @@ -37,8 +37,7 @@ import { import BigNumber from "bignumber.js"; import BN from "bn.js"; import JSBI from "jsbi"; -import { Wallet } from "@coral-xyz/anchor"; -import { SolendActionCore } from "./actions"; +import { SaveWallet, SolendActionCore } from "./actions"; import { repayMaxObligationLiquidityInstruction } from "../instructions/repayMaxObligationLiquidity"; import { depositMaxReserveLiquidityAndObligationCollateralInstruction } from "../instructions/depositMaxReserveLiquidityAndObligationCollateral"; @@ -54,7 +53,7 @@ export class Margin { obligation?: ObligationType; - wallet: Wallet; + wallet: SaveWallet; obligationAddress: PublicKey; @@ -84,7 +83,7 @@ export class Margin { constructor( connection: Connection, - wallet: Wallet, + wallet: SaveWallet, longReserve: ReserveType, shortReserve: ReserveType, pool: PoolType, diff --git a/solend-sdk/src/core/utils/prices.ts b/solend-sdk/src/core/utils/prices.ts index b44a0eea..e889c4a7 100644 --- a/solend-sdk/src/core/utils/prices.ts +++ b/solend-sdk/src/core/utils/prices.ts @@ -43,10 +43,6 @@ export async function fetchPrices( pythOracleData.owner.toBase58() === pythSolanaReceiver.receiver.programId.toBase58() ) { - // pythData = pythSolanaReceiver.receiver.coder.accounts.decode( - // 'priceUpdateV2', - // pythOracleData.data, - // ); const priceUpdate = pythSolanaReceiver.receiver.account.priceUpdateV2.coder.accounts.decode( "priceUpdateV2", diff --git a/solend-sdk/src/instructions/initReserve.ts b/solend-sdk/src/instructions/initReserve.ts index 055c49b2..49a9d605 100644 --- a/solend-sdk/src/instructions/initReserve.ts +++ b/solend-sdk/src/instructions/initReserve.ts @@ -121,6 +121,14 @@ export const initReserveInstruction = ( { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; + if (config.extraOracle) { + keys.push({ + pubkey: config.extraOracle, + isSigner: false, + isWritable: false, + }); + } + return new TransactionInstruction({ keys, programId: lendingProgramId,