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

feat: order request expiry #204

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions npm-admin-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm-admin-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@monaco-protocol/admin-client",
"version": "10.0.0",
"version": "10.1.0-dev",
"description": "Admin interface package for the Monaco Protocol on Solana",
"author": "Monaco Protocol",
"license": "MIT",
Expand Down
10 changes: 7 additions & 3 deletions npm-client/docs/endpoints/create_order_instruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ but the orderPk returned by this function will match the PDA of the order accoun
* `forOutcome` **[boolean][8]** {boolean} whether the order is for or against the outcome
* `price` **[number][7]** {number} price at which the order should be created, the price should be present on the outcome pool for the market
* `stake` **BN** {BN} raw token value of the order taking into account the decimal amount of the token associated with the market
* `priceLadderPk` **PublicKey?** {PublicKey} Optional: publicKey of the price ladder associated with the market outcome - if there is one
* `productPk` **PublicKey?** {PublicKey} Optional: publicKey of product account this order was created on
* `options` **{priceLadderPk: PublicKey?, productPk: PublicKey?, expiresOn: BN?}** 

* `options.priceLadderPk` {PublicKey} Optional: publicKey of the price ladder associated with the market outcome - if there is one
* `options.productPk` {PublicKey} Optional: publicKey of product account this order was created on
* `options.expiresOn` {BN} Optional: unix timestamp (seconds) defining expiration of request; if omitted or null or undefined order request will never expire

### Examples

