Skip to content

Commit e51d09a

Browse files
author
Julien
committed
Add gasLimit and gasPrice as parameters
1 parent 0db36a9 commit e51d09a

File tree

2 files changed

+122
-69
lines changed

2 files changed

+122
-69
lines changed

src/infura/cfd-api-infura.js

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export default class CFDAPI {
5151
* @param leverage The leverage (between 0.01 and 5.00)
5252
* @param isBuyer Creator wants to be contract buyer or seller
5353
* @param creatorProxy Proxy of creator of the new CFD
54+
* @param {Number} gasLimit How much gas we are willing to spent
55+
* @param {Number} gasPrice Price of the gas
5456
*
5557
* @return Promise resolving to a new cfd contract instance on
5658
* success or a promise failure if the tx failed
@@ -61,7 +63,9 @@ export default class CFDAPI {
6163
notionalAmountDai,
6264
leverage,
6365
isBuyer,
64-
creatorProxy
66+
creatorProxy,
67+
gasLimit,
68+
gasPrice
6569
) {
6670
assertBigNumberOrString(strikePrice)
6771
assertBigNumberOrString(notionalAmountDai)
@@ -85,7 +89,9 @@ export default class CFDAPI {
8589
strikePrice: strikePriceBN,
8690
notional: notionalBN.toFixed(),
8791
isBuyer,
88-
value
92+
value,
93+
gasLimit,
94+
gasPrice
8995
})
9096
}
9197

@@ -99,6 +105,8 @@ export default class CFDAPI {
99105
* @param leverage The leverage (between 0.01 and 5.00)
100106
* @param isBuyer Creator wants to be contract buyer or seller
101107
* @param creatorProxy Proxy of creator of the new CFD
108+
* @param {Number} gasLimit How much gas we are willing to spent
109+
* @param {Number} gasPrice Price of the gas
102110
*
103111
* @return Promise resolving to a new cfd contract instance on
104112
* success or a promise failure if the tx failed
@@ -109,7 +117,9 @@ export default class CFDAPI {
109117
notionalAmountDai,
110118
leverage,
111119
isBuyer,
112-
creatorProxy
120+
creatorProxy,
121+
gasLimit,
122+
gasPrice
113123
) {
114124
assertBigNumberOrString(strikePrice)
115125
assertBigNumberOrString(notionalAmountDai)
@@ -141,7 +151,9 @@ export default class CFDAPI {
141151
strikePrice: strikePriceBN,
142152
notional: notionalBN.toFixed(),
143153
isBuyer,
144-
valueETH
154+
valueETH,
155+
gasLimit,
156+
gasPrice
145157
})
146158
}
147159

