|
| 1 | +import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter' |
| 2 | +import { describe, expect, test } from 'vitest' |
| 3 | +import { bridge } from './Synapse.js' |
| 4 | +import { |
| 5 | + DEPOSIT_ETH, |
| 6 | + WITHDRAW_ERC20, |
| 7 | + WITHDRAW_ETH, |
| 8 | + DEPOSIT_ERC20, |
| 9 | + DEPOSIT_CCTP, |
| 10 | + WITHDRAW_CCTP |
| 11 | + |
| 12 | +} from './test-transactions.js' |
| 13 | +import { |
| 14 | + ARBITRUM_CHAIN_ID, |
| 15 | + ETH_CHAIN_ID, |
| 16 | + BSC_CHAIN_ID |
| 17 | +} from './chain-ids.js' |
| 18 | +import { SYNAPSE_BRIDGE_FRAGMENTS } from './abi.js' |
| 19 | +import { parseEther } from 'viem' |
| 20 | +import { SynapseCCTPContract, getContractAddress, CHAIN_TO_ROUTER } from './contract-addresses' |
| 21 | + |
| 22 | + |
| 23 | +const ARBITRUM_USDCE_ADDRESS = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' |
| 24 | +const ARBITRUM_USDC_ADDRESS = '0xaf88d065e77c8cc2239327c5edb3a432268e5831' |
| 25 | +const ETHEREUM_USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' |
| 26 | + |
| 27 | +// A random Ethereum Address |
| 28 | +const TEST_USER = '0xF57D86F6bFcc76AA2C7f62616B2436C60Ad397e2' |
| 29 | + |
| 30 | + |
| 31 | +describe('When given the Synapse plugin', () => { |
| 32 | + describe('When generating the filter', () => { |
| 33 | + |
| 34 | + test('Should return a valid bridge action filter for L2 token tx', async () => { |
| 35 | + const filter = await bridge({ |
| 36 | + sourceChainId: ARBITRUM_CHAIN_ID, |
| 37 | + destinationChainId: ETH_CHAIN_ID, |
| 38 | + tokenAddress: ARBITRUM_USDCE_ADDRESS, |
| 39 | + amount: GreaterThanOrEqual(100000n), |
| 40 | + recipient: TEST_USER |
| 41 | + }) |
| 42 | + |
| 43 | + expect(filter).to.deep.equal({ |
| 44 | + chainId: ARBITRUM_CHAIN_ID, |
| 45 | + to: CHAIN_TO_ROUTER[ARBITRUM_CHAIN_ID], |
| 46 | + input: { |
| 47 | + $abi: SYNAPSE_BRIDGE_FRAGMENTS, |
| 48 | + to: TEST_USER, |
| 49 | + amount: { |
| 50 | + $gte: '100000' |
| 51 | + }, |
| 52 | + chainId: ETH_CHAIN_ID, |
| 53 | + token: ARBITRUM_USDCE_ADDRESS, |
| 54 | + }, |
| 55 | + }) |
| 56 | + }) |
| 57 | + test('Should return a valid transaction for a L1 -> L2 transaction (Non CCTP)'), async () => { |
| 58 | + const filter = await bridge({ |
| 59 | + sourceChainId: ETH_CHAIN_ID, |
| 60 | + destinationChainId: ARBITRUM_CHAIN_ID, |
| 61 | + tokenAddress: ETHEREUM_USDC_ADDRESS, |
| 62 | + amount: GreaterThanOrEqual(100000n), |
| 63 | + recipient: TEST_USER |
| 64 | + }) |
| 65 | + |
| 66 | + expect(filter).to.deep.equal({ |
| 67 | + chainId: ETH_CHAIN_ID, |
| 68 | + to: CHAIN_TO_ROUTER[ETH_CHAIN_ID], |
| 69 | + input: { |
| 70 | + $abi: SYNAPSE_BRIDGE_FRAGMENTS, |
| 71 | + to: TEST_USER, |
| 72 | + amount: { |
| 73 | + $gte: '100000' |
| 74 | + }, |
| 75 | + chainId: ARBITRUM_CHAIN_ID, |
| 76 | + token: ETHEREUM_USDC_ADDRESS, |
| 77 | + }, |
| 78 | + }) |
| 79 | + } |
| 80 | + test('Should return a valid transaction for a L2 -> L1 transaction (Non CCTP)'), async () => { |
| 81 | + const filter = await bridge({ |
| 82 | + sourceChainId: ARBITRUM_CHAIN_ID, |
| 83 | + destinationChainId: ETH_CHAIN_ID, |
| 84 | + tokenAddress: ARBITRUM_USDCE_ADDRESS, |
| 85 | + amount: GreaterThanOrEqual(100000n), |
| 86 | + recipient: TEST_USER |
| 87 | + }) |
| 88 | + |
| 89 | + expect(filter).to.deep.equal({ |
| 90 | + chainId: ARBITRUM_CHAIN_ID, |
| 91 | + to: CHAIN_TO_ROUTER[ARBITRUM_CHAIN_ID], |
| 92 | + input: { |
| 93 | + $abi: SYNAPSE_BRIDGE_FRAGMENTS, |
| 94 | + to: TEST_USER, |
| 95 | + amount: { |
| 96 | + $gte: '100000' |
| 97 | + }, |
| 98 | + chainId: ETH_CHAIN_ID, |
| 99 | + token: ARBITRUM_USDCE_ADDRESS, |
| 100 | + }, |
| 101 | + }) |
| 102 | + } |
| 103 | + // CCTP Transactions |
| 104 | + test('Should return a valid transaction for a L1 -> L2 transaction (CCTP)'), async () => { |
| 105 | + const filter = await bridge({ |
| 106 | + sourceChainId: ETH_CHAIN_ID, |
| 107 | + destinationChainId: ARBITRUM_CHAIN_ID, |
| 108 | + tokenAddress: ETHEREUM_USDC_ADDRESS, |
| 109 | + amount: GreaterThanOrEqual(100000n), |
| 110 | + recipient: TEST_USER, |
| 111 | + contractAddress: getContractAddress(ETH_CHAIN_ID), |
| 112 | + }) |
| 113 | + |
| 114 | + expect(filter).to.deep.equal({ |
| 115 | + chainId: ETH_CHAIN_ID, |
| 116 | + // Update |
| 117 | + to: SynapseCCTPContract[ETH_CHAIN_ID], |
| 118 | + input: { |
| 119 | + $abi: SYNAPSE_BRIDGE_FRAGMENTS, |
| 120 | + //Update |
| 121 | + sender: TEST_USER, |
| 122 | + amount: { |
| 123 | + $gte: '100000' |
| 124 | + }, |
| 125 | + chainId: ARBITRUM_CHAIN_ID, |
| 126 | + token: ETHEREUM_USDC_ADDRESS, |
| 127 | + }, |
| 128 | + }) |
| 129 | + } |
| 130 | + test('Should return a valid transaction for a L2 -> L1 transaction (CCTP)'), async () => { |
| 131 | + const filter = await bridge({ |
| 132 | + sourceChainId: ARBITRUM_CHAIN_ID, |
| 133 | + destinationChainId: ETH_CHAIN_ID, |
| 134 | + tokenAddress: ARBITRUM_USDC_ADDRESS, |
| 135 | + amount: GreaterThanOrEqual(100000n), |
| 136 | + recipient: TEST_USER, |
| 137 | + contractAddress: getContractAddress(ETH_CHAIN_ID), |
| 138 | + }) |
| 139 | + |
| 140 | + expect(filter).to.deep.equal({ |
| 141 | + chainId: ARBITRUM_CHAIN_ID, |
| 142 | + to: SynapseCCTPContract[ARBITRUM_CHAIN_ID], |
| 143 | + input: { |
| 144 | + $abi: SYNAPSE_BRIDGE_FRAGMENTS, |
| 145 | + sender: TEST_USER, |
| 146 | + amount: { |
| 147 | + $gte: '100000' |
| 148 | + }, |
| 149 | + chainId: ETH_CHAIN_ID, |
| 150 | + token: ARBITRUM_USDC_ADDRESS, |
| 151 | + }, |
| 152 | + }) |
| 153 | + } |
| 154 | + |
| 155 | + describe('When applying the filter', () => { |
| 156 | + test('should pass filter with valid L1 ETH tx', async () => { |
| 157 | + const transaction = DEPOSIT_ETH |
| 158 | + const filter = await bridge({ |
| 159 | + sourceChainId: ETH_CHAIN_ID, |
| 160 | + destinationChainId: ARBITRUM_CHAIN_ID, |
| 161 | + tokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', |
| 162 | + amount: GreaterThanOrEqual(parseEther('.2')), |
| 163 | + }) |
| 164 | + expect(apply(transaction, filter)).to.be.true |
| 165 | + }) |
| 166 | + test('should pass filter with valid L2 ETH tx', async () => { |
| 167 | + const transaction = WITHDRAW_ETH |
| 168 | + const filter = await bridge({ |
| 169 | + sourceChainId: ARBITRUM_CHAIN_ID, |
| 170 | + destinationChainId: ETH_CHAIN_ID, |
| 171 | + tokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', |
| 172 | + amount: GreaterThanOrEqual(parseEther('.259')), |
| 173 | + |
| 174 | + }) |
| 175 | + expect(apply(transaction, filter)).to.be.true |
| 176 | + }) |
| 177 | + test('should pass filter with valid L1 Token tx', async () => { |
| 178 | + const transaction = DEPOSIT_ERC20 |
| 179 | + const filter = await bridge({ |
| 180 | + sourceChainId: ETH_CHAIN_ID, |
| 181 | + destinationChainId: BSC_CHAIN_ID, |
| 182 | + tokenAddress: ETHEREUM_USDC_ADDRESS, |
| 183 | + amount: GreaterThanOrEqual('9'), |
| 184 | + }) |
| 185 | + expect(apply(transaction, filter)).to.be.true |
| 186 | + }) |
| 187 | + test('should pass filter with valid L2 token tx', async () => { |
| 188 | + const transaction = WITHDRAW_ERC20 |
| 189 | + const filter = await bridge({ |
| 190 | + sourceChainId: ARBITRUM_CHAIN_ID , |
| 191 | + destinationChainId: ETH_CHAIN_ID, |
| 192 | + tokenAddress: ARBITRUM_USDCE_ADDRESS , |
| 193 | + amount: GreaterThanOrEqual('4006'), |
| 194 | + }) |
| 195 | + expect(apply(transaction, filter)).to.be.true |
| 196 | + }) |
| 197 | + // These are going to fail ? Im not sure how the contract address thing works. |
| 198 | + test('should pass filter with valid CCTP Deposit tx', async () => { |
| 199 | + const transaction = DEPOSIT_CCTP |
| 200 | + const filter = await bridge({ |
| 201 | + sourceChainId: ETH_CHAIN_ID , |
| 202 | + destinationChainId: ARBITRUM_CHAIN_ID, |
| 203 | + tokenAddress: ETHEREUM_USDC_ADDRESS , |
| 204 | + amount: GreaterThanOrEqual('299'), |
| 205 | + contractAddress: '0xd359bc471554504f683fbd4f6e36848612349ddf', |
| 206 | + }) |
| 207 | + expect(apply(transaction, filter)).to.be.true |
| 208 | + }) |
| 209 | + test('should pass filter with valid CCTP Withdraw tx', async () => { |
| 210 | + const transaction = WITHDRAW_CCTP |
| 211 | + const filter = await bridge({ |
| 212 | + sourceChainId: ARBITRUM_CHAIN_ID , |
| 213 | + destinationChainId: ETH_CHAIN_ID, |
| 214 | + tokenAddress: ARBITRUM_USDC_ADDRESS , |
| 215 | + amount: GreaterThanOrEqual('94'), |
| 216 | + contractAddress: '0xd359bc471554504f683fbd4f6e36848612349ddf', |
| 217 | + }) |
| 218 | + expect(apply(transaction, filter)).to.be.true |
| 219 | + }) |
| 220 | + }) |
| 221 | + }) |
| 222 | +}) |
0 commit comments