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

Eng update get response state and action with response expiry #257

Merged
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
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @convergence-rfq/cli

## 4.5.18

### Patch Changes

- Updated dependencies
- @convergence-rfq/[email protected]

## 4.5.17

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@convergence-rfq/cli",
"description": "Official Convergence CLI",
"version": "4.5.17",
"version": "4.5.18",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -47,7 +47,7 @@
"cli": "ts-node src/index.ts"
},
"dependencies": {
"@convergence-rfq/sdk": "4.5.17",
"@convergence-rfq/sdk": "4.5.18",
"@solana/web3.js": "^1.73.0",
"@types/cookie": "^0.5.1",
"commander": "^10.0.0"
Expand Down
6 changes: 6 additions & 0 deletions packages/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @convergence-rfq/sdk

## 4.5.18

### Patch Changes

- Update getResponseStateAndAction to account for responseExpiration

## 4.5.17

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@convergence-rfq/sdk",
"description": "Official Convergence RFQ SDK",
"version": "4.5.17",
"version": "4.5.18",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
inverseResponseSide,
} from '../models';
import { Operation, SyncOperationHandler, useOperation } from '../../../types';
import { RfqTimers } from '@/utils/classes';
import { ResponseTimers, RfqTimers } from '@/utils/classes';
const Key = 'GetResponseStateAndAction' as const;
export type ResponseState =
| 'Active'
Expand Down Expand Up @@ -95,11 +95,13 @@ export const getResponseStateAndActionHandler: SyncOperationHandler<GetResponseS
if (!response.rfq.equals(rfq.address)) {
throw new Error('Response does not match RFQ');
}
const responseTimers = new ResponseTimers(response);
const rfqTimers = new RfqTimers(rfq);
const responseState = getResponseState(
response,
rfq,
rfqTimers,
responseTimers,
responseSide
);
const responseAction = getResponseAction(response, responseState, caller);
Expand All @@ -111,9 +113,10 @@ const getResponseState = (
response: Response,
rfq: Rfq,
rfqTimers: RfqTimers,
responseTimers: ResponseTimers,
responseSide: ResponseSide
): ResponseState => {
const rfqExpired = rfqTimers.isRfqExpired();
const responseExpired = responseTimers.isResponseExpired();
const settlementWindowElapsed = rfqTimers.isRfqSettlementWindowElapsed();
const confirmedInverseResponseSide =
response?.confirmed?.side === inverseResponseSide(responseSide);
Expand All @@ -130,12 +133,12 @@ const getResponseState = (
if (responseConfirmed && confirmedInverseResponseSide) return 'Rejected';
switch (response.state) {
case 'active':
if (!rfqExpired) return 'Active';
if (!responseExpired) return 'Active';
return 'Expired';
case 'canceled':
return 'Cancelled';
case 'waiting-for-last-look':
if (!rfqExpired) return 'WaitingForLastLook';
if (!responseExpired) return 'WaitingForLastLook';
return 'Expired';
case 'settling-preparations':
if (!settlementWindowElapsed) {
Expand Down
14 changes: 13 additions & 1 deletion packages/js/src/utils/classes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccountMeta, TransactionInstruction } from '@solana/web3.js';
import { TransactionBuilder } from './TransactionBuilder';
import { Rfq } from '@/plugins/rfqModule';
import { Response, Rfq } from '@/plugins/rfqModule';

export class InstructionUniquenessTracker {
constructor(public readonly IxArray: TransactionInstruction[]) {
Expand Down Expand Up @@ -76,3 +76,15 @@ export class RfqTimers {
return Date.now() >= this.timeStampSettlement.getTime();
}
}

export class ResponseTimers {
public timestampExpiry: Date;

constructor(response: Response) {
this.timestampExpiry = new Date(response.expirationTimestamp);
}

isResponseExpired(): boolean {
return Date.now() >= this.timestampExpiry.getTime();
}
}
Loading