From 9a1924b2f3d6acb4331a2e7b6a82d9b4d3ec5aec Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Thu, 2 May 2024 14:45:54 +0200 Subject: [PATCH 1/2] improvements for 6963 override --- extension/src/injection.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extension/src/injection.ts b/extension/src/injection.ts index 1e845c94..3cf193dc 100644 --- a/extension/src/injection.ts +++ b/extension/src/injection.ts @@ -46,7 +46,7 @@ const announceEip6963Provider = (provider: InjectedProvider) => { const info = { uuid: '2a0c727b-4359-49a0-920c-b411d32b1d1e', // random uuid name: 'Zodiac Pilot', - // icon: 'TODO', + icon: '//pilot.gnosisguild.org/zodiac48.png', rdns: 'org.gnosisguild.pilot', } @@ -66,13 +66,19 @@ announceEip6963Provider(injectedProvider) // override EIP-6963 provider announcement for MetaMask window.addEventListener('eip6963:announceProvider', (event) => { const ev = event as CustomEvent - if (ev.detail.info.rdns === 'io.metamask' && !ev.detail.metamaskOverride) { + if ( + ev.detail.info.rdns === 'io.metamask' && + ev.detail.info.name !== 'Zodiac Pilot' + ) { window.dispatchEvent( new CustomEvent('eip6963:announceProvider', { detail: Object.freeze({ - info: ev.detail.info, + info: { + ...ev.detail.info, + name: 'Zodiac Pilot', + icon: '//pilot.gnosisguild.org/zodiac48.png', + }, provider: injectedProvider, - metamaskOverride: true, }), }) ) From a9bf1c9c307e6d6e60b9931ee2f6c05cddf3d7dd Mon Sep 17 00:00:00 2001 From: Jan-Felix Date: Thu, 2 May 2024 15:17:56 +0200 Subject: [PATCH 2/2] fix curve transaction flow --- extension/src/providers/ProvideTenderly.tsx | 37 ++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/extension/src/providers/ProvideTenderly.tsx b/extension/src/providers/ProvideTenderly.tsx index fe70a247..d21ee440 100644 --- a/extension/src/providers/ProvideTenderly.tsx +++ b/extension/src/providers/ProvideTenderly.tsx @@ -179,12 +179,14 @@ export class TenderlyProvider extends EventEmitter { private blockNumber: number | undefined private tenderlyForkApi: string + private throttledIncreaseBlock: () => void constructor(chainId: ChainId) { super() this.provider = getEip1193ReadOnlyProvider(chainId, ZERO_ADDRESS) this.chainId = chainId this.tenderlyForkApi = 'https://fork-api.pilot.gnosisguild.org' + this.throttledIncreaseBlock = throttle(this.increaseBlock, 1000) } async request(request: JsonRpcRequest): Promise { @@ -194,7 +196,10 @@ export class TenderlyProvider extends EventEmitter { } if (request.method === 'eth_blockNumber' && this.blockNumber) { - // Save some polling requests so we don't hit Tenderly's rate limits too quickly + // Some apps (such as Curve) only let the user continue in a transaction flow after a certain number of blocks have been mined. + // To simulate progress of time/blocks, we increase the block number when polled, throttled in intervals of 1 second. + // We cache the block number to save some polling requests so we don't hit Tenderly's rate limits too quickly. + this.throttledIncreaseBlock() return this.blockNumber } @@ -228,17 +233,11 @@ export class TenderlyProvider extends EventEmitter { } if (request.method === 'eth_sendTransaction') { - // when sending a transaction, we need retrieve that transaction's ID on Tenderly + // when sending a transaction, we need to retrieve that transaction's ID on Tenderly const { global_head: headTransactionId, block_number } = await this.fetchForkInfo() this.blockNumber = block_number this.transactionIds.set(result, headTransactionId) // result is the transaction hash - - // advance two extra blocks to account for apps waiting on the transaction's inclusion in the next block - window.setTimeout(async () => { - await provider.send('evm_increaseBlocks', ['0x2']) - if (this.blockNumber) this.blockNumber += 2 - }, 1) } return result @@ -337,4 +336,26 @@ export class TenderlyProvider extends EventEmitter { dashboardLink: `https://dashboard.tenderly.co/public/gnosisguild/zodiac-pilot/fork-simulation/${transactionId}`, } } + + private increaseBlock = async () => { + if (!this.forkProviderPromise || !this.blockNumber) return + const provider = await this.forkProviderPromise + await provider.send('evm_increaseBlocks', ['0x1']) + this.blockNumber++ + } +} + +function throttle(func: (...args: any[]) => void, timeout: number) { + let ready = true + return (...args: any[]) => { + if (!ready) { + return + } + + ready = false + func(...args) + setTimeout(() => { + ready = true + }, timeout) + } }