Cargo.toml
README.md
build.sh
clear_all.sh
create_and_deploy.sh
deed
    Cargo.toml
    README.md
    src
        lib.rs
escrow
    Cargo.toml
    README.md
    src
        lib.rs
package.json
registrar
    Cargo.toml
    README.md
    src
        lib.rs
simple_auction.sh

<div align="center">
  <h1>
    NYM Exchange
  </h1>
  <p>
  Auctions for NEAR Protocol Accounts
  </p>
</div>

## Building
Run:
```bash
./build.sh
```

## Testing
To test run:
```bash
cargo test --package registrar -- --nocapture
```

## Changelog

### `0.2.0`

Upgrade near_sdk to 3.1.0, fix transfer contracts to utilize fully trustless transfer logic. extended workflow.

### `0.0.1`

Initial setup
# Escrow

A tiny contract to maintain a registry of accounts in escrow. This contract will be 100% owner-free, meaning escrow contract can never be updated or rug-pulled. Escrow will deploy a new Deed contract for every account being transferred.

### Transfer Flows

#### General Workflow

1. Create new escrow contract, only needs deploy once
2. Deploy new Deed contract for an account
3. Close Escrow for a Deed

Optional other actions:

- Revert Title: Allow owner to regain ownership via escrow

#### Initialization

This happens upon contract deploy of escrow contract. Main requirement is allowing the escrow contract to keep a registry of escrowed accounts.

1. Registrar or DAO deploys new escrow contract, without access keys
2. Users verify no access keys via `near keys escrow.nym.near`

#### Register Title

Register a new title by the following workflow (under the hood):
1. Deploy a new Deed contract to title account (not this contract)
2. call the register method so escrow knows to escrow the deed
3. optionally call a registrar so it also knows the escrowed account

#### Clear Escrow

Proxy to deed change_ownership function

### Commands & Usage

Requires [near cli]()

```bash
# Init
near deploy --wasmFile res/escrow.wasm --initFunction new --initArgs '{"factory": "testnet", "registrar": "auction.nym.testnet", "dao": "dao.sputnik.testnet"}' --accountId escrow_account.testnet

# Start deed (but this is actually called at DEED deploy)
near call _escrow_account_ register '{"underwriter": "some_other_account.testnet", "registrar": true}' --accountId youraccount_to_auction.testnet

# Close deed
near call _escrow_account_ close_escrow '{"auction_id": "some_account.testnet", "new_key": "ed25591:PK_HERE"}' --accountId youraccount.testnet

# Update Settings (only via DAO)
near call _escrow_account_ update_settings '{"dao": "dao.sputnik.testnet", "registrar": "registrar.alias.testnet"}' --accountId dao.sputnik.testnet

# view if account is in escrow
near view _escrow_account_ in_escrow '{"title": "some_account.testnet"}'
near view _escrow_account_ get_underwriter '{"title": "some_account.testnet"}'

# view the escrow settings
near view _escrow_account_ get_settings

```
# Registrar

A tiny contract to manage account ownership and transfer functionality, by utilizing an escrow account as the coordinator

### Transfer Flows

#### General Workflow

1. Deploy registrar
2. Create an auction for account (that is in escrow)
3. accept bids between auction blocks
4. Optional: Reveal phase
5. Finalize auction

#### Initialization

This happens upon contract deploy. Used to specify the escrow account

1. 

### Commands & Usage

Requires [near cli]()

```bash
# Init
near deploy --wasmFile res/registrar.wasm --initFunction new --initArgs '{}' --accountId registrar_account.testnet

```
# Deed

A tiny contract to manage account ownership and transfer functionality, by utilizing an escrow contract as the coordinator

### Transfer Flows

#### General Workflow

1. Initialization
2. change ownership only possible upon auction finalized by new owner

#### Initialization

This happens upon contract deploy from escrow contract. This requires the user to grant escrow full access to their account. All precautions must be taken before initialization can proceed.

1. User grants access to escrow, adding full access key to the account being transfered
2. User deploys a Deed contract, and calls the function "new" on the newly deployed Deed contract, which executes the following logic:
  2A. Make sure the initialization is valid
  2B. Transfer any/all balance on this account (No ability to know any sub account balances)
  2C. Call escrow to register this account with it, optionally allow escrow to tell registrar to include this account in its registery for THIS underwriter
  2D. Finish by assigning state, for future contract calls

#### Transfer of Ownership

The escrow contract will manage the movement from escrow ownership into the new access keys. This is done by allowing the escrow to make judgements about whether an account is available and ready to make a transfer. Such logic and caveats can be seen in the escrow folder.

1. Check access
2. Add new full access key, the new owner
3. Remove original owner id

### Commands & Usage

Requires [near cli]()

```bash
# Init
near deploy --wasmFile res/deed.wasm --initFunction new --initArgs '{"escrow": "escrow.testnet", "underwriter": "ACCOUNT_THAT_WILL_OWN.testnet"}' --accountId ACCOUNT_THAT_WILL_OWN.testnet --gas 300000000000000

# transfer ownership (Only callable via escrow)
near call escrow.testnet claim '{"pk": "ed25519:..."}' --accountId ACCOUNT_THAT_OWNS.testnet --gas 300000000000000
```