@@ -151,11 +163,11 @@ export default class CFDAPI {
151163
* @return Promise resolving to success with tx details or reject depending
152164
* on the outcome.
153165
*/
154-
async deposit(cfdAddress, depositAccountProxy, amount) {
166+
async deposit(cfdAddress, depositAccountProxy, amount, gasLimit, gasPrice) {
155167
const cfd = getContract(cfdAddress, this.web3)
156168
const value = safeValue(amount)
157169

158-
await this.proxyApi.proxyDeposit(depositAccountProxy, cfd, value)
170+
await this.proxyApi.proxyDeposit(depositAccountProxy, cfd, value, gasLimit, gasPrice)
159171
}
160172

161173
/**
@@ -221,10 +233,12 @@ export default class CFDAPI {
221233
* @param cfdAddress Address of a deployed CFD
222234
* @param accountProxy Proxy account making the request
223235
* @param desiredStrikePrice User wants this strike price value for his CFD
236+
* @param {Number} gasLimit How much gas we are willing to spent
237+
* @param {Number} gasPrice Price of the gas
224238
* @return Promise resolving to success with tx details or reject depending
225239
* on the outcome.
226240
*/
227-
async changeStrikePriceCFD(cfdAddress, accountProxy, desiredStrikePrice) {
241+
async changeStrikePriceCFD(cfdAddress, accountProxy, desiredStrikePrice, gasLimit, gasPrice) {
228242
const cfd = getContract(cfdAddress, this.web3)
229243

230244
if (
@@ -246,7 +260,9 @@ export default class CFDAPI {
246260
return this.proxyApi.proxyChangeStrikePrice(
247261
accountProxy,
248262
cfd,
249-
desiredStrikePriceBN
263+
desiredStrikePriceBN,
264+
gasLimit,
265+
gasPrice
250266
)
251267
}
252268

@@ -257,14 +273,18 @@ export default class CFDAPI {
257273
* @param desiredStrikePrice Sellers wants to sell at this strike price.
258274
* @param timeLimit Sale expired after this time (UNIX epoch seconds).
259275
* Defaults to 0 for no limit.
276+
* @param {Number} gasLimit How much gas we are willing to spent
277+
* @param {Number} gasPrice Price of the gas
260278
* @return Promise resolving to success with tx details or reject depending
261279
* on the outcome.
262280
*/
263281
async sellCFD(
264282
cfdAddress,
265283
sellerAccountProxy,
266284
desiredStrikePrice,
267-
timeLimit = 0
285+
timeLimit = 0,
286+
gasLimit,
287+
gasPrice
268288
) {
269289
const cfd = getContract(cfdAddress, this.web3)
270290

@@ -290,7 +310,9 @@ export default class CFDAPI {
290310
sellerAccountProxy,
291311
cfd,
292312
desiredStrikePriceBN,
293-
timeLimit
313+
timeLimit,
314+
gasLimit,
315+
gasPrice
294316
)
295317
}
296318

@@ -300,75 +322,87 @@ export default class CFDAPI {
300322
* @param buyerAccountProxy, The proxy address of the account who is buying
301323
* @param valueToBuy, The amount the user has to pay (DAI)
302324
* @param isBuyerSide, Boolean if the user is buyer or seller
325+
* @param {Number} gasLimit How much gas we are willing to spent
326+
* @param {Number} gasPrice Price of the gas
303327
* @return Promise resolving to success with tx details or reject depending
304328
* on the outcome.
305329
*/
306-
async buyCFD(cfdAddress, buyerAccountProxy, valueToBuy, isBuyerSide) {
330+
async buyCFD(cfdAddress, buyerAccountProxy, valueToBuy, isBuyerSide, gasLimit, gasPrice) {
307331
const cfd = getContract(cfdAddress, this.web3)
308332
const valueToBuyBN = new BigNumber(valueToBuy)
309333
const value = safeValue(valueToBuyBN)
310-
return this.proxyApi.proxyBuy(buyerAccountProxy, cfd, isBuyerSide, value)
334+
return this.proxyApi.proxyBuy(buyerAccountProxy, cfd, isBuyerSide, value, gasLimit, gasPrice)
311335
}
312336

313337
/**
314338
* Tansfer the position in a contract to another account.
315339
* @param cfdAddress, Address of the deployed CFD
316340
* @param fromAccountProxy, Account who is transferring the position
317341
* @param toAccount, Account who the position gets transferred too
342+
* @param {Number} gasLimit How much gas we are willing to spent
343+
* @param {Number} gasPrice Price of the gas
318344
* @return Promise resolving to success with tx details or reject depending
319345
* on the outcome.
320346
*/
321-
async transferPosition(cfdAddress, fromAccountProxy, toAccount) {
347+
async transferPosition(cfdAddress, fromAccountProxy, toAccount, gasLimit, gasPrice) {
322348
const cfd = getContract(cfdAddress, this.web3)
323-
return this.proxyApi.proxyTransferPosition(fromAccountProxy, cfd, toAccount)
349+
return this.proxyApi.proxyTransferPosition(fromAccountProxy, cfd, toAccount, gasLimit, gasPrice)
324350
}
325351

326352
/**
327353
* Invoke liquidateMutual functionality.
328354
* @param cfdAddress, Address of the deployed CFD
329355
* @param accountProxy, The proxy address of the account who is terminating
356+
* @param {Number} gasLimit How much gas we are willing to spent
357+
* @param {Number} gasPrice Price of the gas
330358
* @return Promise resolving to success with tx details or reject depending
331359
* on the outcome.
332360
*/
333-
async liquidateMutual(cfdAddress, accountProxy) {
361+
async liquidateMutual(cfdAddress, accountProxy, gasLimit, gasPrice) {
334362
const cfd = getContract(cfdAddress, this.web3)
335-
return this.proxyApi.proxyLiquidateMutual(accountProxy, cfd)
363+
return this.proxyApi.proxyLiquidateMutual(accountProxy, cfd, gasLimit, gasPrice)
336364
}
337365

338366
/**
339367
* Party cancels liquidateMutual (before second party calls to agree)
340368
* @param cfdAddress, Address of the deployed CFD
341369
* @param accountProxy, The proxy address of the account who is terminating
370+
* @param {Number} gasLimit How much gas we are willing to spent
371+
* @param {Number} gasPrice Price of the gas
342372
* @return Promise resolving to success with tx details or reject depending
343373
* on the outcome.
344374
*/
345-
async liquidateMutualCancel(cfdAddress, accountProxy) {
375+
async liquidateMutualCancel(cfdAddress, accountProxy, gasLimit, gasPrice) {
346376
const cfd = getContract(cfdAddress, this.web3)
347-
return this.proxyApi.proxyLiquidateMutualCancel(accountProxy, cfd)
377+
return this.proxyApi.proxyLiquidateMutualCancel(accountProxy, cfd, gasLimit, gasPrice)
348378
}
349379

350380
/**
351381
* Force liquidation a contract
352382
* @param cfdAddress, Address of the deployed CFD
353383
* @param accountProxy, The proxy address of the account who is terminating
384+
* @param {Number} gasLimit How much gas we are willing to spent
385+
* @param {Number} gasPrice Price of the gas
354386
* @return Promise resolving to success with tx details or reject depending
355387
* on the outcome.
356388
*/
357-
async forceTerminate(cfdAddress, accountProxy) {
389+
async forceTerminate(cfdAddress, accountProxy, gasLimit, gasPrice) {
358390
const cfd = getContract(cfdAddress, this.web3)
359-
return this.proxyApi.proxyForceTerminate(accountProxy, cfd)
391+
return this.proxyApi.proxyForceTerminate(accountProxy, cfd, gasLimit, gasPrice)
360392
}
361393

362394
/**
363395
* Cancel a newly created contract (must be non initialized)
364396
* @param cfdAddress, Address of the deployed CFD
365397
* @param accountProxy, The address of the proxy account who is canceling
398+
* @param {Number} gasLimit How much gas we are willing to spent
399+
* @param {Number} gasPrice Price of the gas
366400
* @return Promise resolving to success with tx details or reject depending
367401
* on the outcome.
368402
*/
369-
async cancelNew(cfdAddress, accountProxy) {
403+
async cancelNew(cfdAddress, accountProxy, gasLimit, gasPrice) {
370404
const cfd = getContract(cfdAddress, this.web3)
371-
return this.proxyApi.proxyCancelNew(accountProxy, cfd)
405+
return this.proxyApi.proxyCancelNew(accountProxy, cfd, gasLimit, gasPrice)
372406
}
373407

374408
/**
@@ -378,21 +412,23 @@ export default class CFDAPI {
378412
* @return Promise resolving to success with tx details or reject depending
379413
* on the outcome.
380414
*/
381-
async cancelSale(cfdAddress, accountProxy) {
415+
async cancelSale(cfdAddress, accountProxy, gasLimit, gasPrice) {
382416
const cfd = getContract(cfdAddress, this.web3)
383-
return this.proxyApi.proxySellCancel(accountProxy, cfd)
417+
return this.proxyApi.proxySellCancel(accountProxy, cfd, gasLimit, gasPrice)
384418
}
385419

386420
/**
387421
* Upgrade a contract to the latest deployed version
388422
* @param cfdAddress, Address of the deployed CFD
389423
* @param accountProxy, The address of the account who is upgrading
424+
* @param {Number} gasLimit How much gas we are willing to spent
425+
* @param {Number} gasPrice Price of the gas
390426
* @return Promise resolving to success with tx details or reject depending
391427
* on the outcome.
392428
*/
393-
async upgradeCFD(cfdAddress, accountProxy) {
429+
async upgradeCFD(cfdAddress, accountProxy, gasLimit, gasPrice) {
394430
const cfd = getContract(cfdAddress, this.web3)
395-
return this.proxyApi.proxyUpgrade(accountProxy, cfd)
431+
return this.proxyApi.proxyUpgrade(accountProxy, cfd, gasLimit, gasPrice)
396432
}
397433

398434
/**
@@ -442,10 +478,12 @@ export default class CFDAPI {
442478
* @param cfdAddress Address of a deployed CFD
443479
* @param selleraccountProxy Account settling the position.
444480
* @param desiredStrikePrice Sellers wants to sell at this strike price.
481+
* @param {Number} gasLimit How much gas we are willing to spent
482+
* @param {Number} gasPrice Price of the gas
445483
* @return Promise resolving to success with tx details or reject depending
446484
* on the outcome.
447485
*/
448-
async changeSaleCFD(cfdAddress, sellerAccountProxy, desiredStrikePrice) {
486+
async changeSaleCFD(cfdAddress, sellerAccountProxy, desiredStrikePrice, gasLimit, gasPrice) {
449487
const cfd = getContract(cfdAddress, this.web3)
450488

451489
if (
@@ -469,7 +507,9 @@ export default class CFDAPI {
469507
return this.proxyApi.proxySellUpdate(
470508
sellerAccountProxy,
471509
cfd,
472-
desiredStrikePriceBN
510+
desiredStrikePriceBN,
511+
gasLimit,
512+
gasPrice
473513
)
474514
}
475515

@@ -478,8 +518,10 @@ export default class CFDAPI {
478518
* @param cfdAddress, Address of the deployed CFD
479519
* @param accountProxy, The address of the account who is topuping
480520
* @param valueToAdd, The amount the user wants to add (DAI)
521+
* @param {Number} gasLimit How much gas we are willing to spent
522+
* @param {Number} gasPrice Price of the gas
481523
*/
482-
async topup(cfdAddress, accountProxy, valueToAdd) {
524+
async topup(cfdAddress, accountProxy, valueToAdd, gasLimit, gasPrice) {
483525
const cfd = getContract(cfdAddress, this.web3)
484526

485527
if (
@@ -495,16 +537,18 @@ export default class CFDAPI {
495537
}
496538

497539
const value = safeValue(valueToAdd)
498-
return this.proxyApi.proxyTopup(accountProxy, cfd, value)
540+
return this.proxyApi.proxyTopup(accountProxy, cfd, value, gasLimit, gasPrice)
499541
}
500542

501543
/**
502544
* Withdraw the amount from a CFD
503545
* @param cfdAddress, Address of the deployed CFD
504546
* @param accountProxy, The address of the account who is withdrawing
505547
* @param valueToWithdraw, The amount the user wants to withdraw (DAI)
548+
* @param {Number} gasLimit How much gas we are willing to spent
549+
* @param {Number} gasPrice Price of the gas
506550
*/
507-
async withdraw(cfdAddress, accountProxy, valueToWithdraw) {
551+
async withdraw(cfdAddress, accountProxy, valueToWithdraw, gasLimit, gasPrice) {
508552
const cfd = getContract(cfdAddress, this.web3)
509553
if (
510554
(await cfd.methods
@@ -519,7 +563,7 @@ export default class CFDAPI {
519563
}
520564

521565
const value = safeValue(valueToWithdraw)
522-
return this.proxyApi.proxyWithdraw(accountProxy, cfd, value)
566+
return this.proxyApi.proxyWithdraw(accountProxy, cfd, value, gasLimit, gasPrice)
523567
}
524568

525569
/**

0 commit comments

Comments
 (0)