Skip to content

poc: confirmation intents #6073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
);
}

async fetchQuotes(requests: GenericQuoteRequest[]) {
return await Promise.all(
requests.map(async (request) => {
const quotes = await fetchBridgeQuotes(
request,
null as never,
this.#clientId,
this.#fetchFn,
this.#config.customBridgeApiBaseUrl ?? BRIDGE_PROD_API_BASE_URL,
);

const quotesWithL1GasFees = await this.#appendL1GasFees(quotes);
const quotesWithSolanaFees = await this.#appendSolanaFees(quotes);

return quotesWithL1GasFees ?? quotesWithSolanaFees ?? quotes;
}),
);
}

_executePoll = async (pollingInput: BridgePollingInput) => {
await this.#fetchBridgeQuotes(pollingInput);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import type {
AfterSimulateHook,
BeforeSignHook,
TransactionContainerType,
TransactionAsset,
} from './types';
import {
GasFeeEstimateLevel,
Expand Down Expand Up @@ -1106,6 +1107,7 @@ export class TransactionController extends BaseController<
* @param txParams - Standard parameters for an Ethereum transaction.
* @param options - Additional options to control how the transaction is added.
* @param options.actionId - Unique ID to prevent duplicate requests.
* @param options.assets - Assets required by the transaction.
* @param options.batchId - A custom ID for the batch this transaction belongs to.
* @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
* @param options.disableGasBuffer - Whether to disable the gas estimation buffer.
Expand All @@ -1128,6 +1130,7 @@ export class TransactionController extends BaseController<
txParams: TransactionParams,
options: {
actionId?: string;
assets?: TransactionAsset[];
batchId?: Hex;
deviceConfirmedOn?: WalletDevice;
disableGasBuffer?: boolean;
Expand All @@ -1151,6 +1154,7 @@ export class TransactionController extends BaseController<

const {
actionId,
assets,
batchId,
deviceConfirmedOn,
disableGasBuffer,
Expand Down Expand Up @@ -1244,6 +1248,7 @@ export class TransactionController extends BaseController<
: {
// Add actionId to txMeta to check if same actionId is seen again
actionId,
assets,
batchId,
chainId,
dappSuggestedGasFees,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class ExtraTransactionsPublishHook {
}));

const transactions: TransactionBatchSingleRequest[] = [
firstTransaction,
...extraTransactions,
firstTransaction,
];

log('Adding transaction batch', {
Expand All @@ -107,9 +107,10 @@ export class ExtraTransactionsPublishHook {
from,
networkClientId,
transactions,
disable7702: true,
disableHook: false,
disable7702: false,
disableHook: true,
disableSequential: true,
requireApproval: false,
});

return resultPromise.promise;
Expand Down
1 change: 1 addition & 0 deletions packages/transaction-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type {
SimulationError,
SimulationToken,
SimulationTokenBalanceChange,
TransactionAsset,
TransactionBatchMeta,
TransactionBatchRequest,
TransactionBatchResult,
Expand Down
7 changes: 7 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type TransactionMeta = {
*/
actionId?: string;

assets?: TransactionAsset[];

/**
* Base fee of the block as a hex value, introduced in EIP-1559.
*/
Expand Down Expand Up @@ -1877,3 +1879,8 @@ export type BeforeSignHook = (request: {
}
| undefined
>;

export type TransactionAsset = {
address: Hex;
amount: Hex;
};
19 changes: 18 additions & 1 deletion packages/transaction-controller/src/utils/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ async function addTransactionBatchWith7702(
const {
addTransaction,
getChainId,
getTransaction,
messenger,
publicKeyEIP7702,
request: userRequest,
Expand Down Expand Up @@ -321,13 +322,23 @@ async function addTransactionBatchWith7702(
),
);

const existingTransaction = transactions.find((tx) => tx.existingTransaction);

const existingTransactionMeta = existingTransaction
? getTransaction(existingTransaction.existingTransaction?.id as string)
: undefined;

const batchParams = generateEIP7702BatchTransaction(from, nestedTransactions);

const txParams: TransactionParams = {
from,
...batchParams,
};

if (existingTransactionMeta) {
txParams.nonce = existingTransactionMeta.txParams.nonce;
}

if (!isSupported) {
const upgradeContractAddress = getEIP7702UpgradeContractAddress(
chainId,
Expand Down Expand Up @@ -383,7 +394,13 @@ async function addTransactionBatchWith7702(
});

// Wait for the transaction to be published.
await result;
const transactionHash = await result;

if (existingTransaction) {
existingTransaction?.existingTransaction?.onPublish?.({
transactionHash,
});
}

return {
batchId,
Expand Down
10 changes: 0 additions & 10 deletions packages/transaction-controller/src/utils/eip7702.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,6 @@ export function generateEIP7702BatchTransaction(
(param) => transaction[param] !== undefined,
);

if (unsupported.length) {
const errorData = unsupported
.map((param) => `${param}: ${transaction[param]}`)
.join(', ');

throw new Error(
`EIP-7702 batch transactions do not support gas parameters per call - ${errorData}`,
);
}

return [
to ?? '0x0000000000000000000000000000000000000000',
value ?? '0x0',
Expand Down
Loading