js-stellar-sdk icon indicating copy to clipboard operation
js-stellar-sdk copied to clipboard

Updating full amount non-XLM asset (all it has) with manageBuyOffer/manageSellOffer fails with op_underfunded.

Open wemb-001 opened this issue 4 years ago • 5 comments

Describe the bug When updating the full amount of non-XLM asset (back to XLM or other) with manageBuyOffer fails with op_underfunded. I have more then sufficient XLM in the account to pay for the fee. This shouldn't fail like this.

This also happens with manageSellOffer, but there you require 'amount' instead of 'buyAmount'.

What version are you on? 8.1.1

To Reproduce Create an offer non-XLM to XLM of any price and any X amount, which is all that you have of that non-XLM asset. Make sure you can pay for the update fee. Update the offer changing the price but with the same X amount. Fails with op_underfunded.

Expected behavior No failure.

Additional context Here is the JavaScript (with StellarSdk 8.1.1) I use: ... let transaction = new window.StellarSdk.TransactionBuilder( {StellarSdk.Account}, { fee: window.StellarSdk.BASE_FEE, networkPassphrase: window.StellarSdk.Networks.PUBLIC } ).addOperation( window.StellarSdk.Operation.manageBuyOffer( { selling: {StellarSdk.Asset}, buying: {StellarSdk.Asset}, buyAmount: {number}.toFixed(7), price: {d:{number},n:{number}}, offerId: {string}, } ) ).setTimeout( 60 ).build(); ... signing, sending, ...

wemb-001 avatar May 06 '21 07:05 wemb-001

Maybe sending a {number} or even a {n:{number},d:{number}} instead of {String} {number}.toFixed(7) for 'amout' or 'buyAmount' would be better, because you prevent the conversion, but I'm following this reference.

wemb-001 avatar May 06 '21 08:05 wemb-001

I found out that this also happens when you are trying to update the price of any buy offer, with the same amount. For instance sell 100 XLM for 1.55 XLM/USDC. Update that to 1.56 XLM/USDC but keep the original amount of 100. Fails with underfunded. Why? The original offer validates there is enough XLM otherwise this can't happen in the first place.

wemb-001 avatar May 06 '21 12:05 wemb-001

Can you share actual transaction that failed with op_underfunded?

bartekn avatar May 06 '21 12:05 bartekn

Request: buyAmount: "1557.5343139" buying: Asset code: "USDC" issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"

offerId: "557330716" price: d: 5000000 n: 7729643

selling: Asset code: "XLM" issuer: undefined

Transaction: _envelopeType: ChildEnum {name: "envelopeTypeTx", value: 2} _fee: "100" _memo: ChildUnion {_switch: ChildEnum, _arm: {…}, _armType: {…}, _value: undefined} _networkPassphrase: "Public Global Stellar Network ; September 2015"

buyAmount: "1557.5343139" buying: Asset code: "USDC" issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN"

offerId: "557330716" price: "1.5459286" selling: Asset code: "XLM" issuer: undefined type: "manageBuyOffer"

length: 1

__sequence: "110672846132347627"_ _signatures: [ChildStruct] _source: "GD3BOT7FD23VW5X2QGLEGZTSS6MMUDE3KVJP6BZKZR7J45RTDCPPD2YI" _timeBounds: {minTime: "0", maxTime: "1620307853"}

wemb-001 avatar May 06 '21 13:05 wemb-001

The manageBuyOffer request object needs the buy amount, while the response of that call gives back the amount of the selling asset?!? Very confusing! Can we use the manageSellOffer call to do the same operation, but then swap the assets?

wemb-001 avatar May 06 '21 17:05 wemb-001