@@ -6,6 +6,7 @@ const { each } = require('lodash');
6
6
const { all, delay } = require ( 'bluebird' ) ;
7
7
const { VAULT_ENDPOINT , GET_CONFIGURATION , GET_SECRETS } = require ( '../../../constants' ) ;
8
8
const { loggerDeposits } = require ( '../../../config/logger' ) ;
9
+ const mathjs = require ( 'mathjs' ) ;
9
10
const VAULT_NAME = ( ) => GET_SECRETS ( ) . vault . name ;
10
11
const VAULT_KEY = ( ) => GET_SECRETS ( ) . vault . key ;
11
12
const VAULT_SECRET = ( ) => GET_SECRETS ( ) . vault . secret ;
@@ -17,8 +18,13 @@ const { MAILTYPE } = require('../../../mail/strings');
17
18
18
19
const vaultCoins = [ ] ;
19
20
21
+ const getAmount = ( amount , fee ) => {
22
+ return mathjs . number ( mathjs . subtract ( mathjs . fraction ( amount ) , mathjs . fraction ( fee ) ) ) ;
23
+ } ;
24
+
20
25
const processWithdrawals = ( ) => {
21
26
return new Promise ( ( resolve , reject ) => {
27
+ loggerDeposits . info ( '/plugins/vault/crons/processWithdrawals starting' ) ;
22
28
each ( GET_SECRETS ( ) . vault . connected_coins , ( coin ) => {
23
29
vaultCoins . push ( {
24
30
currency : coin
@@ -43,7 +49,7 @@ const processWithdrawals = () => {
43
49
} )
44
50
. then ( ( withdrawals ) => {
45
51
if ( withdrawals . length === 0 ) {
46
- loggerDeposits . info ( 'No withdrawals need processing' ) ;
52
+ loggerDeposits . info ( '/plugins/vault/crons/processWithdrawals' , ' No withdrawals need processing') ;
47
53
resolve ( ) ;
48
54
}
49
55
const btcWithdrawals = [ ] ;
@@ -63,7 +69,7 @@ const processWithdrawals = () => {
63
69
body : {
64
70
data : {
65
71
address : withdrawal . address ,
66
- amount : withdrawal . amount ,
72
+ amount : getAmount ( withdrawal . amount , withdrawal . fee )
67
73
}
68
74
} ,
69
75
uri : `${ VAULT_ENDPOINT } /${ VAULT_WALLET ( 'btc' ) } /withdraw/simple` ,
@@ -88,7 +94,7 @@ const processWithdrawals = () => {
88
94
body : {
89
95
data : {
90
96
address : withdrawal . address ,
91
- amount : withdrawal . amount ,
97
+ amount : getAmount ( withdrawal . amount , withdrawal . fee )
92
98
}
93
99
} ,
94
100
uri : `${ VAULT_ENDPOINT } /${ VAULT_WALLET ( 'bch' ) } /withdraw/simple` ,
@@ -111,7 +117,7 @@ const processWithdrawals = () => {
111
117
body : {
112
118
data : {
113
119
address : withdrawal . address ,
114
- amount : withdrawal . amount ,
120
+ amount : getAmount ( withdrawal . amount , withdrawal . fee )
115
121
}
116
122
} ,
117
123
uri : `${ VAULT_ENDPOINT } /${ VAULT_WALLET ( withdrawal . currency ) } /withdraw/simple` ,
@@ -139,7 +145,7 @@ const processWithdrawals = () => {
139
145
data : btcWithdrawals . map ( ( withdrawal ) => {
140
146
return {
141
147
address : withdrawal . address ,
142
- amount : withdrawal . amount
148
+ amount : getAmount ( withdrawal . amount , withdrawal . fee )
143
149
} ;
144
150
} )
145
151
} ,
@@ -161,7 +167,7 @@ const processWithdrawals = () => {
161
167
data : bchWithdrawals . map ( ( withdrawal ) => {
162
168
return {
163
169
address : withdrawal . address ,
164
- amount : withdrawal . amount
170
+ amount : getAmount ( withdrawal . amount , withdrawal . fee )
165
171
} ;
166
172
} )
167
173
} ,
@@ -191,7 +197,7 @@ const processWithdrawals = () => {
191
197
. then ( ( dbWithdrawals ) => {
192
198
return rp ( option . data )
193
199
. then ( ( data ) => {
194
- loggerDeposits . info ( `${ option . dbWithdrawals [ 0 ] . currency } withdrawal successful` ) ;
200
+ loggerDeposits . info ( '/plugins/vault/crons/processWithdrawals perfromWithdrawal' , `${ option . dbWithdrawals [ 0 ] . currency } withdrawal successful` ) ;
195
201
return {
196
202
success : true ,
197
203
data,
@@ -201,7 +207,7 @@ const processWithdrawals = () => {
201
207
} ) ;
202
208
} )
203
209
. catch ( ( err ) => {
204
- loggerDeposits . error ( `${ option . dbWithdrawals [ 0 ] . currency } withdrawal failed: ${ err . message } ` ) ;
210
+ loggerDeposits . error ( '/plugins/vault/crons/processWithdrawals perfromWithdrawal' , `${ option . dbWithdrawals [ 0 ] . currency } withdrawal failed: ${ err . message } ` ) ;
205
211
return {
206
212
success : false ,
207
213
info : {
@@ -236,7 +242,7 @@ const processWithdrawals = () => {
236
242
} ) ) ;
237
243
} )
238
244
. catch ( ( err ) => {
239
- loggerDeposits . error ( `Failed to update successful ${ result . dbWithdrawals [ 0 ] . currency } withdrawal's TXID. ID:${ result . dbWithdrawals . map ( ( wd ) => wd . id ) } , TXID:${ result . data . txid } , Error: ${ err . message } ` ) ;
245
+ loggerDeposits . error ( '/plugins/vault/crons/processWithdrawals txid update' , `Failed to update successful ${ result . dbWithdrawals [ 0 ] . currency } withdrawal's TXID. ID:${ result . dbWithdrawals . map ( ( wd ) => wd . id ) } , TXID:${ result . data . txid } , Error: ${ err . message } ` ) ;
240
246
return {
241
247
success : false ,
242
248
info : {
@@ -269,7 +275,7 @@ const processWithdrawals = () => {
269
275
} ) ) ;
270
276
} )
271
277
. then ( ( ) => {
272
- loggerDeposits . info ( 'processWithdrawals finished' ) ;
278
+ loggerDeposits . info ( '/plugins/vault/crons/ processWithdrawals finished' ) ;
273
279
resolve ( ) ;
274
280
} )
275
281
. catch ( ( err ) => {
0 commit comments