The purpose of Deal Rooms is to allow the safe exchange of fungible tokens for non-fungible tokens (NFT) which represent real-world assets.
A Deal Room is a set of contracts configured to handle one or more deals between a specific buyer, seller, and (optionally) other signatories.
Deals involve the exchange of a set of tokens from a specific asset contract (ERC-721) for an amount of tokens from a specific coin contract (ERC-20).
To settle the deal, signatories must sign it. By default, there are 5 possible signatories arranged in two groups:
-
Agents (any 2 must sign)
- Buyer: the agent wishing to obtain the assets
- Seller: the agent wishing to obtain ERC-20 tokens
- Arbitrator: a third party who can sign on behalf of the Buyer or Seller
-
Approvers (both must sign)
- Documentation Approver: their signature attests that paperwork was in order
- Sensor Approver: their signature attests that the condition of the asset is acceptible
import { DealRoomController } from "dealrooms"
Create a Hub to manage your Deal Rooms:
const hubAddress = await DealRoomController.deployHub(signer)
Deploy a new Deal Room:
const dealRoomCreateParams: DealRoomCreateParams = {
hubAddress: "0x...",
buyer: "0x...",
seller: "0x...",
arbitrator: "0x...",
docApprover: "0x...",
sensorApprover: "0x..."
}
roomAddress = await DealRoomController.deployRoom(dealRoomCreateParams, signer)
Set up a new Deal:
// Make an instance of a DealRoomController
const dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, signer)
await dealRoomController.init()
// Make a deal
const myDeal = await dealRoomController.makeDeal({
erc20: "0x...",
erc721: "0x...",
price: new BigNumber(100), //Number of ERC-20 tokens (coins) requested
assetItems: [ 20100123, 20100124, 20100125, 20100126] // Identifiers of ERC-721 tokens offered in exchange (assets)
})
Seller deposits assets into the escrow contract:
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, sellerSigner)
await dealRoomController.init()
await dealRoomController.depositDealAssets(myDeal.id, [20100123, 20100124, 20100125, 20100126])
Buyer deposits coins into the escrow contract:
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, buyerSigner)
await dealRoomController.init()
await dealRoomController.depositDealCoins(myDeal.id, 100)
Buyer/Seller signs to settle the deal:
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, agentSigner))
await dealRoomController.init()
await dealRoomController.proposeAgentsSettleDeal(myDeal.id)
Approver signs to settle the deal:
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, approverSigner)
await dealRoomController.init()
await dealRoomController.proposeMainSettleDeal(myDeal.id)
Until the deal has settled, the buyer and seller may withdraw their tokens freely. Once the deal has settled, the assets and coins can only be withdrawn by the new owners; the buyer can withdraw assets, the seller can withdraw coins.
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, sellerSigner)
await dealRoomController.init()
await dealRoomController.withdrawDealCoins(myDeal.id)
dealRoomController = new DealRoomController(dealRoomHubAddress, roomAddress, buyerSigner)
await dealRoomController.init()
await dealRoomController.withdrawDealAssets(myDeal.id)
To complete the initialisation, call init()
after calling the constructor. Once instantiated, instance methods will operate with the supplied hub, deal room and signer.
Deploy a Hub contract. This is responsible for maintaining a collection of DealRooms.
Deploy the contracts for a new DealRoom.
type DealRoomCreateParams = {
dealRoomHubAddress: string //Address of Hub contract
buyer: string //Address of signatory
seller: string //Address of signatory
arbitrator: string //Address of signatory
docApprover: string //Address of signatory
sensorApprover: string //Address of signatory
}
Return the Ethereum address of the DealRoom contract.
Get the Ethereum address of the Buyer agent
Get the Ethereum address of the Seller agent
Return a list of Ethereum address for Deal Room contracts.
Create a new Deal in the Deal Room. Pass in a Deal struct with the following properties set:
erc20: string // Ethereum address of coin contract
erc721: string // Ethereum address of token contract
assetItems: BigNumberish[] // Identifiers of asset items for sale
price: BigNumber // Requested price
Get a Deal struct, containing information about the Deal:
id: BigNumberish
erc20: string
erc721: string
price: BigNumber
assetItems: BigNumberish[]
agentConfirmations: number
dealConfirmations: number
dealTransaction: MultiSigTransaction
agentTransaction: MultiSigTransaction
status: number
Get an array of Deals in the current Room.
Return the number of Deals in the current Room.
Return an array of Asset tokens specified in a deal but not yet deposited in the escrow contract.
Return the number of Coin tokens specified in a deal but not yet deposited in the escrow contract.
Return an array of objects indicating the owner of each asset specified in the Deal.
assetId: BigNumber,
owner: string
Deposit an amount of Coin tokens into the escrow contract.
Deposit the specified Asset tokens into the escrow contract.
Withdraw all Coins associated with a given deal.
Withdraw all Assets associated with a given deal.
Return the amount of Coin tokens owned by the current Signer.
Return a list of Asset tokens owned by the current Signer.
Return the current owner of a given Asset token.
Sign the Deal as the current Signer, requesting that it be settled.