Skip to content

Commit

Permalink
Merge 5fe94c1 into fb55d90
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses authored Dec 14, 2024
2 parents fb55d90 + 5fe94c1 commit 770d6d9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
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
20 changes: 19 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,23 @@ describe('Bridge Route with Real Synapse Service', () => {
fromToken: USDC.addresses[1],
toToken: USDC.addresses[10],
amount: '1000',
originUserAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
})

expect(response.status).toBe(200)
expect(Array.isArray(response.body)).toBe(true)
expect(response.body.length).toBeGreaterThan(0)
expect(response.body[0].callData).toBeNull()
}, 15000)

it('should return bridge quotes without callData when originUserAddress is not 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',
})

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,
"schema": {
"type": "string"
},
Expand Down

0 comments on commit 770d6d9

Please sign in to comment.