@@ -138,36 +138,39 @@ class AcpJob {
138138 ? this . baseFare . decimals
139139 : 18 ;
140140
141- const formattedAmount = formatUnits (
142- payableMemo . payableDetails . amount ,
143- decimals
144- ) ;
141+ const grossAmount = payableMemo . payableDetails . amount ;
145142
146- const payableAmount = parseFloat ( formattedAmount ) ;
143+ let netAmount : bigint ;
144+ if ( this . priceType === PriceType . PERCENTAGE ) {
145+ const feeBasisPoints = BigInt ( Math . round ( this . priceValue * 10000 ) ) ;
146+ let feeAmount = ( grossAmount * feeBasisPoints ) / BigInt ( 10000 ) ;
147147
148- if ( ! Number . isFinite ( payableAmount ) ) {
149- throw new AcpError (
150- `Payable amount overflow: ${ formattedAmount } exceeds safe number range`
151- ) ;
148+ if ( feeBasisPoints > BigInt ( 0 ) && feeAmount === BigInt ( 0 ) ) {
149+ feeAmount = BigInt ( 1 ) ;
150+ }
151+
152+ netAmount = grossAmount - feeAmount ;
153+ } else {
154+ netAmount = grossAmount ;
152155 }
153156
154- if ( payableAmount > Number . MAX_SAFE_INTEGER ) {
157+ const formattedAmount = formatUnits ( netAmount , decimals ) ;
158+ const amountNumber = parseFloat ( formattedAmount ) ;
159+
160+ if ( ! Number . isFinite ( amountNumber ) ) {
155161 throw new AcpError (
156- `Payable amount ${ formattedAmount } exceeds MAX_SAFE_INTEGER ( ${ Number . MAX_SAFE_INTEGER } ). Precision may be lost. `
162+ `Net payable amount overflow: ${ formattedAmount } exceeds safe number range `
157163 ) ;
158164 }
159165
160- if ( this . priceType === PriceType . PERCENTAGE ) {
161- const netAmount = payableAmount * ( 1 - this . priceValue ) ;
162- if ( ! Number . isFinite ( netAmount ) ) {
163- throw new AcpError (
164- `Net payable amount calculation overflow for percentage pricing`
165- ) ;
166- }
167- return netAmount ;
166+ if ( amountNumber > Number . MAX_SAFE_INTEGER ) {
167+ throw new AcpError (
168+ `Net payable amount ${ formattedAmount } exceeds MAX_SAFE_INTEGER (${ Number . MAX_SAFE_INTEGER } ). Precision may be lost.`
169+ ) ;
168170 }
169171
170- return payableAmount ;
172+ const factor = Math . pow ( 10 , decimals ) ;
173+ return Math . floor ( amountNumber * factor ) / factor ;
171174 }
172175
173176 async createRequirement ( content : string ) {
0 commit comments