> 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/dokumentasi-teknis/referensi-smart-contract.md).

# Referensi Smart Contract

Signature diambil langsung dari `payana-contract/src/`. Untuk penjelasan konsep, lihat [Lapisan Smart Contract](/payana-saas-docs/arsitektur/smart-contract.md).

## PayrollFactory.sol

| Fungsi                         | Akses                 | Kegunaan                                         |
| ------------------------------ | --------------------- | ------------------------------------------------ |
| `deployVault(...)`             | Publik (HR mendaftar) | Deploy `CompanyVault` baru untuk pemanggil       |
| `setPlatformFee(uint16 bps)`   | `SUPERADMIN_ROLE`     | Atur fee platform (maks. `MAX_PLATFORM_FEE_BPS`) |
| `setProtocolTreasury(address)` | `SUPERADMIN_ROLE`     | Atur alamat treasury platform                    |
| `emergencyFreezeAll()`         | `SUPERADMIN_ROLE`     | Bekukan seluruh vault (kill switch darurat)      |
| `getTotalVaults()`             | View                  | Jumlah vault yang pernah dideploy                |

**Event:** `VaultDeployed(hrAuthority, vaultAddress, companyName)`, `PlatformFeeUpdated(bps)`, `ProtocolTreasuryUpdated(treasury)`

## CompanyVault.sol

### Kas & konfigurasi

| Fungsi                                                        | Akses              | Kegunaan                             |
| ------------------------------------------------------------- | ------------------ | ------------------------------------ |
| `fundVault(uint256 amount)`                                   | `onlyHR`           | Isi saldo IDRX vault                 |
| `fundGas()`                                                   | `onlyHR` (payable) | Isi saldo ETH untuk Paymaster        |
| `withdrawVault(uint256, address)`                             | `onlyHR`           | Tarik saldo IDRX vault               |
| `setCompanyConfig(bpjsBps, pph21Bps, lowBalanceThresholdBps)` | `onlyHR`           | Atur potongan & ambang alert saldo   |
| `pauseVault()` / `resumeVault()`                              | `onlyHR`           | Jeda/lanjutkan seluruh operasi vault |
| `freezeVault()`                                               | —                  | Bekukan vault (kondisi darurat)      |

### Stream gaji

| Fungsi                                  | Akses                                   | Kegunaan                                 |
| --------------------------------------- | --------------------------------------- | ---------------------------------------- |
| `startStream(...)`                      | `onlyHR`                                | Mulai stream gaji karyawan               |
| `pauseStream` / `resumeStream(address)` | `onlyHR`                                | Jeda/lanjutkan stream satu karyawan      |
| `updateFlowRate(address, uint256)`      | `onlyHR`                                | Ubah kecepatan gaji                      |
| `cancelStream(address)`                 | `onlyHR`                                | Hentikan stream permanen                 |
| `claimSalary()`                         | Karyawan (`msg.sender` = Smart Account) | Tarik EWA — accrued sejak klaim terakhir |
| `migrateEmployeeAddress(old, new)`      | `onlyHR`                                | Pindahkan record stream ke alamat baru   |

### Kasbon (Salary Advance)

| Fungsi                             | Akses    | Kegunaan                                                 |
| ---------------------------------- | -------- | -------------------------------------------------------- |
| `requestAdvance(uint256 amount)`   | Karyawan | Ajukan kasbon, maks. `MAX_ADVANCE_BPS` dari gaji bulanan |
| `approveAdvance(address employee)` | `onlyHR` | Setujui & cairkan kasbon yang pending                    |
| `rejectAdvance(address employee)`  | `onlyHR` | Tolak pengajuan kasbon                                   |

Pelunasan (`ADVANCE_REPAY_BPS` = 20%) terjadi otomatis lewat `_autoRepayAdvance` setiap `claimSalary()` dipanggil — bukan fungsi yang dipanggil terpisah.

### PHK (Termination)

