Skip to content

Commit

Permalink
example commit
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Nov 2, 2024
1 parent 36b6345 commit a750e89
Show file tree
Hide file tree
Showing 4 changed files with 732 additions and 25 deletions.
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 @@ 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

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 @@ 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
Loading

0 comments on commit a750e89

Please sign in to comment.