Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

ensure kyber tx gas price is 50 gwei or less. reverts to 50 if greater #1869

Merged
merged 4 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/includes/swap-kyber-modal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<br/>
<!-- KYBER TOKEN TRANSACTION -->
<table class="table small table-condensed table-hover transaction-modal" ng-if="!kyberEthToToken">
<!-- SUMMARY -->
<tbody>
<tr>
<td></td>
Expand Down Expand Up @@ -130,7 +131,8 @@
<table class="table small table-condensed table-hover transaction-modal" ng-show="adv">
<tbody >

<!----------------------------------------------------------------->
<!---------------------- ADVANCED --------------------------------->
<!-- TOKEN SWAP TRANSACTION DETAILS -->
<tr>
<td class="text-left">Token Swap Transaction <br>
<small>via Kyber Network</small>
Expand Down Expand Up @@ -176,7 +178,7 @@
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand All @@ -193,7 +195,7 @@
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN APPROVAL TRANSACTION DETAILS -->
<tr>
<td> Token Approval Transaction</td>
</tr>
Expand Down Expand Up @@ -244,7 +246,7 @@
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTokenTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN RESET APPROVAL VALUE TRANSACTION DETAILS -->
<tr ng-show="kyberTransaction.tokenNeedsReset">
<td> Token Approval Reset Transaction<br>
<em><small>Why? The swap will fail to execute <wbr> if token approval is not reset to 0.</small></em></td>
Expand Down Expand Up @@ -352,7 +354,7 @@
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand Down
38 changes: 35 additions & 3 deletions app/scripts/controllers/swapCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ var swapCtrl = function ($scope, $sce, walletService) {
ethTxLink: null,
tokenNeedsReset: false,
currentTokenApprovalValue: 0,
kyberMaxGas: false,
tokenResetTx: null,
tokenResetTxRaw: null,
tokenResetTxHash: null,
Expand Down Expand Up @@ -908,9 +909,10 @@ var swapCtrl = function ($scope, $sce, walletService) {
try {
$scope.addressString = $scope.walletKyber.getAddressString();
$scope.tx = $scope.buildTransactionObject($scope.kyber.getTradeData($scope.kyberSwapOrder, $scope.kyberSwapOrder.finalRate), $scope.kyber.getKyberNetworkAddress(), $scope.kyberSwapOrder.fromVal);
console.log($scope); // todo remove dev item
var txData = uiFuncs.getTxData($scope);
// console.log("openKyberEthOrder", txData); // todo remove dev item
txData.nonce = txData.gasPrice = null;
txData.nonce = txData.gasprice = null;

$scope.generateKyberTransaction(txData, "OPEN_ETH");
} catch (e) {
Expand Down Expand Up @@ -1005,6 +1007,25 @@ var swapCtrl = function ($scope, $sce, walletService) {
// generate the transaction object based on the specific flow stage
$scope.generateKyberTransaction = function (txData, stage) {
try {
if(stage === "GENERATE_SWAP_TRANSACTION" || stage === "OPEN_ETH"){
let val = globalFuncs.localStorage.getItem("gasPrice")
let gp = new BigNumber(val)
if(gp.gte(50)){
$scope.kyberTransaction.kyberMaxGas = true;
txData.kyberGasPrice = "0xba43b7400"
}
console.log("gasPrice", val); // todo remove dev item
console.log("txData 11", txData); // todo remove dev item
}

// if(txData.gasPrice){
// let gp = new BigNumber(ethFuncs.sanitizeHex(txData.gasPrice))
//
// if(gp.gte(50000000000)){
// txData.gasPrice = "0xba43b7400"
// }
// }
txData.kyber = true;
uiFuncs.generateTx(txData, function (rawTx) {
if (!rawTx.isError) {
switch (stage) {
Expand Down Expand Up @@ -1060,6 +1081,7 @@ var swapCtrl = function ($scope, $sce, walletService) {

// Trigger the opening of the modal for user review and authorization to proceed
$scope.sendKyberModal = function () {
// console.log($scope.kyberTransaction); // todo remove dev item
// console.log($scope.kyberOrderResult.progress.status); //todo remove dev item
try {
switch ($scope.kyberOrderResult.progress.status) {
Expand Down Expand Up @@ -1206,6 +1228,16 @@ var swapCtrl = function ($scope, $sce, walletService) {
} else {
gasLimit = kyber.defaultValues.gasLimit
}
// if(gasPrice){
// let gp = new BigNumber(ethFuncs.sanitizeHex(gasPrice))
// if(gp.gte(50000000000)){
// gasPrice= "0xba43b7400"
// console.log("2", gp.toNumber()); // todo remove dev item
// }
// }
console.log("gasPrice", gasPrice); // todo remove dev item


return {
gasLimit: gasLimit,
data: data,
Expand Down Expand Up @@ -1284,7 +1316,7 @@ var swapCtrl = function ($scope, $sce, walletService) {
if ($scope.kyberTransaction.tokenNeedsReset) {
$scope.parsedKyberResetTokenTx = $scope.parseKyberSignedTransaction($scope.kyberTransaction.tokenResetTx.signedTx);

// Calculate Combined Values
// Calculate Combined Values (three transaction case)
$scope.parsedTx = {};
$scope.parsedTx.totalTxFee = {};
$scope.parsedTx.totalTxFee.wei = new BigNumber($scope.parsedKyberTx.txFee.wei).plus(new BigNumber($scope.parsedKyberTokenTx.txFee.wei)).plus(new BigNumber($scope.parsedKyberResetTokenTx.txFee.wei));
Expand All @@ -1297,7 +1329,7 @@ var swapCtrl = function ($scope, $sce, walletService) {
$scope.parsedTx.totalGasLimit = new BigNumber($scope.parsedKyberTokenTx.gasLimit).plus(new BigNumber($scope.parsedKyberTx.gasLimit)).plus(new BigNumber($scope.parsedKyberResetTokenTx.gasLimit));
} else {

// Calculate Combined Values
// Calculate Combined Values (two transaction case)
$scope.parsedTx = {};
$scope.parsedTx.totalTxFee = {};
$scope.parsedTx.totalTxFee.wei = new BigNumber($scope.parsedKyberTx.txFee.wei).plus(new BigNumber($scope.parsedKyberTokenTx.txFee.wei));
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/uiFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ uiFuncs.generateTx = function(txData, callback) {
try {
uiFuncs.isTxDataValid(txData);
var genTxWithInfo = function(data) {
// console.log("genTxWithInfo", data); // todo remove dev item
var rawTx = {
nonce: ethFuncs.sanitizeHex(data.nonce),
gasPrice: data.isOffline ? ethFuncs.sanitizeHex(data.gasprice) : ethFuncs.sanitizeHex(ethFuncs.addTinyMoreToGas(data.gasprice)),
Expand All @@ -159,6 +160,10 @@ uiFuncs.generateTx = function(txData, callback) {
value: ethFuncs.sanitizeHex(ethFuncs.decimalToHex(etherUnits.toWei(txData.value, txData.unit))),
data: ethFuncs.sanitizeHex(txData.data)
}
if(txData.kyberGasPrice){
rawTx.gasPrice = txData.kyberGasPrice;
}
console.log("rawTx to Sign", rawTx); // todo remove dev item
if (ajaxReq.eip155) rawTx.chainId = ajaxReq.chainId;
rawTx.data = rawTx.data == '' ? '0x' : rawTx.data;
var eTx = new ethUtil.Tx(rawTx);
Expand Down Expand Up @@ -241,6 +246,7 @@ uiFuncs.generateTx = function(txData, callback) {
}
}
uiFuncs.sendTx = function(signedTx, callback) {
console.log("signedTx", signedTx); // todo remove dev item
// check for web3 late signed tx
if (signedTx.slice(0, 2) !== '0x') {
var txParams = JSON.parse(signedTx)
Expand Down
12 changes: 7 additions & 5 deletions chrome-extension/cx-wallet.html
Original file line number Diff line number Diff line change
Expand Up @@ -3115,6 +3115,7 @@ <h4 class="text-primary">
<br/>
<!-- KYBER TOKEN TRANSACTION -->
<table class="table small table-condensed table-hover transaction-modal" ng-if="!kyberEthToToken">
<!-- SUMMARY -->
<tbody>
<tr>
<td></td>
Expand Down Expand Up @@ -3178,7 +3179,8 @@ <h5>Advanced</h5>
<table class="table small table-condensed table-hover transaction-modal" ng-show="adv">
<tbody >

<!----------------------------------------------------------------->
<!---------------------- ADVANCED --------------------------------->
<!-- TOKEN SWAP TRANSACTION DETAILS -->
<tr>
<td class="text-left">Token Swap Transaction <br>
<small>via Kyber Network</small>
Expand Down Expand Up @@ -3224,7 +3226,7 @@ <h5>Advanced</h5>
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand All @@ -3241,7 +3243,7 @@ <h5>Advanced</h5>
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN APPROVAL TRANSACTION DETAILS -->
<tr>
<td> Token Approval Transaction</td>
</tr>
Expand Down Expand Up @@ -3292,7 +3294,7 @@ <h5>Advanced</h5>
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTokenTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN RESET APPROVAL VALUE TRANSACTION DETAILS -->
<tr ng-show="kyberTransaction.tokenNeedsReset">
<td> Token Approval Reset Transaction<br>
<em><small>Why? The swap will fail to execute <wbr> if token approval is not reset to 0.</small></em></td>
Expand Down Expand Up @@ -3400,7 +3402,7 @@ <h5>Advanced</h5>
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand Down
46 changes: 42 additions & 4 deletions chrome-extension/js/etherwallet-master.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,7 @@ <h4 class="text-primary">
<br/>
<!-- KYBER TOKEN TRANSACTION -->
<table class="table small table-condensed table-hover transaction-modal" ng-if="!kyberEthToToken">
<!-- SUMMARY -->
<tbody>
<tr>
<td></td>
Expand Down Expand Up @@ -2563,7 +2564,8 @@ <h5>Advanced</h5>
<table class="table small table-condensed table-hover transaction-modal" ng-show="adv">
<tbody >

<!----------------------------------------------------------------->
<!---------------------- ADVANCED --------------------------------->
<!-- TOKEN SWAP TRANSACTION DETAILS -->
<tr>
<td class="text-left">Token Swap Transaction <br>
<small>via Kyber Network</small>
Expand Down Expand Up @@ -2609,7 +2611,7 @@ <h5>Advanced</h5>
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand All @@ -2626,7 +2628,7 @@ <h5>Advanced</h5>
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN APPROVAL TRANSACTION DETAILS -->
<tr>
<td> Token Approval Transaction</td>
</tr>
Expand Down Expand Up @@ -2677,7 +2679,7 @@ <h5>Advanced</h5>
<td class="small text-right">Data:</td>
<td class="small text-left mono text-width-limit"><p>{{parsedKyberTokenTx.data}}</p></td>
</tr>
<!----------------------------------------------------------------->
<!-- TOKEN RESET APPROVAL VALUE TRANSACTION DETAILS -->
<tr ng-show="kyberTransaction.tokenNeedsReset">
<td> Token Approval Reset Transaction<br>
<em><small>Why? The swap will fail to execute <wbr> if token approval is not reset to 0.</small></em></td>
Expand Down Expand Up @@ -2785,7 +2787,7 @@ <h5>Advanced</h5>
<tr>
<td class="small text-right">Gas Price:</td>
<td class="small text-left mono">{{parsedKyberTx.gasPrice.gwei}} GWEI
<small>({{parsedKyberTx.gasPrice.eth}} ETH)</small>
<small>({{parsedKyberTx.gasPrice.eth}} ETH) <span ng-if="kyberTransaction.kyberMaxGas">| Note: Kyber Network Gas Price Max is 50 GWEI</span></small>
</td>
</tr>
<tr>
Expand Down
Loading