Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 4123386

Browse files
committed
feat: track points
1 parent 96525ad commit 4123386

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

packages/indexer/src/configs/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum RewardPointsActivityType {
4444
REWARD_POINTS_EARNED
4545
ORDER_PLACED_POINTS
4646
ORDER_FILLED_POINTS
47+
TOKEN_TELEPORTED_POINTS
4748
}
4849

4950
"""

packages/indexer/src/services/tokenGateway.service.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { ERC20Abi__factory, TokenGatewayAbi__factory } from "@/configs/src/types/contracts"
22
import PriceHelper from "@/utils/price.helpers"
3-
import { TeleportStatus, TeleportStatusMetadata, TokenGatewayAssetTeleported } from "@/configs/src/types"
3+
import {
4+
TeleportStatus,
5+
TeleportStatusMetadata,
6+
TokenGatewayAssetTeleported,
7+
ProtocolParticipant,
8+
RewardPointsActivityType,
9+
} from "@/configs/src/types"
410
import { timestampToDate } from "@/utils/date.helpers"
511
import { hexToBytes, bytesToHex, hexToString } from "viem"
612
import type { Hex } from "viem"
713
import { TOKEN_GATEWAY_CONTRACT_ADDRESSES } from "@/addresses/tokenGateway.addresses"
14+
import { PointsService } from "./points.service"
15+
import Decimal from "decimal.js"
816

917
export interface IAssetDetails {
1018
erc20_address: string
@@ -87,6 +95,21 @@ export class TokenGatewayService {
8795
transactionHash,
8896
})
8997
await teleport.save()
98+
99+
// Award points for token teleport - using USD value directly
100+
const teleportValue = new Decimal(usdValue.amountValueInUSD)
101+
const pointsToAward = teleportValue.floor().toNumber()
102+
103+
await PointsService.awardPoints(
104+
this.bytes32ToBytes20(teleportParams.from),
105+
`EVM-${sourceChain}`,
106+
BigInt(pointsToAward),
107+
ProtocolParticipant.USER,
108+
RewardPointsActivityType.TOKEN_TELEPORTED_POINTS,
109+
transactionHash,
110+
`Points awarded for teleporting token ${teleportParams.assetId} with value ${usdValue.amountValueInUSD} USD`,
111+
timestamp,
112+
)
90113
}
91114

92115
return teleport
@@ -119,6 +142,23 @@ export class TokenGatewayService {
119142
if (teleport) {
120143
teleport.status = status
121144
await teleport.save()
145+
146+
// Deduct points when teleport is refunded
147+
if (status === TeleportStatus.REFUNDED) {
148+
const teleportValue = new Decimal(teleport.usdValue)
149+
const pointsToDeduct = teleportValue.floor().toNumber()
150+
151+
await PointsService.deductPoints(
152+
teleport.from,
153+
teleport.sourceChain,
154+
BigInt(pointsToDeduct),
155+
ProtocolParticipant.USER,
156+
RewardPointsActivityType.TOKEN_TELEPORTED_POINTS,
157+
transactionHash,
158+
`Points deducted for refunded teleport ${commitment} with value ${teleport.usdValue} USD`,
159+
timestamp,
160+
)
161+
}
122162
}
123163

124164
const teleportStatusMetadata = await TeleportStatusMetadata.create({

0 commit comments

Comments
 (0)