> For the complete documentation index, see [llms.txt](https://payana-saas.gitbook.io/payana-saas-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://payana-saas.gitbook.io/payana-saas-docs/arsitektur/smart-contract.md).

# Lapisan Smart Contract

Ditulis dalam Solidity, dikembangkan dan diuji dengan [Foundry](https://book.getfoundry.sh/), di-deploy ke Base Sepolia. Tiga kontrak inti, masing-masing dengan satu tanggung jawab jelas.

## PayrollFactory

Kontrak pabrik (factory pattern) — satu-satunya kontrak yang di-deploy sekali, lalu bertugas men-deploy `CompanyVault` baru untuk setiap perusahaan yang mendaftar (`deployVault()`). Juga bertanggung jawab atas:

* Registry semua vault yang pernah dibuat (per alamat HR)
* Penerbitan `EmploymentSBT`
* Konfigurasi fee platform, dibatasi maksimum oleh `MAX_PLATFORM_FEE_BPS`

## CompanyVault

Kontrak inti tempat semua uang sungguhan bergerak — **satu instance per perusahaan**, di-deploy oleh `PayrollFactory`. Menyimpan saldo IDRX perusahaan dan menjalankan:

* **Salary streaming** — `startStream`, `claimSalary`
* **Kasbon** — penarikan uang muka dengan batas `MAX_ADVANCE_BPS` dan pelunasan otomatis `ADVANCE_REPAY_BPS`
* **Vesting** — bonus dengan jadwal cliff (`createCliffVest`, klaim setelah tanggal cliff terlewati)
* **PHK** — `proposeTermination` → `approveTermination` → `executeTermination`, dengan `TERMINATION_EXPIRY` 7 hari dan pesangon otomatis berbasis `DEFAULT_SEVERANCE_BPS`
* **Paymaster ERC-4337** — setiap `CompanyVault` mensponsori gas untuk transaksi karyawannya sendiri

## EmploymentSBT

Token ERC-5192 (soulbound — non-transferable) yang menjadi bukti kerja on-chain. Diterbitkan otomatis saat pendaftaran karyawan disetujui, dikunci ke alamat karyawan, dan bisa diperiksa siapa saja lewat halaman `/verify` di frontend.

## Peran & otorisasi

Dua role di level kontrak yang menentukan siapa bisa melakukan apa:

| Role         | Hash                      | Dipegang oleh                                                             | Bisa melakukan                                                                    |
| ------------ | ------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `HR_ROLE`    | `keccak256("HR_ROLE")`    | HR perusahaan                                                             | `startStream`, `proposeTermination`, `executeTermination`, konfigurasi perusahaan |
| `LEGAL_ROLE` | `keccak256("LEGAL_ROLE")` | Legal officer perusahaan (bisa juga HR yang sama, tergantung konfigurasi) | `approveTermination`                                                              |

## Parameter kunci

| Konstanta               | Nilai  | Arti                                                 |
| ----------------------- | ------ | ---------------------------------------------------- |
| `DEFAULT_SEVERANCE_BPS` | 200    | Pesangon default = 2% dari akumulasi gaji            |
| `TERMINATION_EXPIRY`    | 7 hari | Masa berlaku proposal PHK sebelum kedaluwarsa        |
| `MAX_ADVANCE_BPS`       | 8000   | Kasbon maksimum = 80% dari saldo terakumulasi        |
| `ADVANCE_REPAY_BPS`     | 2000   | Pelunasan kasbon otomatis = 20% per klaim            |
| `MAX_PLATFORM_FEE_BPS`  | 100    | Fee platform maksimum = 1%, dikunci di level factory |

## Dependency

Dibangun di atas [OpenZeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) untuk primitive standar (access control, ERC standards) dan [eth-infinitism/account-abstraction](https://github.com/eth-infinitism/account-abstraction) untuk implementasi ERC-4337 (Smart Account & Paymaster).

## Testnet-only

`mocks/MockIDRX.sol` adalah token IDRX tiruan dengan fungsi `mint()` yang sengaja dibuka untuk siapa saja — memudahkan pengujian di testnet. **Kontrak ini tidak pernah boleh di-deploy ke mainnet.**

Referensi fungsi lengkap: [Referensi Smart Contract](/payana-saas-docs/dokumentasi-teknis/referensi-smart-contract.md). Cara deploy: [Deploy Smart Contract](/payana-saas-docs/deployment/smart-contract.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://payana-saas.gitbook.io/payana-saas-docs/arsitektur/smart-contract.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
