@avalabs/avalanche-module
Advanced tools
Comparing version 0.0.0-cp-8362-20240709204552 to 0.0.0-cp-8871-20240710150012
# @avalabs/avalanche-module | ||
## 0.0.0-cp-8362-20240709204552 | ||
## 0.0.0-cp-8871-20240710150012 | ||
### Patch Changes | ||
- c7dbdcd: add getBalances to evm-module | ||
- Updated dependencies [c7dbdcd] | ||
- @avalabs/vm-module-types@0.0.0-cp-8362-20240709204552 | ||
- e73871d: Add getTransactionHistory to avalanche module | ||
- 02560da: Created Avalanche module | ||
- Updated dependencies [e73871d] | ||
- Updated dependencies [e4ff1b5] | ||
- @avalabs/vm-module-types@0.0.0-cp-8871-20240710150012 |
@@ -1,14 +0,15 @@ | ||
import { Module, GetBalancesParams, GetBalancesResponse, Manifest, Network, NetworkFees, GetTransactionHistory, RpcRequest } from '@avalabs/vm-module-types'; | ||
import * as _avalabs_vm_module_types from '@avalabs/vm-module-types'; | ||
import { Module, Manifest, GetNetworkFeeParams, NetworkFees, GetTransactionHistory, RpcRequest } from '@avalabs/vm-module-types'; | ||
declare class AvalancheModule implements Module { | ||
#private; | ||
constructor({ glacierApiUrl }: { | ||
glacierApiUrl: string; | ||
}); | ||
getAddress(): Promise<string>; | ||
getBalances(_: GetBalancesParams): Promise<GetBalancesResponse>; | ||
getBalances(): Promise<string>; | ||
getManifest(): Manifest | undefined; | ||
getNetworkFee(_: { | ||
network: Network; | ||
}): Promise<NetworkFees>; | ||
getTransactionHistory(_: GetTransactionHistory): Promise<{ | ||
transactions: never[]; | ||
}>; | ||
getTokens(_: number): Promise<never[]>; | ||
getNetworkFee(_: GetNetworkFeeParams): Promise<NetworkFees>; | ||
getTokens(): Promise<never[]>; | ||
getTransactionHistory(params: GetTransactionHistory): Promise<_avalabs_vm_module_types.TransactionHistoryResponse>; | ||
onRpcRequest(request: RpcRequest): Promise<{ | ||
@@ -15,0 +16,0 @@ error: Error; |
@@ -1,7 +0,10 @@ | ||
import { parseManifest } from '@avalabs/vm-module-types'; | ||
import { parseManifest, TokenType } from '@avalabs/vm-module-types'; | ||
import { Glacier, Network, SortOrder, BlockchainId, PrimaryNetworkChainName } from '@avalabs/glacier-sdk'; | ||
import l from 'big.js'; | ||
import { Avalanche } from '@avalabs/wallets-sdk'; | ||
var s={name:"AVM",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","avax:fuji-11111111111111111111111111111111LpoYY"],namespaces:["avax"]},cointype:"",permissions:{rpc:{dapps:!0,methods:["avalanche_sendTransaction","avalanche_*"]}},manifestVersion:"0.0"};var r=class{getAddress(){return Promise.resolve("Avalanche address")}getBalances(e){return Promise.resolve({})}getManifest(){let e=parseManifest(s);return e.success?e.data:void 0}getNetworkFee(e){return Promise.resolve({low:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},medium:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},high:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},baseFee:0n})}getTransactionHistory(e){return Promise.resolve({transactions:[]})}getTokens(e){return Promise.resolve([])}async onRpcRequest(e){switch(e.method){default:return {error:new Error(`Method ${e.method} not supported`)}}}}; | ||
var v=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)};var I=(e,n,t)=>(v(e,n,"read from private field"),t?t.call(e):n.get(e)),N=(e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t);},w=(e,n,t,a)=>(v(e,n,"write to private field"),a?a.call(e,t):n.set(e,t),t);var P={name:"AVM",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","avax:fuji-11111111111111111111111111111111LpoYY"],namespaces:["avax"]},cointype:"",permissions:{rpc:{dapps:!0,methods:["avalanche_sendTransaction","avalanche_*"]}},manifestVersion:"0.0"};var L=e=>e.chainInfo.chainName===PrimaryNetworkChainName.P_CHAIN,S=e=>e.chainInfo.chainName===PrimaryNetworkChainName.X_CHAIN;function x(e,n,t="tx"){return `${e}/${t}/${n}`}function h({amount:e,decimals:n}){return e===void 0?new l(0):new l(e/10**n)}function E(e,n,t,a,c,m){let s=new Set(e.consumedUtxos.flatMap(o=>o.addresses)||[]),u=new Set(e.emittedUtxos.flatMap(o=>o.addresses)||[]),r=G({tx:e,isTestnet:n,networkToken:a,froms:s}),i=D({tx:e,isTestnet:n,networkToken:a}),p=t.toLowerCase().startsWith("p-")?t.slice(2):t,d=s.has(p);return {hash:e.txHash,isContractCall:!1,isIncoming:!d,isOutgoing:d,from:[...s.values()].join(","),to:[...u.values()].join(","),isSender:d,timestamp:e.blockTimestamp*1e3,tokens:[{decimal:a.decimals.toString(),name:a.name,symbol:a.symbol,type:TokenType.NATIVE,amount:r.toString()}],gasUsed:i.toString(),explorerLink:x(c,e.txHash,"tx"),txType:e.txType,chainId:m.toString()}}function G({tx:e,isTestnet:n,networkToken:t,froms:a}){let c=["ImportTx","ExportTx"].includes(e.txType),m=e.txType==="BaseTx",s=e.emittedUtxos.filter(o=>o.asset.assetId===T(!!n)&&!o.addresses.some(g=>a.has(g))).reduce((o,g)=>o.add(g.asset.amount),new l(0)),u=e.value.find(o=>o.assetId===T(!!n))?.amount,r=s.gt(new l(0))?s:u?new l(u):new l(0)??new l(0),i=n?Avalanche.FujiContext.pBlockchainID:Avalanche.MainnetContext.pBlockchainID,p=e.emittedUtxos.filter(o=>o.asset.assetId===T(!!n)&&(e.txType==="ImportTx"&&o.consumedOnChainId===i||e.txType==="ExportTx"&&o.consumedOnChainId!==i)).reduce((o,g)=>o.add(g.amount),new l(0)),d=m?r:c?p:e.amountStaked.length===0?F(e.value,!!n):F(e.amountStaked,!!n);return h({amount:d?.toNumber(),decimals:t.decimals})}function D({tx:e,isTestnet:n,networkToken:t}){let a=e.amountBurned?.filter(c=>c.assetId===T(!!n)).reduce((c,m)=>c.add(m.amount),new l(0));return h({amount:a?.toNumber(),decimals:t.decimals})}function F(e,n){return e.filter(t=>t.assetId===T(n)).reduce((t,a)=>t.add(a.amount),new l(0))}function T(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}function H(e,n,t,a,c,m){let s=new Set(e.consumedUtxos.flatMap(o=>o.addresses)||[]),u=new Set(e.emittedUtxos.flatMap(o=>o.addresses)||[]),r=_({tx:e,isTestnet:n,networkToken:a}),i=J({isTestnet:n,tx:e,totalAmountCreated:r,networkToken:a}),p=t.toLowerCase().startsWith("x-")?t.slice(2):t,d=s.has(p);return {hash:e.txHash,isContractCall:!1,isIncoming:!d,isOutgoing:d,from:[...s.values()].join(","),to:[...u.values()].join(","),isSender:d,timestamp:e.timestamp*1e3,tokens:[{decimal:a.decimals.toString(),name:a.name,symbol:a.symbol,type:TokenType.NATIVE,amount:r.toString()}],gasUsed:i.toString(),explorerLink:x(c,e.txHash,"tx"),txType:e.txType,chainId:m.toString()}}function _({tx:e,isTestnet:n,networkToken:t}){let a=["ImportTx","ExportTx"].includes(e.txType),c=n?Avalanche.FujiContext.xBlockchainID:Avalanche.MainnetContext.xBlockchainID,m=e.emittedUtxos.filter(r=>r.asset.assetId===k(!!n)&&(e.txType==="ImportTx"&&r.consumedOnChainId===c||e.txType==="ExportTx"&&r.consumedOnChainId!==c)).reduce((r,i)=>r.add(i.asset.amount),new l(0)),s=e.amountCreated.filter(r=>r.assetId===k(!!n)).reduce((r,i)=>r.add(i.amount),new l(0));return h({amount:(a?m:s).toNumber(),decimals:t.decimals})}function J({isTestnet:e,tx:n,totalAmountCreated:t,networkToken:a}){let m=n.amountUnlocked.filter(s=>s.assetId===k(!!e)).reduce((s,u)=>s.add(u.amount),new l(0)).minus(t);return h({amount:m.toNumber(),decimals:a.decimals})}function k(e){return e?Avalanche.FujiContext.avaxAssetID:Avalanche.MainnetContext.avaxAssetID}var X=async({isTestnet:e,address:n,nextPageToken:t,offset:a,glacierApiUrl:c,networkToken:m,explorerUrl:s,chainId:u})=>{let i=await new Glacier({BASE:c}).primaryNetworkTransactions.listLatestPrimaryNetworkTransactions({addresses:n,blockchainId:W(n),network:e?Network.FUJI:Network.MAINNET,pageSize:a,pageToken:t,sortOrder:SortOrder.DESC}),p=[];return L(i)&&(p=i.transactions.map(d=>E(d,e,n,m,s,u))),S(i)&&(p=i.transactions.map(d=>H(d,e,n,m,s,u))),{transactions:p,nextPageToken:i.nextPageToken}},W=e=>e.split(",")[0]?.toLowerCase().startsWith("p-")?BlockchainId.P_CHAIN:BlockchainId.X_CHAIN;var f,j=class{constructor({glacierApiUrl:n}){N(this,f,void 0);w(this,f,n);}getAddress(){return Promise.resolve("Avalanche address")}getBalances(){return Promise.resolve("Avalanche balances")}getManifest(){let n=parseManifest(P);return n.success?n.data:void 0}getNetworkFee(n){return Promise.resolve({low:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},medium:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},high:{maxPriorityFeePerGas:0n,maxFeePerGas:0n},baseFee:0n})}getTokens(){return Promise.resolve([])}getTransactionHistory(n){return X({...n,glacierApiUrl:I(this,f)})}async onRpcRequest(n){switch(n.method){default:return {error:new Error(`Method ${n.method} not supported`)}}}};f=new WeakMap; | ||
export { r as AvalancheModule }; | ||
export { j as AvalancheModule }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@avalabs/avalanche-module", | ||
"version": "0.0.0-cp-8362-20240709204552", | ||
"version": "0.0.0-cp-8871-20240710150012", | ||
"main": "dist/index.cjs", | ||
@@ -9,3 +9,9 @@ "module": "dist/index.js", | ||
"dependencies": { | ||
"@avalabs/vm-module-types": "0.0.0-cp-8362-20240709204552" | ||
"@avalabs/vm-module-types": "0.0.0-cp-8871-20240710150012", | ||
"@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" | ||
}, | ||
@@ -17,4 +23,5 @@ "devDependencies": { | ||
"tsup": "7.2.0", | ||
"@types/big.js": "6.2.2", | ||
"@internal/tsup-config": "0.0.1", | ||
"eslint-config-custom": "0.0.0-cp-8362-20240709204552" | ||
"eslint-config-custom": "0.0.1" | ||
}, | ||
@@ -21,0 +28,0 @@ "scripts": { |
@@ -7,10 +7,15 @@ import type { | ||
RpcRequest, | ||
GetBalancesResponse, | ||
GetBalancesParams, | ||
Network, | ||
GetNetworkFeeParams, | ||
} from '@avalabs/vm-module-types'; | ||
import { parseManifest } from '@avalabs/vm-module-types'; | ||
import ManifestJson from './manifest.json'; | ||
import { getTransactionHistory } from './handlers/get-transaction-history/get-transaction-history'; | ||
export class AvalancheModule implements Module { | ||
#glacierApiUrl: string; | ||
constructor({ glacierApiUrl }: { glacierApiUrl: string }) { | ||
this.#glacierApiUrl = glacierApiUrl; | ||
} | ||
getAddress(): Promise<string> { | ||
@@ -20,4 +25,4 @@ return Promise.resolve('Avalanche address'); | ||
getBalances(_: GetBalancesParams): Promise<GetBalancesResponse> { | ||
return Promise.resolve({}); | ||
getBalances(): Promise<string> { | ||
return Promise.resolve('Avalanche balances'); | ||
} | ||
@@ -30,3 +35,3 @@ | ||
getNetworkFee(_: { network: Network }): Promise<NetworkFees> { | ||
getNetworkFee(_: GetNetworkFeeParams): Promise<NetworkFees> { | ||
return Promise.resolve({ | ||
@@ -40,8 +45,8 @@ low: { maxPriorityFeePerGas: 0n, maxFeePerGas: 0n }, | ||
getTransactionHistory(_: GetTransactionHistory) { | ||
return Promise.resolve({ transactions: [] }); | ||
getTokens() { | ||
return Promise.resolve([]); | ||
} | ||
getTokens(_: number) { | ||
return Promise.resolve([]); | ||
getTransactionHistory(params: GetTransactionHistory) { | ||
return getTransactionHistory({ ...params, glacierApiUrl: this.#glacierApiUrl }); | ||
} | ||
@@ -48,0 +53,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
75909
22
484
7
7
1
+ Addedbig.js@6.2.1
+ Added@avalabs/vm-module-types@0.0.0-cp-8871-20240710150012(transitive)
+ Addedbig.js@6.2.1(transitive)
- Removed@avalabs/vm-module-types@0.0.0-cp-8362-20240709204552(transitive)
Updated@avalabs/vm-module-types@0.0.0-cp-8871-20240710150012