Category Offers allow buyers to bid on an entire domain category. Sellers can accept these offers, selling domains within the specified category.
Struct
pubstructCategoryOffer{// Account tagpubtag:Tag,// The PDA noncepubnonce:u8,// The total number of domains requestedpubnb_domains:u64,// The SOL price per domainpubsol_price:u64,// The category of the offerpubcategory:Pubkey,// The owner of the offerpubowner:Pubkey,// Timestamp at which the offer was createdpubcreated_at:u64,}
Make Category Offer
The creation of a category offer is managed by the makeCategoryOffer function, which specifies the number of domains, the SOL price per domain, and the category.
Take (Accept) Category Offer
Taking/accepting a category offer is facilitated through the takeCategoryOffer function, allowing sellers to sell domains within the category at the specified price.
import { CATEGORIES } from "@bonfida/sns-categories"; // Map of current categories
import { NAME_OFFERS_ID, makeCategoryOffer } from "@bonfida/name-offers";
const amount = 10 * LAMPORTS_PER_SOL; // Amount of the offer in lamports here 10 SOL
const nbDomains = 10; // Number of domains the buyer wants to buy
const buyer = new PublicKey("...");
// Filter CATEGORIES to find the categoryKey which is the Public key of the category.
const categoryKey = [...CATEGORIES].find(
([, value]) => value === "999-club"
)?.[0];
const ix = await makeCategoryOffer(
amount,
nbDomains,
categoryKey,
NAME_OFFERS_ID,
buyer
);
// ... sign and send instruction
import { CategoryMember } from "@bonfida/sns-categories"; // Map of current categories
import { getDomainKeySync } from "@bonfida/spl-name-service";
import {
NAME_OFFERS_ID,
getCategoryOffer,
takeCategoryOffer
} from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";
const { pubkey: domainKey } = getDomainKeySync("999.sol"); // Domain public key
const memberKey = CategoryMember.findKey("999", categoryKey); // Membership of the domain to the category
const seller = new PublicKey("..."); // Seller of the domain here 999.sol
const referrer: PublicKey | undefined = undefined; // Optional referrer
// Use a util function to get category offers by category, category offers for a specific owner, etc.
const categoryOffers = await getCategoryOffer(connection, categoryKey);
// This example arbitrarily selects the first category offer in the list. Filter offers based on your needs.
const categoryOfferKey = categoryOffers[0].pubkey;
const ix = await takeCategoryOffer(
connection,
NAME_OFFERS_ID,
categoryOfferKey,
domainKey,
memberKey,
seller,
referrer
);
// ... sign and send instruction