Skip to content

Commit

Permalink
chore(mux): consume viem tx types for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Aug 20, 2024
1 parent 939fd62 commit ef0306e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .changeset/thirty-knives-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rabbitholegg/questdk": patch
"@rabbitholegg/questdk-plugin-mux": patch
---

allow for more general transaction typing, fix mux tests
18 changes: 9 additions & 9 deletions apps/questdk/src/filter/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
import {
type AbiFunction,
type Address,
type TransactionEIP1559,
decodeAbiParameters,
decodeFunctionData,
getAbiItem,
Expand All @@ -22,6 +21,7 @@ import {
AbiParameter,
ByteArray,
Hex,
Transaction,
} from 'viem'
type OperatorKey = keyof typeof operators

Expand All @@ -32,7 +32,7 @@ type OperatorKey = keyof typeof operators
* @returns True if all filters pass, false otherwise.
*/
export const handleAnd = (
context: TransactionEIP1559 | Record<string, unknown>,
context: Transaction | Record<string, unknown>,
filter: Filter[],
): boolean => {
for (let i = 0; i < filter.length; i++) {
Expand All @@ -50,7 +50,7 @@ export const handleAnd = (
* @returns True if any filter passes, false otherwise.
*/
export const handleOr = (
context: TransactionEIP1559 | Record<string, unknown>,
context: Transaction | Record<string, unknown>,
filter: Filter[],
): boolean => {
for (let i = 0; i < filter.length; i++) {
Expand All @@ -68,7 +68,7 @@ export const handleOr = (
* @returns True if any filter passes, false otherwise.
*/
export const handleSome = (
context: Array<TransactionEIP1559 | Record<string, unknown>>,
context: Array<Transaction | Record<string, unknown>>,
filter: TransactionFilter | FilterObject,
): boolean => {
for (let i = 0; i < context.length; i++) {
Expand Down Expand Up @@ -150,7 +150,7 @@ export const handleGreaterThanOrEqual = (
* @returns The result of applying the filter.
*/
export const handleFirst = (
context: Array<TransactionEIP1559 | Record<string, unknown>>,
context: Array<Transaction | Record<string, unknown>>,
filter: TransactionFilter | FilterObject,
): boolean => {
return apply(context[0], filter)
Expand All @@ -163,7 +163,7 @@ export const handleFirst = (
* @returns The result of applying the filter.
*/
export const handleLast = (
context: Array<TransactionEIP1559 | Record<string, unknown>>,
context: Array<Transaction | Record<string, unknown>>,
filter: TransactionFilter | FilterObject,
): boolean => {
return apply(context[context.length - 1], filter)
Expand All @@ -176,7 +176,7 @@ export const handleLast = (
* @returns True if the value at the nth index meets the condition, false otherwise.
*/
export const handleNth = (
context: Array<TransactionEIP1559 | Record<string, unknown>>,
context: Array<Transaction | Record<string, unknown>>,
filter: NthFilter,
): boolean => {
const { index, value } = filter
Expand Down Expand Up @@ -361,10 +361,10 @@ const operators = {
* @returns True if all filters pass, false otherwise.
*/
export function apply(
originalContext: TransactionEIP1559 | Record<string, unknown>,
originalContext: Transaction | Record<any, unknown>,
filters: TransactionFilter | FilterObject,
): boolean {
let context: TransactionEIP1559 | Record<string, unknown> = originalContext
let context: Transaction | Record<string, unknown> = originalContext
if (typeof filters === 'object') {
if ('$abi' in filters) {
const processedContext = handleAbiDecode(context, filters as AbiFilter)
Expand Down
20 changes: 10 additions & 10 deletions packages/mux/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const MUX_ETH_MARKET_LONG: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0x4786055f865c301c46d64de5c9b124ec1a97ef1efc1bcbd1030a0100000000000000000000000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000009fbd82c3c72240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065c6b238',
value: '1000000000000000',
value: BigInt('1000000000000000'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -30,7 +30,7 @@ const MUX_ARB_LIMIT_LONG: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0x4786055f865c301c46d64de5c9b124ec1a97ef1efc1bcbd10a0301000000000000000000000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000775f05a07400000000000000000000000000000000000000000000000008b7b8c4ba968140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000065c6b5eb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065c6b5eb',
value: '0',
value: BigInt(0),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -49,7 +49,7 @@ const MUX_DAI_MARKET_SHORT: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0x4786055f865c301c46d64de5c9b124ec1a97ef1efc1bcbd10203000000000000000000000000000000000000000000000000000000000000000000004a1b7db51c960000000000000000000000000000000000000000000000000000009f295cd5f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000065c6b8c3',
value: '0',
value: BigInt('0'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -68,7 +68,7 @@ const GMX_V1_MARKET_ETH_LONG: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0x92644c39000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000fa1c6d5030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000071afd498d000000000000000000000000000000000000000000000000003846bd518406d0300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000',
value: '4580000000000001',
value: BigInt('4580000000000001'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -87,7 +87,7 @@ const GMX_V2_MARKET_USDCE_LONG: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0x92644c39000000000000000000000000000000000000000000000000000000000000000100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000000a7d8c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c34a9fdf9acb000000000000000000000000000000000000000000000005dea4fd6ddfdc32a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000',
value: '180000000000000',
value: BigInt('180000000000000'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -107,7 +107,7 @@ const GMX_V2_LIMIT_WBTC_LONG: TestParams<OptionsActionParams> = {
hash: '0x9fb4a0394ff01c7a5ed180272970b50fddee509baced24d6667fb8e944a6790b',
input:
'0x92644c3900000000000000000000000000000000000000000000000000000000000000010000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f0000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000095989200000000000000000000000000000000000000000000bad652a98addfdcc8c8c00000000000000000000000000000000000000000000098758b21e60d35800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000',
value: '180000000000000',
value: BigInt('180000000000000'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -126,7 +126,7 @@ const GMX_V2_MULTICALL_USDCE_MARKET: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000c4606c70120000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee63360000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc800000000000000000000000000000000000000000000000000000000026232f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4b8444d820000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000005543df729c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003242393236300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000000000000000000000000000000000000000000016d757870726f746f636f6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e45102a7080000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000026232f000000000000000000000000000000000000000000000000000000000025c18d400000000000000000000000000000000000000000000000000000000011d4393000000000000000000000000000000000000b858710425e477bbdf0c7a7dd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093d5b805587e50000000000000000000000000000000000000000000000000005543df729c000000000000000000000000000000000000000000000000000000000000007a12000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000042ff970a61a04b1ca14834a43f5de4533ebddb5cc80001f42f2a2543b76a4166549f7aab2e75bef0aefc5b0f000bb8af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
value: '1500000000000000',
value: BigInt('1500000000000000'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -144,7 +144,7 @@ const GMX_V2_MULTICALL_USDCE_LIMIT: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000c4606c70120000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee63360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ff970a61a04b1ca14834a43f5de4533ebddb5cc80000000000000000000000000000000000000000000000000000000001312d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4b8444d820000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005543df729c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003042393236300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000000000000000000000000000000000000000000006d757870726f746f636f6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c45102a708000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000001312d0000000000000000000000000000000000000000000000000000000000012e1fc0000000000000000000000000000000000000000000000000000000000021327f0000000000000000000000000000000000001573731da25af9d52ebf3c43e800000000000000000000000000000000000000000000000000000940f5fa3f180000000000000000000000000000000000000000000000000000092945701062000000000000000000000000000000000000000000000000000005543df729c000000000000000000000000000000000000000000000000000000000000007a1200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000002bff970a61a04b1ca14834a43f5de4533ebddb5cc8000064af88d065e77c8cc2239327c5edb3a432268e58310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
value: '1500000000000000',
value: BigInt('1500000000000000'),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -162,7 +162,7 @@ const GNS_MARKET_LONG: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0xfb4b71bb000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0b6ccf4be560000000000000000000000000000000000000000000000000000000017c2b31879e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000960000000000000000000000000000000000000000000000000000192d156281c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002540be40000000000000000000000000010c2cbfe29f4f5e4c24d54d36c8f283a61eb0c2f',
value: '0',
value: BigInt(0),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand All @@ -181,7 +181,7 @@ const GNS_LIMIT_SHORT: TestParams<OptionsActionParams> = {
from: '0x865c301c46d64de5c9b124ec1a97ef1efc1bcbd1',
input:
'0xfb4b71bb000000000000000000000000865c301c46d64de5c9b124ec1a97ef1efc1bcbd1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c0b6ccf4be560000000000000000000000000000000000000000000000000000000017c1895250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000001654a4ec18000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000002540be40000000000000000000000000010c2cbfe29f4f5e4c24d54d36c8f283a61eb0c2f',
value: '0',
value: BigInt(0),
},
params: {
chainId: Chains.ARBITRUM_ONE,
Expand Down
15 changes: 3 additions & 12 deletions packages/mux/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ActionParams } from '@rabbitholegg/questdk'
import { type Address, type Hash } from 'viem'
import { TransactionEIP1559, type Address } from 'viem'

export enum Chains {
ETHEREUM = 1,
Expand All @@ -17,23 +17,14 @@ export enum Chains {
SCROLL = 534352,
}

interface Transaction {
chainId: number
from: Address
hash?: Hash
input: string
to: Address
value: string
}

export interface TestCase<T extends ActionParams> {
transaction: Transaction
transaction: Partial<TransactionEIP1559>
params: T
description: string
}

export type TestParams<T extends ActionParams> = {
transaction: Transaction
transaction: Partial<TransactionEIP1559>
params: T
}

Expand Down

0 comments on commit ef0306e

Please sign in to comment.