Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wcc lsk chain #3

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:
- merge_group

jobs:
unit:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install
- name: Unit Tests
run: pnpm test:unit
# No unit tests available
# unit:
# runs-on: ubuntu-latest
# continue-on-error: true
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/actions/install
# - name: Unit Tests
# run: pnpm test:unit
myz1237 marked this conversation as resolved.
Show resolved Hide resolved

integration:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Config } from 'jest'
import { pathsToModuleNameMapper } from 'ts-jest'
import { compilerOptions } from './tsconfig.base.json'

const config: Config = {
preset: 'ts-jest',
Expand All @@ -19,6 +21,9 @@ const config: Config = {
statements: 43,
},
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/src',
}),
}

export default config
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"packageManager": "[email protected]",
"dependencies": {
"@lifi/types": "^15.16.1",
"@lifi/types": "^16.5.0",
"@types/memoizee": "^0.4.11",
"axios": "^1.7.7",
"ethers": "^6.13.3",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type LifiError = { message: string; code: number }
export const LifiError = ({
type LifiError = { message: string; code: number }
export const getLifiError = ({
message,
myz1237 marked this conversation as resolved.
Show resolved Hide resolved
code,
}: {
Expand All @@ -9,5 +9,7 @@ export const LifiError = ({
message,
code,
})
export const isLifiError = (err: any): err is LifiError =>
'code' in err && 'message' in err
export const getErrorMessage = (err: any) =>
'message' in err ? String(err.message) : 'Unknown error'
19 changes: 7 additions & 12 deletions src/tenderly/tenderly.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainId, ErrorCode } from '@lifi/types'

import { HttpResponse, http } from '@tenderlysim/http'
import { logger } from '@tenderlysim/logger'
import { LifiError, getErrorMessage } from '@tenderlysim/common'
import { getLifiError, getErrorMessage, isLifiError } from '@tenderlysim/common'

import {
TENDERLY_BASE_URL,
Expand Down Expand Up @@ -105,22 +105,18 @@ const validateTransactionDetailsResponse = (
response: HttpResponse<TenderlyTransactionResponse>
) => {
if (response.status === 401) {
const unauthorizedError = LifiError({
throw getLifiError({
message: 'Get transaction information call is Unauthorized',
code: ErrorCode.UnauthorizedError,
})

return unauthorizedError
}

if (response.status == 404) {
return LifiError({
throw getLifiError({
message: 'The tx was not found by Tenderly',
code: ErrorCode.NotFoundError,
})
}

return response
}

export const getTransactionDetails =
Expand All @@ -130,7 +126,7 @@ export const getTransactionDetails =
chainId: ChainId
): Promise<TenderlyTransactionResponse> => {
if (!TENDERLY_CHAINS.includes(chainId)) {
throw LifiError({
throw getLifiError({
message: 'The requested tx chain is not supported by Tenderly',
code: ErrorCode.NotProcessableError,
})
Expand All @@ -142,9 +138,7 @@ export const getTransactionDetails =
{ headers: TENDERLY_REQUEST_HEADERS(tenderlyConfig.accessKey) }
)

const validatedResponse = validateTransactionDetailsResponse(response)

if (validatedResponse instanceof LifiError) throw validatedResponse
validateTransactionDetailsResponse(response)

return response.data
} catch (error) {
Expand All @@ -153,7 +147,8 @@ export const getTransactionDetails =
error
)}`
)
throw LifiError({
if (isLifiError(error)) throw error
throw getLifiError({
message: 'The getTransactionDetails call failed',
code: ErrorCode.ThirdPartyError,
})
Expand Down
4 changes: 2 additions & 2 deletions src/tenderly/tenderly.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const TENDERLY_CHAINS: number[] = [
// Gold - 4653
ChainId.IMX, // Immutable - 13371
// Kinto - 7887
// Lisk - 1135
ChainId.MOD, // Mode - 34443
ChainId.OPT, // Optimistic Ethereum - 10
ChainId.POL, // Polygon - 137
Expand All @@ -40,7 +39,6 @@ export const TENDERLY_CHAINS: number[] = [
// Soneium Minato - 1946
ChainId.TAI, // Taiko Mainnet - 167000
// Unreal - 18233
// World Chain - 480
ChainId.AVA, // Avalanche C-Chain - 43114
ChainId.BSC, // BNB - 56
ChainId.FTM, // Fantom - 250
Expand All @@ -51,6 +49,8 @@ export const TENDERLY_CHAINS: number[] = [
ChainId.MOO, // Moonbeam - 1284
ChainId.MOR, // Moonriver - 1285
ChainId.RSK, // RSK - 30
ChainId.WCC, // WorldChain - 480
ChainId.LSK, // Lisk - 1135
// Sei Pacific-1 - 1329
// ZetaChain - 7000
// Zora - 7777777
Expand Down
45 changes: 22 additions & 23 deletions src/tenderly/tenderly.int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ import { ChainId } from '@lifi/types'

import { getTransactionDetails } from './tenderly.api'

beforeAll(() => {
jest.mock('@tenderlysim/http', () => {
return {
http: () => ({
get: (url: string) => {
if (
url.includes(
'0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0'
)
) {
return { data: { error_message: 'execution error' } }
} else if (
url.includes(
'0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d41d0'
)
) {
return { code: 404 }
}
},
}),
}
})
jest.mock('@tenderlysim/http', () => {
return {
http: () => ({
get: (url: string) => {
if (
url.includes(
'0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0'
)
) {
return { data: { error_message: 'execution error' } }
} else if (
url.includes(
'0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d41d0'
)
) {
return { status: 404 }
}
},
}),
}
})

describe('Tenderly', () => {
Expand All @@ -37,11 +35,12 @@ describe('Tenderly', () => {
expect(result.error_message).toEqual('execution error')
})

const unRealChainId = 99999
const failedRequestCases = [
{
value: {
hash: '0x9d6f5e6009d65f65493244b82682b7210648d1dad10ecece2f81c01e951d4ed0',
chain: ChainId.AUR,
chain: unRealChainId,
},
expected: 'The requested tx chain is not supported by Tenderly',
},
Expand Down
8 changes: 4 additions & 4 deletions src/tenderly/tenderly.overwrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from 'ethers'
import memoizee from 'memoizee'

import { logger } from '@tenderlysim/logger'
import { LifiError } from '@tenderlysim/common'
import { getLifiError } from '@tenderlysim/common'

import {
encodeContractStates,
Expand Down Expand Up @@ -67,7 +67,7 @@ const getApprovalMapping = (
},
`Unknown approval mapping for token ${tokenImplementationAddress}`
)
throw LifiError({
throw getLifiError({
message: `Unable to find matching mapping in knownAllowanceMappings.`,
code: ErrorCode.NotProcessableError,
})
Expand Down Expand Up @@ -105,7 +105,7 @@ const getBalanceMapping = (
},
`Unknown balance mapping for token ${tokenImplementationAddress}`
)
throw LifiError({
throw getLifiError({
message: `Unable to find matching mapping in knownBalanceMappings.`,
code: ErrorCode.NotProcessableError,
})
Expand Down Expand Up @@ -143,7 +143,7 @@ export const getTokenOverwrite =
tokenImplementationAddress
)
if (contractStates === undefined) {
throw LifiError({
throw getLifiError({
message: `Unable to find contract states.`,
code: ErrorCode.ThirdPartyError,
})
Expand Down
18 changes: 9 additions & 9 deletions src/tenderly/tenderly.simulate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChainId, ErrorCode, TransactionRequest } from '@lifi/types'

import { LifiError } from '@tenderlysim/common'
import { getLifiError } from '@tenderlysim/common'
import { logger } from '@tenderlysim/logger'

import { simulateTransaction } from './tenderly.api'
Expand All @@ -18,42 +18,42 @@ const validateTransactionRequest = (
transactionRequest?: TransactionRequest
) => {
if (transactionRequest === undefined)
throw LifiError({
throw getLifiError({
message: `No transaction request passed`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.from === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing from`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.to === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing to`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.chainId === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing chainId`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.data === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing data`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.gasPrice === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing gasPrice`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.gasLimit === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing gasLimit`,
code: ErrorCode.MalformedSchema,
})
if (transactionRequest.value === undefined)
throw LifiError({
throw getLifiError({
message: `transactionRequest is missing value`,
code: ErrorCode.MalformedSchema,
})
Expand Down
Loading