| Fungsi                                            | Akses                                                 | Kegunaan                                    |
| ------------------------------------------------- | ----------------------------------------------------- | ------------------------------------------- |
| `proposeTermination(address, bytes32 reasonHash)` | `onlyHR`                                              | Ajukan proposal PHK                         |
| `approveTermination(address)`                     | `LEGAL_ROLE`                                          | Setujui proposal                            |
| `executeTermination(address)`                     | `onlyHR`, butuh persetujuan Legal & belum kedaluwarsa | Eksekusi PHK + cairkan pesangon             |
| `cancelProposal(address)`                         | `onlyHR`                                              | Batalkan proposal (sebelum disetujui Legal) |

### Vesting (Cliff)

| Fungsi                              | Akses    | Kegunaan                                    |
| ----------------------------------- | -------- | ------------------------------------------- |
| `createCliffVest(...)`              | `onlyHR` | Buat bonus dengan jadwal cliff              |
| `claimCliffVest(uint256 vestId)`    | Karyawan | Klaim bonus setelah tanggal cliff terlewati |
| `cancelCliffVest(address, uint256)` | `onlyHR` | Batalkan vesting yang belum diklaim         |

### View functions

`getAccrued(address)`, `getVaultBalance()`, `getSeveranceBalance(address)`, `getStreamInfo(address)`, `isStreamActive(address)`

### Event lengkap

`VaultInitialized`, `VaultFunded`, `VaultWithdrawn`, `VaultPaused`, `VaultResumed`, `VaultFreeze`, `LowVaultBalance`, `StreamCreated`, `StreamPaused`, `StreamResumed`, `FlowRateUpdated`, `StreamSplitsUpdated`, `StreamCancelled`, `SalaryClaimed`, `TaxWithheld`, `SeveranceReleased`, `SeveranceReturned`, `SeveranceShortfall`, `TerminationProposed`, `TerminationApproved`, `TerminationExecuted`, `TerminationCancelled`, `CliffVestCreated`, `CliffVestClaimed`, `CliffVestForfeited`, `ComplianceWithdrawn`, `EmploymentCertified`, `EmploymentRevoked`, `PlatformFeePaid`, `AdvanceRequested`, `AdvanceApproved`, `AdvanceRejected`, `AdvanceRepaid`, `GasFunded`, `EmployeeAddressMigrated`

## EmploymentSBT.sol

| Fungsi                        | Akses                                    | Kegunaan                      |
| ----------------------------- | ---------------------------------------- | ----------------------------- |
| `mint(address employee, ...)` | `MINTER_ROLE` (dipanggil `CompanyVault`) | Terbitkan SBT baru            |
| `revoke(address employee)`    | `MINTER_ROLE`                            | Cabut SBT (mis. saat PHK)     |
| `locked(uint256 tokenId)`     | View                                     | Status kunci token (ERC-5192) |
| `setBaseURI(string)`          | `DEFAULT_ADMIN_ROLE`                     | Atur base URI metadata        |

**Event:** `Locked(tokenId)`, `Unlocked(tokenId)` (standar ERC-5192)

## Konstanta penting

| Konstanta               | Nilai                     | Lokasi           |
| ----------------------- | ------------------------- | ---------------- |
| `HR_ROLE`               | `keccak256("HR_ROLE")`    | `CompanyVault`   |
| `LEGAL_ROLE`            | `keccak256("LEGAL_ROLE")` | `CompanyVault`   |
| `DEFAULT_SEVERANCE_BPS` | 200                       | `CompanyVault`   |
| `TERMINATION_EXPIRY`    | 7 days                    | `CompanyVault`   |
| `MAX_ADVANCE_BPS`       | 8000                      | `CompanyVault`   |
| `ADVANCE_REPAY_BPS`     | 2000                      | `CompanyVault`   |
| `MAX_PLATFORM_FEE_BPS`  | 100                       | `PayrollFactory` |


---

# 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/dokumentasi-teknis/referensi-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.
