Skip to content

Commit

Permalink
feat: getWalletHistory.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed Apr 18, 2024
1 parent cc6ebed commit 8948ffd
Show file tree
Hide file tree
Showing 38 changed files with 1,574 additions and 140 deletions.
7 changes: 7 additions & 0 deletions .changeset/pink-pianos-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': minor
'@moralisweb3/api-generator': minor
'@moralisweb3/evm-api': minor
---

The `toJSON` method of the `EvmInternalTransaction` class returns now the same format as the API (names with underscores).
7 changes: 7 additions & 0 deletions .changeset/popular-turkeys-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': minor
'@moralisweb3/api-generator': minor
'@moralisweb3/evm-api': minor
---

The `address` property of the `EvmWalletActiveChains` has `EvmAddress` type now.
7 changes: 7 additions & 0 deletions .changeset/rich-ads-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@moralisweb3/common-evm-utils': minor
'@moralisweb3/evm-api': minor
'moralis': minor
---

Added the `getWalletHistory` method to the EVM API.
14 changes: 11 additions & 3 deletions packages/apiGenerator/src/generator/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,27 @@ export class Generator {
) {}

public generate() {
const excludedRefs = new Set(this.configuration.mappings.refs.map(r => r.refs).flat());

this.writer.prepare();

for (const operation of this.contract.operations) {
this.generateOperation(operation);
}
for (const simpleType of this.contract.simpleTypes) {
this.generateSimpleType(simpleType);
if (!excludedRefs.has(simpleType.descriptor.ref.toString())) {
this.generateSimpleType(simpleType);
}
}
for (const complexType of this.contract.complexTypes) {
this.generateComplexType(complexType);
if (!excludedRefs.has(complexType.descriptor.ref.toString())) {
this.generateComplexType(complexType);
}
}
for (const unionType of this.contract.unionTypes) {
this.generateUnionType(unionType);
if (!excludedRefs.has(unionType.descriptor.ref.toString())) {
this.generateUnionType(unionType);
}
}

const abstractClientFileGenerator = new AbstractClientFileGenerator(
Expand Down
14 changes: 12 additions & 2 deletions packages/common/evmUtils/generator.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"#/components/schemas/erc20Transfer/properties/block_timestamp"
],
"nativeType": "Date"
},
{
"refs": ["#/components/schemas/internalTransaction"],
"className": "EvmInternalTransaction",
"import": "../../dataTypes"
}
],
"complexTypeProperties": [
Expand All @@ -35,7 +40,11 @@
"contract_address",
"from_wallet",
"to_wallet",
"collection_address"
"collection_address",

"address",
"to_address",
"from_address"
],
"className": "EvmAddress",
"import": "../../dataTypes"
Expand Down Expand Up @@ -108,7 +117,8 @@
"getPairPrice",
"resolveAddressToDomain",
"getTopCryptoCurrenciesByMarketCap",
"getTopCryptoCurrenciesByTradingVolume"
"getTopCryptoCurrenciesByTradingVolume",
"getWalletHistory"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/evmUtils/src/dataTypes/EvmBlock/EvmBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoralisDataObject, BigNumber, dateInputToDate } from '@moralisweb3/common-core';
import { BigNumber, dateInputToDate } from '@moralisweb3/common-core';
import { EvmAddress } from '../EvmAddress';
import { EvmChain } from '../EvmChain';
import { EvmTransaction } from '../EvmTransaction';
Expand All @@ -16,7 +16,7 @@ export type EvmBlockish = EvmBlockInput | EvmBlock;
*
* @category DataType
*/
export class EvmBlock implements MoralisDataObject {
export class EvmBlock {
/**
* Create a new instance of EvmBlock from any valid transaction input
* @param data - the EvmBlockish type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { EvmInternalTransaction } from './EvmInternalTransaction';
import { EvmInternalTransactionInput } from './types';

const exampleInput: EvmInternalTransactionInput = {
chain: '0x1',
transactionHash: '0x2ac6283fb30fe33499416b0388ff27145a0eeb6aa8b37bca40af87d7f1c74e2d',
blockNumber: 16876143,
blockHash: '0xc8d7592122307a771c5172af09699b5a2d36fa540d0fbc656f3d52c619c7536e',
Expand All @@ -23,7 +22,6 @@ describe('EvmInternalTransaction', () => {
it('should create a new EvmInternalTransaction', () => {
const transaction = EvmInternalTransaction.create(exampleInput);

expect(transaction.chain.hex).toBe('0x1');
expect(transaction.transactionHash).toBe('0x2ac6283fb30fe33499416b0388ff27145a0eeb6aa8b37bca40af87d7f1c74e2d');
expect(transaction.blockNumber.toString()).toBe('16876143');
expect(transaction.blockHash).toBe('0xc8d7592122307a771c5172af09699b5a2d36fa540d0fbc656f3d52c619c7536e');
Expand All @@ -46,14 +44,13 @@ describe('EvmInternalTransaction', () => {
const value = transaction.toJSON();

expect(value).toStrictEqual({
chain: '0x1',
from: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5',
to: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85',
transactionHash: '0x2ac6283fb30fe33499416b0388ff27145a0eeb6aa8b37bca40af87d7f1c74e2d',
transaction_hash: '0x2ac6283fb30fe33499416b0388ff27145a0eeb6aa8b37bca40af87d7f1c74e2d',
gas: '263200',
gasUsed: '2569',
blockNumber: '16876143',
blockHash: '0xc8d7592122307a771c5172af09699b5a2d36fa540d0fbc656f3d52c619c7536e',
gas_used: '2569',
block_number: '16876143',
block_nash: '0xc8d7592122307a771c5172af09699b5a2d36fa540d0fbc656f3d52c619c7536e',
input: '0x96e494e8d40a37cd10c71cb3896d1b05b6c707e29cb5aeff0278c6fc7e5e5b31623a1baa',
output: '0x0000000000000000000000000000000000000000000000000000000000000001',
value: '100000',
Expand All @@ -78,13 +75,6 @@ describe('EvmInternalTransaction', () => {
expect(EvmInternalTransaction.equals(transactionA, transactionB)).toBeTruthy();
});

it('should check inequality when chain is different', () => {
const transactionA = EvmInternalTransaction.create(exampleInput);
const transactionB = EvmInternalTransaction.create({ ...exampleInput, chain: '0x2' });

expect(transactionA.equals(transactionB)).toBeFalsy();
});

it('should check inequality when transactionHash is different', () => {
const transactionA = EvmInternalTransaction.create(exampleInput);
const transactionB = EvmInternalTransaction.create({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MoralisDataObject, BigNumber } from '@moralisweb3/common-core';
import { BigNumber } from '@moralisweb3/common-core';
import { EvmAddress } from '../EvmAddress';
import { EvmChain } from '../EvmChain';
import { EvmInternalTransactionInput, EvmInternalTransactionData } from './types';

/**
Expand All @@ -9,14 +8,28 @@ import { EvmInternalTransactionInput, EvmInternalTransactionData } from './types
*/
export type EvmInternalTransactionish = EvmInternalTransactionInput | EvmInternalTransaction;

export interface EvmInternalTransactionJSON {
readonly transaction_hash: string;
readonly block_number: string;
readonly block_hash: string;
readonly type: string;
readonly from: string;
readonly to: string;
readonly value: string;
readonly gas: string;
readonly gas_used: string;
readonly input: string;
readonly output: string;
}

/**
* The EvmTranaction is a representation of a published transaction.
*
* Use this class any time you work with a transaction.
*
* @category DataType
*/
export class EvmInternalTransaction implements MoralisDataObject {
export class EvmInternalTransaction {
/**
* Create a new instance of EvmInternalTransaction from any valid transaction input
* @param data - the EvmInternalTransactionish type
Expand All @@ -32,14 +45,29 @@ export class EvmInternalTransaction implements MoralisDataObject {
return new EvmInternalTransaction(data);
}

static fromJSON(json: EvmInternalTransactionJSON) {
return new EvmInternalTransaction({
blockHash: json.block_hash,
blockNumber: json.block_number,
from: json.from,
gas: json.gas,
gasUsed: json.gas_used,
input: json.input,
output: json.output,
to: json.to,
transactionHash: json.transaction_hash,
type: json.type,
value: json.value,
});
}

private _data: EvmInternalTransactionData;

constructor(data: EvmInternalTransactionInput) {
this._data = EvmInternalTransaction.parse(data);
}

static parse = (data: EvmInternalTransactionInput): EvmInternalTransactionData => ({
chain: EvmChain.create(data.chain),
from: EvmAddress.create(data.from),
to: EvmAddress.create(data.to),
transactionHash: data.transactionHash,
Expand All @@ -66,10 +94,6 @@ export class EvmInternalTransaction implements MoralisDataObject {
const transactionA = EvmInternalTransaction.create(dataA);
const transactionB = EvmInternalTransaction.create(dataB);

if (!transactionA._data.chain.equals(transactionB._data.chain)) {
return false;
}

if (transactionA._data.transactionHash !== transactionB._data.transactionHash) {
return false;
}
Expand All @@ -89,17 +113,20 @@ export class EvmInternalTransaction implements MoralisDataObject {
return EvmInternalTransaction.equals(this, data);
}

toJSON() {
toJSON(): EvmInternalTransactionJSON {
const data = this._data;
return {
...data,
to: data.to?.toJSON(),
from: data.from?.toJSON(),
gas: data.gas?.toString(),
gasUsed: data.gasUsed?.toString(),
value: data.value?.toString(),
chain: data.chain?.toJSON(),
blockNumber: data.blockNumber?.toString(),
block_hash: data.blockHash,
input: data.input,
output: data.output,
transaction_hash: data.transactionHash,
type: data.type,
to: data.to.toJSON(),
from: data.from.toJSON(),
gas: data.gas.toString(),
gas_used: data.gasUsed.toString(),
value: data.value.toString(),
block_number: data.blockNumber.toString(),
};
}

Expand All @@ -114,10 +141,6 @@ export class EvmInternalTransaction implements MoralisDataObject {
return this._data;
}

get chain() {
return this._data.chain;
}

get transactionHash() {
return this._data.transactionHash;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { BigNumber, BigNumberish } from '@moralisweb3/common-core';
import { EvmAddressish, EvmAddress } from '../EvmAddress';
import { EvmChain, EvmChainish } from '../EvmChain';

/**
* Valid EvmInternalTransactionLog input.
*
* @example
* ```ts
* const input = {
* "chain": "0x1",
* "transactionHash": "0x2ac6283fb30fe33499416b0388ff27145a0eeb6aa8b37bca40af87d7f1c74e2d",
* "block_number": 16876143,
* "block_hash": "0xc8d7592122307a771c5172af09699b5a2d36fa540d0fbc656f3d52c619c7536e",
Expand All @@ -24,7 +22,6 @@ import { EvmChain, EvmChainish } from '../EvmChain';
* ```
*/
export interface EvmInternalTransactionInput {
chain: EvmChainish;
transactionHash: string;
blockNumber: BigNumberish;
blockHash: string;
Expand All @@ -42,7 +39,6 @@ export interface EvmInternalTransactionInput {
* Represents a processed internal transaction log.
*/
export interface EvmInternalTransactionData {
chain: EvmChain;
transactionHash: string;
blockNumber: BigNumber;
blockHash: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MoralisDataObject, maybe, BigNumber, dateInputToDate } from '@moralisweb3/common-core';
import { maybe, BigNumber, dateInputToDate } from '@moralisweb3/common-core';
import { EvmAddress } from '../EvmAddress';
import { EvmChain } from '../EvmChain';
import { EvmNative } from '../EvmNative';
Expand All @@ -20,7 +20,7 @@ export type EvmTransactionish = EvmTransactionInput | EvmTransaction;
*
* @category DataType
*/
export class EvmTransaction implements MoralisDataObject {
export class EvmTransaction {
/**
* Create a new instance of EvmTransaction from any valid transaction input
* @param data - the EvmTransactionish type
Expand Down
33 changes: 33 additions & 0 deletions packages/common/evmUtils/src/generated/client/abstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { EvmTradeCollection, EvmTradeCollectionJSON } from '../types/EvmTradeCol
import { GetMultipleTokenPricesOperation, GetMultipleTokenPricesOperationRequest, GetMultipleTokenPricesOperationRequestJSON } from '../operations/GetMultipleTokenPricesOperation';
import { EvmErc20Price, EvmErc20PriceJSON } from '../types/EvmErc20Price';
import { EvmGetMultipleTokenPricesDto, EvmGetMultipleTokenPricesDtoInput, EvmGetMultipleTokenPricesDtoJSON } from '../types/EvmGetMultipleTokenPricesDto';
import { GetWalletHistoryOperation, GetWalletHistoryOperationRequest, GetWalletHistoryOperationRequestJSON } from '../operations/GetWalletHistoryOperation';
import { EvmWalletHistory, EvmWalletHistoryJSON } from '../types/EvmWalletHistory';
import { GetWalletTokenBalancesPriceOperation, GetWalletTokenBalancesPriceOperationRequest, GetWalletTokenBalancesPriceOperationRequestJSON } from '../operations/GetWalletTokenBalancesPriceOperation';
import { EvmErc20TokenBalanceWithPriceResult, EvmErc20TokenBalanceWithPriceResultJSON } from '../types/EvmErc20TokenBalanceWithPriceResult';
import { GetWalletNetWorthOperation, GetWalletNetWorthOperationRequest, GetWalletNetWorthOperationRequestJSON } from '../operations/GetWalletNetWorthOperation';
Expand Down Expand Up @@ -310,6 +312,37 @@ export abstract class AbstractClient {
>(ReviewContractsOperation),
};
public readonly wallets = {
/**
* @description Get the complete history of a wallet
* @param request Request with parameters.
* @param {Object} request.address The address of the wallet
* @param {Object} [request.chain] The chain to query (optional)
* @param {Number} [request.fromBlock] The minimum block number from which to get the transactions
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Number} [request.toBlock] The maximum block number from which to get the transactions.
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
* @param {String} [request.fromDate] The start date from which to get the transactions (format in seconds or datestring accepted by momentjs)
* * Provide the param 'from_block' or 'from_date'
* * If 'from_date' and 'from_block' are provided, 'from_block' will be used. (optional)
* @param {Date} [request.toDate] Get the transactions up to this date (format in seconds or datestring accepted by momentjs)
* * Provide the param 'to_block' or 'to_date'
* * If 'to_date' and 'to_block' are provided, 'to_block' will be used. (optional)
* @param {Boolean} [request.includeInternalTransactions] If the result should contain the internal transactions. (optional)
* @param {Boolean} [request.includeInputData] Set the input data from the result (optional)
* @param {Boolean} [request.nftMetadata] If the result should contain the nft metadata. (optional)
* @param {String} [request.cursor] The cursor returned in the previous response (used for getting the next page). (optional)
* @param {Object} [request.order] The order of the result, in ascending (ASC) or descending (DESC) (optional)
* @param {Number} [request.limit] The desired page size of the result. (optional)
* @returns {Object} Response for the request.
*/
getWalletHistory: this.createEndpoint<
GetWalletHistoryOperationRequest,
GetWalletHistoryOperationRequestJSON,
EvmWalletHistory,
EvmWalletHistoryJSON
>(GetWalletHistoryOperation),
/**
* @description Get token balances for a specific wallet address and their token prices in USD.
* @param request Request with parameters.
Expand Down
Loading

0 comments on commit 8948ffd

Please sign in to comment.