:source-highlighter: highlight.js
:highlightjs-languages: rust
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]

= Pay HEZ as a Fee

This feature allows you to set HEZ (or any other registered asset) as a fee for transaction execution. Here are the steps that you will need to execute to support it.

== Configuration

All you need to configure to start using this feature is an Oracle. You can use some service from any oracle service (like Chainlink, Pyth and others who support Bizinikiwi runtimes) or set up a development-mode solution.

=== 1. Add Oracle Members

To add oracle members, you'll need to submit transactions with sudo or root privileges:

[source,bash]
----
# Add a member (replace with actual address)
subxt tx --url "ws://localhost:9944" \
    --suri "<sudo-suri>" \
    pezpallet-membership add_member \
    --account "<oracle-public-key>"

# Verify members
subxt query --url "ws://localhost:9944" \
    pezpallet-membership members
----

=== 2. Format Oracle Values

Oracle values should be formatted according to your runtime's `OracleValue` type. Here's an example for price data:

// TODO: fix values
[source,rust]
----
// Example price format
type Price = FixedU128;  // price with 18 decimals
type CurrencyId = u32;   // for generic template, for EVM we use u128
----

=== 3. Submit Oracle Data

Here's how to submit oracle data using the CLI:

[source,bash]
----
# Submit price feed for HEZ/USD
subxt tx --url "ws://localhost:9944" \
    --suri "<oracle-member-key>" \
    orml-oracle feed_values \
    --values '[[1, "12000000000000000000"]]'  # replace the CurrencyId with HEZ's AssetId and the number with price of native HEZ in native tokens
----

=== 4. Query Oracle Data

To verify the submitted data:

[source,bash]
----
# Query latest price
subxt query --url "ws://localhost:9944" \
    orml-oracle get \
    --key 1  # CurrencyId
----

== Development Testing

For development purposes, you can set up automated price feeds:

[source,bash]
----
#!/bin/bash

while true; do
    # Generate random price between $10-15
    PRICE=$((RANDOM % 5000 + 10000))
    PRICE_WITH_DECIMALS="${PRICE}000000000000000"
    
    subxt tx --url "ws://localhost:9944" \
        --suri "<oracle-member-key>" \
        orml-oracle feed_values \
        --values "[[1, \"$PRICE_WITH_DECIMALS\"]]"
        
    sleep 60  # Wait 1 minute before next update
done
----

== Opting out

If you want to opt out of this feature, then you can just replace the `pezpallet_asset_tx_payment` with `pezpallet_transaction_payment` piece in `SignedExtra`:

[source,patch]
pub type SignedExtra = (
...
-    pezpallet_asset_tx_payment::ChargeAssetTxPayment<Runtime>,
+    pezpallet_transaction_payment::ChargeTransactionPayment<Runtime>,
...
);