-
Notifications
You must be signed in to change notification settings - Fork 16
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
add hard quote logic #271
Merged
Merged
add hard quote logic #271
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { CosignedV2DutchOrder } from '@uniswap/uniswapx-sdk'; | ||
import { BigNumber } from 'ethers'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import { HardQuoteResponseData } from '../handlers/hard-quote/schema'; | ||
import { currentTimestampInMs, timestampInMstoSeconds } from '../util/time'; | ||
import { HardQuoteRequest } from '.'; | ||
|
||
// data class for hard quote response helpers and conversions | ||
export class HardQuoteResponse { | ||
public createdAt: string; | ||
|
||
constructor( | ||
public request: HardQuoteRequest, | ||
public order: CosignedV2DutchOrder, | ||
public createdAtMs = currentTimestampInMs() | ||
) { | ||
this.createdAt = timestampInMstoSeconds(parseInt(this.createdAtMs)); | ||
} | ||
|
||
public toResponseJSON(): HardQuoteResponseData { | ||
return { | ||
requestId: this.request.requestId, | ||
quoteId: this.request.quoteId, | ||
chainId: this.request.tokenInChainId, | ||
filler: this.order.info.cosignerData.exclusiveFiller, | ||
encodedOrder: this.order.serialize(), | ||
orderHash: this.order.hash(), | ||
}; | ||
} | ||
|
||
public toLog() { | ||
return { | ||
quoteId: this.quoteId, | ||
requestId: this.requestId, | ||
tokenInChainId: this.chainId, | ||
tokenOutChainId: this.chainId, | ||
tokenIn: this.tokenIn, | ||
amountIn: this.amountIn.toString(), | ||
tokenOut: this.tokenOut, | ||
amountOut: this.amountOut.toString(), | ||
swapper: this.swapper, | ||
filler: this.filler, | ||
orderHash: this.order.hash(), | ||
createdAt: this.createdAt, | ||
createdAtMs: this.createdAtMs, | ||
}; | ||
} | ||
|
||
public get quoteId(): string { | ||
return this.request.quoteId ?? uuidv4(); | ||
} | ||
|
||
public get requestId(): string { | ||
return this.request.requestId; | ||
} | ||
|
||
public get chainId(): number { | ||
return this.order.chainId; | ||
} | ||
|
||
public get swapper(): string { | ||
return this.request.swapper; | ||
} | ||
|
||
public get tokenIn(): string { | ||
return this.request.tokenIn; | ||
} | ||
|
||
public get amountOut(): BigNumber { | ||
const resolved = this.order.resolve({ | ||
timestamp: this.order.info.cosignerData.decayStartTime, | ||
}); | ||
let amount = BigNumber.from(0); | ||
for (const output of resolved.outputs) { | ||
amount = amount.add(output.amount); | ||
} | ||
|
||
return amount; | ||
} | ||
|
||
public get amountIn(): BigNumber { | ||
const resolved = this.order.resolve({ | ||
timestamp: this.order.info.cosignerData.decayStartTime, | ||
}); | ||
return resolved.input.amount; | ||
} | ||
|
||
public get tokenOut(): string { | ||
return this.request.tokenOut; | ||
} | ||
|
||
public get filler(): string | undefined { | ||
return this.order.info.cosignerData.exclusiveFiller; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './analytics-events'; | ||
export * from './aws-metrics-logger'; | ||
export * from './HardQuoteRequest'; | ||
export * from './HardQuoteResponse'; | ||
export * from './QuoteRequest'; | ||
export * from './QuoteResponse'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assumes all outputs are same token which is not necessarily true right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumed true anyways for now in main rfq flownsince quoters can only be for one token