Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ensawards.org/data/awards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { App } from "data/apps/types.ts";
import type { EntityMetadata } from "data/entity-metadata/types.ts";
import type { IncentiveProgram, IncentiveProgramSlug } from "data/incentive-programs/types.ts";
import type { Protocol } from "data/protocols/types.ts";
import { type EnsTokens } from "data/shared/ensTokens.ts";
import type { TransactionRef } from "data/shared/transactionRef.ts";
import type { AccountId, UnixTimestamp } from "enssdk";

import type { Price } from "@ensnode/ensnode-sdk";

export const AwardTypes = {
FinancialAward: "financial-award",
RecognitionAward: "recognition-award",
Expand Down Expand Up @@ -53,11 +54,11 @@ export interface AwardAbstract<AwardTypeT extends AwardType> {
export interface AwardRecognition extends AwardAbstract<typeof AwardTypes.RecognitionAward> {}

export interface AwardFinancial extends AwardAbstract<typeof AwardTypes.FinancialAward> {
/** Amount of the award in $ENS.
/** Financial award in any currency supported by {@link Price}.
*
* @invariant Award amount must be finite and greater than 0.
Comment thread
Y3drk marked this conversation as resolved.
*/
price: EnsTokens; // should be replaced with `Price` from enssdk when Issue#1941 is completed.
price: Price;

/**
* Details of the transaction associated with the distribution of this award.
Expand Down
26 changes: 14 additions & 12 deletions ensawards.org/data/awards/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { ChainId } from "enssdk";
import { zeroAddress, zeroHash } from "viem";
import { describe, expect, it } from "vitest";

import { parseEnsTokens } from "@ensnode/ensnode-sdk";

import { type AwardFinancial, AwardTypes } from "./types.ts";
import { sortFinancialAwardsByPrice } from "./utils.ts";
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

Expand All @@ -17,7 +19,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 1,
transaction: {
chainId: placeholderChainId,
Expand All @@ -31,7 +33,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 200,
price: parseEnsTokens("200"),
awardedAt: 2,
transaction: {
chainId: placeholderChainId,
Expand All @@ -45,7 +47,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 150,
price: parseEnsTokens("150"),
awardedAt: 0,
transaction: {
chainId: placeholderChainId,
Expand All @@ -62,7 +64,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 200,
price: parseEnsTokens("200"),
awardedAt: 2,
transaction: {
chainId: placeholderChainId,
Expand All @@ -76,7 +78,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 150,
price: parseEnsTokens("150"),
awardedAt: 0,
transaction: {
chainId: placeholderChainId,
Expand All @@ -90,7 +92,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 1,
transaction: {
chainId: placeholderChainId,
Expand All @@ -114,7 +116,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 2,
transaction: {
chainId: placeholderChainId,
Expand All @@ -128,7 +130,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 1,
transaction: {
chainId: placeholderChainId,
Expand All @@ -142,7 +144,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 3,
transaction: {
chainId: placeholderChainId,
Expand All @@ -159,7 +161,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 1,
transaction: {
chainId: placeholderChainId,
Expand All @@ -173,7 +175,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 2,
transaction: {
chainId: placeholderChainId,
Expand All @@ -187,7 +189,7 @@ describe("awards utils", () => {
chainId: placeholderChainId,
address: zeroAddress,
},
price: 100,
price: parseEnsTokens("100"),
awardedAt: 3,
transaction: {
chainId: placeholderChainId,
Expand Down
15 changes: 10 additions & 5 deletions ensawards.org/data/awards/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { type EnsTokens } from "data/shared/ensTokens";
import { interpretCurrency } from "data/shared/currencies";

import type { Price } from "@ensnode/ensnode-sdk";

import { type Award, type AwardFinancial } from "./types";

/**
* Sorts {@link Award}s of {@link AwardFinancial} type.
Comment thread
Y3drk marked this conversation as resolved.
Outdated
*
* Prioritizes awards with higher {@link AwardFinancial.price} and,
* Prioritizes awards with higher {@link AwardFinancial.price.amount} and,
* in case of a tie, earlier {@link AwardFinancial.awardedAt} date.
*/
export const sortFinancialAwardsByPrice = (a: AwardFinancial, b: AwardFinancial): number => {
if (a.price > b.price) return -1;
if (a.price < b.price) return 1;
const aPriceAmount = interpretCurrency(a.price);
const bPriceAmount = interpretCurrency(b.price);
if (aPriceAmount > bPriceAmount) return -1;
if (aPriceAmount < bPriceAmount) return 1;
Comment thread
Y3drk marked this conversation as resolved.
Outdated

return a.awardedAt - b.awardedAt;
};
Expand All @@ -19,6 +23,7 @@ export const sortFinancialAwardsByPrice = (a: AwardFinancial, b: AwardFinancial)
* Checks if a given award value is valid
* according to the invariants defined in {@link AwardFinancial}.
*/
export const isValidAwardValue = (awardValue: EnsTokens): boolean => {
export const isValidAwardValue = (awardPrice: Price): boolean => {
const awardValue = interpretCurrency(awardPrice);
return Number.isFinite(awardValue) && awardValue > 0;
};
Comment thread
Y3drk marked this conversation as resolved.
Comment thread
Y3drk marked this conversation as resolved.
Loading
Loading