-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: creates Noves API class * feat: adds noves pagination (#2863) --------- Co-authored-by: Nicole O'Brien <[email protected]>
- Loading branch information
1 parent
db9a3e2
commit 82278ad
Showing
38 changed files
with
603 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './noves.api' |
27 changes: 27 additions & 0 deletions
27
packages/shared/src/lib/auxiliary/noves/apis/noves-base.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BaseApi, IRequestParams } from '@core/utils' | ||
import { SupportedChain } from '../interfaces' | ||
|
||
export class NovesBaseApi extends BaseApi { | ||
protected get<T>(params: Omit<IRequestParams, 'body'>): Promise<T | undefined> { | ||
return this.makeRequest<T>({ | ||
...params, | ||
headers: { | ||
apiKey: process.env.NOVES_API_KEY ?? 'demokey', | ||
}, | ||
}) | ||
} | ||
|
||
protected post<T>(params: IRequestParams): Promise<T | undefined> { | ||
return this.makeRequest<T>({ | ||
...params, | ||
headers: { | ||
apiKey: process.env.NOVES_API_KEY ?? 'demokey', | ||
}, | ||
}) | ||
} | ||
|
||
async getSupportedEvmChains(): Promise<SupportedChain[]> { | ||
const response = await this.get<SupportedChain[]>({ path: 'evm/chains' }) | ||
return response ?? [] | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/shared/src/lib/auxiliary/noves/apis/noves-foresight.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NovesForesightDescribeResponse, NovesTransaction } from '../interfaces' | ||
import { NovesBaseApi } from './noves-base.api' | ||
|
||
export class NovesForesightApi extends NovesBaseApi { | ||
constructor() { | ||
super('https://foresight.noves.fi') | ||
} | ||
|
||
async previewTransaction( | ||
chain: string, | ||
transaction: NovesTransaction, | ||
viewAsAccountAddress?: string, | ||
blockNumber?: number | ||
): Promise<unknown | undefined> { | ||
const response = await this.post<unknown>({ | ||
path: `evm/${chain}/preview`, | ||
body: JSON.stringify(transaction), | ||
queryParameters: { | ||
...(viewAsAccountAddress ? { viewAsAccountAddress } : {}), | ||
...(blockNumber ? { blockNumber } : {}), | ||
}, | ||
}) | ||
return response | ||
} | ||
|
||
async describeTransaction( | ||
chain: string, | ||
transaction: NovesTransaction | ||
): Promise<NovesForesightDescribeResponse | undefined> { | ||
const response = await this.post<NovesForesightDescribeResponse>({ | ||
path: `evm/${chain}/describe`, | ||
body: JSON.stringify(transaction), | ||
}) | ||
return response | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/shared/src/lib/auxiliary/noves/apis/noves-nodeplus.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { EthRpcMethod } from '../enums' | ||
import { SupportedChain } from '../interfaces' | ||
import { EthRpcParams, EthRpcResponses, NodeType } from '../types' | ||
import { NovesBaseApi } from './noves-base.api' | ||
|
||
export class NovesNodePlusApi extends NovesBaseApi { | ||
constructor() { | ||
super('https://rpc.noves.fi') | ||
} | ||
|
||
async rpcPost<T extends EthRpcMethod>( | ||
method: T, | ||
chain: SupportedChain, | ||
nodeType: NodeType, | ||
params: EthRpcParams[T] | ||
): Promise<EthRpcResponses[T] | undefined> { | ||
const response = await this.post<EthRpcResponses[T]>({ | ||
path: `${chain.name}_${nodeType}`, | ||
body: JSON.stringify({ | ||
method, | ||
params, | ||
id: 1, | ||
jsonrpc: '2.0', | ||
}), | ||
}) | ||
return response | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/shared/src/lib/auxiliary/noves/apis/noves-pricing.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NovesTokenPriceResponse } from '../interfaces' | ||
import { NovesBaseApi } from './noves-base.api' | ||
|
||
export class NovesPricingApi extends NovesBaseApi { | ||
constructor() { | ||
super('https://pricing.noves.fi') | ||
} | ||
|
||
async getTokenPrice(tokenAddress: string, chain: string): Promise<NovesTokenPriceResponse | undefined> { | ||
const response = await this.get<NovesTokenPriceResponse>({ | ||
path: `${chain}/price/${tokenAddress}`, | ||
}) | ||
return response | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
packages/shared/src/lib/auxiliary/noves/apis/noves-translate.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { QueryParameters } from '@core/utils' | ||
import { | ||
NovesHistoryItem, | ||
NovesHistoryOptions, | ||
NovesHistoryResponse, | ||
NovesPagination, | ||
NovesTxDescriptionResponse, | ||
NovesTxResponse, | ||
NovesTxsOptions, | ||
NovesTxsResponse, | ||
} from '../interfaces' | ||
import { NovesBaseApi } from './noves-base.api' | ||
import { NovesTokenBalancesResponse } from '../types' | ||
|
||
export class NovesTranslateApi extends NovesBaseApi { | ||
constructor() { | ||
super('https://translate.noves.fi') | ||
} | ||
|
||
async getTransaction( | ||
txHash: string, | ||
chain: string, | ||
viewAsAccountAddress?: string | ||
): Promise<NovesTxResponse | undefined> { | ||
const response = await this.get<NovesTxResponse>({ | ||
path: `evm/${chain}/tx/${txHash}`, | ||
queryParameters: viewAsAccountAddress ? { viewAsAccountAddress } : {}, | ||
}) | ||
return response | ||
} | ||
|
||
async describeTransaction(txHash: string, chain: string): Promise<NovesTxDescriptionResponse | undefined> { | ||
const response = await this.get<NovesTxDescriptionResponse>({ path: `evm/${chain}/describeTx/${txHash}` }) | ||
return response | ||
} | ||
|
||
async getTransactionsFromAddress( | ||
accountAddress: string, | ||
chain: string, | ||
options?: NovesTxsOptions | ||
): Promise<NovesTxsResponse | undefined> { | ||
const response = await this.get<NovesTxsResponse>({ | ||
path: `evm/${chain}/txs/${accountAddress}`, | ||
queryParameters: options as QueryParameters, | ||
}) | ||
return response | ||
} | ||
|
||
async getHistoryFromAddress( | ||
accountAddress: string, | ||
chain: string, | ||
options?: NovesHistoryOptions | ||
): Promise<NovesHistoryItem[]> { | ||
const response = await this.get<NovesHistoryResponse>({ | ||
path: `evm/${chain}/history/${accountAddress}`, | ||
queryParameters: options as QueryParameters, | ||
}) | ||
|
||
if (response) { | ||
const responses = await this.recursiveRequest([response], response) | ||
|
||
const items = responses.reduce((acc, response) => { | ||
return [...acc, ...response.items] | ||
}, [] as NovesHistoryItem[]) | ||
|
||
return items | ||
} | ||
|
||
return [] | ||
} | ||
|
||
async recursiveRequest<T extends NovesPagination>( | ||
previousResponses: T[], | ||
pagination: NovesPagination | ||
): Promise<T[]> { | ||
if (pagination?.hasNextPage) { | ||
const response = await this.get<T>({ | ||
path: pagination.nextPageUrl, | ||
}) | ||
|
||
if (response) { | ||
return this.recursiveRequest([...previousResponses, response], response) | ||
} | ||
|
||
return previousResponses | ||
} | ||
|
||
return previousResponses | ||
} | ||
|
||
async getTokenBalancesFromAddress( | ||
accountAddress: string, | ||
chain: string, | ||
tokensHashes: string[], | ||
blockNumber?: number | ||
): Promise<NovesTokenBalancesResponse | undefined> { | ||
const response = await this.post<NovesTokenBalancesResponse>({ | ||
path: `/evm/${chain}/tokens/balancesOf/${accountAddress}`, | ||
body: JSON.stringify(tokensHashes), | ||
queryParameters: blockNumber ? { blockNumber } : {}, | ||
}) | ||
return response | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { INovesApi } from '../interfaces' | ||
import { NovesForesightApi } from './noves-foresight.api' | ||
import { NovesNodePlusApi } from './noves-nodeplus.api' | ||
import { NovesPricingApi } from './noves-pricing.api' | ||
import { NovesTranslateApi } from './noves-translate.api' | ||
|
||
export class NovesApi implements INovesApi { | ||
translate = new NovesTranslateApi() | ||
foresight = new NovesForesightApi() | ||
pricing = new NovesPricingApi() | ||
nodePlus = new NovesNodePlusApi() | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/shared/src/lib/auxiliary/noves/enums/eth-rpc-method.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export enum EthRpcMethod { | ||
BlockNumber = 'eth_blockNumber', | ||
GetBlockByNumber = 'eth_getBlockByNumber', | ||
GetBlockByHash = 'eth_getBlockByHash', | ||
GetTransactionByHash = 'eth_getTransactionByHash', | ||
GetTransactionReceipt = 'eth_getTransactionReceipt', | ||
Call = 'eth_call', | ||
GetBalance = 'eth_getBalance', | ||
GetCode = 'eth_getCode', | ||
GetLogs = 'eth_getLogs', | ||
GetStorageAt = 'eth_getStorageAt', | ||
EstimateGas = 'eth_estimateGas', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './eth-rpc-method.enum' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './apis' | ||
export * from './interfaces' | ||
export * from './types' |
16 changes: 16 additions & 0 deletions
16
packages/shared/src/lib/auxiliary/noves/interfaces/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export * from './noves-api-supported-chain.interface' | ||
export * from './noves-api.interface' | ||
export * from './noves-foresight-api.interface' | ||
export * from './noves-foresight-describe-response.interface' | ||
export * from './noves-history-response.interface' | ||
export * from './noves-nodeplus-api.interface' | ||
export * from './noves-pagination.interface' | ||
export * from './noves-pricing-api.interface' | ||
export * from './noves-token-balance.interface' | ||
export * from './noves-token-price-response.interface' | ||
export * from './noves-token.interface' | ||
export * from './noves-transaction.interface' | ||
export * from './noves-translate-api.interface' | ||
export * from './noves-tx-description-response.interface' | ||
export * from './noves-tx-response.interface' | ||
export * from './noves-txs-response.interface' |
5 changes: 5 additions & 0 deletions
5
packages/shared/src/lib/auxiliary/noves/interfaces/noves-api-supported-chain.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface SupportedChain { | ||
name?: string | ||
ecosystem?: string | ||
evmChainId?: string | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/shared/src/lib/auxiliary/noves/interfaces/noves-api.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { INovesTranslateApi } from './noves-translate-api.interface' | ||
import { INovesForesightApi } from './noves-foresight-api.interface' | ||
import { INovesPricingApi } from './noves-pricing-api.interface' | ||
import { INovesNodeplusApi } from './noves-nodeplus-api.interface' | ||
|
||
export interface INovesApi { | ||
translate: INovesTranslateApi | ||
foresight: INovesForesightApi | ||
pricing: INovesPricingApi | ||
nodePlus: INovesNodeplusApi | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/shared/src/lib/auxiliary/noves/interfaces/noves-foresight-api.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NovesForesightDescribeResponse } from './noves-foresight-describe-response.interface' | ||
import { NovesTransaction } from './noves-transaction.interface' | ||
|
||
export interface INovesForesightApi { | ||
previewTransaction( | ||
chain: string, | ||
transaction: NovesTransaction, | ||
viewAsAccountAddress?: string, | ||
blockNumber?: number | ||
): Promise<unknown | undefined> | ||
describeTransaction( | ||
chain: string, | ||
transaction: NovesTransaction | ||
): Promise<NovesForesightDescribeResponse | undefined> | ||
} |
3 changes: 3 additions & 0 deletions
3
.../shared/src/lib/auxiliary/noves/interfaces/noves-foresight-describe-response.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface NovesForesightDescribeResponse { | ||
description: string | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/shared/src/lib/auxiliary/noves/interfaces/noves-history-response.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NovesPagination } from './noves-pagination.interface' | ||
|
||
export interface NovesHistoryResponse extends NovesPagination { | ||
items: NovesHistoryItem[] | ||
} | ||
|
||
export interface NovesHistoryItem { | ||
transactionHash: string | ||
blockNumber: string | ||
timestamp: number | ||
} |
Oops, something went wrong.