Skip to content

Commit

Permalink
eclipse changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xodia committed Nov 7, 2024
1 parent 5c46e88 commit 622ee02
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 50 deletions.
1 change: 1 addition & 0 deletions solend-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts.ts
__tests__/scripts.test.ts
dist/
node_modules/
4 changes: 2 additions & 2 deletions solend-sdk/__tests__/oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { PythSolanaReceiver, pythSolanaReceiverIdl } from "@pythnetwork/pyth-solana-receiver";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider, Program } from "@coral-xyz/anchor-30";
import { CrossbarClient, loadLookupTables, PullFeed, SB_ON_DEMAND_PID } from "@switchboard-xyz/on-demand";
import { CrossbarClient, loadLookupTables, PullFeed, ON_DEMAND_MAINNET_PID } from "@switchboard-xyz/on-demand";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";

jest.setTimeout(50_000);
Expand All @@ -29,7 +29,7 @@ import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
const provider = new AnchorProvider(connection, new NodeWallet(Keypair.fromSecretKey(new Uint8Array(
testKey
))), {});
const idl = (await Program.fetchIdl(SB_ON_DEMAND_PID, provider))!;
const idl = (await Program.fetchIdl(ON_DEMAND_MAINNET_PID, provider))!;
const sbod = new Program(idl, provider);

const sbPulledOracles = [
Expand Down
2 changes: 1 addition & 1 deletion solend-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@project-serum/anchor": "^0.24.2",
"@pythnetwork/client": "^2.12.0",
"@pythnetwork/price-service-client": "^1.9.0",
"@pythnetwork/pyth-solana-receiver": "^0.8.0",
"@pythnetwork/pyth-solana-receiver": "^0.8.2",
"@solana/buffer-layout": "=4.0.1",
"@solana/spl-token": "^0.3.7",
"@solana/web3.js": "=1.92.3",
Expand Down
67 changes: 40 additions & 27 deletions solend-sdk/src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import {
createWithdrawAndBurnWrapperTokensInstruction,
} from "@solendprotocol/token2022-wrapper-sdk";
import { ReserveType } from "./utils";
import { getSizeOfTransaction } from "../transaction";

const SOL_PADDING_FOR_INTEREST = "1000000";

Expand All @@ -80,6 +79,8 @@ type ActionConfigType = {
token2022Mint?: string;
repayToken2022Mint?: string;
debug?: boolean;
computeUnitPriceMicroLamports?: number;
computeUnitLimit?: number;
};

type SupportType =
Expand Down Expand Up @@ -219,6 +220,10 @@ export class SolendActionCore {

environment: EnvironmentType;

computeUnitPriceMicroLamports?: number;

computeUnitLimit?: number;

private constructor(
programId: PublicKey,
connection: Connection,
Expand Down Expand Up @@ -250,6 +255,8 @@ export class SolendActionCore {
token2022Mint?: PublicKey;
wrappedAta?: PublicKey;
debug?: boolean;
computeUnitPriceMicroLamports?: number;
computeUnitLimit?: number;
}
) {
this.programId = programId;
Expand Down Expand Up @@ -282,6 +289,8 @@ export class SolendActionCore {
// temporarily default to true
this.debug = config?.debug ?? true;
this.environment = config?.environment ?? "production";
this.computeUnitPriceMicroLamports = config?.computeUnitPriceMicroLamports;
this.computeUnitLimit = config?.computeUnitLimit;
}

static async initialize(
Expand Down Expand Up @@ -391,7 +400,6 @@ export class SolendActionCore {
amount,
depositReserves,
borrowReserves,

{
environment: config.environment,
hostAta: config.hostAta,
Expand Down Expand Up @@ -428,6 +436,9 @@ export class SolendActionCore {
TOKEN_2022_PROGRAM_ID
)
: undefined,
debug: config.debug,
computeUnitPriceMicroLamports: config.computeUnitPriceMicroLamports,
computeUnitLimit: config.computeUnitLimit,
}
);
}
Expand Down Expand Up @@ -675,7 +686,7 @@ export class SolendActionCore {
return new VersionedTransaction(
new TransactionMessage({
payerKey: this.publicKey,
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash,
instructions: [
...this.preTxnIxs,
...this.setupIxs,
Expand All @@ -702,17 +713,17 @@ export class SolendActionCore {
if (this.preTxnIxs.length) {
txns.preLendingTxn = new Transaction({
feePayer: this.publicKey,
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash,
}).add(...this.preTxnIxs);
}
txns.lendingTxn = new Transaction({
feePayer: this.publicKey,
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash,
}).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
if (this.postTxnIxs.length) {
txns.postLendingTxn = new Transaction({
feePayer: this.publicKey,
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
recentBlockhash: (await this.connection.getLatestBlockhash()).blockhash,
}).add(...this.postTxnIxs);
}
return txns;
Expand Down Expand Up @@ -754,6 +765,14 @@ export class SolendActionCore {
pullPriceTxns: null,
};

const priorityFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: this.computeUnitPriceMicroLamports ?? 500_000,
});

const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: this.computeUnitLimit ?? 1_000_000,
});

if (this.pullPriceTxns.length) {
txns.pullPriceTxns = this.pullPriceTxns;
}
Expand All @@ -763,7 +782,7 @@ export class SolendActionCore {
new TransactionMessage({
payerKey: this.publicKey,
recentBlockhash: blockhash.blockhash,
instructions: this.preTxnIxs,
instructions: [priorityFeeIx, modifyComputeUnits, ...this.preTxnIxs],
}).compileToV0Message()
);
}
Expand All @@ -780,13 +799,6 @@ export class SolendActionCore {
instructions.push(tip);
}

const priorityFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1_000_000,
});
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: 1_000_000,
});

