Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: fix api failure due to missing dep #224

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions anchor/src/client/investor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as anchor from "@coral-xyz/anchor";
import { BN } from "@coral-xyz/anchor";
import {
Keypair,
PublicKey,
SystemProgram,
TransactionInstruction,
Expand All @@ -11,7 +9,6 @@ import {
import {
getAssociatedTokenAddressSync,
createAssociatedTokenAccountInstruction,
TOKEN_2022_PROGRAM_ID,
createSyncNativeInstruction,
} from "@solana/spl-token";

Expand Down Expand Up @@ -145,8 +142,8 @@ export class InvestorClient {
signerAssetAtaExists = false;
}
const solBalance = new BN(String(await connection.getBalance(signer)));
const delta = amount - wsolBalance;
if (delta > 0 && solBalance > delta) {
const delta = amount.sub(wsolBalance);
if (delta > new BN(0) && solBalance > delta) {
if (!signerAssetAtaExists) {
preInstructions = preInstructions.concat([
createAssociatedTokenAccountInstruction(
Expand All @@ -161,7 +158,7 @@ export class InvestorClient {
SystemProgram.transfer({
fromPubkey: signer,
toPubkey: signerAssetAta,
lamports: delta,
lamports: delta.toNumber(),
}),
createSyncNativeInstruction(signerAssetAta),
]);
Expand Down
6 changes: 3 additions & 3 deletions anchor/src/client/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class JupiterClient {
const outputMint = new PublicKey(
quoteParams?.outputMint || quoteResponse!.outputMint
);
const amount = new BN(quoteParams?.amount || quoteResponse?.inAmount);
const amount = new BN(quoteParams?.amount || quoteResponse!.inAmount);

if (swapInstructions === undefined) {
// Fetch quoteResponse if not specified - quoteParams must be specified in this case
Expand Down Expand Up @@ -253,13 +253,13 @@ export class JupiterClient {
const solBalance = new BN(
await this.base.provider.connection.getBalance(treasuryPda)
);
const delta = amount - wsolBalance;
const delta = amount.sub(wsolBalance);
if (solBalance < delta) {
throw new Error(
`Insufficient balance in treasury (${treasuryPda.toBase58()}) for swap. solBalance: ${solBalance}, lamports needed: ${delta}`
);
}
if (delta > 0 && solBalance > delta) {
if (delta > new BN(0) && solBalance > delta) {
preInstructions.push(
await this.base.program.methods
.wsolWrap(new BN(amount))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"private": true,
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@drift-labs/sdk": "2.96.0-beta.14",
"@fast-csv/format": "^5.0.0",
"@fast-csv/parse": "^5.0.0",
"@hookform/resolvers": "^3.9.0",
Expand Down Expand Up @@ -97,7 +98,6 @@
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@drift-labs/sdk": "2.71.0-beta.4",
"@nx/eslint": "^19.4.1",
"@nx/eslint-plugin": "^19.4.1",
"@nx/express": "19.3.2",
Expand Down
Loading