Skip to content

Commit

Permalink
Patch arb price check reverting and add timestamp field.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeanBoyCousin committed Nov 2, 2023
1 parent d0b32fb commit b27925b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ type ERC20 @entity {
type AirdropTransaction @entity {
id: ID!

timestamp: BigInt!
address: Bytes!
decimals: Int!
name: String!
Expand Down
11 changes: 6 additions & 5 deletions src/ERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Transfer } from '../generated/ARB/ERC20'
import { chainlinkAggregator } from '../generated/ARB/chainlinkAggregator'
import { AirdropRecipient, AirdropTransaction } from '../generated/schema'
import { CHAINLINK_AGGREGATOR_ARB_USD, TREASURY } from './addresses'
import { BIG_DECIMAL_1e18, BIG_DECIMAL_1e8 } from './constants'
import { BIGINT_ZERO, BIG_DECIMAL_1e18, BIG_DECIMAL_1e8 } from './constants'

export function handleTransfer(event: Transfer): void {
const amount = event.params.value
Expand All @@ -14,10 +14,10 @@ export function handleTransfer(event: Transfer): void {

// get current ARB price.
const chainlinkAggregatorContractARB = chainlinkAggregator.bind(Address.fromString(CHAINLINK_AGGREGATOR_ARB_USD))
const arbPrice = chainlinkAggregatorContractARB.latestAnswer()
const arbPrice = chainlinkAggregatorContractARB.try_latestAnswer()

// Get USD value.
const price = arbPrice.toBigDecimal().div(BIG_DECIMAL_1e8)
const price = !arbPrice.reverted ? arbPrice.value.toBigDecimal().div(BIG_DECIMAL_1e8) : BIGINT_ZERO.toBigDecimal()
const value = amount
.toBigDecimal()
.div(BIG_DECIMAL_1e18)
Expand All @@ -26,14 +26,15 @@ export function handleTransfer(event: Transfer): void {
if (fromAddress.toHexString() == TREASURY) {
// Create transaction entity.
const newTransaction = new AirdropTransaction(transactionHash)


newTransaction.timestamp = event.block.timestamp
newTransaction.address = event.address
newTransaction.decimals = 18
newTransaction.name = 'Arbitrum'
newTransaction.symbol = 'ARB'

newTransaction.amount = amount
newTransaction.arbPrice = arbPrice
newTransaction.arbPrice = !arbPrice.reverted ? arbPrice.value : BIGINT_ZERO
newTransaction.from = fromAddress
newTransaction.to = toAddress

Expand Down

0 comments on commit b27925b

Please sign in to comment.