# OmniEscrow

OmniEscrow is a form of digital asset auctioning and bidding. Any ERC20 or native tokens can be auctioned and bidden. Upon acceptance of a bid the bidder instantly receives the offered assets, and the auctioner instantly receives the bidden assets; this happens in the same transaction ensuring safety and transparency. Accessible from [escrow.omnify.finance](http://escrow.omnify.finance/) and [app.omnify.finance/escrow](https://app.omnify.finance/escrow)

<figure><img src="https://1401536863-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuyWAhHhL3vEiQQseVlGe%2Fuploads%2F0GgnzkYgbEnohArpFgkD%2FX%20-%20Escrow1%20.png?alt=media&#x26;token=cc63f529-312e-4c5c-b0a8-cf8b57999fdd" alt=""><figcaption><p>Scenes from an OmniEscrow contract</p></figcaption></figure>

### Interactions

There are many actions that can be conducted when calling an OmniEscrow contract. You can create a new auction, place a bid, accept a placed bid, cancel your created auction, and cancel your placed bid whenever you want. Start by downloading the [OmniEscrow interface](https://github.com/OmniKobra/Omnify/blob/main/Omni/Contracts/Omnify/src/interfaces/escrowInterface.sol) from our github repo. You can find a list of all Omnify services' tiers and fees at [omnify.finance/fees](https://omnify.finance/fees).&#x20;

Let's start by defining an OmniEscrow variable

```solidity
IEscrow99 public omniescrow = IEscrow99(0xaA01ED5B276A1B61850799FFD8d42f9bc7fe8CC5);
```

### Creating an auction

To create a new Escrow auction (internally called an escrow contract), we only need to call `newContract`. Let's take a look at its parameters first.

```solidity
function newContract(
string memory _id, // the auction Identifier, must not be a duplicate
address _asset, // The token address, use address(0) for native tokens
uint256 _amount // amount to offer in the auction (in Wei)
)external payable;
```

Now lets call it with our parameters

```solidity
address public asset = address(0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664);
uint256 public amount = 1000000;
uint256 public msgVal = 0;
uint256 escrowFee = omniescrow.contractFee(); // Get Omnify's escrow fee
msgVal += escrowFee;
if (asset == address(0)) {
    msgVal += amount;  
}
omniescrow.newContract{value: msgVal}(
'id1', // our assigned id
asset, // address of USDC on Avax
amount // 1 USDC in Wei
);
```

**We successfully created a new escrow auction.**

### Cancel an auction

Cancelling an auction can only be done by the creator. Upon cancelling the owner gets their assets back, and the bidders will still be able to cancel their bids to get their assets back even after the auction has been cancelled.

To cancel an OmniEscrow auction simply call `deleteContract` and pass the id of the contract you wish to cancel.

```solidity
omniescrow.deleteContract('id1');
```

### Place a bid

To place a bid on an existing and live contract, we need to call `newBid` and pass it the id of the auction we want to bid on. An auction's owner cannot place a bid on their own auction. Let's take a look at the parameters of `newBid`.

```solidity
function newBid(
string memory _contractId, // Identifier of the auction we want to bid on
address _asset, // token address of bidden asset, use address(0) for native tokens
uint256 _amount // amount of bidden asset in Wei
) external payable;
```

Now let's call it with our parameters.

```solidity
omniescrow.newBid(
'id1', // Auction identifier
address(0), // Native token bid
1 * 10 ** 16 // Bid amount in Wei
);
```

After placing a bid, the auction automatically assigns it a number (`bidCount`) that identifies it. We will need that number when we need to either accept or cancel a bid.

### Getting a bid's count

To lookup a bid's count on a certain contract we need to lookup the auction and get its current bid count right after placing our bid. So after calling newBid, we call `lookupCountractBidCount` , and yes countract is a typo in the deployed source code 😞.

```solidity
omniescrow.newBid(
'id1', 
address(0), 
1 * 10 ** 16 
);
omniescrow.lookupCountractBidCount('id1'); // OUR BID COUNT
```

### Accepting a bid

To accept one of the bids on our auction, the bid must not be cancelled and the auction must be ongoing (no other accepted bids and auction is not cancelled). The owner of the auction can call `acceptBid` and pass it the auction ID and the accepted bid's count. Upon accepting a bid the bidder gets the offered assets and the auction owner gets the accepted bid's asset. Both events happen simultaneously in the same transaction.

```solidity
omniescrow.acceptBid(
'id1', // Auction ID
1 // Accepting the first bid
);
```

### Cancel a bid

Any bidder can cancel their bid as long as it hasnt been accepted by the auction owner. To cancel a bid call `cancelBid` and pass it the auction's ID and the bid's count.

```solidity
omniescrow.cancelBid(
'id1', // Auction ID
1 // Bid Count
);
```

***Now we now know how to interact with OmniEscrow contracts.*****&#x20;😮‍💨**
