Skip to content

Commit

Permalink
add latest repsonse expiration to sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagaprasadvr committed Oct 31, 2023
1 parent 74d9d88 commit c34a425
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 25 deletions.
10 changes: 5 additions & 5 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"@bundlr-network/client": "^0.8.8",
"@convergence-rfq/beet": "0.7.10",
"@convergence-rfq/beet-solana": "0.4.11",
"@convergence-rfq/psyoptions-american-instrument": "2.2.13",
"@convergence-rfq/psyoptions-european-instrument": "2.2.13",
"@convergence-rfq/rfq": "2.2.13",
"@convergence-rfq/risk-engine": "2.2.13",
"@convergence-rfq/spot-instrument": "2.2.13",
"@convergence-rfq/psyoptions-american-instrument": "2.2.14",
"@convergence-rfq/psyoptions-european-instrument": "2.2.14",
"@convergence-rfq/rfq": "2.2.14",
"@convergence-rfq/risk-engine": "2.2.14",
"@convergence-rfq/spot-instrument": "2.2.14",
"@coral-xyz/borsh": "^0.26.0",
"@mithraic-labs/psy-american": "^0.2.3",
"@mithraic-labs/tokenized-euros": "^0.2.3",
Expand Down
17 changes: 17 additions & 0 deletions packages/js/src/plugins/rfqModule/operations/respondToRfq.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRespondToRfqInstruction } from '@convergence-rfq/rfq';
import { PublicKey, AccountMeta, ComputeBudgetProgram } from '@solana/web3.js';

import BN from 'bn.js';
import { SendAndConfirmTransactionResponse } from '../../rpcModule';
import { assertResponse, Response } from '../models/Response';
import { Convergence } from '../../../Convergence';
Expand Down Expand Up @@ -99,6 +100,11 @@ export type RespondToRfqInput = {
*/
ask?: Quote;

/**
* The optional response expirationTimestamp in milliseconds.
*/
expirationTimestamp?: number;

/**
* The address of the RFQ account.
*/
Expand Down Expand Up @@ -239,6 +245,7 @@ export const respondToRfqBuilder = async (
user: maker.publicKey,
programs,
}),
expirationTimestamp,
} = params;

if (!bid && !ask) {
Expand All @@ -247,6 +254,15 @@ export const respondToRfqBuilder = async (

const rfqModel = await convergence.rfqs().findRfqByAddress({ address: rfq });

let expirationTimestampBn: BN;
if (!expirationTimestamp) {
const rfqExpirationTimestamp =
rfqModel.creationTimestamp / 1_000 + rfqModel.activeWindow;
expirationTimestampBn = new BN(rfqExpirationTimestamp);
} else {
expirationTimestampBn = new BN(expirationTimestamp / 1_000);
}

const { response, pdaDistinguisher } =
await getNextResponsePdaAndDistinguisher(
convergence,
Expand Down Expand Up @@ -323,6 +339,7 @@ export const respondToRfqBuilder = async (
bid: bid && toSolitaQuote(bid, rfqModel.quoteAsset.getDecimals()),
ask: ask && toSolitaQuote(ask, rfqModel.quoteAsset.getDecimals()),
pdaDistinguisher,
expirationTimestamp: expirationTimestampBn,
}
),
signers: [maker],
Expand Down
5 changes: 5 additions & 0 deletions packages/js/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,11 @@ export const createRfq = async (
cvg: Convergence,
amount: number,
orderType: OrderType,
activeWindow?: number,
rfqType: 'open' | 'fixed-base' | 'fixed-quote' = 'fixed-base',
quoteMintPk = QUOTE_MINT_PK,
baseMintPk = BASE_MINT_BTC_PK
// 10 minutes
) => {
let instrumentAmount = 1;
let fixedSizeAmount = 1;
Expand All @@ -429,6 +431,7 @@ export const createRfq = async (
orderType,
fixedSize: { type: rfqType, amount: fixedSizeAmount },
quoteAsset: await SpotQuoteInstrument.create(cvg, quoteMint),
activeWindow,
});
return { rfq, response };
};
Expand All @@ -438,6 +441,7 @@ export const respondToRfq = async (
rfq: Rfq,
bid?: number,
ask?: number,
responseExpirationTimestamp?: number,
legsMultiplier?: number
) => {
if (!bid && !ask) {
Expand All @@ -448,6 +452,7 @@ export const respondToRfq = async (
rfq: rfq.address,
bid: bid ? { price: bid, legsMultiplier } : undefined,
ask: ask ? { price: ask, legsMultiplier } : undefined,
expirationTimestamp: responseExpirationTimestamp,
});
};

Expand Down
20 changes: 20 additions & 0 deletions packages/js/tests/unit/response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,24 @@ describe('unit.response', () => {
expect(r.rfq.toBase58()).toEqual(rfq0.address.toBase58())
);
});

it('Cannot confirm Response if response is expired', async () => {
const rfq = await createRfq(takerCvg, amount0, 'buy', 3);

const res = await respondToRfq(
makerCvg,
rfq.rfq,
undefined,
amount1,
Date.now() / 1_000 + 2
);

expect(
await makerCvg.rfqs().confirmResponse({
response: res.rfqResponse.address,
rfq: rfq.rfq.address,
side: 'ask',
})
).toThrowError('Response is expired');
});
});
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1240,54 +1240,54 @@
bn.js "^5.2.0"
debug "^4.3.3"

