-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: turn HardquoteResponse into base class for V2 & V3
- Loading branch information
Showing
6 changed files
with
101 additions
and
45 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BigNumber } from "ethers"; | ||
import { HardQuoteResponse } from "./HardQuoteResponse"; | ||
import { CosignedV2DutchOrder } from "@uniswap/uniswapx-sdk"; | ||
|
||
export class V2HardQuoteResponse extends HardQuoteResponse<CosignedV2DutchOrder> { | ||
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 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; | ||
} | ||
} |
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,48 @@ | ||
import { CosignedV3DutchOrder } from "@uniswap/uniswapx-sdk"; | ||
import { HardQuoteResponse } from "./HardQuoteResponse"; | ||
|
||
export class V3HardQuoteResponse extends HardQuoteResponse<CosignedV3DutchOrder> { | ||
public toLog() { | ||
return { | ||
quoteId: this.quoteId, | ||
requestId: this.requestId, | ||
tokenInChainId: this.chainId, | ||
tokenOutChainId: this.chainId, | ||
tokenIn: this.tokenIn, | ||
input: this.input, | ||
tokenOut: this.tokenOut, | ||
outputs: this.outputs, | ||
swapper: this.swapper, | ||
filler: this.filler, | ||
orderHash: this.order.hash(), | ||
createdAt: this.createdAt, | ||
createdAtMs: this.createdAtMs, | ||
}; | ||
} | ||
|
||
get input() { | ||
const input = this.order.info.input; | ||
const relativeAmounts = input.curve.relativeAmounts.map((amount) => amount.toString()); | ||
|
||
return { | ||
...input, | ||
curve: { | ||
...input.curve, | ||
relativeAmounts, | ||
}, | ||
} | ||
} | ||
|
||
get outputs() { | ||
const processedOutputs = this.order.info.outputs.map((output) => { | ||
return { | ||
...output, | ||
curve: { | ||
...output.curve, | ||
relativeAmounts: output.curve.relativeAmounts.map((amount) => amount.toString()), | ||
} | ||
} | ||
}); | ||
return processedOutputs; | ||
} | ||
} |
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