diff --git a/README.md b/README.md index 32ef57d..057e648 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This app is designed for projects looking to host and manage their Token Generat ## App Configuration - add your Token Address, Chain id and other optional metadata to `./app-config.ts` +- [OPTIONAL] Overriding Allowlists: check `apps/dapp/src/allowlist/README.md` for how-to ## Dev Setup diff --git a/apps/dapp/src/allowlist/README.md b/apps/dapp/src/allowlist/README.md new file mode 100644 index 0000000..a284091 --- /dev/null +++ b/apps/dapp/src/allowlist/README.md @@ -0,0 +1,4 @@ +# Allowlist Overriding + +1. Check `allowlists.ts` and add your allowlist(s) to it. +2. That's it. diff --git a/apps/dapp/src/allowlist/allowlists.ts b/apps/dapp/src/allowlist/allowlists.ts new file mode 100644 index 0000000..84a1a5e --- /dev/null +++ b/apps/dapp/src/allowlist/allowlists.ts @@ -0,0 +1,23 @@ +/** The allowlists exported from this file will override the metadata server's allowlists + * + * The object key should be the auction id, which can be retrieved from the subgraph: + * 1) Obtain the subgraph URL for the auction chain here: https://github.com/Axis-Fi/ui-libs/tree/main/packages/deployments/src/chains + * 2) Obtain the subgraph version from https://github.com/Axis-Fi/ui-libs/blob/main/packages/deployments/src/subgraph-config.ts + * 3) Run the following query replacing the base token with your token address: + * + * query getBatchAuctionLotsByBaseTokenAddress { + batchAuctionLots(where: { baseToken: "0x0000000000000000000000000000000000000000" }) { + id + } + } + + The return id value is the key to be used for the allowlist + */ + +export default { + //Example format + "blast-sepolia-0x1234567890123456789012345678901234567890-1": [ + ["0x0000000000000000000000000000000000000000", "300000000000000000"], + ["0x0000000000000000000000000000000000000001", "1777777700000000000"], + ], +} as Record>; diff --git a/apps/dapp/src/allowlist/index.ts b/apps/dapp/src/allowlist/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/apps/dapp/src/allowlist/utils.test.ts b/apps/dapp/src/allowlist/utils.test.ts new file mode 100644 index 0000000..f846255 --- /dev/null +++ b/apps/dapp/src/allowlist/utils.test.ts @@ -0,0 +1,39 @@ +import { describe, it, expect } from "vitest"; +import { overrideAllowlist } from "./utils"; +import { getBatchAuctionMock } from "src/stories/mocks/batch-auction"; + +const SAMPLE_ALLOWLIST = [ + ["0x0000000000000000000000000000000000000000", "300000000000000000"], + ["0x0000000000000000000000000000000000000001", "1777777700000000000"], +]; + +describe("Allowlist Overrides", () => { + it("overrides an allowlist if file is present", () => { + const mockAuction = getBatchAuctionMock(); + const result = overrideAllowlist(mockAuction, SAMPLE_ALLOWLIST); + + const allowlist = result?.info?.allowlist; + + expect(Array.isArray(allowlist)).toBe(true); + + allowlist?.forEach((element) => { + expect(element).toHaveProperty("values"); + expect(Array.isArray(element.values)).toBe(true); + + element.values.forEach((value) => { + expect(typeof value).toBe("string"); + }); + }); + }); + + it("keeps auction unchanged if no allowlist for that id is present", () => { + const mockAuction = getBatchAuctionMock({ + id: "blast-sepolia-0x1234567890123456789012345678901234567890-2", + }); + const result = overrideAllowlist(mockAuction); + const allowlist = result?.info?.allowlist; + + expect(result).toEqual(mockAuction); + expect(allowlist).toBe(undefined); + }); +}); diff --git a/apps/dapp/src/allowlist/utils.ts b/apps/dapp/src/allowlist/utils.ts new file mode 100644 index 0000000..ddd21c8 --- /dev/null +++ b/apps/dapp/src/allowlist/utils.ts @@ -0,0 +1,41 @@ +import { Auction } from "@axis-finance/types"; +import allowlists from "./allowlists"; + +/** + * Returns the existing allowlist file if it exists locally + */ +export function getAllowlistByAuctionId(id: Auction["id"]) { + return allowlists[id]; +} + +/** + * Overrides an auction allowlist property with a local allowlist file + */ +export function overrideAllowlist( + auction: Auction, + allowlist?: Array, +): Auction { + if (!allowlist || allowlist.length === 0) return auction; + + const _auction = auction; + + if (!allowlist) return auction; + + if (auction.info === null) { + _auction.info = { + links: [], + allowlist: [], + }; + } + + const mappedAllowlist = allowlist.map((values) => ({ values })); + + return { + ..._auction, + info: { + ..._auction.info, + links: _auction.info?.links ?? [], + allowlist: mappedAllowlist, + }, + }; +} diff --git a/apps/dapp/src/modules/auction/hooks/use-auctions.ts b/apps/dapp/src/modules/auction/hooks/use-auctions.ts index da8a083..461fc92 100644 --- a/apps/dapp/src/modules/auction/hooks/use-auctions.ts +++ b/apps/dapp/src/modules/auction/hooks/use-auctions.ts @@ -12,6 +12,10 @@ import { AUCTION_CHAIN_ID, AUCTION_TOKEN_ADDRESS, } from "../../../../../../app-config"; +import { + getAllowlistByAuctionId, + overrideAllowlist, +} from "src/allowlist/utils"; export type AuctionsResult = { data: Auction[]; @@ -62,7 +66,12 @@ export function useAuctions(): AuctionsResult { chainId, }; - return preparedAuction as Auction; + const auctionWithOverridenAllowlist = overrideAllowlist( + preparedAuction as Auction, + getAllowlistByAuctionId(preparedAuction.id), + ); + + return auctionWithOverridenAllowlist; }) .sort(sortAuction);