Skip to content

Commit

Permalink
swagger bump
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Nov 2, 2024
1 parent 36b6345 commit a1ebff3
Show file tree
Hide file tree
Showing 7 changed files with 812 additions and 1,259 deletions.
18 changes: 18 additions & 0 deletions packages/rest-api/generate-swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const swaggerJsdoc = require('swagger-jsdoc');

Check failure on line 1 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check warning on line 1 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check failure on line 1 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check warning on line 1 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
const fs = require('fs');

Check failure on line 2 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

`fs` import should occur before import of `swagger-jsdoc`

Check warning on line 2 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check failure on line 2 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

`fs` import should occur before import of `swagger-jsdoc`

Check warning on line 2 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Synapse REST API',
version: '1.8.4',
description: 'A node.js project exposing a rest api for synapse sdk quotes',

Check warning on line 10 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·······`

Check warning on line 10 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·······`
}

Check warning on line 11 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`

Check warning on line 11 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
apis: ['./src/routes/*.ts']

Check warning on line 13 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`

Check warning on line 13 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
};

Check warning on line 14 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check warning on line 14 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

const swaggerSpec = swaggerJsdoc(options);

Check warning on line 16 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check warning on line 16 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
fs.writeFileSync('swagger.json', JSON.stringify(swaggerSpec, null, 2));

Check warning on line 17 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check warning on line 17 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
console.log('Swagger JSON generated!');

Check warning on line 18 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`

Check warning on line 18 in packages/rest-api/generate-swagger.js

View workflow job for this annotation

GitHub Actions / lint

Delete `;`
4 changes: 3 additions & 1 deletion packages/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"lint:check": "eslint . --max-warnings=0",
"ci:lint": "npm run lint:check",
"test": "jest",
"test:coverage": "jest --collect-coverage"
"test:coverage": "jest --collect-coverage",
"generate-swagger": "swagger-jsdoc -d swagger.config.js -o swagger.json"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
Expand Down
28 changes: 28 additions & 0 deletions packages/rest-api/src/controllers/bridgeController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { validationResult } from 'express-validator'
import { parseUnits } from '@ethersproject/units'
import { defaultAbiCoder, Interface } from '@ethersproject/abi'

import { formatBNToString } from '../utils/formatBNToString'
import { Synapse } from '../services/synapseService'
import { tokenAddressToToken } from '../utils/tokenAddressToToken'
import { logger } from '../middleware/logger'

const BRIDGE_INTERFACE = new Interface([
'function bridge(address to, uint256 chainId, address token, uint256 amount, tuple(address routerAdapter, address tokenOut, uint256 minAmountOut, uint256 deadline, bytes rawParams) originQuery, tuple(address routerAdapter, address tokenOut, uint256 minAmountOut, uint256 deadline, bytes rawParams) destQuery) external payable',
])

export const bridgeController = async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
Expand Down Expand Up @@ -42,6 +47,28 @@ export const bridgeController = async (req, res) => {
fromChain.toString(),
quote.originQuery.tokenOut
)

const txData = BRIDGE_INTERFACE.encodeFunctionData('bridge', [
originUserAddress,
Number(toChain),
fromToken,
amountInWei,
[
quote.originQuery.routerAdapter,
quote.originQuery.tokenOut,
quote.originQuery.minAmountOut,
quote.originQuery.deadline,
quote.originQuery.rawParams

Check warning on line 61 in packages/rest-api/src/controllers/bridgeController.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`

Check warning on line 61 in packages/rest-api/src/controllers/bridgeController.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
],
[
quote.destQuery.routerAdapter,
quote.destQuery.tokenOut,
quote.destQuery.minAmountOut,
quote.destQuery.deadline,
quote.destQuery.rawParams
]
])

return {
...quote,
maxAmountOutStr: formatBNToString(
Expand All @@ -52,6 +79,7 @@ export const bridgeController = async (req, res) => {
quote.feeAmount,
originQueryTokenOutInfo.decimals
),
txData,
}
})

Expand Down
4 changes: 4 additions & 0 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const router: express.Router = express.Router()
* type: string
* bridgeFeeFormatted:
* type: string
* txData:
* type: string
* description: Encoded transaction calldata for the bridge function
* example:
* - id: "01920c87-7f14-7cdf-90e1-e13b2d4af55f"
* feeAmount:
Expand Down Expand Up @@ -147,6 +150,7 @@ const router: express.Router = express.Router()
* destChainId: 42161
* maxAmountOutStr: "999046.695719"
* bridgeFeeFormatted: "400"
* txData: "0x3f4c16de000000000000000000000000..."
* 400:
* description: Invalid input
* content:
Expand Down
11 changes: 11 additions & 0 deletions packages/rest-api/swagger.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
definition: {
openapi: '3.0.0',
info: {
title: 'Synapse REST API',
version: '1.8.4',
description: 'A node.js project exposing a rest api for synapse sdk quotes',
}
},
apis: ['./src/routes/*.ts'] // This will look in all .ts files in src directory
};
Loading

0 comments on commit a1ebff3

Please sign in to comment.