@metamask/assets-controllers 11.1.0 → 12.0.0
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/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [12.0.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `AssetsContractController` methods `getProvider`, `getChainId`, `getERC721Standard`, and `getERC1155Standard` ([#1638](https://github.com/MetaMask/core/pull/1638))
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- **BREAKING**: Add `getNetworkClientById` to `AssetsContractController` constructor options ([#1638](https://github.com/MetaMask/core/pull/1638))
|
|
15
|
+
- Add optional `networkClientId` parameter to various `AssetContractController` methods ([#1638](https://github.com/MetaMask/core/pull/1638))
|
|
16
|
+
- The affected methods are:
|
|
17
|
+
- `getERC20BalanceOf`
|
|
18
|
+
- `getERC20TokenDecimals`
|
|
19
|
+
- `getERC20TokenName`
|
|
20
|
+
- `getERC721NftTokenId`
|
|
21
|
+
- `getTokenStandardAndDetails`
|
|
22
|
+
- `getERC721TokenURI`
|
|
23
|
+
- `getERC721AssetName`
|
|
24
|
+
- `getERC721AssetSymbol`
|
|
25
|
+
- `getERC721OwnerOf`
|
|
26
|
+
- `getERC1155TokenURI`
|
|
27
|
+
- `getERC1155BalanceOf`
|
|
28
|
+
- `transferSingleERC1155`
|
|
29
|
+
- `getBalancesInSingleCall`
|
|
30
|
+
|
|
9
31
|
## [11.1.0]
|
|
10
32
|
### Added
|
|
11
33
|
- Add `tokenURI` to `NftMetadata` type ([#1577](https://github.com/MetaMask/core/pull/1577))
|
|
@@ -226,7 +248,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
226
248
|
### Changed
|
|
227
249
|
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
|
|
228
250
|
|
|
229
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@
|
|
251
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@12.0.0...HEAD
|
|
252
|
+
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@11.1.0...@metamask/assets-controllers@12.0.0
|
|
230
253
|
[11.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@11.0.1...@metamask/assets-controllers@11.1.0
|
|
231
254
|
[11.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@11.0.0...@metamask/assets-controllers@11.0.1
|
|
232
255
|
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controllers@10.0.0...@metamask/assets-controllers@11.0.0
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
+
import { Web3Provider } from '@ethersproject/providers';
|
|
2
3
|
import type { BaseConfig, BaseState } from '@metamask/base-controller';
|
|
3
4
|
import { BaseController } from '@metamask/base-controller';
|
|
4
|
-
import type { NetworkState } from '@metamask/network-controller';
|
|
5
|
+
import type { NetworkClientId, NetworkState, NetworkController } from '@metamask/network-controller';
|
|
5
6
|
import type { PreferencesState } from '@metamask/preferences-controller';
|
|
6
7
|
import type { Hex } from '@metamask/utils';
|
|
7
8
|
import type { BN } from 'ethereumjs-util';
|
|
9
|
+
import { ERC20Standard } from './Standards/ERC20Standard';
|
|
10
|
+
import { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standard';
|
|
11
|
+
import { ERC721Standard } from './Standards/NftStandards/ERC721/ERC721Standard';
|
|
8
12
|
/**
|
|
9
13
|
* Check if token detection is enabled for certain networks
|
|
10
14
|
*
|
|
@@ -38,13 +42,11 @@ export interface BalanceMap {
|
|
|
38
42
|
*/
|
|
39
43
|
export declare class AssetsContractController extends BaseController<AssetsContractConfig, BaseState> {
|
|
40
44
|
private _provider?;
|
|
41
|
-
private erc721Standard?;
|
|
42
|
-
private erc1155Standard?;
|
|
43
|
-
private erc20Standard?;
|
|
44
45
|
/**
|
|
45
46
|
* Name of this controller used during composition
|
|
46
47
|
*/
|
|
47
48
|
name: string;
|
|
49
|
+
private readonly getNetworkClientById;
|
|
48
50
|
/**
|
|
49
51
|
* Creates a AssetsContractController instance.
|
|
50
52
|
*
|
|
@@ -52,13 +54,15 @@ export declare class AssetsContractController extends BaseController<AssetsContr
|
|
|
52
54
|
* @param options.chainId - The chain ID of the current network.
|
|
53
55
|
* @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.
|
|
54
56
|
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
57
|
+
* @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.
|
|
55
58
|
* @param config - Initial options used to configure this controller.
|
|
56
59
|
* @param state - Initial state to set on this controller.
|
|
57
60
|
*/
|
|
58
|
-
constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, }: {
|
|
61
|
+
constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, getNetworkClientById, }: {
|
|
59
62
|
chainId: Hex;
|
|
60
63
|
onPreferencesStateChange: (listener: (preferencesState: PreferencesState) => void) => void;
|
|
61
64
|
onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
|
|
65
|
+
getNetworkClientById: NetworkController['getNetworkClientById'];
|
|
62
66
|
}, config?: Partial<AssetsContractConfig>, state?: Partial<BaseState>);
|
|
63
67
|
/**
|
|
64
68
|
* Sets a new provider.
|
|
@@ -69,46 +73,86 @@ export declare class AssetsContractController extends BaseController<AssetsContr
|
|
|
69
73
|
*/
|
|
70
74
|
set provider(provider: any);
|
|
71
75
|
get provider(): any;
|
|
76
|
+
/**
|
|
77
|
+
* Get the relevant provider instance.
|
|
78
|
+
*
|
|
79
|
+
* @param networkClientId - Network Client ID.
|
|
80
|
+
* @returns Web3Provider instance.
|
|
81
|
+
*/
|
|
82
|
+
getProvider(networkClientId?: NetworkClientId): Web3Provider;
|
|
83
|
+
/**
|
|
84
|
+
* Get the relevant chain ID.
|
|
85
|
+
*
|
|
86
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
87
|
+
* @returns Hex chain ID.
|
|
88
|
+
*/
|
|
89
|
+
getChainId(networkClientId?: NetworkClientId): Hex;
|
|
90
|
+
/**
|
|
91
|
+
* Get a ERC20Standard instance using the relevant provider instance.
|
|
92
|
+
*
|
|
93
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
94
|
+
* @returns ERC20Standard instance.
|
|
95
|
+
*/
|
|
96
|
+
getERC20Standard(networkClientId?: NetworkClientId): ERC20Standard;
|
|
97
|
+
/**
|
|
98
|
+
* Get a ERC721Standard instance using the relevant provider instance.
|
|
99
|
+
*
|
|
100
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
101
|
+
* @returns ERC721Standard instance.
|
|
102
|
+
*/
|
|
103
|
+
getERC721Standard(networkClientId?: NetworkClientId): ERC721Standard;
|
|
104
|
+
/**
|
|
105
|
+
* Get a ERC1155Standard instance using the relevant provider instance.
|
|
106
|
+
*
|
|
107
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
108
|
+
* @returns ERC1155Standard instance.
|
|
109
|
+
*/
|
|
110
|
+
getERC1155Standard(networkClientId?: NetworkClientId): ERC1155Standard;
|
|
72
111
|
/**
|
|
73
112
|
* Get balance or count for current account on specific asset contract.
|
|
74
113
|
*
|
|
75
114
|
* @param address - Asset ERC20 contract address.
|
|
76
115
|
* @param selectedAddress - Current account public address.
|
|
116
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
77
117
|
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
78
118
|
*/
|
|
79
|
-
getERC20BalanceOf(address: string, selectedAddress: string): Promise<BN>;
|
|
119
|
+
getERC20BalanceOf(address: string, selectedAddress: string, networkClientId?: NetworkClientId): Promise<BN>;
|
|
80
120
|
/**
|
|
81
121
|
* Query for the decimals for a given ERC20 asset.
|
|
82
122
|
*
|
|
83
123
|
* @param address - ERC20 asset contract address.
|
|
124
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
84
125
|
* @returns Promise resolving to the 'decimals'.
|
|
85
126
|
*/
|
|
86
|
-
getERC20TokenDecimals(address: string): Promise<string>;
|
|
127
|
+
getERC20TokenDecimals(address: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
87
128
|
/**
|
|
88
129
|
* Query for the name for a given ERC20 asset.
|
|
89
130
|
*
|
|
90
131
|
* @param address - ERC20 asset contract address.
|
|
132
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
91
133
|
* @returns Promise resolving to the 'decimals'.
|
|
92
134
|
*/
|
|
93
|
-
getERC20TokenName(address: string): Promise<string>;
|
|
135
|
+
getERC20TokenName(address: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
94
136
|
/**
|
|
95
137
|
* Enumerate assets assigned to an owner.
|
|
96
138
|
*
|
|
97
139
|
* @param address - ERC721 asset contract address.
|
|
98
140
|
* @param selectedAddress - Current account public address.
|
|
99
141
|
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
|
|
142
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
100
143
|
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
|
|
101
144
|
*/
|
|
102
|
-
getERC721NftTokenId(address: string, selectedAddress: string, index: number): Promise<string>;
|
|
145
|
+
getERC721NftTokenId(address: string, selectedAddress: string, index: number, networkClientId?: NetworkClientId): Promise<string>;
|
|
103
146
|
/**
|
|
104
147
|
* Enumerate assets assigned to an owner.
|
|
105
148
|
*
|
|
106
149
|
* @param tokenAddress - ERC721 asset contract address.
|
|
107
150
|
* @param userAddress - Current account public address.
|
|
108
151
|
* @param tokenId - ERC721 asset identifier.
|
|
152
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
109
153
|
* @returns Promise resolving to an object containing the token standard and a set of details which depend on which standard the token supports.
|
|
110
154
|
*/
|
|
111
|
-
getTokenStandardAndDetails(tokenAddress: string, userAddress?: string, tokenId?: string): Promise<{
|
|
155
|
+
getTokenStandardAndDetails(tokenAddress: string, userAddress?: string, tokenId?: string, networkClientId?: NetworkClientId): Promise<{
|
|
112
156
|
standard: string;
|
|
113
157
|
tokenURI?: string | undefined;
|
|
114
158
|
symbol?: string | undefined;
|
|
@@ -121,48 +165,54 @@ export declare class AssetsContractController extends BaseController<AssetsContr
|
|
|
121
165
|
*
|
|
122
166
|
* @param address - ERC721 asset contract address.
|
|
123
167
|
* @param tokenId - ERC721 asset identifier.
|
|
168
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
124
169
|
* @returns Promise resolving to the 'tokenURI'.
|
|
125
170
|
*/
|
|
126
|
-
getERC721TokenURI(address: string, tokenId: string): Promise<string>;
|
|
171
|
+
getERC721TokenURI(address: string, tokenId: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
127
172
|
/**
|
|
128
173
|
* Query for name for a given asset.
|
|
129
174
|
*
|
|
130
175
|
* @param address - ERC721 or ERC20 asset contract address.
|
|
176
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
131
177
|
* @returns Promise resolving to the 'name'.
|
|
132
178
|
*/
|
|
133
|
-
getERC721AssetName(address: string): Promise<string>;
|
|
179
|
+
getERC721AssetName(address: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
134
180
|
/**
|
|
135
181
|
* Query for symbol for a given asset.
|
|
136
182
|
*
|
|
137
183
|
* @param address - ERC721 or ERC20 asset contract address.
|
|
184
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
138
185
|
* @returns Promise resolving to the 'symbol'.
|
|
139
186
|
*/
|
|
140
|
-
getERC721AssetSymbol(address: string): Promise<string>;
|
|
187
|
+
getERC721AssetSymbol(address: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
141
188
|
/**
|
|
142
189
|
* Query for owner for a given ERC721 asset.
|
|
143
190
|
*
|
|
144
191
|
* @param address - ERC721 asset contract address.
|
|
145
192
|
* @param tokenId - ERC721 asset identifier.
|
|
193
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
146
194
|
* @returns Promise resolving to the owner address.
|
|
147
195
|
*/
|
|
148
|
-
getERC721OwnerOf(address: string, tokenId: string): Promise<string>;
|
|
196
|
+
getERC721OwnerOf(address: string, tokenId: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
149
197
|
/**
|
|
150
198
|
* Query for tokenURI for a given asset.
|
|
151
199
|
*
|
|
152
200
|
* @param address - ERC1155 asset contract address.
|
|
153
201
|
* @param tokenId - ERC1155 asset identifier.
|
|
202
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
154
203
|
* @returns Promise resolving to the 'tokenURI'.
|
|
155
204
|
*/
|
|
156
|
-
getERC1155TokenURI(address: string, tokenId: string): Promise<string>;
|
|
205
|
+
getERC1155TokenURI(address: string, tokenId: string, networkClientId?: NetworkClientId): Promise<string>;
|
|
157
206
|
/**
|
|
158
207
|
* Query for balance of a given ERC 1155 token.
|
|
159
208
|
*
|
|
160
209
|
* @param userAddress - Wallet public address.
|
|
161
210
|
* @param nftAddress - ERC1155 asset contract address.
|
|
162
211
|
* @param nftId - ERC1155 asset identifier.
|
|
212
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
163
213
|
* @returns Promise resolving to the 'balanceOf'.
|
|
164
214
|
*/
|
|
165
|
-
getERC1155BalanceOf(userAddress: string, nftAddress: string, nftId: string): Promise<BN>;
|
|
215
|
+
getERC1155BalanceOf(userAddress: string, nftAddress: string, nftId: string, networkClientId?: NetworkClientId): Promise<BN>;
|
|
166
216
|
/**
|
|
167
217
|
* Transfer single ERC1155 token.
|
|
168
218
|
*
|
|
@@ -171,18 +221,20 @@ export declare class AssetsContractController extends BaseController<AssetsContr
|
|
|
171
221
|
* @param recipientAddress - ERC1155 token recipient.
|
|
172
222
|
* @param nftId - ERC1155 token id.
|
|
173
223
|
* @param qty - Quantity of tokens to be sent.
|
|
224
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
174
225
|
* @returns Promise resolving to the 'transferSingle' ERC1155 token.
|
|
175
226
|
*/
|
|
176
|
-
transferSingleERC1155(nftAddress: string, senderAddress: string, recipientAddress: string, nftId: string, qty: string): Promise<void>;
|
|
227
|
+
transferSingleERC1155(nftAddress: string, senderAddress: string, recipientAddress: string, nftId: string, qty: string, networkClientId?: NetworkClientId): Promise<void>;
|
|
177
228
|
/**
|
|
178
229
|
* Get the token balance for a list of token addresses in a single call. Only non-zero balances
|
|
179
230
|
* are returned.
|
|
180
231
|
*
|
|
181
232
|
* @param selectedAddress - The address to check token balances for.
|
|
182
233
|
* @param tokensToDetect - The token addresses to detect balances for.
|
|
234
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
183
235
|
* @returns The list of non-zero token balances.
|
|
184
236
|
*/
|
|
185
|
-
getBalancesInSingleCall(selectedAddress: string, tokensToDetect: string[]): Promise<BalanceMap>;
|
|
237
|
+
getBalancesInSingleCall(selectedAddress: string, tokensToDetect: string[], networkClientId?: NetworkClientId): Promise<BalanceMap>;
|
|
186
238
|
}
|
|
187
239
|
export default AssetsContractController;
|
|
188
240
|
//# sourceMappingURL=AssetsContractController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsContractController.d.ts","sourceRoot":"","sources":["../src/AssetsContractController.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"AssetsContractController.d.ts","sourceRoot":"","sources":["../src/AssetsContractController.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KA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EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;;;;OAQG;IACG,uBAAuB,CAC3B,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EAAE,EACxB,eAAe,CAAC,EAAE,eAAe;CA6BpC;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -47,10 +47,11 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
47
47
|
* @param options.chainId - The chain ID of the current network.
|
|
48
48
|
* @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.
|
|
49
49
|
* @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
|
|
50
|
+
* @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.
|
|
50
51
|
* @param config - Initial options used to configure this controller.
|
|
51
52
|
* @param state - Initial state to set on this controller.
|
|
52
53
|
*/
|
|
53
|
-
constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, }, config, state) {
|
|
54
|
+
constructor({ chainId: initialChainId, onPreferencesStateChange, onNetworkStateChange, getNetworkClientById, }, config, state) {
|
|
54
55
|
super(config, state);
|
|
55
56
|
/**
|
|
56
57
|
* Name of this controller used during composition
|
|
@@ -62,6 +63,7 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
62
63
|
chainId: initialChainId,
|
|
63
64
|
};
|
|
64
65
|
this.initialize();
|
|
66
|
+
this.getNetworkClientById = getNetworkClientById;
|
|
65
67
|
onPreferencesStateChange(({ ipfsGateway }) => {
|
|
66
68
|
this.configure({ ipfsGateway });
|
|
67
69
|
});
|
|
@@ -81,55 +83,105 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
81
83
|
* @property provider - Provider used to create a new underlying Web3 instance
|
|
82
84
|
*/
|
|
83
85
|
set provider(provider) {
|
|
84
|
-
this._provider =
|
|
85
|
-
this.erc721Standard = new ERC721Standard_1.ERC721Standard(this._provider);
|
|
86
|
-
this.erc1155Standard = new ERC1155Standard_1.ERC1155Standard(this._provider);
|
|
87
|
-
this.erc20Standard = new ERC20Standard_1.ERC20Standard(this._provider);
|
|
86
|
+
this._provider = provider;
|
|
88
87
|
}
|
|
89
88
|
get provider() {
|
|
90
89
|
throw new Error('Property only used for setting');
|
|
91
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the relevant provider instance.
|
|
93
|
+
*
|
|
94
|
+
* @param networkClientId - Network Client ID.
|
|
95
|
+
* @returns Web3Provider instance.
|
|
96
|
+
*/
|
|
97
|
+
getProvider(networkClientId) {
|
|
98
|
+
const provider = networkClientId
|
|
99
|
+
? this.getNetworkClientById(networkClientId).provider
|
|
100
|
+
: this._provider;
|
|
101
|
+
if (provider === undefined) {
|
|
102
|
+
throw new Error(exports.MISSING_PROVIDER_ERROR);
|
|
103
|
+
}
|
|
104
|
+
return new providers_1.Web3Provider(provider);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the relevant chain ID.
|
|
108
|
+
*
|
|
109
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
110
|
+
* @returns Hex chain ID.
|
|
111
|
+
*/
|
|
112
|
+
getChainId(networkClientId) {
|
|
113
|
+
return networkClientId
|
|
114
|
+
? this.getNetworkClientById(networkClientId).configuration.chainId
|
|
115
|
+
: this.config.chainId;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get a ERC20Standard instance using the relevant provider instance.
|
|
119
|
+
*
|
|
120
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
121
|
+
* @returns ERC20Standard instance.
|
|
122
|
+
*/
|
|
123
|
+
getERC20Standard(networkClientId) {
|
|
124
|
+
const provider = this.getProvider(networkClientId);
|
|
125
|
+
return new ERC20Standard_1.ERC20Standard(provider);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get a ERC721Standard instance using the relevant provider instance.
|
|
129
|
+
*
|
|
130
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
131
|
+
* @returns ERC721Standard instance.
|
|
132
|
+
*/
|
|
133
|
+
getERC721Standard(networkClientId) {
|
|
134
|
+
const provider = this.getProvider(networkClientId);
|
|
135
|
+
return new ERC721Standard_1.ERC721Standard(provider);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get a ERC1155Standard instance using the relevant provider instance.
|
|
139
|
+
*
|
|
140
|
+
* @param networkClientId - Network Client ID used to get the provider.
|
|
141
|
+
* @returns ERC1155Standard instance.
|
|
142
|
+
*/
|
|
143
|
+
getERC1155Standard(networkClientId) {
|
|
144
|
+
const provider = this.getProvider(networkClientId);
|
|
145
|
+
return new ERC1155Standard_1.ERC1155Standard(provider);
|
|
146
|
+
}
|
|
92
147
|
/**
|
|
93
148
|
* Get balance or count for current account on specific asset contract.
|
|
94
149
|
*
|
|
95
150
|
* @param address - Asset ERC20 contract address.
|
|
96
151
|
* @param selectedAddress - Current account public address.
|
|
152
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
97
153
|
* @returns Promise resolving to BN object containing balance for current account on specific asset contract.
|
|
98
154
|
*/
|
|
99
|
-
getERC20BalanceOf(address, selectedAddress) {
|
|
155
|
+
getERC20BalanceOf(address, selectedAddress, networkClientId) {
|
|
100
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
return this.erc20Standard.getBalanceOf(address, selectedAddress);
|
|
157
|
+
const erc20Standard = this.getERC20Standard(networkClientId);
|
|
158
|
+
return erc20Standard.getBalanceOf(address, selectedAddress);
|
|
105
159
|
});
|
|
106
160
|
}
|
|
107
161
|
/**
|
|
108
162
|
* Query for the decimals for a given ERC20 asset.
|
|
109
163
|
*
|
|
110
164
|
* @param address - ERC20 asset contract address.
|
|
165
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
111
166
|
* @returns Promise resolving to the 'decimals'.
|
|
112
167
|
*/
|
|
113
|
-
getERC20TokenDecimals(address) {
|
|
168
|
+
getERC20TokenDecimals(address, networkClientId) {
|
|
114
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return yield this.erc20Standard.getTokenDecimals(address);
|
|
170
|
+
const erc20Standard = this.getERC20Standard(networkClientId);
|
|
171
|
+
return erc20Standard.getTokenDecimals(address);
|
|
119
172
|
});
|
|
120
173
|
}
|
|
121
174
|
/**
|
|
122
175
|
* Query for the name for a given ERC20 asset.
|
|
123
176
|
*
|
|
124
177
|
* @param address - ERC20 asset contract address.
|
|
178
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
125
179
|
* @returns Promise resolving to the 'decimals'.
|
|
126
180
|
*/
|
|
127
|
-
getERC20TokenName(address) {
|
|
181
|
+
getERC20TokenName(address, networkClientId) {
|
|
128
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
return yield this.erc20Standard.getTokenName(address);
|
|
183
|
+
const erc20Standard = this.getERC20Standard(networkClientId);
|
|
184
|
+
return erc20Standard.getTokenName(address);
|
|
133
185
|
});
|
|
134
186
|
}
|
|
135
187
|
/**
|
|
@@ -138,13 +190,12 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
138
190
|
* @param address - ERC721 asset contract address.
|
|
139
191
|
* @param selectedAddress - Current account public address.
|
|
140
192
|
* @param index - An NFT counter less than `balanceOf(selectedAddress)`.
|
|
193
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
141
194
|
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
|
|
142
195
|
*/
|
|
143
|
-
getERC721NftTokenId(address, selectedAddress, index) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
return this.erc721Standard.getNftTokenId(address, selectedAddress, index);
|
|
196
|
+
getERC721NftTokenId(address, selectedAddress, index, networkClientId) {
|
|
197
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
198
|
+
return erc721Standard.getNftTokenId(address, selectedAddress, index);
|
|
148
199
|
}
|
|
149
200
|
/**
|
|
150
201
|
* Enumerate assets assigned to an owner.
|
|
@@ -152,33 +203,34 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
152
203
|
* @param tokenAddress - ERC721 asset contract address.
|
|
153
204
|
* @param userAddress - Current account public address.
|
|
154
205
|
* @param tokenId - ERC721 asset identifier.
|
|
206
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
155
207
|
* @returns Promise resolving to an object containing the token standard and a set of details which depend on which standard the token supports.
|
|
156
208
|
*/
|
|
157
|
-
getTokenStandardAndDetails(tokenAddress, userAddress, tokenId) {
|
|
209
|
+
getTokenStandardAndDetails(tokenAddress, userAddress, tokenId, networkClientId) {
|
|
158
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.erc20Standard === undefined) {
|
|
162
|
-
throw new Error(exports.MISSING_PROVIDER_ERROR);
|
|
163
|
-
}
|
|
211
|
+
// Asserts provider is available
|
|
212
|
+
this.getProvider(networkClientId);
|
|
164
213
|
const { ipfsGateway } = this.config;
|
|
165
214
|
// ERC721
|
|
166
215
|
try {
|
|
167
|
-
|
|
216
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
217
|
+
return Object.assign({}, (yield erc721Standard.getDetails(tokenAddress, ipfsGateway, tokenId)));
|
|
168
218
|
}
|
|
169
219
|
catch (_a) {
|
|
170
220
|
// Ignore
|
|
171
221
|
}
|
|
172
222
|
// ERC1155
|
|
173
223
|
try {
|
|
174
|
-
|
|
224
|
+
const erc1155Standard = this.getERC1155Standard(networkClientId);
|
|
225
|
+
return Object.assign({}, (yield erc1155Standard.getDetails(tokenAddress, ipfsGateway, tokenId)));
|
|
175
226
|
}
|
|
176
227
|
catch (_b) {
|
|
177
228
|
// Ignore
|
|
178
229
|
}
|
|
179
230
|
// ERC20
|
|
180
231
|
try {
|
|
181
|
-
|
|
232
|
+
const erc20Standard = this.getERC20Standard(networkClientId);
|
|
233
|
+
return Object.assign({}, (yield erc20Standard.getDetails(tokenAddress, userAddress)));
|
|
182
234
|
}
|
|
183
235
|
catch (_c) {
|
|
184
236
|
// Ignore
|
|
@@ -191,42 +243,39 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
191
243
|
*
|
|
192
244
|
* @param address - ERC721 asset contract address.
|
|
193
245
|
* @param tokenId - ERC721 asset identifier.
|
|
246
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
194
247
|
* @returns Promise resolving to the 'tokenURI'.
|
|
195
248
|
*/
|
|
196
|
-
getERC721TokenURI(address, tokenId) {
|
|
249
|
+
getERC721TokenURI(address, tokenId, networkClientId) {
|
|
197
250
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
return this.erc721Standard.getTokenURI(address, tokenId);
|
|
251
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
252
|
+
return erc721Standard.getTokenURI(address, tokenId);
|
|
202
253
|
});
|
|
203
254
|
}
|
|
204
255
|
/**
|
|
205
256
|
* Query for name for a given asset.
|
|
206
257
|
*
|
|
207
258
|
* @param address - ERC721 or ERC20 asset contract address.
|
|
259
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
208
260
|
* @returns Promise resolving to the 'name'.
|
|
209
261
|
*/
|
|
210
|
-
getERC721AssetName(address) {
|
|
262
|
+
getERC721AssetName(address, networkClientId) {
|
|
211
263
|
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return this.erc721Standard.getAssetName(address);
|
|
264
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
265
|
+
return erc721Standard.getAssetName(address);
|
|
216
266
|
});
|
|
217
267
|
}
|
|
218
268
|
/**
|
|
219
269
|
* Query for symbol for a given asset.
|
|
220
270
|
*
|
|
221
271
|
* @param address - ERC721 or ERC20 asset contract address.
|
|
272
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
222
273
|
* @returns Promise resolving to the 'symbol'.
|
|
223
274
|
*/
|
|
224
|
-
getERC721AssetSymbol(address) {
|
|
275
|
+
getERC721AssetSymbol(address, networkClientId) {
|
|
225
276
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
return this.erc721Standard.getAssetSymbol(address);
|
|
277
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
278
|
+
return erc721Standard.getAssetSymbol(address);
|
|
230
279
|
});
|
|
231
280
|
}
|
|
232
281
|
/**
|
|
@@ -234,14 +283,13 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
234
283
|
*
|
|
235
284
|
* @param address - ERC721 asset contract address.
|
|
236
285
|
* @param tokenId - ERC721 asset identifier.
|
|
286
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
237
287
|
* @returns Promise resolving to the owner address.
|
|
238
288
|
*/
|
|
239
|
-
getERC721OwnerOf(address, tokenId) {
|
|
289
|
+
getERC721OwnerOf(address, tokenId, networkClientId) {
|
|
240
290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
return this.erc721Standard.getOwnerOf(address, tokenId);
|
|
291
|
+
const erc721Standard = this.getERC721Standard(networkClientId);
|
|
292
|
+
return erc721Standard.getOwnerOf(address, tokenId);
|
|
245
293
|
});
|
|
246
294
|
}
|
|
247
295
|
/**
|
|
@@ -249,14 +297,13 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
249
297
|
*
|
|
250
298
|
* @param address - ERC1155 asset contract address.
|
|
251
299
|
* @param tokenId - ERC1155 asset identifier.
|
|
300
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
252
301
|
* @returns Promise resolving to the 'tokenURI'.
|
|
253
302
|
*/
|
|
254
|
-
getERC1155TokenURI(address, tokenId) {
|
|
303
|
+
getERC1155TokenURI(address, tokenId, networkClientId) {
|
|
255
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
return this.erc1155Standard.getTokenURI(address, tokenId);
|
|
305
|
+
const erc1155Standard = this.getERC1155Standard(networkClientId);
|
|
306
|
+
return erc1155Standard.getTokenURI(address, tokenId);
|
|
260
307
|
});
|
|
261
308
|
}
|
|
262
309
|
/**
|
|
@@ -265,14 +312,13 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
265
312
|
* @param userAddress - Wallet public address.
|
|
266
313
|
* @param nftAddress - ERC1155 asset contract address.
|
|
267
314
|
* @param nftId - ERC1155 asset identifier.
|
|
315
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
268
316
|
* @returns Promise resolving to the 'balanceOf'.
|
|
269
317
|
*/
|
|
270
|
-
getERC1155BalanceOf(userAddress, nftAddress, nftId) {
|
|
318
|
+
getERC1155BalanceOf(userAddress, nftAddress, nftId, networkClientId) {
|
|
271
319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
return yield this.erc1155Standard.getBalanceOf(nftAddress, userAddress, nftId);
|
|
320
|
+
const erc1155Standard = this.getERC1155Standard(networkClientId);
|
|
321
|
+
return erc1155Standard.getBalanceOf(nftAddress, userAddress, nftId);
|
|
276
322
|
});
|
|
277
323
|
}
|
|
278
324
|
/**
|
|
@@ -283,14 +329,13 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
283
329
|
* @param recipientAddress - ERC1155 token recipient.
|
|
284
330
|
* @param nftId - ERC1155 token id.
|
|
285
331
|
* @param qty - Quantity of tokens to be sent.
|
|
332
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
286
333
|
* @returns Promise resolving to the 'transferSingle' ERC1155 token.
|
|
287
334
|
*/
|
|
288
|
-
transferSingleERC1155(nftAddress, senderAddress, recipientAddress, nftId, qty) {
|
|
335
|
+
transferSingleERC1155(nftAddress, senderAddress, recipientAddress, nftId, qty, networkClientId) {
|
|
289
336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
return yield this.erc1155Standard.transferSingle(nftAddress, senderAddress, recipientAddress, nftId, qty);
|
|
337
|
+
const erc1155Standard = this.getERC1155Standard(networkClientId);
|
|
338
|
+
return erc1155Standard.transferSingle(nftAddress, senderAddress, recipientAddress, nftId, qty);
|
|
294
339
|
});
|
|
295
340
|
}
|
|
296
341
|
/**
|
|
@@ -299,16 +344,19 @@ class AssetsContractController extends base_controller_1.BaseController {
|
|
|
299
344
|
*
|
|
300
345
|
* @param selectedAddress - The address to check token balances for.
|
|
301
346
|
* @param tokensToDetect - The token addresses to detect balances for.
|
|
347
|
+
* @param networkClientId - Network Client ID to fetch the provider with.
|
|
302
348
|
* @returns The list of non-zero token balances.
|
|
303
349
|
*/
|
|
304
|
-
getBalancesInSingleCall(selectedAddress, tokensToDetect) {
|
|
350
|
+
getBalancesInSingleCall(selectedAddress, tokensToDetect, networkClientId) {
|
|
305
351
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
|
|
352
|
+
const chainId = this.getChainId(networkClientId);
|
|
353
|
+
const provider = this.getProvider(networkClientId);
|
|
354
|
+
if (!(chainId in exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID)) {
|
|
307
355
|
// Only fetch balance if contract address exists
|
|
308
356
|
return {};
|
|
309
357
|
}
|
|
310
|
-
const contractAddress = exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[
|
|
311
|
-
const contract = new contracts_1.Contract(contractAddress, single_call_balance_checker_abi_1.default,
|
|
358
|
+
const contractAddress = exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[chainId];
|
|
359
|
+
const contract = new contracts_1.Contract(contractAddress, single_call_balance_checker_abi_1.default, provider);
|
|
312
360
|
const result = yield contract.balances([selectedAddress], tokensToDetect);
|
|
313
361
|
const nonZeroBalances = {};
|
|
314
362
|
/* istanbul ignore else */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsContractController.js","sourceRoot":"","sources":["../src/AssetsContractController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAoD;AACpD,wDAAwD;AAExD,+DAA2D;AAC3D,iEAAsE;AAKtE,sGAA4E;AAE5E,6CAA+D;AAC/D,6DAA0D;AAC1D,sFAAmF;AACnF,mFAAgF;AAEhF;;;;;GAKG;AACU,QAAA,uCAAuC,GAAwB;IAC1E,CAAC,4CAA+B,CAAC,OAAO,CAAC,EACvC,4CAA4C;IAC9C,CAAC,4CAA+B,CAAC,GAAG,CAAC,EACnC,4CAA4C;IAC9C,CAAC,4CAA+B,CAAC,OAAO,CAAC,EACvC,4CAA4C;IAC9C,CAAC,4CAA+B,CAAC,IAAI,CAAC,EACpC,4CAA4C;IAC9C,CAAC,4CAA+B,CAAC,MAAM,CAAC,EACtC,4CAA4C;CAC/C,CAAC;AAEW,QAAA,sBAAsB,GACjC,uHAAuH,CAAC;AAwB1H;;GAEG;AACH,MAAa,wBAAyB,SAAQ,gCAG7C;IAcC;;;;;;;;;OASG;IACH,YACE,EACE,OAAO,EAAE,cAAc,EACvB,wBAAwB,EACxB,oBAAoB,GASrB,EACD,MAAsC,EACtC,KAA0B;QAE1B,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAhCvB;;WAEG;QACM,SAAI,GAAG,0BAA0B,CAAC;QA8BzC,IAAI,CAAC,aAAa,GAAG;YACnB,QAAQ,EAAE,SAAS;YACnB,WAAW,EAAE,2CAAwB;YACrC,OAAO,EAAE,cAAc;SACxB,CAAC;QACF,IAAI,CAAC,UAAU,EA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,IAAI,CAAC,SAAS,CACf,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,cAAc,CAAC,CAAC;YAC1E,MAAM,eAAe,GAAe,EAAE,CAAC;YACvC,0BAA0B;YAC1B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;oBAC7C,MAAM,OAAO,GAAO,MAAM,CAAC,KAAK,CAAC,CAAC;oBAClC,0BAA0B;oBAC1B,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE;wBAC3B,eAAe,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC;qBACzC;gBACH,CAAC,CAAC,CAAC;aACJ;YACD,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF;AAnXD,4DAmXC;AAED,kBAAe,wBAAwB,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { IPFS_DEFAULT_GATEWAY_URL } from '@metamask/controller-utils';\nimport type { NetworkState } from '@metamask/network-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport type { Hex } from '@metamask/utils';\nimport type { BN } from 'ethereumjs-util';\nimport abiSingleCallBalancesContract from 'single-call-balance-checker-abi';\n\nimport { SupportedTokenDetectionNetworks } from './assetsUtil';\nimport { ERC20Standard } from './Standards/ERC20Standard';\nimport { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standard';\nimport { ERC721Standard } from './Standards/NftStandards/ERC721/ERC721Standard';\n\n/**\n * Check if token detection is enabled for certain networks\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports token detection\n */\nexport const SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID: Record<Hex, string> = {\n [SupportedTokenDetectionNetworks.mainnet]:\n '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39',\n [SupportedTokenDetectionNetworks.bsc]:\n '0x2352c63A83f9Fd126af8676146721Fa00924d7e4',\n [SupportedTokenDetectionNetworks.polygon]:\n '0x2352c63A83f9Fd126af8676146721Fa00924d7e4',\n [SupportedTokenDetectionNetworks.avax]:\n '0xD023D153a0DFa485130ECFdE2FAA7e612EF94818',\n [SupportedTokenDetectionNetworks.aurora]:\n '0x1286415D333855237f89Df27D388127181448538',\n};\n\nexport const MISSING_PROVIDER_ERROR =\n 'AssetsContractController failed to set the provider correctly. A provider must be set for this method to be available';\n\n/**\n * @type AssetsContractConfig\n *\n * Assets Contract controller configuration\n * @property provider - Provider used to create a new web3 instance\n */\nexport interface AssetsContractConfig extends BaseConfig {\n provider: any;\n ipfsGateway: string;\n chainId: Hex;\n}\n\n/**\n * @type BalanceMap\n *\n * Key value object containing the balance for each tokenAddress\n * @property [tokenAddress] - Address of the token\n */\nexport interface BalanceMap {\n [tokenAddress: string]: BN;\n}\n\n/**\n * Controller that interacts with contracts on mainnet through web3\n */\nexport class AssetsContractController extends BaseController<\n AssetsContractConfig,\n BaseState\n> {\n private _provider?: Web3Provider;\n\n private erc721Standard?: ERC721Standard;\n\n private erc1155Standard?: ERC1155Standard;\n\n private erc20Standard?: ERC20Standard;\n\n /**\n * Name of this controller used during composition\n */\n override name = 'AssetsContractController';\n\n /**\n * Creates a AssetsContractController instance.\n *\n * @param options - The controller options.\n * @param options.chainId - The chain ID of the current network.\n * @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.\n * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n chainId: initialChainId,\n onPreferencesStateChange,\n onNetworkStateChange,\n }: {\n chainId: Hex;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n },\n config?: Partial<AssetsContractConfig>,\n state?: Partial<BaseState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n provider: undefined,\n ipfsGateway: IPFS_DEFAULT_GATEWAY_URL,\n chainId: initialChainId,\n };\n this.initialize();\n\n onPreferencesStateChange(({ ipfsGateway }) => {\n this.configure({ ipfsGateway });\n });\n\n onNetworkStateChange((networkState) => {\n if (this.config.chainId !== networkState.providerConfig.chainId) {\n this.configure({\n chainId: networkState.providerConfig.chainId,\n });\n }\n });\n }\n\n /**\n * Sets a new provider.\n *\n * TODO: Replace this wth a method.\n *\n * @property provider - Provider used to create a new underlying Web3 instance\n */\n set provider(provider: any) {\n this._provider = new Web3Provider(provider);\n this.erc721Standard = new ERC721Standard(this._provider);\n this.erc1155Standard = new ERC1155Standard(this._provider);\n this.erc20Standard = new ERC20Standard(this._provider);\n }\n\n get provider() {\n throw new Error('Property only used for setting');\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getERC20BalanceOf(\n address: string,\n selectedAddress: string,\n ): Promise<BN> {\n if (!this.erc20Standard) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc20Standard.getBalanceOf(address, selectedAddress);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'decimals'.\n */\n async getERC20TokenDecimals(address: string): Promise<string> {\n if (this.erc20Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return await this.erc20Standard.getTokenDecimals(address);\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @returns Promise resolving to the 'decimals'.\n */\n async getERC20TokenName(address: string): Promise<string> {\n if (this.erc20Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return await this.erc20Standard.getTokenName(address);\n }\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getERC721NftTokenId(\n address: string,\n selectedAddress: string,\n index: number,\n ): Promise<string> {\n if (this.erc721Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc721Standard.getNftTokenId(address, selectedAddress, index);\n }\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param tokenAddress - ERC721 asset contract address.\n * @param userAddress - Current account public address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to an object containing the token standard and a set of details which depend on which standard the token supports.\n */\n async getTokenStandardAndDetails(\n tokenAddress: string,\n userAddress?: string,\n tokenId?: string,\n ): Promise<{\n standard: string;\n tokenURI?: string | undefined;\n symbol?: string | undefined;\n name?: string | undefined;\n decimals?: string | undefined;\n balance?: BN | undefined;\n }> {\n if (\n this.erc721Standard === undefined ||\n this.erc1155Standard === undefined ||\n this.erc20Standard === undefined\n ) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n\n const { ipfsGateway } = this.config;\n\n // ERC721\n try {\n return {\n ...(await this.erc721Standard.getDetails(\n tokenAddress,\n ipfsGateway,\n tokenId,\n )),\n };\n } catch {\n // Ignore\n }\n\n // ERC1155\n try {\n return {\n ...(await this.erc1155Standard.getDetails(\n tokenAddress,\n ipfsGateway,\n tokenId,\n )),\n };\n } catch {\n // Ignore\n }\n\n // ERC20\n try {\n return {\n ...(await this.erc20Standard.getDetails(tokenAddress, userAddress)),\n };\n } catch {\n // Ignore\n }\n\n throw new Error('Unable to determine contract standard');\n }\n\n /**\n * Query for tokenURI for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getERC721TokenURI(address: string, tokenId: string): Promise<string> {\n if (this.erc721Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc721Standard.getTokenURI(address, tokenId);\n }\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 or ERC20 asset contract address.\n * @returns Promise resolving to the 'name'.\n */\n async getERC721AssetName(address: string): Promise<string> {\n if (this.erc721Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc721Standard.getAssetName(address);\n }\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 or ERC20 asset contract address.\n * @returns Promise resolving to the 'symbol'.\n */\n async getERC721AssetSymbol(address: string): Promise<string> {\n if (this.erc721Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc721Standard.getAssetSymbol(address);\n }\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @returns Promise resolving to the owner address.\n */\n async getERC721OwnerOf(address: string, tokenId: string): Promise<string> {\n if (this.erc721Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc721Standard.getOwnerOf(address, tokenId);\n }\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @param tokenId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getERC1155TokenURI(address: string, tokenId: string): Promise<string> {\n if (this.erc1155Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return this.erc1155Standard.getTokenURI(address, tokenId);\n }\n\n /**\n * Query for balance of a given ERC 1155 token.\n *\n * @param userAddress - Wallet public address.\n * @param nftAddress - ERC1155 asset contract address.\n * @param nftId - ERC1155 asset identifier.\n * @returns Promise resolving to the 'balanceOf'.\n */\n async getERC1155BalanceOf(\n userAddress: string,\n nftAddress: string,\n nftId: string,\n ): Promise<BN> {\n if (this.erc1155Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return await this.erc1155Standard.getBalanceOf(\n nftAddress,\n userAddress,\n nftId,\n );\n }\n\n /**\n * Transfer single ERC1155 token.\n *\n * @param nftAddress - ERC1155 token address.\n * @param senderAddress - ERC1155 token sender.\n * @param recipientAddress - ERC1155 token recipient.\n * @param nftId - ERC1155 token id.\n * @param qty - Quantity of tokens to be sent.\n * @returns Promise resolving to the 'transferSingle' ERC1155 token.\n */\n async transferSingleERC1155(\n nftAddress: string,\n senderAddress: string,\n recipientAddress: string,\n nftId: string,\n qty: string,\n ): Promise<void> {\n if (this.erc1155Standard === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n return await this.erc1155Standard.transferSingle(\n nftAddress,\n senderAddress,\n recipientAddress,\n nftId,\n qty,\n );\n }\n\n /**\n * Get the token balance for a list of token addresses in a single call. Only non-zero balances\n * are returned.\n *\n * @param selectedAddress - The address to check token balances for.\n * @param tokensToDetect - The token addresses to detect balances for.\n * @returns The list of non-zero token balances.\n */\n async getBalancesInSingleCall(\n selectedAddress: string,\n tokensToDetect: string[],\n ) {\n if (!(this.config.chainId in SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID)) {\n // Only fetch balance if contract address exists\n return {};\n }\n const contractAddress =\n SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[this.config.chainId];\n\n const contract = new Contract(\n contractAddress,\n abiSingleCallBalancesContract,\n this._provider,\n );\n const result = await contract.balances([selectedAddress], tokensToDetect);\n const nonZeroBalances: BalanceMap = {};\n /* istanbul ignore else */\n if (result.length > 0) {\n tokensToDetect.forEach((tokenAddress, index) => {\n const balance: BN = result[index];\n /* istanbul ignore else */\n if (String(balance) !== '0') {\n nonZeroBalances[tokenAddress] = balance;\n }\n });\n }\n return nonZeroBalances;\n }\n}\n\nexport default AssetsContractController;\n"]}
|
|
1
|
+
{"version":3,"file":"AssetsContractController.js","sourceRoot":"","sources":["../src/AssetsContractController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAoD;AACpD,w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C,eAAe,CAAC,CAAC;YACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;YACnD,IAAI,CAAC,CAAC,OAAO,IAAI,+CAAuC,CAAC,EAAE;gBACzD,gDAAgD;gBAChD,OAAO,EAAE,CAAC;aACX;YACD,MAAM,eAAe,GAAG,+CAAuC,CAAC,OAAO,CAAC,CAAC;YAEzE,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAC3B,eAAe,EACf,yCAA6B,EAC7B,QAAQ,CACT,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,cAAc,CAAC,CAAC;YAC1E,MAAM,eAAe,GAAe,EAAE,CAAC;YACvC,0BAA0B;YAC1B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;oBAC7C,MAAM,OAAO,GAAO,MAAM,CAAC,KAAK,CAAC,CAAC;oBAClC,0BAA0B;oBAC1B,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE;wBAC3B,eAAe,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC;qBACzC;gBACH,CAAC,CAAC,CAAC;aACJ;YACD,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF;AA/bD,4DA+bC;AAED,kBAAe,wBAAwB,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { IPFS_DEFAULT_GATEWAY_URL } from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkState,\n NetworkController,\n} from '@metamask/network-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport type { Hex } from '@metamask/utils';\nimport type { BN } from 'ethereumjs-util';\nimport abiSingleCallBalancesContract from 'single-call-balance-checker-abi';\n\nimport { SupportedTokenDetectionNetworks } from './assetsUtil';\nimport { ERC20Standard } from './Standards/ERC20Standard';\nimport { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standard';\nimport { ERC721Standard } from './Standards/NftStandards/ERC721/ERC721Standard';\n\n/**\n * Check if token detection is enabled for certain networks\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports token detection\n */\nexport const SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID: Record<Hex, string> = {\n [SupportedTokenDetectionNetworks.mainnet]:\n '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39',\n [SupportedTokenDetectionNetworks.bsc]:\n '0x2352c63A83f9Fd126af8676146721Fa00924d7e4',\n [SupportedTokenDetectionNetworks.polygon]:\n '0x2352c63A83f9Fd126af8676146721Fa00924d7e4',\n [SupportedTokenDetectionNetworks.avax]:\n '0xD023D153a0DFa485130ECFdE2FAA7e612EF94818',\n [SupportedTokenDetectionNetworks.aurora]:\n '0x1286415D333855237f89Df27D388127181448538',\n};\n\nexport const MISSING_PROVIDER_ERROR =\n 'AssetsContractController failed to set the provider correctly. A provider must be set for this method to be available';\n\n/**\n * @type AssetsContractConfig\n *\n * Assets Contract controller configuration\n * @property provider - Provider used to create a new web3 instance\n */\nexport interface AssetsContractConfig extends BaseConfig {\n provider: any;\n ipfsGateway: string;\n chainId: Hex;\n}\n\n/**\n * @type BalanceMap\n *\n * Key value object containing the balance for each tokenAddress\n * @property [tokenAddress] - Address of the token\n */\nexport interface BalanceMap {\n [tokenAddress: string]: BN;\n}\n\n/**\n * Controller that interacts with contracts on mainnet through web3\n */\nexport class AssetsContractController extends BaseController<\n AssetsContractConfig,\n BaseState\n> {\n private _provider?: any;\n\n /**\n * Name of this controller used during composition\n */\n override name = 'AssetsContractController';\n\n private readonly getNetworkClientById: NetworkController['getNetworkClientById'];\n\n /**\n * Creates a AssetsContractController instance.\n *\n * @param options - The controller options.\n * @param options.chainId - The chain ID of the current network.\n * @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.\n * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.\n * @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(\n {\n chainId: initialChainId,\n onPreferencesStateChange,\n onNetworkStateChange,\n getNetworkClientById,\n }: {\n chainId: Hex;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n onNetworkStateChange: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n getNetworkClientById: NetworkController['getNetworkClientById'];\n },\n config?: Partial<AssetsContractConfig>,\n state?: Partial<BaseState>,\n ) {\n super(config, state);\n this.defaultConfig = {\n provider: undefined,\n ipfsGateway: IPFS_DEFAULT_GATEWAY_URL,\n chainId: initialChainId,\n };\n this.initialize();\n this.getNetworkClientById = getNetworkClientById;\n\n onPreferencesStateChange(({ ipfsGateway }) => {\n this.configure({ ipfsGateway });\n });\n\n onNetworkStateChange((networkState) => {\n if (this.config.chainId !== networkState.providerConfig.chainId) {\n this.configure({\n chainId: networkState.providerConfig.chainId,\n });\n }\n });\n }\n\n /**\n * Sets a new provider.\n *\n * TODO: Replace this wth a method.\n *\n * @property provider - Provider used to create a new underlying Web3 instance\n */\n set provider(provider: any) {\n this._provider = provider;\n }\n\n get provider() {\n throw new Error('Property only used for setting');\n }\n\n /**\n * Get the relevant provider instance.\n *\n * @param networkClientId - Network Client ID.\n * @returns Web3Provider instance.\n */\n getProvider(networkClientId?: NetworkClientId): Web3Provider {\n const provider = networkClientId\n ? this.getNetworkClientById(networkClientId).provider\n : this._provider;\n\n if (provider === undefined) {\n throw new Error(MISSING_PROVIDER_ERROR);\n }\n\n return new Web3Provider(provider);\n }\n\n /**\n * Get the relevant chain ID.\n *\n * @param networkClientId - Network Client ID used to get the provider.\n * @returns Hex chain ID.\n */\n getChainId(networkClientId?: NetworkClientId): Hex {\n return networkClientId\n ? this.getNetworkClientById(networkClientId).configuration.chainId\n : this.config.chainId;\n }\n\n /**\n * Get a ERC20Standard instance using the relevant provider instance.\n *\n * @param networkClientId - Network Client ID used to get the provider.\n * @returns ERC20Standard instance.\n */\n getERC20Standard(networkClientId?: NetworkClientId): ERC20Standard {\n const provider = this.getProvider(networkClientId);\n return new ERC20Standard(provider);\n }\n\n /**\n * Get a ERC721Standard instance using the relevant provider instance.\n *\n * @param networkClientId - Network Client ID used to get the provider.\n * @returns ERC721Standard instance.\n */\n getERC721Standard(networkClientId?: NetworkClientId): ERC721Standard {\n const provider = this.getProvider(networkClientId);\n return new ERC721Standard(provider);\n }\n\n /**\n * Get a ERC1155Standard instance using the relevant provider instance.\n *\n * @param networkClientId - Network Client ID used to get the provider.\n * @returns ERC1155Standard instance.\n */\n getERC1155Standard(networkClientId?: NetworkClientId): ERC1155Standard {\n const provider = this.getProvider(networkClientId);\n return new ERC1155Standard(provider);\n }\n\n /**\n * Get balance or count for current account on specific asset contract.\n *\n * @param address - Asset ERC20 contract address.\n * @param selectedAddress - Current account public address.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to BN object containing balance for current account on specific asset contract.\n */\n async getERC20BalanceOf(\n address: string,\n selectedAddress: string,\n networkClientId?: NetworkClientId,\n ): Promise<BN> {\n const erc20Standard = this.getERC20Standard(networkClientId);\n return erc20Standard.getBalanceOf(address, selectedAddress);\n }\n\n /**\n * Query for the decimals for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'decimals'.\n */\n async getERC20TokenDecimals(\n address: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc20Standard = this.getERC20Standard(networkClientId);\n return erc20Standard.getTokenDecimals(address);\n }\n\n /**\n * Query for the name for a given ERC20 asset.\n *\n * @param address - ERC20 asset contract address.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'decimals'.\n */\n async getERC20TokenName(\n address: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc20Standard = this.getERC20Standard(networkClientId);\n return erc20Standard.getTokenName(address);\n }\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param address - ERC721 asset contract address.\n * @param selectedAddress - Current account public address.\n * @param index - An NFT counter less than `balanceOf(selectedAddress)`.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.\n */\n getERC721NftTokenId(\n address: string,\n selectedAddress: string,\n index: number,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return erc721Standard.getNftTokenId(address, selectedAddress, index);\n }\n\n /**\n * Enumerate assets assigned to an owner.\n *\n * @param tokenAddress - ERC721 asset contract address.\n * @param userAddress - Current account public address.\n * @param tokenId - ERC721 asset identifier.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to an object containing the token standard and a set of details which depend on which standard the token supports.\n */\n async getTokenStandardAndDetails(\n tokenAddress: string,\n userAddress?: string,\n tokenId?: string,\n networkClientId?: NetworkClientId,\n ): Promise<{\n standard: string;\n tokenURI?: string | undefined;\n symbol?: string | undefined;\n name?: string | undefined;\n decimals?: string | undefined;\n balance?: BN | undefined;\n }> {\n // Asserts provider is available\n this.getProvider(networkClientId);\n\n const { ipfsGateway } = this.config;\n\n // ERC721\n try {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return {\n ...(await erc721Standard.getDetails(\n tokenAddress,\n ipfsGateway,\n tokenId,\n )),\n };\n } catch {\n // Ignore\n }\n\n // ERC1155\n try {\n const erc1155Standard = this.getERC1155Standard(networkClientId);\n return {\n ...(await erc1155Standard.getDetails(\n tokenAddress,\n ipfsGateway,\n tokenId,\n )),\n };\n } catch {\n // Ignore\n }\n\n // ERC20\n try {\n const erc20Standard = this.getERC20Standard(networkClientId);\n return {\n ...(await erc20Standard.getDetails(tokenAddress, userAddress)),\n };\n } catch {\n // Ignore\n }\n\n throw new Error('Unable to determine contract standard');\n }\n\n /**\n * Query for tokenURI for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getERC721TokenURI(\n address: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return erc721Standard.getTokenURI(address, tokenId);\n }\n\n /**\n * Query for name for a given asset.\n *\n * @param address - ERC721 or ERC20 asset contract address.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'name'.\n */\n async getERC721AssetName(\n address: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return erc721Standard.getAssetName(address);\n }\n\n /**\n * Query for symbol for a given asset.\n *\n * @param address - ERC721 or ERC20 asset contract address.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'symbol'.\n */\n async getERC721AssetSymbol(\n address: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return erc721Standard.getAssetSymbol(address);\n }\n\n /**\n * Query for owner for a given ERC721 asset.\n *\n * @param address - ERC721 asset contract address.\n * @param tokenId - ERC721 asset identifier.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the owner address.\n */\n async getERC721OwnerOf(\n address: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc721Standard = this.getERC721Standard(networkClientId);\n return erc721Standard.getOwnerOf(address, tokenId);\n }\n\n /**\n * Query for tokenURI for a given asset.\n *\n * @param address - ERC1155 asset contract address.\n * @param tokenId - ERC1155 asset identifier.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'tokenURI'.\n */\n async getERC1155TokenURI(\n address: string,\n tokenId: string,\n networkClientId?: NetworkClientId,\n ): Promise<string> {\n const erc1155Standard = this.getERC1155Standard(networkClientId);\n return erc1155Standard.getTokenURI(address, tokenId);\n }\n\n /**\n * Query for balance of a given ERC 1155 token.\n *\n * @param userAddress - Wallet public address.\n * @param nftAddress - ERC1155 asset contract address.\n * @param nftId - ERC1155 asset identifier.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'balanceOf'.\n */\n async getERC1155BalanceOf(\n userAddress: string,\n nftAddress: string,\n nftId: string,\n networkClientId?: NetworkClientId,\n ): Promise<BN> {\n const erc1155Standard = this.getERC1155Standard(networkClientId);\n return erc1155Standard.getBalanceOf(nftAddress, userAddress, nftId);\n }\n\n /**\n * Transfer single ERC1155 token.\n *\n * @param nftAddress - ERC1155 token address.\n * @param senderAddress - ERC1155 token sender.\n * @param recipientAddress - ERC1155 token recipient.\n * @param nftId - ERC1155 token id.\n * @param qty - Quantity of tokens to be sent.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns Promise resolving to the 'transferSingle' ERC1155 token.\n */\n async transferSingleERC1155(\n nftAddress: string,\n senderAddress: string,\n recipientAddress: string,\n nftId: string,\n qty: string,\n networkClientId?: NetworkClientId,\n ): Promise<void> {\n const erc1155Standard = this.getERC1155Standard(networkClientId);\n return erc1155Standard.transferSingle(\n nftAddress,\n senderAddress,\n recipientAddress,\n nftId,\n qty,\n );\n }\n\n /**\n * Get the token balance for a list of token addresses in a single call. Only non-zero balances\n * are returned.\n *\n * @param selectedAddress - The address to check token balances for.\n * @param tokensToDetect - The token addresses to detect balances for.\n * @param networkClientId - Network Client ID to fetch the provider with.\n * @returns The list of non-zero token balances.\n */\n async getBalancesInSingleCall(\n selectedAddress: string,\n tokensToDetect: string[],\n networkClientId?: NetworkClientId,\n ) {\n const chainId = this.getChainId(networkClientId);\n const provider = this.getProvider(networkClientId);\n if (!(chainId in SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID)) {\n // Only fetch balance if contract address exists\n return {};\n }\n const contractAddress = SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[chainId];\n\n const contract = new Contract(\n contractAddress,\n abiSingleCallBalancesContract,\n provider,\n );\n const result = await contract.balances([selectedAddress], tokensToDetect);\n const nonZeroBalances: BalanceMap = {};\n /* istanbul ignore else */\n if (result.length > 0) {\n tokensToDetect.forEach((tokenAddress, index) => {\n const balance: BN = result[index];\n /* istanbul ignore else */\n if (String(balance) !== '0') {\n nonZeroBalances[tokenAddress] = balance;\n }\n });\n }\n return nonZeroBalances;\n }\n}\n\nexport default AssetsContractController;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/assets-controllers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"@ethersproject/bignumber": "^5.7.0",
|
|
33
33
|
"@ethersproject/contracts": "^5.7.0",
|
|
34
34
|
"@ethersproject/providers": "^5.7.0",
|
|
35
|
-
"@metamask/abi-utils": "^2.0.
|
|
35
|
+
"@metamask/abi-utils": "^2.0.2",
|
|
36
36
|
"@metamask/approval-controller": "^3.5.1",
|
|
37
37
|
"@metamask/base-controller": "^3.2.1",
|
|
38
38
|
"@metamask/contract-metadata": "^2.3.1",
|
|
39
39
|
"@metamask/controller-utils": "^4.3.2",
|
|
40
40
|
"@metamask/eth-query": "^3.0.1",
|
|
41
41
|
"@metamask/metamask-eth-abis": "3.0.0",
|
|
42
|
-
"@metamask/network-controller": "^12.
|
|
42
|
+
"@metamask/network-controller": "^12.2.0",
|
|
43
43
|
"@metamask/preferences-controller": "^4.4.0",
|
|
44
44
|
"@metamask/rpc-errors": "^5.1.1",
|
|
45
45
|
"@metamask/utils": "^6.2.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@metamask/approval-controller": "^3.5.1",
|
|
72
|
-
"@metamask/network-controller": "^12.
|
|
72
|
+
"@metamask/network-controller": "^12.2.0",
|
|
73
73
|
"@metamask/preferences-controller": "^4.4.0"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|