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

Fix/swagger override #3369

Closed
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test:coverage": "jest --collect-coverage"
},
"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

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

View workflow job for this annotation

GitHub Actions / lint

Insert `,`

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

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
]

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

View workflow job for this annotation

GitHub Actions / lint

Insert `,`

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

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
])

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
26 changes: 16 additions & 10 deletions packages/rest-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,16 @@
"type": "integer"
},
"maxAmountOutStr": {
"type": "string"
"type": "string",
"description": "The formatted maximum output amount"
},
"bridgeFeeFormatted": {
"type": "string"
"type": "string",
"description": "The formatted bridge fee"
},
"txData": {
"type": "string",
"description": "Encoded transaction calldata for the bridge function"
}
}
}
Expand Down Expand Up @@ -323,7 +329,8 @@
"originChainId": 1,
"destChainId": 42161,
"maxAmountOutStr": "999046.695719",
"bridgeFeeFormatted": "400"
"bridgeFeeFormatted": "400",
"txData": "0x3f4c16de000000000000000000000000..."
}
]
}
Expand Down Expand Up @@ -1408,11 +1415,12 @@
}
},
"example": {
"data": "0xb5d1cdd4000000000000000000000000abb4f79430002534df3f62e964d62659a010ef3c000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000003b9aca0000000000000000000000000000000000000000000000000000000000000000800000000000000000000000007e7a0e201fd38d3adaa9523da6c109a07118c96a000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000000000000000003b96eaed0000000000000000000000000000000000000000000000000000000066ecbb7c00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001116898dda4015ed8ddefb84b6e8bc24528af2d800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
"to": "0x7E7A0e201FD38d3ADAA9523Da6C109a07118C96a",
"value": {
"type": "BigNumber",
"hex": "0x00"
"data": "0xb5d1cdd4000000000000000000000000abb4f79430002534df3f62e964d62659a010ef3c000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000080000000000000000000000007e7a0e201fd38d3adaa9523da6c109a07118c96a000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000000000000000000000000000003b96eaed0000000000000000000000000000000000000000000000000000000066ecbb7c00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001116898dda4015ed8ddefb84b6e8bc24528af2d800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
"to": "0x7E7A0e201FD38d3ADAA9523Da6C109a07118C96a",
"value": {
"type": "BigNumber",
"hex": "0x00"
}
}
}
}
Expand Down Expand Up @@ -2288,7 +2296,6 @@
}
}
}
}
},
"tags": ["RFQ Indexer API"]
}
Expand Down Expand Up @@ -2378,7 +2385,6 @@
}
}
}
}
},
"tags": ["RFQ Indexer API"]
}
Expand Down
Loading
Loading