@stabbleorg/anchor-contrib
Advanced tools
Comparing version
@@ -5,1 +5,2 @@ export * from "./wallet"; | ||
export * from "./parser"; | ||
export * from "./safeNumber"; |
@@ -21,2 +21,3 @@ "use strict"; | ||
__exportStar(require("./parser"), exports); | ||
__exportStar(require("./safeNumber"), exports); | ||
//# sourceMappingURL=index.js.map |
import { Provider } from "@coral-xyz/anchor"; | ||
import { AddressLookupTableAccount, BlockhashWithExpiryBlockHeight, ConfirmOptions, PublicKey, Signer, TokenAccountBalancePair, Transaction, TransactionInstruction, TransactionSignature, VersionedTransaction } from "@solana/web3.js"; | ||
import { PriorityLevel } from "./helius"; | ||
import { FloatLike } from "./safeNumber"; | ||
export type TransactionArgs<T> = { | ||
@@ -28,3 +29,3 @@ altAccounts?: AddressLookupTableAccount[]; | ||
closeIntermediateTokenAccountInstruction(accountAddress: PublicKey): TransactionInstruction; | ||
transferWSOLInstructions(accountAddress: PublicKey, amount: string | number): Promise<TransactionInstruction[]>; | ||
transferWSOLInstructions(accountAddress: PublicKey, amount: FloatLike): Promise<TransactionInstruction[]>; | ||
getTokenBalances(): Promise<TokenAccountBalancePair[]>; | ||
@@ -31,0 +32,0 @@ getPriorityFeeEstimate(transaction: VersionedTransaction, priorityLevel?: PriorityLevel): Promise<number>; |
@@ -17,5 +17,5 @@ "use strict"; | ||
const bs58_1 = __importDefault(require("bs58")); | ||
const decimal_js_1 = require("decimal.js"); | ||
const spl_token_1 = require("@solana/spl-token"); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const safeNumber_1 = require("./safeNumber"); | ||
class WalletContext { | ||
@@ -74,3 +74,3 @@ constructor(provider) { | ||
toPubkey: accountAddress, | ||
lamports: BigInt(new decimal_js_1.Decimal(amount).mul(web3_js_1.LAMPORTS_PER_SOL).toDP(0, decimal_js_1.Decimal.ROUND_DOWN).toString()), | ||
lamports: BigInt(safeNumber_1.SafeNumber.toGiga(amount).toString()), | ||
}), (0, spl_token_1.createSyncNativeInstruction)(accountAddress)); | ||
@@ -106,3 +106,3 @@ return instructions; | ||
const balances = result.items.map((item) => { | ||
const decAmount = new decimal_js_1.Decimal(item.token_info.balance).div(new decimal_js_1.Decimal(10).pow(item.token_info.decimals)); | ||
const uiAmountString = safeNumber_1.SafeNumber.toUiAmountString(item.token_info.balance, item.token_info.decimals); | ||
return { | ||
@@ -112,8 +112,8 @@ address: new web3_js_1.PublicKey(item.id), | ||
decimals: item.token_info.decimals, | ||
uiAmountString: decAmount.toString(), | ||
uiAmount: decAmount.toNumber(), | ||
uiAmountString: uiAmountString, | ||
uiAmount: Number(uiAmountString), | ||
}; | ||
}); | ||
if (result.nativeBalance.lamports) { | ||
const decNativeAmount = new decimal_js_1.Decimal(result.nativeBalance.lamports).div(new decimal_js_1.Decimal(web3_js_1.LAMPORTS_PER_SOL)); | ||
const uiAmountString = safeNumber_1.SafeNumber.toNanoString(result.nativeBalance.lamports); | ||
balances.push({ | ||
@@ -123,4 +123,4 @@ address: spl_token_1.NATIVE_MINT, | ||
decimals: 9, | ||
uiAmountString: decNativeAmount.toString(), | ||
uiAmount: decNativeAmount.toNumber(), | ||
uiAmountString, | ||
uiAmount: Number(uiAmountString), | ||
}); | ||
@@ -127,0 +127,0 @@ } |
{ | ||
"name": "@stabbleorg/anchor-contrib", | ||
"version": "0.7.2-beta", | ||
"version": "0.7.2", | ||
"main": "dist/index.js", | ||
@@ -20,2 +20,3 @@ "types": "dist/index.d.ts", | ||
"@solana/web3.js": "^1.91.0", | ||
"bn.js": "^5.2.1", | ||
"bs58": "^5.0.0", | ||
@@ -25,2 +26,3 @@ "decimal.js": "^10.4.3" | ||
"devDependencies": { | ||
"@types/bn.js": "^5.1.5", | ||
"prettier": "^3.2.5", | ||
@@ -27,0 +29,0 @@ "typescript": "^5.4.5" |
@@ -5,1 +5,2 @@ export * from "./wallet"; | ||
export * from "./parser"; | ||
export * from "./safeNumber"; |
import bs58 from "bs58"; | ||
import { Decimal } from "decimal.js"; | ||
import { Provider } from "@coral-xyz/anchor"; | ||
@@ -21,3 +20,2 @@ import { | ||
ConfirmOptions, | ||
LAMPORTS_PER_SOL, | ||
PublicKey, | ||
@@ -34,2 +32,3 @@ Signer, | ||
import { HeliusResponse, GetPriorityFeeEstimateResponse, PriorityLevel, SearchAssetsResponse } from "./helius"; | ||
import { FloatLike, SafeNumber } from "./safeNumber"; | ||
@@ -114,6 +113,3 @@ export type TransactionArgs<T> = { | ||
async transferWSOLInstructions( | ||
accountAddress: PublicKey, | ||
amount: string | number, | ||
): Promise<TransactionInstruction[]> { | ||
async transferWSOLInstructions(accountAddress: PublicKey, amount: FloatLike): Promise<TransactionInstruction[]> { | ||
const instructions = await this.createIntermediateTokenAccountInstructions(accountAddress, NATIVE_MINT); | ||
@@ -124,3 +120,3 @@ instructions.push( | ||
toPubkey: accountAddress, | ||
lamports: BigInt(new Decimal(amount).mul(LAMPORTS_PER_SOL).toDP(0, Decimal.ROUND_DOWN).toString()), | ||
lamports: BigInt(SafeNumber.toGiga(amount).toString()), | ||
}), | ||
@@ -158,3 +154,3 @@ createSyncNativeInstruction(accountAddress), | ||
const balances = result.items.map<TokenAccountBalancePair>((item) => { | ||
const decAmount = new Decimal(item.token_info.balance).div(new Decimal(10).pow(item.token_info.decimals)); | ||
const uiAmountString = SafeNumber.toUiAmountString(item.token_info.balance, item.token_info.decimals); | ||
return { | ||
@@ -164,4 +160,4 @@ address: new PublicKey(item.id), | ||
decimals: item.token_info.decimals, | ||
uiAmountString: decAmount.toString(), | ||
uiAmount: decAmount.toNumber(), | ||
uiAmountString: uiAmountString, | ||
uiAmount: Number(uiAmountString), | ||
}; | ||
@@ -171,3 +167,3 @@ }); | ||
if (result.nativeBalance.lamports) { | ||
const decNativeAmount = new Decimal(result.nativeBalance.lamports).div(new Decimal(LAMPORTS_PER_SOL)); | ||
const uiAmountString = SafeNumber.toNanoString(result.nativeBalance.lamports); | ||
balances.push({ | ||
@@ -177,4 +173,4 @@ address: NATIVE_MINT, | ||
decimals: 9, | ||
uiAmountString: decNativeAmount.toString(), | ||
uiAmount: decNativeAmount.toNumber(), | ||
uiAmountString, | ||
uiAmount: Number(uiAmountString), | ||
}); | ||
@@ -181,0 +177,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39912
23.54%25
19.05%753
25.08%6
20%3
50%+ Added