-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add_paraswap_swap' of https://github.com/rabbitholegg/q…
…uestdk-plugins into add_paraswap_swap
- Loading branch information
Showing
19 changed files
with
2,133 additions
and
2,133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter' | ||
import { describe, expect, test } from 'vitest' | ||
import { SWAP_ETH, SWAP_TOKENS } from './test-transactions' | ||
import { CAMELOT_ROUTER } from './contract-addresses' | ||
import { ARBITRUM_CHAIN_ID } from './chain-ids' | ||
import { parseEther } from 'viem' | ||
import { swap } from './Camelot' | ||
import { CAMELOT_ABI } from './abi' | ||
describe('Given the camelot plugin', () => { | ||
describe('When handling the bridge', () => { | ||
test('should return a valid action filter', async () => { | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
contractAddress: CAMELOT_ROUTER, | ||
tokenOut: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C', | ||
amountOut: GreaterThanOrEqual(parseEther('0.0005')), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: 42161, | ||
to: '0xc873fEcbd354f5A56E00E710B90EF4201db2448d', | ||
input: { | ||
$abi: CAMELOT_ABI, | ||
path: { | ||
$and: [{ $last: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C' }], | ||
}, | ||
amountOutMin: { $gte: '500000000000000' }, | ||
}, | ||
}) | ||
}) | ||
test('should pass filter with valid ETH transactions', async () => { | ||
const transaction = SWAP_ETH | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
contractAddress: CAMELOT_ROUTER, | ||
tokenOut: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C', | ||
amountOut: GreaterThanOrEqual(parseEther('0.0005')), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
|
||
test('should not pass filter with valid tokens transactions', async () => { | ||
const transaction = SWAP_TOKENS | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
tokenIn: '0x5190F06EaceFA2C552dc6BD5e763b81C73293293', // WOMBEX | ||
tokenOut: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', // TETHER | ||
amountIn: GreaterThanOrEqual(parseEther('750')), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
}) | ||
}) | ||
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter' | ||
import { describe, expect, test } from 'vitest' | ||
import { SWAP_ETH, SWAP_TOKENS } from './test-transactions' | ||
import { CAMELOT_ROUTER } from './contract-addresses' | ||
import { ARBITRUM_CHAIN_ID } from './chain-ids' | ||
import { parseEther } from 'viem' | ||
import { swap } from './Camelot' | ||
import { CAMELOT_ABI } from './abi' | ||
describe('Given the camelot plugin', () => { | ||
describe('When handling the bridge', () => { | ||
test('should return a valid action filter', async () => { | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
contractAddress: CAMELOT_ROUTER, | ||
tokenOut: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C', | ||
amountOut: GreaterThanOrEqual(parseEther('0.0005')), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: 42161, | ||
to: '0xc873fEcbd354f5A56E00E710B90EF4201db2448d', | ||
input: { | ||
$abi: CAMELOT_ABI, | ||
path: { | ||
$and: [{ $last: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C' }], | ||
}, | ||
amountOutMin: { $gte: '500000000000000' }, | ||
}, | ||
}) | ||
}) | ||
test('should pass filter with valid ETH transactions', async () => { | ||
const transaction = SWAP_ETH | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
contractAddress: CAMELOT_ROUTER, | ||
tokenOut: '0xBfbCFe8873fE28Dfa25f1099282b088D52bbAD9C', | ||
amountOut: GreaterThanOrEqual(parseEther('0.0005')), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
|
||
test('should not pass filter with valid tokens transactions', async () => { | ||
const transaction = SWAP_TOKENS | ||
const filter = await swap({ | ||
chainId: ARBITRUM_CHAIN_ID, | ||
tokenIn: '0x5190F06EaceFA2C552dc6BD5e763b81C73293293', // WOMBEX | ||
tokenOut: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', // TETHER | ||
amountIn: GreaterThanOrEqual(parseEther('750')), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
import { | ||
type TransactionFilter, | ||
type SwapActionParams, | ||
compressJson, | ||
type FilterOperator, | ||
} from '@rabbitholegg/questdk' | ||
import { type Address } from 'viem' | ||
import { CHAIN_ID_ARRAY, ARBITRUM_CHAIN_ID } from './chain-ids' | ||
import { | ||
DEFAULT_TOKEN_LIST_URL, | ||
WETH_ADDRESS_ARBITRUM, | ||
} from './contract-addresses' | ||
import { CAMELOT_ABI } from './abi' | ||
import { CAMELOT_ROUTER } from './contract-addresses' | ||
|
||
export const buildPathQuery = (tokenIn?: string, tokenOut?: string) => { | ||
// v2 paths are formatted as [<token>, <token>] | ||
const conditions: FilterOperator[] = [] | ||
|
||
if (tokenIn) { | ||
conditions.push({ $first: tokenIn }) | ||
} | ||
|
||
if (tokenOut) { | ||
conditions.push({ $last: tokenOut }) | ||
} | ||
|
||
return { | ||
$and: conditions, | ||
} | ||
} | ||
|
||
export const swap = async ( | ||
swap: SwapActionParams, | ||
): Promise<TransactionFilter> => { | ||
const { chainId, contractAddress, tokenIn, tokenOut, amountOut, recipient } = | ||
swap | ||
const amountIn = tokenIn === WETH_ADDRESS_ARBITRUM ? swap.amountIn : undefined | ||
|
||
// We always want to return a compressed JSON object which we'll transform into a TransactionFilter | ||
return compressJson({ | ||
chainId: chainId, // The chainId of the source chain | ||
to: contractAddress || CAMELOT_ROUTER, // The contract address of the bridge | ||
input: { | ||
$abi: CAMELOT_ABI, // The ABI of the bridge | ||
to: recipient, // The recipient of the swap | ||
path: buildPathQuery(tokenIn, tokenOut), // The path of the swap | ||
amountOutMin: amountOut, // The minimum amount of tokens to receive | ||
amountIn: amountIn, // The amount of tokens to send | ||
}, // The input object is where we'll put the ABI and the parameters | ||
}) | ||
} | ||
|
||
export const getSupportedTokenAddresses = async ( | ||
_chainId: number, | ||
): Promise<Address[]> => { | ||
// Only return supported tokens for ARBITRUM_CHAIN_ID | ||
return _chainId === ARBITRUM_CHAIN_ID ? DEFAULT_TOKEN_LIST_URL : [] | ||
} | ||
|
||
export const getSupportedChainIds = async (): Promise<number[]> => { | ||
return CHAIN_ID_ARRAY | ||
} | ||
import { | ||
type TransactionFilter, | ||
type SwapActionParams, | ||
compressJson, | ||
type FilterOperator, | ||
} from '@rabbitholegg/questdk' | ||
import { type Address } from 'viem' | ||
import { CHAIN_ID_ARRAY, ARBITRUM_CHAIN_ID } from './chain-ids' | ||
import { | ||
DEFAULT_TOKEN_LIST_URL, | ||
WETH_ADDRESS_ARBITRUM, | ||
} from './contract-addresses' | ||
import { CAMELOT_ABI } from './abi' | ||
import { CAMELOT_ROUTER } from './contract-addresses' | ||
|
||
export const buildPathQuery = (tokenIn?: string, tokenOut?: string) => { | ||
// v2 paths are formatted as [<token>, <token>] | ||
const conditions: FilterOperator[] = [] | ||
|
||
if (tokenIn) { | ||
conditions.push({ $first: tokenIn }) | ||
} | ||
|
||
if (tokenOut) { | ||
conditions.push({ $last: tokenOut }) | ||
} | ||
|
||
return { | ||
$and: conditions, | ||
} | ||
} | ||
|
||
export const swap = async ( | ||
swap: SwapActionParams, | ||
): Promise<TransactionFilter> => { | ||
const { chainId, contractAddress, tokenIn, tokenOut, amountOut, recipient } = | ||
swap | ||
const amountIn = tokenIn === WETH_ADDRESS_ARBITRUM ? swap.amountIn : undefined | ||
|
||
// We always want to return a compressed JSON object which we'll transform into a TransactionFilter | ||
return compressJson({ | ||
chainId: chainId, // The chainId of the source chain | ||
to: contractAddress || CAMELOT_ROUTER, // The contract address of the bridge | ||
input: { | ||
$abi: CAMELOT_ABI, // The ABI of the bridge | ||
to: recipient, // The recipient of the swap | ||
path: buildPathQuery(tokenIn, tokenOut), // The path of the swap | ||
amountOutMin: amountOut, // The minimum amount of tokens to receive | ||
amountIn: amountIn, // The amount of tokens to send | ||
}, // The input object is where we'll put the ABI and the parameters | ||
}) | ||
} | ||
|
||
export const getSupportedTokenAddresses = async ( | ||
_chainId: number, | ||
): Promise<Address[]> => { | ||
// Only return supported tokens for ARBITRUM_CHAIN_ID | ||
return _chainId === ARBITRUM_CHAIN_ID ? DEFAULT_TOKEN_LIST_URL : [] | ||
} | ||
|
||
export const getSupportedChainIds = async (): Promise<number[]> => { | ||
return CHAIN_ID_ARRAY | ||
} |
Oops, something went wrong.