> For the complete documentation index, see [llms.txt](https://cramiumlabs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cramiumlabs.gitbook.io/docs/sdk-mpc-ios/usage-guide-for-an-mpc-wallet-app/transaction-policy.md).

# Transaction Policy

The [Transaction Policy (TP)](https://cramiumlabs.gitbook.io/docs/feature-list/transaction-policy) module ensures secure and customizable transaction controls for users by integrating features like whitelisting and time delays.

#### 1. getCurrentPolicy

The `getCurrentPolicy()` method retrieves the current transaction policy configuration. This includes details about the whitelisted addresses, time limits, and whether the policy is enabled.

**Example**:

```swift
    fun main() {
        // Retrieve the current transaction policy
        let resPolicy = getCurrentPolicy()
    }

```

#### 3. enablePolicy

The `enablePolicy()` method allows enabling/disabling of a transaction policy. - enabled: A flag to enable or disable the transaction policy. - force: A flag to enable the turning- off mode (default is false)

**Example**:

```swift
    fun main() {
        let enablePolicy = true
        let force = true
    
        // enable the Transaction Policy
        let updatedPolicy = enablePolicy(
            enablePolicy: enablePolicy,
            force: force,
        )
    }

```

#### 3. disablePolicy

The `disablePolicy()` method allows disable transaction policy.

**Example**:

```swift
    fun main() {
         val updatedPolicy = disablePolicy()
    }

```

#### 4. addWalletAddress

The `addWalletAddress()` method allows you to add a recipient’s wallet address to the whitelist. - address: The recipient's wallet address that you want to whitelist. - networkChain: the chain of wallet - labels: the alias of wallet

**Example**:

```swift
   fun main() {
        // Address to be added to the whitelist
        let recipientAddress = "recipientAddress"
        let networkChain = "networkChain"
        let labels = ["alias0"]

        // Add the address to the whitelist
        let whitelistResult = addWalletAddress(recipientAddress, networkChain, labels)

        // Handle the response
        println("Whitelisted Address Result: $whitelistResult")
    }

```

#### 5. removeWalletAddress

The `removeWalletAddress()` method removes a specified address from the whitelist. - walletId: The whitelist wallet id

**Example**:

```swift
   fun main() {
        // Address to be added to the whitelist
        let walletId = "walletId"

        // Add the address to the whitelist
        let whitelistResult = removeWalletAddress(walletId)
    }

```

#### 6. updateWalletAddress

The `updateWalletAddress()` method update a specified address from the whitelist. - walletId: The whitelist wallet id - labels: the alias of wallet

**Example**:

```swift
   fun main() {

        let walletId = "walletId"
        let labels = ["alias0"]
        
        let resValidateStatus = updateWalletAddress(walletId, labels)
        
    }

```

#### 7. getTransactionAmountLimit

The `getTransactionAmountLimit()` method retrieves the current transaction amount limit policy.

* **Returns**: The current `TransactionLimitPolicy` object.
* **Throws**: An error if the retrieval process fails.

**Example**:

```swift
func main() {
    do {
        let policy = try await getTransactionAmountLimit()
    } catch {
        print("Error retrieving transaction limit policy: \(error)")
    }
}

```

#### 8. updateTransactionAmountLimit

The `updateTransactionAmountLimit()` method updates the transaction amount limit policy with new parameters.

* **Parameters**:
  * `perTransactionLimit`: The maximum allowed amount per transaction.
  * `dailyLimit`: The maximum cumulative amount allowed per day.
  * `enable`: A Boolean indicating whether the transaction limit policy should be enabled.
* **Throws**: An error if updating the transaction amount limit fails.

**Example**:

```swift
func main() {
    do {
        try await updateTransactionAmountLimit(perTransactionLimit: 500000, dailyLimit: 5000000, enable: true)
        print("Transaction amount limit updated successfully.")
    } catch {
        print("Error updating transaction amount limit: \(error)")
    }
}
```

#### 9. updateTransactionAmountLimitForSpecificAddress

**Description:**\
Updates the transaction amount limit for a specific wallet address and its associated network chain. The new limits must not exceed the corresponding global limits. Increases may be staged (subject to a security delay or whitelisting process), while reductions take effect immediately.

**Parameters:**

* `address`: The wallet address whose limits are being updated.
* `networkChain`: The blockchain network identifier (e.g., "1" for Ethereum).
* `perTransactionLimit`: The new maximum allowed amount for a single transaction for this address.
* `dailyLimit`: The new maximum cumulative amount allowed per day for this address.
* `enable`: A Boolean indicating whether the new limits should be enabled.

**Throws:**\
An error if the update operation fails.

**Example:**

```swift
func main() async {
    do {
        let address = "walletAddress"
        let networkChain = "1"
        let perTransactionLimit: Int64 = 100000
        let dailyLimit: Int64 = 1000000
        let enable = true
        try await updateTransactionAmountLimitForSpecificAddress(
            address: address,
            networkChain: networkChain,
            perTransactionLimit: perTransactionLimit,
            dailyLimit: dailyLimit,
            enable: enable
        )
        print("Specific address transaction limit updated successfully.")
    } catch {
        print("Error updating transaction amount limit for specific address: \(error)")
    }
}
```

***

#### 10. getTransactionCurrentUsage

**Description:**\
Retrieves the current snapshot of daily transaction usage. This includes global usage totals as well as detailed usage statistics per wallet address.

**Returns:**\
A `TransactionCurrentUsage` object containing today's transaction usage details.

**Throws:**\
An error if the operation fails.

**Example:**

```swift
func main() async {
    do {
        let usage = try await getTransactionCurrentUsage()
        print("Transaction Usage: \(usage)")
    } catch {
        print("Error retrieving transaction usage: \(error)")
    }
}
```

***

#### 11. recordTransactionDailyUsage

**Description:**\
Records a transaction for daily usage tracking. It logs the transaction amount, status, and associated wallet information. Daily counters are automatically reset when the day changes.

**Parameters:**

* `address`: The wallet address from which the transaction originated.
* `networkChain`: The blockchain network identifier.
* `amount`: The transaction amount.
* `status`: The status of the transaction (e.g., `"SUCCESS"`, `"FAILED"`, or `"UNKNOWN"`).

**Returns:**\
A `TransactionRecordResponse` object containing updated usage totals and the recorded date.

**Throws:**\
An error if the operation fails.

**Example:**

```swift
func main() async {
    do {
        let address = "walletAddress"
        let networkChain = "1"
        let amount: Int64 = 25000
        let status: TransactionRecordStatus = .SUCCESS
        let recordResponse = try await recordTransactionDailyUsage(
            address: address,
            networkChain: networkChain,
            amount: amount,
            status: status
        )
        print("Transaction recorded: \(recordResponse)")
    } catch {
        print("Error recording transaction: \(error)")
    }
}
```

***

#### 12. checkAmountWithPolicy

**Description:**\
Validates whether a given transaction amount in USD complies with the current global and address-specific limits defined by the active policy.

**Parameters:**

* `amountInUsd`: The transaction amount in USD.
* `address`: The wallet address associated with the transaction.
* `networkChain`: The blockchain network identifier.

**Returns:**\
A Boolean value indicating if the transaction amount is within the allowed limits.

**Throws:**\
An error if the validation operation fails.

**Example:**

```swift
func main() async {
    do {
        let amountInUsd: Int64 = 1500
        let address = "walletAddress"
        let networkChain = "1"
        let isValid = try await checkAmountWithPolicy(amountInUsd: amountInUsd, address: address, networkChain: networkChain)
        print("Transaction amount valid: \(isValid)")
    } catch {
        print("Error validating transaction amount: \(error)")
    }
}
```
