Skip to content

Commit

Permalink
allow custom gas price and gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lessmore92 committed Nov 13, 2021
1 parent 977443d commit df6555e
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions src/Foundation/StandardERC20Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ public function balanceOf(string $address)
* @param float $amount
* @return Transaction\Transaction
*/
public function transfer(string $from, string $to, float $amount)
public function transfer(string $from, string $to, float $amount, string $gasLimit = 'default', string $gasPrice = 'default')
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferData($to, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($from, 'pending'));
$gasLimit = $this->getGasLimit('transfer');
$gasPrice = $this->getSafeGasPrice();
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferData($to, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($from, 'pending'));
if (strtolower($gasLimit) === 'default')
{
$gasLimit = $this->getGasLimit('transfer');
}
if (strtolower($gasPrice) === 'default')
{
$gasPrice = $this->getSafeGasPrice();
}

return (new TransactionBuilder())
->setEth($this->getEth())
Expand All @@ -96,14 +102,20 @@ public function buildTransferData(string $to, $amount)
;
}

public function approve(string $ownerAddress, string $spenderAddress, string $amount)
public function approve(string $ownerAddress, string $spenderAddress, string $amount, string $gasLimit = 'default', string $gasPrice = 'default')
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildApproveData($spenderAddress, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($ownerAddress, 'pending'));
$gasLimit = $this->getGasLimit('approve');
$gasPrice = $this->getSafeGasPrice();
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildApproveData($spenderAddress, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($ownerAddress, 'pending'));
if (strtolower($gasLimit) === 'default')
{
$gasLimit = $this->getGasLimit('approve');
}
if (strtolower($gasPrice) === 'default')
{
$gasPrice = $this->getSafeGasPrice();
}

return (new TransactionBuilder())
->setEth($this->getEth())
Expand Down Expand Up @@ -137,14 +149,20 @@ public function allowance(string $ownerAddress, string $spenderAddress)
* @param float $amount
* @return Transaction\Transaction
*/
public function transferFrom(string $spender, string $from, string $to, float $amount)
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferFromData($from, $to, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($spender, 'pending'));
$gasLimit = $this->getGasLimit('transferFrom');
$gasPrice = $this->getSafeGasPrice();
public function transferFrom(string $spender, string $from, string $to, float $amount, string $gasLimit = 'default', string $gasPrice = 'default')
{
$amount = Number::scaleUp($amount, $this->decimals());
$data = $this->buildTransferFromData($from, $to, $amount);
$nonce = Number::toHex($this->getEth()
->getTransactionCount($spender, 'pending'));
if (strtolower($gasLimit) === 'default')
{
$gasLimit = $this->getGasLimit('transferFrom');
}
if (strtolower($gasPrice) === 'default')
{
$gasPrice = $this->getSafeGasPrice();
}

return (new TransactionBuilder())
->setEth($this->getEth())
Expand Down

0 comments on commit df6555e

Please sign in to comment.