Fixed Price Offers (Listings)
Fixed Price Offers allow sellers to list domain names for sale at a predetermined price. Buyers can purchase these domain names by paying the specified amount.
Struct
pub struct FixedPriceOffer {
/// Account tag
pub tag: Tag,
/// Nonce
pub nonce: u8,
/// Name being sold
pub name_account: Pubkey,
/// Offer owner
pub owner: Pubkey,
/// Quote token used for offer
pub quote_mint: Pubkey,
/// Amount of the offer
pub offer_amount: u64,
// Offer amount token account destination
pub token_destination: Pubkey,
};
Make Fixed Price Offer
Creating a fixed price offer is handled by the makeFixedPriceOffer
function, as shown in the code snippet below.
import { NAME_OFFERS_ID, makeFixedPriceOffer } from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";
const seller = new PublicKey("..."); // Public key of the seller i.e domain owner
const mint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); // USDC mint
const amount = 1 * 1e6; // Amount with decimals, here 1 USDC
const { pubkey: domainKey } = getDomainKeySync("something.sol"); // Domain public key
const ix = await makeFixedPriceOffer(
connection,
amount,
mint,
seller,
domainKey,
NAME_OFFERS_ID
);
Buy Fixed Price Offer
Buying a fixed price offer is facilitated through the buyFixedPrice
function, which ensures the transfer of the domain to the buyer and the payment to the seller:
import {
NAME_OFFERS_ID,
buyFixedPrice,
getFixedPriceOffersForName
} from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";
const buyer = new PublicKey("..."); // Public key of the offer buyer
const source = new PublicKey("..."); // Source of the funds used to purchase the offer. In case of SOL it's the same as `buyer`. If another token is used, it's the ATA of the buyer for the given mint.
const { pubkey: domainKey } = getDomainKeySync("something.sol"); // Domain public key
const referrer: PublicKey | undefined = undefined; // Optional referrer
// Util function to get fixed price offers by name, by owner, or all fixed price offers.
const fixedPriceOffers = await getFixedPriceOffersForName(
connection,
domainKey
);
// This example arbitrarily selects the first fixed price offer in the list. Filter offers based on the your needs.
const fixedPriceKey = fixedPriceOffers[0].pubkey;
const ix = await buyFixedPrice(
connection,
fixedPriceKey,
buyer,
source,
NAME_OFFERS_ID,
referrer
);
Last updated