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.0-CP-8870-20240716182958 to 0.0.0-CP-8870-20240716213854

src/env.ts

21

CHANGELOG.md
# @avalabs/avalanche-module
## 0.0.0-CP-8870-20240716182958
## 0.0.0-CP-8870-20240716213854
### Patch Changes
- 1fb6926: Fixe internal dependencies
- @avalabs/vm-module-types@0.0.0-CP-8870-20240716213854
## 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.0-CP-8870-20240716182958
- @internal/utils@0.0.0-CP-8870-20240716182958
- @avalabs/vm-module-types@0.0.14
- @internal/utils@0.0.2

@@ -12,0 +27,0 @@ ## 0.0.13

11

dist/index.js

@@ -1,12 +0,11 @@

import { parseManifest, TokenType } from '@avalabs/vm-module-types';
import { parseManifest, Environment, TokenType } from '@avalabs/vm-module-types';
import { rpcErrors } from '@metamask/rpc-errors';
import { Network, SortOrder, BlockchainId, PrimaryNetworkChainName } from '@avalabs/glacier-sdk';
import l from 'big.js';
import { Network, SortOrder, BlockchainId, Glacier, PrimaryNetworkChainName } from '@avalabs/glacier-sdk';
import u from 'big.js';
import { Avalanche } from '@avalabs/wallets-sdk';
import { getEnv, GlacierService } from '@internal/utils';
var I=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var w=(e,t,n)=>(I(e,t,"read from private field"),n?n.call(e):t.get(e)),A=(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);},N=(e,t,n,o)=>(I(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var B={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 b(){return {baseFee:BigInt(1e6),low:{maxFeePerGas:BigInt(1e6)},medium:{maxFeePerGas:BigInt(1e6)},high:{maxFeePerGas:BigInt(1e6)},isFixedFee:!0}}var L=e=>e.chainInfo.chainName===PrimaryNetworkChainName.P_CHAIN,E=e=>e.chainInfo.chainName===PrimaryNetworkChainName.X_CHAIN;function x(e,t,n="tx"){return `${e}/${n}/${t}`}function h({amount:e,decimals:t}){return e===void 0?new l(0):new l(e/10**t)}function R({tx:e,address:t,networkToken:n,chainId:o,explorerUrl:i,isTestnet:c}){let r=new Set(e.consumedUtxos.flatMap(a=>a.addresses)||[]),p=new Set(e.emittedUtxos.flatMap(a=>a.addresses)||[]),s=D({tx:e,isTestnet:c,networkToken:n,froms:r}),m=_({tx:e,isTestnet:c,networkToken:n}),u=t.toLowerCase().startsWith("p-")?t.slice(2):t,d=r.has(u);return {hash:e.txHash,isContractCall:!1,isIncoming:!d,isOutgoing:d,from:[...r.values()].join(","),to:[...p.values()].join(","),isSender:d,timestamp:e.blockTimestamp*1e3,tokens:[{decimal:n.decimals.toString(),name:n.name,symbol:n.symbol,type:TokenType.NATIVE,amount:s.toString()}],gasUsed:m.toString(),explorerLink:x(i??"",e.txHash,"tx"),txType:e.txType,chainId:o.toString()}}function D({tx:e,isTestnet:t,networkToken:n,froms:o}){let i=["ImportTx","ExportTx"].includes(e.txType),c=e.txType==="BaseTx",r=e.emittedUtxos.filter(a=>a.asset.assetId===g(!!t)&&!a.addresses.some(T=>o.has(T))).reduce((a,T)=>a.add(T.asset.amount),new l(0)),p=e.value.find(a=>a.assetId===g(!!t))?.amount,s=r.gt(new l(0))?r:p?new l(p):new l(0)??new l(0),m=t?Avalanche.FujiContext.pBlockchainID:Avalanche.MainnetContext.pBlockchainID,u=e.emittedUtxos.filter(a=>a.asset.assetId===g(!!t)&&(e.txType==="ImportTx"&&a.consumedOnChainId===m||e.txType==="ExportTx"&&a.consumedOnChainId!==m)).reduce((a,T)=>a.add(T.amount),new l(0)),d=c?s:i?u:e.amountStaked.length===0?F(e.value,!!t):F(e.amountStaked,!!t);return h({amount:d?.toNumber(),decimals:n.decimals})}function _({tx:e,isTestnet:t,networkToken:n}){let o=e.amountBurned?.filter(i=>i.assetId===g(!!t)).reduce((i,c)=>i.add(c.amount),new l(0));return h({amount:o?.toNumber(),decimals:n.decimals})}function F(e,t){return e.filter(n=>n.assetId===g(t)).reduce((n,o)=>n.add(o.amount),new l(0))}function g(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}function H({tx:e,address:t,networkToken:n,chainId:o,explorerUrl:i,isTestnet:c}){let r=new Set(e.consumedUtxos.flatMap(a=>a.addresses)||[]),p=new Set(e.emittedUtxos.flatMap(a=>a.addresses)||[]),s=J({tx:e,isTestnet:c,networkToken:n}),m=q({isTestnet:c,tx:e,totalAmountCreated:s,networkToken:n}),u=t.toLowerCase().startsWith("x-")?t.slice(2):t,d=r.has(u);return {hash:e.txHash,isContractCall:!1,isIncoming:!d,isOutgoing:d,from:[...r.values()].join(","),to:[...p.values()].join(","),isSender:d,timestamp:e.timestamp*1e3,tokens:[{decimal:n.decimals.toString(),name:n.name,symbol:n.symbol,type:TokenType.NATIVE,amount:s.toString()}],gasUsed:m.toString(),explorerLink:x(i??"",e.txHash,"tx"),txType:e.txType,chainId:o.toString()}}function J({tx:e,isTestnet:t,networkToken:n}){let o=["ImportTx","ExportTx"].includes(e.txType),i=t?Avalanche.FujiContext.xBlockchainID:Avalanche.MainnetContext.xBlockchainID,c=e.emittedUtxos.filter(s=>s.asset.assetId===y(!!t)&&(e.txType==="ImportTx"&&s.consumedOnChainId===i||e.txType==="ExportTx"&&s.consumedOnChainId!==i)).reduce((s,m)=>s.add(m.asset.amount),new l(0)),r=e.amountCreated.filter(s=>s.assetId===y(!!t)).reduce((s,m)=>s.add(m.amount),new l(0));return h({amount:(o?c:r).toNumber(),decimals:n.decimals})}function q({isTestnet:e,tx:t,totalAmountCreated:n,networkToken:o}){let c=t.amountUnlocked.filter(r=>r.assetId===y(!!e)).reduce((r,p)=>r.add(p.amount),new l(0)).minus(n);return h({amount:c.toNumber(),decimals:o.decimals})}function y(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}var X=async({address:e,nextPageToken:t,offset:n,network:o,glacierService:i})=>{let{isTestnet:c,networkToken:r,explorerUrl:p,chainId:s}=o,m=await i.listLatestPrimaryNetworkTransactions({addresses:e,blockchainId:Y(e),network:c?Network.FUJI:Network.MAINNET,pageSize:n,pageToken:t,sortOrder:SortOrder.DESC}),u=[];return L(m)&&(u=m.transactions.map(d=>R({tx:d,isTestnet:c,address:e,networkToken:r,explorerUrl:p,chainId:s}))),E(m)&&(u=m.transactions.map(d=>H({tx:d,isTestnet:c,address:e,networkToken:r,explorerUrl:p,chainId:s}))),{transactions:u,nextPageToken:m.nextPageToken}},Y=e=>e.split(",")[0]?.toLowerCase().startsWith("p-")?BlockchainId.P_CHAIN:BlockchainId.X_CHAIN;var f,j=class{constructor({environment:t}){A(this,f,void 0);let{glacierApiUrl:n}=getEnv(t);N(this,f,new GlacierService({glacierApiUrl:n}));}getAddress(){return Promise.resolve("Avalanche address")}getBalances(t){return Promise.resolve({})}getManifest(){let t=parseManifest(B);return t.success?t.data:void 0}getNetworkFee(t){return b()}getTransactionHistory({network:t,address:n,nextPageToken:o,offset:i}){return X({network:t,address:n,nextPageToken:o,offset:i,glacierService:w(this,f)})}getTokens(t){return Promise.resolve([])}async onRpcRequest(t,n){switch(t.method){default:return {error:rpcErrors.methodNotSupported(`Method ${t.method} not supported`)}}}};f=new WeakMap;
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 { j as AvalancheModule };
export { _ as AvalancheModule };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map
{
"name": "@avalabs/avalanche-module",
"version": "0.0.0-CP-8870-20240716182958",
"version": "0.0.0-CP-8870-20240716213854",
"main": "dist/index.cjs",

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

"dependencies": {
"@avalabs/vm-module-types": "0.0.0-CP-8870-20240716182958",
"@avalabs/vm-module-types": "0.0.0-CP-8870-20240716213854",
"@metamask/rpc-errors": "6.3.0",
"@avalabs/utils-sdk": "v2.8.0-alpha.193",
"@avalabs/chains-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.0-CP-8870-20240716182958"
"big.js": "6.2.1"
},

@@ -26,4 +24,5 @@ "devDependencies": {

"@types/big.js": "6.2.2",
"@internal/utils": "0.0.0-CP-8870-20240716213854",
"@internal/tsup-config": "0.0.1",
"eslint-config-custom": "0.0.0-CP-8870-20240716182958"
"eslint-config-custom": "0.0.1"
},

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

@@ -6,3 +6,3 @@ import type { GetTransactionHistory, Transaction, TransactionHistoryResponse } from '@avalabs/vm-module-types';

import { convertXChainTransaction } from './convert-x-chain-transaction';
import type { GlacierService } from '@internal/utils';
import type { AvalancheGlacierService } from '../../services/glacier-service/glacier-service';

@@ -15,4 +15,11 @@ export const getTransactionHistory = async ({

glacierService,
}: GetTransactionHistory & { glacierService: GlacierService }): Promise<TransactionHistoryResponse> => {
}: GetTransactionHistory & { glacierService: AvalancheGlacierService }): Promise<TransactionHistoryResponse> => {
const { isTestnet, networkToken, explorerUrl, chainId } = network;
const isHealthy = glacierService.isHealthy();
if (!isHealthy) {
return {
transactions: [],
nextPageToken: '',
};
}

@@ -19,0 +26,0 @@ const response = await glacierService.listLatestPrimaryNetworkTransactions({

@@ -17,10 +17,11 @@ import type {

import { getTransactionHistory } from './handlers/get-transaction-history/get-transaction-history';
import { getEnv, GlacierService } from '@internal/utils';
import { getEnv } from './env';
import { AvalancheGlacierService } from './services/glacier-service/glacier-service';
export class AvalancheModule implements Module {
#glacierService: GlacierService;
#glacierService: AvalancheGlacierService;
constructor({ environment }: { environment: Environment }) {
const { glacierApiUrl } = getEnv(environment);
this.#glacierService = new GlacierService({ glacierApiUrl });
this.#glacierService = new AvalancheGlacierService({ glacierApiUrl });
}

@@ -27,0 +28,0 @@

@@ -5,5 +5,11 @@ {

"outDir": "./dist",
"declaration": false,
"incremental": false // Need to turn off because of tsup dts
},
"include": ["src"]
"include": ["src"],
"references": [
{
"path": "../../packages-internal/utils/tsconfig.json"
}
]
}

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