"@convergence-rfq/[email protected].13":
version "2.2.13"
resolved "https://registry.yarnpkg.com/@convergence-rfq/psyoptions-american-instrument/-/psyoptions-american-instrument-2.2.13.tgz#c4d0ab251ecc325a382e0e75ca743711a49fc7c7"
integrity sha512-DAsERQdjTxPhayB3GElWKlKsFPrd42XnG+CLg6+7Q1SZGDQFB19G7UafcwJJmik5wwrxcWJHLCONhmPZEmLCAg==
"@convergence-rfq/[email protected].14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@convergence-rfq/psyoptions-american-instrument/-/psyoptions-american-instrument-2.2.14.tgz#25e2da5709ae4dd3d031d54112f10016003cd2ae"
integrity sha512-8uEDCLPqc26nCwPWpm43xFN9wv3x9BSWf2h0kUhfmGUFnyVH7VfIrMNlxJwC2S6329TtlnTyl5bDbO2a+aMPQw==
dependencies:
"@convergence-rfq/beet" "^0.7.10"
"@convergence-rfq/beet-solana" "^0.4.11"
"@solana/spl-token" "^0.3.5"
"@solana/web3.js" "^1.56.2"
bn.js "^5.2.0"

"@convergence-rfq/[email protected].13":
version "2.2.13"
resolved "https://registry.yarnpkg.com/@convergence-rfq/psyoptions-european-instrument/-/psyoptions-european-instrument-2.2.13.tgz#1915a640040011eb193d6b96dc26ca3ed992941e"
integrity sha512-S7jM0mrhjx3QiT62fJAKVWSBlqcXCpk+KESNvy7mdSnJZGgpVTnyQeLWSqwO2cDElDOLn4Z40yfRTRgxssuPnw==
"@convergence-rfq/[email protected].14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@convergence-rfq/psyoptions-european-instrument/-/psyoptions-european-instrument-2.2.14.tgz#eff403b346cc28424b7fc34404615b29292b341e"
integrity sha512-6Ga6iRaP2aQmrCcwT7G15Oucuvq6ySqAYHijS1MIUfw/iP9uqbpYdb2eDdUBMY8lY9CTvwm3zZ9C4i1NLDQJog==
dependencies:
"@convergence-rfq/beet" "^0.7.10"
"@convergence-rfq/beet-solana" "^0.4.11"
"@solana/spl-token" "^0.3.5"
"@solana/web3.js" "^1.56.2"
bn.js "^5.2.0"

"@convergence-rfq/[email protected].13":
version "2.2.13"
resolved "https://registry.yarnpkg.com/@convergence-rfq/rfq/-/rfq-2.2.13.tgz#d78cd575ee176935c42ee178a51d6ee8e7637d89"
integrity sha512-0/QzK8roBoc/oCKVj/Z0gHeBYxjLvxlb1SqvmVlqlQPWjpoZfAojse04+g5c1LnUO9X0STU0Cn5tKDFbt0Jerg==
"@convergence-rfq/[email protected].14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@convergence-rfq/rfq/-/rfq-2.2.14.tgz#7b2ad2d33908f6cc17c776b7d2ce2ab80c70af8a"
integrity sha512-MGGVOrJ7zjoJrjd3WNpCX2upzrw6XipJuRU2MAuffVV53p5t7xS896MONW5eCt/Zp4ffvWO9PYh5s0dZkcs17g==
dependencies:
"@convergence-rfq/beet" "^0.7.10"
"@convergence-rfq/beet-solana" "^0.4.11"
"@solana/spl-token" "^0.3.5"
"@solana/web3.js" "^1.56.2"
bn.js "^5.2.0"

"@convergence-rfq/[email protected].13":
version "2.2.13"
resolved "https://registry.yarnpkg.com/@convergence-rfq/risk-engine/-/risk-engine-2.2.13.tgz#0449366fe33f31711f1c484e7e95d9871ffb9b23"
integrity sha512-koUzlOGm20/sH42IYkiM34NCL4lsNX7YO93rILgdmm68I31njx7gNxLneLvyebfMcvJiSF3NKdmbu3dpn/U8Qg==
"@convergence-rfq/[email protected].14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@convergence-rfq/risk-engine/-/risk-engine-2.2.14.tgz#1ecefeb27ea9233df8bab970953f2b41d1a538e4"
integrity sha512-mAhALsP5w/UEfwz4wn6p/6niTkOvjG4Ae5KXQH36g0KMwCHdFipr45ZPkqmiGAR0cT1PvOiz376qa566BUyt2Q==
dependencies:
"@convergence-rfq/beet" "^0.7.10"
"@convergence-rfq/beet-solana" "^0.4.11"
"@solana/spl-token" "^0.3.5"
"@solana/web3.js" "^1.56.2"
bn.js "^5.2.0"

"@convergence-rfq/[email protected].13":
version "2.2.13"
resolved "https://registry.yarnpkg.com/@convergence-rfq/spot-instrument/-/spot-instrument-2.2.13.tgz#06550c962f0f4e68ed277c551586b138fec5b329"
integrity sha512-C2l0/vALFR7SxPrVu0GvzlyYrLH/Uy2wZ5IyDHnn74Xt/SBUOx4VdB2F2mHyLl/KG+yLaMREfcmBB7ZV2FHEyQ==
"@convergence-rfq/[email protected].14":
version "2.2.14"
resolved "https://registry.yarnpkg.com/@convergence-rfq/spot-instrument/-/spot-instrument-2.2.14.tgz#5b7596022245045f44d3565d94deda658e034438"
integrity sha512-NTeiltgcM36akuXIwrXSAavoec61rQq1Z2siLM0TXG/wC9B8LGvDkXQdUfu0jqrgXe5auf2cPOxsq3E80AAEZg==
dependencies:
"@convergence-rfq/beet" "^0.7.10"
"@convergence-rfq/beet-solana" "^0.4.11"
Expand Down

0 comments on commit c34a425

Please sign in to comment.