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

feat(rest-api): Adds Swagger for api docs [SLT-205] #3159

Merged
merged 13 commits into from
Sep 20, 2024
1 change: 1 addition & 0 deletions packages/rest-api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
files: ['**/*.ts'],
rules: {
'guard-for-in': 'off',
'jsdoc/check-indentation': 'off',
},
},
],
Expand Down
4 changes: 4 additions & 0 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@
"@babel/preset-typescript": "^7.24.7",
"@types/jest": "^29.5.13",
"@types/supertest": "^6.0.2",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.6",
"concurrently": "^8.2.0",
"jest": "^29.7.0",
"lodash": "^4.17.21",
"nodemon": "^3.0.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2"
}
Expand Down
5 changes: 5 additions & 0 deletions packages/rest-api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import express from 'express'
import swaggerUi from 'swagger-ui-express'

import { specs } from './swagger'
import routes from './routes'

const app = express()
const port = process.env.PORT || 3000

app.use(express.json())

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs))

app.use('/', routes)

export const server = app.listen(port, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const getSynapseTxIdController = async (req, res) => {
bridgeModule,
txHash
)

res.json({ synapseTxId })
} catch (err) {
res.status(500).json({
Expand Down
175 changes: 175 additions & 0 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,181 @@ import { checksumAddresses } from '../middleware/checksumAddresses'

const router = express.Router()

/**
* @openapi
* /bridge:
* get:
* summary: Get quotes for bridging tokens between chains
* description: Retrieve list of detailed bridge quotes based on origin and destination chains based on tokens and amount
* parameters:
* - in: query
* name: fromChain
* required: true
* schema:
* type: string
* description: The source chain ID
* - in: query
* name: toChain
* required: true
* schema:
* type: string
* description: The destination chain ID
* - in: query
* name: fromToken
* required: true
* schema:
* type: string
* description: The address of the token on the source chain
* - in: query
* name: toToken
* required: true
* schema:
* type: string
* description: The address of the token on the destination chain
* - in: query
* name: amount
* required: true
* schema:
* type: string
* description: The amount of tokens to bridge
* responses:
* 200:
* description: Successful response
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* feeAmount:
* $ref: '#/components/schemas/BigNumber'
* feeConfig:
* type: object
* properties:
* bridgeFee:
* type: integer
* minFee:
* $ref: '#/components/schemas/BigNumber'
abtestingalpha marked this conversation as resolved.
Show resolved Hide resolved
* maxFee:
* $ref: '#/components/schemas/BigNumber'
* routerAddress:
* type: string
* maxAmountOut:
* $ref: '#/components/schemas/BigNumber'
* originQuery:
* type: object
* destQuery:
* type: object
* estimatedTime:
* type: integer
* bridgeModuleName:
* type: string
* gasDropAmount:
* $ref: '#/components/schemas/BigNumber'
* originChainId:
* type: integer
* destChainId:
* type: integer
* maxAmountOutStr:
* type: string
* bridgeFeeFormatted:
* type: string
* example:
* - id: "01920c87-7f14-7cdf-90e1-e13b2d4af55f"
* feeAmount:
* type: "BigNumber"
* hex: "0x17d78400"
* feeConfig:
* bridgeFee: 4000000
* minFee:
* type: "BigNumber"
* hex: "0x3d0900"
* maxFee:
* type: "BigNumber"
* hex: "0x17d78400"
* routerAddress: "0xd5a597d6e7ddf373a92C8f477DAAA673b0902F48"
* maxAmountOut:
* type: "BigNumber"
* hex: "0xe89bd2cb27"
* originQuery:
* routerAdapter: "0x0000000000000000000000000000000000000000"
* tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
abtestingalpha marked this conversation as resolved.
Show resolved Hide resolved
* minAmountOut:
* type: "BigNumber"
* hex: "0xe8d4a51000"
* deadline:
* type: "BigNumber"
* hex: "0x66ecb04b"
* rawParams: "0x"
* destQuery:
* routerAdapter: "0xd5a597d6e7ddf373a92C8f477DAAA673b0902F48"
* tokenOut: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
* minAmountOut:
* type: "BigNumber"
* hex: "0xe89bd2cb27"
* deadline:
* type: "BigNumber"
* hex: "0x66f5e873"
* rawParams: "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009a2dea7b81cfe3e0011d44d41c5c5142b8d9abdf00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
* estimatedTime: 1020
* bridgeModuleName: "SynapseCCTP"
* gasDropAmount:
* type: "BigNumber"
* hex: "0x0110d9316ec000"
* originChainId: 1
* destChainId: 42161
* maxAmountOutStr: "999046.695719"
* bridgeFeeFormatted: "400"
abtestingalpha marked this conversation as resolved.
Show resolved Hide resolved
* 400:
* description: Invalid input
* content:
* application/json:
* schema:
* type: object
* properties:
* error:
* type: object
* properties:
* value:
* type: string
* message:
* type: string
* field:
* type: string
* location:
* type: string
* example:
* error:
* value: "999"
* message: "Unsupported fromChain"
* field: "fromChain"
* location: "query"
* 500:
* description: Server error
* content:
* application/json:
* schema:
* type: object
* properties:
* error:
* type: string
* details:
* type: string
*
* components:
* schemas:
* BigNumber:
* type: object
* properties:
* type:
* type: string
* enum: [BigNumber]
* hex:
* type: string
*/
router.get(
'/',
checksumAddresses(['fromToken', 'toToken']),
Expand Down
110 changes: 110 additions & 0 deletions packages/rest-api/src/routes/bridgeTxInfoRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,116 @@ import { checksumAddresses } from '../middleware/checksumAddresses'

const router = express.Router()

/**
* @openapi
* /bridgeTxInfo:
* get:
* summary: Get bridge transaction information
* description: Retrieve transaction information for bridging tokens between chains
* parameters:
* - in: query
* name: fromChain
* required: true
* schema:
* type: string
abtestingalpha marked this conversation as resolved.
Show resolved Hide resolved
* description: The source chain ID
* - in: query
* name: fromToken
* required: true
* schema:
* type: string
* description: The address of the token on the source chain
* - in: query
* name: toChain
* required: true
* schema:
* type: string
* description: The destination chain ID
* - in: query
* name: toToken
* required: true
* schema:
* type: string
* description: The address of the token on the destination chain
* - in: query
* name: amount
* required: true
* schema:
* type: string
* description: The amount of tokens to bridge
* - in: query
* name: destAddress
* required: true
* schema:
* type: string
* description: The destination address for the bridged tokens
* responses:
* 200:
* description: Successful response
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* data:
* type: string
* description: Encoded transaction data
* to:
* type: string
* description: The address of the contract to interact with
* value:
* type: object
* properties:
* type:
* type: string
* enum: [BigNumber]
* hex:
* type: string
* description: The amount of native currency to send with the transaction
abtestingalpha marked this conversation as resolved.
Show resolved Hide resolved
* example:
* - data: "0xc2288147000000000000000000000000abb4f79430002534df3f62e964d62659a010ef3c000000000000000000000000000000000000000000000000000000000000a4b1000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000174876e80000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000174876e8000000000000000000000000000000000000000000000000000000000066ecbadf00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d5a597d6e7ddf373a92c8f477daaa673b0902f48000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb90000000000000000000000000000000000000000000000000000001744e380400000000000000000000000000000000000000000000000000000000066f5f30700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009a2dea7b81cfe3e0011d44d41c5c5142b8d9abdf00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"
* to: "0xd5a597d6e7ddf373a92C8f477DAAA673b0902F48"
* value:
* type: "BigNumber"
* hex: "0x00"
* 400:
* description: Invalid input
* content:
* application/json:
* schema:
* type: object
* properties:
* error:
* type: object
* properties:
* value:
* type: string
* message:
* type: string
* field:
* type: string
* location:
* type: string
* example:
* error:
* value: "999"
* message: "Unsupported fromChain"
* field: "fromChain"
* location: "query"
* 500:
* description: Server error
* content:
* application/json:
* schema:
* type: object
* properties:
* error:
* type: string
* details:
* type: string
*/
router.get(
'/',
checksumAddresses(['fromToken', 'toToken']),
Expand Down
Loading
Loading