Stork Documentation
Ask or search…
K

TWAP and Funding Fee Calculations

In addition to streaming index and mark price feeds, Stork also offers a funding payment specific REST API that contains the following components:
  1. 1.
    Index TWAP
  2. 2.
    DEX Contract TWAP
  3. 3.
    Funding Fee computation

Index TWAP

The Index TWAP offers a 60-minute TWAP of the Stork index price on supported markets. This is useful for situations where exchanges prefer to perform TWAP calculations off-chain to reduce gas and storage fees.

DEX Contract TWAP

The DEX Contract TWAP is a DEX-specific integration that allows an exchange to offload additional components of the funding fee calculation to Stork. In this scenario, Stork uses its publisher network to integrate directly with the DEX to maintain a TWAP (currently 60-minute to match the index TWAP) of the exchange's contract price.

Funding Fee

The Index TWAP and Contract TWAP can be used to compute the funding fee at appropriate times, substantially reducing the storage and gas required compared to an on-chain equivalent.
The funding fee for a given timestamp is calculated as abs(contract - index).

Usage

While the Stork index TWAP is shared across all Funding Fee users, the DEX Contract TWAP requires a unique integration per client. Thus, the funding fee (and funding fee REST endpoint) will be unique per exchange.
Below is an example response from the REST endpoint, where <exchange> is changed to the name of the exchange integration:
{
"oracle_prices": {
"BTCUSD": {
"index_price": "27166101218448645836800",
"<exchange>_price": "21781140000000000000000",
"funding_fee": "5384961218448645836800",
"evm_signed_prices": {
"0x15328d261ac4f18039e59157de5e8c049140836f": {
"index_price": {
"price": "27166101218448645836800",
"external_asset_id": "BTCUSD",
"timestamped_signature": {
"signature": {
"r": "0x4542d26b164ff4d14e0e79a2a190a20620b5dcd9043b5ed7a1e920206881c7ed",
"s": "0x663de91bd921dda10d11e58f1ae0f79b55ef2ff60e23c022392c0312afa66562",
"v": "0x1b"
},
"timestamp": "1679518980",
"msg_hash": "0xfa7bee1c3f8e4ea4ad376c2c95810967f90b657d39496af9ccb2fd8de9314110"
}
},
"<exchange>_price": {
"price": "21781140000000000000000",
"external_asset_id": "BTCUSD",
"timestamped_signature": {
"signature": {
"r": "0xd2951552c1a6a655cd515b26c24acaf1442e350e1a5a1cffed1b4c84e595536b",
"s": "0x4581156f718239e6813802cda2d211073502b6447f7a6bfeb3f502167fb0b93f",
"v": "0x1c"
},
"timestamp": "1679518980",
"msg_hash": "0x1bc32a28bbda571517e87d16d327310b116228fda45f7328cc70dfa8a9503627"
}
},
"funding_fee": {
"price": "5384961218448645836800",
"external_asset_id": "BTCUSD",
"timestamped_signature": {
"signature": {
"r": "0x29603ca18c0726ae96e4c49b9d27b057ab402275744f71518a800d1495cbeaa",
"s": "0x4dd866dcde0e066987d5a1151fe0c13a0761a780a46d9518351684a71f0588e5",
"v": "0x1b"
},
"timestamp": "1679518980",
"msg_hash": "0xe9614dccbeee55639d732b484a87a7fd571bdde2c94e62a2e8beb16d2ba5c0e1"
}
}
}
}
},
"timestamp": "1679518980",
"type": "ORACLES_PRICE_TICK"
}
Contact us to set up your funding fee integration!