@metamask-previews/assets-controllers 36.0.0-preview-e9effc96 → 36.0.0-preview-276db038
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.js +6 -6
- package/dist/AssetsContractController.mjs +5 -5
- package/dist/NftController.js +3 -3
- package/dist/NftController.mjs +2 -2
- package/dist/NftDetectionController.js +3 -3
- package/dist/NftDetectionController.mjs +2 -2
- package/dist/Standards/ERC20Standard.js +3 -3
- package/dist/Standards/ERC20Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs +2 -2
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.js +3 -3
- package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +2 -2
- package/dist/TokenBalancesController.js +2 -2
- package/dist/TokenBalancesController.mjs +1 -1
- package/dist/TokenDetectionController.js +3 -3
- package/dist/TokenDetectionController.mjs +2 -2
- package/dist/TokenListController.js +4 -4
- package/dist/TokenListController.mjs +3 -3
- package/dist/TokenRatesController.js +3 -3
- package/dist/TokenRatesController.mjs +2 -2
- package/dist/TokensController.js +6 -6
- package/dist/TokensController.mjs +5 -5
- package/dist/assetsUtil.js +2 -2
- package/dist/assetsUtil.mjs +1 -1
- package/dist/{chunk-2J3CVSQ5.js → chunk-3LPQTUGG.js} +5 -5
- package/dist/{chunk-7H2V5SW4.mjs → chunk-3QDXAE2D.mjs} +2 -2
- package/dist/{chunk-PPJTMDXC.mjs → chunk-46KUC5FH.mjs} +2 -2
- package/dist/{chunk-RXBDSHHH.mjs → chunk-54JUUBXY.mjs} +5 -5
- package/dist/{chunk-B46K3T54.js → chunk-5QLC2MHV.js} +5 -5
- package/dist/{chunk-TPUVGGNO.js → chunk-ADJ3IFJH.js} +11 -11
- package/dist/{chunk-5IMEJ2FS.mjs → chunk-AX522TDL.mjs} +2 -2
- package/dist/{chunk-Z6NCPTNT.js → chunk-BBCZM5P4.js} +3 -3
- package/dist/{chunk-24HGVPDI.mjs → chunk-BZEAPSD5.mjs} +5 -5
- package/dist/chunk-BZEAPSD5.mjs.map +1 -0
- package/dist/{chunk-RI6LDZPC.mjs → chunk-C7LNCQXM.mjs} +2 -2
- package/dist/{chunk-62HDABFM.mjs → chunk-CN53OZAM.mjs} +135 -79
- package/dist/chunk-CN53OZAM.mjs.map +1 -0
- package/dist/{chunk-K6DUHENW.mjs → chunk-CUFSPB7T.mjs} +2 -2
- package/dist/{chunk-IJS7EZU2.js → chunk-GHG3DOUK.js} +138 -82
- package/dist/chunk-GHG3DOUK.js.map +1 -0
- package/dist/{chunk-4U2L56TY.js → chunk-ISK2VSBB.js} +4 -4
- package/dist/{chunk-DOCJ35CC.js → chunk-JCR4H6YL.js} +3 -3
- package/dist/{chunk-6VQJFTNC.mjs → chunk-JJX7TMH5.mjs} +8 -11
- package/dist/chunk-JJX7TMH5.mjs.map +1 -0
- package/dist/{chunk-OJLB6FID.js → chunk-K7A3EOIM.js} +3 -3
- package/dist/{chunk-A7VI64MA.mjs → chunk-KPBNX6GP.mjs} +2 -2
- package/dist/{chunk-R4HATJKU.js → chunk-MZI3SDQN.js} +7 -7
- package/dist/chunk-MZI3SDQN.js.map +1 -0
- package/dist/{chunk-2YFZGRUL.mjs → chunk-S5CFNNOM.mjs} +2 -2
- package/dist/{chunk-ZWZZUFO5.mjs → chunk-TFLYM4PY.mjs} +3 -3
- package/dist/{chunk-HTIZ4JKG.js → chunk-UOHZYA2W.js} +42 -43
- package/dist/chunk-UOHZYA2W.js.map +1 -0
- package/dist/{chunk-OCV7GPA2.mjs → chunk-V2OAFJSL.mjs} +39 -40
- package/dist/chunk-V2OAFJSL.mjs.map +1 -0
- package/dist/{chunk-DSDI75PJ.js → chunk-X2HRAVDO.js} +4 -4
- package/dist/{chunk-NHFZIY2K.js → chunk-YGGUAMHV.js} +7 -10
- package/dist/chunk-YGGUAMHV.js.map +1 -0
- package/dist/{chunk-3QLHZOXA.js → chunk-ZAR4BIOC.js} +7 -7
- package/dist/index.js +14 -16
- package/dist/index.mjs +13 -15
- package/dist/token-service.js +3 -3
- package/dist/token-service.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/AssetsContractController.d.ts +93 -56
- package/dist/types/AssetsContractController.d.ts.map +1 -1
- package/dist/types/NftController.d.ts +3 -15
- package/dist/types/NftController.d.ts.map +1 -1
- package/dist/types/TokenBalancesController.d.ts +6 -8
- package/dist/types/TokenBalancesController.d.ts.map +1 -1
- package/dist/types/assetsUtil.d.ts +3 -3
- package/dist/types/assetsUtil.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +13 -12
- package/dist/chunk-24HGVPDI.mjs.map +0 -1
- package/dist/chunk-62HDABFM.mjs.map +0 -1
- package/dist/chunk-6VQJFTNC.mjs.map +0 -1
- package/dist/chunk-HTIZ4JKG.js.map +0 -1
- package/dist/chunk-IJS7EZU2.js.map +0 -1
- package/dist/chunk-NHFZIY2K.js.map +0 -1
- package/dist/chunk-OCV7GPA2.mjs.map +0 -1
- package/dist/chunk-R4HATJKU.js.map +0 -1
- /package/dist/{chunk-2J3CVSQ5.js.map → chunk-3LPQTUGG.js.map} +0 -0
- /package/dist/{chunk-7H2V5SW4.mjs.map → chunk-3QDXAE2D.mjs.map} +0 -0
- /package/dist/{chunk-PPJTMDXC.mjs.map → chunk-46KUC5FH.mjs.map} +0 -0
- /package/dist/{chunk-RXBDSHHH.mjs.map → chunk-54JUUBXY.mjs.map} +0 -0
- /package/dist/{chunk-B46K3T54.js.map → chunk-5QLC2MHV.js.map} +0 -0
- /package/dist/{chunk-TPUVGGNO.js.map → chunk-ADJ3IFJH.js.map} +0 -0
- /package/dist/{chunk-5IMEJ2FS.mjs.map → chunk-AX522TDL.mjs.map} +0 -0
- /package/dist/{chunk-Z6NCPTNT.js.map → chunk-BBCZM5P4.js.map} +0 -0
- /package/dist/{chunk-RI6LDZPC.mjs.map → chunk-C7LNCQXM.mjs.map} +0 -0
- /package/dist/{chunk-K6DUHENW.mjs.map → chunk-CUFSPB7T.mjs.map} +0 -0
- /package/dist/{chunk-4U2L56TY.js.map → chunk-ISK2VSBB.js.map} +0 -0
- /package/dist/{chunk-DOCJ35CC.js.map → chunk-JCR4H6YL.js.map} +0 -0
- /package/dist/{chunk-OJLB6FID.js.map → chunk-K7A3EOIM.js.map} +0 -0
- /package/dist/{chunk-A7VI64MA.mjs.map → chunk-KPBNX6GP.mjs.map} +0 -0
- /package/dist/{chunk-2YFZGRUL.mjs.map → chunk-S5CFNNOM.mjs.map} +0 -0
- /package/dist/{chunk-ZWZZUFO5.mjs.map → chunk-TFLYM4PY.mjs.map} +0 -0
- /package/dist/{chunk-DSDI75PJ.js.map → chunk-X2HRAVDO.js.map} +0 -0
- /package/dist/{chunk-3QLHZOXA.js.map → chunk-ZAR4BIOC.js.map} +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type { PreferencesState } from '@metamask/preferences-controller';
|
|
6
|
-
import type { Hex } from '@metamask/utils';
|
|
1
|
+
import type { ActionConstraint, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
|
+
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetNetworkConfigurationByNetworkClientId, NetworkControllerGetSelectedNetworkClientAction, NetworkControllerGetStateAction, NetworkControllerNetworkDidChangeEvent, Provider } from '@metamask/network-controller';
|
|
3
|
+
import type { PreferencesControllerStateChangeEvent } from '@metamask/preferences-controller';
|
|
4
|
+
import { type Hex } from '@metamask/utils';
|
|
7
5
|
import type BN from 'bn.js';
|
|
8
6
|
import { ERC20Standard } from './Standards/ERC20Standard';
|
|
9
7
|
import { ERC1155Standard } from './Standards/NftStandards/ERC1155/ERC1155Standard';
|
|
@@ -14,78 +12,117 @@ import { ERC721Standard } from './Standards/NftStandards/ERC721/ERC721Standard';
|
|
|
14
12
|
* @param chainId - ChainID of network
|
|
15
13
|
* @returns Whether the current network supports token detection
|
|
16
14
|
*/
|
|
17
|
-
export declare const SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID:
|
|
15
|
+
export declare const SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID: {
|
|
16
|
+
readonly "0x1": "0xb1f8e55c7f64d203c1400b9d8555d050f94adf39";
|
|
17
|
+
readonly "0x38": "0x2352c63A83f9Fd126af8676146721Fa00924d7e4";
|
|
18
|
+
readonly "0x89": "0x2352c63A83f9Fd126af8676146721Fa00924d7e4";
|
|
19
|
+
readonly "0xa86a": "0xD023D153a0DFa485130ECFdE2FAA7e612EF94818";
|
|
20
|
+
readonly "0x4e454152": "0x1286415D333855237f89Df27D388127181448538";
|
|
21
|
+
readonly "0xe704": "0x10dAd7Ca3921471f616db788D9300DC97Db01783";
|
|
22
|
+
readonly "0xe708": "0xF62e6a41561b3650a69Bb03199C735e3E3328c0D";
|
|
23
|
+
readonly "0xa4b1": "0x151E24A486D7258dd7C33Fb67E4bB01919B7B32c";
|
|
24
|
+
readonly "0xa": "0xB1c568e9C3E6bdaf755A60c7418C269eb11524FC";
|
|
25
|
+
readonly "0x2105": "0x6AA75276052D96696134252587894ef5FFA520af";
|
|
26
|
+
readonly "0x144": "0x458fEd3144680a5b8bcfaa0F9594aa19B4Ea2D34";
|
|
27
|
+
readonly "0x19": "0x768ca200f0fc702ac9ea502498c18f5eff176378";
|
|
28
|
+
readonly "0xa4ec": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
29
|
+
readonly "0x64": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
30
|
+
readonly "0xfa": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
31
|
+
readonly "0x44d": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
32
|
+
readonly "0x504": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
33
|
+
readonly "0x505": "0x6aa75276052d96696134252587894ef5ffa520af";
|
|
34
|
+
};
|
|
18
35
|
export declare const MISSING_PROVIDER_ERROR = "AssetsContractController failed to set the provider correctly. A provider must be set for this method to be available";
|
|
19
|
-
/**
|
|
20
|
-
* @type AssetsContractConfig
|
|
21
|
-
*
|
|
22
|
-
* Assets Contract controller configuration
|
|
23
|
-
* @property provider - Provider used to create a new web3 instance
|
|
24
|
-
*/
|
|
25
|
-
export interface AssetsContractConfig extends BaseConfig {
|
|
26
|
-
provider: Provider | undefined;
|
|
27
|
-
ipfsGateway: string;
|
|
28
|
-
chainId: Hex;
|
|
29
|
-
}
|
|
30
36
|
/**
|
|
31
37
|
* @type BalanceMap
|
|
32
38
|
*
|
|
33
39
|
* Key value object containing the balance for each tokenAddress
|
|
34
40
|
* @property [tokenAddress] - Address of the token
|
|
35
41
|
*/
|
|
36
|
-
export
|
|
42
|
+
export type BalanceMap = {
|
|
37
43
|
[tokenAddress: string]: BN;
|
|
38
|
-
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The name of the {@link AssetsContractController}
|
|
47
|
+
*/
|
|
48
|
+
declare const name = "AssetsContractController";
|
|
49
|
+
/**
|
|
50
|
+
* A utility type that derives the public method names of a given messenger consumer class,
|
|
51
|
+
* and uses it to generate the class's internal messenger action types.
|
|
52
|
+
* @template Controller - A messenger consumer class.
|
|
53
|
+
*/
|
|
54
|
+
type ControllerActionsMap<Controller> = {
|
|
55
|
+
[ClassMethod in keyof Controller as Controller[ClassMethod] extends ActionConstraint['handler'] ? ClassMethod : never]: {
|
|
56
|
+
type: `${typeof name}:${ClassMethod & string}`;
|
|
57
|
+
handler: Controller[ClassMethod];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
type AssetsContractControllerActionsMap = ControllerActionsMap<AssetsContractController>;
|
|
61
|
+
/**
|
|
62
|
+
* The union of all public class method names of {@link AssetsContractController}.
|
|
63
|
+
*/
|
|
64
|
+
type AssetsContractControllerMethodName = keyof AssetsContractControllerActionsMap;
|
|
65
|
+
/**
|
|
66
|
+
* The union of all internal messenger actions available to the {@link AssetsContractControllerMessenger}.
|
|
67
|
+
*/
|
|
68
|
+
export type AssetsContractControllerActions = AssetsContractControllerActionsMap[AssetsContractControllerMethodName];
|
|
69
|
+
export type AssetsContractControllerGetERC20StandardAction = AssetsContractControllerActionsMap['getERC20Standard'];
|
|
70
|
+
export type AssetsContractControllerGetERC721StandardAction = AssetsContractControllerActionsMap['getERC721Standard'];
|
|
71
|
+
export type AssetsContractControllerGetERC1155StandardAction = AssetsContractControllerActionsMap['getERC1155Standard'];
|
|
72
|
+
export type AssetsContractControllerGetERC20BalanceOfAction = AssetsContractControllerActionsMap['getERC20BalanceOf'];
|
|
73
|
+
export type AssetsContractControllerGetERC20TokenDecimalsAction = AssetsContractControllerActionsMap['getERC20TokenDecimals'];
|
|
74
|
+
export type AssetsContractControllerGetERC20TokenNameAction = AssetsContractControllerActionsMap['getERC20TokenName'];
|
|
75
|
+
export type AssetsContractControllerGetERC721NftTokenIdAction = AssetsContractControllerActionsMap['getERC721NftTokenId'];
|
|
76
|
+
export type AssetsContractControllerGetERC721TokenURIAction = AssetsContractControllerActionsMap['getERC721TokenURI'];
|
|
77
|
+
export type AssetsContractControllerGetERC721AssetNameAction = AssetsContractControllerActionsMap['getERC721AssetName'];
|
|
78
|
+
export type AssetsContractControllerGetERC721AssetSymbolAction = AssetsContractControllerActionsMap['getERC721AssetSymbol'];
|
|
79
|
+
export type AssetsContractControllerGetERC721OwnerOfAction = AssetsContractControllerActionsMap['getERC721OwnerOf'];
|
|
80
|
+
export type AssetsContractControllerGetERC1155TokenURIAction = AssetsContractControllerActionsMap['getERC1155TokenURI'];
|
|
81
|
+
export type AssetsContractControllerGetERC1155BalanceOfAction = AssetsContractControllerActionsMap['getERC1155BalanceOf'];
|
|
82
|
+
export type AssetsContractControllerTransferSingleERC1155Action = AssetsContractControllerActionsMap['transferSingleERC1155'];
|
|
83
|
+
export type AssetsContractControllerGetTokenStandardAndDetailsAction = AssetsContractControllerActionsMap['getTokenStandardAndDetails'];
|
|
84
|
+
export type AssetsContractControllerGetBalancesInSingleCallAction = AssetsContractControllerActionsMap['getBalancesInSingleCall'];
|
|
85
|
+
/**
|
|
86
|
+
* The union of all internal messenger events available to the {@link AssetsContractControllerMessenger}.
|
|
87
|
+
*/
|
|
88
|
+
export type AssetsContractControllerEvents = never;
|
|
89
|
+
/**
|
|
90
|
+
* The union of all external messenger actions that must be allowed by the {@link AssetsContractControllerMessenger}.
|
|
91
|
+
*/
|
|
92
|
+
export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetNetworkConfigurationByNetworkClientId | NetworkControllerGetSelectedNetworkClientAction | NetworkControllerGetStateAction;
|
|
93
|
+
/**
|
|
94
|
+
* The union of all external messenger event that must be allowed by the {@link AssetsContractControllerMessenger}.
|
|
95
|
+
*/
|
|
96
|
+
export type AllowedEvents = PreferencesControllerStateChangeEvent | NetworkControllerNetworkDidChangeEvent;
|
|
97
|
+
/**
|
|
98
|
+
* The messenger of the {@link AssetsContractController}.
|
|
99
|
+
*/
|
|
100
|
+
export type AssetsContractControllerMessenger = RestrictedControllerMessenger<typeof name, AssetsContractControllerActions | AllowedActions, AssetsContractControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
|
39
101
|
/**
|
|
40
102
|
* Controller that interacts with contracts on mainnet through web3
|
|
41
103
|
*/
|
|
42
|
-
export declare class AssetsContractController
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
* Name of this controller used during composition
|
|
46
|
-
*/
|
|
47
|
-
name: "AssetsContractController";
|
|
48
|
-
private readonly getNetworkClientById;
|
|
104
|
+
export declare class AssetsContractController {
|
|
105
|
+
#private;
|
|
106
|
+
protected messagingSystem: AssetsContractControllerMessenger;
|
|
49
107
|
/**
|
|
50
108
|
* Creates a AssetsContractController instance.
|
|
51
109
|
*
|
|
52
110
|
* @param options - The controller options.
|
|
111
|
+
* @param options.messenger - The controller messenger.
|
|
53
112
|
* @param options.chainId - The chain ID of the current network.
|
|
54
|
-
* @param options.onPreferencesStateChange - Allows subscribing to preference controller state changes.
|
|
55
|
-
* @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.
|
|
56
|
-
* @param options.getNetworkClientById - Gets the network client with the given id from the NetworkController.
|
|
57
|
-
* @param config - Initial options used to configure this controller.
|
|
58
|
-
* @param state - Initial state to set on this controller.
|
|
59
113
|
*/
|
|
60
|
-
constructor({ chainId: initialChainId,
|
|
114
|
+
constructor({ messenger, chainId: initialChainId, }: {
|
|
115
|
+
messenger: AssetsContractControllerMessenger;
|
|
61
116
|
chainId: Hex;
|
|
62
|
-
|
|
63
|
-
onNetworkDidChange: (listener: (networkState: NetworkState) => void) => void;
|
|
64
|
-
getNetworkClientById: NetworkController['getNetworkClientById'];
|
|
65
|
-
}, config?: Partial<AssetsContractConfig>, state?: Partial<BaseState>);
|
|
117
|
+
});
|
|
66
118
|
/**
|
|
67
119
|
* Sets a new provider.
|
|
68
120
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @property provider - Provider used to create a new underlying Web3 instance
|
|
72
|
-
*/
|
|
73
|
-
set provider(provider: Provider);
|
|
74
|
-
get provider(): Provider;
|
|
75
|
-
/**
|
|
76
|
-
* Get the relevant provider instance.
|
|
77
|
-
*
|
|
78
|
-
* @param networkClientId - Network Client ID.
|
|
79
|
-
* @returns Web3Provider instance.
|
|
80
|
-
*/
|
|
81
|
-
getProvider(networkClientId?: NetworkClientId): Web3Provider;
|
|
82
|
-
/**
|
|
83
|
-
* Get the relevant chain ID.
|
|
84
|
-
*
|
|
85
|
-
* @param networkClientId - Network Client ID used to get the provider.
|
|
86
|
-
* @returns Hex chain ID.
|
|
121
|
+
* @param provider - Provider used to create a new underlying Web3 instance
|
|
87
122
|
*/
|
|
88
|
-
|
|
123
|
+
setProvider(provider: Provider | undefined): void;
|
|
124
|
+
get ipfsGateway(): string;
|
|
125
|
+
get chainId(): `0x${string}`;
|
|
89
126
|
/**
|
|
90
127
|
* Get a ERC20Standard instance using the relevant provider instance.
|
|
91
128
|
*
|
|
@@ -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":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC3C,yDAAyD,EACzD,+CAA+C,EAC/C,+BAA+B,EAC/B,sCAAsC,EACtC,QAAQ,EACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,EAAyB,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,OAAO,CAAC;AAI5B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,uCAAuC;;;;;;;;;;;;;;;;;;;CAqCZ,CAAC;AAEzC,eAAO,MAAM,sBAAsB,0HACsF,CAAC;AAE1H;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,IAAI,6BAA6B,CAAC;AAExC;;;;GAIG;AAEH,KAAK,oBAAoB,CAAC,UAAU,IAAI;KACrC,WAAW,IAAI,MAAM,UAAU,IAAI,UAAU,CAAC,WAAW,CAAC,SAAS,gBAAgB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,eAAe,GAChC,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;OAMG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;;OAOG;IACG,gBAAgB,CACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;;OAOG;IACG,kBAAkB,CACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,CAAC;IAKlB;;;;;;;;OAQG;IACG,mBAAmB,CACvB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,EAAE,CAAC;IAKd;;;;;;;;;;OAUG;IACG,qBAAqB,CACzB,UAAU,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;CAgCpC;AAED,eAAe,wBAAwB,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { BaseController, type ControllerGetStateAction } from '@metamask/base-co
|
|
|
5
5
|
import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerNetworkDidChangeEvent } from '@metamask/network-controller';
|
|
6
6
|
import type { PreferencesControllerStateChangeEvent } from '@metamask/preferences-controller';
|
|
7
7
|
import type { Hex } from '@metamask/utils';
|
|
8
|
-
import type {
|
|
8
|
+
import type { AssetsContractControllerGetERC1155BalanceOfAction, AssetsContractControllerGetERC1155TokenURIAction, AssetsContractControllerGetERC721AssetNameAction, AssetsContractControllerGetERC721AssetSymbolAction, AssetsContractControllerGetERC721OwnerOfAction, AssetsContractControllerGetERC721TokenURIAction } from './AssetsContractController';
|
|
9
9
|
import { Source } from './constants';
|
|
10
10
|
import type { Collection, Attributes, LastSale, TopBid } from './NftDetectionController';
|
|
11
11
|
type NFTStandardType = 'ERC721' | 'ERC1155';
|
|
@@ -149,7 +149,7 @@ export type NftControllerActions = NftControllerGetStateAction;
|
|
|
149
149
|
/**
|
|
150
150
|
* The external actions available to the {@link NftController}.
|
|
151
151
|
*/
|
|
152
|
-
export type AllowedActions = AddApprovalRequest | AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction | NetworkControllerGetNetworkClientByIdAction;
|
|
152
|
+
export type AllowedActions = AddApprovalRequest | AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction | NetworkControllerGetNetworkClientByIdAction | AssetsContractControllerGetERC721AssetNameAction | AssetsContractControllerGetERC721AssetSymbolAction | AssetsContractControllerGetERC721TokenURIAction | AssetsContractControllerGetERC721OwnerOfAction | AssetsContractControllerGetERC1155BalanceOfAction | AssetsContractControllerGetERC1155TokenURIAction;
|
|
153
153
|
export type AllowedEvents = PreferencesControllerStateChangeEvent | NetworkControllerNetworkDidChangeEvent | AccountsControllerSelectedEvmAccountChangeEvent;
|
|
154
154
|
export type NftControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NftControllerState>;
|
|
155
155
|
export type NftControllerEvents = NftControllerStateChangeEvent;
|
|
@@ -176,29 +176,17 @@ export declare class NftController extends BaseController<typeof controllerName,
|
|
|
176
176
|
* @param options.openSeaEnabled - Controls whether the OpenSea API is used.
|
|
177
177
|
* @param options.useIpfsSubdomains - Controls whether IPFS subdomains are used.
|
|
178
178
|
* @param options.isIpfsGatewayEnabled - Controls whether IPFS is enabled or not.
|
|
179
|
-
* @param options.getERC721AssetName - Gets the name of the asset at the given address.
|
|
180
|
-
* @param options.getERC721AssetSymbol - Gets the symbol of the asset at the given address.
|
|
181
|
-
* @param options.getERC721TokenURI - Gets the URI of the ERC721 token at the given address, with the given ID.
|
|
182
|
-
* @param options.getERC721OwnerOf - Get the owner of a ERC-721 NFT.
|
|
183
|
-
* @param options.getERC1155BalanceOf - Gets balance of a ERC-1155 NFT.
|
|
184
|
-
* @param options.getERC1155TokenURI - Gets the URI of the ERC1155 token at the given address, with the given ID.
|
|
185
179
|
* @param options.onNftAdded - Callback that is called when an NFT is added. Currently used pass data
|
|
186
180
|
* for tracking the NFT added event.
|
|
187
181
|
* @param options.messenger - The controller messenger.
|
|
188
182
|
* @param options.state - Initial state to set on this controller.
|
|
189
183
|
*/
|
|
190
|
-
constructor({ chainId: initialChainId, ipfsGateway, openSeaEnabled, useIpfsSubdomains, isIpfsGatewayEnabled,
|
|
184
|
+
constructor({ chainId: initialChainId, ipfsGateway, openSeaEnabled, useIpfsSubdomains, isIpfsGatewayEnabled, onNftAdded, messenger, state, }: {
|
|
191
185
|
chainId: Hex;
|
|
192
186
|
ipfsGateway?: string;
|
|
193
187
|
openSeaEnabled?: boolean;
|
|
194
188
|
useIpfsSubdomains?: boolean;
|
|
195
189
|
isIpfsGatewayEnabled?: boolean;
|
|
196
|
-
getERC721AssetName: AssetsContractController['getERC721AssetName'];
|
|
197
|
-
getERC721AssetSymbol: AssetsContractController['getERC721AssetSymbol'];
|
|
198
|
-
getERC721TokenURI: AssetsContractController['getERC721TokenURI'];
|
|
199
|
-
getERC721OwnerOf: AssetsContractController['getERC721OwnerOf'];
|
|
200
|
-
getERC1155BalanceOf: AssetsContractController['getERC1155BalanceOf'];
|
|
201
|
-
getERC1155TokenURI: AssetsContractController['getERC1155TokenURI'];
|
|
202
190
|
onNftAdded?: (data: {
|
|
203
191
|
address: string;
|
|
204
192
|
symbol: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NftController.d.ts","sourceRoot":"","sources":["../../src/NftController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,+CAA+C,EAC/C,kCAAkC,EAClC,0CAA0C,EAC3C,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EACV,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,EACd,KAAK,wBAAwB,EAC9B,MAAM,2BAA2B,CAAC;AAenC,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC3C,sCAAsC,EAEvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,qCAAqC,EAEtC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"NftController.d.ts","sourceRoot":"","sources":["../../src/NftController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,+CAA+C,EAC/C,kCAAkC,EAClC,0CAA0C,EAC3C,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EACV,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,cAAc,EACd,KAAK,wBAAwB,EAC9B,MAAM,2BAA2B,CAAC;AAenC,OAAO,KAAK,EACV,eAAe,EACf,2CAA2C,EAC3C,sCAAsC,EAEvC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,qCAAqC,EAEtC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,OAAO,KAAK,EACV,iDAAiD,EACjD,gDAAgD,EAChD,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EA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C;QAClC,WAAW,CAAC,EAAE,MAAM,CAAC;KACjB;IAsBN;;;;;;;;;OASG;IACH,uBAAuB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,EACjB,EACE,eAAe,EACf,WAAW,GACZ,GAAE;QACD,eAAe,CAAC,EAAE,eAAe,CAAC;QAClC,WAAW,CAAC,EAAE,MAAM,CAAC;KACjB;IA4BR;;;;;;;;OAQG;IACH,0BAA0B,CACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAgBrC;;;;;;;OAOG;IACH,SAAS,CACP,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG;IA+Bd;;;;;;;OAOG;IACH,wCAAwC,CACtC,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,GAAG,GACX,OAAO;IA6BJ,gBAAgB,CAAC,gBAAgB,EAAE,gBAAgB;CAqD1D;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
|
|
2
|
+
import type { RestrictedControllerMessenger, ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
3
|
+
import { BaseController } from '@metamask/base-controller';
|
|
4
|
+
import type { AssetsContractControllerGetERC20BalanceOfAction } from './AssetsContractController';
|
|
4
5
|
import type { Token } from './TokenRatesController';
|
|
5
6
|
import type { TokensControllerStateChangeEvent } from './TokensController';
|
|
6
7
|
declare const controllerName = "TokenBalancesController";
|
|
@@ -9,13 +10,11 @@ declare const controllerName = "TokenBalancesController";
|
|
|
9
10
|
* @property interval - Polling interval used to fetch new token balances.
|
|
10
11
|
* @property tokens - List of tokens to track balances for.
|
|
11
12
|
* @property disabled - If set to true, all tracked tokens contract balances updates are blocked.
|
|
12
|
-
* @property getERC20BalanceOf - Gets the balance of the given account at the given contract address.
|
|
13
13
|
*/
|
|
14
14
|
type TokenBalancesControllerOptions = {
|
|
15
15
|
interval?: number;
|
|
16
16
|
tokens?: Token[];
|
|
17
17
|
disabled?: boolean;
|
|
18
|
-
getERC20BalanceOf: AssetsContractController['getERC20BalanceOf'];
|
|
19
18
|
messenger: TokenBalancesControllerMessenger;
|
|
20
19
|
state?: Partial<TokenBalancesControllerState>;
|
|
21
20
|
};
|
|
@@ -32,7 +31,7 @@ export type TokenBalancesControllerState = {
|
|
|
32
31
|
};
|
|
33
32
|
export type TokenBalancesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, TokenBalancesControllerState>;
|
|
34
33
|
export type TokenBalancesControllerActions = TokenBalancesControllerGetStateAction;
|
|
35
|
-
export type AllowedActions = AccountsControllerGetSelectedAccountAction;
|
|
34
|
+
export type AllowedActions = AccountsControllerGetSelectedAccountAction | AssetsContractControllerGetERC20BalanceOfAction;
|
|
36
35
|
export type TokenBalancesControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, TokenBalancesControllerState>;
|
|
37
36
|
export type TokenBalancesControllerEvents = TokenBalancesControllerStateChangeEvent;
|
|
38
37
|
export type AllowedEvents = TokensControllerStateChangeEvent;
|
|
@@ -56,11 +55,10 @@ export declare class TokenBalancesController extends BaseController<typeof contr
|
|
|
56
55
|
* @param options.interval - Polling interval used to fetch new token balances.
|
|
57
56
|
* @param options.tokens - List of tokens to track balances for.
|
|
58
57
|
* @param options.disabled - If set to true, all tracked tokens contract balances updates are blocked.
|
|
59
|
-
* @param options.getERC20BalanceOf - Gets the balance of the given account at the given contract address.
|
|
60
58
|
* @param options.state - Initial state to set on this controller.
|
|
61
59
|
* @param options.messenger - The controller restricted messenger.
|
|
62
60
|
*/
|
|
63
|
-
constructor({ interval, tokens, disabled,
|
|
61
|
+
constructor({ interval, tokens, disabled, messenger, state, }: TokenBalancesControllerOptions);
|
|
64
62
|
/**
|
|
65
63
|
* Allows controller to update tracked tokens contract balances.
|
|
66
64
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenBalancesController.d.ts","sourceRoot":"","sources":["../../src/TokenBalancesController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"TokenBalancesController.d.ts","sourceRoot":"","sources":["../../src/TokenBalancesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,KAAK,EACV,6BAA6B,EAC7B,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,KAAK,EAAE,+CAA+C,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAI3E,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAMjD;;;;;GAKG;AACH,KAAK,8BAA8B,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,gCAAgC,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,qCAAqC,GAAG,wBAAwB,CAC1E,OAAO,cAAc,EACrB,4BAA4B,CAC7B,CAAC;AAEF,MAAM,MAAM,8BAA8B,GACxC,qCAAqC,CAAC;AAExC,MAAM,MAAM,cAAc,GACtB,0CAA0C,GAC1C,+CAA+C,CAAC;AAEpD,MAAM,MAAM,uCAAuC,GACjD,0BAA0B,CACxB,OAAO,cAAc,EACrB,4BAA4B,CAC7B,CAAC;AAEJ,MAAM,MAAM,6BAA6B,GACvC,uCAAuC,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAE7D,MAAM,MAAM,gCAAgC,GAAG,6BAA6B,CAC1E,OAAO,cAAc,EACrB,8BAA8B,GAAG,cAAc,EAC/C,6BAA6B,GAAG,aAAa,EAC7C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,4BAA4B,CAI3E;AAED;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,cAAc,CACzD,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IASC;;;;;;;;;OASG;gBACS,EACV,QAA2B,EAC3B,MAAW,EACX,QAAgB,EAChB,SAAS,EACT,KAAU,GACX,EAAE,8BAA8B;IA8BjC;;OAEG;IACH,MAAM;IAIN;;OAEG;IACH,OAAO;IAIP;;;;OAIG;IACG,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB5C;;OAEG;IACG,cAAc;CA6BrB;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -98,10 +98,10 @@ export declare function removeIpfsProtocolPrefix(ipfsUrl: string): string;
|
|
|
98
98
|
* @returns IFPS content identifier (cid) and sub path as string.
|
|
99
99
|
* @throws Will throw if the url passed is not ipfs.
|
|
100
100
|
*/
|
|
101
|
-
export declare function getIpfsCIDv1AndPath(ipfsUrl: string): {
|
|
101
|
+
export declare function getIpfsCIDv1AndPath(ipfsUrl: string): Promise<{
|
|
102
102
|
cid: string;
|
|
103
103
|
path?: string;
|
|
104
|
-
}
|
|
104
|
+
}>;
|
|
105
105
|
/**
|
|
106
106
|
* Formats URL correctly for use retrieving assets hosted on IPFS.
|
|
107
107
|
*
|
|
@@ -110,7 +110,7 @@ export declare function getIpfsCIDv1AndPath(ipfsUrl: string): {
|
|
|
110
110
|
* @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.
|
|
111
111
|
* @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.
|
|
112
112
|
*/
|
|
113
|
-
export declare function getFormattedIpfsUrl(ipfsGateway: string, ipfsUrl: string, subdomainSupported: boolean): string
|
|
113
|
+
export declare function getFormattedIpfsUrl(ipfsGateway: string, ipfsUrl: string, subdomainSupported: boolean): Promise<string>;
|
|
114
114
|
/**
|
|
115
115
|
* Adds URL protocol prefix to input URL string if missing.
|
|
116
116
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetsUtil.d.ts","sourceRoot":"","sources":["../../src/assetsUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"assetsUtil.d.ts","sourceRoot":"","sources":["../../src/assetsUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAK1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,KAAK,EAAE,GAAG,EAAE,WAA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AAE;IACD,kBAAkB,EAAE,0BAA0B,CAAC;IAC/C,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,GAAG,EAAE,CAAC;IACtB,OAAO,EAAE,GAAG,CAAC;CACd,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAyCjC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { AccountInformation, AccountTrackerControllerMessenger, AccountTrackerControllerState, AccountTrackerControllerActions, AccountTrackerControllerGetStateAction, AccountTrackerControllerStateChangeEvent, AccountTrackerControllerEvents, } from './AccountTrackerController';
|
|
2
2
|
export { AccountTrackerController } from './AccountTrackerController';
|
|
3
|
-
export
|
|
3
|
+
export type { AssetsContractControllerActions, AssetsContractControllerEvents, AssetsContractControllerGetERC20StandardAction, AssetsContractControllerGetERC721StandardAction, AssetsContractControllerGetERC1155StandardAction, AssetsContractControllerGetERC20BalanceOfAction, AssetsContractControllerGetERC20TokenDecimalsAction, AssetsContractControllerGetERC20TokenNameAction, AssetsContractControllerGetERC721NftTokenIdAction, AssetsContractControllerGetERC721TokenURIAction, AssetsContractControllerGetERC721AssetNameAction, AssetsContractControllerGetERC721AssetSymbolAction, AssetsContractControllerGetERC721OwnerOfAction, AssetsContractControllerGetERC1155TokenURIAction, AssetsContractControllerGetERC1155BalanceOfAction, AssetsContractControllerTransferSingleERC1155Action, AssetsContractControllerGetTokenStandardAndDetailsAction, AssetsContractControllerGetBalancesInSingleCallAction, AssetsContractControllerMessenger, BalanceMap, } from './AssetsContractController';
|
|
4
|
+
export { SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID, AssetsContractController, } from './AssetsContractController';
|
|
4
5
|
export * from './CurrencyRateController';
|
|
5
6
|
export type { NftControllerState, NftControllerMessenger, NftControllerActions, NftControllerGetStateAction, NftControllerEvents, NftControllerStateChangeEvent, Nft, NftContract, NftMetadata, } from './NftController';
|
|
6
7
|
export { getDefaultNftControllerState, NftController } from './NftController';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iCAAiC,EACjC,6BAA6B,EAC7B,+BAA+B,EAC/B,sCAAsC,EACtC,wCAAwC,EACxC,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iCAAiC,EACjC,6BAA6B,EAC7B,+BAA+B,EAC/B,sCAAsC,EACtC,wCAAwC,EACxC,8BAA8B,GAC/B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,8CAA8C,EAC9C,+CAA+C,EAC/C,gDAAgD,EAChD,+CAA+C,EAC/C,mDAAmD,EACnD,+CAA+C,EAC/C,iDAAiD,EACjD,+CAA+C,EAC/C,gDAAgD,EAChD,kDAAkD,EAClD,8CAA8C,EAC9C,gDAAgD,EAChD,iDAAiD,EACjD,mDAAmD,EACnD,wDAAwD,EACxD,qDAAqD,EACrD,iCAAiC,EACjC,UAAU,GACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uCAAuC,EACvC,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,6BAA6B,EAC7B,GAAG,EACH,WAAW,EACX,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9E,YAAY,EACV,+BAA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C;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,mCAAmC,EACnC,sBAAsB,EACtB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,kCAAkC,EAClC,kCAAkC,GACnC,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/assets-controllers",
|
|
3
|
-
"version": "36.0.0-preview-
|
|
3
|
+
"version": "36.0.0-preview-276db038",
|
|
4
4
|
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controllers",
|
|
36
36
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controllers",
|
|
37
37
|
"publish:preview": "yarn npm publish --tag preview",
|
|
38
|
-
"test": "jest --reporters=jest-silent-reporter",
|
|
39
|
-
"test:clean": "jest --clearCache",
|
|
40
|
-
"test:verbose": "jest --verbose",
|
|
41
|
-
"test:watch": "jest --watch"
|
|
38
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
39
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
40
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
41
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@ethereumjs/util": "^8.1.0",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"@ethersproject/bignumber": "^5.7.0",
|
|
47
47
|
"@ethersproject/contracts": "^5.7.0",
|
|
48
48
|
"@ethersproject/providers": "^5.7.0",
|
|
49
|
-
"@metamask/abi-utils": "^2.0.
|
|
49
|
+
"@metamask/abi-utils": "^2.0.3",
|
|
50
50
|
"@metamask/accounts-controller": "^17.2.0",
|
|
51
|
-
"@metamask/approval-controller": "^7.0.
|
|
52
|
-
"@metamask/base-controller": "^6.0.
|
|
51
|
+
"@metamask/approval-controller": "^7.0.2",
|
|
52
|
+
"@metamask/base-controller": "^6.0.2",
|
|
53
53
|
"@metamask/contract-metadata": "^2.4.0",
|
|
54
|
-
"@metamask/controller-utils": "^11.0.
|
|
54
|
+
"@metamask/controller-utils": "^11.0.2",
|
|
55
55
|
"@metamask/eth-query": "^4.0.0",
|
|
56
56
|
"@metamask/keyring-controller": "^17.1.1",
|
|
57
57
|
"@metamask/metamask-eth-abis": "^3.1.1",
|
|
@@ -65,15 +65,16 @@
|
|
|
65
65
|
"async-mutex": "^0.5.0",
|
|
66
66
|
"bn.js": "^5.2.1",
|
|
67
67
|
"cockatiel": "^3.1.2",
|
|
68
|
+
"immer": "^9.0.6",
|
|
68
69
|
"lodash": "^4.17.21",
|
|
69
|
-
"multiformats": "^
|
|
70
|
+
"multiformats": "^13.1.0",
|
|
70
71
|
"single-call-balance-checker-abi": "^1.0.0",
|
|
71
72
|
"uuid": "^8.3.2"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
75
|
"@metamask/auto-changelog": "^3.4.4",
|
|
75
76
|
"@metamask/ethjs-provider-http": "^0.3.0",
|
|
76
|
-
"@metamask/keyring-api": "^8.0.
|
|
77
|
+
"@metamask/keyring-api": "^8.0.1",
|
|
77
78
|
"@types/jest": "^27.4.1",
|
|
78
79
|
"@types/lodash": "^4.14.191",
|
|
79
80
|
"@types/node": "^16.18.54",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"ts-jest": "^27.1.4",
|
|
86
87
|
"typedoc": "^0.24.8",
|
|
87
88
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
88
|
-
"typescript": "~
|
|
89
|
+
"typescript": "~5.0.4"
|
|
89
90
|
},
|
|
90
91
|
"peerDependencies": {
|
|
91
92
|
"@metamask/accounts-controller": "^17.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assetsUtil.ts"],"sourcesContent":["import type { BigNumber } from '@ethersproject/bignumber';\nimport {\n convertHexToDecimal,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { CID } from 'multiformats/cid';\n\nimport type { Nft, NftMetadata } from './NftController';\nimport type { AbstractTokenPricesService } from './token-prices-service';\nimport { type ContractExchangeRates } from './TokenRatesController';\n\n/**\n * The maximum number of token addresses that should be sent to the Price API in\n * a single request.\n */\nexport const TOKEN_PRICES_BATCH_SIZE = 30;\n\n/**\n * Compares nft metadata entries to any nft entry.\n * We need this method when comparing a new fetched nft metadata, in case a entry changed to a defined value,\n * there's a need to update the nft in state.\n *\n * @param newNftMetadata - Nft metadata object.\n * @param nft - Nft object to compare with.\n * @returns Whether there are differences.\n */\nexport function compareNftMetadata(newNftMetadata: NftMetadata, nft: Nft) {\n const keys: (keyof NftMetadata)[] = [\n 'image',\n 'backgroundColor',\n 'imagePreview',\n 'imageThumbnail',\n 'imageOriginal',\n 'animation',\n 'animationOriginal',\n 'externalLink',\n 'tokenURI',\n ];\n const differentValues = keys.reduce((value, key) => {\n if (newNftMetadata[key] && newNftMetadata[key] !== nft[key]) {\n return value + 1;\n }\n return value;\n }, 0);\n return differentValues > 0;\n}\n\n/**\n * Checks whether the existing nft object has all the keys of the new incoming nft metadata object\n * @param newNftMetadata - New nft metadata object\n * @param nft - Existing nft object to compare with\n * @returns Whether the existing nft object has all the new keys from the new Nft metadata object\n */\nexport function hasNewCollectionFields(\n newNftMetadata: NftMetadata,\n nft: Nft,\n): boolean {\n const keysNewNftMetadata = Object.keys(newNftMetadata.collection ?? {});\n const keysExistingNft = new Set(Object.keys(nft.collection ?? {}));\n\n return keysNewNftMetadata.some((key) => !keysExistingNft.has(key));\n}\n\nconst aggregatorNameByKey: Record<string, string> = {\n aave: 'Aave',\n bancor: 'Bancor',\n cmc: 'CMC',\n cryptocom: 'Crypto.com',\n coinGecko: 'CoinGecko',\n oneInch: '1inch',\n paraswap: 'Paraswap',\n pmm: 'PMM',\n zapper: 'Zapper',\n zerion: 'Zerion',\n zeroEx: '0x',\n synthetix: 'Synthetix',\n yearn: 'Yearn',\n apeswap: 'ApeSwap',\n binanceDex: 'BinanceDex',\n pancakeTop100: 'PancakeTop100',\n pancakeExtended: 'PancakeExtended',\n balancer: 'Balancer',\n quickswap: 'QuickSwap',\n matcha: 'Matcha',\n pangolinDex: 'PangolinDex',\n pangolinDexStableCoin: 'PangolinDexStableCoin',\n pangolinDexAvaxBridge: 'PangolinDexAvaxBridge',\n traderJoe: 'TraderJoe',\n airswapLight: 'AirswapLight',\n kleros: 'Kleros',\n};\n\n/**\n * Formats aggregator names to presentable format.\n *\n * @param aggregators - List of token list names in camelcase.\n * @returns Formatted aggregator names.\n */\nexport const formatAggregatorNames = (aggregators: string[]) => {\n return aggregators.map(\n (key) =>\n aggregatorNameByKey[key] ||\n `${key[0].toUpperCase()}${key.substring(1, key.length)}`,\n );\n};\n\n/**\n * Format token list assets to use image proxy from Codefi.\n *\n * @param params - Object that contains chainID and tokenAddress.\n * @param params.chainId - ChainID of network in 0x-prefixed hexadecimal format.\n * @param params.tokenAddress - Address of token in mixed or lowercase.\n * @returns Formatted image url\n */\nexport const formatIconUrlWithProxy = ({\n chainId,\n tokenAddress,\n}: {\n chainId: Hex;\n tokenAddress: string;\n}) => {\n const chainIdDecimal = convertHexToDecimal(chainId).toString();\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `https://static.cx.metamask.io/api/v1/tokenIcons/${chainIdDecimal}/${tokenAddress.toLowerCase()}.png`;\n};\n\n/**\n * Networks where token detection is supported - Values are in hex format\n */\nexport enum SupportedTokenDetectionNetworks {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n mainnet = '0x1', // decimal: 1\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n bsc = '0x38', // decimal: 56\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon = '0x89', // decimal: 137\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n avax = '0xa86a', // decimal: 43114\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n aurora = '0x4e454152', // decimal: 1313161554\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_goerli = '0xe704', // decimal: 59140\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n linea_mainnet = '0xe708', // decimal: 59144\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n arbitrum = '0xa4b1', // decimal: 42161\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n optimism = '0xa', // decimal: 10\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n base = '0x2105', // decimal: 8453\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n zksync = '0x144', // decimal: 324\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n cronos = '0x19', // decimal: 25\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n celo = '0xa4ec', // decimal: 42220\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n gnosis = '0x64', // decimal: 100\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n fantom = '0xfa', // decimal: 250\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n polygon_zkevm = '0x44d', // decimal: 1101\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonbeam = '0x504', // decimal: 1284\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n moonriver = '0x505', // decimal: 1285\n}\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 function isTokenDetectionSupportedForNetwork(chainId: Hex): boolean {\n return Object.values<Hex>(SupportedTokenDetectionNetworks).includes(chainId);\n}\n\n/**\n * Check if token list polling is enabled for a given network.\n * Currently this method is used to support e2e testing for consumers of this package.\n *\n * @param chainId - ChainID of network\n * @returns Whether the current network supports tokenlists\n */\nexport function isTokenListSupportedForNetwork(chainId: Hex): boolean {\n return isTokenDetectionSupportedForNetwork(chainId);\n}\n\n/**\n * Removes IPFS protocol prefix from input string.\n *\n * @param ipfsUrl - An IPFS url (e.g. ipfs://{content id})\n * @returns IPFS content identifier and (possibly) path in a string\n * @throws Will throw if the url passed is not IPFS.\n */\nexport function removeIpfsProtocolPrefix(ipfsUrl: string) {\n if (ipfsUrl.startsWith('ipfs://ipfs/')) {\n return ipfsUrl.replace('ipfs://ipfs/', '');\n } else if (ipfsUrl.startsWith('ipfs://')) {\n return ipfsUrl.replace('ipfs://', '');\n }\n // this method should not be used with non-ipfs urls (i.e. startsWith('ipfs://') === true)\n throw new Error('this method should not be used with non ipfs urls');\n}\n\n/**\n * Extracts content identifier and path from an input string.\n *\n * @param ipfsUrl - An IPFS URL minus the IPFS protocol prefix\n * @returns IFPS content identifier (cid) and sub path as string.\n * @throws Will throw if the url passed is not ipfs.\n */\nexport function getIpfsCIDv1AndPath(ipfsUrl: string): {\n cid: string;\n path?: string;\n} {\n const url = removeIpfsProtocolPrefix(ipfsUrl);\n\n // check if there is a path\n // (CID is everything preceding first forward slash, path is everything after)\n const index = url.indexOf('/');\n const cid = index !== -1 ? url.substring(0, index) : url;\n const path = index !== -1 ? url.substring(index) : undefined;\n\n // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)\n // because most cid v0s appear to be incompatible with IPFS subdomains\n return {\n cid: CID.parse(cid).toV1().toString(),\n path,\n };\n}\n\n/**\n * Formats URL correctly for use retrieving assets hosted on IPFS.\n *\n * @param ipfsGateway - The users preferred IPFS gateway (full URL or just host).\n * @param ipfsUrl - The IFPS URL pointed at the asset.\n * @param subdomainSupported - Boolean indicating whether the URL should be formatted with subdomains or not.\n * @returns A formatted URL, with the user's preferred IPFS gateway and format (subdomain or not), pointing to an asset hosted on IPFS.\n */\nexport function getFormattedIpfsUrl(\n ipfsGateway: string,\n ipfsUrl: string,\n subdomainSupported: boolean,\n): string {\n const { host, protocol, origin } = new URL(addUrlProtocolPrefix(ipfsGateway));\n if (subdomainSupported) {\n const { cid, path } = getIpfsCIDv1AndPath(ipfsUrl);\n return `${protocol}//${cid}.ipfs.${host}${path ?? ''}`;\n }\n const cidAndPath = removeIpfsProtocolPrefix(ipfsUrl);\n return `${origin}/ipfs/${cidAndPath}`;\n}\n\n/**\n * Adds URL protocol prefix to input URL string if missing.\n *\n * @param urlString - An IPFS URL.\n * @returns A URL with a https:// prepended.\n */\nexport function addUrlProtocolPrefix(urlString: string): string {\n if (!urlString.match(/(^http:\\/\\/)|(^https:\\/\\/)/u)) {\n return `https://${urlString}`;\n }\n return urlString;\n}\n\n/**\n * Converts an Ethers BigNumber to a BN.\n *\n * @param bigNumber - An Ethers BigNumber instance.\n * @returns A BN object.\n */\nexport function ethersBigNumberToBN(bigNumber: BigNumber): BN {\n return new BN(remove0x(bigNumber.toHexString()), 'hex');\n}\n\n/**\n * Partitions a list of values into groups that are at most `batchSize` in\n * length.\n *\n * @param values - The list of values.\n * @param args - The remaining arguments.\n * @param args.batchSize - The desired maximum number of values per batch.\n * @returns The list of batches.\n */\nexport function divideIntoBatches<Value>(\n values: Value[],\n { batchSize }: { batchSize: number },\n): Value[][] {\n const batches = [];\n for (let i = 0; i < values.length; i += batchSize) {\n batches.push(values.slice(i, i + batchSize));\n }\n return batches;\n}\n\n/**\n * Constructs an object from processing batches of the given values\n * sequentially.\n *\n * @param args - The arguments to this function.\n * @param args.values - A list of values to iterate over.\n * @param args.batchSize - The maximum number of values in each batch.\n * @param args.eachBatch - A function to call for each batch. This function is\n * similar to the function that `Array.prototype.reduce` takes, in that it\n * receives the object that is being built, each batch in the list of batches\n * and the index, and should return an updated version of the object.\n * @param args.initialResult - The initial value of the final data structure,\n * i.e., the value that will be fed into the first call of `eachBatch`.\n * @returns The built object.\n */\nexport async function reduceInBatchesSerially<\n Value,\n Result extends Record<PropertyKey, unknown>,\n>({\n values,\n batchSize,\n eachBatch,\n initialResult,\n}: {\n values: Value[];\n batchSize: number;\n eachBatch: (\n workingResult: Partial<Result>,\n batch: Value[],\n index: number,\n ) => Partial<Result> | Promise<Partial<Result>>;\n initialResult: Partial<Result>;\n}): Promise<Result> {\n const batches = divideIntoBatches(values, { batchSize });\n let workingResult = initialResult;\n for (const [index, batch] of batches.entries()) {\n workingResult = await eachBatch(workingResult, batch, index);\n }\n // There's no way around this — we have to assume that in the end, the result\n // matches the intended type.\n const finalResult = workingResult as Result;\n return finalResult;\n}\n\n/**\n * Retrieves token prices for a set of contract addresses in a specific currency and chainId.\n *\n * @param args - The arguments to function.\n * @param args.tokenPricesService - An object in charge of retrieving token prices.\n * @param args.nativeCurrency - The native currency to request price in.\n * @param args.tokenAddresses - The list of contract addresses.\n * @param args.chainId - The chainId of the tokens.\n * @returns The prices for the requested tokens.\n */\nexport async function fetchTokenContractExchangeRates({\n tokenPricesService,\n nativeCurrency,\n tokenAddresses,\n chainId,\n}: {\n tokenPricesService: AbstractTokenPricesService;\n nativeCurrency: string;\n tokenAddresses: Hex[];\n chainId: Hex;\n}): Promise<ContractExchangeRates> {\n const isChainIdSupported =\n tokenPricesService.validateChainIdSupported(chainId);\n const isCurrencySupported =\n tokenPricesService.validateCurrencySupported(nativeCurrency);\n\n if (!isChainIdSupported || !isCurrencySupported) {\n return {};\n }\n\n const tokenPricesByTokenAddress = await reduceInBatchesSerially<\n Hex,\n Awaited<ReturnType<AbstractTokenPricesService['fetchTokenPrices']>>\n >({\n values: [...tokenAddresses].sort(),\n batchSize: TOKEN_PRICES_BATCH_SIZE,\n eachBatch: async (allTokenPricesByTokenAddress, batch) => {\n const tokenPricesByTokenAddressForBatch =\n await tokenPricesService.fetchTokenPrices({\n tokenAddresses: batch,\n chainId,\n currency: nativeCurrency,\n });\n\n return {\n ...allTokenPricesByTokenAddress,\n ...tokenPricesByTokenAddressForBatch,\n };\n },\n initialResult: {},\n });\n\n return Object.entries(tokenPricesByTokenAddress).reduce(\n (obj, [tokenAddress, tokenPrice]) => {\n return {\n ...obj,\n [toChecksumHexAddress(tokenAddress)]: tokenPrice?.price,\n };\n },\n {},\n );\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AACf,SAAS,WAAW;AAUb,IAAM,0BAA0B;AAWhC,SAAS,mBAAmB,gBAA6B,KAAU;AACxE,QAAM,OAA8B;AAAA,I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A,eAAsB,gCAAgC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKmC;AACjC,QAAM,qBACJ,mBAAmB,yBAAyB,OAAO;AACrD,QAAM,sBACJ,mBAAmB,0BAA0B,cAAc;AAE7D,MAAI,CAAC,sBAAsB,CAAC,qBAAqB;AAC/C,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,4BAA4B,MAAM,wBAGtC;AAAA,IACA,QAAQ,CAAC,GAAG,cAAc,EAAE,KAAK;AAAA,IACjC,WAAW;AAAA,IACX,WAAW,OAAO,8BAA8B,UAAU;AACxD,YAAM,oCACJ,MAAM,mBAAmB,iBAAiB;AAAA,QACxC,gBAAgB;AAAA,QAChB;AAAA,QACA,UAAU;AAAA,MACZ,CAAC;AAEH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,IACF;AAAA,IACA,eAAe,CAAC;AAAA,EAClB,CAAC;AAED,SAAO,OAAO,QAAQ,yBAAyB,EAAE;AAAA,IAC/C,CAAC,KAAK,CAAC,cAAc,UAAU,MAAM;AACnC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,qBAAqB,YAAY,CAAC,GAAG,YAAY;AAAA,MACpD;AAAA,IACF;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":["SupportedTokenDetectionNetworks"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AssetsContractController.ts"],"sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { BaseConfig, BaseState } from '@metamask/base-controller';\nimport { BaseControllerV1 } from '@metamask/base-controller';\nimport { IPFS_DEFAULT_GATEWAY_URL } from '@metamask/controller-utils';\nimport type {\n NetworkClientId,\n NetworkState,\n NetworkController,\n Provider,\n} from '@metamask/network-controller';\nimport type { PreferencesState } from '@metamask/preferences-controller';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\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 [SupportedTokenDetectionNetworks.linea_goerli]:\n '0x10dAd7Ca3921471f616db788D9300DC97Db01783',\n [SupportedTokenDetectionNetworks.linea_mainnet]:\n '0xF62e6a41561b3650a69Bb03199C735e3E3328c0D',\n [SupportedTokenDetectionNetworks.arbitrum]:\n '0x151E24A486D7258dd7C33Fb67E4bB01919B7B32c',\n [SupportedTokenDetectionNetworks.optimism]:\n '0xB1c568e9C3E6bdaf755A60c7418C269eb11524FC',\n [SupportedTokenDetectionNetworks.base]:\n '0x6AA75276052D96696134252587894ef5FFA520af',\n [SupportedTokenDetectionNetworks.zksync]:\n '0x458fEd3144680a5b8bcfaa0F9594aa19B4Ea2D34',\n [SupportedTokenDetectionNetworks.cronos]:\n '0x768ca200f0fc702ac9ea502498c18f5eff176378',\n [SupportedTokenDetectionNetworks.celo]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\n [SupportedTokenDetectionNetworks.gnosis]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\n [SupportedTokenDetectionNetworks.fantom]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\n [SupportedTokenDetectionNetworks.polygon_zkevm]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\n [SupportedTokenDetectionNetworks.moonbeam]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\n [SupportedTokenDetectionNetworks.moonriver]:\n '0x6aa75276052d96696134252587894ef5ffa520af',\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 */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface AssetsContractConfig extends BaseConfig {\n provider: Provider | undefined;\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 */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\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 BaseControllerV1<\n AssetsContractConfig,\n BaseState\n> {\n private _provider?: Provider;\n\n /**\n * Name of this controller used during composition\n */\n override name = 'AssetsContractController' as const;\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.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.\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 onNetworkDidChange,\n getNetworkClientById,\n }: {\n chainId: Hex;\n onPreferencesStateChange: (\n listener: (preferencesState: PreferencesState) => void,\n ) => void;\n onNetworkDidChange: (\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 onNetworkDidChange(({ selectedNetworkClientId }) => {\n const selectedNetworkClient = getNetworkClientById(\n selectedNetworkClientId,\n );\n const { chainId } = selectedNetworkClient.configuration;\n\n if (this.config.chainId !== chainId) {\n this.configure({\n chainId: selectedNetworkClient.configuration.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: Provider) {\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"],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAE7B,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AAUzC,OAAO,mCAAmC;AAanC,IAAM,0CAA+D;AAAA,EAC1E,oBAAwC,GACtC;AAAA,EACF,iBAAoC,GAClC;AAAA,EACF,qBAAwC,GACtC;AAAA,EACF,oBAAqC,GACnC;AAAA,EACF,0BAAuC,GACrC;AAAA,EACF,4BAA6C,GAC3C;AAAA,EACF,6BAA8C,GAC5C;AAAA,EACF,wBAAyC,GACvC;AAAA,EACF,qBAAyC,GACvC;AAAA,EACF,oBAAqC,GACnC;AAAA,EACF,qBAAuC,GACrC;AAAA,EACF,oBAAuC,GACrC;AAAA,EACF,oBAAqC,GACnC;AAAA,EACF,oBAAuC,GACrC;AAAA,EACF,oBAAuC,GACrC;AAAA,EACF,4BAA8C,GAC5C;AAAA,EACF,uBAAyC,GACvC;AAAA,EACF,wBAA0C,GACxC;AACJ;AAEO,IAAM,yBACX;AAiCK,IAAM,2BAAN,cAAuC,iBAG5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBA,YACE;AAAA,IACE,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAUA,QACA,OACA;AACA,UAAM,QAAQ,KAAK;AAlCrB;AAAA;AAAA;AAAA,SAAS,OAAO;AAmCd,SAAK,gBAAgB;AAAA,MACnB,UAAU;AAAA,MACV,aAAa;AAAA,MACb,SAAS;AAAA,IACX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