Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 28927bf

Browse files
committed
feat: use EIP1559 gas prices for ZRX Portal
1 parent a836942 commit 28927bf

File tree

8 files changed

+287
-80
lines changed

8 files changed

+287
-80
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"fix": "yarn lint --fix",
2020
"pre_push": "yarn lint:prettier && yarn lint && yarn test",
2121
"update:tools": "aws s3 sync --delete s3://docs-markdown/ mdx/tools/ --profile $(npm config get awscli_profile)",
22-
"dev": "npm run update:tools && node --max-old-space-size=16384 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode development --content-base public --https",
22+
"dev": "npm run update:tools && node --max-old-space-size=16384 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode development --content-base public",
2323
"deploy_dogfood": "npm run update:tools && yarn index_docs --environment dogfood && npm run build:prod && aws s3 sync ./public/. s3://dogfood.0xproject.com --profile $(npm config get awscli_profile) --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers && ./cdn-cache-clear.sh dogfood",
2424
"deploy_staging": "npm run update:tools && yarn index_docs --environment staging && npm run build:prod && aws s3 sync ./public/. s3://staging-0xproject --profile $(npm config get awscli_profile) --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers",
2525
"deploy_live": "npm run update:tools && yarn index_docs --environment production && DEPLOY_ROLLBAR_SOURCEMAPS=true npm run build:prod && aws s3 sync ./public/. s3://0x.org --profile $(npm config get awscli_profile) --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --exclude *.map.js && ./cdn-cache-clear.sh live",
@@ -36,13 +36,13 @@
3636
"dependencies": {
3737
"@0x/asset-buyer": "6.2.0-beta.3",
3838
"@0x/contract-addresses": "^4.1.0",
39-
"@0x/contract-wrappers": "^13.2.0",
39+
"@0x/contract-wrappers": "^13.18.0",
4040
"@0x/contracts-dev-utils": "^1.0.2",
4141
"@0x/contracts-treasury": "^1.0.2",
42-
"@0x/json-schemas": "^5.0.2",
42+
"@0x/json-schemas": "^6.4.0",
4343
"@0x/order-utils": "^10.0.1",
44-
"@0x/subproviders": "^6.0.2",
45-
"@0x/utils": "^5.1.1",
44+
"@0x/subproviders": "^6.6.1",
45+
"@0x/utils": "^6.4.4",
4646
"@0x/web3-wrapper": "^7.0.2",
4747
"@reach/dialog": "^0.11.2",
4848
"@reach/tabs": "^0.1.6",
@@ -70,7 +70,7 @@
7070
"deep-equal": "^1.0.1",
7171
"dotenv": "^10.0.0",
7272
"dotenv-webpack": "^7.0.3",
73-
"ethereum-types": "^3.0.0",
73+
"ethereum-types": "^3.6.0",
7474
"ethereumjs-util": "^5.1.1",
7575
"ethers": "^5.0.24",
7676
"find-versions": "^2.0.0",

ts/hooks/use_allowance.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const useAllowance = (): UseAllowanceHookResult => {
4141
const ownerAddress = (providerState.account as AccountReady).address;
4242

4343
// const localStorageSpeed = localStorage.getItem('gas-speed');
44-
const gasInfo = await backendClient.getGasInfoAsync('instant');
44+
const gasInfo = await backendClient.getGasInfoAsync();
4545

4646
const contractAddresses = getContractAddressesForChainOrThrow(networkId);
4747
const erc20ProxyAddress = contractAddresses.erc20Proxy;
@@ -56,7 +56,8 @@ export const useAllowance = (): UseAllowanceHookResult => {
5656
.approve(erc20ProxyAddress, constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
5757
.awaitTransactionSuccessAsync({
5858
from: ownerAddress,
59-
gasPrice: gasInfo.gasPriceInWei,
59+
maxFeePerGas: gasInfo.maxFeePerGas,
60+
maxPriorityFeePerGas: gasInfo.maxPriorityFeePerGas,
6061
});
6162

6263
await txPromise.txHashPromise;

ts/hooks/use_stake.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ export const useStake = (networkId: ChainId, providerState: ProviderState): UseS
119119
setLoadingState(TransactionLoadingState.WaitingForSignature);
120120

121121
// const localStorageSpeed = localStorage.getItem('gas-speed');
122-
const gasInfo = await backendClient.getGasInfoAsync('instant');
123-
const txPromise = stakingProxyContract
124-
.batchExecute(data)
125-
.awaitTransactionSuccessAsync({ from: ownerAddress, gasPrice: gasInfo.gasPriceInWei });
122+
const gasInfo = await backendClient.getGasInfoAsync();
123+
const txPromise = stakingProxyContract.batchExecute(data).awaitTransactionSuccessAsync({
124+
from: ownerAddress,
125+
maxFeePerGas: gasInfo.maxFeePerGas,
126+
maxPriorityFeePerGas: gasInfo.maxPriorityFeePerGas,
127+
});
126128

127129
await txPromise.txHashPromise;
128130
setEstimatedTimeMs(gasInfo.estimatedTimeMs);
@@ -249,11 +251,13 @@ export const useStake = (networkId: ChainId, providerState: ProviderState): UseS
249251

250252
setLoadingState(TransactionLoadingState.WaitingForSignature);
251253

252-
const gasInfo = await backendClient.getGasInfoAsync('instant');
254+
const gasInfo = await backendClient.getGasInfoAsync();
253255

254-
const txPromise = stakingContract
255-
.unstake(zrxAmountBaseUnits)
256-
.awaitTransactionSuccessAsync({ from: ownerAddress, gasPrice: gasInfo.gasPriceInWei });
256+
const txPromise = stakingContract.unstake(zrxAmountBaseUnits).awaitTransactionSuccessAsync({
257+
from: ownerAddress,
258+
maxFeePerGas: gasInfo.maxFeePerGas,
259+
maxPriorityFeePerGas: gasInfo.maxPriorityFeePerGas,
260+
});
257261

258262
await txPromise.txHashPromise;
259263
setEstimatedTimeMs(gasInfo.estimatedTimeMs);

ts/pages/governance/vote_form.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,19 @@ class VoteFormComponent extends React.Component<Props> {
275275
const { votePreference } = this.state;
276276

277277
// const localStorageSpeed = localStorage.getItem('gas-speed');
278-
const gasInfo = await backendClient.getGasInfoAsync('instant');
278+
const gasInfo = await backendClient.getGasInfoAsync();
279279

280280
const txPromise = contract
281281
.castVote(
282282
proposalIdBigNumber,
283283
votePreference === VoteValue.Yes,
284284
operatedPools ? operatedPools.map((pool) => encodePoolId(parseInt(pool.poolId, 10))) : [],
285285
)
286-
.awaitTransactionSuccessAsync({ from: selectedAddress, gasPrice: gasInfo.gasPriceInWei });
286+
.awaitTransactionSuccessAsync({
287+
from: selectedAddress,
288+
maxFeePerGas: gasInfo.maxFeePerGas,
289+
maxPriorityFeePerGas: gasInfo.maxPriorityFeePerGas,
290+
});
287291
const txHash = await txPromise.txHashPromise;
288292
if (onVoted) {
289293
this.setState({

ts/types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,17 @@ export interface WebsiteBackendTokenInfo {
817817
symbol: string;
818818
}
819819

820-
export interface GasInfo {
821-
gasPriceInWei: BigNumber;
822-
estimatedTimeMs: number;
820+
export interface EIP1559GasInfo {
821+
price: number;
822+
maxPriorityFeePerGas: number;
823+
maxFeePerGas: number;
824+
baseFeePerGas: number;
823825
}
824826

827+
export type GasInfo = EIP1559GasInfo & {
828+
estimatedTimeMs: number;
829+
};
830+
825831
export interface WebsiteBackendGasWaitTimeInfo {
826832
fastestWait: number;
827833
fastWait: number;

ts/utils/backend_client.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BigNumber } from '@0x/utils';
21
import * as _ from 'lodash';
32

43
import { Web3Wrapper } from '@0x/web3-wrapper';
54
import { ZeroExProvider } from 'ethereum-types';
65

76
import {
7+
EIP1559GasInfo,
88
GasInfo,
99
MailchimpSubscriberInfo,
1010
WebsiteBackendCFLMetricsData,
@@ -17,7 +17,6 @@ import {
1717
WebsiteBackendTokenInfo,
1818
WebsiteBackendTradingPairs,
1919
} from 'ts/types';
20-
import { constants } from 'ts/utils/constants';
2120
import { fetchUtils } from 'ts/utils/fetch_utils';
2221
import { utils } from 'ts/utils/utils';
2322

@@ -41,11 +40,18 @@ export interface GasInfoSelection {
4140
fast: number;
4241
}
4342

44-
const speedToSelectionMap: { [key: string]: string } = {
45-
standard: 'average',
46-
fast: 'fast',
47-
instant: 'fastest',
48-
};
43+
interface GasApiSingleSourceResponse {
44+
result: {
45+
source: string;
46+
timestamp: number;
47+
instant: EIP1559GasInfo;
48+
fast: EIP1559GasInfo;
49+
standard: EIP1559GasInfo;
50+
low: EIP1559GasInfo;
51+
};
52+
}
53+
54+
type GasSpeedSelectors = 'instant' | 'fast' | 'standard' | 'low';
4955

5056
const speedToWaitTimeMap: { [key: string]: string } = {
5157
standard: 'avgWait',
@@ -199,29 +205,22 @@ export const backendClient = {
199205
return data;
200206
},
201207

202-
async getGasInfoAsync(speed?: string): Promise<GasInfo> {
203-
// Median gas prices across 0x api gas oracles
204-
// Defaulting to average/standard gas. Using eth gas station for time estimates
205-
const gasApiPath = 'source/gas_now?output=eth_gas_station';
206-
const gasInfoReq = fetchUtils.requestAsync(ZEROEX_GAS_API, gasApiPath);
207-
const speedInput = speed || 'standard';
208+
async getGasInfoAsync(speed?: GasSpeedSelectors): Promise<GasInfo> {
209+
const gasApiPath = 'v2/source/block_native';
210+
const gasInfoReq: Promise<GasApiSingleSourceResponse> = fetchUtils.requestAsync(ZEROEX_GAS_API, gasApiPath);
211+
const speedInput: GasSpeedSelectors = speed || 'standard';
208212

209-
const gasSpeed = speedToSelectionMap[speedInput];
210-
const waitTime = speedToWaitTimeMap[speedInput];
211213
const gasWaitTimesReq = fetchUtils.requestAsync(utils.getBackendBaseUrl(), ETH_GAS_STATION_ENDPOINT);
212214

213-
const res: [WebsiteBackendGasInfo, WebsiteBackendGasWaitTimeInfo] = await Promise.all([
215+
const [gasInfo, gasWaitTimes]: [GasApiSingleSourceResponse, WebsiteBackendGasWaitTimeInfo] = await Promise.all([
214216
gasInfoReq,
215217
gasWaitTimesReq,
216218
]);
217-
const gasInfo = res[0];
218-
const gasWaitTimes = res[1];
219-
// Eth Gas Station result is gwei * 10
220-
const gasPriceInGwei = new BigNumber((gasInfo as any)[gasSpeed] / 10);
221219
// Time is in minutes
220+
const waitTime = speedToWaitTimeMap[speedInput];
222221
const estimatedTimeMs = (gasWaitTimes as any)[waitTime] * 60 * 1000; // Minutes to MS
223222

224-
return { gasPriceInWei: gasPriceInGwei.multipliedBy(constants.GWEI_IN_WEI), estimatedTimeMs };
223+
return { ...gasInfo.result[speedInput], estimatedTimeMs };
225224
},
226225

227226
async getGasInfoSelectionAsync(): Promise<GasInfoSelection> {

webpack.config.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,12 @@ module.exports = (_env, argv) => {
147147
disableHostCheck: true,
148148
// Fixes assertion error
149149
// Source: https://github.com/webpack/webpack-dev-server/issues/1491
150-
https: {
151-
spdy: {
152-
protocols: ['http/1.1'],
153-
},
154-
},
155150
},
156151
};
157152

158153
if (isDevEnvironment) {
159154
config.mode = 'development';
160155
config.devtool = 'cheap-module-eval-source-map';
161-
// SSL certs
162-
if (fs.existsSync('./server.cert') && fs.existsSync('./server.key')) {
163-
config.devServer.https = {
164-
...config.devServer.https,
165-
key: fs.readFileSync('./server.key'),
166-
cert: fs.readFileSync('./server.cert'),
167-
};
168-
}
169156
} else {
170157
config.mode = 'production';
171158
config.devtool = 'source-map';

0 commit comments

Comments
 (0)