-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/synapsecns/sanguine
- Loading branch information
Showing
66 changed files
with
8,031 additions
and
5,318 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
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 |
---|---|---|
|
@@ -3,6 +3,25 @@ | |
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## [1.0.77](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-09-19) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* **synapse-interface:** Reorders validation to check existence first ([#3156](https://github.com/synapsecns/sanguine/issues/3156)) ([fd1540d](https://github.com/synapsecns/sanguine/commit/fd1540d21d142e38d16428d172cb182168a62b6e)) | ||
|
||
|
||
|
||
|
||
|
||
## [1.0.76](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-09-19) | ||
|
||
**Note:** Version bump only for package @synapsecns/rest-api | ||
|
||
|
||
|
||
|
||
|
||
## [1.0.75](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-09-18) | ||
|
||
**Note:** Version bump only for package @synapsecns/rest-api | ||
|
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
29 changes: 29 additions & 0 deletions
29
packages/rest-api/src/controllers/destinationTokensController.ts
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,29 @@ | ||
import { validationResult } from 'express-validator' | ||
|
||
import { tokenAddressToToken } from '../utils/tokenAddressToToken' | ||
import { BRIDGE_ROUTE_MAPPING } from '../utils/bridgeRouteMapping' | ||
|
||
export const destinationTokensController = async (req, res) => { | ||
const errors = validationResult(req) | ||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ errors: errors.array() }) | ||
} | ||
|
||
try { | ||
const { fromChain, fromToken } = req.query | ||
|
||
const fromTokenInfo = tokenAddressToToken(fromChain.toString(), fromToken) | ||
|
||
const constructedKey = `${fromTokenInfo.symbol}-${fromChain}` | ||
|
||
const options = BRIDGE_ROUTE_MAPPING[constructedKey] | ||
|
||
res.json(options) | ||
} catch (err) { | ||
res.status(500).json({ | ||
error: | ||
'An unexpected error occurred in /destinationTokens. Please try again later.', | ||
details: err.message, | ||
}) | ||
} | ||
} |
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,14 @@ | ||
import { Request, Response, NextFunction } from 'express' | ||
import { getAddress, isAddress } from 'ethers/lib/utils' | ||
|
||
export const checksumAddresses = (addressFields: string[]) => { | ||
return (req: Request, _res: Response, next: NextFunction) => { | ||
for (const field of addressFields) { | ||
const address = req.query[field] | ||
if (typeof address === 'string' && isAddress(address)) { | ||
req.query[field] = getAddress(address) | ||
} | ||
} | ||
next() | ||
} | ||
} |
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,40 @@ | ||
import express from 'express' | ||
import { check } from 'express-validator' | ||
import { isAddress } from 'ethers/lib/utils' | ||
|
||
import { CHAINS_ARRAY } from '../constants/chains' | ||
import { showFirstValidationError } from '../middleware/showFirstValidationError' | ||
import { destinationTokensController } from '../controllers/destinationTokensController' | ||
import { isTokenAddress } from '../utils/isTokenAddress' | ||
import { isTokenSupportedOnChain } from '../utils/isTokenSupportedOnChain' | ||
import { checksumAddresses } from '../middleware/checksumAddresses' | ||
|
||
const router = express.Router() | ||
|
||
router.get( | ||
'/', | ||
checksumAddresses(['fromToken']), | ||
[ | ||
check('fromChain') | ||
.exists() | ||
.withMessage('fromChain is required') | ||
.isNumeric() | ||
.custom((value) => CHAINS_ARRAY.some((c) => c.id === Number(value))) | ||
.withMessage('Unsupported fromChain'), | ||
check('fromToken') | ||
.exists() | ||
.withMessage('fromToken is required') | ||
.custom((value) => isAddress(value)) | ||
.withMessage('Invalid fromToken address') | ||
.custom((value) => isTokenAddress(value)) | ||
.withMessage('Unsupported fromToken address') | ||
.custom((value, { req }) => | ||
isTokenSupportedOnChain(value, req.query.fromChain as string) | ||
) | ||
.withMessage('Token not supported on specified chain'), | ||
], | ||
showFirstValidationError, | ||
destinationTokensController | ||
) | ||
|
||
export default router |
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
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
Oops, something went wrong.