Unsolicited Offers

Unsolicited offers allow buyers to propose a purchase price for a domain not listed for sale. The domain owner can then accept or ignore the offer.

Struct

pub struct Offer {
    /// Tag
    pub tag: Tag,
    /// Nonce
    pub nonce: u8,
    /// Name account of the offer
    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,
    /// Escrow account key
    pub escrow: Pubkey,
}

Make Offer

import { NAME_OFFERS_ID, makeOffer } from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";

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 owner = new PublicKey("..."); // Owner of the unsolicited offer
const tokenSource = new PublicKey("..."); // Token source used to place the offer.

const ix = await makeOffer(
  amount,
  domainKey,
  owner,
  mint,
  tokenSource,
  NAME_OFFERS_ID
);

// ... sign and send instruction

Accept Offer

import { 
NAME_OFFERS_ID, 
getOffersForName, 
acceptOffer 
} from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";

const domainOwner = new PublicKey("..."); // Current domain owner
const { pubkey: domainKey } = getDomainKeySync("something.sol"); // Domain public key
const offerEscrow = new PublicKey("..."); // PDA used to store the funds of the offer, the address is written in the state
const destination = new PublicKey("..."); // The token account used to receive the funds from the escrow
const referrer: PublicKey | undefined = undefined; // Optional referrer

// Use a util function from the SDK to get offers by domain name, by domain owner, etc.
const offers = await getOffersForName(connection, "something.sol");

// This example arbitrarily selects the first offer in the list. Filter offers based on your needs.
const offerKey = offers[0].pubkey;
const offerOwner = offers[0].owner;

const ix = await acceptOffer(
  connection,
  NAME_OFFERS_ID,
  offerKey,
  offerOwner,
  publicKey,
  domainKey,
  offerEscrow,
  destination,
  referrer
);

// ... sign and send instruction

Cancel Offer

import { 
NAME_OFFERS_ID, 
cancelOffer 
} from "@bonfida/name-offers";
import { getDomainKeySync } from "@bonfida/spl-name-service";
import { getAssociatedTokenAddress } from "@solana/spl-token";

// Offer token mint is the mint address of the token the offer was made in.
const tokenDestination = getAssociatedTokenAddress(offerTokenMint, offerOwner);

// See acceptOffer example above for offerKey description
const ix = await cancelOffer(domainOwner, tokenDestination, offerKey, NAME_OFFERS_ID)

// ... sign and send instruction

Last updated