generated from ChainSafe/yarn-workspaces-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: get bridge history for an address #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
f3da187
validate /w team
BeroBurny 47afc40
swap `zod` with `superstruct`
BeroBurny 3956863
first case for api refactor
BeroBurny ce3b88c
move sprinter to separate file
BeroBurny db2a9cf
refactor
BeroBurny 18f768b
smoll fixes
BeroBurny b1151a8
sprinter class docs
BeroBurny c72bc78
add enum :man_shrugging:
BeroBurny ddd45f2
micro bug fixes
BeroBurny c61895f
refactor POC to match new SDK
BeroBurny ed12547
lint
BeroBurny 9c4272d
change sprinter sdk from dependencies to peer dependencies
BeroBurny 2121e83
partially refactor react sdk
BeroBurny b8656c9
react sdk docs and smool fix
BeroBurny 4d73265
fix yarn.lock
BeroBurny c84f104
fix ci
BeroBurny 33ef698
fix yarn command
BeroBurny c5e921d
save
BeroBurny a7f93e3
save general
BeroBurny 56231ea
refactor `sourceChains` behavior for single hop
BeroBurny dd1d8c8
sdk docs v1 on new approach
BeroBurny e46aeed
react docs v1
BeroBurny 7f72af1
Merge branch 'master' into beroburny/api-refactor
BeroBurny 046d431
dirty fix
BeroBurny a75d753
wtf is that? remove! purger!
BeroBurny f45864e
prettify category and push overview into index
BeroBurny eeb6625
fix example response for available tokens
BeroBurny 0589132
fix network list
BeroBurny 2efbfd7
implement remark plugins
BeroBurny fbe318b
fix `recipient`
BeroBurny 7d69042
implement calldata usages
BeroBurny b86162e
gas tips
BeroBurny 9acc443
smoll fix
BeroBurny a4ddc83
refactor gas tip
BeroBurny bc516e4
implement tabs in bridge and call
BeroBurny dfad461
ci / cd
BeroBurny e1fd86c
gas limit
BeroBurny 2566a3c
aggregate
BeroBurny 06a56ac
fix links
BeroBurny 2ca9ae6
breaking changes docs
BeroBurny 5c1faed
sejv
BeroBurny c4c7852
status
BeroBurny 33156ae
comments
BeroBurny edc6911
curl example
BeroBurny 6622bd5
address comments regarding method names
BeroBurny 9b04fb4
fix breaking changes doc
BeroBurny 1407c48
feat: added bridge history method
saadahmsiddiqui 6349c33
Merge branch 'beroburny/api-refactor' of github.com:ChainSafe/sprinte…
saadahmsiddiqui c645b18
revert lock file changes
saadahmsiddiqui d404fc0
revert lock file
saadahmsiddiqui 95ebbf9
newline add end of file `yarn.lock`
saadahmsiddiqui 670c339
fix lint
saadahmsiddiqui 126235c
resolve marins comments
saadahmsiddiqui 1151874
Merge branch 'master' of github.com:ChainSafe/sprinter-ts into berobu…
saadahmsiddiqui 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
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,10 +1,17 @@ | ||
| import {useSprinterBalances} from "../lib/hooks.ts"; | ||
| import { useSprinterBalances } from "../lib/hooks.ts"; | ||
|
|
||
| export function Action() { | ||
| const hook = useSprinterBalances("0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"); | ||
| const hook = useSprinterBalances( | ||
| "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519" | ||
| ); | ||
|
|
||
| return (<button onClick={() => { | ||
| hook.getUserBalances(); | ||
| hook.getUserBalances(); | ||
| }}>Action</button>) | ||
| } | ||
| return ( | ||
| <button | ||
| onClick={() => { | ||
| hook.getUserBalances(); | ||
| }} | ||
| > | ||
| Action | ||
| </button> | ||
| ); | ||
| } |
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,46 @@ | ||
| import { Environment } from "../enums"; | ||
| import { getTransfers } from "../sygma/api"; | ||
| import type { Status, SygmaTransfer } from "../sygma/types"; | ||
| import type { Address } from "../types"; | ||
|
|
||
| interface History { | ||
| originTx: string; | ||
| originName: string; | ||
| destinationTx?: string; | ||
| destinationName: string; | ||
| amount: string; | ||
| tokenSymbol: string; | ||
| status: Status; | ||
| } | ||
|
|
||
| function handleSygmaResponseEntry(entry: SygmaTransfer): History { | ||
| return { | ||
| originTx: entry.deposit?.txHash || "0x0", | ||
| originName: entry.fromDomain.name, | ||
| destinationTx: entry.execution?.txHash, | ||
| destinationName: entry.toDomain.name, | ||
| amount: entry.amount, | ||
| tokenSymbol: entry.fee.tokenSymbol, | ||
| status: entry.status, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns bridging history | ||
| * for an address | ||
| * @param {Address} address | ||
| * @param {Environment} environment | ||
| * @returns {Promise<History[]>} | ||
| */ | ||
| export async function getBridgeHistory( | ||
| address: Address, | ||
| environment: Environment = Environment.MAINNET, | ||
| ): Promise<History[]> { | ||
| // TODO: add logic for all supported bridges | ||
| const transactions = await getTransfers(address, environment).then( | ||
| (sygmaTransfers) => | ||
| sygmaTransfers.map((transfer) => handleSygmaResponseEntry(transfer)), | ||
| ); | ||
|
|
||
| return transactions; | ||
| } | ||
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 +1,2 @@ | ||
| export { experimental_getTrackingUrl } from "./getTrackingUrl"; | ||
| export { getBridgeHistory } from "./getBridgeHistory"; |
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Environment } from "../enums"; | ||
|
|
||
| import type { SygmaTransfer } from "./types"; | ||
|
|
||
| const SYGMA_API_ENDPOINT: Record<Environment, string> = { | ||
| [Environment.MAINNET]: "https://api.buildwithsygma.com/", | ||
| [Environment.TESTNET]: "https://api.test.buildwithsygma.com/", | ||
| }; | ||
|
|
||
| /** | ||
| * Returns list of sygma transfers for an address | ||
| * @param {`0x${string}`} address EVM address | ||
| * @param {Environment} environment TESTNET or MAINNET | ||
| * @returns {Promise<Array<SygmaTransfer>>} | ||
| */ | ||
| export async function getTransfers( | ||
| address: string, | ||
| environment: Environment, | ||
| ): Promise<Array<SygmaTransfer>> { | ||
| const transfersPath = `/api/sender/${address}/transfers`; | ||
| const url = new URL(transfersPath, SYGMA_API_ENDPOINT[environment]); | ||
| url.searchParams.set("limit", "100"); | ||
|
|
||
| const response: SygmaTransfer[] = await fetch(url.toString()).then( | ||
| (response): Promise<SygmaTransfer[]> => response.json(), | ||
| ); | ||
|
|
||
| return response; | ||
| } |
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,2 @@ | ||
| export * from "./api"; | ||
| export * from "./types"; |
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,67 @@ | ||
| export enum Status { | ||
| pending = "pending", | ||
| executed = "executed", | ||
| failed = "failed", | ||
| } | ||
|
|
||
| export interface SygmaTransfer { | ||
| id: string; | ||
| depositNonce: number; | ||
| resource: Resource; | ||
| fromDomain: Domain; | ||
| fromDomainId: number; | ||
| toDomain: Domain; | ||
| toDomainId: number; | ||
| sender: string; | ||
| destination: string; | ||
| amount: string; | ||
| timestamp?: string; | ||
| status: Status; | ||
| deposit?: Deposit; | ||
| execution?: Execution; | ||
| fee: Fee; | ||
| resourceID: string; | ||
| usdValue: number; | ||
| accountId: string; | ||
| } | ||
|
|
||
| export interface Resource { | ||
| id: string; | ||
| type: string; | ||
| } | ||
|
|
||
| export interface Domain { | ||
| id: string; | ||
| name: string; | ||
| lastIndexedBlock: string; | ||
| } | ||
|
|
||
| export interface Deposit { | ||
| id: string; | ||
| transferId: string; | ||
| type: string; | ||
| txHash: string; | ||
| blockNumber: string; | ||
| depositData: string; | ||
| handlerResponse: string; | ||
| timestamp: string; | ||
| } | ||
|
|
||
| export interface Execution { | ||
| id: string; | ||
| transferId: string; | ||
| type: string; | ||
| txHash: string; | ||
| blockNumber: string; | ||
| executionEvent: string; | ||
| timestamp: string; | ||
| } | ||
|
|
||
| export interface Fee { | ||
| amount: string; | ||
| id: string; | ||
| tokenAddress: string; | ||
| tokenSymbol: string; | ||
| transferId: string; | ||
| decimals: number; | ||
| } |
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.