From 7b3f3c94775787a8e223c482358c71e3a164fe0b Mon Sep 17 00:00:00 2001 From: Tomek Marciniak Date: Sun, 27 Oct 2024 11:13:48 +0100 Subject: [PATCH] fix(providers): remove fee estimation (for now) --- apps/docs/src/pages/connect/wallet-client.mdx | 14 -------- apps/klesia/src/index.spec.ts | 12 ------- apps/klesia/src/index.ts | 4 --- apps/klesia/src/methods/mina.spec.ts | 5 --- apps/klesia/src/methods/mina.ts | 32 ------------------- apps/klesia/src/schema.ts | 13 -------- .../src/__snapshots__/client.spec.ts.snap | 30 +++++++++++++++-- .../src/__snapshots__/store.spec.ts.snap | 12 +++++++ packages/connect/src/client.ts | 13 +------- 9 files changed, 41 insertions(+), 94 deletions(-) diff --git a/apps/docs/src/pages/connect/wallet-client.mdx b/apps/docs/src/pages/connect/wallet-client.mdx index d126985..840dcd8 100644 --- a/apps/docs/src/pages/connect/wallet-client.mdx +++ b/apps/docs/src/pages/connect/wallet-client.mdx @@ -124,20 +124,6 @@ const client = createWalletClient({ account, network: "devnet" }); const chainId = await client.getChainId(); ``` -### Get estimated fees - -Query the estimated fees of a transaction. - -```ts twoslash -import { toAccount } from "@mina-js/accounts"; -import { createWalletClient } from '@mina-js/connect' - -const account = toAccount('B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5'); -const client = createWalletClient({ account, network: "devnet" }); - -const fees = await client.estimateFees(); -``` - ## Wallet commands If you provide a local wallet, Wallet Client will sign with it, otherwise, it will use the injected wallet. diff --git a/apps/klesia/src/index.spec.ts b/apps/klesia/src/index.spec.ts index 3530e72..2821101 100644 --- a/apps/klesia/src/index.spec.ts +++ b/apps/klesia/src/index.spec.ts @@ -55,16 +55,4 @@ describe("Mina Devnet RPC", () => { expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0); expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0); }); - - it("returns result for mina_estimateFee", async () => { - const response = await request({ - json: { - method: "mina_estimateFees", - }, - }); - const { result } = (await response.json()) as { - result: { medium: string }; - }; - expect(result.medium.length).toBeGreaterThan(0); - }); }); diff --git a/apps/klesia/src/index.ts b/apps/klesia/src/index.ts index 823fa74..2dea387 100644 --- a/apps/klesia/src/index.ts +++ b/apps/klesia/src/index.ts @@ -123,10 +123,6 @@ export const klesiaRpcRoute = api.openapi(rpcRoute, async ({ req, json }) => { }); return json(buildResponse({ result }), 200); }) - .with({ method: RpcMethod.enum.mina_estimateFees }, async () => { - const result = await mina.estimateFees(); - return json(buildResponse({ result }), 200); - }) .exhaustive(); }); diff --git a/apps/klesia/src/methods/mina.spec.ts b/apps/klesia/src/methods/mina.spec.ts index 23624fd..b012ee1 100644 --- a/apps/klesia/src/methods/mina.spec.ts +++ b/apps/klesia/src/methods/mina.spec.ts @@ -28,8 +28,3 @@ it("should get account info", async () => { expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0); expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0); }); - -it("should estimate fee", async () => { - const result = await mina.estimateFees(); - expect(result.medium.length).toBeGreaterThan(0); -}); diff --git a/apps/klesia/src/methods/mina.ts b/apps/klesia/src/methods/mina.ts index b67c123..136e930 100644 --- a/apps/klesia/src/methods/mina.ts +++ b/apps/klesia/src/methods/mina.ts @@ -175,37 +175,6 @@ const getAccount = async ({ publicKey }: { publicKey: string }) => { } }; -const estimateFees = async () => { - const client = getNodeClient(); - try { - const { data } = await client.query( - gql` - query { - snarkPool { - fee - } - } - `, - {}, - ); - const fees = data.snarkPool - .map((entry: { fee: string }) => entry.fee) - .filter((entry: string) => entry !== "0") - .map((entry: string) => BigInt(entry)); - return { - low: String(calculateQuantile(fees, PRIORITY.low)), - medium: String(calculateQuantile(fees, PRIORITY.medium)), - high: String(calculateQuantile(fees, PRIORITY.high)), - }; - } catch { - return { - low: "10000000", - medium: "100000000", - high: "200000000", - }; - } -}; - export const mina = { getTransactionCount, getBalance, @@ -213,5 +182,4 @@ export const mina = { chainId, sendTransaction, getAccount, - estimateFees, }; diff --git a/apps/klesia/src/schema.ts b/apps/klesia/src/schema.ts index 8b0b036..1483f2a 100644 --- a/apps/klesia/src/schema.ts +++ b/apps/klesia/src/schema.ts @@ -43,7 +43,6 @@ export const RpcMethod = z.enum([ "mina_chainId", "mina_sendTransaction", "mina_getAccount", - "mina_estimateFees", ]); export type RpcMethodType = z.infer; @@ -72,10 +71,6 @@ export const RpcMethodSchema = z.discriminatedUnion("method", [ method: z.literal(RpcMethod.enum.mina_getAccount), params: PublicKeyParamsSchema, }), - z.object({ - method: z.literal(RpcMethod.enum.mina_estimateFees), - params: EmptyParamsSchema, - }), ]); export const JsonRpcResponse = z.object({ @@ -122,14 +117,6 @@ export const RpcResponseSchema = z.union([ balance: z.string(), }), }), - JsonRpcResponse.extend({ - method: z.literal(RpcMethod.enum.mina_estimateFees), - result: z.object({ - low: z.string(), - medium: z.string(), - high: z.string(), - }), - }), ]), ErrorSchema, ]); diff --git a/packages/connect/src/__snapshots__/client.spec.ts.snap b/packages/connect/src/__snapshots__/client.spec.ts.snap index d1c5206..bf6d90d 100644 --- a/packages/connect/src/__snapshots__/client.spec.ts.snap +++ b/packages/connect/src/__snapshots__/client.spec.ts.snap @@ -3,7 +3,6 @@ exports[`matches snapshot of local source 1`] = ` { "createNullifier": [Function: AsyncFunction], - "estimateFees": [Function: AsyncFunction], "getAccounts": [Function: AsyncFunction], "getBalance": [Function: AsyncFunction], "getChainId": [Function: AsyncFunction], @@ -18,7 +17,34 @@ exports[`matches snapshot of local source 1`] = ` exports[`matches snapshot of json-rpc source 1`] = ` { "createNullifier": [Function: AsyncFunction], - "estimateFees": [Function: AsyncFunction], + "getAccounts": [Function: AsyncFunction], + "getBalance": [Function: AsyncFunction], + "getChainId": [Function: AsyncFunction], + "getTransactionCount": [Function: AsyncFunction], + "prepareTransactionRequest": [Function: AsyncFunction], + "signFields": [Function: AsyncFunction], + "signMessage": [Function: AsyncFunction], + "signTransaction": [Function: AsyncFunction], +} +`; + +exports[`matches snapshot of local source 2`] = ` +{ + "createNullifier": [Function: AsyncFunction], + "getAccounts": [Function: AsyncFunction], + "getBalance": [Function: AsyncFunction], + "getChainId": [Function: AsyncFunction], + "getTransactionCount": [Function: AsyncFunction], + "prepareTransactionRequest": [Function: AsyncFunction], + "signFields": [Function: AsyncFunction], + "signMessage": [Function: AsyncFunction], + "signTransaction": [Function: AsyncFunction], +} +`; + +exports[`matches snapshot of json-rpc source 2`] = ` +{ + "createNullifier": [Function: AsyncFunction], "getAccounts": [Function: AsyncFunction], "getBalance": [Function: AsyncFunction], "getChainId": [Function: AsyncFunction], diff --git a/packages/connect/src/__snapshots__/store.spec.ts.snap b/packages/connect/src/__snapshots__/store.spec.ts.snap index 0d7e124..54b5516 100644 --- a/packages/connect/src/__snapshots__/store.spec.ts.snap +++ b/packages/connect/src/__snapshots__/store.spec.ts.snap @@ -11,3 +11,15 @@ exports[`should initialize the store 1`] = ` "subscribe": [Function: subscribe], } `; + +exports[`should initialize the store 2`] = ` +{ + "_listeners": [Function: _listeners], + "clear": [Function: clear], + "destroy": [Function: destroy], + "findProvider": [Function: findProvider], + "getProviders": [Function: getProviders], + "reset": [Function: reset], + "subscribe": [Function: subscribe], +} +`; diff --git a/packages/connect/src/client.ts b/packages/connect/src/client.ts index 172df81..70193d2 100644 --- a/packages/connect/src/client.ts +++ b/packages/connect/src/client.ts @@ -117,16 +117,6 @@ export const createWalletClient = ({ if (account.type !== "local") throw new Error("Account type not supported"); return account.createNullifier(params); }; - const estimateFees = async () => { - const { result } = await klesiaClient.request<"mina_estimateFees">({ - method: "mina_estimateFees", - }); - return { - low: result.low, - medium: result.medium, - high: result.high, - }; - }; const prepareTransactionRequest = async ( transaction: PartiallyFormedTransactionProperties, ) => { @@ -136,7 +126,7 @@ export const createWalletClient = ({ nonce = await getTransactionCount(); } if (!fee) { - fee = (await estimateFees()).medium; + fee = "0.01"; } return { ...transaction, @@ -153,7 +143,6 @@ export const createWalletClient = ({ signMessage, signFields, createNullifier, - estimateFees, prepareTransactionRequest, }; };