Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getFeeStats endpoint #1006

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Added
- `rpc.Server` now has a `getFeeStats` method which retrieves fee statistics for a previous chunk of ledgers to provide users with a way to provide informed decisions about getting their transactions included in the following ledgers ([#998](https://github.com/stellar/js-stellar-sdk/issues/998)):

```typescript
export interface GetFeeStatsResponse {
sorobanInclusionFee: FeeDistribution;
inclusionFee: FeeDistribution;
latestLedger: number; // uint32
}

interface FeeDistribution {
max: string; // uint64
min: string; // uint64
mode: string; // uint64
p10: string; // uint64
p20: string; // uint64
p30: string; // uint64
p40: string; // uint64
p50: string; // uint64
p60: string; // uint64
p70: string; // uint64
p80: string; // uint64
p90: string; // uint64
p95: string; // uint64
p99: string; // uint64
transactionCount: string; // uint32
ledgerCount: number; // uint32
}
```
Comment on lines +9 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good.



## [v12.1.0](https://github.com/stellar/js-stellar-sdk/compare/v12.0.1...v12.1.0)

Expand Down
26 changes: 26 additions & 0 deletions src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,30 @@ export namespace Api {
/** State Difference information */
stateChanges?: RawLedgerEntryChange[];
}

export interface GetFeeStatsResponse {
sorobanInclusionFee: FeeDistribution;
inclusionFee: FeeDistribution;
latestLedger: number; // uint32
}

interface FeeDistribution {
max: string; // uint64
min: string; // uint64
mode: string; // uint64
p10: string; // uint64
p20: string; // uint64
p30: string; // uint64
p40: string; // uint64
p50: string; // uint64
p60: string; // uint64
p70: string; // uint64
p80: string; // uint64
p90: string; // uint64
p95: string; // uint64
p99: string; // uint64

transactionCount: string; // uint32
ledgerCount: number; // uint32
}
}
11 changes: 11 additions & 0 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,15 @@ export class Server {
throw error;
}
}

/**
* Provides an analysis of the recent fee stats for regular and smart
* contract operations.
*
* @returns {Promise<Api.GetFeeStatsResponse>} the fee stats
* @see https://soroban.stellar.org/api/methods/getFeeStats
*/
public async getFeeStats(): Promise<Api.GetFeeStatsResponse> {
return jsonrpc.postObject(this.serverURL.toString(), 'getFeeStats');
}
}
57 changes: 57 additions & 0 deletions test/unit/server/soroban/get_fee_stats_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { Server, AxiosClient } = StellarSdk.rpc;

describe("Server#getFeeStats", function () {
beforeEach(function () {
this.server = new Server(serverUrl);
this.axiosMock = sinon.mock(AxiosClient);
});

afterEach(function () {
this.axiosMock.verify();
this.axiosMock.restore();
});

it("requests the correct endpoint", function (done) {
const innerFeeStat = {
max: "100000000000000000000", // just > uint32
min: "100",
mode: "100",
p10: "100",
p20: "100",
p30: "100",
p40: "100",
p50: "100",
p60: "100",
p70: "100",
p80: "100",
p90: "100",
p95: "100",
p99: "100",
transactionCount: "200",
ledgerCount: "300",
};
const result = {
sorobanInclusionFee: innerFeeStat,
inclusionFee: innerFeeStat,
latestLedger: "12345678",
};

this.axiosMock
.expects("post")
.withArgs(serverUrl, {
jsonrpc: "2.0",
id: 1,
method: "getFeeStats",
params: null,
})
.returns(Promise.resolve({ data: { result } }));

this.server
.getFeeStats()
.then(function (response) {
expect(response).to.be.deep.equal(result);
done();
})
.catch((err) => done(err));
});
});
Loading