-
Notifications
You must be signed in to change notification settings - Fork 0
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
8 changed files
with
370 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
[ | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "approve", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_from", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferFrom", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint8" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "symbol", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transfer", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
} | ||
], | ||
"name": "allowance", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"payable": true, | ||
"stateMutability": "payable", | ||
"type": "fallback" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
} | ||
] |
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,41 @@ | ||
import { Transfer } from "../generated/SEED-ERC20/ERC20" | ||
import { TokenBalance } from "../generated/schema" | ||
import { | ||
fetchTokenDetails, | ||
fetchAccount, | ||
fetchBalance | ||
} from "./utils" | ||
import { BigDecimal } from "@graphprotocol/graph-ts" | ||
|
||
export function handleTransfer(event: Transfer): void { | ||
let token = fetchTokenDetails(event) | ||
if(!token) return | ||
|
||
let fromAddress = event.params.from.toHex() | ||
let toAddress = event.params.to.toHex() | ||
|
||
let fromAccount = fetchAccount(fromAddress) | ||
let toAccount = fetchAccount(toAddress) | ||
|
||
let fromTokenBalance = TokenBalance.load(token.id + "-" + fromAccount.id) | ||
if (!fromTokenBalance) { | ||
fromTokenBalance = new TokenBalance(token.id + "-" + fromAccount.id) | ||
fromTokenBalance.token = token.id | ||
fromTokenBalance.account = fromAccount.id | ||
} | ||
fromTokenBalance.amount = fetchBalance(event.address, event.params.from) | ||
if(fromTokenBalance.amount != BigDecimal.zero()) { | ||
fromTokenBalance.save() | ||
} | ||
|
||
let toTokenBalance = TokenBalance.load(token.id + "-" + toAccount.id) | ||
if (!toTokenBalance) { | ||
toTokenBalance = new TokenBalance(token.id + "-" + toAccount.id) | ||
toTokenBalance.token = token.id | ||
toTokenBalance.account = toAccount.id | ||
} | ||
toTokenBalance.amount = fetchBalance(event.address, event.params.to) | ||
if (toTokenBalance.amount != BigDecimal.zero()) { | ||
toTokenBalance.save() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
import { ERC20 } from "../generated/SEED-ERC20/ERC20" | ||
import { Account, Token } from "../generated/schema" | ||
import { BigDecimal, ethereum, Address } from "@graphprotocol/graph-ts" | ||
|
||
export function fetchTokenDetails(event: ethereum.Event): Token | null { | ||
let token = Token.load(event.address.toHex()) | ||
if (!token) { | ||
token = new Token(event.address.toHex()) | ||
|
||
token.name = "Uɴᴋɴᴏᴡɴ" | ||
token.symbol = "𝑈𝑛𝑘𝑛𝑜𝑤𝑛" | ||
token.decimals = BigDecimal.zero() | ||
|
||
let erc20 = ERC20.bind(event.address) | ||
|
||
let tokenName = erc20.try_name() | ||
if (!tokenName.reverted) { | ||
token.name = tokenName.value | ||
} | ||
|
||
let tokenSymbol = erc20.try_symbol() | ||
if (!tokenSymbol.reverted) { | ||
token.symbol = tokenSymbol.value | ||
} | ||
|
||
let tokenDecimal = erc20.try_decimals() | ||
if (!tokenDecimal.reverted) { | ||
token.decimals = BigDecimal.fromString(tokenDecimal.value.toString()) | ||
} | ||
|
||
token.save() | ||
} | ||
return token | ||
} | ||
|
||
export function fetchAccount(address: string): Account { | ||
let account = Account.load(address) | ||
if (!account) { | ||
account = new Account(address) | ||
account.save() | ||
} | ||
if(!account) throw new Error(`Failed to fetch account: "${address}".`) | ||
return account | ||
} | ||
|
||
export function fetchBalance( | ||
tokenAddress: Address, | ||
accountAddress: Address | ||
): BigDecimal { | ||
let erc20 = ERC20.bind(tokenAddress) | ||
let tokenBalance = erc20.try_balanceOf(accountAddress) | ||
if(tokenBalance.reverted) { | ||
throw new Error(`Failed to fetch balance: "${tokenBalance.reverted.toString()}".`) | ||
} | ||
return tokenBalance.value.toBigDecimal() | ||
} |
Oops, something went wrong.