Skip to content

Commit

Permalink
it works!
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Aug 29, 2024
1 parent e43e907 commit f17f0f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
12 changes: 2 additions & 10 deletions packages/indexer-common/src/allocations/__tests__/tap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ const rav = {
),
senderAddress: SENDER_ADDRESS_1,
redeemedAt: null,
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
}

const SIGNATURE = Buffer.from(
Expand Down Expand Up @@ -240,8 +238,6 @@ describe('TAP', () => {
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_3,
redeemedAt: new Date(redeemDate),
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)
const ravs = await receiptCollector['pendingRAVs']()
Expand Down Expand Up @@ -277,8 +273,6 @@ describe('TAP', () => {
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_3,
redeemedAt: new Date(redeemDate),
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)

Expand Down Expand Up @@ -379,8 +373,6 @@ describe('TAP', () => {
signature: SIGNATURE,
senderAddress: SENDER_ADDRESS_3,
redeemedAt: new Date(redeemDate),
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
}
await queryFeeModels.receiptAggregateVouchers.create(rav2)
let ravs = await receiptCollector['pendingRAVs']()
Expand All @@ -390,9 +382,9 @@ describe('TAP', () => {
where: { last: true, final: true },
})
//Final rav wont be returned here
expect(ravs).toEqual([rav])
expect(ravs).toEqual([expect.objectContaining(rav)])
// Expect final rav to be returned here
expect(finalRavs).toEqual([{ ...rav2, final: true }])
expect(finalRavs).toEqual([expect.objectContaining({ ...rav2, final: true })])
},
timeout,
)
Expand Down
31 changes: 14 additions & 17 deletions packages/indexer-common/src/allocations/query-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,14 @@ export class AllocationReceiptCollector implements ReceiptCollector {
): Promise<ReceiptAggregateVoucher[]> {
const tapSubgraphResponse = await this.findTransactionsForRavs(ravLastNotFinal)

const redeemedRavsNotOnOurDatabase = tapSubgraphResponse.transactions.filter((tx) => {
const ravNotInOurDb = !ravLastNotFinal.find(
(rav) =>
toAddress(rav.senderAddress) === toAddress(tx.sender.id) &&
toAddress(rav.allocationId) === toAddress(tx.allocationID),
)
console.log("allocation: " + tx.allocationID + " sender: " + tx.sender.id + " not in db: " + ravNotInOurDb)
return ravNotInOurDb
})
const redeemedRavsNotOnOurDatabase = tapSubgraphResponse.transactions.filter(
(tx) =>
!ravLastNotFinal.find(
(rav) =>
toAddress(rav.senderAddress) === toAddress(tx.sender.id) &&
toAddress(rav.allocationId) === toAddress(tx.allocationID),
),
)

// for each transaction that is not redeemed on our database
// but was redeemed on the blockchain, update it to redeemed
Expand All @@ -620,18 +619,17 @@ export class AllocationReceiptCollector implements ReceiptCollector {
}
}

console.log(tapSubgraphResponse.transactions)
// Filter unfinalized RAVS fetched from DB, keeping RAVs that have not yet been redeemed on-chain
const nonRedeemedRavs = ravLastNotFinal
.filter((rav) => !!rav.redeemedAt)
.filter(
(rav) =>
!tapSubgraphResponse.transactions.find((tx) => {
toAddress(rav.senderAddress) === toAddress(tx.sender.id) &&
toAddress(rav.allocationId) === toAddress(tx.allocationID)
}),
!tapSubgraphResponse.transactions.find(
(tx) =>
toAddress(rav.senderAddress) === toAddress(tx.sender.id) &&
toAddress(rav.allocationId) === toAddress(tx.allocationID),
),
)
console.log(nonRedeemedRavs)

// we use the subgraph timestamp to make decisions
// block timestamp minus 1 minute (because of blockchain timestamp uncertainty)
Expand Down Expand Up @@ -721,7 +719,6 @@ export class AllocationReceiptCollector implements ReceiptCollector {
AND timestamp_ns < ${blockTimestampNs}
`

console.log(query)
await this.models.receiptAggregateVouchers.sequelize?.query(query)
}

Expand All @@ -736,7 +733,6 @@ export class AllocationReceiptCollector implements ReceiptCollector {
AND redeemed_at < to_timestamp(${blockTimestampSecs - this.finalityTime})
`

console.log(query)
await this.models.receiptAggregateVouchers.sequelize?.query(query)
}

Expand Down Expand Up @@ -1122,6 +1118,7 @@ export class AllocationReceiptCollector implements ReceiptCollector {
.toLowerCase()
.replace('0x', '')}'
`

await this.models.receiptAggregateVouchers.sequelize?.query(query)
}

Expand Down

0 comments on commit f17f0f5

Please sign in to comment.