Skip to content

Commit 585533b

Browse files
committed
Fix the calculation formula for devAmountOut
1 parent 3931ecf commit 585533b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/agent/positionsCreateWithAnyTokens.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ApproveIfNeededResult,
88
} from './common/approveIfNeeded'
99
import { UndefinedOr, whenDefined } from '@devprotocol/util-ts'
10+
import { BigNumber } from 'bignumber.js'
1011

1112
type Params = {
1213
readonly provider: ContractRunner
@@ -88,11 +89,15 @@ export async function positionsCreateWithAnyTokens(
8889
? await cont.getEstimatedDevForTokens(
8990
options.path,
9091
typeof options.gatewayBasisPoints === 'number'
91-
? (
92-
(BigInt(options.tokenAmount) *
93-
BigInt(options.gatewayBasisPoints)) /
94-
BigInt('10000')
95-
).toString()
92+
? new BigNumber(options.tokenAmount)
93+
.times(
94+
new BigNumber(10000)
95+
.minus(options.gatewayBasisPoints)
96+
.div(10000),
97+
)
98+
.times(0.8) // x0.8 = Hardcoded tolerance for quote and transaction differences
99+
.dp(0)
100+
.toFixed()
96101
: options.tokenAmount,
97102
)
98103
: 'Neither devAmountOut nor tokenAmount provided'

0 commit comments

Comments
 (0)