@avalabs/avalanche-module 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -12
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +4 -4
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs +13 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
- package/src/handlers/get-balances/convert-p-chain-balance.ts +91 -0
- package/src/handlers/get-balances/covnert-x-chain-balance.ts +74 -0
- package/src/handlers/get-balances/get-balances.ts +100 -0
- package/src/handlers/get-balances/typeguards.ts +9 -0
- package/src/handlers/get-balances/utils.ts +27 -0
- package/src/index.ts +1 -0
- package/src/module.ts +9 -5
- package/src/services/glacier-service/glacier-service.ts +19 -0
- /package/src/handlers/{get-network-fee.test.ts → get-network-fee/get-network-fee.test.ts} +0 -0
- /package/src/handlers/{get-network-fee.ts → get-network-fee/get-network-fee.ts} +0 -0
package/src/module.ts
CHANGED
|
@@ -12,26 +12,30 @@ import type {
|
|
|
12
12
|
import { parseManifest } from '@avalabs/vm-module-types';
|
|
13
13
|
import { rpcErrors } from '@metamask/rpc-errors';
|
|
14
14
|
import ManifestJson from '../manifest.json';
|
|
15
|
-
import { getNetworkFee } from './handlers/get-network-fee';
|
|
15
|
+
import { getNetworkFee } from './handlers/get-network-fee/get-network-fee';
|
|
16
16
|
import { getTransactionHistory } from './handlers/get-transaction-history/get-transaction-history';
|
|
17
17
|
import { getEnv } from './env';
|
|
18
18
|
import { AvalancheGlacierService } from './services/glacier-service/glacier-service';
|
|
19
|
-
import { hashBlockchainId } from '@internal/utils';
|
|
19
|
+
import { hashBlockchainId, TokenService } from '@internal/utils';
|
|
20
|
+
import { getBalances } from './handlers/get-balances/get-balances';
|
|
20
21
|
|
|
21
22
|
export class AvalancheModule implements Module {
|
|
22
23
|
#glacierService: AvalancheGlacierService;
|
|
24
|
+
#proxyApiUrl: string;
|
|
23
25
|
|
|
24
26
|
constructor({ environment }: { environment: Environment }) {
|
|
25
|
-
const { glacierApiUrl } = getEnv(environment);
|
|
27
|
+
const { glacierApiUrl, proxyApiUrl } = getEnv(environment);
|
|
26
28
|
this.#glacierService = new AvalancheGlacierService({ glacierApiUrl });
|
|
29
|
+
this.#proxyApiUrl = proxyApiUrl;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
getAddress(): Promise<string> {
|
|
30
33
|
return Promise.resolve('Avalanche address');
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
getBalances(
|
|
34
|
-
|
|
36
|
+
getBalances({ addresses, network, storage, currency }: GetBalancesParams): Promise<GetBalancesResponse> {
|
|
37
|
+
const tokenService = new TokenService({ storage, proxyApiUrl: this.#proxyApiUrl });
|
|
38
|
+
return getBalances({ addresses, currency, network, glacierService: this.#glacierService, tokenService });
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
getManifest(): Manifest | undefined {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BlockchainId,
|
|
3
3
|
Glacier,
|
|
4
|
+
type ListCChainAtomicBalancesResponse,
|
|
4
5
|
type ListCChainAtomicTransactionsResponse,
|
|
6
|
+
type ListPChainBalancesResponse,
|
|
5
7
|
type ListPChainTransactionsResponse,
|
|
8
|
+
type ListXChainBalancesResponse,
|
|
6
9
|
type ListXChainTransactionsResponse,
|
|
7
10
|
Network,
|
|
8
11
|
PrimaryNetworkTxType,
|
|
@@ -53,4 +56,20 @@ export class AvalancheGlacierService {
|
|
|
53
56
|
throw error;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
59
|
+
|
|
60
|
+
async getChainBalance(params: {
|
|
61
|
+
blockchainId: BlockchainId;
|
|
62
|
+
network: Network;
|
|
63
|
+
blockTimestamp?: number;
|
|
64
|
+
addresses?: string;
|
|
65
|
+
}): Promise<ListPChainBalancesResponse | ListXChainBalancesResponse | ListCChainAtomicBalancesResponse> {
|
|
66
|
+
try {
|
|
67
|
+
return this.glacierSdk.primaryNetworkBalances.getBalancesByAddresses(params);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof GlacierUnhealthyError) {
|
|
70
|
+
this.setGlacierToUnhealthy();
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
56
75
|
}
|
|
File without changes
|
|
File without changes
|