diff --git a/packages/optimism/src/Optimism.test.ts b/packages/optimism/src/Optimism.test.ts index 52783a9bb..43e689c2b 100644 --- a/packages/optimism/src/Optimism.test.ts +++ b/packages/optimism/src/Optimism.test.ts @@ -1,127 +1,135 @@ import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter' import { describe, expect, test } from 'vitest' import { bridge } from './Optimism.js' -import { l1StandardBridgeABI, l2StandardBridgeABI, addresses } from '@eth-optimism/contracts-ts' -import {DEPOSIT_ETH, DEPOSIT_TETHER, WITHDRAW_ETH, WITHDRAW_USDC} from './test-transactions.js' -import { ETH_TOKEN_ADDRESS, USDC_TOKEN_ADDRESS, TETHER_TOKEN_ADDRESS } from './token-addresses' +import { + l1StandardBridgeABI, + l2StandardBridgeABI, + addresses, +} from '@eth-optimism/contracts-ts' +import { + DEPOSIT_ETH, + DEPOSIT_TETHER, + WITHDRAW_ETH, + WITHDRAW_USDC, +} from './test-transactions.js' +import { + ETH_TOKEN_ADDRESS, + USDC_TOKEN_ADDRESS, + TETHER_TOKEN_ADDRESS, +} from './token-addresses' import { parseEther } from 'viem' // Replace *project* with the name of the project describe('Given the optimism plugin', () => { describe('When generating the filter', () => { test('should return a valid bridge action filter for L2 token tx', async () => { + const filter = await bridge({ + sourceChainId: 10, + destinationChainId: 1, + tokenAddress: USDC_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(100000n), + }) - - const filter = await bridge({ - sourceChainId: 10, - destinationChainId: 1, - tokenAddress: USDC_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(100000n), - }) - - expect(filter).to.deep.equal({ - chainId: '0xa', - to: addresses.L2StandardBridge[420], - input: { - $abi: l2StandardBridgeABI, - _l2Token: USDC_TOKEN_ADDRESS, - _amount: { - $gte: '100000', - }, + expect(filter).to.deep.equal({ + chainId: '0xa', + to: addresses.L2StandardBridge[420], + input: { + $abi: l2StandardBridgeABI, + _l2Token: USDC_TOKEN_ADDRESS, + _amount: { + $gte: '100000', }, - }) + }, }) + }) - test('should return a valid bridge action filter for L1 token tx', async () => { - - const filter = await bridge({ - sourceChainId: 1, - destinationChainId: 10, - tokenAddress: USDC_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(100000n), - }) - - expect(filter).to.deep.equal({ - chainId: '0x1', - to: addresses.L1StandardBridge[1], - input: { - $abi: l1StandardBridgeABI, - _l1Token: USDC_TOKEN_ADDRESS, - _amount: { - $gte: '100000', - }, - }, - }) + test('should return a valid bridge action filter for L1 token tx', async () => { + const filter = await bridge({ + sourceChainId: 1, + destinationChainId: 10, + tokenAddress: USDC_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(100000n), }) - test('should return a valid bridge action filter for L1 ETH tx', async () => { - const filter = await bridge({ - sourceChainId: 1, - destinationChainId: 10, - tokenAddress: ETH_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(100000n), - }) - - expect(filter).to.deep.equal({ - chainId: '0x1', - to: addresses.L1StandardBridge[1], - value: { + expect(filter).to.deep.equal({ + chainId: '0x1', + to: addresses.L1StandardBridge[1], + input: { + $abi: l1StandardBridgeABI, + _l1Token: USDC_TOKEN_ADDRESS, + _amount: { $gte: '100000', }, - input: { - $abi: l1StandardBridgeABI, - }, - }) + }, }) }) - describe('When applying the filter', () => { - test('should pass filter with valid L1 ETH tx', async() => { - const transaction = DEPOSIT_ETH; - const filter = await bridge({ - sourceChainId: 1, - destinationChainId: 10, // Optimism - tokenAddress: ETH_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(parseEther('.2')), - }) - - expect(apply(transaction, filter)).to.be.true + test('should return a valid bridge action filter for L1 ETH tx', async () => { + const filter = await bridge({ + sourceChainId: 1, + destinationChainId: 10, + tokenAddress: ETH_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(100000n), + }) + + expect(filter).to.deep.equal({ + chainId: '0x1', + to: addresses.L1StandardBridge[1], + value: { + $gte: '100000', + }, + input: { + $abi: l1StandardBridgeABI, + }, + }) }) - test('should pass filter with valid L1 Token tx', async() => { - const transaction = DEPOSIT_TETHER; - const filter = await bridge({ - sourceChainId: 1, - destinationChainId: 10, // Optimism - tokenAddress: TETHER_TOKEN_ADDRESS, - amount: GreaterThanOrEqual('85000000'), - }) - - expect(apply(transaction, filter)).to.be.true + }) + describe('When applying the filter', () => { + test('should pass filter with valid L1 ETH tx', async () => { + const transaction = DEPOSIT_ETH + const filter = await bridge({ + sourceChainId: 1, + destinationChainId: 10, // Optimism + tokenAddress: ETH_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(parseEther('.2')), + }) + + expect(apply(transaction, filter)).to.be.true }) - test('should pass filter with valid L2 ETH tx', async() => { - const transaction = WITHDRAW_ETH; - const filter = await bridge({ - sourceChainId: 10, - destinationChainId: 1, // Optimism - tokenAddress: ETH_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(parseEther('37')), - }) - - expect(apply(transaction, filter)).to.be.true + test('should pass filter with valid L1 Token tx', async () => { + const transaction = DEPOSIT_TETHER + const filter = await bridge({ + sourceChainId: 1, + destinationChainId: 10, // Optimism + tokenAddress: TETHER_TOKEN_ADDRESS, + amount: GreaterThanOrEqual('85000000'), + }) + + expect(apply(transaction, filter)).to.be.true }) - test('should pass filter with valid L2 token tx', async() => { - const transaction = WITHDRAW_USDC; - const filter = await bridge({ - sourceChainId: 10, - destinationChainId: 1, // Optimism - tokenAddress: USDC_TOKEN_ADDRESS, - amount: GreaterThanOrEqual(10000000), - }) - - expect(apply(transaction, filter)).to.be.true + test('should pass filter with valid L2 ETH tx', async () => { + const transaction = WITHDRAW_ETH + const filter = await bridge({ + sourceChainId: 10, + destinationChainId: 1, // Optimism + tokenAddress: ETH_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(parseEther('37')), + }) + + expect(apply(transaction, filter)).to.be.true }) + test('should pass filter with valid L2 token tx', async () => { + const transaction = WITHDRAW_USDC + const filter = await bridge({ + sourceChainId: 10, + destinationChainId: 1, // Optimism + tokenAddress: USDC_TOKEN_ADDRESS, + amount: GreaterThanOrEqual(10000000), + }) + + expect(apply(transaction, filter)).to.be.true }) - + }) test('should not pass filter with invalid transactions', () => {}) }) diff --git a/packages/optimism/src/test-transactions.ts b/packages/optimism/src/test-transactions.ts index 1d61491bc..ddff47ccf 100644 --- a/packages/optimism/src/test-transactions.ts +++ b/packages/optimism/src/test-transactions.ts @@ -15,7 +15,8 @@ export const DEPOSIT_ETH = { to: '0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1', value: '0x030d98d59a960000', nonce: 0, - input: '0xb1a1a8820000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000', + input: + '0xb1a1a8820000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000', r: '0xee9a85ccbc4c4e1dfd7db1bd2a700070d7b9ad4e072d3fdcda2e898b8a65022d', s: '0x31b6f6dce0d9a805826a7ee18876585a1391f58f739a0a455c2814eb98ff4c92', v: 1, @@ -40,7 +41,8 @@ export const DEPOSIT_TETHER = { to: '0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1', value: '0x00', nonce: 104, - input: '0x58a997f6000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e5800000000000000000000000000000000000000000000000000000000055d4a800000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', + input: + '0x58a997f6000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e5800000000000000000000000000000000000000000000000000000000055d4a800000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', r: '0x98e7c7feeaa58524f23a229c0ddbe2256a3f05368975b65b5c9a8d14bdb49d6b', s: '0x7b6831b8c7fc790fb44882a2fca1603f227d3f401273abe5246c9ecec4085cf0', v: 0, @@ -65,7 +67,8 @@ export const WITHDRAW_ETH = { to: '0x4200000000000000000000000000000000000010', value: '0x020c29fee2ce810000', nonce: 668, - input: '0x32b7006d000000000000000000000000deaddeaddeaddeaddeaddeaddeaddeaddead00000000000000000000000000000000000000000000000000020c29fee2ce810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000', + input: + '0x32b7006d000000000000000000000000deaddeaddeaddeaddeaddeaddeaddeaddead00000000000000000000000000000000000000000000000000020c29fee2ce810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000', r: '0x1d3135f59614d962194b0f4b4e1e2b05ed2a16cd04d919f034a3a07e90d6fbb5', s: '0x7f49b4b6dac351ff45e59c39f87ced493581331af269623ca7962cddc940688f', v: 1, @@ -90,7 +93,8 @@ export const WITHDRAW_USDC = { to: '0x4200000000000000000000000000000000000010', value: '0x00', nonce: 4, - input: '0x32b7006d0000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c3160700000000000000000000000000000000000000000000000000000000009b7f52000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000', + input: + '0x32b7006d0000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c3160700000000000000000000000000000000000000000000000000000000009b7f52000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000', r: '0x999adbe51288f0677585d8b18df1ef95fa470cf661c9e22916f0c4f07d6be755', s: '0x177e4b8a577bba056ac2ee8f84f1fe87a0f78ae4aedac92c3eb26be5d9e22657', v: 0, diff --git a/packages/optimism/src/token-addresses.ts b/packages/optimism/src/token-addresses.ts index ad328ee58..c9da70ded 100644 --- a/packages/optimism/src/token-addresses.ts +++ b/packages/optimism/src/token-addresses.ts @@ -1,4 +1,3 @@ -export const ETH_TOKEN_ADDRESS = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'; -export const USDC_TOKEN_ADDRESS = '0x7F5c764cBc14f9669B88837ca1490cCa17c31607'; -export const TETHER_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; - +export const ETH_TOKEN_ADDRESS = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000' +export const USDC_TOKEN_ADDRESS = '0x7F5c764cBc14f9669B88837ca1490cCa17c31607' +export const TETHER_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'