Conversation
and refactor acp job type
9136129 to
0d059da
Compare
47f8011 to
7f59360
Compare
|
Performed two main testings for USDC (6 Decimals)Since USDC has a maximum of 6 decimals, the edge case that I aimed to test is if the calculated service fee is < 1μ it should default to 1μ (in this case, 0.005 will be 0.0000005 which translates to 0.5μ).
This contradicts with the design where any service fee that is <1μ should always default to 1μ *Important to note that μ in solidity only supports integer and not values such as 0.5 Next Steps: Identify the issue and where to fix it by @Ang-dot Ether (18 Decimals)For tokens that have 18 decimals, the function that truncates to decimals is actually making the calculation lose accuracy because it only truncates to 6 decimals as shown below: // acpFare.ts
constructor(fareAmount: number, fare: Fare) {
const truncateTo6Decimals = (input: string): number => {
const [intPart, decPart = ""] = input.split(".");
if (decPart === "") {
return parseFloat(intPart);
}
const truncated = decPart.slice(0, 6).padEnd(6, "0");
return parseFloat(`${intPart}.${truncated}`);
};
super(fare.formatAmount(truncateTo6Decimals(fareAmount.toString())), fare);
}Hence, I've implemented a fix for it by letting it truncate to take in the decimal from the constructor(fareAmount: number, fare: Fare) {
const truncateToTokenDecimals = (input: string, decimals: number): number => {
const [intPart, decPart = ""] = input.split(".");
if (decPart === "") {
return parseFloat(intPart);
}
const truncated = decPart.slice(0, decimals);
return parseFloat(`${intPart}.${truncated}`);
};
super(fare.formatAmount(truncateToTokenDecimals(fareAmount.toString(), fare.decimals)), fare);
}Next Steps: Review the code and make sure that it is backward compatible with USDC (tested out by @JohnsonChin1009, but needs someone to help review)
|
PR changes: