Skip to content

Commit

Permalink
polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed Jul 27, 2022
1 parent 64ab9ae commit 77c7282
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/Config/MoralisConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface EvmUtilsConfigValues {
formatEvmChainId: EvmChainIdFormat;
}

// @moralisweb3/api
interface ApiConfigValues {
// @moralisweb3/api-utils
interface ApiUtilsConfigValues {
apiKey: string;
}

Expand All @@ -30,7 +30,7 @@ interface SolApiConfigValues {
export type MoralisConfigValues =
| CoreConfigValues
| EvmUtilsConfigValues
| ApiConfigValues
| ApiUtilsConfigValues
| EvmApiConfigValues
| SolApiConfigValues
| { [key: string]: string | number }; // Other, not strong typed values.
16 changes: 8 additions & 8 deletions packages/core/src/dataTypes/BigNumber/BigNumber.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigNumber } from './BigNumber';

describe('BigNumber', () => {
it('from() returns integer', () => {
const value = BigNumber.from('1000000000000000000');
it('create() returns integer', () => {
const value = BigNumber.create('1000000000000000000');
expect(value.toString()).toEqual('1000000000000000000');
expect(value.toJSON()).toEqual('0x0de0b6b3a7640000');
expect(value.toDecimal(0)).toEqual('1000000000000000000');
Expand All @@ -26,12 +26,12 @@ describe('BigNumber', () => {
});

it('does not create a new instance if BigNumber instance passed', () => {
const value = BigNumber.from(0x1);
expect(BigNumber.from(value) === value).toBe(true);
const value = BigNumber.create(0x1);
expect(BigNumber.create(value) === value).toBe(true);
});

describe('math', () => {
const from = (value: number) => BigNumber.from(value);
const from = (value: number) => BigNumber.create(value);

it('add() multiplies correctly', () => {
expect(from(2).add(from(3)).toString()).toEqual('5');
Expand All @@ -49,9 +49,9 @@ describe('BigNumber', () => {
expect(from(15).div(from(5)).toString()).toEqual('3');
});

it('eq() returns correct value', () => {
expect(from(1).eq(from(1))).toBe(true);
expect(from(1).eq(from(-1))).toBe(false);
it('equals() returns correct value', () => {
expect(from(1).equals(from(1))).toBe(true);
expect(from(1).equals(from(-1))).toBe(false);
});
});
});
6 changes: 3 additions & 3 deletions packages/core/src/dataTypes/BigNumber/BigNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BigNumberParser, BigNumberPrimitive } from './BigNumberParser';
export type BigNumberish = BigNumber | BigNumberPrimitive;

export class BigNumber {
public static from(value: BigNumberish): BigNumber {
public static create(value: BigNumberish): BigNumber {
if (value instanceof BigNumber) {
return value;
}
Expand Down Expand Up @@ -37,7 +37,7 @@ export class BigNumber {
return new BigNumber(this.value / asBigInt(value));
}

public eq(value: BigNumber): boolean {
public equals(value: BigNumber): boolean {
return this.value === value.toBigInt();
}

Expand All @@ -59,5 +59,5 @@ export class BigNumber {
}

function asBigInt(value: BigNumberish): bigint {
return BigNumber.from(value).toBigInt();
return BigNumber.create(value).toBigInt();
}
2 changes: 1 addition & 1 deletion packages/evmApi/src/resolvers/account/getTokenTransfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getTokenTransfersResolver = new ApiPaginatedResolver({
address: EvmAddress.create(transfer.address),
toAddress: EvmAddress.create(transfer.to_address),
fromAddress: EvmAddress.create(transfer.from_address),
value: BigNumber.from(transfer.value),
value: BigNumber.create(transfer.value),
blockTimestamp: new Date(transfer.block_timestamp),
})),
resultToJson: (data) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/evmApi/src/resolvers/account/getTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getTransactionsResolver = new ApiPaginatedResolver({
blockNumber: +transaction.block_number,
blockTimestamp: new Date(transaction.block_timestamp),
gasPrice: transaction.gas_price,
gasLimit: BigNumber.from(transaction.gas),
gasLimit: BigNumber.create(transaction.gas),
to: transaction.to_address,
// Not specified in Api response
accessList: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/evmApi/src/resolvers/token/getTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getTokenAllowanceResolver = new ApiResolver({
name: 'getTokenAllowance',
getUrl: (params: Params) => `${BASE_URL}/erc20/${params.address}/allowance`,
apiToResult: (data: ApiResult) => ({
allowance: BigNumber.from(data.allowance),
allowance: BigNumber.create(data.allowance),
}),
resultToJson: (data) => ({
allowance: data.allowance.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/evmUtils/src/dataTypes/Erc20Value/Erc20Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Erc20Value implements MoralisData {
const erc20ValueA = Erc20Value.create(valueA);
const erc20ValueB = Erc20Value.create(valueB);

return erc20ValueA.value.eq(erc20ValueB.value);
return erc20ValueA.value.equals(erc20ValueB.value);
}

equals(value: Erc20Valueish): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/evmUtils/src/dataTypes/EvmNative/EvmNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class EvmNative implements MoralisData {
const evmNativeA = EvmNative.create(valueA);
const evmNativeB = EvmNative.create(valueB);

return evmNativeA.rawValue.eq(evmNativeB.rawValue);
return evmNativeA.rawValue.equals(evmNativeB.rawValue);
}

public equals(value: EvmNative): boolean {
Expand Down
10 changes: 5 additions & 5 deletions packages/evmUtils/src/dataTypes/EvmTransaction/EvmTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export class EvmTransaction implements MoralisDataObject {
return {
to: maybe(value.to, EvmAddress.create),
from: maybe(value.from, EvmAddress.create),
nonce: maybe(value.nonce, BigNumber.from),
nonce: maybe(value.nonce, BigNumber.create),

gasLimit: maybe(value.gasLimit, BigNumber.from),
gasPrice: maybe(value.gasPrice, BigNumber.from),
gasLimit: maybe(value.gasLimit, BigNumber.create),
gasPrice: maybe(value.gasPrice, BigNumber.create),

data: maybe(value.data),
value: maybe(value.value, (val) => EvmNative.create(val, 'wei')),
Expand All @@ -51,8 +51,8 @@ export class EvmTransaction implements MoralisDataObject {
type: maybe(value.type),
accessList: maybe(value.accessList, accessListify),

maxPriorityFeePerGas: maybe(value.maxPriorityFeePerGas, BigNumber.from),
maxFeePerGas: maybe(value.maxFeePerGas, BigNumber.from),
maxPriorityFeePerGas: maybe(value.maxPriorityFeePerGas, BigNumber.create),
maxFeePerGas: maybe(value.maxFeePerGas, BigNumber.create),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const transactionResponseData: EvmTransactionResponseInput = {
hash: HASH,
};

const expectedTotalGas = BigNumber.from(inputWithAllData.cumulativeGasUsed).mul(inputWithAllData.gasPrice).toString();
const expectedTotalGas = BigNumber.create(inputWithAllData.cumulativeGasUsed).mul(inputWithAllData.gasPrice).toString();

describe('EvmTransactionReceipt', () => {
beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class EvmTransactionReceipt implements MoralisDataObject {

contractAddress: maybe(value.contractAddress, EvmAddress.create),

gasUsed: BigNumber.from(value.gasUsed),
cumulativeGasUsed: BigNumber.from(value.cumulativeGasUsed),
gasPrice: BigNumber.from(value.gasPrice),
gasUsed: BigNumber.create(value.gasUsed),
cumulativeGasUsed: BigNumber.create(value.cumulativeGasUsed),
gasPrice: BigNumber.create(value.gasPrice),

logs: value.logs?.map((log) => EvmTransactionLog.create(log)),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EvmTransactionResponse implements MoralisDataObject {
static parse(value: EvmTransactionResponseInput): EvmTransactionResponseData {
return {
hash: value.hash,
nonce: BigNumber.from(value.nonce || 0), // TODO: what if nonce is empty? should be zero?
nonce: BigNumber.create(value.nonce || 0), // TODO: what if nonce is empty? should be zero?
chain: EvmChain.create(value.chain),

from: EvmAddress.create(value.from),
Expand All @@ -54,15 +54,15 @@ export class EvmTransactionResponse implements MoralisDataObject {
blockHash: maybe(value.blockHash),
blockTimestamp: maybe(value.blockTimestamp, (value) => (value instanceof Date ? value : new Date(value))),

gasLimit: maybe(value.gasLimit, BigNumber.from),
gasPrice: maybe(value.gasPrice, BigNumber.from),
gasLimit: maybe(value.gasLimit, BigNumber.create),
gasPrice: maybe(value.gasPrice, BigNumber.create),

data: maybe(value.data),

type: maybe(value.type),

maxPriorityFeePerGas: maybe(value.maxPriorityFeePerGas, BigNumber.from),
maxFeePerGas: maybe(value.maxFeePerGas, BigNumber.from),
maxPriorityFeePerGas: maybe(value.maxPriorityFeePerGas, BigNumber.create),
maxFeePerGas: maybe(value.maxFeePerGas, BigNumber.create),
};
}

Expand Down

0 comments on commit 77c7282

Please sign in to comment.