txns.lendingTxn = new VersionedTransaction(
new TransactionMessage({
payerKey: this.publicKey,
Expand All @@ -802,7 +814,7 @@ export class SolendActionCore {
new TransactionMessage({
payerKey: this.publicKey,
recentBlockhash: blockhash.blockhash,
instructions: this.postTxnIxs,
instructions: [priorityFeeIx, modifyComputeUnits, ...this.postTxnIxs],
}).compileToV0Message()
);
}
Expand Down Expand Up @@ -1167,6 +1179,13 @@ export class SolendActionCore {
}

private async buildPullPriceTxns(oracleKeys: Array<string>) {
const priorityFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: this.computeUnitPriceMicroLamports ?? 1_000_000,
});
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
units: 1_000_000,
});

const oracleAccounts = await this.connection.getMultipleAccountsInfo(
oracleKeys.map((o) => new PublicKey(o)),
"processed"
Expand Down Expand Up @@ -1230,15 +1249,6 @@ export class SolendActionCore {
accountLookups
);

const priorityFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1_000_000,
});
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit(
{
units: 1_000_000,
}
);

const instructions = [priorityFeeIx, modifyComputeUnits, ix];

if (this.debug)
Expand Down Expand Up @@ -1326,9 +1336,13 @@ export class SolendActionCore {
0 // shardId of 0
);

transactionBuilder.addInstructions([
{ instruction: priorityFeeIx, signers: [] },
{ instruction: modifyComputeUnits, signers: [] },
]);

const transactionsWithSigners =
await transactionBuilder.buildVersionedTransactions({
tightComputeBudget: true,
jitoTipLamports: this.pullPriceTxns.length
? undefined
: this.jitoTipAmount,
Expand All @@ -1337,6 +1351,7 @@ export class SolendActionCore {
for (const transaction of transactionsWithSigners) {
const signers = transaction.signers;
const tx = transaction.tx;

if (signers) {
tx.sign(signers);
}
Expand All @@ -1363,8 +1378,6 @@ export class SolendActionCore {
])
);

console.log(allReserveAddresses);

await this.buildPullPriceTxns([
...allReserveAddresses.map((address) => reserveMap[address].pythOracle),
...allReserveAddresses.map(
Expand Down
9 changes: 5 additions & 4 deletions solend-sdk/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Cluster, PublicKey } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";
import BigNumber from "bignumber.js";
import { EnvironmentType } from "./types";
export const WAD = "1".concat(Array(18 + 1).join("0"));
export const POSITION_LIMIT = 6;
export const SOL_PADDING_FOR_INTEREST = "1000000";
export const SLOTS_PER_YEAR = 63072000;
export const WRAPPER_PROGRAM_ID = new PublicKey(
"3JmCcXAjmBpFzHHuUpgJFfTQEQnAR7K1erNLtWV1g7d9"
);
export const WRAPPER_PROGRAM_ID =
process.env.NEXT_PUBLIC_BRANCH === "eclipse"
? new PublicKey("55ttmJsE9v5PtScfnA2q6S9VXgSPopV6WziiwH94SYws")
: new PublicKey("3JmCcXAjmBpFzHHuUpgJFfTQEQnAR7K1erNLtWV1g7d9");
export const SOLEND_ADDRESSES = [
"5pHk2TmnqQzRF9L6egy5FfiyBgS7G9cMZ5RFaJAvghzw",
"yaDPAockQPna7Srx5LB2TugJSKHUduHghyZdQcn7zYz",
Expand Down
Loading

0 comments on commit 622ee02

Please sign in to comment.