Skip to content
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

Making address (origin and dest) mandated in rest API #3459

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/bridge/docs/02-Bridge/02-REST-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The API is available at [`https://api.synapseprotocol.com/`](https://api.synapse
| Date | Description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 2024‑10‑01 | [https://synapse-rest-api-v2.herokuapp.com/](https://synapse-rest-api-v2.herokuapp.com/) is no longer maintained and has been fully deprecated as of October 2024. |
| 2024‑11‑19 | [https://api.synapseprotocol.com/](https://api.synapseprotocol.com/) the /bridgeTxInfo endpoint has been consolidated into the /bridge endpoint, which now returns call data |
| 2024‑11‑19 | [https://api.synapseprotocol.com/](https://api.synapseprotocol.com/) the /bridgeTxInfo endpoint has been consolidated into the /bridge endpoint, which now returns call data |
| 2024‑12‑12 | [https://api.synapseprotocol.com/](https://api.synapseprotocol.com/bridge) the /bridge endpoint now requires both `originUserAddress` and `destAddress` to generate call data. |

## Support

Expand Down
25 changes: 13 additions & 12 deletions packages/rest-api/src/controllers/bridgeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ export const bridgeController = async (req, res) => {
quote.originQuery.tokenOut
)

const callData = destAddress
? await Synapse.bridge(
destAddress,
quote.routerAddress,
Number(fromChain),
Number(toChain),
fromToken,
amountInWei,
quote.originQuery,
quote.destQuery
)
: null
const callData =
destAddress && originUserAddress
? await Synapse.bridge(
destAddress,
quote.routerAddress,
Number(fromChain),
Number(toChain),
fromToken,
amountInWei,
quote.originQuery,
quote.destQuery
)
: null

return {
...quote,
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const router: express.Router = express.Router()
* required: false
* schema:
* type: string
* description: The address of the user on the origin chain
* description: The address of the user on the origin chain (required to generate callData)
* - in: query
* name: destAddress
* required: false
* schema:
* type: string
* description: The destination address for the bridge transaction
* description: The destination address for the bridge transaction (required to generate callData)
* responses:
* 200:
* description: Successful response
Expand Down
4 changes: 3 additions & 1 deletion packages/rest-api/src/tests/bridgeRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ describe('Bridge Route with Real Synapse Service', () => {
expect(response.body.error).toHaveProperty('field', 'amount')
})

it('should return bridge quotes with callData when destAddress is provided', async () => {
it('should return bridge quotes with callData when originUserAddress and destAddress are provided', async () => {
const response = await request(app).get('/bridge').query({
fromChain: '1',
toChain: '10',
fromToken: USDC.addresses[1],
toToken: USDC.addresses[10],
amount: '1000',
destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
originUserAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
})

expect(response.status).toBe(200)
Expand All @@ -200,6 +201,7 @@ describe('Bridge Route with Real Synapse Service', () => {
fromToken: USDC.addresses[1],
toToken: USDC.addresses[10],
amount: '1000',
originUserAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
Defi-Moses marked this conversation as resolved.
Show resolved Hide resolved
})

expect(response.status).toBe(200)
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
{
"in": "query",
"name": "destAddress",
"required": true,
"required": false,
Defi-Moses marked this conversation as resolved.
Show resolved Hide resolved
"schema": {
"type": "string"
},
Expand Down
Loading