
How to get Uniswap V3 liquidity pool address for whitelisting?
Similar to what we did for Uniswap V2 on how to find address of smart contract pool that will be generated we can do the same for V3 https://mirror.xyz/n00b21337.eth/0QkNt3NnLnnUSy4jFmWnaeRr_38Z3wlYKKf1O6URG3c Depending on what chain we are at, you can find all the addresses of Factories here https://github.com/Uniswap/sdk-core/blob/5365ae4cd021ab53b94b0879ec6ceb6ad3ebdce9/src/addresses.ts#L135 Aim for the v3CoreFactoryAddress values.**So there are a few methods to do that, one could be to us...
Example of implementation of EIP 4906 metadata updates
EIP 4096 has an interesting method of updating your metadata with events, more details here. https://eips.ethereum.org/EIPS/eip-4906 So lets see how to implement it with an example. First you need to create a file with interface that has this code in itpragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /// @title EIP-721 Metadata Update Extension interface IERC4906 is IERC165 { /// @dev This event emits when the metadata of a token is changed. /// Third-...
Transaction Bytecode vs Deployed Bytecode, differences and how to read them
Main difference between deployed bytecode or runtime bytecode and bytecode that is shown in deployed transaction is that later has initial code in it and its bigger in size. So what is initial(init) code?A smart contract's constructor is a one-time function not stored on the blockchain but present in the initial code. When creating a contract, users can also send native currency. It's vital to ensure the contract can accept this currency at deployment. If it can't, the creation...
R4Nd0m k0lLEC7I0N 0F U5EFul PHindiN92 0N mY j0URney PhR0m n00b 2 1337. rAmBL1N92 aBoUt 5Ol1d17y, rE4C7, nf7, dEfi, WE83

How to get Uniswap V3 liquidity pool address for whitelisting?
Similar to what we did for Uniswap V2 on how to find address of smart contract pool that will be generated we can do the same for V3 https://mirror.xyz/n00b21337.eth/0QkNt3NnLnnUSy4jFmWnaeRr_38Z3wlYKKf1O6URG3c Depending on what chain we are at, you can find all the addresses of Factories here https://github.com/Uniswap/sdk-core/blob/5365ae4cd021ab53b94b0879ec6ceb6ad3ebdce9/src/addresses.ts#L135 Aim for the v3CoreFactoryAddress values.**So there are a few methods to do that, one could be to us...
Example of implementation of EIP 4906 metadata updates
EIP 4096 has an interesting method of updating your metadata with events, more details here. https://eips.ethereum.org/EIPS/eip-4906 So lets see how to implement it with an example. First you need to create a file with interface that has this code in itpragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /// @title EIP-721 Metadata Update Extension interface IERC4906 is IERC165 { /// @dev This event emits when the metadata of a token is changed. /// Third-...
Transaction Bytecode vs Deployed Bytecode, differences and how to read them
Main difference between deployed bytecode or runtime bytecode and bytecode that is shown in deployed transaction is that later has initial code in it and its bigger in size. So what is initial(init) code?A smart contract's constructor is a one-time function not stored on the blockchain but present in the initial code. When creating a contract, users can also send native currency. It's vital to ensure the contract can accept this currency at deployment. If it can't, the creation...
R4Nd0m k0lLEC7I0N 0F U5EFul PHindiN92 0N mY j0URney PhR0m n00b 2 1337. rAmBL1N92 aBoUt 5Ol1d17y, rE4C7, nf7, dEfi, WE83

Subscribe to N00b21337

Subscribe to N00b21337
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers


