-
Notifications
You must be signed in to change notification settings - Fork 8
fix(intentsV2): decode hex state machine IDs in estimateFillOrderV2 #286
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
Open
ddboy19912
wants to merge
8
commits into
main
Choose a base branch
from
fix/estimate-fill-order-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−16
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93bd8cc
fix(intentsV2): decode hex state machine IDs in estimateFillOrderV2
ddboy19912 f120a4e
chore: update intent v2 mainnet addresses
ddboy19912 87246f6
[sdk]: decode hex state machine IDs in estimateFillOrderV2
royvardhan fbb21dc
chore: update intent v2 mainnet addresses
royvardhan 63e8652
feat: add order lifecylce status checkers
ddboy19912 21efa26
Merge branch 'fix/estimate-fill-order-v2' of https://github.com/polyt…
ddboy19912 22528b4
feat(intentV2): add order status checker methods
ddboy19912 1cac19e
fix: improve v2 method
ddboy19912 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 hidden or 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 hidden or 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,11 @@ | ||
| # @hyperbridge/sdk | ||
|
|
||
| ## 1.6.3 | ||
|
|
||
| ### Patch Changes | ||
|
|
||
| - Further improvements to intents v2 | ||
|
|
||
| ## 1.6.2 | ||
|
|
||
| ### Patch Changes | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
packages/sdk/src/protocols/intentsV2/OrderStatusChecker.ts
This file contains hidden or 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,79 @@ | ||
| import { isHex, hexToString } from "viem" | ||
| import { ABI as IntentGatewayV2ABI } from "@/abis/IntentGatewayV2" | ||
| import { orderV2Commitment, bytes32ToBytes20 } from "@/utils" | ||
| import type { OrderV2, HexString } from "@/types" | ||
| import type { IntentsV2Context } from "./types" | ||
|
|
||
| export class OrderStatusChecker { | ||
| constructor(private readonly ctx: IntentsV2Context) {} | ||
|
|
||
| /** | ||
| * Checks if a V2 order has been filled by reading the commitment storage slot on the destination chain. | ||
| * | ||
| * Reads the storage slot returned by `calculateCommitmentSlotHash` on the IntentGatewayV2 contract. | ||
| * A non-zero value at that slot means the solver has called `fillOrder` and the order is complete | ||
| * from the user's perspective (the beneficiary has received their tokens). | ||
| * | ||
| * @param order - The V2 order to check. `order.id` is used as the commitment; if not set it is computed. | ||
| * @returns True if the order has been filled on the destination chain, false otherwise. | ||
| */ | ||
| async isOrderFilled(order: OrderV2): Promise<boolean> { | ||
| const commitment = (order.id ?? orderV2Commitment(order)) as HexString | ||
| const destStateMachineId = isHex(order.destination) | ||
| ? hexToString(order.destination as HexString) | ||
| : order.destination | ||
|
|
||
| const intentGatewayV2Address = this.ctx.dest.configService.getIntentGatewayV2Address(destStateMachineId) | ||
|
|
||
| const filledSlot = await this.ctx.dest.client.readContract({ | ||
| abi: IntentGatewayV2ABI, | ||
| address: intentGatewayV2Address, | ||
| functionName: "calculateCommitmentSlotHash", | ||
| args: [commitment], | ||
| }) | ||
|
|
||
| const filledStatus = await this.ctx.dest.client.getStorageAt({ | ||
| address: intentGatewayV2Address, | ||
| slot: filledSlot as HexString, | ||
| }) | ||
|
|
||
| return filledStatus !== "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a V2 order has been refunded by reading the `_orders` mapping on the source chain. | ||
| * | ||
| * Calls `_orders(commitment, tokenAddress)` for each input token. When the order is placed the | ||
| * escrowed amounts are stored there. After a successful refund the contract zeroes them out. | ||
| * An order is considered refunded when all escrowed input amounts have been returned (i.e. are 0). | ||
| * | ||
| * @param order - The V2 order to check. `order.id` is used as the commitment; if not set it is computed. | ||
| * @returns True if all escrowed inputs have been returned to the user on the source chain, false otherwise. | ||
| */ | ||
| async isOrderRefunded(order: OrderV2): Promise<boolean> { | ||
| if (!order.inputs || order.inputs.length === 0) return false | ||
|
|
||
| const commitment = (order.id ?? orderV2Commitment(order)) as HexString | ||
| const sourceStateMachineId = isHex(order.source) | ||
| ? hexToString(order.source as HexString) | ||
| : order.source | ||
|
|
||
| const intentGatewayV2Address = this.ctx.source.configService.getIntentGatewayV2Address(sourceStateMachineId) | ||
|
|
||
| for (const input of order.inputs) { | ||
| const tokenAddress = bytes32ToBytes20(input.token) | ||
| const escrowedAmount = await this.ctx.source.client.readContract({ | ||
| abi: IntentGatewayV2ABI, | ||
| address: intentGatewayV2Address, | ||
| functionName: "_orders", | ||
| args: [commitment, tokenAddress], | ||
| }) | ||
|
|
||
| if (escrowedAmount !== 0n) { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.