Skip to content

Commit

Permalink
api: fix api failure due to missing dep
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Oct 1, 2024
1 parent 9276c54 commit d741672
Show file tree
Hide file tree
Showing 4 changed files with 514 additions and 49 deletions.
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
4 changes: 2 additions & 2 deletions anchor/src/client/jupiter.ts
Original file line number Diff line number Diff line change
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

0 comments on commit d741672

Please sign in to comment.