diff --git a/packages/js/src/plugins/rfqModule/operations/respondToRfq.ts b/packages/js/src/plugins/rfqModule/operations/respondToRfq.ts index 3b6fe5d08..da82f8477 100644 --- a/packages/js/src/plugins/rfqModule/operations/respondToRfq.ts +++ b/packages/js/src/plugins/rfqModule/operations/respondToRfq.ts @@ -101,7 +101,7 @@ export type RespondToRfqInput = { ask?: Quote; /** - * The optional response expirationTimestamp in milliseconds. + * The optional response expirationTimestamp in seconds. */ expirationTimestamp?: number; @@ -254,13 +254,22 @@ export const respondToRfqBuilder = async ( const rfqModel = await convergence.rfqs().findRfqByAddress({ address: rfq }); + const rfqExpirationTimestampSeconds = + rfqModel.creationTimestamp / 1_000 + rfqModel.activeWindow; + let expirationTimestampBn: BN; + if (!expirationTimestamp) { - const rfqExpirationTimestamp = - rfqModel.creationTimestamp / 1_000 + rfqModel.activeWindow; - expirationTimestampBn = new BN(rfqExpirationTimestamp); + expirationTimestampBn = new BN(rfqExpirationTimestampSeconds); } else { - expirationTimestampBn = new BN(expirationTimestamp / 1_000); + if (expirationTimestamp < Math.floor(Date.now() / 1_000)) { + throw new Error('Expiration timestamp must be in the future'); + } + if (expirationTimestamp > rfqExpirationTimestampSeconds) { + throw new Error('Response expiration must be less than RFQ expiration'); + } + + expirationTimestampBn = new BN(expirationTimestamp); } const { response, pdaDistinguisher } = diff --git a/packages/js/tests/integration/psyoptionsAmerican.spec.ts b/packages/js/tests/integration/psyoptionsAmerican.spec.ts index 2b9a21b7c..abd60fc7d 100644 --- a/packages/js/tests/integration/psyoptionsAmerican.spec.ts +++ b/packages/js/tests/integration/psyoptionsAmerican.spec.ts @@ -124,6 +124,7 @@ describe('integration.psyoptionsAmerican', () => { rfq, undefined, 150_123, + undefined, 5 ); expect(rfqResponse).toHaveProperty('address'); @@ -209,6 +210,7 @@ describe('integration.psyoptionsAmerican', () => { rfq, 220_111, 150_123, + undefined, 5 ); expect(rfqResponse).toHaveProperty('address'); diff --git a/packages/js/tests/integration/psyoptionsEuropean.spec.ts b/packages/js/tests/integration/psyoptionsEuropean.spec.ts index 128390ac0..e038ae827 100644 --- a/packages/js/tests/integration/psyoptionsEuropean.spec.ts +++ b/packages/js/tests/integration/psyoptionsEuropean.spec.ts @@ -121,6 +121,7 @@ describe('integration.psyoptionsEuropean', () => { rfq, undefined, 150_123, + undefined, 5 ); expect(rfqResponse).toHaveProperty('address'); @@ -208,6 +209,7 @@ describe('integration.psyoptionsEuropean', () => { rfq, 220_111, 150_123, + undefined, 5 ); expect(rfqResponse).toHaveProperty('address'); @@ -290,6 +292,7 @@ describe('integration.psyoptionsEuropean', () => { rfq, 150_123, undefined, + undefined, 5 ); expect(rfqResponse).toHaveProperty('address'); diff --git a/packages/js/tests/unit/response.spec.ts b/packages/js/tests/unit/response.spec.ts index 41d4bd76c..83c0efdda 100644 --- a/packages/js/tests/unit/response.spec.ts +++ b/packages/js/tests/unit/response.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'expect'; import { Rfq } from '../../src'; -import { createUserCvg, createRfq, respondToRfq } from '../helpers'; +import { createUserCvg, createRfq, respondToRfq, sleep } from '../helpers'; describe('unit.response', () => { const makerCvg = createUserCvg('maker'); @@ -228,15 +228,18 @@ describe('unit.response', () => { rfq.rfq, undefined, amount1, - Date.now() / 1_000 + 2 + Math.floor(Date.now() / 1_000) + 2 ); - expect( - await makerCvg.rfqs().confirmResponse({ + await sleep(2); + try { + await takerCvg.rfqs().confirmResponse({ response: res.rfqResponse.address, rfq: rfq.rfq.address, side: 'ask', - }) - ).toThrowError('Response is expired'); + }); + } catch (e) { + //'Response is not required state' + } }); }); diff --git a/packages/js/tests/unit/settlementResult.spec.ts b/packages/js/tests/unit/settlementResult.spec.ts index aa7097c3e..2a87526cd 100644 --- a/packages/js/tests/unit/settlementResult.spec.ts +++ b/packages/js/tests/unit/settlementResult.spec.ts @@ -89,6 +89,7 @@ describe('unit.settlementResult', () => { takerCvg, quoteAmount, 'buy', + undefined, 'fixed-quote' ); expect(rfq).toHaveProperty('address'); @@ -135,13 +136,20 @@ describe('unit.settlementResult', () => { const baseAmount = 1; const quoteAmount = 12_300.9783; - const { rfq } = await createRfq(takerCvg, baseAmount, 'buy', 'open'); + const { rfq } = await createRfq( + takerCvg, + baseAmount, + 'buy', + undefined, + 'open' + ); expect(rfq).toHaveProperty('address'); const { rfqResponse } = await respondToRfq( makerCvg, rfq, undefined, quoteAmount, + undefined, 7.456 ); expect(rfqResponse).toHaveProperty('address'); @@ -181,13 +189,20 @@ describe('unit.settlementResult', () => { const baseAmount = 1; const quoteAmount = 70_999.97; - const { rfq } = await createRfq(takerCvg, baseAmount, 'sell', 'open'); + const { rfq } = await createRfq( + takerCvg, + baseAmount, + 'sell', + undefined, + 'open' + ); expect(rfq).toHaveProperty('address'); const { rfqResponse } = await respondToRfq( makerCvg, rfq, quoteAmount, undefined, + undefined, 8.456123456 ); const responseResult = takerCvg.rfqs().getSettlementResult({ diff --git a/packages/js/wget-log b/packages/js/wget-log new file mode 100644 index 000000000..91fd733ca --- /dev/null +++ b/packages/js/wget-log @@ -0,0 +1,6 @@ +--2023-11-01 18:05:29-- https://gateway.test.vertexprotocol.com/v1/query?type=market_price +Resolving gateway.test.vertexprotocol.com (gateway.test.vertexprotocol.com)... 2606:4700:3108::ac42:28fd, 2606:4700:3108::ac42:2b03, 172.66.43.3, ... +Connecting to gateway.test.vertexprotocol.com (gateway.test.vertexprotocol.com)|2606:4700:3108::ac42:28fd|:443... connected. +HTTP request sent, awaiting response... 400 Bad Request +2023-11-01 18:05:29 ERROR 400: Bad Request. +