Skip to content

Commit

Permalink
Merge pull request #101 from proto-kit/feature/tx-fees
Browse files Browse the repository at this point in the history
Feature/tx fees
  • Loading branch information
maht0rz authored Mar 29, 2024
2 parents 9088675 + 51524b7 commit 068457a
Show file tree
Hide file tree
Showing 74 changed files with 24,657 additions and 2,347 deletions.
24,021 changes: 22,698 additions & 1,323 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "yab",
"name": "protokit",
"version": "0.0.0",
"license": "MIT",
"type": "module",
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/graphql/modules/QueryGraphqlModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
RuntimeModulesRecord,
} from "@proto-kit/module";
import {
MandatoryProtocolModulesRecord,
NetworkState,
Protocol,
ProtocolModulesRecord,
Expand Down Expand Up @@ -80,7 +81,9 @@ export class QueryGraphqlModule<
private readonly networkStateTransportModule: NetworkStateTransportModule,
@inject("Runtime") private readonly runtime: Runtime<RuntimeModules>,
@inject("Protocol")
private readonly protocol: Protocol<ProtocolModulesRecord>,
private readonly protocol: Protocol<
MandatoryProtocolModulesRecord & ProtocolModulesRecord
>,
@inject("BlockStorage")
private readonly blockStorage: BlockStorage & HistoricalBlockStorage
) {
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@proto-kit/protocol": "*",
"@proto-kit/sdk": "*",
"@proto-kit/sequencer": "*",
"@proto-kit/library": "*",
"o1js": "0.13.1"
},
"devDependencies": {
Expand All @@ -46,6 +47,7 @@
"@proto-kit/protocol": "*",
"@proto-kit/sdk": "*",
"@proto-kit/sequencer": "*",
"@proto-kit/library": "*",
"@types/figlet": "^1.5.7",
"@types/ink": "^2.0.3",
"@types/node": "^20.8.10",
Expand Down
93 changes: 44 additions & 49 deletions packages/cli/src/LocalhostAppChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@ import "reflect-metadata";
import { PrivateKey } from "o1js";
import { Runtime, RuntimeModulesRecord } from "@proto-kit/module";
import {
BlockProver,
StateTransitionProver,
VanillaProtocol,
AccountStateModule,
MandatoryProtocolModulesRecord,
Protocol,
ProtocolModulesRecord,
} from "@proto-kit/protocol";
import { ModulesConfig } from "@proto-kit/common";
import {
BlockProducerModule,
InMemoryDatabase,
LocalTaskQueue,
LocalTaskWorkerModule,
ManualBlockTrigger,
NoopBaseLayer,
PrivateMempool,
Sequencer,
SequencerModulesRecord,
UnprovenProducerModule,
} from "@proto-kit/sequencer";
InMemorySequencerModules,
VanillaProtocolModules,
VanillaRuntimeModules,
} from "@proto-kit/library";
import { Sequencer, SequencerModulesRecord } from "@proto-kit/sequencer";
import {
BlockStorageResolver,
GraphqlSequencerModule,
Expand All @@ -33,41 +24,37 @@ import {
} from "@proto-kit/api";
import {
AppChain,
AppChainModulesRecord,
InMemorySigner,
InMemoryTransactionSender,
StateServiceQueryModule,
BlockStorageNetworkStateModule,
AppChainModulesRecord,
InMemoryTransactionSender,
} from "@proto-kit/sdk";

export class LocalhostAppChain<
RuntimeModules extends RuntimeModulesRecord
RuntimeModules extends RuntimeModulesRecord,
ProtocolModules extends ProtocolModulesRecord &
MandatoryProtocolModulesRecord,
SequencerModules extends SequencerModulesRecord,
AppChainModules extends AppChainModulesRecord
> extends AppChain<
RuntimeModules,
ProtocolModulesRecord,
SequencerModulesRecord,
AppChainModulesRecord
ProtocolModules,
SequencerModules,
AppChainModules
> {
public static fromRuntime<
RuntimeModules extends RuntimeModulesRecord
>(definition: { modules: RuntimeModules }) {
public static fromRuntime<RuntimeModules extends RuntimeModulesRecord>(
runtimeModules: RuntimeModules
) {
const appChain = LocalhostAppChain.from({
runtime: Runtime.from(definition),

protocol: VanillaProtocol.from({}),

sequencer: Sequencer.from({
modules: {
Database: InMemoryDatabase,
Mempool: PrivateMempool,
GraphqlServer,
LocalTaskWorkerModule,
BaseLayer: NoopBaseLayer,
BlockProducerModule,
UnprovenProducerModule,
BlockTrigger: ManualBlockTrigger,
TaskQueue: LocalTaskQueue,

Runtime: Runtime.from({
modules: VanillaRuntimeModules.with(runtimeModules),
}),
Protocol: Protocol.from({
modules: VanillaProtocolModules.with({}),
}),
Sequencer: Sequencer.from({
modules: InMemorySequencerModules.with({
GraphqlServer: GraphqlServer,
Graphql: GraphqlSequencerModule.from({
modules: {
MempoolResolver,
Expand All @@ -78,26 +65,32 @@ export class LocalhostAppChain<
MerkleWitnessResolver,
},
}),
},
}),
}),

modules: {
// TODO: remove in favour of a real tx sender for the SettlementModule
// temporary dependency to make the SettlementModule work
TransactionSender: InMemoryTransactionSender,
QueryTransportModule: StateServiceQueryModule,
NetworkStateTransportModule: BlockStorageNetworkStateModule,
},
});

appChain.configure({
...appChain.config,

appChain.configurePartial({
Protocol: {
BlockProver: {},
StateTransitionProver: {},
AccountState: {},
BlockHeight: {},
LastStateRoot: {},
TransactionFee: {
tokenId: 0n,
feeRecipient: PrivateKey.random().toPublicKey().toBase58(),
baseFee: 0n,
perWeightUnitFee: 0n,
methods: {},
},
},

Sequencer: {
Database: {},
UnprovenProducerModule: {},
Expand All @@ -123,8 +116,10 @@ export class LocalhostAppChain<
BaseLayer: {},
TaskQueue: {},
BlockTrigger: {},
SettlementModule: {
feepayer: PrivateKey.random(),
},
},

QueryTransportModule: {},
NetworkStateTransportModule: {},
});
Expand Down
97 changes: 3 additions & 94 deletions packages/cli/src/commands/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
state,
} from "@proto-kit/module";
import {
AccountStateModule,
AccountStateHook,
Option,
Protocol,
State,
StateMap,
VanillaProtocol,
} from "@proto-kit/protocol";
import { VanillaProtocolModules } from "@proto-kit/library";
import { Presets, log, TypedClass } from "@proto-kit/common";
import {
AsyncStateService,
Expand Down Expand Up @@ -54,98 +55,6 @@ import { Spinner } from "@inkjs/ui";

log.setLevel("ERROR");

export async function startServer({
runtime,
}: {
runtime: TypedClass<Runtime<RuntimeModulesRecord>>;
}) {
const appChain = AppChain.from({
runtime,

protocol: VanillaProtocol.from({}),

sequencer: Sequencer.from({
modules: {
Mempool: PrivateMempool,
GraphqlServer,
LocalTaskWorkerModule,
BaseLayer: NoopBaseLayer,
BlockProducerModule,
BlockTrigger: ManualBlockTrigger,
TaskQueue: LocalTaskQueue,

Graphql: GraphqlSequencerModule.from({
modules: {
MempoolResolver,
QueryGraphqlModule,
BlockStorageResolver,
NodeStatusResolver,
},

config: {
MempoolResolver: {},
QueryGraphqlModule: {},
BlockStorageResolver: {},
NodeStatusResolver: {},
},
}),
},
}),

modules: {
Signer: InMemorySigner,
TransactionSender: InMemoryTransactionSender,
QueryTransportModule: StateServiceQueryModule,
},
});

appChain.configure({
Runtime: {
Balances: {},
},

Protocol: {
BlockProver: {},
StateTransitionProver: {},
AccountState: {},
},

Sequencer: {
GraphqlServer: {
port: 8080,
host: "0.0.0.0",
graphiql: true,
},

Graphql: {
QueryGraphqlModule: {},
MempoolResolver: {},
BlockStorageResolver: {},
NodeStatusResolver: {},
},

Mempool: {},
BlockProducerModule: {},
LocalTaskWorkerModule: {},
BaseLayer: {},
TaskQueue: {},

BlockTrigger: {},
},

TransactionSender: {},
QueryTransportModule: {},

Signer: {
signer: PrivateKey.random(),
},
});

await appChain.start();

return appChain;
}

let appChain: AppChain<any, any, any, any>;

export interface UnprovenBlockExtras {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/test/chain.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export class Balances extends RuntimeModule<object> {
}

const appChain = LocalhostAppChain.fromRuntime({
modules: {
Balances,
},
Balances,
});

appChain.configurePartial({
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/config/ConfigurableModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Configurable<Config> {
config: Config;
}

export type NoConfig = Record<string, never>;
export type NoConfig = Record<never, never>;

/**
* Used by various module sub-types that may need to be configured
Expand Down
16 changes: 8 additions & 8 deletions packages/common/src/config/ModuleContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,21 @@ export class ModuleContainer<
this.config = config;
}

public configurePartial(
config: RecursivePartial<ModulesConfig<Modules>>
) {
public configurePartial(config: RecursivePartial<ModulesConfig<Modules>>) {
this.config = merge<
(ModulesConfig<Modules>) | NoConfig,
ModulesConfig<Modules> | NoConfig,
RecursivePartial<ModulesConfig<Modules>>
>(this.currentConfig ?? {}, config);
}

public get config() {
return super.config;
}

// eslint-disable-next-line accessor-pairs
public set config(config: ModulesConfig<Modules>) {
super.config = merge<
(ModulesConfig<Modules>) | NoConfig,
ModulesConfig<Modules> | NoConfig,
ModulesConfig<Modules>
>(this.currentConfig ?? {}, config);
}
Expand Down Expand Up @@ -346,9 +348,7 @@ export class ModuleContainer<
moduleName: StringKeyOf<Modules>,
containedModule: InstanceType<Modules[StringKeyOf<Modules>]>
) {
// Has to be super.config, getters behave really weird when subtyping
const config = super.config?.[moduleName];

const config = this.config?.[moduleName];
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!config) {
throw errors.configNotSetInContainer(moduleName.toString());
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/zkProgrammable/ZkProgrammable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
...args: any
) => Promise<Proof<PublicInput, PublicOutput>>)
>;
analyzeMethods: ReturnType<typeof Experimental.ZkProgram>["analyzeMethods"];
}

export function verifyToMockable<PublicInput, PublicOutput>(
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/zkProgrammable/provableMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { ProvableMethodExecutionContext } from "./ProvableMethodExecutionContext
import type { WithZkProgrammable, ZkProgrammable } from "./ZkProgrammable";
import { ToFieldable } from "../utils";

export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> & ToFieldable;
export type O1JSPrimitive = InferProvable<ProvableExtended<unknown>> &
ToFieldable;
export type ArgumentTypes = (O1JSPrimitive | Proof<unknown, unknown>)[];

// eslint-disable-next-line etc/prefer-interface
Expand Down
5 changes: 4 additions & 1 deletion packages/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
"access": "public"
},
"dependencies": {
"@proto-kit/protocol": "*",
"bigint-isqrt": "^0.3.2",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"reflect-metadata": "^0.1.13"
},
"peerDependencies": {
"@proto-kit/protocol": "*",
"@proto-kit/module": "*",
"@proto-kit/common": "*",
"@proto-kit/sequencer": "*",
"o1js": "0.13.1",
"tsyringe": "^4.7.0"
},
Expand Down
Loading

0 comments on commit 068457a

Please sign in to comment.