Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #168

Merged
merged 11 commits into from
Oct 4, 2023
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ANCHOR_PROVIDER_URL=https://api.devnet.solana.com
ANCHOR_WALLET=/Users/pindaroso/.config/solana/id.json
ANCHOR_WALLET=~/.config/solana/id.json
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
**Note:** Version 0 of Semantic Versioning is handled differently from version 1 and above.
The minor version will be incremented upon a breaking change and the patch version will be incremented for features.

## [2.2.13] - 2023-10-04

### Fixes

- psyoptions-american: Refactored PsyOptions American instrument to handle call and put logic. See PR ([#166](https://github.com/convergence-rfq/convergence-program-library/pull/166)) for full details.

## [2.2.12] - 2023-08-17

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion psyoptions-american-instrument/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@convergence-rfq/psyoptions-american-instrument",
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
6 changes: 2 additions & 4 deletions psyoptions-american-instrument/program/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ pub struct ValidateData<'info> {

/// user provided
pub american_meta: Account<'info, OptionMarket>,
#[account(constraint = american_meta.underlying_asset_mint == mint_info.mint_address @ PsyoptionsAmericanError::PassedMintDoesNotMatch)]
pub mint_info: Account<'info, MintInfo>,
#[account(constraint = american_meta.quote_asset_mint == quote_mint.mint_address @ PsyoptionsAmericanError::PassedMintDoesNotMatch)]
pub quote_mint: Account<'info, MintInfo>,
pub underlying_asset_mint: Account<'info, MintInfo>,
pub stable_asset_mint: Account<'info, MintInfo>,
}

#[derive(Accounts)]
Expand Down
57 changes: 46 additions & 11 deletions psyoptions-american-instrument/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use errors::PsyoptionsAmericanError;
use instructions::*;
use rfq::state::MintType;
use rfq::state::{AssetIdentifier, AuthoritySide};
use risk_engine::state::OptionType;
use state::{AssetIdentifierDuplicate, ParsedLegData};
use state::{AuthoritySideDuplicate, TOKEN_DECIMALS};

Expand All @@ -30,8 +31,8 @@ pub mod psyoptions_american_instrument {
) -> Result<()> {
let ValidateData {
american_meta,
mint_info,
quote_mint,
underlying_asset_mint,
stable_asset_mint,
..
} = &ctx.accounts;

Expand All @@ -49,30 +50,64 @@ pub mod psyoptions_american_instrument {
american_meta_address == american_meta.key(),
PsyoptionsAmericanError::PassedAmericanMetaDoesNotMatch
);

let option_type = option_common_data.option_type;
let underlying_amount_per_contract: u64;
let strike_price: u64;
let underlying_mint: Pubkey;
let quote_mint: Pubkey;
let expected_mint = american_meta.option_mint;

match option_type {
OptionType::Call => {
underlying_amount_per_contract = 10_u64.pow(underlying_asset_mint.decimals as u32);
strike_price = option_common_data.strike_price;
quote_mint = stable_asset_mint.mint_address;
underlying_mint = underlying_asset_mint.mint_address;
}
OptionType::Put => {
underlying_amount_per_contract = option_common_data.strike_price;
strike_price = 10_u64.pow(underlying_asset_mint.decimals as u32);
quote_mint = underlying_asset_mint.mint_address;
underlying_mint = stable_asset_mint.mint_address;
}
}

require!(
mint_address == expected_mint,
PsyoptionsAmericanError::PassedMintDoesNotMatch
);

require!(
option_common_data.underlying_amount_per_contract
== american_meta.underlying_amount_per_contract,
PsyoptionsAmericanError::PassedUnderlyingAmountPerContractDoesNotMatch
underlying_mint == american_meta.underlying_asset_mint,
PsyoptionsAmericanError::PassedMintDoesNotMatch
);
require_eq!(
option_common_data.underlying_amound_per_contract_decimals,
mint_info.decimals,

require!(
quote_mint == american_meta.quote_asset_mint,
PsyoptionsAmericanError::PassedMintDoesNotMatch
);

require!(
underlying_amount_per_contract == american_meta.underlying_amount_per_contract,
PsyoptionsAmericanError::PassedUnderlyingAmountPerContractDoesNotMatch
);

require!(
option_common_data.strike_price == american_meta.quote_amount_per_contract,
strike_price == american_meta.quote_amount_per_contract,
PsyoptionsAmericanError::PassedStrikePriceDoesNotMatch
);
require_eq!(
option_common_data.strike_price_decimals,
quote_mint.decimals,
stable_asset_mint.decimals,
PsyoptionsAmericanError::PassedStrikePriceDecimalsDoesNotMatch
);
require_eq!(
option_common_data.underlying_amound_per_contract_decimals,
underlying_asset_mint.decimals,
PsyoptionsAmericanError::PassedUnderlyingAmountPerContractDecimalsDoesNotMatch
);

require!(
option_common_data.expiration_timestamp == american_meta.expiration_unix_timestamp,
PsyoptionsAmericanError::PassedExpirationTimestampDoesNotMatch
Expand All @@ -84,7 +119,7 @@ pub mod psyoptions_american_instrument {
);

if let (Some(passed_base_asset_index), MintType::AssetWithRisk { base_asset_index }) =
(base_asset_index, mint_info.mint_type)
(base_asset_index, underlying_asset_mint.mint_type)
{
require!(
passed_base_asset_index == u16::from(base_asset_index),
Expand Down
2 changes: 1 addition & 1 deletion psyoptions-european-instrument/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@convergence-rfq/psyoptions-european-instrument",
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
8 changes: 4 additions & 4 deletions psyoptions-european-instrument/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod psyoptions_european_instrument {
) -> Result<()> {
let ValidateData {
euro_meta,
mint_info,
underlying_asset_mint,
..
} = &ctx.accounts;

Expand Down Expand Up @@ -89,7 +89,7 @@ pub mod psyoptions_european_instrument {
);

if let (Some(passed_base_asset_index), MintType::AssetWithRisk { base_asset_index }) =
(base_asset_index, mint_info.mint_type)
(base_asset_index, underlying_asset_mint.mint_type)
{
require!(
passed_base_asset_index == u16::from(base_asset_index),
Expand Down Expand Up @@ -331,8 +331,8 @@ pub struct ValidateData<'info> {

/// user provided
pub euro_meta: Account<'info, EuroMeta>,
#[account(constraint = euro_meta.underlying_mint == mint_info.mint_address @ PsyoptionsEuropeanError::PassedMintDoesNotMatch)]
pub mint_info: Account<'info, MintInfo>,
#[account(constraint = euro_meta.underlying_mint == underlying_asset_mint.mint_address @ PsyoptionsEuropeanError::PassedMintDoesNotMatch)]
pub underlying_asset_mint: Account<'info, MintInfo>,
}

#[derive(Accounts)]
Expand Down
2 changes: 1 addition & 1 deletion rfq/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@convergence-rfq/rfq",
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion risk-engine/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@convergence-rfq/risk-engine",
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion spot-instrument/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@convergence-rfq/spot-instrument",
"version": "2.2.12",
"version": "2.2.13",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down
Loading
Loading