-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dynamic evm gas estimation (#7449)
* feat: add the ShimmerEVM details * feat: add new encoding WIP * feat: Split getOutputParameters logic into l1 and l2 related * feat: Introduce Output (and related models) serialization code from iota.js * feat: add new encoding * feat: Add logic for gas estimation [WiP] * feat: Fix gas estimation request (seams to work now) [WiP] * chore: cleanup code * fix: test * feat: add profile migration to update evm chains * feat: Move iota.js Output building to helper function. Fix a type error. * feat: Fix response parsing for gasEstimate * feat: Add parsing recipient aliasId and sender pubKeyHash with iota-sdk in output serialization * feat: Build output for gas estimation using @iota/sdk prepareOutput * feat: Update gas estimation logic with help of Jorge * revert: undo changes that cant go to develop * fix: displayed gas estimation in send confirmation popup * fix: Skip tests about layer2 as getOutputParameters now does prepareOutput which we can't do in test context * feat: add gas estimation loading --------- Co-authored-by: cpl121 <[email protected]> Co-authored-by: Begoña Alvarez <[email protected]>
- Loading branch information
1 parent
410e0f2
commit c315744
Showing
7 changed files
with
491 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 38 additions & 4 deletions
42
packages/shared/lib/core/layer-2/utils/getEstimatedGasForTransferFromTransactionDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
import { GAS_BUDGET } from '../constants' | ||
import BigInteger from 'big-integer' | ||
import { getActiveProfile } from '@core/profile' | ||
|
||
export function getEstimatedGasForTransferFromTransactionDetails(): Promise<number> { | ||
// TODO: Add impl gas estimate with wasp API | ||
return Promise.resolve(GAS_BUDGET.toJSNumber()) | ||
interface GasEstimatePayload { | ||
gasBurned?: number | ||
gasFeeCharged?: number | ||
} | ||
|
||
export async function getEstimatedGasForTransferFromTransactionDetails( | ||
serializedOutputHex: string | ||
): Promise<GasEstimatePayload> { | ||
const profile = getActiveProfile() | ||
const chainMetadata = profile.network?.chains?.[0] ?? null | ||
|
||
if (chainMetadata) { | ||
const URL = `${chainMetadata.iscpEndpoint}/estimategas-onledger` | ||
const body = JSON.stringify({ outputBytes: serializedOutputHex }) | ||
|
||
const requestInit: RequestInit = { | ||
method: 'POST', | ||
body, | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
|
||
const response = await fetch(URL, requestInit) | ||
|
||
if (response.status === 200) { | ||
const data = await response.json() | ||
const gasBurned = BigInteger(data.gasBurned as string).toJSNumber() | ||
const gasFeeCharged = BigInteger(data.gasFeeCharged as string).toJSNumber() | ||
|
||
return { gasBurned, gasFeeCharged } | ||
} | ||
} | ||
|
||
return {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.