New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@avalabs/avalanche-module

Package Overview
Dependencies
Maintainers
0
Versions
507
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/avalanche-module - npm Package Compare versions

Comparing version 0.0.13 to 0.0.15

src/env.ts

17

CHANGELOG.md
# @avalabs/avalanche-module
## 0.0.15
### Patch Changes
- Updated dependencies [f536d58]
- @avalabs/vm-module-types@0.0.15
- @internal/utils@0.0.3
## 0.0.14
### Patch Changes
- 0593258: add getBalances to evm-module
- Updated dependencies [0593258]
- @avalabs/vm-module-types@0.0.14
- @internal/utils@0.0.2
## 0.0.13

@@ -4,0 +21,0 @@

13

dist/index.d.ts
import * as _metamask_rpc_errors from '@metamask/rpc-errors';
import { Module, Manifest, Network, NetworkFees, GetTransactionHistory, RpcRequest } from '@avalabs/vm-module-types';
import * as _avalabs_vm_module_types_dist_transaction_history from '@avalabs/vm-module-types/dist/transaction-history';
import { Module, Environment, GetBalancesParams, GetBalancesResponse, Manifest, Network, NetworkFees, GetTransactionHistory, RpcRequest } from '@avalabs/vm-module-types';
declare class AvalancheModule implements Module {
#private;
constructor({ environment }: {
environment: Environment;
});
getAddress(): Promise<string>;
getBalances(): Promise<string>;
getBalances(_: GetBalancesParams): Promise<GetBalancesResponse>;
getManifest(): Manifest | undefined;
getNetworkFee(_: Network): Promise<NetworkFees>;
getTransactionHistory(_: GetTransactionHistory): Promise<{
transactions: never[];
}>;
getTransactionHistory({ network, address, nextPageToken, offset }: GetTransactionHistory): Promise<_avalabs_vm_module_types_dist_transaction_history.TransactionHistoryResponse>;
getTokens(_: Network): Promise<never[]>;

@@ -13,0 +16,0 @@ onRpcRequest(request: RpcRequest, _network: Network): Promise<{

@@ -1,8 +0,11 @@

import { parseManifest } from '@avalabs/vm-module-types';
import { parseManifest, Environment, TokenType } from '@avalabs/vm-module-types';
import { rpcErrors } from '@metamask/rpc-errors';
import { Network, SortOrder, BlockchainId, Glacier, PrimaryNetworkChainName } from '@avalabs/glacier-sdk';
import u from 'big.js';
import { Avalanche } from '@avalabs/wallets-sdk';
var r={name:"Avalanche",description:"",version:"0.0.1",sources:{module:{checksum:"",location:{npm:{filePath:"dist/bundle.js",packageName:"@avalabs/avalanche-module",registry:"https://registry.npmjs.org"}}},provider:{checksum:"",location:{npm:{filePath:"dist/provider.js",packageName:"@avalabs/avalanche-module",registry:"https://registry.npmjs.org"}}}},network:{chainIds:["avax:2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM","avax:2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm","avax:11111111111111111111111111111111LpoYY"],namespaces:["avax"]},cointype:"60",permissions:{rpc:{dapps:!0,methods:["avalanche_sendTransaction","avalanche_*"]}},manifestVersion:"0.0"};async function t(){return {baseFee:BigInt(1e6),low:{maxFeePerGas:BigInt(1e6)},medium:{maxFeePerGas:BigInt(1e6)},high:{maxFeePerGas:BigInt(1e6)},isFixedFee:!0}}var s=class{getAddress(){return Promise.resolve("Avalanche address")}getBalances(){return Promise.resolve("Avalanche balances")}getManifest(){let e=parseManifest(r);return e.success?e.data:void 0}getNetworkFee(e){return t()}getTransactionHistory(e){return Promise.resolve({transactions:[]})}getTokens(e){return Promise.resolve([])}async onRpcRequest(e,m){switch(e.method){default:return {error:rpcErrors.methodNotSupported(`Method ${e.method} not supported`)}}}};
var J=Object.defineProperty;var q=(e,t,n)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var g=(e,t,n)=>(q(e,typeof t!="symbol"?t+"":t,n),n),I=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var B=(e,t,n)=>(I(e,t,"read from private field"),n?n.call(e):t.get(e)),P=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n);},b=(e,t,n,o)=>(I(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var L={name:"Avalanche",description:"",version:"0.0.1",sources:{module:{checksum:"",location:{npm:{filePath:"dist/bundle.js",packageName:"@avalabs/avalanche-module",registry:"https://registry.npmjs.org"}}},provider:{checksum:"",location:{npm:{filePath:"dist/provider.js",packageName:"@avalabs/avalanche-module",registry:"https://registry.npmjs.org"}}}},network:{chainIds:["avax:2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM","avax:2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm","avax:11111111111111111111111111111111LpoYY"],namespaces:["avax"]},cointype:"60",permissions:{rpc:{dapps:!0,methods:["avalanche_sendTransaction","avalanche_*"]}},manifestVersion:"0.0"};async function S(){return {baseFee:BigInt(1e6),low:{maxFeePerGas:BigInt(1e6)},medium:{maxFeePerGas:BigInt(1e6)},high:{maxFeePerGas:BigInt(1e6)},isFixedFee:!0}}var U=e=>e.chainInfo.chainName===PrimaryNetworkChainName.P_CHAIN,H=e=>e.chainInfo.chainName===PrimaryNetworkChainName.X_CHAIN;function f(e,t,n="tx"){return `${e}/${n}/${t}`}function h({amount:e,decimals:t}){return e===void 0?new u(0):new u(e/10**t)}function F({tx:e,address:t,networkToken:n,chainId:o,explorerUrl:r,isTestnet:c}){let i=new Set(e.consumedUtxos.flatMap(a=>a.addresses)||[]),p=new Set(e.emittedUtxos.flatMap(a=>a.addresses)||[]),s=Y({tx:e,isTestnet:c,networkToken:n,froms:i}),l=$({tx:e,isTestnet:c,networkToken:n}),d=t.toLowerCase().startsWith("p-")?t.slice(2):t,m=i.has(d);return {hash:e.txHash,isContractCall:!1,isIncoming:!m,isOutgoing:m,from:[...i.values()].join(","),to:[...p.values()].join(","),isSender:m,timestamp:e.blockTimestamp*1e3,tokens:[{decimal:n.decimals.toString(),name:n.name,symbol:n.symbol,type:TokenType.NATIVE,amount:s.toString()}],gasUsed:l.toString(),explorerLink:f(r??"",e.txHash,"tx"),txType:e.txType,chainId:o.toString()}}function Y({tx:e,isTestnet:t,networkToken:n,froms:o}){let r=["ImportTx","ExportTx"].includes(e.txType),c=e.txType==="BaseTx",i=e.emittedUtxos.filter(a=>a.asset.assetId===x(!!t)&&!a.addresses.some(T=>o.has(T))).reduce((a,T)=>a.add(T.asset.amount),new u(0)),p=e.value.find(a=>a.assetId===x(!!t))?.amount,s=i.gt(new u(0))?i:p?new u(p):new u(0)??new u(0),l=t?Avalanche.FujiContext.pBlockchainID:Avalanche.MainnetContext.pBlockchainID,d=e.emittedUtxos.filter(a=>a.asset.assetId===x(!!t)&&(e.txType==="ImportTx"&&a.consumedOnChainId===l||e.txType==="ExportTx"&&a.consumedOnChainId!==l)).reduce((a,T)=>a.add(T.amount),new u(0)),m=c?s:r?d:e.amountStaked.length===0?G(e.value,!!t):G(e.amountStaked,!!t);return h({amount:m?.toNumber(),decimals:n.decimals})}function $({tx:e,isTestnet:t,networkToken:n}){let o=e.amountBurned?.filter(r=>r.assetId===x(!!t)).reduce((r,c)=>r.add(c.amount),new u(0));return h({amount:o?.toNumber(),decimals:n.decimals})}function G(e,t){return e.filter(n=>n.assetId===x(t)).reduce((n,o)=>n.add(o.amount),new u(0))}function x(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}function X({tx:e,address:t,networkToken:n,chainId:o,explorerUrl:r,isTestnet:c}){let i=new Set(e.consumedUtxos.flatMap(a=>a.addresses)||[]),p=new Set(e.emittedUtxos.flatMap(a=>a.addresses)||[]),s=Q({tx:e,isTestnet:c,networkToken:n}),l=Z({isTestnet:c,tx:e,totalAmountCreated:s,networkToken:n}),d=t.toLowerCase().startsWith("x-")?t.slice(2):t,m=i.has(d);return {hash:e.txHash,isContractCall:!1,isIncoming:!m,isOutgoing:m,from:[...i.values()].join(","),to:[...p.values()].join(","),isSender:m,timestamp:e.timestamp*1e3,tokens:[{decimal:n.decimals.toString(),name:n.name,symbol:n.symbol,type:TokenType.NATIVE,amount:s.toString()}],gasUsed:l.toString(),explorerLink:f(r??"",e.txHash,"tx"),txType:e.txType,chainId:o.toString()}}function Q({tx:e,isTestnet:t,networkToken:n}){let o=["ImportTx","ExportTx"].includes(e.txType),r=t?Avalanche.FujiContext.xBlockchainID:Avalanche.MainnetContext.xBlockchainID,c=e.emittedUtxos.filter(s=>s.asset.assetId===A(!!t)&&(e.txType==="ImportTx"&&s.consumedOnChainId===r||e.txType==="ExportTx"&&s.consumedOnChainId!==r)).reduce((s,l)=>s.add(l.asset.amount),new u(0)),i=e.amountCreated.filter(s=>s.assetId===A(!!t)).reduce((s,l)=>s.add(l.amount),new u(0));return h({amount:(o?c:i).toNumber(),decimals:n.decimals})}function Z({isTestnet:e,tx:t,totalAmountCreated:n,networkToken:o}){let c=t.amountUnlocked.filter(i=>i.assetId===A(!!e)).reduce((i,p)=>i.add(p.amount),new u(0)).minus(n);return h({amount:c.toNumber(),decimals:o.decimals})}function A(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}var V=async({address:e,nextPageToken:t,offset:n,network:o,glacierService:r})=>{let{isTestnet:c,networkToken:i,explorerUrl:p,chainId:s}=o;if(!r.isHealthy())return {transactions:[],nextPageToken:""};let d=await r.listLatestPrimaryNetworkTransactions({addresses:e,blockchainId:te(e),network:c?Network.FUJI:Network.MAINNET,pageSize:n,pageToken:t,sortOrder:SortOrder.DESC}),m=[];return U(d)&&(m=d.transactions.map(a=>F({tx:a,isTestnet:c,address:e,networkToken:i,explorerUrl:p,chainId:s}))),H(d)&&(m=d.transactions.map(a=>X({tx:a,isTestnet:c,address:e,networkToken:i,explorerUrl:p,chainId:s}))),{transactions:m,nextPageToken:d.nextPageToken}},te=e=>e.split(",")[0]?.toLowerCase().startsWith("p-")?BlockchainId.P_CHAIN:BlockchainId.X_CHAIN;var ne={glacierApiUrl:"https://glacier-api.avax.network",proxyApiUrl:"https://proxy-api.avax.network"},ae={glacierApiUrl:"https://glacier-api-dev.avax.network",proxyApiUrl:"https://proxy-api-dev.avax.network"},O=e=>{switch(e){case Environment.PRODUCTION:return ne;case Environment.DEV:return ae}};var N=class extends Error{constructor(){super(...arguments);g(this,"message","Glacier is unhealthy. Try again later.");}},C=class{constructor({glacierApiUrl:t}){g(this,"glacierSdk");g(this,"isGlacierHealthy",!0);g(this,"isHealthy",()=>this.isGlacierHealthy);this.glacierSdk=new Glacier({BASE:t});}setGlacierToUnhealthy(){this.isGlacierHealthy=!1,setTimeout(()=>{this.isGlacierHealthy=!0;},5*60*1e3);}async listLatestPrimaryNetworkTransactions(t){try{return this.glacierSdk.primaryNetworkTransactions.listLatestPrimaryNetworkTransactions(t)}catch(n){throw n instanceof N&&this.setGlacierToUnhealthy(),n}}};var y,_=class{constructor({environment:t}){P(this,y,void 0);let{glacierApiUrl:n}=O(t);b(this,y,new C({glacierApiUrl:n}));}getAddress(){return Promise.resolve("Avalanche address")}getBalances(t){return Promise.resolve({})}getManifest(){let t=parseManifest(L);return t.success?t.data:void 0}getNetworkFee(t){return S()}getTransactionHistory({network:t,address:n,nextPageToken:o,offset:r}){return V({network:t,address:n,nextPageToken:o,offset:r,glacierService:B(this,y)})}getTokens(t){return Promise.resolve([])}async onRpcRequest(t,n){switch(t.method){default:return {error:rpcErrors.methodNotSupported(`Method ${t.method} not supported`)}}}};y=new WeakMap;
export { s as AvalancheModule };
export { _ as AvalancheModule };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map
{
"name": "@avalabs/avalanche-module",
"version": "0.0.13",
"version": "0.0.15",
"main": "dist/index.cjs",

@@ -9,10 +9,10 @@ "module": "dist/index.js",

"dependencies": {
"@avalabs/vm-module-types": "0.0.13",
"@avalabs/vm-module-types": "0.0.15",
"@metamask/rpc-errors": "6.3.0",
"@avalabs/utils-sdk": "v2.8.0-alpha.187",
"@avalabs/chains-sdk": "v2.8.0-alpha.187",
"@avalabs/etherscan-sdk": "v2.8.0-alpha.187",
"@avalabs/glacier-sdk": "v2.8.0-alpha.187",
"@avalabs/wallets-sdk": "v2.8.0-alpha.187",
"big.js": "6.2.1"
"@avalabs/utils-sdk": "v2.8.0-alpha.193",
"@avalabs/etherscan-sdk": "v2.8.0-alpha.193",
"@avalabs/glacier-sdk": "v2.8.0-alpha.193",
"@avalabs/wallets-sdk": "v2.8.0-alpha.193",
"big.js": "6.2.1",
"@internal/utils": "0.0.3"
},

@@ -26,3 +26,3 @@ "devDependencies": {

"@internal/tsup-config": "0.0.1",
"eslint-config-custom": "0.0.2"
"eslint-config-custom": "0.0.3"
},

@@ -29,0 +29,0 @@ "scripts": {

@@ -7,10 +7,17 @@ import { type PChainTransaction, type NetworkToken } from '@avalabs/glacier-sdk';

export function convertPChainTransaction(
tx: PChainTransaction,
isTestnet: boolean,
address: string,
networkToken: NetworkToken,
explorerUrl: string,
chainId: number,
): Transaction {
export function convertPChainTransaction({
tx,
address,
networkToken,
chainId,
explorerUrl,
isTestnet,
}: {
tx: PChainTransaction;
address: string;
networkToken: NetworkToken;
chainId: number;
explorerUrl?: string;
isTestnet?: boolean;
}): Transaction {
const froms = new Set(tx.consumedUtxos.flatMap((utxo) => utxo.addresses) || []);

@@ -49,3 +56,3 @@ const tos = new Set(tx.emittedUtxos.flatMap((utxo) => utxo.addresses) || []);

gasUsed: avaxBurnedAmount.toString(),
explorerLink: getExplorerAddressByNetwork(explorerUrl, tx.txHash, 'tx'),
explorerLink: getExplorerAddressByNetwork(explorerUrl ?? '', tx.txHash, 'tx'),
txType: tx.txType,

@@ -63,3 +70,3 @@ chainId: chainId.toString(),

tx: PChainTransaction;
isTestnet: boolean;
isTestnet?: boolean;
networkToken: NetworkToken;

@@ -111,3 +118,3 @@ froms: Set<string>;

tx: PChainTransaction;
isTestnet: boolean;
isTestnet?: boolean;
networkToken: NetworkToken;

@@ -114,0 +121,0 @@ }): Big {

@@ -7,10 +7,17 @@ import { type NetworkToken, XChainNonLinearTransaction, XChainLinearTransaction } from '@avalabs/glacier-sdk';

export function convertXChainTransaction(
tx: XChainNonLinearTransaction | XChainLinearTransaction,
isTestnet: boolean,
address: string,
networkToken: NetworkToken,
explorerUrl: string,
chainId: number,
): Transaction {
export function convertXChainTransaction({
tx,
address,
networkToken,
chainId,
explorerUrl,
isTestnet,
}: {
tx: XChainNonLinearTransaction | XChainLinearTransaction;
address: string;
networkToken: NetworkToken;
chainId: number;
isTestnet?: boolean;
explorerUrl?: string;
}): Transaction {
const froms = new Set(tx.consumedUtxos.flatMap((utxo) => utxo.addresses) || []);

@@ -47,3 +54,3 @@ const tos = new Set(tx.emittedUtxos.flatMap((utxo) => utxo.addresses) || []);

gasUsed: avaxBurnedAmount.toString(),
explorerLink: getExplorerAddressByNetwork(explorerUrl, tx.txHash, 'tx'),
explorerLink: getExplorerAddressByNetwork(explorerUrl ?? '', tx.txHash, 'tx'),
txType: tx.txType,

@@ -60,3 +67,3 @@ chainId: chainId.toString(),

tx: XChainNonLinearTransaction | XChainLinearTransaction;
isTestnet: boolean;
isTestnet?: boolean;
networkToken: NetworkToken;

@@ -88,3 +95,3 @@ }): Big {

}: {
isTestnet: boolean;
isTestnet?: boolean;
tx: XChainNonLinearTransaction | XChainLinearTransaction;

@@ -91,0 +98,0 @@ totalAmountCreated: Big;

import type { GetTransactionHistory, Transaction, TransactionHistoryResponse } from '@avalabs/vm-module-types';
import { BlockchainId, Network, SortOrder, Glacier } from '@avalabs/glacier-sdk';
import { BlockchainId, Network, SortOrder } from '@avalabs/glacier-sdk';
import { isPChainTransactions, isXChainTransactions } from './utils';
import { convertPChainTransaction } from './convert-p-chain-transaction';
import { convertXChainTransaction } from './convert-x-chain-transaction';
import type { AvalancheGlacierService } from '../../services/glacier-service/glacier-service';
export const getTransactionHistory = async ({
isTestnet,
address,
nextPageToken,
offset,
glacierApiUrl,
networkToken,
explorerUrl,
chainId,
}: GetTransactionHistory): Promise<TransactionHistoryResponse> => {
const glacierSdk = new Glacier({ BASE: glacierApiUrl });
network,
glacierService,
}: GetTransactionHistory & { glacierService: AvalancheGlacierService }): Promise<TransactionHistoryResponse> => {
const { isTestnet, networkToken, explorerUrl, chainId } = network;
const isHealthy = glacierService.isHealthy();
if (!isHealthy) {
return {
transactions: [],
nextPageToken: '',
};
}
const response = await glacierSdk.primaryNetworkTransactions.listLatestPrimaryNetworkTransactions({
const response = await glacierService.listLatestPrimaryNetworkTransactions({
addresses: address,

@@ -31,3 +36,3 @@ blockchainId: getBlockchainIdByAddress(address),

transactions = response.transactions.map((value) =>
convertPChainTransaction(value, isTestnet, address, networkToken, explorerUrl, chainId),
convertPChainTransaction({ tx: value, isTestnet, address, networkToken, explorerUrl, chainId }),
);

@@ -37,3 +42,3 @@ }

transactions = response.transactions.map((value) =>
convertXChainTransaction(value, isTestnet, address, networkToken, explorerUrl, chainId),
convertXChainTransaction({ tx: value, isTestnet, address, networkToken, explorerUrl, chainId }),
);

@@ -40,0 +45,0 @@ }

@@ -8,2 +8,5 @@ import type {

Network,
GetBalancesParams,
GetBalancesResponse,
Environment,
} from '@avalabs/vm-module-types';

@@ -14,4 +17,14 @@ import { parseManifest } from '@avalabs/vm-module-types';

import { getNetworkFee } from './handlers/get-network-fee';
import { getTransactionHistory } from './handlers/get-transaction-history/get-transaction-history';
import { getEnv } from './env';
import { AvalancheGlacierService } from './services/glacier-service/glacier-service';
export class AvalancheModule implements Module {
#glacierService: AvalancheGlacierService;
constructor({ environment }: { environment: Environment }) {
const { glacierApiUrl } = getEnv(environment);
this.#glacierService = new AvalancheGlacierService({ glacierApiUrl });
}
getAddress(): Promise<string> {

@@ -21,4 +34,4 @@ return Promise.resolve('Avalanche address');

getBalances(): Promise<string> {
return Promise.resolve('Avalanche balances');
getBalances(_: GetBalancesParams): Promise<GetBalancesResponse> {
return Promise.resolve({});
}

@@ -35,4 +48,4 @@

getTransactionHistory(_: GetTransactionHistory) {
return Promise.resolve({ transactions: [] });
getTransactionHistory({ network, address, nextPageToken, offset }: GetTransactionHistory) {
return getTransactionHistory({ network, address, nextPageToken, offset, glacierService: this.#glacierService });
}

@@ -39,0 +52,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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