|
1 | 1 | import { ERC20Abi__factory, TokenGatewayAbi__factory } from "@/configs/src/types/contracts" |
2 | 2 | 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" |
4 | 10 | import { timestampToDate } from "@/utils/date.helpers" |
5 | 11 | import { hexToBytes, bytesToHex, hexToString } from "viem" |
6 | 12 | import type { Hex } from "viem" |
7 | 13 | import { TOKEN_GATEWAY_CONTRACT_ADDRESSES } from "@/addresses/tokenGateway.addresses" |
| 14 | +import { PointsService } from "./points.service" |
| 15 | +import Decimal from "decimal.js" |
8 | 16 |
|
9 | 17 | export interface IAssetDetails { |
10 | 18 | erc20_address: string |
@@ -87,6 +95,21 @@ export class TokenGatewayService { |
87 | 95 | transactionHash, |
88 | 96 | }) |
89 | 97 | 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 | + ) |
90 | 113 | } |
91 | 114 |
|
92 | 115 | return teleport |
@@ -119,6 +142,23 @@ export class TokenGatewayService { |
119 | 142 | if (teleport) { |
120 | 143 | teleport.status = status |
121 | 144 | 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 | + } |
122 | 162 | } |
123 | 163 |
|
124 | 164 | const teleportStatusMetadata = await TeleportStatusMetadata.create({ |
|
0 commit comments