Skip to content

Commit 50f69f6

Browse files
Merge pull request #7092 from BitGo/WIN-7368-avaxc-fix-max-gas-price-esimation
fix(avac): floor gas price estimates to 1
2 parents 659a51f + aa75ca7 commit 50f69f6

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

modules/sdk-coin-avaxc/src/avaxc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ export class AvaxC extends AbstractEthLikeNewCoins {
11031103
const feeEstimate: FeeEstimate = await this.feeEstimate(feeEstimateParams);
11041104

11051105
const gasLimit = feeEstimate.gasLimitEstimate;
1106-
const gasPrice = Math.round(feeEstimate.feeEstimate / gasLimit);
1106+
// Even if `feeEstimate < gasLimit`, we shouldn't end up with `gasPrice === 0`.
1107+
const gasPrice = Math.max(Math.round(feeEstimate.feeEstimate / gasLimit), 1);
11071108
const gasPriceMax = gasPrice * 5;
11081109
// Payment id a random number so its different for every tx
11091110
const paymentId = Math.floor(Math.random() * 10000000000).toString();

modules/sdk-coin-avaxc/test/unit/avaxc.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,41 @@ describe('Avalanche C-Chain', function () {
785785
});
786786
});
787787

788+
describe('Hop Transaction Parameters', () => {
789+
const sandBox = sinon.createSandbox();
790+
791+
afterEach(function () {
792+
sandBox.restore();
793+
});
794+
795+
it('should create hop transaction parameters with gasPriceMax > 0', async function () {
796+
const mockFeeEstimate = {
797+
feeEstimate: '120000',
798+
gasLimitEstimate: 500000,
799+
};
800+
sandBox.stub(tavaxCoin, 'feeEstimate').resolves(mockFeeEstimate);
801+
const recipients = [
802+
{
803+
address:
804+
'P-fuji14xa0q4858ct3kfvpkwnw2dys3m63kt6famckf6~P-fuji1hljye3kesjtpj87m00e8vwkayg6eys6theuxfg~P-fuji1lelqx4cleh3dzk5kplstz6mwrt3duk7d7wwmpp',
805+
amount: '100000000000000000',
806+
},
807+
];
808+
809+
const result = await tavaxCoin.createHopTransactionParams({
810+
recipients,
811+
type: 'Export' as keyof typeof TransactionType,
812+
});
813+
814+
result.should.have.property('hopParams');
815+
result.hopParams.should.have.properties(['userReqSig', 'gasPriceMax', 'paymentId', 'gasLimit']);
816+
result.hopParams.userReqSig.should.equal('0x');
817+
result.hopParams.gasPriceMax.should.be.above(0);
818+
result.hopParams.paymentId.should.be.a.String();
819+
result.hopParams.gasLimit.should.equal(500000);
820+
});
821+
});
822+
788823
describe('Explain Transaction', () => {
789824
it('should explain a half signed import in C transaction', async () => {
790825
const testData = IMPORT_C;

0 commit comments

Comments
 (0)