Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@
"build": "tsc --project ."
},
"peerDependencies": {
"@metamask/composable-controller": "^1.0.2",
"@metamask/composable-controller": "^3.0.3",
"@metamask/network-controller": "^3.0.0"
},
"devDependencies": {
"@babel/runtime": "^7.0.0",
"@lavamoat/allow-scripts": "^3.0.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/composable-controller": "^1.0.2",
"@metamask/composable-controller": "^3.0.3",
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/transaction-controller": "^3.0.0",
"@metamask/approval-controller": "^3.5.1",
"@metamask/network-controller": "^12.2.0",
"@metamask/transaction-controller": "^11.0.0",
"@types/jest": "^26.0.22",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"babel-runtime": "^6.26.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "~2.26.0",
Expand All @@ -66,10 +70,10 @@
"typescript": "^5.1.0"
},
"dependencies": {
"@metamask/base-controller": "^1.1.2",
"@metamask/controller-utils": "^8.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/gas-fee-controller": "^3.0.0",
"@metamask/base-controller": "^3.2.1",
"@metamask/controller-utils": "^5.0.2",
"@metamask/eth-query": "^3.0.1",
"@metamask/gas-fee-controller": "^6.1.2",
"@metamask/utils": "^8.3.0",
"abort-controller": "^3.0.0",
"async-mutex": "^0.4.1",
Expand All @@ -81,9 +85,12 @@
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false,
"@metamask/gas-fee-controller>babel-runtime>core-js": false,
"@metamask/gas-fee-controller>ethereumjs-util>ethereum-cryptography>keccak": false,
"@metamask/gas-fee-controller>ethereumjs-util>ethereum-cryptography>secp256k1": false
"@metamask/gas-fee-controller>ethereumjs-util>ethereum-cryptography>secp256k1": false,
"@metamask/transaction-controller>babel-runtime>core-js": false,
"babel-runtime>core-js": false,
"@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
"@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
}
}
}
12 changes: 6 additions & 6 deletions src/SwapsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
GasFeeStateLegacy,
} from '@metamask/gas-fee-controller';
import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
import type { Transaction } from '@metamask/transaction-controller';
import type { TransactionParams } from '@metamask/transaction-controller';
import type { Hex } from '@metamask/utils';
import { Mutex } from 'async-mutex';
import { BigNumber } from 'bignumber.js';
Expand Down Expand Up @@ -162,7 +162,7 @@ export type SwapsState = {
topAggId: null | string;
isInPolling: boolean;
pollingCyclesLeft: number;
approvalTransaction: Transaction | null;
approvalTransaction: TransactionParams | null;
quoteValues: { [key: string]: QuoteValues } | null;
quoteRefreshSeconds: number | null;
usedGasEstimate: EthGasPriceEstimate | GasFeeEstimates | null;
Expand All @@ -179,7 +179,7 @@ export type SwapsState = {
type SwapsNextState = {
quotes: { [key: string]: Quote };
quotesLastFetched: null | number;
approvalTransaction: Transaction | null;
approvalTransaction: TransactionParams | null;
topAggId: null | string;
topAggSavings?: QuoteSavings | null;
quoteValues: { [key: string]: QuoteValues } | null;
Expand Down Expand Up @@ -239,7 +239,7 @@ export default class SwapsController extends BaseController<
private readonly fetchEstimatedMultiLayerL1Fee?: (
eth: any,
options: {
txParams: Transaction;
txParams: TransactionParams;
chainId: Hex;
},
) => Promise<string | undefined>;
Expand Down Expand Up @@ -573,7 +573,7 @@ export default class SwapsController extends BaseController<

/* istanbul ignore next */
private async timedoutGasReturn(
tradeTxParams: Transaction | null,
tradeTxParams: TransactionParams | null,
): Promise<{ gas: string | null }> {
if (!tradeTxParams) {
return { gas: null };
Expand Down Expand Up @@ -835,7 +835,7 @@ export default class SwapsController extends BaseController<
fetchEstimatedMultiLayerL1Fee?: (
eth: EthQuery,
options: {
txParams: Transaction;
txParams: TransactionParams;
chainId: Hex;
},
) => Promise<string | undefined>;
Expand Down
4 changes: 2 additions & 2 deletions src/swapsInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Transaction } from '@metamask/transaction-controller';
import type { TransactionParams } from '@metamask/transaction-controller';
import type { BigNumber } from 'bignumber.js';

export enum APIType {
Expand Down Expand Up @@ -80,7 +80,7 @@ export type APIAggregatorMetadata = {

type QuoteTransaction = {
value: string;
} & Transaction;
} & TransactionParams;

/**
* Savings of a quote
Expand Down
21 changes: 12 additions & 9 deletions src/swapsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BNToHex,
query,
} from '@metamask/controller-utils';
import type { Transaction } from '@metamask/transaction-controller';
import type { TransactionParams } from '@metamask/transaction-controller';
import type { Hex } from '@metamask/utils';
import { add0x } from '@metamask/utils';
import { BigNumber } from 'bignumber.js';
Expand Down Expand Up @@ -42,7 +42,7 @@ import { APIType } from './swapsInterfaces';
// /
// / BEGIN: Lifted from now unexported normalizeTransaction in @metamask/transaction-controller@3.0.0
// /
const TX_NORMALIZERS: { [param in keyof Transaction]: any } = {
const TX_NORMALIZERS: { [param in keyof TransactionParams]: any } = {
data: (data: string) => add0x(data),
from: (from: string) => add0x(from).toLowerCase(),
gas: (gas: string) => add0x(gas),
Expand All @@ -62,9 +62,9 @@ const TX_NORMALIZERS: { [param in keyof Transaction]: any } = {
* @param transaction - Transaction object to normalize.
* @returns Normalized Transaction object.
*/
export function normalizeTransaction(transaction: Transaction) {
const normalizedTransaction: Transaction = { from: '' };
let key: keyof Transaction;
export function normalizeTransaction(transaction: TransactionParams) {
const normalizedTransaction: TransactionParams = { from: '' };
let key: keyof TransactionParams;
for (key in TX_NORMALIZERS) {
if (transaction[key]) {
normalizedTransaction[key] = TX_NORMALIZERS[key](
Expand Down Expand Up @@ -449,8 +449,8 @@ export function calculateGasEstimateWithRefund(
export function getSwapsTokensReceived(
receipt: TransactionReceipt,
approvalReceipt: TransactionReceipt | null,
transaction: Transaction,
approvalTransaction: Transaction,
transaction: TransactionParams,
approvalTransaction: TransactionParams,
destinationToken: SwapsToken,
previousBalance: string,
postBalance: string,
Expand Down Expand Up @@ -685,7 +685,10 @@ export function calcTokenAmount(value: number | BigNumber, decimals: number) {
* @param ethQuery - The ethQuery object.
* @returns Promise resolving to an object containing gas and gasPrice.
*/
export async function estimateGas(transaction: Transaction, ethQuery: any) {
export async function estimateGas(
transaction: TransactionParams,
ethQuery: any,
) {
const estimatedTransaction = { ...transaction };
const { value, data } = estimatedTransaction;
const { gasLimit } = await query(ethQuery, 'getBlockByNumber', [
Expand Down Expand Up @@ -733,7 +736,7 @@ export function constructTxParams({
gasPrice?: string;
amount?: string;
}): any {
const txParams: Transaction = {
const txParams: TransactionParams = {
data,
from,
value: '0',
Expand Down
Loading