Skip to content

Commit 8e3fcf4

Browse files
committed
bump starknet-js version and update starknet rpc endpoint
1 parent 6d1a050 commit 8e3fcf4

File tree

21 files changed

+284
-360
lines changed

21 files changed

+284
-360
lines changed

apps/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,6 @@
163163
"mobx-utils": "^6",
164164
"react": "^16.8.0 || ^17 || ^18",
165165
"react-dom": "^16.8.0 || ^17 || ^18",
166-
"starknet": "^7"
166+
"starknet": "^8"
167167
}
168168
}

apps/extension/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,7 @@ export const EmbedChainInfos: (ChainInfo | ModularChainInfo)[] = [
22662266
"https://keplr-ext-update-note-images.s3.amazonaws.com/token/starknet.png",
22672267
starknet: {
22682268
chainId: "starknet:SN_MAIN",
2269-
rpc: "https://rpc-starknet.keplr.app/rpc/v0_8",
2269+
rpc: "https://rpc-starknet.keplr.app/rpc/v0_9",
22702270
currencies: [
22712271
{
22722272
type: "erc20",
@@ -2423,7 +2423,7 @@ export const EmbedChainInfos: (ChainInfo | ModularChainInfo)[] = [
24232423
"https://keplr-ext-update-note-images.s3.amazonaws.com/token/starknet.png",
24242424
starknet: {
24252425
chainId: "starknet:SN_SEPOLIA",
2426-
rpc: "https://rpc-starknet-sepolia.keplr.app/rpc/v0_8",
2426+
rpc: "https://rpc-starknet-sepolia.keplr.app/rpc/v0_9",
24272427
currencies: [
24282428
{
24292429
type: "erc20",

apps/extension/src/hooks/claim/use-starknet-claim-rewards.ts

Lines changed: 61 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIntl } from "react-intl";
22
import { useStore } from "../../stores";
3-
import { CoinPretty, Dec, Int } from "@keplr-wallet/unit";
3+
import { CoinPretty, Dec } from "@keplr-wallet/unit";
44
import { Call, CallData, num } from "starknet";
55
import { ERC20Currency } from "@keplr-wallet/types";
66
import { InExtensionMessageRequester } from "@keplr-wallet/router-extension";
@@ -91,45 +91,39 @@ export const useStarknetClaimRewards = () => {
9191
);
9292
}
9393

94-
const {
95-
l1_gas_consumed,
96-
l1_gas_price,
97-
l2_gas_consumed,
98-
l2_gas_price,
99-
l1_data_gas_consumed,
100-
l1_data_gas_price,
101-
} = await starknetAccount.estimateInvokeFee(
94+
const { resourceBounds } = await starknetAccount.estimateInvokeFee(
10295
account.starknetHexAddress,
10396
calls
10497
);
10598

106-
const extraL2GasForOnchainVerification = account.isNanoLedger
107-
? new Dec(90240)
108-
: new Dec(22039040);
109-
110-
const adjustedL2GasConsumed = new Dec(l2_gas_consumed ?? 0).add(
111-
extraL2GasForOnchainVerification
112-
);
99+
const { l1_gas, l2_gas, l1_data_gas } = resourceBounds;
113100

114-
const l1Fee = new Dec(l1_gas_consumed).mul(new Dec(l1_gas_price));
115-
const l2Fee = adjustedL2GasConsumed.mul(new Dec(l2_gas_price ?? 0));
116-
const l1DataFee = new Dec(l1_data_gas_consumed).mul(
117-
new Dec(l1_data_gas_price)
118-
);
101+
const extraL2GasForOnchainVerification = account.isNanoLedger
102+
? BigInt(90240)
103+
: BigInt(22039040);
119104

120-
const calculatedOverallFee = l1Fee.add(l2Fee).add(l1DataFee);
105+
const adjustedL2GasConsumed =
106+
l2_gas.max_amount + extraL2GasForOnchainVerification;
121107

122-
const margin = new Dec(1.5);
108+
const l1Fee = l1_gas.max_amount * l1_gas.max_price_per_unit;
109+
const l2Fee = adjustedL2GasConsumed * l2_gas.max_price_per_unit;
110+
const l1DataFee =
111+
l1_data_gas.max_amount * l1_data_gas.max_price_per_unit;
123112

124-
const totalGasConsumed = new Dec(l1_gas_consumed)
125-
.add(new Dec(l2_gas_consumed ?? 0))
126-
.add(new Dec(l1_data_gas_consumed));
113+
const calculatedOverallFee = l1Fee + l2Fee + l1DataFee;
127114

128-
const adjustedGasPrice = calculatedOverallFee.quo(totalGasConsumed);
115+
const totalGasConsumed =
116+
l1_gas.max_amount + adjustedL2GasConsumed + l1_data_gas.max_amount;
129117

130-
const gasPrice = new CoinPretty(feeCurrency, adjustedGasPrice);
131-
const maxGasPrice = gasPrice.mul(margin);
132-
const maxGas = totalGasConsumed.mul(margin);
118+
// margin 1.5x = 3/2
119+
const adjustedGasPrice = calculatedOverallFee / totalGasConsumed;
120+
const maxGasPrice = new CoinPretty(
121+
feeCurrency,
122+
new Dec(((adjustedGasPrice * BigInt(3)) / BigInt(2)).toString())
123+
);
124+
const maxGas = new Dec(
125+
((totalGasConsumed * BigInt(3)) / BigInt(2)).toString()
126+
);
133127

134128
// compare the account balance and fee
135129
const feeCurrencyBalance =
@@ -177,24 +171,27 @@ export const useStarknetClaimRewards = () => {
177171
);
178172
}
179173

180-
const maxL1DataGas = new Dec(l1_data_gas_consumed).mul(margin);
181-
const maxL1Gas = new Dec(l1_gas_consumed).mul(margin);
182-
const maxL2Gas = adjustedL2GasConsumed.mul(margin);
183-
184-
const maxL1DataGasPrice = new Dec(l1_data_gas_price).mul(margin);
185-
const maxL1GasPrice = new Dec(l1_gas_price).mul(margin);
186-
const maxL2GasPrice = new Dec(l2_gas_price ?? 0).mul(margin);
174+
// margin 1.5x = 3/2
175+
const maxL1Gas = (l1_gas.max_amount * BigInt(3)) / BigInt(2);
176+
const maxL1GasPrice =
177+
(l1_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
178+
const maxL2Gas = (adjustedL2GasConsumed * BigInt(3)) / BigInt(2);
179+
const maxL2GasPrice =
180+
(l2_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
181+
const maxL1DataGas = (l1_data_gas.max_amount * BigInt(3)) / BigInt(2);
182+
const maxL1DataGasPrice =
183+
(l1_data_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
187184

188185
const { transaction_hash: txHash } = await starknetAccount.execute(
189186
account.starknetHexAddress,
190187
calls,
191188
{
192-
l1MaxGas: maxL1Gas.truncate().toString(),
193-
l1MaxGasPrice: maxL1GasPrice.truncate().toString(),
194-
l1MaxDataGas: maxL1DataGas.truncate().toString(),
195-
l1MaxDataGasPrice: maxL1DataGasPrice.truncate().toString(),
196-
l2MaxGas: maxL2Gas.truncate().toString(),
197-
l2MaxGasPrice: maxL2GasPrice.truncate().toString(),
189+
l1MaxGas: num.toHex(maxL1Gas),
190+
l1MaxGasPrice: num.toHex(maxL1GasPrice),
191+
l1MaxDataGas: num.toHex(maxL1DataGas),
192+
l1MaxDataGasPrice: num.toHex(maxL1DataGasPrice),
193+
l2MaxGas: num.toHex(maxL2Gas),
194+
l2MaxGasPrice: num.toHex(maxL2GasPrice),
198195
},
199196
async (chainId, calls, details) => {
200197
return await new InExtensionMessageRequester().sendMessage(
@@ -291,54 +288,39 @@ export const useStarknetClaimRewards = () => {
291288
try {
292289
state.setIsSimulating(true);
293290

294-
const {
295-
l1_gas_consumed,
296-
l1_gas_price,
297-
l2_gas_consumed,
298-
l2_gas_price,
299-
l1_data_gas_consumed,
300-
l1_data_gas_price,
301-
} = await starknetAccount.estimateInvokeFee(
291+
const { resourceBounds } = await starknetAccount.estimateInvokeFee(
302292
account.starknetHexAddress,
303293
calls
304294
);
305295

306-
const extraL2GasForOnchainVerification = account.isNanoLedger
307-
? new Dec(90240)
308-
: new Dec(22039040);
309-
310-
const adjustedL2GasConsumed = new Dec(l2_gas_consumed ?? 0).add(
311-
extraL2GasForOnchainVerification
312-
);
296+
const { l1_gas, l2_gas, l1_data_gas } = resourceBounds;
313297

314-
const margin = new Dec(1.5);
315-
316-
const maxL1DataGas = new Dec(l1_data_gas_consumed).mul(margin);
317-
const maxL1Gas = new Dec(l1_gas_consumed).mul(margin);
318-
const maxL2Gas = adjustedL2GasConsumed.mul(margin);
298+
const extraL2GasForOnchainVerification = account.isNanoLedger
299+
? BigInt(90240)
300+
: BigInt(22039040);
319301

320-
const maxL1DataGasPrice = new Dec(l1_data_gas_price).mul(margin);
321-
const maxL1GasPrice = new Dec(l1_gas_price).mul(margin);
322-
const maxL2GasPrice = new Dec(l2_gas_price ?? 0).mul(margin);
302+
const adjustedL2GasConsumed =
303+
l2_gas.max_amount + extraL2GasForOnchainVerification;
323304

324-
const safeToHex = (value: string | Int | null | undefined): string => {
325-
if (value === null || value === undefined) {
326-
return "0";
327-
}
328-
const val = value.toString();
329-
return num.toHex(val === "0x" ? "0" : val);
330-
};
305+
// margin 1.5x = 3/2
306+
const maxL1Gas = (l1_gas.max_amount * BigInt(3)) / BigInt(2);
307+
const maxL1GasPrice = (l1_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
308+
const maxL2Gas = (adjustedL2GasConsumed * BigInt(3)) / BigInt(2);
309+
const maxL2GasPrice = (l2_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
310+
const maxL1DataGas = (l1_data_gas.max_amount * BigInt(3)) / BigInt(2);
311+
const maxL1DataGasPrice =
312+
(l1_data_gas.max_price_per_unit * BigInt(3)) / BigInt(2);
331313

332314
const { transaction_hash: txHash } = await starknetAccount.execute(
333315
account.starknetHexAddress,
334316
calls,
335317
{
336-
l1MaxGas: safeToHex(maxL1Gas.truncate()),
337-
l1MaxGasPrice: safeToHex(maxL1GasPrice.truncate()),
338-
l1MaxDataGas: safeToHex(maxL1DataGas.truncate()),
339-
l1MaxDataGasPrice: safeToHex(maxL1DataGasPrice.truncate()),
340-
l2MaxGas: safeToHex(maxL2Gas.truncate()),
341-
l2MaxGasPrice: safeToHex(maxL2GasPrice.truncate()),
318+
l1MaxGas: num.toHex(maxL1Gas),
319+
l1MaxGasPrice: num.toHex(maxL1GasPrice),
320+
l1MaxDataGas: num.toHex(maxL1DataGas),
321+
l1MaxDataGasPrice: num.toHex(maxL1DataGasPrice),
322+
l2MaxGas: num.toHex(maxL2Gas),
323+
l2MaxGasPrice: num.toHex(maxL2GasPrice),
342324
}
343325
);
344326
if (!txHash) {

apps/extension/src/pages/sign/utils/handle-starknet-sign.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import {
1212
Call,
1313
DeployAccountContractPayload,
14-
num,
1514
hash as starknetHash,
1615
shortString,
1716
constants,
@@ -37,7 +36,7 @@ import {
3736
} from "@ledgerhq/hw-app-starknet";
3837
import { PubKeyStarknet } from "@keplr-wallet/crypto";
3938
import { Fee } from "@keplr-wallet/stores-starknet/build/account/internal";
40-
import { Int } from "@keplr-wallet/unit";
39+
import { safeToBigInt } from "@keplr-wallet/common";
4140

4241
// eip-2645 derivation path, m/2645'/starknet'/{application}'/0'/{accountId}'/0
4342
export const STARKNET_LEDGER_DERIVATION_PATH =
@@ -88,14 +87,6 @@ export const connectAndSignDeployAccountTxWithLedger = async (
8887
chainId.replace("starknet:", "")
8988
) as constants.StarknetChainId;
9089

91-
const safeToHex = (value: string | Int | null | undefined): string => {
92-
if (value === null || value === undefined) {
93-
return "0";
94-
}
95-
const val = value.toString();
96-
return num.toHex(val === "0x" ? "0" : val);
97-
};
98-
9990
const transaction: V3DeployAccountSignerDetails = {
10091
version: "0x3",
10192
chainId: starknetChainId,
@@ -106,16 +97,16 @@ export const connectAndSignDeployAccountTxWithLedger = async (
10697
addressSalt,
10798
resourceBounds: {
10899
l1_gas: {
109-
max_amount: safeToHex(fee.l1MaxGas),
110-
max_price_per_unit: safeToHex(fee.l1MaxGasPrice),
100+
max_amount: safeToBigInt(fee.l1MaxGas),
101+
max_price_per_unit: safeToBigInt(fee.l1MaxGasPrice),
111102
},
112103
l2_gas: {
113-
max_amount: safeToHex(fee.l2MaxGas),
114-
max_price_per_unit: safeToHex(fee.l2MaxGasPrice),
104+
max_amount: safeToBigInt(fee.l2MaxGas),
105+
max_price_per_unit: safeToBigInt(fee.l2MaxGasPrice),
115106
},
116107
l1_data_gas: {
117-
max_amount: safeToHex(fee.l1MaxDataGas),
118-
max_price_per_unit: safeToHex(fee.l1MaxDataGasPrice),
108+
max_amount: safeToBigInt(fee.l1MaxDataGas),
109+
max_price_per_unit: safeToBigInt(fee.l1MaxDataGasPrice),
119110
},
120111
},
121112
tip: "0x0",

apps/extension/src/pages/starknet/components/account-activation-modal/index.tsx

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,41 +179,35 @@ export const AccountActivationModal: FunctionComponent<{
179179
"0x" + Buffer.from(params.salt).toString("hex")
180180
);
181181

182-
const {
183-
l1_gas_consumed,
184-
l1_gas_price,
185-
l2_gas_consumed,
186-
l2_gas_price,
187-
l1_data_gas_consumed,
188-
l1_data_gas_price,
189-
} = estimateResult;
182+
const { l1_gas, l2_gas, l1_data_gas } = estimateResult.resourceBounds;
190183

191184
const extraL2GasForOnchainVerification = account.isNanoLedger
192-
? new Dec(90240)
193-
: new Dec(22039040);
185+
? BigInt(90240)
186+
: BigInt(22039040);
194187

195-
const adjustedL2GasConsumed = new Dec(l2_gas_consumed ?? 0).add(
196-
extraL2GasForOnchainVerification
197-
);
198-
199-
const l1Fee = new Dec(l1_gas_consumed).mul(new Dec(l1_gas_price));
200-
const l2Fee = adjustedL2GasConsumed.mul(new Dec(l2_gas_price ?? 0));
201-
const l1DataFee = new Dec(l1_data_gas_consumed).mul(
202-
new Dec(l1_data_gas_price)
203-
);
188+
const adjustedL2GasConsumed =
189+
l2_gas.max_amount + extraL2GasForOnchainVerification;
204190

205-
const calculatedOverallFee = l1Fee.add(l2Fee).add(l1DataFee);
191+
const l1Fee = l1_gas.max_amount * l1_gas.max_price_per_unit;
192+
const l2Fee = adjustedL2GasConsumed * l2_gas.max_price_per_unit;
193+
const l1DataFee =
194+
l1_data_gas.max_amount * l1_data_gas.max_price_per_unit;
206195

207-
const totalGasConsumed = new Dec(l1_gas_consumed)
208-
.add(adjustedL2GasConsumed)
209-
.add(new Dec(l1_data_gas_consumed));
196+
const calculatedOverallFee = l1Fee + l2Fee + l1DataFee;
210197

211-
const adjustedGasPrice = calculatedOverallFee.quo(totalGasConsumed);
198+
const totalGasConsumed =
199+
l1_gas.max_amount + adjustedL2GasConsumed + l1_data_gas.max_amount;
212200

213-
const gasPriceMargin = new Dec(1.5);
214-
215-
const gasPrice = new CoinPretty(feeCurrency, adjustedGasPrice);
216-
const maxGasPrice = gasPrice.mul(gasPriceMargin);
201+
// margin 1.5x = 3/2
202+
const adjustedGasPrice = calculatedOverallFee / totalGasConsumed;
203+
const gasPrice = new CoinPretty(
204+
feeCurrency,
205+
new Dec(adjustedGasPrice.toString())
206+
);
207+
const maxGasPrice = new CoinPretty(
208+
feeCurrency,
209+
new Dec(((adjustedGasPrice * BigInt(3)) / BigInt(2)).toString())
210+
);
217211

218212
feeConfig.setGasPrice({
219213
gasPrice: gasPrice,
@@ -222,16 +216,16 @@ export const AccountActivationModal: FunctionComponent<{
222216

223217
return {
224218
l1Gas: {
225-
consumed: l1_gas_consumed.toString(),
226-
price: l1_gas_price.toString(),
219+
consumed: l1_gas.max_amount.toString(),
220+
price: l1_gas.max_price_per_unit.toString(),
227221
},
228222
l1DataGas: {
229-
consumed: l1_data_gas_consumed.toString(),
230-
price: l1_data_gas_price.toString(),
223+
consumed: l1_data_gas.max_amount.toString(),
224+
price: l1_data_gas.max_price_per_unit.toString(),
231225
},
232226
l2Gas: {
233227
consumed: adjustedL2GasConsumed.toString(),
234-
price: l2_gas_price?.toString() ?? "0",
228+
price: l2_gas.max_price_per_unit.toString(),
235229
},
236230
};
237231
};

0 commit comments

Comments
 (0)