First login to the graph site with your github account, then go to Dashboard on the link here https://thegraph.com/explorer/dashboard and there you will have big button that says Add Subraph, click on it and fill the info needed to add subgraph.
After you add your boilerplate you will be provided with 3 additional step that you need to do.
so first install graph-cli locally with npm install -g @graphprotocol/graph-cli
Next you need to initialize your subgraph as this is probably your first time it is best to do that from example made by subgraph team so for the part where it says
graph init --from-example <GITHUB_USER>/<SUBGRAPH NAME> <DIRECTORY> we will run
graph init --from-example davekaj/example-subgraph
to copy from example and on next prompt add your subgraph name and local directory where it will go. This will install example code from Gravatar that is also used here in this video <https://www.youtube.com/watch?v=coa0Vw47qNc>
What you need to do after all this is to change your code to match the project you want to use, this is most difficult part.
First you need to add abi for your project into /abis directory, so for example add Ren.json into that directory and add ABI you can find here on etherscan https://etherscan.io/address/0x408e41876cccdc0f92210600ef50372656052a38… just find your contract there and copy/paste ABI
Go into subgraph.yaml and change description and name under dataSources, address and abi under source, enteties, abis and eventHandlers under mapping. For me and REN contract it looks like this
specVersion: 0.0.2
description: Ren for Ethereum
repository: https://github.com/graphprotocol/example-subgraph
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Ren
network: mainnet
source:
address: '0x408e41876cCCDC0F92210600ef50372656052a38'
abi: Ren
startBlock: 4827494
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- User
- UserCounter
- TransferCounter
- TotalSupply
abis:
- name: Ren
file: ./abis/Ren.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
file: ./src/mapping.ts
So with this I changed subgraph yaml, what I need to change next is schema.graphql which needs to reflect info and enteties what you want to save to graph and consume later. So here we add entities that will be constructed or updated on our events.
How are we going to do all of this? We are going to borrow things a bit, as this is contract of ERC20 token and this are Standard ERC events, we will find some other ERC20 tokens and use their graph code to quickly solve our needs. So lets go to the https://github.com/centrehq/usdc-subgraph/blob/master/subgraph.yaml and use entities and eventHandlers that they use in their yaml. If you want more entities and events you can also check https://github.com/daostack/subgraph/blob/master/src/mappings/DAOToken/… and fetch those or find some other. Also best would be to code your own and not just copy but for learning purposes and first step, this is fine.
So we got subgraph yaml file ready but we need to setup our entites, so we can use it from this repo and set https://github.com/centrehq/usdc-subgraph/blob/master/schema.graphql so you will have this in your schema.graphql when you leave out mint and mintCounter as entities
type User @entity {
id: ID!
address: String!
balance: BigInt!
transactionCount: Int!
}
type UserCounter @entity {
id: ID!
count: Int!
}
type TransferCounter @entity {
id: ID!
count: Int!
totalTransferred: BigInt!
}
type TotalSupply @entity {
id: ID!
supply: BigInt!
minted: BigInt!
burned: BigInt!
}
The last part we need to do is mappings, this will be a little harder as we cant just copy paste mappings from other subgraphs as they have their specific code https://github.com/centrehq/usdc-subgraph/blob/master/src/mapping.ts
First thing we need to do is run graph codegen in terminal. This will generate an AssemblyScript class for every smart contract in the ABI files mentioned in subgraph.yaml, allowing you to bind these contracts to specific addresses in the mappings and call read-only contract methods against the block being processed. It will also generate a class for every contract event to provide easy access to event parameters as well as the block and transaction the event originated from. All of these types are written to <OUTPUT_DIR>/<DATA_SOURCE_NAME>/<ABI_NAME>.ts
So unless we provide output dir it will be in default dir which is called "generated". In our example before it is not generated folder but types folder and then from there methods used in events are imported. So for our example we want to change those paths so we will change it to below
To have more knowledge on how to fill and manipulate data in your entities and mappings check the video from this specifi point https://youtu.be/e5OwjDao3MA?t=1556
With that we can finally run again yarn codegen and deploy the code to subgraph, we will do this with this line. 4.1 First set the token with graph auth https://api.thegraph.com/deploy/ token is written on top of your dashboard. 4.2 Then you need to run this command to deploy the graph graph deploy -- debug \ - node https://api.thegraph.com/deploy/ \ - ipfs https://api.thegraph.com/ipfs/ \ <github / subgraph_name> which will be like below when proper parametars are added. graph deploy --debug --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ adriadrop/ren-project If last line passes all the checks subgraph will be created and it will start to index data, if not you will get bunch of errors, probably some mappings will be wrong, maybe event wili miss some parameters or similar. For info how to debug this errors check here https://thegraph.com/docs/assemblyscript-api#logging-and-debugging
First login to the graph site with your github account, then go to Dashboard on the link here https://thegraph.com/explorer/dashboard and there you will have big button that says Add Subraph, click on it and fill the info needed to add subgraph.
After you add your boilerplate you will be provided with 3 additional step that you need to do.
so first install graph-cli locally with npm install -g @graphprotocol/graph-cli
Next you need to initialize your subgraph as this is probably your first time it is best to do that from example made by subgraph team so for the part where it says
graph init --from-example <GITHUB_USER>/<SUBGRAPH NAME> <DIRECTORY> we will run
graph init --from-example davekaj/example-subgraph
to copy from example and on next prompt add your subgraph name and local directory where it will go. This will install example code from Gravatar that is also used here in this video <https://www.youtube.com/watch?v=coa0Vw47qNc>
What you need to do after all this is to change your code to match the project you want to use, this is most difficult part.
First you need to add abi for your project into /abis directory, so for example add Ren.json into that directory and add ABI you can find here on etherscan https://etherscan.io/address/0x408e41876cccdc0f92210600ef50372656052a38… just find your contract there and copy/paste ABI
Go into subgraph.yaml and change description and name under dataSources, address and abi under source, enteties, abis and eventHandlers under mapping. For me and REN contract it looks like this
specVersion: 0.0.2
description: Ren for Ethereum
repository: https://github.com/graphprotocol/example-subgraph
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Ren
network: mainnet
source:
address: '0x408e41876cCCDC0F92210600ef50372656052a38'
abi: Ren
startBlock: 4827494
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- User
- UserCounter
- TransferCounter
- TotalSupply
abis:
- name: Ren
file: ./abis/Ren.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
file: ./src/mapping.ts
So with this I changed subgraph yaml, what I need to change next is schema.graphql which needs to reflect info and enteties what you want to save to graph and consume later. So here we add entities that will be constructed or updated on our events.
How are we going to do all of this? We are going to borrow things a bit, as this is contract of ERC20 token and this are Standard ERC events, we will find some other ERC20 tokens and use their graph code to quickly solve our needs. So lets go to the https://github.com/centrehq/usdc-subgraph/blob/master/subgraph.yaml and use entities and eventHandlers that they use in their yaml. If you want more entities and events you can also check https://github.com/daostack/subgraph/blob/master/src/mappings/DAOToken/… and fetch those or find some other. Also best would be to code your own and not just copy but for learning purposes and first step, this is fine.
So we got subgraph yaml file ready but we need to setup our entites, so we can use it from this repo and set https://github.com/centrehq/usdc-subgraph/blob/master/schema.graphql so you will have this in your schema.graphql when you leave out mint and mintCounter as entities
type User @entity {
id: ID!
address: String!
balance: BigInt!
transactionCount: Int!
}
type UserCounter @entity {
id: ID!
count: Int!
}
type TransferCounter @entity {
id: ID!
count: Int!
totalTransferred: BigInt!
}
type TotalSupply @entity {
id: ID!
supply: BigInt!
minted: BigInt!
burned: BigInt!
}
The last part we need to do is mappings, this will be a little harder as we cant just copy paste mappings from other subgraphs as they have their specific code https://github.com/centrehq/usdc-subgraph/blob/master/src/mapping.ts
First thing we need to do is run graph codegen in terminal. This will generate an AssemblyScript class for every smart contract in the ABI files mentioned in subgraph.yaml, allowing you to bind these contracts to specific addresses in the mappings and call read-only contract methods against the block being processed. It will also generate a class for every contract event to provide easy access to event parameters as well as the block and transaction the event originated from. All of these types are written to <OUTPUT_DIR>/<DATA_SOURCE_NAME>/<ABI_NAME>.ts
So unless we provide output dir it will be in default dir which is called "generated". In our example before it is not generated folder but types folder and then from there methods used in events are imported. So for our example we want to change those paths so we will change it to below
To have more knowledge on how to fill and manipulate data in your entities and mappings check the video from this specifi point https://youtu.be/e5OwjDao3MA?t=1556
With that we can finally run again yarn codegen and deploy the code to subgraph, we will do this with this line. 4.1 First set the token with graph auth https://api.thegraph.com/deploy/ token is written on top of your dashboard. 4.2 Then you need to run this command to deploy the graph graph deploy -- debug \ - node https://api.thegraph.com/deploy/ \ - ipfs https://api.thegraph.com/ipfs/ \ <github / subgraph_name> which will be like below when proper parametars are added. graph deploy --debug --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ adriadrop/ren-project If last line passes all the checks subgraph will be created and it will start to index data, if not you will get bunch of errors, probably some mappings will be wrong, maybe event wili miss some parameters or similar. For info how to debug this errors check here https://thegraph.com/docs/assemblyscript-api#logging-and-debugging
import { Burn, Transfer } from '../generated/Ren/Ren'
import {
User,
UserCounter,
TransferCounter,
TotalSupply
} from '../generated/schema'
import { BigInt } from '@graphprotocol/graph-ts'
// After all that we will have this in our mappings
import { Burn, Transfer } from '../generated/Ren/Ren'
import {
User,
UserCounter,
TransferCounter,
TotalSupply
} from '../generated/schema'
import { BigInt } from '@graphprotocol/graph-ts'
export function handleTransfer(event: Transfer): void {
let day = (event.block.timestamp / BigInt.fromI32(60 * 60 * 24))
let userFrom = User.load(event.params.from.toHex())
if (userFrom == null) {
userFrom = newUser(event.params.from.toHex(), event.params.from.toHex());
}
userFrom.balance = userFrom.balance - event.params.value
userFrom.transactionCount = userFrom.transactionCount + 1
userFrom.save()
let userTo = User.load(event.params.to.toHex())
if (userTo == null) {
userTo = newUser(event.params.to.toHex(), event.params.to.toHex());
// UserCounter
let userCounter = UserCounter.load('singleton')
if (userCounter == null) {
userCounter = new UserCounter('singleton')
userCounter.count = 1
} else {
userCounter.count = userCounter.count + 1
}
userCounter.save()
userCounter.id = day.toString()
userCounter.save()
}
userTo.balance = userTo.balance + event.params.value
userTo.transactionCount = userTo.transactionCount + 1
userTo.save()
// Transfer counter total and historical
let transferCounter = TransferCounter.load('singleton')
if (transferCounter == null) {
transferCounter = new TransferCounter('singleton')
transferCounter.count = 0
transferCounter.totalTransferred = BigInt.fromI32(0)
}
transferCounter.count = transferCounter.count + 1
transferCounter.totalTransferred = transferCounter.totalTransferred + event.params.value
transferCounter.save()
transferCounter.id = day.toString()
transferCounter.save()
}
function newUser(id: string, address: string): User {
let user = new User(id);
user.address = address
user.balance = BigInt.fromI32(0)
user.transactionCount = 0
return user
}
import { Burn, Transfer } from '../generated/Ren/Ren'
import {
User,
UserCounter,
TransferCounter,
TotalSupply
} from '../generated/schema'
import { BigInt } from '@graphprotocol/graph-ts'
// After all that we will have this in our mappings
import { Burn, Transfer } from '../generated/Ren/Ren'
import {
User,
UserCounter,
TransferCounter,
TotalSupply
} from '../generated/schema'
import { BigInt } from '@graphprotocol/graph-ts'
export function handleTransfer(event: Transfer): void {
let day = (event.block.timestamp / BigInt.fromI32(60 * 60 * 24))
let userFrom = User.load(event.params.from.toHex())
if (userFrom == null) {
userFrom = newUser(event.params.from.toHex(), event.params.from.toHex());
}
userFrom.balance = userFrom.balance - event.params.value
userFrom.transactionCount = userFrom.transactionCount + 1
userFrom.save()
let userTo = User.load(event.params.to.toHex())
if (userTo == null) {
userTo = newUser(event.params.to.toHex(), event.params.to.toHex());
// UserCounter
let userCounter = UserCounter.load('singleton')
if (userCounter == null) {
userCounter = new UserCounter('singleton')
userCounter.count = 1
} else {
userCounter.count = userCounter.count + 1
}
userCounter.save()
userCounter.id = day.toString()
userCounter.save()
}
userTo.balance = userTo.balance + event.params.value
userTo.transactionCount = userTo.transactionCount + 1
userTo.save()
// Transfer counter total and historical
let transferCounter = TransferCounter.load('singleton')
if (transferCounter == null) {
transferCounter = new TransferCounter('singleton')
transferCounter.count = 0
transferCounter.totalTransferred = BigInt.fromI32(0)
}
transferCounter.count = transferCounter.count + 1
transferCounter.totalTransferred = transferCounter.totalTransferred + event.params.value
transferCounter.save()
transferCounter.id = day.toString()
transferCounter.save()
}
function newUser(id: string, address: string): User {
let user = new User(id);
user.address = address
user.balance = BigInt.fromI32(0)
user.transactionCount = 0
return user
}
No activity yet