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

[DNM] swagger bump [SLT-453] #3367

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
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 @@
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 @@
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
Loading