Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions apps/dapp/src/allowlist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Allowlist Overriding

1. Check `allowlists.ts` and add your allowlist(s) to it.
2. That's it.
23 changes: 23 additions & 0 deletions apps/dapp/src/allowlist/allowlists.ts
Original file line number Diff line number Diff line change
@@ -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<string, Array<string[]>>;
Empty file.
39 changes: 39 additions & 0 deletions apps/dapp/src/allowlist/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
41 changes: 41 additions & 0 deletions apps/dapp/src/allowlist/utils.ts
Original file line number Diff line number Diff line change
@@ -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<string[]>,
): 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,
},
};
}
11 changes: 10 additions & 1 deletion apps/dapp/src/modules/auction/hooks/use-auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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);

Expand Down