Skip to content

Commit

Permalink
Merge pull request #440 from rabbitholegg/mmackz/across-depositv3
Browse files Browse the repository at this point in the history
feat(across): add support for depositV3
  • Loading branch information
mmackz authored Jun 11, 2024
2 parents ee7ebcb + ca79640 commit d219a9e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-laws-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-across": minor
---

add support for depositV3
2 changes: 1 addition & 1 deletion packages/across/src/Across.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
failingTestCases,
passingTestCases,
} from './test-transactions'
import { Chains } from '@rabbitholegg/questdk-plugin-utils'
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk'
import { Chains } from '@rabbitholegg/questdk-plugin-utils'
import { parseEther } from 'viem'
import { describe, expect, test } from 'vitest'

Expand Down
24 changes: 18 additions & 6 deletions packages/across/src/Across.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ACROSS_BRIDGE_ABI } from './abi'
import { ACROSS_BRIDGE_ABI, DEPOSIT_V3_ABI } from './abi'
import { CHAIN_ID_ARRAY } from './chain-ids'
import {
CHAIN_TO_SPOKEPOOL,
Expand Down Expand Up @@ -26,11 +26,23 @@ export const bridge = async (bridge: BridgeActionParams) => {
chainId: sourceChainId,
to: bridgeContract,
input: {
$abi: ACROSS_BRIDGE_ABI,
recipient: recipient,
destinationChainId: destinationChainId,
amount: amount,
originToken: tokenIn,
$or: [
{
$abi: ACROSS_BRIDGE_ABI,
recipient: recipient,
destinationChainId: destinationChainId,
amount: amount,
originToken: tokenIn,
},
{
$abi: DEPOSIT_V3_ABI,
depositor: recipient,
recipient: recipient,
inputToken: tokenIn,
inputAmount: amount,
destinationChainId: destinationChainId,
},
],
},
})
}
Expand Down
23 changes: 23 additions & 0 deletions packages/across/src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ export const ACROSS_BRIDGE_ABI = [
type: 'function',
},
]

export const DEPOSIT_V3_ABI = [
{
inputs: [
{ internalType: 'address', name: 'depositor', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
{ internalType: 'address', name: 'inputToken', type: 'address' },
{ internalType: 'address', name: 'outputToken', type: 'address' },
{ internalType: 'uint256', name: 'inputAmount', type: 'uint256' },
{ internalType: 'uint256', name: 'outputAmount', type: 'uint256' },
{ internalType: 'uint256', name: 'destinationChainId', type: 'uint256' },
{ internalType: 'address', name: 'exclusiveRelayer', type: 'address' },
{ internalType: 'uint32', name: 'quoteTimestamp', type: 'uint32' },
{ internalType: 'uint32', name: 'fillDeadline', type: 'uint32' },
{ internalType: 'uint32', name: 'exclusivityDeadline', type: 'uint32' },
{ internalType: 'bytes', name: 'message', type: 'bytes' },
],
name: 'depositV3',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
]
46 changes: 43 additions & 3 deletions packages/across/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,56 @@ const BRIDGE_ETH2: TestParams<BridgeActionParams> = {
params: {
sourceChainId: Chains.BASE,
destinationChainId: Chains.ARBITRUM_ONE,
// tokenAddress: zeroAddress,
// amount: GreaterThanOrEqual(parseEther('9')),
// recipient: '0xeb01d9ef642c54f42a36fd3a80b66f0fcb13e92a',
tokenAddress: zeroAddress,
amount: GreaterThanOrEqual(parseEther('0.005')),
recipient: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
},
}

const BRIDGE_ETH_V3: TestParams<BridgeActionParams> = {
transaction: {
chainId: 10,
from: '0xcf14cffb33955277ab408d420f82aefdf91be04e',
to: '0x6f26bf09b1c792e3228e5467807a900a503c0281',
hash: '0x5a76e1fe88402da77d409d5abf6ba00e26070f194f4cf877c409d16263b34099',
input:
'0x7b939232000000000000000000000000cf14cffb33955277ab408d420f82aefdf91be04e000000000000000000000000cf14cffb33955277ab408d420f82aefdf91be04e0000000000000000000000004200000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010a741a46278000000000000000000000000000000000000000000000000000010a69e3a087d2fd40000000000000000000000000000000000000000000000000000000000002105000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000666275cf000000000000000000000000000000000000000000000000000000006662c816000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000',
value: '1200000000000000000',
},
params: {
sourceChainId: Chains.OPTIMISM,
destinationChainId: Chains.BASE,
tokenAddress: zeroAddress,
amount: GreaterThanOrEqual(parseEther('1')),
recipient: '0xcf14cffb33955277ab408d420f82aefdf91be04e',
},
}

const BRIDGE_TOKENS_V3: TestParams<BridgeActionParams> = {
transaction: {
chainId: 10,
from: '0x9b02ad1c383bbbcc7cd181b6cd70b2dc8b7436db',
to: '0x6f26bf09b1c792e3228e5467807a900a503c0281',
hash: '0x5023a43b5117ecbc4b8fb4a42a5b576922c4d98d1779a4436a158c0b95797b11',
input:
'0x7b9392320000000000000000000000009b02ad1c383bbbcc7cd181b6cd70b2dc8b7436db0000000000000000000000009b02ad1c383bbbcc7cd181b6cd70b2dc8b7436db0000000000000000000000000b2c639c533813f4aa9d7837caf62653d097ff85000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000324c740000000000000000000000000000000000000000000000000000000000324582c000000000000000000000000000000000000000000000000000000000000a4b100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000066625b53000000000000000000000000000000000000000000000000000000006662b08e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000',
value: '0',
},
params: {
sourceChainId: Chains.OPTIMISM,
destinationChainId: Chains.ARBITRUM_ONE,
tokenAddress: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', // USDC
amount: GreaterThanOrEqual(parseUnits('50', 6)),
recipient: '0x9b02ad1c383bbbcc7cd181b6cd70b2dc8b7436db',
},
}

export const passingTestCases = [
createTestCase(BRIDGE_ERC, 'when bridging ERC20 tokens'),
createTestCase(BRIDGE_ETH, 'when bridging ETH'),
createTestCase(BRIDGE_ETH2, 'when bridging ETH'),
createTestCase(BRIDGE_TOKENS_V3, 'when bridging tokens using depositV3'),
createTestCase(BRIDGE_ETH_V3, 'when bridging ETH using depositV3'),
createTestCase(BRIDGE_ERC, 'when amount is "any"', { amount: undefined }),
createTestCase(BRIDGE_ERC, 'when token is "any"', {
amount: undefined,
Expand Down

0 comments on commit d219a9e

Please sign in to comment.