Expand All @@ -67,7 +70,8 @@ const price = 1.5
const stake = 20,000,000,000
const priceLadderPk = new PublicKey('Dopn2C9R4G6GaPwFAxaNWM33D7o1PXyYZtBBDFZf9cEhH')
const productPk = new PublicKey('yourNewExcHangeZf9cEhHopn2C9R4G6GaPwFAxaNWM33D')
const instruction = await buildOrderInstruction(program, marketPk, marketOutcomeIndex, forOutcome, price, stake, , productPk)
const expiresOn = new BN(1010101010101)
const instruction = await buildOrderInstruction(program, marketPk, marketOutcomeIndex, forOutcome, price, stake, {priceLadderPk, productPk, expiresOn} )
```

Returns **OrderInstructionResponse** derived order publicKey and the instruction to perform a create order transaction
Expand Down
3 changes: 2 additions & 1 deletion npm-client/docs/types/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Type: {purchaser: PublicKey, market: PublicKey, marketOutcomeIndex: [number][26]

## OrderRequest

Type: {purchaser: PublicKey, marketOutcomeIndex: [number][26], forOutcome: [boolean][27], product: (PublicKey | null), stake: BN, expectedPrice: [number][26], delayExpirationTimestamp: BN, productCommissionRate: [number][26], distinctSeed: [Array][28]<[number][26]>, creationTimestamp: BN}
Type: {purchaser: PublicKey, marketOutcomeIndex: [number][26], forOutcome: [boolean][27], product: (PublicKey | null), stake: BN, expectedPrice: [number][26], delayExpirationTimestamp: BN, productCommissionRate: [number][26], distinctSeed: [Array][28]<[number][26]>, creationTimestamp: BN, expiresOn: BN}

### Properties

Expand All @@ -76,6 +76,7 @@ Type: {purchaser: PublicKey, marketOutcomeIndex: [number][26], forOutcome: [bool
* `productCommissionRate` **[number][26]**&#x20;
* `distinctSeed` **[Array][28]<[number][26]>**&#x20;
* `creationTimestamp` **BN**&#x20;
* `expiresOn` **BN**&#x20;

## OrderInstructionResponse

Expand Down
4 changes: 2 additions & 2 deletions npm-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@monaco-protocol/client",
"version": "11.0.0",
"version": "11.1.0-dev",
"description": "Interface package for the Monaco Protocol on Solana",
"author": "Monaco Protocol",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions npm-client/src/create_order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export async function createOrder(
forOutcome,
price,
stake,
priceLadderPk,
productPk,
{
priceLadderPk,
productPk,
},
);

response.addResponseData({
Expand Down
27 changes: 18 additions & 9 deletions npm-client/src/create_order_instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ export async function buildOrderInstructionUIStake(
forOutcome,
price,
stakeInteger.data.stakeInteger,
priceLadderPk,
productPk,
{
priceLadderPk,
productPk,
},
);
}

Expand All @@ -69,8 +71,10 @@ export async function buildOrderInstructionUIStake(
* @param forOutcome {boolean} whether the order is for or against the outcome
* @param price {number} price at which the order should be created, the price should be present on the outcome pool for the market
* @param stake {BN} raw token value of the order taking into account the decimal amount of the token associated with the market
* @param priceLadderPk {PublicKey} Optional: publicKey of the price ladder associated with the market outcome - if there is one
* @param productPk {PublicKey} Optional: publicKey of product account this order was created on
* @param options
* @param options.priceLadderPk {PublicKey} Optional: publicKey of the price ladder associated with the market outcome - if there is one
* @param options.productPk {PublicKey} Optional: publicKey of product account this order was created on
* @param options.expiresOn {BN} Optional: unix timestamp (seconds) defining expiration of request; if omitted or null or undefined order request will never expire
* @returns {OrderInstructionResponse} derived order publicKey and the instruction to perform a create order transaction
*
* @example
Expand All @@ -82,7 +86,8 @@ export async function buildOrderInstructionUIStake(
* const stake = 20,000,000,000
* const priceLadderPk = new PublicKey('Dopn2C9R4G6GaPwFAxaNWM33D7o1PXyYZtBBDFZf9cEhH')
* const productPk = new PublicKey('yourNewExcHangeZf9cEhHopn2C9R4G6GaPwFAxaNWM33D')
* const instruction = await buildOrderInstruction(program, marketPk, marketOutcomeIndex, forOutcome, price, stake, , productPk)
* const expiresOn = new BN(1010101010101)
* const instruction = await buildOrderInstruction(program, marketPk, marketOutcomeIndex, forOutcome, price, stake, {priceLadderPk, productPk, expiresOn} )
*/
export async function buildOrderInstruction(
program: Program,
Expand All @@ -91,8 +96,11 @@ export async function buildOrderInstruction(
forOutcome: boolean,
price: number,
stake: BN,
priceLadderPk?: PublicKey,
productPk?: PublicKey,
options: {
priceLadderPk?: PublicKey;
productPk?: PublicKey;
expiresOn?: BN;
},
): Promise<ClientResponse<OrderInstructionResponse>> {
const response = new ResponseFactory({} as OrderInstructionResponse);
const provider = program.provider as AnchorProvider;
Expand Down Expand Up @@ -135,6 +143,7 @@ export async function buildOrderInstruction(
stake: stake,
price: price,
distinctSeed: distinctSeed,
expiresOn: options.expiresOn ?? null,
})
.accounts({
reservedOrder: orderPk,
Expand All @@ -147,12 +156,12 @@ export async function buildOrderInstruction(
marketOutcome: marketAccounts.data.marketOutcomePda,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
priceLadder: priceLadderPk == undefined ? null : priceLadderPk,
priceLadder: options.priceLadderPk ?? null,
purchaserToken: purchaserTokenAccount.data.associatedTokenAccount,
marketEscrow: marketAccounts.data.escrowPda,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
product: productPk == undefined ? null : productPk,
product: options.productPk ?? null,
orderRequestQueue: marketAccounts.data.marketOrderRequestQueuePda,
})
.instruction();
Expand Down
1 change: 1 addition & 0 deletions npm-client/types/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type OrderRequest = {
productCommissionRate: number;
distinctSeed: number[];
creationTimestamp: BN;
expiresOn: BN;
};

export type OrderInstructionResponse = {
Expand Down
2 changes: 1 addition & 1 deletion programs/monaco_protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "monaco_protocol"
version = "0.14.0"
version = "0.14.1-dev"
description = "Created with Anchor"
edition = "2018"

Expand Down
2 changes: 2 additions & 0 deletions programs/monaco_protocol/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum CoreError {
CreationMarketMismatch,
#[msg("Order Creation: purchaser mismatch")]
CreationPurchaserMismatch,
#[msg("Order Creation: expired")]
CreationExpired,

#[msg("Order Request Creation: request queue is full")]
OrderRequestCreationQueueFull,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn update_on_order_match(
mod tests {
use super::*;
use crate::instructions::market_position;
use crate::state::market_order_request_queue::OrderRequest;
use crate::state::market_order_request_queue::{mock_order_request, OrderRequest};
use test_case::test_case;

struct OrderData {
Expand Down Expand Up @@ -228,9 +228,10 @@ mod tests {
let mut market_position = market_position(vec![0_i128; 3], vec![0_u64; 3]);

for order_data in orders.into_vec() {
let order_request = order_request(
order_data.outcome_index as u16,
let order_request = mock_order_request(
Pubkey::new_unique(),
order_data.for_outcome,
order_data.outcome_index as u16,
order_data.stake,
order_data.price,
);
Expand Down Expand Up @@ -277,26 +278,6 @@ mod tests {
}
}

fn order_request(
market_outcome_index: u16,
for_outcome: bool,
stake: u64,
expected_price: f64,
) -> OrderRequest {
OrderRequest {
purchaser: Default::default(),
market_outcome_index,
for_outcome,
product: None,
stake,
expected_price,
delay_expiration_timestamp: 0,
product_commission_rate: 0f64,
distinct_seed: [0; 16],
creation_timestamp: 0,
}
}

fn market_position(
market_outcome_sums: Vec<i128>,
unmatched_exposures: Vec<u64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn on_order_match(

#[cfg(test)]
mod test {
use crate::state::market_order_request_queue::OrderRequest;
use crate::state::market_order_request_queue::{mock_order_request, OrderRequest};
use crate::state::{
market_account::{MarketOrderBehaviour, MarketStatus},
market_matching_pool_account::Cirque,
Expand Down Expand Up @@ -430,27 +430,6 @@ mod test {
}
}

fn mock_order_request(
purchaser: Pubkey,
for_outcome: bool,
outcome: u16,
stake: u64,
price: f64,
) -> OrderRequest {
OrderRequest {
purchaser,
market_outcome_index: outcome,
for_outcome,
stake,
expected_price: price,
product: None,
product_commission_rate: 0.0,
delay_expiration_timestamp: 0,
distinct_seed: [0; 16],
creation_timestamp: 0,
}
}

fn mock_order(market_pk: Pubkey, order_request: OrderRequest, payer_pk: Pubkey) -> Order {
Order {
market: market_pk,
Expand Down
Loading