diff --git a/lib/web/rgb.ts b/lib/web/rgb.ts index 9981f26d..d8bb10d0 100644 --- a/lib/web/rgb.ts +++ b/lib/web/rgb.ts @@ -157,6 +157,12 @@ export const createOffer = async ( ): Promise => JSON.parse(await BMC.create_offer(nostrHexSk, request)); +export const createAuctionBid = async ( + nostrHexSk: string, + request: RgbAuctionBidRequest +): Promise => + JSON.parse(await BMC.create_auction_bid(nostrHexSk, request)); + export const createBid = async ( nostrHexSk: string, request: RgbBidRequest @@ -169,6 +175,15 @@ export const createSwap = async ( ): Promise => JSON.parse(await BMC.create_swap(nostrHexSk, request)); +export const finishAuction = async ( + nostrHexSk: string, + request: string +): Promise => + JSON.parse(await BMC.finish_auction(nostrHexSk, request)); + +export const listAuctions = async (): Promise => + JSON.parse(await BMC.list_auctions()); + export const directSwap = async ( nostrHexSk: string, request: RgbBidRequest @@ -935,9 +950,30 @@ export interface PublicRgbOfferResponse { /// Bitcoin Price bitcoinPrice: bigint; /// Initial Offer PSBT - offerPsbt: string; + offerPsbt?: string; +} + +export interface RgbAuctionFinishResponse { + /// Bundle ID + bundle_id: string, + /// New Change Outpoint + outpoint: string, + /// Sold Items + sold: Map, + /// Reamining Items + remaining: Map, } +export interface RgbSwapItem { + /// Contract ID + contractId: string, + /// Iface + iface: string, + /// Final Consig + contractAmount: string, +} + + export interface PublicRgbBidResponse { /// Bid ID bidId: string; diff --git a/src/web.rs b/src/web.rs index de2d03fd..1b545c90 100644 --- a/src/web.rs +++ b/src/web.rs @@ -9,8 +9,9 @@ use crate::rgb::structs::ContractAmount; use crate::structs::{ AcceptRequest, FullIssueRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest, IssueMediaRequest, IssueRequest, MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest, - RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, RgbSaveTransferRequest, - RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, WatcherRequest, + RgbAuctionBidRequest, RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, + RgbSaveTransferRequest, RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, + WatcherRequest, }; pub fn set_panic_hook() { @@ -874,6 +875,21 @@ pub mod rgb { }) } + #[wasm_bindgen] + pub fn create_auction_bid(nostr_hex_sk: String, request: JsValue) -> Promise { + set_panic_hook(); + + future_to_promise(async move { + let bid_req: RgbAuctionBidRequest = serde_wasm_bindgen::from_value(request).unwrap(); + match crate::rgb::create_auction_bid(&nostr_hex_sk, bid_req).await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } + #[wasm_bindgen] pub fn create_bid(nostr_hex_sk: String, request: JsValue) -> Promise { set_panic_hook(); @@ -904,6 +920,34 @@ pub mod rgb { }) } + #[wasm_bindgen] + pub fn finish_auction(nostr_hex_sk: String, request: JsValue) -> Promise { + set_panic_hook(); + + future_to_promise(async move { + let bundle_id: String = serde_wasm_bindgen::from_value(request).unwrap(); + match crate::rgb::finish_auction_offers(&nostr_hex_sk, bundle_id).await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } + + #[wasm_bindgen] + pub fn list_auctions() -> Promise { + set_panic_hook(); + + future_to_promise(async move { + match crate::rgb::list_auctions().await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } #[wasm_bindgen] pub fn direct_swap(nostr_hex_sk: String, request: JsValue) -> Promise { set_panic_hook();