Skip to content

Commit

Permalink
update input types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xodia committed Jan 16, 2025
1 parent 48c5213 commit 9be5470
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 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.39",
"version": "0.13.42",
"private": true,
"main": "src/index.ts",
"module": "src/index.ts",
Expand Down
67 changes: 42 additions & 25 deletions solend-sdk/src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,21 @@ 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";

export type InputReserveType = {
address: string;
liquidityAddress: string;
cTokenMint: string;
cTokenLiquidityAddress: string;
pythOracle: string;
switchboardOracle: string;
mintAddress: string;
liquidityFeeReceiverAddress: string;
};

type ActionConfigType = {
environment?: EnvironmentType;
customObligationAddress?: PublicKey;
Expand Down Expand Up @@ -158,12 +162,21 @@ export type ActionType =
| "forgive"
| "liquidate";

type InputPoolReserveType = {
address: string;
pythOracle: string;
switchboardOracle: string;
mintAddress: string;
liquidityFeeReceiverAddress: string;
extraOracle?: string;
};

type InputPoolType = {
address: string;
owner: string;
name: string | null;
authorityAddress: string;
reserves: Array<ReserveType>;
reserves: Array<InputPoolReserveType>;
};

export type InstructionWithSigners = {
Expand All @@ -188,7 +201,7 @@ export class SolendActionCore {

connection: Connection;

reserve: ReserveType;
reserve: InputReserveType;

pool: InputPoolType;

Expand Down Expand Up @@ -263,7 +276,7 @@ export class SolendActionCore {
private constructor(
programId: PublicKey,
connection: Connection,
reserve: ReserveType,
reserve: InputReserveType,
pool: InputPoolType,
wallet: SaveWallet,
obligationAddress: PublicKey,
Expand Down Expand Up @@ -333,7 +346,7 @@ export class SolendActionCore {

static async initialize(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
action: ActionType,
amount: BN,
wallet: SaveWallet,
Expand Down Expand Up @@ -490,7 +503,7 @@ export class SolendActionCore {

static async buildForgiveTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand Down Expand Up @@ -518,7 +531,7 @@ export class SolendActionCore {

static async buildDepositTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -542,7 +555,7 @@ export class SolendActionCore {

static async buildBorrowTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -565,7 +578,7 @@ export class SolendActionCore {
}
static async buildDepositReserveLiquidityTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -587,7 +600,7 @@ export class SolendActionCore {

static async buildRedeemReserveCollateralTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -609,7 +622,7 @@ export class SolendActionCore {

static async buildDepositObligationCollateralTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -631,7 +644,7 @@ export class SolendActionCore {

static async buildWithdrawCollateralTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -655,7 +668,7 @@ export class SolendActionCore {

static async buildWithdrawTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -679,7 +692,7 @@ export class SolendActionCore {

static async buildRepayTxns(
pool: InputPoolType,
reserve: ReserveType,
reserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand All @@ -703,7 +716,7 @@ export class SolendActionCore {

static async buildLiquidateTxns(
pool: InputPoolType,
withdrawReserve: ReserveType,
withdrawReserve: InputReserveType,
connection: Connection,
amount: string,
wallet: SaveWallet,
Expand Down Expand Up @@ -1106,7 +1119,7 @@ export class SolendActionCore {
);
}

async addLiquidateIx(repayReserve: ReserveType) {
async addLiquidateIx(repayReserve: InputReserveType) {
if (this.debug) console.log("adding liquidate ix to lending txn");
if (
!this.repayInfo?.userRepayCollateralAccountAddress ||
Expand All @@ -1128,7 +1141,7 @@ export class SolendActionCore {
new PublicKey(this.reserve.cTokenMint),
new PublicKey(this.reserve.cTokenLiquidityAddress),
new PublicKey(this.reserve.liquidityAddress),
new PublicKey(this.reserve.feeReceiverAddress),
new PublicKey(this.reserve.liquidityFeeReceiverAddress),
this.obligationAddress,
new PublicKey(this.pool.address),
new PublicKey(this.pool.authorityAddress),
Expand Down Expand Up @@ -1286,7 +1299,11 @@ export class SolendActionCore {
"processed"
);

const provider = new AnchorProvider(this.connection, this.wallet, {});
const provider = new AnchorProvider(this.connection, {
publicKey: this.wallet.publicKey,
signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise.resolve(tx),
signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise.resolve(txs as T[]),
}, {});
const idl = (await Program.fetchIdl(ON_DEMAND_MAINNET_PID, provider))!;

if (this.environment === "production" || this.environment === "beta") {
Expand Down Expand Up @@ -1477,7 +1494,7 @@ export class SolendActionCore {
const reserveMap = this.pool.reserves.reduce((acc, reserve) => {
acc[reserve.address] = reserve;
return acc;
}, {} as Record<string, ReserveType>);
}, {} as Record<string, InputPoolReserveType>);

const allReserveAddresses = Array.from(
new Set(singleReserve ? [this.reserve.address] : [
Expand Down

0 comments on commit 9be5470

Please sign in to comment.