10000 feat(rest-api,sdk-router): intent endpoint [SYN-77] by ChiTimesChi · Pull Request #3613 · synapsecns/sanguine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(rest-api,sdk-router): intent endpoint [SYN-77] #3613

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

Merged
merged 14 commits into from
Mar 21, 2025
Merged
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
462 changes: 454 additions & 8 deletions contrib/restclient/client.gen.go

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions packages/rest-api/src/controllers/intentController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { validationResult } from 'express-validator'

import { Synapse } from '../services/synapseService'
import { logger } from '../middleware/logger'
import {
DEFAULT_SWAP_SLIPPAGE_BIPS,
SLIPPAGE_BIPS_DENOMINATOR,
} from '../constants'
import { stringifyTxValue } from '../utils/replaceTxValue'

export const intentController = async (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
try {
const {
fromChainId,
fromToken,
fromAmount,
fromSender,
toChainId,
toToken,
toRecipient,
slippage,
allowMultipleTxs,
} = req.query as {
fromChainId: number
fromToken: string
fromAmount: string
fromSender?: string
toChainId: number
toToken: string
toRecipient?: string
slippage?: number
allowMultipleTxs?: boolean
}

// Convert percentage slippage to bips
const slippageBips = slippage ? slippage * 100 : DEFAULT_SWAP_SLIPPAGE_BIPS

const intentQuotes = await Synapse.intent({
fromChainId,
fromToken,
fromAmount,
fromSender,
toChainId,
toToken,
toRecipient,
slippage: {
numerator: slippageBips,
denominator: SLIPPAGE_BIPS_DENOMINATOR,
},
allowMultipleTxs,
})

// Convert all BigNumber values to strings.
const payload = intentQuotes.map((quote) => ({
...quote,
fromAmount: quote.fromAmount.toString(),
expectedToAmount: quote.expectedToAmount.toString(),
minToAmount: quote.minToAmount.toString(),
steps: quote.steps.map((step) => ({
...step,
fromAmount: step.fromAmount.toString(),
expectedToAmount: step.expectedToAmount.toString(),
minToAmount: step.minToAmount.toString(),
gasDropAmount: step.gasDropAmount.toString(),
callData: stringifyTxValue({
tx: step.tx,
preserveTx: !!fromSender && !!toRecipient,
}),
tx: undefined,
})),
}))

logger.info(`Successful intentController response`, {
query: req.query,
payload,
})
res.json(payload)
} catch (err) {
logger.error(`Error in intentController`, {
query: req.query,
error: err.message,
stack: err.stack,
})
res.status(500).json({
error: 'An unexpected error occurred in /intent. Please try again later.',
})
}
}
10 changes: 6 additions & 4 deletions packages/rest-api/src/routes/bridgeV2Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ const router: express.Router = express.Router()
* estimatedTime:
* type: integer
* description: Estimated time for the bridge in seconds
* moduleName:
* type: string
* description: The name of the bridge module used for this quote
* moduleNames:
* type: array
* items:
* type: string
* description: The names of the bridge or swap modules used for this quote
* gasDropAmount:
* type: string
* description: Amount of native token airdropped on destination chain (in native token decimals)
Expand Down Expand Up @@ -139,7 +141,7 @@ const router: express.Router = express.Router()
* minToAmount: "994051462240"
* routerAddress: "0x512000a034E154908Efb1eC48579F4ffDb000512"
* estimatedTime: 30
* moduleName: "SynapseRFQ"
* moduleNames: ["SynapseRFQ"]
* gasDropAmount: "0"
* callData: {
* to: "0x512000a034E154908Efb1eC48579F4ffDb000512",
Expand Down
2 changes: 2 additions & 0 deletions packages/rest-api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import destinationTokensRoute from './destinationTokensRoute'
import bridgeLimitsRoute from './bridgeLimitsRoute'
import chainIconRoute from './chainIconRoute'
import addressIconRoute from './addressIconRoute'
import intentRoute from './intentRoute'

const router: express.Router = express.Router()

router.use('/', indexRoute)
router.use('/intent', intentRoute)
router.use('/swap', swapRoute)
router.use('/swapTxInfo', swapTxInfoRoute)
router.use('/swap/v2', swapV2Route)
Expand Down
Loading
Loading
0