@metamask-previews/assets-controllers 11.1.0-preview.04c2e62 → 11.1.0-preview.2f7e793
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/dist/AssetsContractController.d.ts +70 -18
- package/dist/AssetsContractController.d.ts.map +1 -1
- package/dist/AssetsContractController.js +121 -73
- package/dist/AssetsContractController.js.map +1 -1
- package/dist/TokensController.d.ts +45 -21
- package/dist/TokensController.d.ts.map +1 -1
- package/dist/TokensController.js +55 -28
- package/dist/TokensController.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,EAAE,EA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Ae,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 */
|