From 1a8e4009bd31e43d999b43d0902f7dd8c26eb1ab Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 11:59:08 -0700 Subject: [PATCH 1/8] custom recipietn address --- .../src/components/form/BridgeForm.svelte | 15 ++++++- .../bridge-ui/src/components/form/To.svelte | 40 +++++++++++++++++++ packages/bridge-ui/src/domain/bridge.ts | 1 + packages/bridge-ui/src/erc20/bridge.spec.ts | 2 + packages/bridge-ui/src/erc20/bridge.ts | 14 +++---- packages/bridge-ui/src/eth/bridge.ts | 14 +++---- 6 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 packages/bridge-ui/src/components/form/To.svelte diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index 4486b1d2ea1..d17df640c8d 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -25,7 +25,6 @@ import { pendingTransactions, transactions as transactionsStore, - transactioner, } from '../../store/transactions'; import { ProcessingFeeMethod } from '../../domain/fee'; import Memo from './Memo.svelte'; @@ -39,6 +38,7 @@ import { fetchFeeData } from '@wagmi/core'; import { providers } from '../../store/providers'; import { checkIfTokenIsDeployedCrossChain } from '../../utils/checkIfTokenIsDeployedCrossChain'; + import To from './To.svelte'; let amount: string; let amountInput: HTMLInputElement; @@ -51,6 +51,8 @@ let loading: boolean = false; let isFaucetModalOpen: boolean = false; let memoError: string; + let to: string = ''; + let showTo: boolean = false; $: getUserBalance($signer, $token, $fromChain); @@ -222,6 +224,11 @@ try { loading = true; if (requiresAllowance) throw Error('requires additional allowance'); + if (showTo) { + if (!ethers.utils.isAddress(to)) { + throw Error('Invalid custom recipient address'); + } + } const amountInWei = ethers.utils.parseUnits(amount, $token.decimals); @@ -238,7 +245,7 @@ $fromChain, ); - const bridgeOpts = { + const bridgeOpts: BridgeOpts = { amountInWei: amountInWei, signer: $signer, tokenAddress: await addrForToken(), @@ -248,6 +255,7 @@ processingFeeInWei: getProcessingFee(), memo: memo, isBridgedTokenAlreadyDeployed, + to: (showTo && to) ?? (await $signer.getAddress()), }; const doesUserHaveEnoughBalance = await checkUserHasEnoughBalance( @@ -324,6 +332,7 @@ tokenVaultAddress: $chainIdToTokenVaultAddress.get($fromChain.id), processingFeeInWei: getProcessingFee(), memo: memo, + to: showTo && to ? to : await $signer.getAddress(), }); const requiredGas = gasEstimate.mul(feeData.gasPrice); const userBalance = await $signer.getBalance('latest'); @@ -421,6 +430,8 @@ bind:isOpen={isFaucetModalOpen} /> {/if} + + diff --git a/packages/bridge-ui/src/components/form/To.svelte b/packages/bridge-ui/src/components/form/To.svelte new file mode 100644 index 00000000000..cefaef95765 --- /dev/null +++ b/packages/bridge-ui/src/components/form/To.svelte @@ -0,0 +1,40 @@ + + +
+ (tooltipOpen = true)}> + Memo + + + { + showTo = !showTo; + }} + bind:checked={showTo} /> +
+{#if showTo} + +{/if} + + + +

+ You can set a custom address as the recipient of your funds, instead of + your current wallet address. +

+
+
diff --git a/packages/bridge-ui/src/domain/bridge.ts b/packages/bridge-ui/src/domain/bridge.ts index b7b3798ea97..94e2d07bf72 100644 --- a/packages/bridge-ui/src/domain/bridge.ts +++ b/packages/bridge-ui/src/domain/bridge.ts @@ -26,6 +26,7 @@ type BridgeOpts = { tokenId?: string; memo?: string; isBridgedTokenAlreadyDeployed?: boolean; + to: string; }; type ClaimOpts = { diff --git a/packages/bridge-ui/src/erc20/bridge.spec.ts b/packages/bridge-ui/src/erc20/bridge.spec.ts index dfd79d301d3..9902a43c3b8 100644 --- a/packages/bridge-ui/src/erc20/bridge.spec.ts +++ b/packages/bridge-ui/src/erc20/bridge.spec.ts @@ -53,6 +53,7 @@ const opts: BridgeOpts = { tokenVaultAddress: '0x456', processingFeeInWei: BigNumber.from(2), memo: 'memo', + to: await wallet.getAddress(), }; const approveOpts: ApproveOpts = { @@ -228,6 +229,7 @@ describe('bridge tests', () => { fromChainId: mainnet.id, toChainId: taiko.id, tokenVaultAddress: '0x456', + to: await wallet.getAddress(), }; await bridge.Bridge(opts); diff --git a/packages/bridge-ui/src/erc20/bridge.ts b/packages/bridge-ui/src/erc20/bridge.ts index 0755fa9a6a1..ea786e81f06 100644 --- a/packages/bridge-ui/src/erc20/bridge.ts +++ b/packages/bridge-ui/src/erc20/bridge.ts @@ -34,7 +34,7 @@ class ERC20Bridge implements Bridge { srcChainId: opts.fromChainId, destChainId: opts.toChainId, owner: owner, - to: owner, + to: opts.to, refundAddress: owner, depositValue: opts.amountInWei, callValue: 0, @@ -108,13 +108,11 @@ class ERC20Bridge implements Bridge { throw Error('token vault does not have required allowance'); } - const { contract, owner, message } = await ERC20Bridge.prepareTransaction( - opts, - ); + const { contract, message } = await ERC20Bridge.prepareTransaction(opts); const tx = await contract.sendERC20( message.destChainId, - owner, + message.to, opts.tokenAddress, opts.amountInWei, message.gasLimit, @@ -130,13 +128,11 @@ class ERC20Bridge implements Bridge { } async EstimateGas(opts: BridgeOpts): Promise { - const { contract, owner, message } = await ERC20Bridge.prepareTransaction( - opts, - ); + const { contract, message } = await ERC20Bridge.prepareTransaction(opts); const gasEstimate = await contract.estimateGas.sendERC20( message.destChainId, - owner, + message.to, opts.tokenAddress, opts.amountInWei, message.gasLimit, diff --git a/packages/bridge-ui/src/eth/bridge.ts b/packages/bridge-ui/src/eth/bridge.ts index 936eceb4e9b..eb97a3d5e96 100644 --- a/packages/bridge-ui/src/eth/bridge.ts +++ b/packages/bridge-ui/src/eth/bridge.ts @@ -35,7 +35,7 @@ class ETHBridge implements BridgeInterface { srcChainId: opts.fromChainId, destChainId: opts.toChainId, owner: owner, - to: owner, + to: opts.to, refundAddress: owner, depositValue: opts.amountInWei, callValue: 0, @@ -59,13 +59,11 @@ class ETHBridge implements BridgeInterface { } async Bridge(opts: BridgeOpts): Promise { - const { contract, owner, message } = await ETHBridge.prepareTransaction( - opts, - ); + const { contract, message } = await ETHBridge.prepareTransaction(opts); const tx = await contract.sendEther( message.destChainId, - owner, + message.to, message.gasLimit, message.processingFee, message.refundAddress, @@ -81,13 +79,11 @@ class ETHBridge implements BridgeInterface { } async EstimateGas(opts: BridgeOpts): Promise { - const { contract, owner, message } = await ETHBridge.prepareTransaction( - opts, - ); + const { contract, message } = await ETHBridge.prepareTransaction(opts); const gasEstimate = await contract.estimateGas.sendEther( message.destChainId, - owner, + message.to, message.gasLimit, message.processingFee, message.refundAddress, From 79d5a8b37dda6c1b7a0b6919486d8bc2e4d7d793 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 12:03:09 -0700 Subject: [PATCH 2/8] input size --- packages/bridge-ui/src/components/form/To.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/components/form/To.svelte b/packages/bridge-ui/src/components/form/To.svelte index cefaef95765..09e455e56cd 100644 --- a/packages/bridge-ui/src/components/form/To.svelte +++ b/packages/bridge-ui/src/components/form/To.svelte @@ -8,9 +8,9 @@ let tooltipOpen: boolean = false; -
+
(tooltipOpen = true)}> - Memo + Custom Recipient From 9e2e3889cd35d419c1b2db13ff344cdbadad8e77 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 12:15:15 -0700 Subject: [PATCH 3/8] show --- packages/bridge-ui/src/components/form/BridgeForm.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index d17df640c8d..47883994ec5 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -255,7 +255,7 @@ processingFeeInWei: getProcessingFee(), memo: memo, isBridgedTokenAlreadyDeployed, - to: (showTo && to) ?? (await $signer.getAddress()), + to: showTo && to ? to : await $signer.getAddress(), }; const doesUserHaveEnoughBalance = await checkUserHasEnoughBalance( From 52b730f2c82d0075dac7cc0389abf33919d5cb6d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 12:35:48 -0700 Subject: [PATCH 4/8] test --- packages/bridge-ui/src/App.svelte | 15 ++++++++++++++- packages/bridge-ui/src/eth/bridge.spec.ts | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index b407342520f..aad260a8a4f 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -146,23 +146,37 @@ const apiTxs = await $relayerApi.GetAllByAddress(userAddress); + console.log(apiTxs); + const blockInfoMap = await $relayerApi.GetBlockInfo(); relayerBlockInfoMap.set(blockInfoMap); const txs = await $transactioner.GetAllByAddress(userAddress); + console.log(txs); // const hashToApiTxsMap = new Map(apiTxs.map((tx) => { // return [tx.hash, tx]; // })) + // const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => { + // if (apiTxs.find((apiTx) => apiTx.hash.toLowerCase() === tx.hash)) { + // return false; + // } + // return true; + // }); + const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => { const blockInfo = blockInfoMap.get(tx.fromChainId); + console.log('blockinfo', blockInfo.latestProcessedBlock); + console.log('blockNUmber', tx.receipt.blockNumber); if (blockInfo?.latestProcessedBlock >= tx.receipt.blockNumber) { return false; } return true; }); + console.log(updatedStorageTxs); + $transactioner.UpdateStorageByAddress(userAddress, updatedStorageTxs); transactions.set([...updatedStorageTxs, ...apiTxs]); @@ -170,7 +184,6 @@ const tokens = await $tokenService.GetTokens(userAddress); userTokens.set(tokens); } - return store; }); pendingTransactions.subscribe((store) => { diff --git a/packages/bridge-ui/src/eth/bridge.spec.ts b/packages/bridge-ui/src/eth/bridge.spec.ts index f1818229797..b0474a3f1d3 100644 --- a/packages/bridge-ui/src/eth/bridge.spec.ts +++ b/packages/bridge-ui/src/eth/bridge.spec.ts @@ -84,6 +84,7 @@ describe('bridge tests', () => { tokenVaultAddress: '0x456', processingFeeInWei: BigNumber.from(2), memo: 'memo', + to: await wallet.getAddress(), }; expect(mockSigner.getAddress).not.toHaveBeenCalled(); @@ -115,6 +116,7 @@ describe('bridge tests', () => { fromChainId: mainnet.id, toChainId: taiko.id, tokenVaultAddress: '0x456', + to: await wallet.getAddress(), }; await bridge.Bridge(opts); From b5c3aae948e52dfcbf6485dc09450f159cf56b3e Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 12:43:17 -0700 Subject: [PATCH 5/8] test --- packages/bridge-ui/src/erc20/bridge.spec.ts | 2 +- packages/bridge-ui/src/eth/bridge.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/erc20/bridge.spec.ts b/packages/bridge-ui/src/erc20/bridge.spec.ts index 9902a43c3b8..7e5f2aef5c1 100644 --- a/packages/bridge-ui/src/erc20/bridge.spec.ts +++ b/packages/bridge-ui/src/erc20/bridge.spec.ts @@ -53,7 +53,7 @@ const opts: BridgeOpts = { tokenVaultAddress: '0x456', processingFeeInWei: BigNumber.from(2), memo: 'memo', - to: await wallet.getAddress(), + to: '0x', }; const approveOpts: ApproveOpts = { diff --git a/packages/bridge-ui/src/eth/bridge.spec.ts b/packages/bridge-ui/src/eth/bridge.spec.ts index b0474a3f1d3..5be9866ead4 100644 --- a/packages/bridge-ui/src/eth/bridge.spec.ts +++ b/packages/bridge-ui/src/eth/bridge.spec.ts @@ -84,7 +84,7 @@ describe('bridge tests', () => { tokenVaultAddress: '0x456', processingFeeInWei: BigNumber.from(2), memo: 'memo', - to: await wallet.getAddress(), + to: '0x', }; expect(mockSigner.getAddress).not.toHaveBeenCalled(); @@ -116,7 +116,7 @@ describe('bridge tests', () => { fromChainId: mainnet.id, toChainId: taiko.id, tokenVaultAddress: '0x456', - to: await wallet.getAddress(), + to: '0x', }; await bridge.Bridge(opts); From 6592aed674331f23d0f55451031897beafdd5f7c Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 12:48:36 -0700 Subject: [PATCH 6/8] tests --- packages/bridge-ui/src/erc20/bridge.spec.ts | 2 +- packages/bridge-ui/src/eth/bridge.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/bridge-ui/src/erc20/bridge.spec.ts b/packages/bridge-ui/src/erc20/bridge.spec.ts index 7e5f2aef5c1..d430a096c37 100644 --- a/packages/bridge-ui/src/erc20/bridge.spec.ts +++ b/packages/bridge-ui/src/erc20/bridge.spec.ts @@ -199,7 +199,7 @@ describe('bridge tests', () => { expect(mockContract.sendERC20).toHaveBeenCalled(); expect(mockContract.sendERC20).toHaveBeenCalledWith( opts.toChainId, - '0xfake', + '0x', opts.tokenAddress, opts.amountInWei, BigNumber.from(2640000), diff --git a/packages/bridge-ui/src/eth/bridge.spec.ts b/packages/bridge-ui/src/eth/bridge.spec.ts index 5be9866ead4..0a2ec53b279 100644 --- a/packages/bridge-ui/src/eth/bridge.spec.ts +++ b/packages/bridge-ui/src/eth/bridge.spec.ts @@ -93,7 +93,7 @@ describe('bridge tests', () => { expect(mockSigner.getAddress).toHaveBeenCalled(); expect(mockContract.sendEther).toHaveBeenCalledWith( opts.toChainId, - wallet.getAddress(), + '0x', BigNumber.from(140000), opts.processingFeeInWei, wallet.getAddress(), @@ -116,7 +116,7 @@ describe('bridge tests', () => { fromChainId: mainnet.id, toChainId: taiko.id, tokenVaultAddress: '0x456', - to: '0x', + to: await wallet.getAddress(), }; await bridge.Bridge(opts); From 0b1925b7d2578938f182b797c6efb342549d4575 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 13 Mar 2023 18:54:29 -0700 Subject: [PATCH 7/8] address comments --- packages/bridge-ui/src/App.svelte | 5 ----- packages/bridge-ui/src/components/form/BridgeForm.svelte | 6 ++---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index aad260a8a4f..b9aaa6d47fb 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -153,7 +153,6 @@ const txs = await $transactioner.GetAllByAddress(userAddress); - console.log(txs); // const hashToApiTxsMap = new Map(apiTxs.map((tx) => { // return [tx.hash, tx]; // })) @@ -167,16 +166,12 @@ const updatedStorageTxs: BridgeTransaction[] = txs.filter((tx) => { const blockInfo = blockInfoMap.get(tx.fromChainId); - console.log('blockinfo', blockInfo.latestProcessedBlock); - console.log('blockNUmber', tx.receipt.blockNumber); if (blockInfo?.latestProcessedBlock >= tx.receipt.blockNumber) { return false; } return true; }); - console.log(updatedStorageTxs); - $transactioner.UpdateStorageByAddress(userAddress, updatedStorageTxs); transactions.set([...updatedStorageTxs, ...apiTxs]); diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index 47883994ec5..95363a3f924 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -224,10 +224,8 @@ try { loading = true; if (requiresAllowance) throw Error('requires additional allowance'); - if (showTo) { - if (!ethers.utils.isAddress(to)) { - throw Error('Invalid custom recipient address'); - } + if (showTo && !ethers.utils.isAddress(to)) { + throw Error('Invalid custom recipient address'); } const amountInWei = ethers.utils.parseUnits(amount, $token.decimals); From 8c918c250d7c976a596727f8f8bbcfeeca13dc9d Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:26:02 -0700 Subject: [PATCH 8/8] Update packages/bridge-ui/src/App.svelte Co-authored-by: shadab-taiko <108871478+shadab-taiko@users.noreply.github.com> --- packages/bridge-ui/src/App.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/bridge-ui/src/App.svelte b/packages/bridge-ui/src/App.svelte index b9aaa6d47fb..a16c1ed7d5b 100644 --- a/packages/bridge-ui/src/App.svelte +++ b/packages/bridge-ui/src/App.svelte @@ -146,7 +146,6 @@ const apiTxs = await $relayerApi.GetAllByAddress(userAddress); - console.log(apiTxs); const blockInfoMap = await $relayerApi.GetBlockInfo(); relayerBlockInfoMap.set(blockInfoMap);