Skip to main content

AddAssetBuyOrder

AddAssetBuyOrder is used to add a buy order for a specific asset. If a buy order already exists for the asset, it will be updated.

A buy order instructs the RFQ (Request For Quote) system to request a quote from a peer for the acquisition of an asset.

The normal use of a buy order is as follows:

  1. Alice, operating a wallet node, wants to receive a Tap asset as payment by issuing a Lightning invoice.
  2. Alice has an asset channel established with Bob's edge node.
  3. Before issuing the invoice, Alice needs to agree on an exchange rate with Bob, who will facilitate the asset transfer.
  4. To obtain the best exchange rate, Alice creates a buy order specifying the desired asset.
  5. Alice's RFQ subsystem processes the buy order and sends buy requests to relevant peers to find the best rate. In this example, Bob is the only available peer.
  6. Once Bob provides a satisfactory quote, Alice accepts it.
  7. Alice issues the Lightning invoice, which Charlie will pay.
  8. Instead of paying Alice directly, Charlie pays Bob.
  9. Bob then forwards the agreed amount of the Tap asset to Alice over their asset channel.

Source: rfqrpc/rfq.proto

gRPC

rpc AddAssetBuyOrder (AddAssetBuyOrderRequest) returns (AddAssetBuyOrderResponse);

REST

HTTP MethodPath
POST /v1/taproot-assets/rfq/buyorder/asset-id/{asset_specifier.asset_id_str}

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10029'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
const TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('rfqrpc/rfq.proto', loaderOptions);
const rfqrpc = grpc.loadPackageDefinition(packageDefinition).rfqrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new rfqrpc.Rfq(GRPC_HOST, creds);
let request = {
asset_specifier: <AssetSpecifier>,
asset_max_amt: <uint64>,
expiry: <uint64>,
peer_pub_key: <bytes>,
timeout_seconds: <uint32>,
};
client.addAssetBuyOrder(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "accepted_quote": <PeerAcceptedBuyQuote>,
// "invalid_quote": <InvalidQuoteResponse>,
// "rejected_quote": <RejectedQuoteResponse>,
// }

Messages

rfqrpc.AddAssetBuyOrderRequest

Source: rfqrpc/rfq.proto

FieldgRPC TypeREST TypeREST Placement
asset_specifier
AssetSpecifierobjectmixed
asset_max_amt
uint64stringbody
expiry
uint64stringbody
peer_pub_key
bytesstringbody
timeout_seconds
uint32integerbody

rfqrpc.AddAssetBuyOrderResponse

Source: rfqrpc/rfq.proto

FieldgRPC TypeREST Type
accepted_quote
PeerAcceptedBuyQuoteobject
invalid_quote
InvalidQuoteResponseobject
rejected_quote
RejectedQuoteResponseobject

Nested Messages

rfqrpc.AssetSpecifier

FieldgRPC TypeREST Type
asset_id
bytesstring
asset_id_str
stringstring
group_key
bytesstring
group_key_str
stringstring

rfqrpc.FixedPoint

FieldgRPC TypeREST Type
coefficient
stringstring
scale
uint32integer

rfqrpc.InvalidQuoteResponse

FieldgRPC TypeREST Type
status
QuoteRespStatusstring
peer
stringstring
id
bytesstring

rfqrpc.PeerAcceptedBuyQuote

FieldgRPC TypeREST Type
peer
stringstring
id
bytesstring
scid
uint64string
asset_amount
uint64string
ask_asset_rate
FixedPointobject
expiry
uint64string

rfqrpc.RejectedQuoteResponse

FieldgRPC TypeREST Type
peer
stringstring
id
bytesstring
error_message
stringstring
error_code
uint32integer

Enums

rfqrpc.QuoteRespStatus

NameNumber
INVALID_ASSET_RATES
0
INVALID_EXPIRY
1
PRICE_ORACLE_QUERY_ERR
2