Skip to content

Commit

Permalink
Only run logic if transfer is from the treasury.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeanBoyCousin committed Nov 3, 2023
1 parent f0277a4 commit 5dcb2d5
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/ERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ import { CHAINLINK_AGGREGATOR_ARB_USD, TREASURY } from './addresses'
import { BIGINT_ZERO, BIG_DECIMAL_1e18, BIG_DECIMAL_1e8 } from './constants'

export function handleTransfer(event: Transfer): void {
const amount = event.params.value
const fromAddress = event.params.from
const toAddress = event.params.to
const transactionHash = event.transaction.hash.toHex()

// get current ARB price.
const chainlinkAggregatorContractARB = chainlinkAggregator.bind(Address.fromString(CHAINLINK_AGGREGATOR_ARB_USD))
const arbPrice = chainlinkAggregatorContractARB.try_latestAnswer()
if (fromAddress.toHexString() == TREASURY) {
const amount = event.params.value
const toAddress = event.params.to
const transactionHash = event.transaction.hash.toHex()

// Get USD value.
const price = !arbPrice.reverted ? arbPrice.value.toBigDecimal().div(BIG_DECIMAL_1e8) : BIGINT_ZERO.toBigDecimal()
const value = amount
.toBigDecimal()
.div(BIG_DECIMAL_1e18)
.times(price)
// get current ARB price.
const chainlinkAggregatorContractARB = chainlinkAggregator.bind(Address.fromString(CHAINLINK_AGGREGATOR_ARB_USD))
const arbPrice = chainlinkAggregatorContractARB.try_latestAnswer()

// Get USD value.
const price = !arbPrice.reverted ? arbPrice.value.toBigDecimal().div(BIG_DECIMAL_1e8) : BIGINT_ZERO.toBigDecimal()
const value = amount
.toBigDecimal()
.div(BIG_DECIMAL_1e18)
.times(price)

if (fromAddress.toHexString() == TREASURY) {
// Create transaction entity.
const newTransaction = new AirdropTransaction(transactionHash)

newTransaction.timestamp = event.block.timestamp
newTransaction.address = event.address
newTransaction.decimals = 18
Expand Down

0 comments on commit 5dcb2d5

Please sign in to comment.