-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
480 additions
and
68 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# copied from https://github.com/LimeChain/demo-subgraph/blob/main/Dockerfile | ||
|
||
FROM --platform=linux/x86_64 ubuntu:22.04 | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
ENV ARGS="" | ||
|
||
RUN apt update \ | ||
&& apt install -y sudo curl postgresql postgresql-contrib | ||
|
||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - \ | ||
&& sudo apt-get install -y nodejs | ||
|
||
RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/0.6.0/binary-linux-22 \ | ||
&& chmod a+x binary-linux-22 | ||
|
||
RUN mkdir matchstick | ||
WORKDIR /matchstick | ||
|
||
CMD ../binary-linux-22 ${ARGS} |
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
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
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
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,69 +1,66 @@ | ||
import { Address, BigInt } from '@graphprotocol/graph-ts' | ||
import { Address, BigInt, log } from '@graphprotocol/graph-ts' | ||
|
||
// Initialize a Token Definition with the attributes | ||
export class StaticTokenDefinition { | ||
address: Address | ||
symbol: string | ||
name: string | ||
decimals: BigInt | ||
} | ||
|
||
// Get all tokens with a static defintion | ||
static getStaticDefinitions(): Array<StaticTokenDefinition> { | ||
const staticDefinitions: Array<StaticTokenDefinition> = [ | ||
{ | ||
address: Address.fromString('0xe0b7927c4af23765cb51314a0e0521a9645f0e2a'), | ||
symbol: 'DGD', | ||
name: 'DGD', | ||
decimals: BigInt.fromI32(9), | ||
}, | ||
{ | ||
address: Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'), | ||
symbol: 'AAVE', | ||
name: 'Aave Token', | ||
decimals: BigInt.fromI32(18), | ||
}, | ||
{ | ||
address: Address.fromString('0xeb9951021698b42e4399f9cbb6267aa35f82d59d'), | ||
symbol: 'LIF', | ||
name: 'Lif', | ||
decimals: BigInt.fromI32(18), | ||
}, | ||
{ | ||
address: Address.fromString('0xbdeb4b83251fb146687fa19d1c660f99411eefe3'), | ||
symbol: 'SVD', | ||
name: 'savedroid', | ||
decimals: BigInt.fromI32(18), | ||
}, | ||
{ | ||
address: Address.fromString('0xbb9bc244d798123fde783fcc1c72d3bb8c189413'), | ||
symbol: 'TheDAO', | ||
name: 'TheDAO', | ||
decimals: BigInt.fromI32(16), | ||
}, | ||
{ | ||
address: Address.fromString('0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2'), | ||
symbol: 'HPB', | ||
name: 'HPBCoin', | ||
decimals: BigInt.fromI32(18), | ||
}, | ||
] | ||
return staticDefinitions | ||
} | ||
|
||
// Helper for hardcoded tokens | ||
static fromAddress(tokenAddress: Address): StaticTokenDefinition | null { | ||
const staticDefinitions = this.getStaticDefinitions() | ||
const tokenAddressHex = tokenAddress.toHexString() | ||
export const getStaticDefinition = ( | ||
tokenAddress: Address, | ||
staticDefinitions: Array<StaticTokenDefinition> | ||
): StaticTokenDefinition | null => { | ||
const tokenAddressHex = tokenAddress.toHexString() | ||
|
||
// Search the definition using the address | ||
for (let i = 0; i < staticDefinitions.length; i++) { | ||
const staticDefinition = staticDefinitions[i] | ||
if (staticDefinition.address.toHexString() == tokenAddressHex) { | ||
return staticDefinition | ||
} | ||
// Search the definition using the address | ||
for (let i = 0; i < staticDefinitions.length; i++) { | ||
const staticDefinition = staticDefinitions[i] | ||
if (staticDefinition.address.toHexString() == tokenAddressHex) { | ||
return staticDefinition | ||
} | ||
|
||
// If not found, return null | ||
return null | ||
} | ||
|
||
// If not found, return null | ||
return null | ||
} | ||
|
||
export const STATIC_TOKEN_DEFINITIONS: Array<StaticTokenDefinition> = [ | ||
{ | ||
address: Address.fromString('0xe0b7927c4af23765cb51314a0e0521a9645f0e2a'), | ||
symbol: 'DGD', | ||
name: 'DGD', | ||
decimals: BigInt.fromI32(9) | ||
}, | ||
{ | ||
address: Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'), | ||
symbol: 'AAVE', | ||
name: 'Aave Token', | ||
decimals: BigInt.fromI32(18) | ||
}, | ||
{ | ||
address: Address.fromString('0xeb9951021698b42e4399f9cbb6267aa35f82d59d'), | ||
symbol: 'LIF', | ||
name: 'Lif', | ||
decimals: BigInt.fromI32(18) | ||
}, | ||
{ | ||
address: Address.fromString('0xbdeb4b83251fb146687fa19d1c660f99411eefe3'), | ||
symbol: 'SVD', | ||
name: 'savedroid', | ||
decimals: BigInt.fromI32(18) | ||
}, | ||
{ | ||
address: Address.fromString('0xbb9bc244d798123fde783fcc1c72d3bb8c189413'), | ||
symbol: 'TheDAO', | ||
name: 'TheDAO', | ||
decimals: BigInt.fromI32(16) | ||
}, | ||
{ | ||
address: Address.fromString('0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2'), | ||
symbol: 'HPB', | ||
name: 'HPBCoin', | ||
decimals: BigInt.fromI32(18) | ||
} | ||
] |
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts' | ||
import { assert, createMockedFunction, newMockEvent } from 'matchstick-as' | ||
import { PoolCreated } from '../src/types/Factory/Factory' | ||
import { handlePoolCreatedHelper } from '../src/mappings/factory' | ||
import { Factory } from '../src/types/schema' | ||
import { FACTORY_ADDRESS } from '../src/utils/constants' | ||
|
||
const USDC_MAINNET_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' | ||
const WETH_MAINNET_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' | ||
export const USDC_WETH_03_MAINNET_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8' | ||
export const POOL_FEE_TIER_03 = 3000 | ||
export const POOL_TICK_SPACING_03 = 60 | ||
|
||
export class TokenFixture { | ||
address: string | ||
symbol: string | ||
name: string | ||
totalSupply: string | ||
decimals: string | ||
} | ||
|
||
export const USDC_MAINNET_FIXTURE: TokenFixture = { | ||
address: USDC_MAINNET_ADDRESS, | ||
symbol: 'USDC', | ||
name: 'USD Coin', | ||
totalSupply: '300', | ||
decimals: '6' | ||
} | ||
|
||
export const WETH_MAINNET_FIXTURE: TokenFixture = { | ||
address: WETH_MAINNET_ADDRESS, | ||
symbol: 'WETH', | ||
name: 'Wrapped Ether', | ||
totalSupply: '100', | ||
decimals: '18' | ||
} | ||
|
||
export const MOCK_EVENT = newMockEvent() | ||
|
||
export const createTestPool = ( | ||
mockEvent: ethereum.Event, | ||
factoryAddress: string, | ||
token0: TokenFixture, | ||
token1: TokenFixture, | ||
poolAddressHexString: string, | ||
feeTier: number, | ||
tickSpacing: number | ||
): void => { | ||
const mockEvent = newMockEvent() | ||
const token0Address = Address.fromString(token0.address) | ||
const token1Address = Address.fromString(token1.address) | ||
const poolAddress = Address.fromString(poolAddressHexString) | ||
const parameters = [ | ||
new ethereum.EventParam('token0', ethereum.Value.fromAddress(token0Address)), | ||
new ethereum.EventParam('token1', ethereum.Value.fromAddress(token1Address)), | ||
new ethereum.EventParam('fee', ethereum.Value.fromI32(feeTier as i32)), | ||
new ethereum.EventParam('tickSpacing', ethereum.Value.fromI32(tickSpacing as i32)), | ||
new ethereum.EventParam('pool', ethereum.Value.fromAddress(poolAddress)) | ||
] | ||
const poolCreatedEvent = new PoolCreated( | ||
mockEvent.address, | ||
mockEvent.logIndex, | ||
mockEvent.transactionLogIndex, | ||
mockEvent.logType, | ||
mockEvent.block, | ||
mockEvent.transaction, | ||
parameters, | ||
mockEvent.receipt | ||
) | ||
// create mock contract calls for token0 | ||
createMockedFunction(token0Address, 'symbol', 'symbol():(string)').returns([ethereum.Value.fromString(token0.symbol)]) | ||
createMockedFunction(token0Address, 'name', 'name():(string)').returns([ethereum.Value.fromString(token0.name)]) | ||
createMockedFunction(token0Address, 'totalSupply', 'totalSupply():(uint256)').returns([ | ||
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(token0.totalSupply)) | ||
]) | ||
createMockedFunction(token0Address, 'decimals', 'decimals():(uint32)').returns([ | ||
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(token0.decimals)) | ||
]) | ||
// create mock contract calls for token1 | ||
createMockedFunction(token1Address, 'symbol', 'symbol():(string)').returns([ethereum.Value.fromString(token1.symbol)]) | ||
createMockedFunction(token1Address, 'name', 'name():(string)').returns([ethereum.Value.fromString(token1.name)]) | ||
createMockedFunction(token1Address, 'totalSupply', 'totalSupply():(uint256)').returns([ | ||
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(token1.totalSupply)) | ||
]) | ||
createMockedFunction(token1Address, 'decimals', 'decimals():(uint32)').returns([ | ||
ethereum.Value.fromUnsignedBigInt(BigInt.fromString(token1.decimals)) | ||
]) | ||
handlePoolCreatedHelper(poolCreatedEvent, factoryAddress, [token0.address, token1.address]) | ||
} | ||
|
||
// Typescript for Subgraphs do not support Record types so we use a 2D string array to represent the object instead. | ||
export const assertObjectMatches = (entityType: string, id: string, obj: string[][]): void => { | ||
for (let i = 0; i < obj.length; i++) { | ||
assert.fieldEquals(entityType, id, obj[i][0], obj[i][1]) | ||
} | ||
} |
Oops, something went wrong.