lez-programs/artifacts/stablecoin-idl.json
r4bbit fe9d919299 feat(twap-oracle): implement CreatePriceObservations instruction
Adds the CreatePriceObservations instruction to the TWAP oracle program.
The instruction initialises a PriceObservations PDA for a given price
source account and time window, writing the initial tick and timestamp
as the first entry.

Key design decisions:

- Per-window accounts: each (price_source, window_duration) pair maps to
  a distinct PriceObservations PDA. The window duration is baked into the
  PDA seed so a single price source can support multiple TWAP windows
  (24h, 7d, 30d) at independent sampling rates without sharing a buffer.

- window_duration not stored on struct: it is implicit in the PDA address.
  Any reader that located the account already knows the window duration
  used to derive it. Storing it would be redundant.

- Authorization is implicit: the PriceObservations PDA is derived from
  the price source account ID, so is_authorized = true on the price source
  proves the caller controls it without a redundant authority field.

- Impersonation is prevented by the PDA check: passing a controlled price
  source with a victim's observations account ID fails immediately because
  the computed PDA (from the attacker's source) does not match.

Closes #126
2026-06-09 13:23:46 +02:00

358 lines
7.2 KiB
JSON

{
"version": "0.1.0",
"name": "stablecoin",
"instructions": [
{
"name": "open_position",
"accounts": [
{
"name": "owner",
"writable": false,
"signer": false,
"init": false
},
{
"name": "position",
"writable": false,
"signer": false,
"init": false
},
{
"name": "vault",
"writable": false,
"signer": false,
"init": false
},
{
"name": "user_holding",
"writable": false,
"signer": false,
"init": false
},
{
"name": "token_definition",
"writable": false,
"signer": false,
"init": false
}
],
"args": [
{
"name": "collateral_amount",
"type": "u128"
}
]
},
{
"name": "withdraw_collateral",
"accounts": [
{
"name": "owner",
"writable": false,
"signer": false,
"init": false
},
{
"name": "position",
"writable": false,
"signer": false,
"init": false
},
{
"name": "vault",
"writable": false,
"signer": false,
"init": false
},
{
"name": "destination",
"writable": false,
"signer": false,
"init": false
}
],
"args": [
{
"name": "amount",
"type": "u128"
}
]
},
{
"name": "repay_debt",
"accounts": [
{
"name": "owner",
"writable": false,
"signer": false,
"init": false
},
{
"name": "position",
"writable": false,
"signer": false,
"init": false
},
{
"name": "stablecoin_definition",
"writable": false,
"signer": false,
"init": false
},
{
"name": "user_stablecoin_holding",
"writable": false,
"signer": false,
"init": false
}
],
"args": [
{
"name": "amount",
"type": "u128"
}
]
}
],
"accounts": [
{
"name": "Position",
"type": {
"kind": "struct",
"fields": [
{
"name": "collateral_vault_id",
"type": "account_id"
},
{
"name": "collateral_definition_id",
"type": "account_id"
},
{
"name": "collateral_amount",
"type": "u128"
},
{
"name": "debt_amount",
"type": "u128"
}
]
}
},
{
"name": "TokenDefinition",
"type": {
"kind": "enum",
"variants": [
{
"name": "Fungible",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "total_supply",
"type": "u128"
},
{
"name": "metadata_id",
"type": {
"option": "account_id"
}
}
]
},
{
"name": "NonFungible",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "printable_supply",
"type": "u128"
},
{
"name": "metadata_id",
"type": "account_id"
}
]
}
]
}
},
{
"name": "TokenHolding",
"type": {
"kind": "enum",
"variants": [
{
"name": "Fungible",
"fields": [
{
"name": "definition_id",
"type": "account_id"
},
{
"name": "balance",
"type": "u128"
}
]
},
{
"name": "NftMaster",
"fields": [
{
"name": "definition_id",
"type": "account_id"
},
{
"name": "print_balance",
"type": "u128"
}
]
},
{
"name": "NftPrintedCopy",
"fields": [
{
"name": "definition_id",
"type": "account_id"
},
{
"name": "owned",
"type": "bool"
}
]
}
]
}
},
{
"name": "TokenMetadata",
"type": {
"kind": "struct",
"fields": [
{
"name": "definition_id",
"type": "account_id"
},
{
"name": "standard",
"type": {
"defined": "MetadataStandard"
}
},
{
"name": "uri",
"type": "string"
},
{
"name": "creators",
"type": "string"
},
{
"name": "primary_sale_date",
"type": "u64"
}
]
}
},
{
"name": "PriceObservations",
"type": {
"kind": "struct",
"fields": [
{
"name": "price_source_id",
"type": "account_id"
},
{
"name": "write_index",
"type": "u32"
},
{
"name": "total_entries",
"type": "u64"
},
{
"name": "last_recorded_tick",
"type": "i32"
},
{
"name": "entries",
"type": {
"vec": {
"defined": "ObservationEntry"
}
}
}
]
}
},
{
"name": "OraclePriceAccount",
"type": {
"kind": "struct",
"fields": [
{
"name": "base_asset",
"type": "account_id"
},
{
"name": "quote_asset",
"type": "account_id"
},
{
"name": "price",
"type": "u128"
},
{
"name": "timestamp",
"type": "u64"
},
{
"name": "source_id",
"type": "string"
},
{
"name": "confidence_interval",
"type": "u128"
}
]
}
}
],
"types": [
{
"name": "ObservationEntry",
"kind": "struct",
"fields": [
{
"name": "timestamp",
"type": "u64"
},
{
"name": "tick_cumulative",
"type": "i64"
}
]
},
{
"name": "MetadataStandard",
"kind": "enum",
"variants": [
{
"name": "Simple"
},
{
"name": "Expanded"
}
]
}
],
"instruction_type": "stablecoin_core::Instruction"
}