Skip to content

Commit

Permalink
hardcode max origin value
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Sep 18, 2024
1 parent 55c8d85 commit aa521c3
Showing 1 changed file with 14 additions and 45 deletions.
59 changes: 14 additions & 45 deletions packages/rest-api/src/controllers/getBridgeLimitsController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { validationResult } from 'express-validator'
import { BigNumber } from 'ethers'
import { parseUnits } from '@ethersproject/units'

import { Synapse } from '../services/synapseService'
Expand All @@ -17,16 +16,7 @@ export const getBridgeLimitsController = async (req, res) => {
const fromTokenInfo = tokenAddressToToken(fromChain, fromToken)
const toTokenInfo = tokenAddressToToken(toChain, toToken)

const upperLimitAmount = parseUnits('1000000', fromTokenInfo.decimals)
const upperLimitBridgeQuotes = await Synapse.allBridgeQuotes(
Number(fromChain),
Number(toChain),
fromTokenInfo.address,
toTokenInfo.address,
upperLimitAmount
)

const lowerLimitValues = [
const testValues = [
'0.01',
'0.1',
'1',
Expand All @@ -37,35 +27,25 @@ export const getBridgeLimitsController = async (req, res) => {
'100000',
'1000000',
]
let lowerLimitBridgeQuotes = null
let smallestBridgeQuotes = null

for (const limit of lowerLimitValues) {
const lowerLimitAmount = parseUnits(limit, fromTokenInfo.decimals)
for (const value of testValues) {
const amount = parseUnits(value, fromTokenInfo.decimals)

lowerLimitBridgeQuotes = await Synapse.allBridgeQuotes(
smallestBridgeQuotes = await Synapse.allBridgeQuotes(
Number(fromChain),
Number(toChain),
fromTokenInfo.address,
toTokenInfo.address,
lowerLimitAmount
amount
)

if (lowerLimitBridgeQuotes && lowerLimitBridgeQuotes.length > 0) {
if (smallestBridgeQuotes && smallestBridgeQuotes.length > 0) {
break
}
}

const maxBridgeAmountQuote = upperLimitBridgeQuotes.reduce(
(maxQuote, currentQuote) => {
const currentMaxAmount = currentQuote.maxAmountOut
const maxAmount = maxQuote ? maxQuote.maxAmountOut : BigNumber.from(0)

return currentMaxAmount.gt(maxAmount) ? currentQuote : maxQuote
},
null
)

const minBridgeAmountQuote = lowerLimitBridgeQuotes.reduce(
const minAmountQuote = smallestBridgeQuotes.reduce(
(minQuote, currentQuote) => {
const currentFeeAmount = currentQuote.feeAmount
const minFeeAmount = minQuote ? minQuote.feeAmount : null
Expand All @@ -77,33 +57,22 @@ export const getBridgeLimitsController = async (req, res) => {
null
)

if (!maxBridgeAmountQuote || !minBridgeAmountQuote) {
if (!minAmountQuote) {
return res.status(400).json({ errors: 'Route does not exist' })
}

const maxAmountOriginQueryTokenOutInfo = tokenAddressToToken(
toChain,
maxBridgeAmountQuote.destQuery.tokenOut
)

const minAmountOriginQueryTokenOutInfo = tokenAddressToToken(
const minAmountQuoteOriginQueryTokenOutInfo = tokenAddressToToken(
fromChain,
minBridgeAmountQuote.originQuery.tokenOut
)

const maxOriginAmount = formatBNToString(
maxBridgeAmountQuote.maxAmountOut,
maxAmountOriginQueryTokenOutInfo.decimals
minAmountQuote.originQuery.tokenOut
)

const minOriginAmount = formatBNToString(
minBridgeAmountQuote.feeAmount,
minAmountOriginQueryTokenOutInfo.decimals
minAmountQuote.feeAmount,
minAmountQuoteOriginQueryTokenOutInfo.decimals
)

return res.json({
lowerLimitBridgeQuotes,
maxOriginAmount,
maxOriginAmount: '1000000',
minOriginAmount,
})
} catch (err) {
Expand Down

0 comments on commit aa521c3

Please sign in to comment.