Skip to content

Commit

Permalink
fix(lint): auto-fix [ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
mzywang committed May 29, 2024
1 parent 13c6389 commit 1dfb743
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
10 changes: 6 additions & 4 deletions src/mappings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Pool as PoolTemplate } from '../types/templates'
import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../utils/token'
import { ADDRESS_ZERO, FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from './../utils/constants'
import { WHITELIST_TOKENS } from './../utils/pricing'
import { STATIC_TOKEN_DEFINITIONS, StaticTokenDefinition } from '../utils/staticTokenDefinition'

// The subgraph handler must have this signature to be able to handle events,
// however, we invoke a helper in order to inject dependencies for unit tests.
Expand All @@ -18,7 +19,8 @@ export function handlePoolCreated(event: PoolCreated): void {
export function handlePoolCreatedHelper(
event: PoolCreated,
factoryAddress: string = FACTORY_ADDRESS,
whitelistTokens: string[] = WHITELIST_TOKENS
whitelistTokens: string[] = WHITELIST_TOKENS,
staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS,
): void {
// temp fix
if (event.params.pool == Address.fromHexString('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248')) {
Expand Down Expand Up @@ -57,10 +59,10 @@ export function handlePoolCreatedHelper(
// fetch info if null
if (token0 === null) {
token0 = new Token(event.params.token0.toHexString())
token0.symbol = fetchTokenSymbol(event.params.token0)
token0.name = fetchTokenName(event.params.token0)
token0.symbol = fetchTokenSymbol(event.params.token0, staticTokenDefinitions)
token0.name = fetchTokenName(event.params.token0, staticTokenDefinitions)
token0.totalSupply = fetchTokenTotalSupply(event.params.token0)
const decimals = fetchTokenDecimals(event.params.token0)
const decimals = fetchTokenDecimals(event.params.token0, staticTokenDefinitions)

// bail if we couldn't figure out the decimals
if (decimals === null) {
Expand Down
4 changes: 2 additions & 2 deletions tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const createTestPool = (
token1: TokenFixture,
poolAddressHexString: string,
feeTier: number,
tickSpacing: number
tickSpacing: number,
): void => {
const mockEvent = newMockEvent()
const token0Address = Address.fromString(token0.address)
Expand All @@ -64,7 +64,7 @@ export const createTestPool = (
mockEvent.block,
mockEvent.transaction,
parameters,
mockEvent.receipt
mockEvent.receipt,
)
// create mock contract calls for token0
createMockedFunction(token0Address, 'symbol', 'symbol():(string)').returns([ethereum.Value.fromString(token0.symbol)])
Expand Down
34 changes: 17 additions & 17 deletions tests/handlePoolCreated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
POOL_TICK_SPACING_03,
USDC_MAINNET_FIXTURE,
USDC_WETH_03_MAINNET_POOL,
WETH_MAINNET_FIXTURE
WETH_MAINNET_FIXTURE,
} from './constants'

describe('handlePoolCreated', () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('handlePoolCreated', () => {
['totalValueLockedETH', '0'],
['totalValueLockedUSD', '0'],
['totalValueLockedETHUntracked', '0'],
['totalValueLockedUSDUntracked', '0']
['totalValueLockedUSDUntracked', '0'],
])

assertObjectMatches('Bundle', '1', [['ethPriceUSD', '0']])
Expand All @@ -64,7 +64,7 @@ describe('handlePoolCreated', () => {
['totalValueLockedUSDUntracked', '0'],
['txCount', '0'],
['poolCount', '0'],
['whitelistPools', `[${USDC_WETH_03_MAINNET_POOL}]`]
['whitelistPools', `[${USDC_WETH_03_MAINNET_POOL}]`],
])

assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [
Expand All @@ -82,7 +82,7 @@ describe('handlePoolCreated', () => {
['totalValueLockedUSDUntracked', '0'],
['txCount', '0'],
['poolCount', '0'],
['whitelistPools', `[${USDC_WETH_03_MAINNET_POOL}]`]
['whitelistPools', `[${USDC_WETH_03_MAINNET_POOL}]`],
])

assertObjectMatches('Pool', USDC_WETH_03_MAINNET_POOL, [
Expand All @@ -109,7 +109,7 @@ describe('handlePoolCreated', () => {
['untrackedVolumeUSD', '0'],
['collectedFeesToken0', '0'],
['collectedFeesToken1', '0'],
['collectedFeesUSD', '0']
['collectedFeesUSD', '0'],
])
})

Expand All @@ -125,7 +125,7 @@ describe('handlePoolCreated', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'symbol', 'symbol():(string)').reverts()
createMockedFunction(usdcAddress, 'symbol', 'symbol():(bytes32)').returns([
ethereum.Value.fromBytes(Bytes.fromUTF8('USDC'))
ethereum.Value.fromBytes(Bytes.fromUTF8('USDC')),
])
const symbol = fetchTokenSymbol(usdcAddress)
assert.stringEquals(symbol, 'USDC')
Expand All @@ -135,15 +135,15 @@ describe('handlePoolCreated', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'symbol', 'symbol():(string)').reverts()
createMockedFunction(usdcAddress, 'symbol', 'symbol():(bytes32)').returns([
ethereum.Value.fromBytes(Bytes.fromHexString(NULL_ETH_HEX_STRING))
ethereum.Value.fromBytes(Bytes.fromHexString(NULL_ETH_HEX_STRING)),
])
const staticDefinitions: Array<StaticTokenDefinition> = [
{
address: Address.fromString(USDC_MAINNET_FIXTURE.address),
symbol: 'USDC',
name: 'USD Coin',
decimals: BigInt.fromI32(6)
}
decimals: BigInt.fromI32(6),
},
]
const symbol = fetchTokenSymbol(usdcAddress, staticDefinitions)
assert.stringEquals(symbol, 'USDC')
Expand All @@ -170,7 +170,7 @@ describe('handlePoolCreated', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'name', 'name():(string)').reverts()
createMockedFunction(usdcAddress, 'name', 'name():(bytes32)').returns([
ethereum.Value.fromBytes(Bytes.fromUTF8('USD Coin'))
ethereum.Value.fromBytes(Bytes.fromUTF8('USD Coin')),
])
const name = fetchTokenName(usdcAddress)
assert.stringEquals(name, 'USD Coin')
Expand All @@ -180,15 +180,15 @@ describe('handlePoolCreated', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'name', 'name():(string)').reverts()
createMockedFunction(usdcAddress, 'name', 'name():(bytes32)').returns([
ethereum.Value.fromBytes(Bytes.fromHexString(NULL_ETH_HEX_STRING))
ethereum.Value.fromBytes(Bytes.fromHexString(NULL_ETH_HEX_STRING)),
])
const staticDefinitions: Array<StaticTokenDefinition> = [
{
address: Address.fromString(USDC_MAINNET_FIXTURE.address),
symbol: 'USDC',
name: 'USD Coin',
decimals: BigInt.fromI32(6)
}
decimals: BigInt.fromI32(6),
},
]
const name = fetchTokenName(usdcAddress, staticDefinitions)
assert.stringEquals(name, 'USD Coin')
Expand All @@ -207,7 +207,7 @@ describe('handlePoolCreated', () => {
test('success - fetch token total supply', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'totalSupply', 'totalSupply():(uint256)').returns([
ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300'))
ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300')),
])
const totalSupply = fetchTokenTotalSupply(usdcAddress)
assert.bigIntEquals(totalSupply, BigInt.fromString('300'))
Expand All @@ -225,7 +225,7 @@ describe('handlePoolCreated', () => {
test('success - fetch token decimals', () => {
const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address)
createMockedFunction(usdcAddress, 'decimals', 'decimals():(uint32)').returns([
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(6))
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(6)),
])
const decimals = fetchTokenDecimals(usdcAddress)
assert.assertTrue(decimals == BigInt.fromI32(6))
Expand All @@ -239,8 +239,8 @@ describe('handlePoolCreated', () => {
address: Address.fromString(USDC_MAINNET_FIXTURE.address),
symbol: 'USDC',
name: 'USD Coin',
decimals: BigInt.fromI32(6)
}
decimals: BigInt.fromI32(6),
},
]
const decimals = fetchTokenDecimals(usdcAddress, staticDefinitions)
assert.assertTrue(decimals == BigInt.fromI32(6))
Expand Down

0 comments on commit 1dfb743

Please sign in to comment.