@@ -2,69 +2,21 @@ import {
22 createIndicator ,
33 createNextIndicator ,
44 createPageable ,
5- EMPTY_LIST ,
65 type Pageable ,
76 type PageIndicator ,
87} from '@masknet/shared-base'
98import { fetchJSON } from '@masknet/web3-providers/helpers'
10- import {
11- GasOptionType ,
12- isSameAddress ,
13- SourceType ,
14- toFixed ,
15- TokenType ,
16- type Transaction ,
17- } from '@masknet/web3-shared-base'
18- import { ChainId , type GasOption , isValidChainId , resolveImageURL , SchemaType } from '@masknet/web3-shared-evm'
19- import { compact , first , unionWith } from 'lodash-es'
9+ import { type Transaction } from '@masknet/web3-shared-base'
10+ import { type ChainId , type SchemaType } from '@masknet/web3-shared-evm'
11+ import { compact } from 'lodash-es'
2012import urlcat from 'urlcat'
21- import type {
22- BaseGasOptions ,
23- BaseHubOptions ,
24- FungibleTokenAPI ,
25- HistoryAPI ,
26- NonFungibleTokenAPI ,
27- } from '../entry-types.js'
28- import { getAssetFullName } from '../helpers/getAssetFullName.js'
29- import { getNativeAssets } from '../helpers/getNativeAssets.js'
30- import { getAssetsList , getGasOptions , getNonFungibleAsset , getNonFungibleAssets } from './base-api.js'
31- import { formatAsset , formatRestTransaction , isValidAsset , zerionChainIdResolver } from './helpers.js'
13+ import type { BaseHubOptions } from '../entry-types.js'
14+ import { formatRestTransaction } from './helpers.js'
3215import type { TransactionsResponse } from './reset-types.js'
33- import type { ZerionNonFungibleCollection , ZerionNonFungibleTokenItem } from './types.js'
3416
35- const ZERION_NFT_DETAIL_URL = 'https://app.zerion.io/nfts/'
36- const filterAssetType = [ 'compound' , 'trash' , 'uniswap' , 'uniswap-v2' , 'nft' ]
3717const ZERION_REST_API = 'https://zerion-proxy.r2d2.to/'
3818
39- class ZerionAPI implements FungibleTokenAPI . Provider < ChainId , SchemaType > , HistoryAPI . Provider < ChainId , SchemaType > {
40- async getAssets ( address : string , options ?: BaseHubOptions < ChainId > ) {
41- const { meta, payload } = await getAssetsList ( address , 'positions' )
42- if ( meta . status !== 'ok' ) return createPageable ( EMPTY_LIST , createIndicator ( options ?. indicator ) )
43-
44- const assets = payload . positions ?. positions
45- . filter (
46- ( x ) =>
47- x . type === 'asset' &&
48- x . asset . icon_url &&
49- x . asset . is_displayable &&
50- ! filterAssetType . includes ( x . asset . type ) &&
51- isValidAsset ( x ) &&
52- zerionChainIdResolver ( x . chain ) ,
53- )
54- . map ( ( x ) => {
55- return formatAsset ( zerionChainIdResolver ( x . chain ) ! , x )
56- } )
57-
58- return createPageable (
59- unionWith (
60- assets || [ ] ,
61- getNativeAssets ( ) ,
62- ( a , z ) => isSameAddress ( a . address , z . address ) && a . chainId === z . chainId ,
63- ) ,
64- createIndicator ( options ?. indicator ) ,
65- )
66- }
67-
19+ class ZerionAPI {
6820 async getTransactions (
6921 address : string ,
7022 { indicator, size = 20 } : BaseHubOptions < ChainId > = { } ,
@@ -88,138 +40,4 @@ class ZerionAPI implements FungibleTokenAPI.Provider<ChainId, SchemaType>, Histo
8840 }
8941}
9042
91- class ZerionNonFungibleTokenAPI implements NonFungibleTokenAPI . Provider < ChainId , SchemaType > {
92- createNonFungibleCollectionFromCollectionData ( chainId : ChainId , collection : ZerionNonFungibleCollection ) {
93- return {
94- chainId,
95- scheme : SchemaType . ERC721 ,
96- name : collection . name ,
97- slug : collection . collection_id ,
98- description : collection . description ,
99- iconURL : collection . icon_url ,
100- source : SourceType . Zerion ,
101- }
102- }
103- createNonFungibleTokenPermalink ( address ?: string , tokenId ?: string ) {
104- if ( ! address || ! tokenId ) return
105- return ZERION_NFT_DETAIL_URL + `${ address } :${ tokenId } `
106- }
107-
108- createNonFungibleTokenAssetFromNFT ( chainId : ChainId , nft : ZerionNonFungibleTokenItem ) {
109- const name = getAssetFullName (
110- nft . asset . contract_address ,
111- nft . asset . collection . name ,
112- nft . asset . name ,
113- nft . asset . token_id ,
114- )
115- return {
116- chainId,
117- id : `${ chainId } _${ nft . asset . contract_address } _${ nft . asset . token_id } ` ,
118- type : TokenType . NonFungible ,
119- schema : nft . standard === 'ERC1155' ? SchemaType . ERC1155 : SchemaType . ERC721 ,
120- address : nft . asset . contract_address ,
121- tokenId : nft . asset . token_id ,
122- contract : {
123- chainId,
124- schema : nft . standard === 'ERC1155' ? SchemaType . ERC1155 : SchemaType . ERC721 ,
125- address : nft . asset . contract_address ,
126- name : nft . asset . collection . name ,
127- symbol : nft . asset . symbol ,
128- } ,
129- metadata : {
130- chainId,
131- name,
132- symbol : nft . asset . symbol ,
133- imageURL : resolveImageURL ( nft . asset . preview . url , name , nft . asset . contract_address ) ,
134- mediaURL : nft . asset . detail . url ,
135- mediaType : nft . asset . detail . meta . type ,
136- source : SourceType . Zerion ,
137- } ,
138- collection : {
139- chainId,
140- name : nft . asset . collection_info . name ,
141- slug : nft . asset . collection_info . slug ,
142- description : nft . asset . collection_info . description ,
143- address : nft . asset . contract_address ,
144- iconURL : nft . asset . collection_info . icon_url ?? nft . asset . collection . icon_url ,
145- verified : nft . asset . is_verified ,
146- isSpam : undefined ,
147- } ,
148- source : SourceType . Zerion ,
149- link : this . createNonFungibleTokenPermalink ( nft . asset . contract_address , nft . asset . token_id ) ,
150- }
151- }
152-
153- async getAsset (
154- address : string ,
155- tokenId : string ,
156- { chainId = ChainId . Mainnet , account } : BaseHubOptions < ChainId > = { } ,
157- ) {
158- if ( ! account || ! isValidChainId ( chainId ) ) return
159- const response = await getNonFungibleAsset ( account , address , tokenId )
160- if ( ! response ?. payload . nft . length ) return
161- const payload = first ( response . payload . nft )
162- if ( ! payload ) return
163- return this . createNonFungibleTokenAssetFromNFT ( chainId , payload )
164- }
165- async getAssets ( account : string , { chainId = ChainId . Mainnet , indicator, size } : BaseHubOptions < ChainId > = { } ) {
166- if ( ! isValidChainId ( chainId ) ) return createPageable ( EMPTY_LIST , createIndicator ( indicator ) )
167- const response = await getNonFungibleAssets ( account , indicator ?. index , size )
168- if ( ! response ?. payload . nft . length ) return createPageable ( EMPTY_LIST , createIndicator ( indicator ) )
169- const assets = response . payload . nft . map ( ( x ) => this . createNonFungibleTokenAssetFromNFT ( chainId , x ) )
170-
171- return createPageable (
172- assets ,
173- createIndicator ( indicator ) ,
174- assets . length ? createNextIndicator ( indicator ) : undefined ,
175- )
176- }
177-
178- async getAssetsByCollection (
179- address : string ,
180- { chainId = ChainId . Mainnet , indicator, size, account } : BaseHubOptions < ChainId > = { } ,
181- ) {
182- if ( ! account || ! isValidChainId ( chainId ) ) return createPageable ( EMPTY_LIST , createIndicator ( indicator ) )
183- const response = await getNonFungibleAssets ( account , indicator ?. index , size , address )
184- if ( ! response ) return
185- const assets = response . payload . nft . map ( ( x ) => this . createNonFungibleTokenAssetFromNFT ( chainId , x ) )
186-
187- return createPageable (
188- assets ,
189- createIndicator ( indicator ) ,
190- assets . length ? createNextIndicator ( indicator ) : undefined ,
191- )
192- }
193- }
194-
195- class ZerionGasAPI implements BaseGasOptions . Provider < ChainId , GasOption > {
196- async getGasOptions ( chainId : ChainId ) : Promise < Record < GasOptionType , GasOption > | undefined > {
197- if ( ! isValidChainId ( chainId ) ) return
198- const result = await getGasOptions ( chainId )
199- return {
200- [ GasOptionType . FAST ] : {
201- estimatedSeconds : 15 ,
202- suggestedMaxFeePerGas : toFixed ( result ?. fast ) ,
203- suggestedMaxPriorityFeePerGas : '0' ,
204- } ,
205- [ GasOptionType . NORMAL ] : {
206- estimatedSeconds : 30 ,
207- suggestedMaxFeePerGas : toFixed ( result ?. standard ) ,
208- suggestedMaxPriorityFeePerGas : '0' ,
209- } ,
210- [ GasOptionType . SLOW ] : {
211- estimatedSeconds : 60 ,
212- suggestedMaxFeePerGas : toFixed ( result ?. slow ) ,
213- suggestedMaxPriorityFeePerGas : '0' ,
214- } ,
215- [ GasOptionType . CUSTOM ] : {
216- estimatedSeconds : 0 ,
217- suggestedMaxFeePerGas : '' ,
218- suggestedMaxPriorityFeePerGas : '' ,
219- } ,
220- }
221- }
222- }
22343export const Zerion = new ZerionAPI ( )
224- export const ZerionNonFungibleToken = new ZerionNonFungibleTokenAPI ( )
225- export const ZerionGas = new ZerionGasAPI ( )
0 commit comments