Skip to content

Commit

Permalink
fix(providers): remove fee estimation (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Oct 27, 2024
1 parent 0edb91b commit 7b3f3c9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 94 deletions.
14 changes: 0 additions & 14 deletions apps/docs/src/pages/connect/wallet-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 0 additions & 12 deletions apps/klesia/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
4 changes: 0 additions & 4 deletions apps/klesia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
5 changes: 0 additions & 5 deletions apps/klesia/src/methods/mina.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
32 changes: 0 additions & 32 deletions apps/klesia/src/methods/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,11 @@ 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,
blockHash,
chainId,
sendTransaction,
getAccount,
estimateFees,
};
13 changes: 0 additions & 13 deletions apps/klesia/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const RpcMethod = z.enum([
"mina_chainId",
"mina_sendTransaction",
"mina_getAccount",
"mina_estimateFees",
]);
export type RpcMethodType = z.infer<typeof RpcMethod>;

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
]);
Expand Down
30 changes: 28 additions & 2 deletions packages/connect/src/__snapshots__/client.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down
12 changes: 12 additions & 0 deletions packages/connect/src/__snapshots__/store.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
`;
13 changes: 1 addition & 12 deletions packages/connect/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) => {
Expand All @@ -136,7 +126,7 @@ export const createWalletClient = ({
nonce = await getTransactionCount();
}
if (!fee) {
fee = (await estimateFees()).medium;
fee = "0.01";
}
return {
...transaction,
Expand All @@ -153,7 +143,6 @@ export const createWalletClient = ({
signMessage,
signFields,
createNullifier,
estimateFees,
prepareTransactionRequest,
};
};

0 comments on commit 7b3f3c9

Please sign in to comment.