# Named Wallet

## Code <a href="#code" id="code"></a>

* Github : [https://github.com/0xSilicon/opencohort-contracts](https://github.com/0xSilicon/opencohort-contracts/)

## Wallet Factory Contract <a href="#wallet-factory-contract" id="wallet-factory-contract"></a>

A Factory contract for deploying Named Wallets, providing an efficient and scalable solution for creating wallets with unique identities.

### Address (Factory)

* Mainnet: `0x5F53CD20ecE6605c62a3525E1031b1d87Be05D80`
* Sepolia: `0x507cBAFFaf2DbD1f872089E9aF8087F120C96710`

### Functions <a href="#functions" id="functions"></a>

#### deployWallet

deployWallet is used to deploy a new wallet contract, initializing it with the specified properties and returning the address of the newly deployed wallet contract.

```solidity
function deployWallet(
    address virtualAddress,
    WalletInfo memory walletInfo,
    string[] calldata keys,
    string[] calldata values
) external returns (address)
```

**Parameters:**

<table data-header-hidden><thead><tr><th width="193"></th><th width="158"></th><th></th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td><code>virtualAddress</code></td><td>address</td><td>The address associated with the virtual or designated environment where the wallet will be linked. (ex, <code>0x1234567890abcdef1234567890abcdef12345678</code>)</td></tr><tr><td><code>walletInfo</code></td><td><a href="https://wiki.prod.ozys.work/wiki/spaces/SD/pages/51478574/Silicon+docs#Data-Structures">WalletInfo</a></td><td>A structured data type (<code>WalletInfo</code>) containing essential wallet details.</td></tr><tr><td><code>keys</code></td><td>string[]</td><td>An array of strings representing the property keys of the wallet. <strong>It is mandatory that the array includes a key labeled</strong> <code>category</code></td></tr><tr><td><code>values</code></td><td>string[]</td><td>An array of strings representing the corresponding values for each key in the <code>keys</code> array. These values define the actual data or settings for the wallet's properties.</td></tr></tbody></table>

**Return Values**

<table data-header-hidden><thead><tr><th width="191"></th><th></th></tr></thead><tbody><tr><td>Type</td><td>Description</td></tr><tr><td>address</td><td>The address of the newly deployed wallet.</td></tr></tbody></table>

#### **computeAddress**

This function computes the address of a contract that will be deployed using the `CREATE2` opcode, based on the provided signer and virtual address. It returns the future address of the contract, which can be predicted before deployment.

{% code overflow="wrap" %}

```solidity
function computeAddress(
    address signer,
    address virtualAddress
) external view returns (address)
```

{% endcode %}

**Parameters:**

<table data-header-hidden><thead><tr><th width="199"></th><th width="142"></th><th></th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td><code>signer</code></td><td>address</td><td>The address of the signer, used to generate a unique salt for contract address computation.</td></tr><tr><td><code>virtualAddress</code></td><td>address</td><td>The address associated with the virtual environment or contract, used in combination with the signer to create a unique salt.</td></tr></tbody></table>

**Return Values**

<table data-header-hidden><thead><tr><th width="218"></th><th></th></tr></thead><tbody><tr><td>Type</td><td>Description</td></tr><tr><td>address</td><td>The predicted address of the contract that would be deployed using the <code>CREATE2</code> opcode.</td></tr></tbody></table>

#### **getDataHash**

This function computes a hash of the data that will be signed by the `signer` when activating a wallet.

```solidity
function getDataHash(
    address virtualAddress,
    address owner
) external view returns (bytes32)
```

Parameters:

<table data-header-hidden><thead><tr><th width="205"></th><th width="124"></th><th></th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td><code>virtualAddress</code></td><td>address</td><td>The address associated with the virtual environment or contract, used to identify the wallet in the context of the activation process.</td></tr><tr><td><code>owner</code></td><td>address</td><td>The address of the person who will take over the ownership of the wallet.</td></tr></tbody></table>

Return Values

<table data-header-hidden><thead><tr><th width="211"></th><th></th></tr></thead><tbody><tr><td>Type</td><td>Description</td></tr><tr><td>bytes32</td><td>The hash of the data that the <code>signer</code> will sign to activate the wallet.</td></tr></tbody></table>

&#x20;

#### **activateWallet**

This function allows the transfer of ownership of a wallet contract, deployed via `deployWallet`, from the `signer` to the `owner`. The wallet contract address is computed using the `computeAddress` function, and the ownership transfer is verified through the signature provided by the `signer`.

```solidity
function activateWallet(
    address signer,
    address virtualAddress,
    address owner,
    bytes calldata signature
) external
```

**Parameters:**

<table data-header-hidden><thead><tr><th width="199"></th><th width="154"></th><th></th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td><p><code>signer</code></p><p> </p></td><td>address</td><td>The address of the current wallet owner. This address signs the data to confirm the ownership transfer to the new <code>owner</code>.</td></tr><tr><td><code>virtualAddress</code></td><td>address</td><td>The address associated with the virtual environment or contract to which the wallet is linked.</td></tr><tr><td><code>owner</code></td><td>address</td><td>The address of the new wallet owner, who will receive ownership of the wallet.</td></tr><tr><td><code>signature</code></td><td>bytes32</td><td>The signature corresponding to the hash of the data that is generated by the <code>getDataHash</code> function.</td></tr></tbody></table>

## Named Wallet Contract

### Data Structures

#### Struct WalletInfo

```solidity
struct WalletInfo {
    string name;
    string image;
    string description;
    uint256 rate;
}
```

* The properties `name`, `image`, and `description` are stored in the `NameTagMetadata` struct ([l](https://github.com/0xSilicon/opencohort-contracts/blob/main/contracts/token/OpenNameTag.sol#L27)[ink](https://github.com/0xSilicon/opencohort-contracts/blob/56aaff9c49fc380416bc6cb674dabc79e91d319c/contracts/token/OpenNameTag.sol#L27)) of OpenNameTag.
* `rate`: Tax rate paid to the signer when assets are transferred from the wallet.

### Functions <a href="#functions.1" id="functions.1"></a>

#### **Asset Transfer Functions**

These functions allow the contract owner to transfer assets, either native tokens (ETH) or specific tokens, to other addresses.

**transferTo**

```solidity
transferTo(address to, uint256 amount) public payable onlyOwner
```

* **Description**: Transfers a specified amount of native cryptocurrency (ETH) to the given address. This function is restricted to the `owner`, ensuring that only the contract owner can transfer funds from the contract's balance.

&#x20;

**transferTokenTo**

```solidity
transferTokenTo(address token, address to, uint256 amount) public onlyOwner
```

* **Description**: Transfers a specified amount of a particular ERC20 token from the contract to the given address. The contract owner is the only one authorized to initiate token transfers, ensuring control over the assets.

#### **Configuration Functions**

These functions are used to modify and update various configurations or properties of the contract. They are generally restricted to specific roles, such as the `signer` or `factory`, to ensure proper authorization before making changes.

**changeTaxRate**

```solidity
function changeTaxRate(uint256 rate_) public onlySigner
```

* **Description**: Changes the tax rate of the system. Only the `signer` is allowed to modify the tax rate to ensure that only authorized parties can make financial adjustments.

&#x20;

**changeInfo**

{% code overflow="wrap" %}

```solidity
function changeInfo(string memory _name, string memory _image, string memory _description) public onlySigner
```

{% endcode %}

* **Description**: Updates the basic information of the contract, such as the name, image, and description. This function is restricted to the `signer` to prevent unauthorized changes to the contract's identity or metadata.

&#x20;

**addPropertyBatch**

{% code overflow="wrap" %}

```solidity
function addPropertyBatch(string[] calldata keys, string[] calldata values) external onlySignerOrFactory
```

{% endcode %}

* **Description**: Adds multiple properties (key-value pairs) to the contract in batch. This function can be called by either the `signer` or the `factory`, allowing for efficient property management by authorized roles.

&#x20;

**removeProperty**

```solidity
function removeProperty(string calldata key) external onlySigner
```

* **Description**: Removes a specific property identified by its key. Only the `signer` can remove properties, ensuring that property changes are made with proper authorization.
