diff --git a/.yarn/versions/833a7eca.yml b/.yarn/versions/833a7eca.yml new file mode 100644 index 00000000..ba59edbd --- /dev/null +++ b/.yarn/versions/833a7eca.yml @@ -0,0 +1,6 @@ +releases: + "@fluent-wallet/cfx_fee-history": patch + +declined: + - helios + - helios-background diff --git a/packages/background/package.json b/packages/background/package.json index 7ddbeae9..612764f0 100644 --- a/packages/background/package.json +++ b/packages/background/package.json @@ -14,6 +14,7 @@ "@fluent-wallet/cfx_client-version": "workspace:packages/rpcs/cfx_clientVersion", "@fluent-wallet/cfx_epoch-number": "workspace:packages/rpcs/cfx_epochNumber", "@fluent-wallet/cfx_estimate-gas-and-collateral": "workspace:packages/rpcs/cfx_estimateGasAndCollateral", + "@fluent-wallet/cfx_fee-history": "workspace:packages/rpcs/cfx_feeHistory", "@fluent-wallet/cfx_gas-price": "workspace:packages/rpcs/cfx_gasPrice", "@fluent-wallet/cfx_get-account": "workspace:packages/rpcs/cfx_getAccount", "@fluent-wallet/cfx_get-account-pending-info": "workspace:*", @@ -46,7 +47,7 @@ "@fluent-wallet/cfx_get-transaction-by-hash": "workspace:packages/rpcs/cfx_getTransactionByHash", "@fluent-wallet/cfx_get-transaction-receipt": "workspace:packages/rpcs/cfx_getTransactionReceipt", "@fluent-wallet/cfx_get-vote-list": "workspace:packages/rpcs/cfx_getVoteList", - "@fluent-wallet/cfx_max-priority-fee-per-gas": "workspace:*", + "@fluent-wallet/cfx_max-priority-fee-per-gas": "workspace:packages/rpcs/cfx_maxPriorityFeePerGas", "@fluent-wallet/cfx_net-version": "workspace:packages/rpcs/cfx_netVersion", "@fluent-wallet/cfx_opened-method-groups": "workspace:*", "@fluent-wallet/cfx_request-accounts": "workspace:packages/rpcs/cfx_requestAccounts", diff --git a/packages/background/src/index.integration.test.js b/packages/background/src/index.integration.test.js index 07f2dd51..8b22c147 100644 --- a/packages/background/src/index.integration.test.js +++ b/packages/background/src/index.integration.test.js @@ -167,6 +167,20 @@ describe('integration test', () => { }) }) + describe('cfx_feeHistory', async () => { + test('cfx_feeHistory', async () => { + const result = await request({ + method: 'cfx_feeHistory', + params: ['0x5', 'latest_state', [20, 30]], + }) + console.log(result) + expect(result.result.baseFeePerGas.length).toBe(6) + expect(result.result.gasUsedRatio.length).toBe(5) + expect(result.result.oldestEpoch).toBeDefined() + expect(result.result.reward.length).toBe(5) + }) + }) + describe('cfx_getStatus', () => { test('cfx_getStatus', async () => { const stat = await request({method: 'cfx_getStatus'}) @@ -329,7 +343,10 @@ describe('integration test', () => { ( await request({ method: 'wallet_deleteNetwork', - params: {password, networkId: db.getNetworkByType('eth')[0].eid}, + params: { + password, + networkId: db.getNetworkByType('eth')[0].eid, + }, }) ).result, ).toBe(true) @@ -359,7 +376,10 @@ describe('integration test', () => { ( await request({ method: 'wallet_deleteNetwork', - params: {password, networkId: db.getNetworkByName('foo')[0].eid}, + params: { + password, + networkId: db.getNetworkByName('foo')[0].eid, + }, }) ).error.message, ).toMatch(/Not allowed to delete builtin network/) @@ -1215,7 +1235,10 @@ describe('integration test', () => { // app is from the right site expect(app.site.eid).toBe(db.getSite()[0].eid) // app has the right permissions - expect(app.perms).toStrictEqual({wallet_accounts: {}, wallet_basic: {}}) + expect(app.perms).toStrictEqual({ + wallet_accounts: {}, + wallet_basic: {}, + }) // app has the right authed accounts expect( app.account.map(a => [a1.eid, a2.eid].includes(a.eid)), @@ -1289,7 +1312,10 @@ describe('integration test', () => { // app is from the right site expect(app.site.eid).toBe(db.getSite()[0].eid) // app has the right permissions - expect(app.perms).toStrictEqual({wallet_accounts: {}, wallet_basic: {}}) + expect(app.perms).toStrictEqual({ + wallet_accounts: {}, + wallet_basic: {}, + }) // app has the right authed accounts expect( app.account.map(a => [a1.eid, a2.eid].includes(a.eid)), @@ -1629,7 +1655,10 @@ describe('integration test', () => { ( await request({ method: 'wallet_getAddressPrivateKey', - params: {address: addr.value, accountId: db.getAccount()[0].eid}, + params: { + address: addr.value, + accountId: db.getAccount()[0].eid, + }, _internal: true, }) ).error.message, diff --git a/packages/background/src/rpc-engine-opts.js b/packages/background/src/rpc-engine-opts.js index a36abcd8..91a58419 100644 --- a/packages/background/src/rpc-engine-opts.js +++ b/packages/background/src/rpc-engine-opts.js @@ -91,7 +91,8 @@ import * as cfxSendRawTransaction from '@fluent-wallet/cfx_send-raw-transaction' import * as cfxSendTransaction from '@fluent-wallet/cfx_send-transaction' import * as cfxSignTransaction from '@fluent-wallet/cfx_sign-transaction' import * as cfxTypedSignV4 from '@fluent-wallet/cfx_sign-typed-data_v4' -import * as cfx_maxPriorityFeePerGas from '@fluent-wallet/cfx_max-priority-fee-per-gas' +import * as cfxMaxPriorityFeePerGas from '@fluent-wallet/cfx_max-priority-fee-per-gas' +import * as cfxFeeHistory from '@fluent-wallet/cfx_fee-history' import * as ethAccounts from '@fluent-wallet/eth_accounts' import * as ethBlockNumber from '@fluent-wallet/eth_block-number' import * as ethCall from '@fluent-wallet/eth_call' @@ -321,7 +322,8 @@ export const rpcEngineOpts = { cfxSendTransaction, cfxSignTxWithLedgerNanoS, cfxGetMaxGasLimit, - cfx_maxPriorityFeePerGas, + cfxMaxPriorityFeePerGas, + cfxFeeHistory, // eth ethGetCode, diff --git a/packages/rpcs/cfx_feeHistory/README.md b/packages/rpcs/cfx_feeHistory/README.md new file mode 100644 index 00000000..eb139798 --- /dev/null +++ b/packages/rpcs/cfx_feeHistory/README.md @@ -0,0 +1 @@ +# @fluent-wallet/cfx_fee-history diff --git a/packages/rpcs/cfx_feeHistory/doc.js b/packages/rpcs/cfx_feeHistory/doc.js new file mode 100644 index 00000000..52fdf31e --- /dev/null +++ b/packages/rpcs/cfx_feeHistory/doc.js @@ -0,0 +1,4 @@ +export default { + metadata: {standard: true}, + en: 'No doc available', +} diff --git a/packages/rpcs/cfx_feeHistory/index.js b/packages/rpcs/cfx_feeHistory/index.js new file mode 100644 index 00000000..783b1d20 --- /dev/null +++ b/packages/rpcs/cfx_feeHistory/index.js @@ -0,0 +1,28 @@ +import { + cat, + epochRefNoMined, + number, + schema, + string, + zeroOrMore, +} from '@fluent-wallet/spec' + +export const NAME = 'cfx_feeHistory' + +export const schemas = { + input: [ + cat, + string, + epochRefNoMined, + [schema, [zeroOrMore, [number, {max: 100, min: 1}]]], + ], +} + +export const permissions = { + external: ['popup', 'inpage'], + locked: true, +} + +export const main = ({f, params}) => { + return f(params) +} diff --git a/packages/rpcs/cfx_feeHistory/package.json b/packages/rpcs/cfx_feeHistory/package.json new file mode 100644 index 00000000..7cd25d18 --- /dev/null +++ b/packages/rpcs/cfx_feeHistory/package.json @@ -0,0 +1,9 @@ +{ + "name": "@fluent-wallet/cfx_fee-history", + "type": "module", + "main": "index.js", + "version": "0.0.0", + "dependencies": { + "@fluent-wallet/spec": "workspace:packages/spec" + } +} diff --git a/yarn.lock b/yarn.lock index 4436f552..ed7e05e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3746,6 +3746,14 @@ __metadata: languageName: unknown linkType: soft +"@fluent-wallet/cfx_fee-history@workspace:packages/rpcs/cfx_feeHistory": + version: 0.0.0-use.local + resolution: "@fluent-wallet/cfx_fee-history@workspace:packages/rpcs/cfx_feeHistory" + dependencies: + "@fluent-wallet/spec": "workspace:packages/spec" + languageName: unknown + linkType: soft + "@fluent-wallet/cfx_gas-price@workspace:packages/rpcs/cfx_gasPrice": version: 0.0.0-use.local resolution: "@fluent-wallet/cfx_gas-price@workspace:packages/rpcs/cfx_gasPrice" @@ -4028,7 +4036,7 @@ __metadata: languageName: unknown linkType: soft -"@fluent-wallet/cfx_max-priority-fee-per-gas@workspace:*, @fluent-wallet/cfx_max-priority-fee-per-gas@workspace:packages/rpcs/cfx_maxPriorityFeePerGas": +"@fluent-wallet/cfx_max-priority-fee-per-gas@workspace:packages/rpcs/cfx_maxPriorityFeePerGas": version: 0.0.0-use.local resolution: "@fluent-wallet/cfx_max-priority-fee-per-gas@workspace:packages/rpcs/cfx_maxPriorityFeePerGas" dependencies: @@ -17884,6 +17892,7 @@ __metadata: "@fluent-wallet/cfx_client-version": "workspace:packages/rpcs/cfx_clientVersion" "@fluent-wallet/cfx_epoch-number": "workspace:packages/rpcs/cfx_epochNumber" "@fluent-wallet/cfx_estimate-gas-and-collateral": "workspace:packages/rpcs/cfx_estimateGasAndCollateral" + "@fluent-wallet/cfx_fee-history": "workspace:packages/rpcs/cfx_feeHistory" "@fluent-wallet/cfx_gas-price": "workspace:packages/rpcs/cfx_gasPrice" "@fluent-wallet/cfx_get-account": "workspace:packages/rpcs/cfx_getAccount" "@fluent-wallet/cfx_get-account-pending-info": "workspace:*" @@ -17916,7 +17925,7 @@ __metadata: "@fluent-wallet/cfx_get-transaction-by-hash": "workspace:packages/rpcs/cfx_getTransactionByHash" "@fluent-wallet/cfx_get-transaction-receipt": "workspace:packages/rpcs/cfx_getTransactionReceipt" "@fluent-wallet/cfx_get-vote-list": "workspace:packages/rpcs/cfx_getVoteList" - "@fluent-wallet/cfx_max-priority-fee-per-gas": "workspace:*" + "@fluent-wallet/cfx_max-priority-fee-per-gas": "workspace:packages/rpcs/cfx_maxPriorityFeePerGas" "@fluent-wallet/cfx_net-version": "workspace:packages/rpcs/cfx_netVersion" "@fluent-wallet/cfx_opened-method-groups": "workspace:*" "@fluent-wallet/cfx_request-accounts": "workspace:packages/rpcs/cfx_requestAccounts"