Closed particle4dev closed 6 years ago
Currently, a user needs at least 2 utxos in their address in order to swap. To split it, before we call buy method we check user's unspent utxos. If it's less than 2, we call the buy method for the first time and notify the user that the funds are in preparation.
For the best user experience for the application, I think a user only need deposits their coin and when they go to the buy page, they are ready to buy.
Can we split the funds when a user deposits their coin on the first time?
Let me know your solution or any case that I miss.
ping @ca333 @siulynot
We can do it either way. For best user experience we could check for balance each 60 seconds - if balance > 0 && utxo.num < 2 then do split
- so we add another interval based check. We also need to inform the user that the dICO App will automatically split the UTXO when a deposit is made to a wallet with 0 utxos. Because when splitting utxo it will deduct the transaction fee from the original deposit.
What we could also do is including the "splitting procedure" into the swap-status. So the splitting becomes part of the swap (Step 1/X) - so dICO app does automatically split funds if utxo.num<2 and afterwards reissue the swap-request/call.
So we have 2 options. Option 2 might be better because we only split if a user wants (to buy). Option 1 will always split - even if a user does deposit and withdrawl without buying (simple wallet-functionality).
@ca333 thanks. Option 2 looks good. I will try to implement it first before option 1.
There could be a problem with option 2 on slow coins like BTC. The split will take long to get done. But there is not many more options.
splitting BTC automatically will also lead to the same time-issue (waiting for confirmation) - on top the user wont be able to do any further steps with his funds before the split is done, even if he decides to not buy. @particle4dev thats fine - lets go with option 2 as default.
@siulynot we could still add a config option autosplit = true/false
to allow this option for dICO app operators. But i advice against it as default setting.
hi guys,
I have succeeded in integrating autosplit utxos
into buying process. But when I reissue the swap-request, I occur this error:
cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade
Here how to reproduce the bug:
listunspent
first time:[{
"tx_hash": "db3394c1e25e5b022d2568a089ae063fd23729813588280a080749fbb694b0e2",
"tx_pos": 0,
"height": 44637,
"value": 9899000000
}]
buy
first time (autosplit):{
"rawtx": "0100000001e2b094b6fb4907080a288835812937d23f06ae89a068252d025b5ee2c19433db0000000000ffffffff0482f38430020000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac7ce7cc0b000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac7ce7cc0b000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac5efae705000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac00000000",
"hex": "0100000001e2b094b6fb4907080a288835812937d23f06ae89a068252d025b5ee2c19433db000000006a473044022044bb1d5cc516456b75f6b4671cb4bb4c179cc6cd7875c16b3db5cc3bd12dc61b0220687111eb8f65824769f550205295cc858718fedc69aa1339848e7c3dc0a145cc01210342b862088e34b340c0c2286a3f8f6dc0437dcac9a66eb131d2f71ff1d78615abffffffff0482f38430020000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac7ce7cc0b000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac7ce7cc0b000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac5efae705000000001976a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac00000000",
"tx": {
"version": 1,
"locktime": 0,
"vin": [{
"txid": "db3394c1e25e5b022d2568a089ae063fd23729813588280a080749fbb694b0e2",
"vout": 0,
"scriptPubKey": {
"hex": "76a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac"
}
}],
"vout": [{
"satoshis": "9403954050",
"scriptPubKey": {
"hex": "76a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac"
}
}, {
"satoshis": "197977980",
"scriptPubKey": {
"hex": "76a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac"
}
}, {
"satoshis": "197977980",
"scriptPubKey": {
"hex": "76a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac"
}
}, {
"satoshis": "99088990",
"scriptPubKey": {
"hex": "76a9141edcfe6f235e20a9db5abb0f7275a978486bf14088ac"
}
}]
},
"txid": "43128980de820c918f5be08cd0e307f45f4f5f77ac46e51a38aa907a50dfc239",
"txfee": 1000,
"complete": true
}
listunspent
again:[
{
tx_hash: '43128980de820c918f5be08cd0e307f45f4f5f77ac46e51a38aa907a50dfc239',
tx_pos: 0,
height: 0,
value: 9403954050
},
{
tx_hash: '43128980de820c918f5be08cd0e307f45f4f5f77ac46e51a38aa907a50dfc239',
tx_pos: 1,
height: 0,
value: 197977980
},
{
tx_hash: '43128980de820c918f5be08cd0e307f45f4f5f77ac46e51a38aa907a50dfc239',
tx_pos: 2,
height: 0,
value: 197977980
},
{
tx_hash: '43128980de820c918f5be08cd0e307f45f4f5f77ac46e51a38aa907a50dfc239',
tx_pos: 3,
height: 0,
value: 99088990
}
];
buy
again then you will occur this error:cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade
Do we need to restart the marketmaker to solve this error?
pull the latest code from this branch to test:
https://github.com/KomodoPlatform/dicoapp-e/tree/split-the-funds-when-utxos-is-less-than-2
ping @ca333 @siulynot
from this docs, we need to restart the marketmaker app again.
we dont need to restart the marketmaker app - i am using this feature often.
How long did the app wait before it did reissue the buy-call after the split??
I think the issue has to do with order size after the split. Other than that, you might have needed to wait for confirmation.
yes exactly - first issue was not waited long enough for utxo split tx confirmation. second issue was utxos didnt match order request. I adviced him to buy a diff amount - after doubing amount to buy buy went through. i described the most optimal solution in discord:
most "clean and elegant" solution would be still this: User defines amount to buy - now since we know the price, we also know how much the user will be spending for this order - now we issue a manual split TX (sendmany to ourself) that is specifically trimmed to match the user-request. in this case we wont ever use the "auto-split" feature of marketmaker but instead do always a manual split-tx that is based on the user-balance and buy-request.
cool, thanks for the update.
Title: split the funds when utxos is less than 2
Business/User Value: As a user I want to split the funds to at least 2 utxos so that I can make a swap.
Acceptance Criteria GIVEN [necessary context and preconditions for story] WHEN [action] THEN [reaction]
DEV NOTES
DESIGN Notes None
---other items that you may add to a story---
NEEDS PM None
NEEDS DESIGN None
Related issues
https://github.com/particle4dev/dicoapp-e/issues/60
/label ~"story"