Skip to content

Commit 068457a

Browse files
authored
Merge pull request #101 from proto-kit/feature/tx-fees
Feature/tx fees
2 parents 9088675 + 51524b7 commit 068457a

File tree

74 files changed

+24657
-2347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+24657
-2347
lines changed

package-lock.json

Lines changed: 22698 additions & 1323 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "yab",
2+
"name": "protokit",
33
"version": "0.0.0",
44
"license": "MIT",
55
"type": "module",

packages/api/src/graphql/modules/QueryGraphqlModule.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
RuntimeModulesRecord,
2424
} from "@proto-kit/module";
2525
import {
26+
MandatoryProtocolModulesRecord,
2627
NetworkState,
2728
Protocol,
2829
ProtocolModulesRecord,
@@ -80,7 +81,9 @@ export class QueryGraphqlModule<
8081
private readonly networkStateTransportModule: NetworkStateTransportModule,
8182
@inject("Runtime") private readonly runtime: Runtime<RuntimeModules>,
8283
@inject("Protocol")
83-
private readonly protocol: Protocol<ProtocolModulesRecord>,
84+
private readonly protocol: Protocol<
85+
MandatoryProtocolModulesRecord & ProtocolModulesRecord
86+
>,
8487
@inject("BlockStorage")
8588
private readonly blockStorage: BlockStorage & HistoricalBlockStorage
8689
) {

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@proto-kit/protocol": "*",
3737
"@proto-kit/sdk": "*",
3838
"@proto-kit/sequencer": "*",
39+
"@proto-kit/library": "*",
3940
"o1js": "0.13.1"
4041
},
4142
"devDependencies": {
@@ -46,6 +47,7 @@
4647
"@proto-kit/protocol": "*",
4748
"@proto-kit/sdk": "*",
4849
"@proto-kit/sequencer": "*",
50+
"@proto-kit/library": "*",
4951
"@types/figlet": "^1.5.7",
5052
"@types/ink": "^2.0.3",
5153
"@types/node": "^20.8.10",

packages/cli/src/LocalhostAppChain.ts

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@ import "reflect-metadata";
22
import { PrivateKey } from "o1js";
33
import { Runtime, RuntimeModulesRecord } from "@proto-kit/module";
44
import {
5-
BlockProver,
6-
StateTransitionProver,
7-
VanillaProtocol,
8-
AccountStateModule,
5+
MandatoryProtocolModulesRecord,
6+
Protocol,
97
ProtocolModulesRecord,
108
} from "@proto-kit/protocol";
11-
import { ModulesConfig } from "@proto-kit/common";
129
import {
13-
BlockProducerModule,
14-
InMemoryDatabase,
15-
LocalTaskQueue,
16-
LocalTaskWorkerModule,
17-
ManualBlockTrigger,
18-
NoopBaseLayer,
19-
PrivateMempool,
20-
Sequencer,
21-
SequencerModulesRecord,
22-
UnprovenProducerModule,
23-
} from "@proto-kit/sequencer";
10+
InMemorySequencerModules,
11+
VanillaProtocolModules,
12+
VanillaRuntimeModules,
13+
} from "@proto-kit/library";
14+
import { Sequencer, SequencerModulesRecord } from "@proto-kit/sequencer";
2415
import {
2516
BlockStorageResolver,
2617
GraphqlSequencerModule,
@@ -33,41 +24,37 @@ import {
3324
} from "@proto-kit/api";
3425
import {
3526
AppChain,
36-
AppChainModulesRecord,
37-
InMemorySigner,
38-
InMemoryTransactionSender,
3927
StateServiceQueryModule,
4028
BlockStorageNetworkStateModule,
29+
AppChainModulesRecord,
30+
InMemoryTransactionSender,
4131
} from "@proto-kit/sdk";
4232

4333
export class LocalhostAppChain<
44-
RuntimeModules extends RuntimeModulesRecord
34+
RuntimeModules extends RuntimeModulesRecord,
35+
ProtocolModules extends ProtocolModulesRecord &
36+
MandatoryProtocolModulesRecord,
37+
SequencerModules extends SequencerModulesRecord,
38+
AppChainModules extends AppChainModulesRecord
4539
> extends AppChain<
4640
RuntimeModules,
47-
ProtocolModulesRecord,
48-
SequencerModulesRecord,
49-
AppChainModulesRecord
41+
ProtocolModules,
42+
SequencerModules,
43+
AppChainModules
5044
> {
51-
public static fromRuntime<
52-
RuntimeModules extends RuntimeModulesRecord
53-
>(definition: { modules: RuntimeModules }) {
45+
public static fromRuntime<RuntimeModules extends RuntimeModulesRecord>(
46+
runtimeModules: RuntimeModules
47+
) {
5448
const appChain = LocalhostAppChain.from({
55-
runtime: Runtime.from(definition),
56-
57-
protocol: VanillaProtocol.from({}),
58-
59-
sequencer: Sequencer.from({
60-
modules: {
61-
Database: InMemoryDatabase,
62-
Mempool: PrivateMempool,
63-
GraphqlServer,
64-
LocalTaskWorkerModule,
65-
BaseLayer: NoopBaseLayer,
66-
BlockProducerModule,
67-
UnprovenProducerModule,
68-
BlockTrigger: ManualBlockTrigger,
69-
TaskQueue: LocalTaskQueue,
70-
49+
Runtime: Runtime.from({
50+
modules: VanillaRuntimeModules.with(runtimeModules),
51+
}),
52+
Protocol: Protocol.from({
53+
modules: VanillaProtocolModules.with({}),
54+
}),
55+
Sequencer: Sequencer.from({
56+
modules: InMemorySequencerModules.with({
57+
GraphqlServer: GraphqlServer,
7158
Graphql: GraphqlSequencerModule.from({
7259
modules: {
7360
MempoolResolver,
@@ -78,26 +65,32 @@ export class LocalhostAppChain<
7865
MerkleWitnessResolver,
7966
},
8067
}),
81-
},
68+
}),
8269
}),
83-
8470
modules: {
71+
// TODO: remove in favour of a real tx sender for the SettlementModule
72+
// temporary dependency to make the SettlementModule work
73+
TransactionSender: InMemoryTransactionSender,
8574
QueryTransportModule: StateServiceQueryModule,
8675
NetworkStateTransportModule: BlockStorageNetworkStateModule,
8776
},
8877
});
8978

90-
appChain.configure({
91-
...appChain.config,
92-
79+
appChain.configurePartial({
9380
Protocol: {
9481
BlockProver: {},
9582
StateTransitionProver: {},
9683
AccountState: {},
9784
BlockHeight: {},
9885
LastStateRoot: {},
86+
TransactionFee: {
87+
tokenId: 0n,
88+
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
89+
baseFee: 0n,
90+
perWeightUnitFee: 0n,
91+
methods: {},
92+
},
9993
},
100-
10194
Sequencer: {
10295
Database: {},
10396
UnprovenProducerModule: {},
@@ -123,8 +116,10 @@ export class LocalhostAppChain<
123116
BaseLayer: {},
124117
TaskQueue: {},
125118
BlockTrigger: {},
119+
SettlementModule: {
120+
feepayer: PrivateKey.random(),
121+
},
126122
},
127-
128123
QueryTransportModule: {},
129124
NetworkStateTransportModule: {},
130125
});

packages/cli/src/commands/start.tsx

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import {
1010
state,
1111
} from "@proto-kit/module";
1212
import {
13-
AccountStateModule,
13+
AccountStateHook,
1414
Option,
15+
Protocol,
1516
State,
1617
StateMap,
17-
VanillaProtocol,
1818
} from "@proto-kit/protocol";
19+
import { VanillaProtocolModules } from "@proto-kit/library";
1920
import { Presets, log, TypedClass } from "@proto-kit/common";
2021
import {
2122
AsyncStateService,
@@ -54,98 +55,6 @@ import { Spinner } from "@inkjs/ui";
5455

5556
log.setLevel("ERROR");
5657

57-
export async function startServer({
58-
runtime,
59-
}: {
60-
runtime: TypedClass<Runtime<RuntimeModulesRecord>>;
61-
}) {
62-
const appChain = AppChain.from({
63-
runtime,
64-
65-
protocol: VanillaProtocol.from({}),
66-
67-
sequencer: Sequencer.from({
68-
modules: {
69-
Mempool: PrivateMempool,
70-
GraphqlServer,
71-
LocalTaskWorkerModule,
72-
BaseLayer: NoopBaseLayer,
73-
BlockProducerModule,
74-
BlockTrigger: ManualBlockTrigger,
75-
TaskQueue: LocalTaskQueue,
76-
77-
Graphql: GraphqlSequencerModule.from({
78-
modules: {
79-
MempoolResolver,
80-
QueryGraphqlModule,
81-
BlockStorageResolver,
82-
NodeStatusResolver,
83-
},
84-
85-
config: {
86-
MempoolResolver: {},
87-
QueryGraphqlModule: {},
88-
BlockStorageResolver: {},
89-
NodeStatusResolver: {},
90-
},
91-
}),
92-
},
93-
}),
94-
95-
modules: {
96-
Signer: InMemorySigner,
97-
TransactionSender: InMemoryTransactionSender,
98-
QueryTransportModule: StateServiceQueryModule,
99-
},
100-
});
101-
102-
appChain.configure({
103-
Runtime: {
104-
Balances: {},
105-
},
106-
107-
Protocol: {
108-
BlockProver: {},
109-
StateTransitionProver: {},
110-
AccountState: {},
111-
},
112-
113-
Sequencer: {
114-
GraphqlServer: {
115-
port: 8080,
116-
host: "0.0.0.0",
117-
graphiql: true,
118-
},
119-
120-
Graphql: {
121-
QueryGraphqlModule: {},
122-
MempoolResolver: {},
123-
BlockStorageResolver: {},
124-
NodeStatusResolver: {},
125-
},
126-
127-
Mempool: {},
128-
BlockProducerModule: {},
129-
LocalTaskWorkerModule: {},
130-
BaseLayer: {},
131-
TaskQueue: {},
132-
133-
BlockTrigger: {},
134-
},
135-
136-
TransactionSender: {},
137-
QueryTransportModule: {},
138-
139-
Signer: {
140-
signer: PrivateKey.random(),
141-
},
142-
});
143-
144-
await appChain.start();
145-
146-
return appChain;
147-
}
148-
14958
let appChain: AppChain<any, any, any, any>;
15059

15160
export interface UnprovenBlockExtras {

packages/cli/test/chain.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export class Balances extends RuntimeModule<object> {
3939
}
4040

4141
const appChain = LocalhostAppChain.fromRuntime({
42-
modules: {
43-
Balances,
44-
},
42+
Balances,
4543
});
4644

4745
appChain.configurePartial({

packages/common/src/config/ConfigurableModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface Configurable<Config> {
1919
config: Config;
2020
}
2121

22-
export type NoConfig = Record<string, never>;
22+
export type NoConfig = Record<never, never>;
2323

2424
/**
2525
* Used by various module sub-types that may need to be configured

packages/common/src/config/ModuleContainer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,21 @@ export class ModuleContainer<
289289
this.config = config;
290290
}
291291

292-
public configurePartial(
293-
config: RecursivePartial<ModulesConfig<Modules>>
294-
) {
292+
public configurePartial(config: RecursivePartial<ModulesConfig<Modules>>) {
295293
this.config = merge<
296-
(ModulesConfig<Modules>) | NoConfig,
294+
ModulesConfig<Modules> | NoConfig,
297295
RecursivePartial<ModulesConfig<Modules>>
298296
>(this.currentConfig ?? {}, config);
299297
}
300298

299+
public get config() {
300+
return super.config;
301+
}
302+
301303
// eslint-disable-next-line accessor-pairs
302304
public set config(config: ModulesConfig<Modules>) {
303305
super.config = merge<
304-
(ModulesConfig<Modules>) | NoConfig,
306+
ModulesConfig<Modules> | NoConfig,
305307
ModulesConfig<Modules>
306308
>(this.currentConfig ?? {}, config);
307309
}
@@ -346,9 +348,7 @@ export class ModuleContainer<
346348
moduleName: StringKeyOf<Modules>,
347349
containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
348350
) {
349-
// Has to be super.config, getters behave really weird when subtyping
350-
const config = super.config?.[moduleName];
351-
351+
const config = this.config?.[moduleName];
352352
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
353353
if (!config) {
354354
throw errors.configNotSetInContainer(moduleName.toString());

packages/common/src/zkProgrammable/ZkProgrammable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
4646
...args: any
4747
) => Promise<Proof<PublicInput, PublicOutput>>)
4848
>;
49+
analyzeMethods: ReturnType<typeof Experimental.ZkProgram>["analyzeMethods"];
4950
}
5051

5152
export function verifyToMockable<PublicInput, PublicOutput>(

0 commit comments

Comments
 (0)