Skip to content

Commit

Permalink
better wallet types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xodia committed Nov 21, 2024
1 parent c436e09 commit dee4191
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion solend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
55 changes: 36 additions & 19 deletions solend-sdk/src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Transaction | VersionedTransaction>(
tx: T
): Promise<T>;
signAllTransactions<T extends Transaction | VersionedTransaction>(
txs: T[]
): Promise<T[]>;
};

const SOL_PADDING_FOR_INTEREST = "1000000";

Expand Down Expand Up @@ -153,6 +164,9 @@ type InputPoolType = {
reserves: Array<ReserveType>;
};

export const CROSSBAR_URL1 = "https://crossbar.save.finance";
export const CROSSBAR_URL2 = "https://crossbar.switchboard.xyz";

export class SolendActionCore {
programId: PublicKey;

Expand Down Expand Up @@ -201,7 +215,7 @@ export class SolendActionCore {

jitoTipAmount: number;

wallet: Wallet;
wallet: SaveWallet;

debug: boolean;

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

computeUnitLimit?: number;

errors: Array<any> = [];

private constructor(
programId: PublicKey,
connection: Connection,
reserve: ReserveType,
pool: InputPoolType,
wallet: Wallet,
wallet: SaveWallet,
obligationAddress: PublicKey,
obligationAccountInfo: Obligation | null,
userTokenAccountAddress: PublicKey,
Expand Down Expand Up @@ -298,7 +314,7 @@ export class SolendActionCore {
reserve: ReserveType,
action: ActionType,
amount: BN,
wallet: Wallet,
wallet: SaveWallet,
connection: Connection,
config: ActionConfigType
) {
Expand Down Expand Up @@ -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}`
);
Expand Down Expand Up @@ -448,7 +467,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
obligationAddress: PublicKey,
config: ActionConfigType
) {
Expand Down Expand Up @@ -476,7 +495,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -500,7 +519,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -523,7 +542,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -545,7 +564,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -567,7 +586,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -589,7 +608,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -613,7 +632,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -637,7 +656,7 @@ export class SolendActionCore {
reserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand All @@ -661,7 +680,7 @@ export class SolendActionCore {
withdrawReserve: ReserveType,
connection: Connection,
amount: string,
wallet: Wallet,
wallet: SaveWallet,
config: ActionConfigType
) {
const axn = await SolendActionCore.initialize(
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions solend-sdk/src/core/margin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -54,7 +53,7 @@ export class Margin {

obligation?: ObligationType;

wallet: Wallet;
wallet: SaveWallet;

obligationAddress: PublicKey;

Expand Down Expand Up @@ -84,7 +83,7 @@ export class Margin {

constructor(
connection: Connection,
wallet: Wallet,
wallet: SaveWallet,
longReserve: ReserveType,
shortReserve: ReserveType,
pool: PoolType,
Expand Down
4 changes: 0 additions & 4 deletions solend-sdk/src/core/utils/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions solend-sdk/src/instructions/initReserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dee4191

Please sign in to comment.