2026-05-11 14:51:50 +02:00
|
|
|
{
|
|
|
|
|
"version": "0.1.0",
|
|
|
|
|
"name": "stablecoin",
|
|
|
|
|
"instructions": [
|
feat(stablecoin): implement `open_position`
Adds the `open_position` instruction to the Stablecoin Program. The instruction
claims a per-owner `Position` PDA, initializes a collateral vault token holding
via a chained `Token::InitializeAccount` under the vault's PDA authority, and
moves `collateral_amount` from the user's holding into the vault with a chained
`Token::Transfer`. `Position` is persisted with `collateral_amount` and
`debt_amount = 0`; the debt path is deferred to `generate_debt`.
- Add `Position` struct, `OpenPosition` instruction variant, and
`compute_position_pda{,_seed}` / `compute_position_vault_pda{,_seed}` helpers
in `stablecoin_core` with domain-separated PDA seeds.
- Implement `open_position::open_position` mirroring the ATA `create` and AMM
`new_definition` patterns: authorization and uninitialized-state asserts, PDA
verification, and same-transaction chained `InitializeAccount` + `Transfer`.
- Wire the new instruction through the SPEL guest and regenerate the stablecoin
IDL artifact.
- Cover the happy path, all assertion paths, and PDA determinism /
non-collision in 11 new unit tests.
2026-05-11 17:14:27 -03:00
|
|
|
{
|
|
|
|
|
"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"
|
|
|
|
|
}
|
|
|
|
|
]
|
2026-05-11 14:51:50 +02:00
|
|
|
}
|
|
|
|
|
],
|
2026-05-12 13:04:59 -03:00
|
|
|
"accounts": [
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "OraclePriceAccount",
|
2026-05-12 13:04:59 -03:00
|
|
|
"type": {
|
|
|
|
|
"kind": "struct",
|
|
|
|
|
"fields": [
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "base_asset",
|
2026-05-12 13:04:59 -03:00
|
|
|
"type": "account_id"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "quote_asset",
|
2026-05-12 13:04:59 -03:00
|
|
|
"type": "account_id"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "price",
|
2026-05-12 13:04:59 -03:00
|
|
|
"type": "u128"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "timestamp",
|
|
|
|
|
"type": "u64"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "source_identifier",
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "confidence_interval",
|
2026-05-12 13:04:59 -03:00
|
|
|
"type": "u128"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-05-14 00:20:14 -03:00
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "Position",
|
2026-05-14 00:20:14 -03:00
|
|
|
"type": {
|
|
|
|
|
"kind": "struct",
|
|
|
|
|
"fields": [
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "collateral_vault_id",
|
2026-05-14 00:20:14 -03:00
|
|
|
"type": "account_id"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "collateral_definition_id",
|
2026-05-14 00:20:14 -03:00
|
|
|
"type": "account_id"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "collateral_amount",
|
2026-05-14 00:20:14 -03:00
|
|
|
"type": "u128"
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-05-14 01:24:57 -03:00
|
|
|
"name": "debt_amount",
|
2026-05-14 00:20:14 -03:00
|
|
|
"type": "u128"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-05-12 13:04:59 -03:00
|
|
|
{
|
|
|
|
|
"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"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"types": [
|
|
|
|
|
{
|
|
|
|
|
"name": "MetadataStandard",
|
|
|
|
|
"kind": "enum",
|
|
|
|
|
"variants": [
|
|
|
|
|
{
|
|
|
|
|
"name": "Simple"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "Expanded"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
2026-05-11 14:51:50 +02:00
|
|
|
"instruction_type": "stablecoin_core::Instruction"
|
|
|
|
|
}
|