Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mijoco/stx_helpers

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mijoco/stx_helpers - npm Package Compare versions

Comparing version 0.0.9 to 0.1.0

6

dist/account/account.js

@@ -16,2 +16,3 @@ "use strict";

const custom_node_1 = require("../custom-node");
const stacks_node_1 = require("../stacks-node");
const appConfig = new connect_1.AppConfig(['store_write', 'publish_data']);

@@ -33,5 +34,6 @@ exports.userSession = new connect_1.UserSession({ appConfig }); // we will use this export from other files

try {
result = yield (0, custom_node_1.getBitcoinBalances)(api, stxAddress, cardinal, ordinal);
result.tokenBalances = yield (0, stacks_node_1.getTokenBalances)(api, stxAddress);
result.walletBalances = yield (0, custom_node_1.getWalletBalances)(api, stxAddress, cardinal, ordinal);
try {
result.sBTCBalance = Number((_a = result.stacksTokenInfo) === null || _a === void 0 ? void 0 : _a.fungible_tokens[contractId + '::sbtc'].balance);
result.sBTCBalance = Number((_a = result.tokenBalances) === null || _a === void 0 ? void 0 : _a.fungible_tokens[contractId + '::sbtc'].balance);
}

@@ -38,0 +40,0 @@ catch (err) {

@@ -1,4 +0,5 @@

export declare function getBitcoinBalances(api: string, stxAddress: string, cardinal: string, ordinal: string): Promise<any>;
import { WalletBalances } from "../sbtc";
export declare function getWalletBalances(api: string, stxAddress: string, cardinal: string, ordinal: string): Promise<WalletBalances>;
export declare function fetchSbtcWalletAddress(api: string): Promise<any>;
export declare function getBalanceAtHeight(api: string, stxAddress: string, height: number): Promise<any>;
export declare function getStackerInfo(api: string, address: string, cycle: number): Promise<any>;

@@ -12,9 +12,24 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getStackerInfo = exports.getBalanceAtHeight = exports.fetchSbtcWalletAddress = exports.getBitcoinBalances = void 0;
function getBitcoinBalances(api, stxAddress, cardinal, ordinal) {
exports.getStackerInfo = exports.getBalanceAtHeight = exports.fetchSbtcWalletAddress = exports.getWalletBalances = void 0;
function getWalletBalances(api, stxAddress, cardinal, ordinal) {
return __awaiter(this, void 0, void 0, function* () {
return fetchUserBalances(api, stxAddress, cardinal, ordinal);
var _a, _b, _c, _d;
const rawBal = yield fetchUserBalances(api, stxAddress, cardinal, ordinal);
return {
stacks: {
address: stxAddress,
amount: Number(((_b = (_a = rawBal === null || rawBal === void 0 ? void 0 : rawBal.tokenBalances) === null || _a === void 0 ? void 0 : _a.stx) === null || _b === void 0 ? void 0 : _b.balance) || '0')
},
cardinal: {
address: ((_c = rawBal.cardinalInfo) === null || _c === void 0 ? void 0 : _c.address) || 'unknown',
amount: bitcoinBalanceFromMempool(rawBal === null || rawBal === void 0 ? void 0 : rawBal.cardinalInfo)
},
ordinal: {
address: ((_d = rawBal.ordinalInfo) === null || _d === void 0 ? void 0 : _d.address) || 'unknown',
amount: bitcoinBalanceFromMempool(rawBal === null || rawBal === void 0 ? void 0 : rawBal.ordinalInfo)
}
};
});
}
exports.getBitcoinBalances = getBitcoinBalances;
exports.getWalletBalances = getWalletBalances;
function fetchSbtcWalletAddress(api) {

@@ -29,2 +44,8 @@ return __awaiter(this, void 0, void 0, function* () {

exports.fetchSbtcWalletAddress = fetchSbtcWalletAddress;
function bitcoinBalanceFromMempool(addressMempoolObject) {
var _a;
if (!addressMempoolObject)
return 0;
return (((_a = addressMempoolObject === null || addressMempoolObject === void 0 ? void 0 : addressMempoolObject.chain_stats) === null || _a === void 0 ? void 0 : _a.funded_txo_sum) - addressMempoolObject.chain_stats.spent_txo_sum) || 0;
}
function fetchUserBalances(api, stxAddress, cardinal, ordinal) {

@@ -31,0 +52,0 @@ return __awaiter(this, void 0, void 0, function* () {

@@ -207,4 +207,5 @@ import { InFlight, GovernanceData, ProposalEvent, SoloPoolData } from './dao';

sBTCBalance: number;
stxBalance: number;
stacksTokenInfo?: AddressHiroObject;
tokenBalances?: TokenBalances;
walletBalances?: WalletBalances;
stxBalance?: number;
bnsNameInfo?: any;

@@ -216,2 +217,16 @@ cardinalInfo?: AddressMempoolObject;

};
export type WalletBalances = {
stacks: {
address: string;
amount: number;
};
cardinal: {
address: string;
amount: number;
};
ordinal: {
address: string;
amount: number;
};
};
export type AddressMempoolObject = {

@@ -234,3 +249,3 @@ address: string;

};
export type AddressHiroObject = {
export type TokenBalances = {
stx: {

@@ -237,0 +252,0 @@ balance: number;

import { StacksMainnet, StacksTestnet } from "@stacks/network";
import { TokenBalances } from "../sbtc";
export declare function fetchDataVar(stacksApi: string, contractAddress: string, contractName: string, dataVarName: string): Promise<any>;

@@ -7,4 +8,4 @@ export declare function getStacksNetwork(network: string): StacksMainnet | StacksTestnet;

export declare function fetchStacksInfo(stacksApi: string): Promise<any>;
export declare function getStacksBalances(stacksApi: string, principal: string): Promise<any>;
export declare function getTokenBalances(stacksApi: string, principal: string): Promise<TokenBalances>;
export declare function getPoxInfo(stacksApi: string): Promise<any>;
export declare function fetchExchangeRates(stxEcoApi: string): Promise<any>;

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchExchangeRates = exports.getPoxInfo = exports.getStacksBalances = exports.fetchStacksInfo = exports.isConstructed = exports.lookupContract = exports.getStacksNetwork = exports.fetchDataVar = void 0;
exports.fetchExchangeRates = exports.getPoxInfo = exports.getTokenBalances = exports.fetchStacksInfo = exports.isConstructed = exports.lookupContract = exports.getStacksNetwork = exports.fetchDataVar = void 0;
const network_1 = require("@stacks/network");

@@ -78,3 +78,3 @@ function fetchDataVar(stacksApi, contractAddress, contractName, dataVarName) {

exports.fetchStacksInfo = fetchStacksInfo;
function getStacksBalances(stacksApi, principal) {
function getTokenBalances(stacksApi, principal) {
return __awaiter(this, void 0, void 0, function* () {

@@ -87,3 +87,3 @@ const path = `${stacksApi}/extended/v1/address/${principal}/balances`;

}
exports.getStacksBalances = getStacksBalances;
exports.getTokenBalances = getTokenBalances;
function getPoxInfo(stacksApi) {

@@ -90,0 +90,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"name": "@mijoco/stx_helpers",
"version": "0.0.9",
"version": "0.1.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc