Francium-DeFi / francium-sdk

The Francium SDK.
https://francium.io/
30 stars 16 forks source link

Error thrown by getUserFarmPosition in 1.2.23 #1

Open aantia opened 2 years ago

aantia commented 2 years ago

I just updated the sdk to 1.2.23, and I'm now seeing an error when I call FranciumSDK.getUserFarmPosition(Web3.PublicKey). The error is UnhandledPromiseRejectionWarning: Error: Number can only safely store up to 53 bits. which I've seen when trying to convert overly-large BNs to Numbers, but it's being thrown before I actually touch any of the data. Here's the full trace:

(node:23064) UnhandledPromiseRejectionWarning: Error: Number can only safely store up to 53 bits
    at assert (D:\Programs\VSCode_projects\francium_interactor\node_modules\bn.js\lib\bn.js:6:21)
    at BN.toNumber (D:\Programs\VSCode_projects\francium_interactor\node_modules\bn.js\lib\bn.js:547:7)
    at formatFarmUserPosition (D:\Programs\VSCode_projects\francium_interactor\node_modules\francium-sdk\dist\utils\formatters\farm.js:8:32)
    at D:\Programs\VSCode_projects\francium_interactor\node_modules\francium-sdk\dist\main\index.js:62:62
    at Array.map (<anonymous>)
    at FranciumSDK.<anonymous> (D:\Programs\VSCode_projects\francium_interactor\node_modules\francium-sdk\dist\main\index.js:60:38)
    at Generator.next (<anonymous>)
    at fulfilled (D:\Programs\VSCode_projects\francium_interactor\node_modules\francium-sdk\dist\main\index.js:5:58)  
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
aantia commented 2 years ago

Sorry, I had a mental glitch and closed this incorrectly.

Updated information: The error occurs in utils/formatters/farm.js, on line 8. The problem is in the expression 'totalShares.toNumber() === 0'; this only works if totalShares (which is a BN) is small enough to represent in 53 bits.

aantia commented 2 years ago

Replace the line with this and it'll work (it's a bit ugly, though):

const userLP = totalShares.length < 2 ? (totalShares.toNumber() === 0 ? 0 : userShares.mul(totalLP).div(totalShares)) : userShares.mul(totalLP).div(totalShares);

DFL-Levi commented 2 years ago

Thanks! This solution helped me too.

DFL-Levi commented 2 years ago

@aantia maybe you can make pr on this issue.

missrhyme commented 2 years ago

fixed in 1.2.30

DFL-Levi commented 2 years ago

Thank you!