---
# System prepended metadata

title: Identity based on a smart contract

---

# Identity based on a smart contract

## Goal
Consume an external lending or borrowing service through the RIF Gateway's service interface.

## Use cases 
### N-N
```mermaid
sequenceDiagram
actor EOA
participant SP_Interface_SC
participant Identity_SC
participant Lending_Service 

EOA->>SP_Interface_SC: Call 
SP_Interface_SC->>SP_Interface_SC: Gets identity from own mapping
SP_Interface_SC->>Identity_SC: Request Execute call 
Identity_SC->>Lending_Service: Lend()
Lending_Service-->>Identity_SC: Ok() or Fail()
Identity_SC-->>SP_Interface_SC: Ok() or Fail()
SP_Interface_SC-->>EOA: Ok() or Fail()
```

Note: Identity_SC must whitelist the SP_Interface_SC to allow calls only from that specific smart contract.

### 1-N (RIF Gateway Owner allows service providers to use individual identities)

```mermaid
sequenceDiagram
actor EOA
participant SP_Interface_SC
participant Identity_Factory
participant Identity_SC
participant Lending_Service 

EOA->>SP_Interface_SC: Call 
SP_Interface_SC->>Identity_Factory: Request identity
Identity_Factory-->>SP_Interface_SC: EOA Smart Contract Identity
SP_Interface_SC->>Identity_SC: Request execute call 
Identity_SC->>Lending_Service: Lend()
Lending_Service-->>Identity_SC: Ok() or Fail()
Identity_SC-->>SP_Interface_SC: Ok() or Fail()
SP_Interface_SC-->>EOA: Ok() or Fail()
```

### 1-N Fully Decentralized (User allows service providers to use individual identities)

```mermaid
sequenceDiagram
actor EOA
participant SP_Interface_SC
participant Identity_Factory
participant Identity_SC
participant Lending_Service 

EOA->>Identity_Factory: Approve(SP_Interface_SC)
EOA->>SP_Interface_SC: Call 
SP_Interface_SC->>Identity_Factory: Request identity
Identity_Factory-->>SP_Interface_SC: EOA Smart Contract Identity
SP_Interface_SC->>Identity_SC: Request execute call 
Identity_SC->>Lending_Service: Lend()
Lending_Service-->>Identity_SC: Ok() or Fail()
Identity_SC-->>SP_Interface_SC: Ok() or Fail()
SP_Interface_SC-->>EOA: Ok() or Fail()
```
