@proto-kit/protocol 0.1.1-develop.600 → 0.1.1-develop.651
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blockmodules/NoopSettlementHook.d.ts.map +1 -1
- package/dist/blockmodules/NoopSettlementHook.js +1 -1
- package/dist/hooks/AccountStateHook.d.ts.map +1 -1
- package/dist/hooks/AccountStateHook.js +10 -3
- package/dist/hooks/BlockHeightHook.d.ts +3 -3
- package/dist/hooks/BlockHeightHook.d.ts.map +1 -1
- package/dist/hooks/BlockHeightHook.js +5 -4
- package/dist/hooks/LastStateRootBlockHook.d.ts +8 -0
- package/dist/hooks/LastStateRootBlockHook.d.ts.map +1 -0
- package/dist/hooks/LastStateRootBlockHook.js +15 -0
- package/dist/hooks/NoopBlockHook.d.ts +6 -4
- package/dist/hooks/NoopBlockHook.d.ts.map +1 -1
- package/dist/hooks/NoopBlockHook.js +4 -4
- package/dist/hooks/NoopSettlementHook.d.ts +6 -0
- package/dist/hooks/NoopSettlementHook.d.ts.map +1 -0
- package/dist/hooks/NoopSettlementHook.js +18 -0
- package/dist/index.d.ts +18 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -6
- package/dist/model/Option.d.ts +3 -2
- package/dist/model/Option.d.ts.map +1 -1
- package/dist/model/Option.js +5 -0
- package/dist/model/RuntimeLike.d.ts +11 -0
- package/dist/model/RuntimeLike.d.ts.map +1 -0
- package/dist/model/RuntimeLike.js +1 -0
- package/dist/model/StateTransition.d.ts +6 -5
- package/dist/model/StateTransition.d.ts.map +1 -1
- package/dist/model/StateTransition.js +3 -0
- package/dist/model/StateTransitionReduction.d.ts +3 -0
- package/dist/model/StateTransitionReduction.d.ts.map +1 -0
- package/dist/model/StateTransitionReduction.js +26 -0
- package/dist/protocol/Protocol.d.ts +11 -18
- package/dist/protocol/Protocol.d.ts.map +1 -1
- package/dist/protocol/Protocol.js +4 -27
- package/dist/protocol/ProtocolModule.d.ts.map +1 -1
- package/dist/protocol/ProtocolModule.js +1 -1
- package/dist/prover/block/BlockProver.d.ts.map +1 -1
- package/dist/prover/block/BlockProver.js +8 -6
- package/dist/prover/block/accummulators/BlockHashMerkleTree.js +1 -1
- package/dist/prover/statetransition/StateTransitionProver.d.ts +3 -2
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +1 -1
- package/dist/prover/statetransition/StateTransitionProver.js +1 -0
- package/dist/settlement/ContractModule.d.ts +15 -0
- package/dist/settlement/ContractModule.d.ts.map +1 -0
- package/dist/settlement/ContractModule.js +11 -0
- package/dist/settlement/SettlementContractModule.d.ts +39 -0
- package/dist/settlement/SettlementContractModule.d.ts.map +1 -0
- package/dist/settlement/SettlementContractModule.js +68 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts +12 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchContractProtocolModule.js +36 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts +22 -0
- package/dist/settlement/contracts/DispatchSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/DispatchSmartContract.js +110 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts +19 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementContractProtocolModule.js +44 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts +41 -0
- package/dist/settlement/contracts/SettlementSmartContract.d.ts.map +1 -0
- package/dist/settlement/contracts/SettlementSmartContract.js +235 -0
- package/dist/settlement/messages/Deposit.d.ts +39 -0
- package/dist/settlement/messages/Deposit.d.ts.map +1 -0
- package/dist/settlement/messages/Deposit.js +6 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts +109 -0
- package/dist/settlement/messages/OutgoingMessageArgument.d.ts.map +1 -0
- package/dist/settlement/messages/OutgoingMessageArgument.js +32 -0
- package/dist/settlement/messages/Withdrawal.d.ts +40 -0
- package/dist/settlement/messages/Withdrawal.d.ts.map +1 -0
- package/dist/settlement/messages/Withdrawal.js +13 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts +24 -0
- package/dist/settlement/modularity/ProvableSettlementHook.d.ts.map +1 -0
- package/dist/settlement/modularity/ProvableSettlementHook.js +3 -0
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts +3 -3
- package/dist/settlement/modules/NetworkStateSettlementModule.d.ts.map +1 -1
- package/dist/settlement/modules/NetworkStateSettlementModule.js +1 -1
- package/dist/state/State.d.ts.map +1 -1
- package/dist/state/State.js +2 -1
- package/dist/state/assert/assert.d.ts.map +1 -1
- package/dist/state/assert/assert.js +8 -5
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.d.ts.map +1 -1
- package/dist/state/context/RuntimeMethodExecutionContext.js +2 -1
- package/dist/utils/MinaPrefixedProvableHashList.d.ts +2 -2
- package/dist/utils/MinaPrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/PrefixedProvableHashList.d.ts +2 -2
- package/dist/utils/PrefixedProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableHashList.d.ts +3 -3
- package/dist/utils/ProvableHashList.d.ts.map +1 -1
- package/dist/utils/ProvableReductionHashList.d.ts +14 -0
- package/dist/utils/ProvableReductionHashList.d.ts.map +1 -0
- package/dist/utils/ProvableReductionHashList.js +50 -0
- package/dist/utils/StateTransitionReductionList.d.ts +11 -0
- package/dist/utils/StateTransitionReductionList.d.ts.map +1 -0
- package/dist/utils/StateTransitionReductionList.js +60 -0
- package/package.json +2 -2
- package/src/{blockmodules/AccountStateModule.ts → hooks/AccountStateHook.ts} +3 -1
- package/src/{blockmodules → hooks}/NoopSettlementHook.ts +1 -2
- package/src/index.ts +18 -6
- package/src/model/Option.ts +16 -0
- package/src/model/RuntimeLike.ts +12 -0
- package/src/model/StateTransition.ts +10 -2
- package/src/protocol/Protocol.ts +19 -44
- package/src/protocol/ProtocolModule.ts +3 -2
- package/src/prover/block/BlockProver.ts +20 -8
- package/src/prover/block/accummulators/BlockHashMerkleTree.ts +1 -1
- package/src/prover/statetransition/StateTransitionProver.ts +4 -2
- package/src/settlement/ContractModule.ts +24 -0
- package/src/settlement/SettlementContractModule.ts +127 -0
- package/src/settlement/contracts/DispatchContractProtocolModule.ts +39 -0
- package/src/settlement/contracts/DispatchSmartContract.ts +135 -0
- package/src/settlement/contracts/SettlementContractProtocolModule.ts +65 -0
- package/src/settlement/{SettlementContract.ts → contracts/SettlementSmartContract.ts} +87 -202
- package/src/settlement/messages/Deposit.ts +6 -0
- package/src/settlement/messages/OutgoingMessageArgument.ts +41 -0
- package/src/settlement/messages/Withdrawal.ts +14 -0
- package/src/settlement/{ProvableSettlementHook.ts → modularity/ProvableSettlementHook.ts} +7 -10
- package/src/settlement/modules/NetworkStateSettlementModule.ts +3 -3
- package/src/state/State.ts +2 -1
- package/src/state/assert/assert.ts +8 -6
- package/src/state/context/RuntimeMethodExecutionContext.ts +8 -5
- package/src/utils/MinaPrefixedProvableHashList.ts +2 -2
- package/src/utils/PrefixedProvableHashList.ts +2 -2
- package/src/utils/ProvableHashList.ts +3 -3
- package/src/utils/ProvableReductionHashList.ts +68 -0
- package/src/utils/StateTransitionReductionList.ts +88 -0
- package/test/BlockProver.test.ts +2 -2
- package/test/Protocol.test.ts +15 -10
- package/test/settlement/SettlementContract.test.ts +45 -0
- package/test/utils/ProvableReductionHashList.test.ts +114 -0
- /package/src/{blockmodules → hooks}/BlockHeightHook.ts +0 -0
- /package/src/{blockmodules → hooks}/LastStateRootBlockHook.ts +0 -0
- /package/src/{blockmodules → hooks}/NoopBlockHook.ts +0 -0
- /package/src/{blockmodules → hooks}/NoopTransactionHook.ts +0 -0
- /package/src/{blockmodules → hooks}/SequenceStateTransactionModule.ts +0 -0
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
/* eslint-disable max-lines */
|
|
14
|
-
import { Bool, Experimental, Field, Poseidon, Provable, SelfProof } from "o1js";
|
|
14
|
+
import { Bool, Experimental, Field, Poseidon, Provable, SelfProof, } from "o1js";
|
|
15
15
|
import { container, inject, injectable, injectAll } from "tsyringe";
|
|
16
16
|
import { provableMethod, ZkProgrammable, } from "@proto-kit/common";
|
|
17
17
|
import { DefaultProvableHashList } from "../../utils/ProvableHashList";
|
|
@@ -21,7 +21,8 @@ import { ProvableStateTransition, } from "../../model/StateTransition";
|
|
|
21
21
|
import { RuntimeMethodExecutionContext } from "../../state/context/RuntimeMethodExecutionContext";
|
|
22
22
|
import { NetworkState } from "../../model/network/NetworkState";
|
|
23
23
|
import { SignedTransaction } from "../../model/transaction/SignedTransaction";
|
|
24
|
-
import { MinaActions, MinaActionsHashList } from "../../utils/MinaPrefixedProvableHashList";
|
|
24
|
+
import { MinaActions, MinaActionsHashList, } from "../../utils/MinaPrefixedProvableHashList";
|
|
25
|
+
import { StateTransitionReductionList } from "../../utils/StateTransitionReductionList";
|
|
25
26
|
import { BlockProverExecutionData, BlockProverPublicInput, BlockProverPublicOutput, } from "./BlockProvable";
|
|
26
27
|
import { BlockHashMerkleTreeWitness, BlockHashTreeEntry, } from "./accummulators/BlockHashMerkleTree";
|
|
27
28
|
const errors = {
|
|
@@ -116,7 +117,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
116
117
|
const { stateTransitions, status, statusMessage } = executionContext.current().result;
|
|
117
118
|
status.assertTrue(statusMessage);
|
|
118
119
|
const transitions = stateTransitions.map((transition) => transition.toProvable());
|
|
119
|
-
const hashList = new
|
|
120
|
+
const hashList = new StateTransitionReductionList(ProvableStateTransition, stateTransitionProof.publicInput.protocolTransitionsHash);
|
|
120
121
|
transitions.forEach((transition) => {
|
|
121
122
|
hashList.push(transition);
|
|
122
123
|
});
|
|
@@ -221,7 +222,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
221
222
|
transactionProof.verifyIf(verifyTransactionProof);
|
|
222
223
|
// 2. Execute beforeBlock hooks
|
|
223
224
|
const beforeBlockResult = this.executeBlockHooks(state, networkState, "beforeBlock");
|
|
224
|
-
const beforeBlockHashList = new
|
|
225
|
+
const beforeBlockHashList = new StateTransitionReductionList(ProvableStateTransition);
|
|
225
226
|
beforeBlockResult.stateTransitions.forEach((st) => {
|
|
226
227
|
beforeBlockHashList.push(st.toProvable());
|
|
227
228
|
});
|
|
@@ -246,14 +247,14 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
246
247
|
// 5. Execute afterBlock hooks
|
|
247
248
|
this.assertSTProofInput(stateTransitionProof, state.stateRoot);
|
|
248
249
|
const afterBlockResult = this.executeBlockHooks(state, beforeBlockResult.networkState, "afterBlock");
|
|
249
|
-
const afterBlockHashList = new
|
|
250
|
+
const afterBlockHashList = new StateTransitionReductionList(ProvableStateTransition);
|
|
250
251
|
afterBlockResult.stateTransitions.forEach((st) => {
|
|
251
252
|
afterBlockHashList.push(st.toProvable());
|
|
252
253
|
});
|
|
253
254
|
state.networkStateHash = afterBlockResult.networkState.hash();
|
|
254
255
|
// We are reusing runtime STs here as afterBlock STs
|
|
255
256
|
stateTransitionProof.publicInput.stateTransitionsHash.assertEquals(afterBlockHashList.commitment, "STProof from-ST-hash not matching generated ST-hash from afterBlock hooks");
|
|
256
|
-
state.stateRoot = stateTransitionProof.
|
|
257
|
+
state.stateRoot = Provable.if(stsEmitted, stateTransitionProof.publicOutput.stateRoot, state.stateRoot);
|
|
257
258
|
// 6. Close block
|
|
258
259
|
// Calculate the new block index
|
|
259
260
|
const blockIndex = blockWitness.calculateIndex();
|
|
@@ -385,6 +386,7 @@ export class BlockProverProgrammable extends ZkProgrammable {
|
|
|
385
386
|
return {
|
|
386
387
|
compile: program.compile.bind(program),
|
|
387
388
|
verify: program.verify.bind(program),
|
|
389
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
388
390
|
Proof: SelfProofClass,
|
|
389
391
|
methods,
|
|
390
392
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createMerkleTree } from "@proto-kit/common";
|
|
2
2
|
import { Bool, Field, Poseidon, Struct } from "o1js";
|
|
3
|
-
export class BlockHashMerkleTree extends createMerkleTree(
|
|
3
|
+
export class BlockHashMerkleTree extends createMerkleTree(40) {
|
|
4
4
|
}
|
|
5
5
|
export class BlockHashMerkleTreeWitness extends BlockHashMerkleTree.WITNESS {
|
|
6
6
|
}
|
|
@@ -6,6 +6,7 @@ import { ProvableStateTransitionType, StateTransitionProvableBatch } from "../..
|
|
|
6
6
|
import { ProtocolModule } from "../../protocol/ProtocolModule";
|
|
7
7
|
import { StateTransitionProvable, StateTransitionProverPublicInput, StateTransitionProof, StateTransitionProverPublicOutput } from "./StateTransitionProvable";
|
|
8
8
|
import { StateTransitionWitnessProviderReference } from "./StateTransitionWitnessProviderReference";
|
|
9
|
+
import { StateTransitionProverType } from "../../protocol/Protocol";
|
|
9
10
|
interface StateTransitionProverExecutionState {
|
|
10
11
|
stateRoot: Field;
|
|
11
12
|
protocolStateRoot: Field;
|
|
@@ -39,9 +40,9 @@ export declare class StateTransitionProverProgrammable extends ZkProgrammable<St
|
|
|
39
40
|
runBatch(publicInput: StateTransitionProverPublicInput, batch: StateTransitionProvableBatch): StateTransitionProverPublicOutput;
|
|
40
41
|
merge(publicInput: StateTransitionProverPublicInput, proof1: StateTransitionProof, proof2: StateTransitionProof): StateTransitionProverPublicOutput;
|
|
41
42
|
}
|
|
42
|
-
export declare class StateTransitionProver extends ProtocolModule implements StateTransitionProvable {
|
|
43
|
+
export declare class StateTransitionProver extends ProtocolModule implements StateTransitionProvable, StateTransitionProverType {
|
|
43
44
|
readonly witnessProviderReference: StateTransitionWitnessProviderReference;
|
|
44
|
-
|
|
45
|
+
zkProgrammable: StateTransitionProverProgrammable;
|
|
45
46
|
constructor(witnessProviderReference: StateTransitionWitnessProviderReference);
|
|
46
47
|
runBatch(publicInput: StateTransitionProverPublicInput, batch: StateTransitionProvableBatch): StateTransitionProverPublicOutput;
|
|
47
48
|
merge(publicInput: StateTransitionProverPublicInput, proof1: StateTransitionProof, proof2: StateTransitionProof): StateTransitionProverPublicOutput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAGd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,oBAAoB,EACpB,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"StateTransitionProver.d.ts","sourceRoot":"","sources":["../../../src/prover/statetransition/StateTransitionProver.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,EAAuB,MAAM,MAAM,CAAC;AAEtE,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAGd,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAG/D,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,oBAAoB,EACpB,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAepE,UAAU,mCAAmC;IAC3C,SAAS,EAAE,KAAK,CAAC;IACjB,iBAAiB,EAAE,KAAK,CAAC;IACzB,mBAAmB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;IAC/D,sBAAsB,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;CACnE;AAOD;;;GAGG;AACH,qBAAa,iCAAkC,SAAQ,cAAc,CACnE,gCAAgC,EAChC,iCAAiC,CAClC;IAGG,OAAO,CAAC,QAAQ,CAAC,qBAAqB;aACtB,wBAAwB,EAAE,uCAAuC;gBADhE,qBAAqB,EAAE,qBAAqB,EAC7C,wBAAwB,EAAE,uCAAuC;IAKnF,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAEM,gBAAgB,IAAI,cAAc,CACvC,gCAAgC,EAChC,iCAAiC,CAClC;IAsDD,OAAO,KAAK,eAAe,GAM1B;IAED;;;OAGG;IACI,gBAAgB,CACrB,SAAS,EAAE,KAAK,EAChB,iBAAiB,EAAE,KAAK,EACxB,6BAA6B,EAAE,KAAK,EACpC,gCAAgC,EAAE,KAAK,EACvC,eAAe,EAAE,4BAA4B,GAC5C,mCAAmC;IA6BtC;;;OAGG;IACI,eAAe,CACpB,KAAK,EAAE,mCAAmC,EAC1C,UAAU,EAAE,uBAAuB,EACnC,IAAI,EAAE,2BAA2B,EACjC,KAAK,SAAI;IAiDX;;OAEG;IAEI,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAkB7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAqErC;AAED,qBACa,qBACX,SAAQ,cACR,YAAW,uBAAuB,EAAE,yBAAyB;aAM3C,wBAAwB,EAAE,uCAAuC;IAJ5E,cAAc,EAAE,iCAAiC,CAAC;gBAIvC,wBAAwB,EAAE,uCAAuC;IAS5E,QAAQ,CACb,WAAW,EAAE,gCAAgC,EAC7C,KAAK,EAAE,4BAA4B,GAClC,iCAAiC;IAI7B,KAAK,CACV,WAAW,EAAE,gCAAgC,EAC7C,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,iCAAiC;CAGrC"}
|
|
@@ -72,6 +72,7 @@ export class StateTransitionProverProgrammable extends ZkProgrammable {
|
|
|
72
72
|
return {
|
|
73
73
|
compile: program.compile.bind(program),
|
|
74
74
|
verify: program.verify.bind(program),
|
|
75
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
75
76
|
Proof: SelfProofClass,
|
|
76
77
|
methods,
|
|
77
78
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigurableModule, NoConfig, TypedClass } from "@proto-kit/common";
|
|
2
|
+
import { SmartContract } from "o1js";
|
|
3
|
+
export type SmartContractClassFromInterface<Type> = typeof SmartContract & TypedClass<Type>;
|
|
4
|
+
/**
|
|
5
|
+
* This module type is used to define a contract module that can be used to
|
|
6
|
+
* construct and inject smart contract instances.
|
|
7
|
+
* It defines a method contractFactory, whose arguments can be configured via
|
|
8
|
+
* the Argument generic. It returns a smart contract class that is a subclass
|
|
9
|
+
* of SmartContract and implements a certain interface as specified by the
|
|
10
|
+
* ContractType generic.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class ContractModule<ContractType, Arguments = undefined, Config = NoConfig> extends ConfigurableModule<Config> {
|
|
13
|
+
abstract contractFactory(args: Arguments): SmartContractClassFromInterface<ContractType>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ContractModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContractModule.d.ts","sourceRoot":"","sources":["../../src/settlement/ContractModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAErC,MAAM,MAAM,+BAA+B,CAAC,IAAI,IAAI,OAAO,aAAa,GACtE,UAAU,CAAC,IAAI,CAAC,CAAC;AAEnB;;;;;;;GAOG;AACH,8BAAsB,cAAc,CAClC,YAAY,EAEZ,SAAS,GAAG,SAAS,EACrB,MAAM,GAAG,QAAQ,CACjB,SAAQ,kBAAkB,CAAC,MAAM,CAAC;aAClB,eAAe,CAC7B,IAAI,EAAE,SAAS,GACd,+BAA+B,CAAC,YAAY,CAAC;CACjD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigurableModule } from "@proto-kit/common";
|
|
2
|
+
/**
|
|
3
|
+
* This module type is used to define a contract module that can be used to
|
|
4
|
+
* construct and inject smart contract instances.
|
|
5
|
+
* It defines a method contractFactory, whose arguments can be configured via
|
|
6
|
+
* the Argument generic. It returns a smart contract class that is a subclass
|
|
7
|
+
* of SmartContract and implements a certain interface as specified by the
|
|
8
|
+
* ContractType generic.
|
|
9
|
+
*/
|
|
10
|
+
export class ContractModule extends ConfigurableModule {
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AreProofsEnabled, ChildContainerProvider, ModuleContainer, ModulesRecord, TypedClass } from "@proto-kit/common";
|
|
2
|
+
import { PublicKey, SmartContract } from "o1js";
|
|
3
|
+
import { ProtocolEnvironment } from "../protocol/ProtocolEnvironment";
|
|
4
|
+
import { ProtocolModule } from "../protocol/ProtocolModule";
|
|
5
|
+
import { ContractModule, SmartContractClassFromInterface } from "./ContractModule";
|
|
6
|
+
import { DispatchContractProtocolModule } from "./contracts/DispatchContractProtocolModule";
|
|
7
|
+
import { DispatchContractType } from "./contracts/DispatchSmartContract";
|
|
8
|
+
import { SettlementContractConfig, SettlementContractProtocolModule } from "./contracts/SettlementContractProtocolModule";
|
|
9
|
+
import { SettlementContractType } from "./contracts/SettlementSmartContract";
|
|
10
|
+
export type SettlementModulesRecord = ModulesRecord<TypedClass<ContractModule<unknown, unknown, unknown>>>;
|
|
11
|
+
export type MandatorySettlementModulesRecord = {
|
|
12
|
+
SettlementContract: TypedClass<ContractModule<SettlementContractType, SmartContractClassFromInterface<DispatchContractType>, SettlementContractConfig>>;
|
|
13
|
+
DispatchContract: TypedClass<ContractModule<DispatchContractType, unknown, unknown>>;
|
|
14
|
+
};
|
|
15
|
+
export declare class SettlementContractModule<SettlementModules extends SettlementModulesRecord & MandatorySettlementModulesRecord> extends ModuleContainer<SettlementModules> implements ProtocolModule<unknown> {
|
|
16
|
+
constructor(definition: {
|
|
17
|
+
modules: SettlementModules;
|
|
18
|
+
});
|
|
19
|
+
static from<SettlementModules extends SettlementModulesRecord & MandatorySettlementModulesRecord>(modules: SettlementModules): TypedClass<SettlementContractModule<SettlementModules>>;
|
|
20
|
+
static fromDefaults(): TypedClass<SettlementContractModule<{
|
|
21
|
+
SettlementContract: typeof SettlementContractProtocolModule;
|
|
22
|
+
DispatchContract: typeof DispatchContractProtocolModule;
|
|
23
|
+
}>>;
|
|
24
|
+
protocol?: ProtocolEnvironment;
|
|
25
|
+
get appChain(): AreProofsEnabled | undefined;
|
|
26
|
+
create(childContainerProvider: ChildContainerProvider): void;
|
|
27
|
+
getContractClasses(): {
|
|
28
|
+
settlement: SmartContractClassFromInterface<SettlementContractType>;
|
|
29
|
+
dispatch: SmartContractClassFromInterface<DispatchContractType>;
|
|
30
|
+
};
|
|
31
|
+
createContracts(addresses: {
|
|
32
|
+
settlement: PublicKey;
|
|
33
|
+
dispatch: PublicKey;
|
|
34
|
+
}): {
|
|
35
|
+
settlement: SettlementContractType & SmartContract;
|
|
36
|
+
dispatch: DispatchContractType & SmartContract;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=SettlementContractModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettlementContractModule.d.ts","sourceRoot":"","sources":["../../src/settlement/SettlementContractModule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EACL,cAAc,EACd,+BAA+B,EAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EACjC,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E,MAAM,MAAM,uBAAuB,GAAG,aAAa,CACjD,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CACtD,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,kBAAkB,EAAE,UAAU,CAC5B,cAAc,CACZ,sBAAsB,EACtB,+BAA+B,CAAC,oBAAoB,CAAC,EACrD,wBAAwB,CACzB,CACF,CAAC;IACF,gBAAgB,EAAE,UAAU,CAC1B,cAAc,CAAC,oBAAoB,EAAE,OAAO,EAAE,OAAO,CAAC,CACvD,CAAC;CACH,CAAC;AAEF,qBACa,wBAAwB,CACjC,iBAAiB,SAAS,uBAAuB,GAC/C,gCAAgC,CAEpC,SAAQ,eAAe,CAAC,iBAAiB,CACzC,YAAW,cAAc,CAAC,OAAO,CAAC;gBAEf,UAAU,EAAE;QAAE,OAAO,EAAE,iBAAiB,CAAA;KAAE;WAI/C,IAAI,CAChB,iBAAiB,SAAS,uBAAuB,GAC/C,gCAAgC,EAElC,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;WAQ5C,YAAY;;;;IAQnB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAEtC,IAAW,QAAQ,IAAI,gBAAgB,GAAG,SAAS,CAElD;IAGM,MAAM,CAAC,sBAAsB,EAAE,sBAAsB;IAMrD,kBAAkB,IAAI;QAC3B,UAAU,EAAE,+BAA+B,CAAC,sBAAsB,CAAC,CAAC;QACpE,QAAQ,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;KACjE;IAkBM,eAAe,CAAC,SAAS,EAAE;QAChC,UAAU,EAAE,SAAS,CAAC;QACtB,QAAQ,EAAE,SAAS,CAAC;KACrB,GAAG;QACF,UAAU,EAAE,sBAAsB,GAAG,aAAa,CAAC;QACnD,QAAQ,EAAE,oBAAoB,GAAG,aAAa,CAAC;KAChD;CAWF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var SettlementContractModule_1;
|
|
11
|
+
import { ModuleContainer } from "@proto-kit/common";
|
|
12
|
+
import { injectable } from "tsyringe";
|
|
13
|
+
import { DispatchContractProtocolModule } from "./contracts/DispatchContractProtocolModule";
|
|
14
|
+
import { SettlementContractProtocolModule, } from "./contracts/SettlementContractProtocolModule";
|
|
15
|
+
let SettlementContractModule = SettlementContractModule_1 = class SettlementContractModule extends ModuleContainer {
|
|
16
|
+
constructor(definition) {
|
|
17
|
+
super(definition);
|
|
18
|
+
}
|
|
19
|
+
static from(modules) {
|
|
20
|
+
return class ScopedSettlementContractModule extends SettlementContractModule_1 {
|
|
21
|
+
constructor() {
|
|
22
|
+
super({ modules });
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static fromDefaults() {
|
|
27
|
+
return SettlementContractModule_1.from({
|
|
28
|
+
SettlementContract: SettlementContractProtocolModule,
|
|
29
|
+
DispatchContract: DispatchContractProtocolModule,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
get appChain() {
|
|
33
|
+
return this.protocol?.getAreProofsEnabled();
|
|
34
|
+
}
|
|
35
|
+
// **
|
|
36
|
+
create(childContainerProvider) {
|
|
37
|
+
super.create(childContainerProvider);
|
|
38
|
+
}
|
|
39
|
+
// private assertIsKeyofModules
|
|
40
|
+
getContractClasses() {
|
|
41
|
+
const settlementContractKey = "SettlementContract";
|
|
42
|
+
const dispatchContractKey = "DispatchContract";
|
|
43
|
+
this.assertIsValidModuleName(settlementContractKey);
|
|
44
|
+
this.assertIsValidModuleName(dispatchContractKey);
|
|
45
|
+
const settlementModule = this.resolve(settlementContractKey);
|
|
46
|
+
const dispatchModule = this.resolve(dispatchContractKey);
|
|
47
|
+
const dispatch = dispatchModule.contractFactory(undefined);
|
|
48
|
+
const settlement = settlementModule.contractFactory(dispatch);
|
|
49
|
+
return {
|
|
50
|
+
settlement,
|
|
51
|
+
dispatch,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
createContracts(addresses) {
|
|
55
|
+
const { dispatch, settlement } = this.getContractClasses();
|
|
56
|
+
const dispatchInstance = new dispatch(addresses.dispatch);
|
|
57
|
+
const settlementInstance = new settlement(addresses.settlement);
|
|
58
|
+
return {
|
|
59
|
+
dispatch: dispatchInstance,
|
|
60
|
+
settlement: settlementInstance,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
SettlementContractModule = SettlementContractModule_1 = __decorate([
|
|
65
|
+
injectable(),
|
|
66
|
+
__metadata("design:paramtypes", [Object])
|
|
67
|
+
], SettlementContractModule);
|
|
68
|
+
export { SettlementContractModule };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RuntimeLike } from "../../model/RuntimeLike";
|
|
2
|
+
import { ContractModule, SmartContractClassFromInterface } from "../ContractModule";
|
|
3
|
+
import { DispatchContractType } from "./DispatchSmartContract";
|
|
4
|
+
export type DispatchContractConfig = {
|
|
5
|
+
incomingMessagesMethods: Record<string, `${string}.${string}`>;
|
|
6
|
+
};
|
|
7
|
+
export declare class DispatchContractProtocolModule extends ContractModule<DispatchContractType, undefined, DispatchContractConfig> {
|
|
8
|
+
private readonly runtime;
|
|
9
|
+
constructor(runtime: RuntimeLike);
|
|
10
|
+
contractFactory(): SmartContractClassFromInterface<DispatchContractType>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=DispatchContractProtocolModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DispatchContractProtocolModule.d.ts","sourceRoot":"","sources":["../../../src/settlement/contracts/DispatchContractProtocolModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,+BAA+B,EAChC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,sBAAsB,GAAG;IACnC,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;CAChE,CAAC;AAEF,qBACa,8BAA+B,SAAQ,cAAc,CAChE,oBAAoB,EACpB,SAAS,EACT,sBAAsB,CACvB;IACuC,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW;IAIpE,eAAe,IAAI,+BAA+B,CAAC,oBAAoB,CAAC;CAWhF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { inject, injectable } from "tsyringe";
|
|
14
|
+
import { ContractModule, } from "../ContractModule";
|
|
15
|
+
import { DispatchSmartContract, } from "./DispatchSmartContract";
|
|
16
|
+
let DispatchContractProtocolModule = class DispatchContractProtocolModule extends ContractModule {
|
|
17
|
+
constructor(runtime) {
|
|
18
|
+
super();
|
|
19
|
+
this.runtime = runtime;
|
|
20
|
+
}
|
|
21
|
+
contractFactory() {
|
|
22
|
+
const { incomingMessagesMethods } = this.config;
|
|
23
|
+
const methodIdMappings = this.runtime.methodIdResolver.methodIdMap();
|
|
24
|
+
DispatchSmartContract.args = {
|
|
25
|
+
incomingMessagesPaths: incomingMessagesMethods,
|
|
26
|
+
methodIdMappings,
|
|
27
|
+
};
|
|
28
|
+
return DispatchSmartContract;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
DispatchContractProtocolModule = __decorate([
|
|
32
|
+
injectable(),
|
|
33
|
+
__param(0, inject("Runtime")),
|
|
34
|
+
__metadata("design:paramtypes", [Object])
|
|
35
|
+
], DispatchContractProtocolModule);
|
|
36
|
+
export { DispatchContractProtocolModule };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Field, PublicKey, SmartContract, State, UInt64 } from "o1js";
|
|
2
|
+
import { RuntimeMethodIdMapping } from "../../model/RuntimeLike";
|
|
3
|
+
export declare const ACTIONS_EMPTY_HASH: import("o1js/dist/node/lib/field").Field;
|
|
4
|
+
export interface DispatchContractType {
|
|
5
|
+
updateMessagesHash: (executedMessagesHash: Field, newPromisedMessagesHash: Field) => void;
|
|
6
|
+
initialize: (settlementContract: PublicKey) => void;
|
|
7
|
+
promisedMessagesHash: State<Field>;
|
|
8
|
+
}
|
|
9
|
+
export declare class DispatchSmartContract extends SmartContract implements DispatchContractType {
|
|
10
|
+
static args: {
|
|
11
|
+
methodIdMappings: RuntimeMethodIdMapping;
|
|
12
|
+
incomingMessagesPaths: Record<string, `${string}.${string}`>;
|
|
13
|
+
};
|
|
14
|
+
promisedMessagesHash: State<import("o1js/dist/node/lib/field").Field>;
|
|
15
|
+
honoredMessagesHash: State<import("o1js/dist/node/lib/field").Field>;
|
|
16
|
+
settlementContract: State<PublicKey>;
|
|
17
|
+
updateMessagesHash(executedMessagesHash: Field, newPromisedMessagesHash: Field): void;
|
|
18
|
+
initialize(settlementContract: PublicKey): void;
|
|
19
|
+
private dispatchMessage;
|
|
20
|
+
deposit(amount: UInt64): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=DispatchSmartContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DispatchSmartContract.d.ts","sourceRoot":"","sources":["../../../src/settlement/contracts/DispatchSmartContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EAIL,SAAS,EAET,aAAa,EACb,KAAK,EAEL,MAAM,EACP,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAQjE,eAAO,MAAM,kBAAkB,0CAA6B,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,kBAAkB,EAAE,CAClB,oBAAoB,EAAE,KAAK,EAC3B,uBAAuB,EAAE,KAAK,KAC3B,IAAI,CAAC;IACV,UAAU,EAAE,CAAC,kBAAkB,EAAE,SAAS,KAAK,IAAI,CAAC;IAEpD,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;CACpC;AAED,qBAAa,qBACX,SAAQ,aACR,YAAW,oBAAoB;IAE/B,OAAc,IAAI,EAAE;QAClB,gBAAgB,EAAE,sBAAsB,CAAC;QACzC,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;KAC9D,CAAC;IAEmB,oBAAoB,kDAAkB;IAEtC,mBAAmB,kDAAkB;IAEjC,kBAAkB,mBAAsB;IAG1D,kBAAkB,CACvB,oBAAoB,EAAE,KAAK,EAC3B,uBAAuB,EAAE,KAAK;IAezB,UAAU,CAAC,kBAAkB,EAAE,SAAS;IAY/C,OAAO,CAAC,eAAe;IA8BhB,OAAO,CAAC,MAAM,EAAE,MAAM;CAyB9B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { AccountUpdate, Field, method, Poseidon, PublicKey, Reducer, SmartContract, State, state, UInt64, } from "o1js";
|
|
11
|
+
import { RuntimeTransaction } from "../../model/transaction/RuntimeTransaction";
|
|
12
|
+
import { MinaActions, MinaEvents, } from "../../utils/MinaPrefixedProvableHashList";
|
|
13
|
+
import { Deposit } from "../messages/Deposit";
|
|
14
|
+
export const ACTIONS_EMPTY_HASH = Reducer.initialActionState;
|
|
15
|
+
export class DispatchSmartContract extends SmartContract {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
this.promisedMessagesHash = State();
|
|
19
|
+
this.honoredMessagesHash = State();
|
|
20
|
+
this.settlementContract = State();
|
|
21
|
+
}
|
|
22
|
+
updateMessagesHash(executedMessagesHash, newPromisedMessagesHash) {
|
|
23
|
+
const promisedMessagesHash = this.promisedMessagesHash.getAndAssertEquals();
|
|
24
|
+
this.honoredMessagesHash.getAndAssertEquals();
|
|
25
|
+
executedMessagesHash.assertEquals(promisedMessagesHash);
|
|
26
|
+
this.honoredMessagesHash.set(executedMessagesHash);
|
|
27
|
+
// Assert and apply new promisedMessagesHash
|
|
28
|
+
this.self.account.actionState.assertEquals(newPromisedMessagesHash);
|
|
29
|
+
this.promisedMessagesHash.set(newPromisedMessagesHash);
|
|
30
|
+
}
|
|
31
|
+
initialize(settlementContract) {
|
|
32
|
+
this.promisedMessagesHash.getAndAssertEquals().assertEquals(Field(0));
|
|
33
|
+
this.honoredMessagesHash.getAndAssertEquals().assertEquals(Field(0));
|
|
34
|
+
this.settlementContract
|
|
35
|
+
.getAndAssertEquals()
|
|
36
|
+
.assertEquals(PublicKey.empty());
|
|
37
|
+
this.promisedMessagesHash.set(ACTIONS_EMPTY_HASH);
|
|
38
|
+
this.honoredMessagesHash.set(ACTIONS_EMPTY_HASH);
|
|
39
|
+
this.settlementContract.set(settlementContract);
|
|
40
|
+
}
|
|
41
|
+
dispatchMessage(methodId, value, valueType) {
|
|
42
|
+
const args = valueType.toFields(value);
|
|
43
|
+
// Should be the same as RuntimeTransaction.hash
|
|
44
|
+
const argsHash = Poseidon.hash(args);
|
|
45
|
+
const runtimeTransaction = RuntimeTransaction.fromMessage({
|
|
46
|
+
methodId,
|
|
47
|
+
argsHash,
|
|
48
|
+
});
|
|
49
|
+
// Append tx to incomingMessagesHash
|
|
50
|
+
const actionData = runtimeTransaction.hashData();
|
|
51
|
+
const actionHash = MinaActions.actionHash(actionData);
|
|
52
|
+
this.self.body.actions = {
|
|
53
|
+
hash: actionHash,
|
|
54
|
+
data: [actionData],
|
|
55
|
+
};
|
|
56
|
+
const eventHash = MinaEvents.eventHash(args);
|
|
57
|
+
this.self.body.events = {
|
|
58
|
+
hash: eventHash,
|
|
59
|
+
data: [args],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
deposit(amount) {
|
|
63
|
+
// Save this, since otherwise it would be a second witness later,
|
|
64
|
+
// which could be a different values than the first
|
|
65
|
+
const { sender } = this;
|
|
66
|
+
const settlementContract = this.settlementContract.getAndAssertEquals();
|
|
67
|
+
// Credit the amount to the settlement contract
|
|
68
|
+
const balanceAU = AccountUpdate.create(settlementContract);
|
|
69
|
+
balanceAU.balance.addInPlace(amount);
|
|
70
|
+
this.self.approve(balanceAU);
|
|
71
|
+
const action = new Deposit({
|
|
72
|
+
address: sender,
|
|
73
|
+
amount,
|
|
74
|
+
});
|
|
75
|
+
const { methodIdMappings, incomingMessagesPaths } = DispatchSmartContract.args;
|
|
76
|
+
const methodId = Field(methodIdMappings[incomingMessagesPaths.deposit].methodId).toConstant();
|
|
77
|
+
this.dispatchMessage(methodId.toConstant(), action, Deposit);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
__decorate([
|
|
81
|
+
state(Field),
|
|
82
|
+
__metadata("design:type", Object)
|
|
83
|
+
], DispatchSmartContract.prototype, "promisedMessagesHash", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
state(Field),
|
|
86
|
+
__metadata("design:type", Object)
|
|
87
|
+
], DispatchSmartContract.prototype, "honoredMessagesHash", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
state(PublicKey),
|
|
90
|
+
__metadata("design:type", Object)
|
|
91
|
+
], DispatchSmartContract.prototype, "settlementContract", void 0);
|
|
92
|
+
__decorate([
|
|
93
|
+
method,
|
|
94
|
+
__metadata("design:type", Function),
|
|
95
|
+
__metadata("design:paramtypes", [Field,
|
|
96
|
+
Field]),
|
|
97
|
+
__metadata("design:returntype", void 0)
|
|
98
|
+
], DispatchSmartContract.prototype, "updateMessagesHash", null);
|
|
99
|
+
__decorate([
|
|
100
|
+
method,
|
|
101
|
+
__metadata("design:type", Function),
|
|
102
|
+
__metadata("design:paramtypes", [PublicKey]),
|
|
103
|
+
__metadata("design:returntype", void 0)
|
|
104
|
+
], DispatchSmartContract.prototype, "initialize", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
method,
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", [UInt64]),
|
|
109
|
+
__metadata("design:returntype", void 0)
|
|
110
|
+
], DispatchSmartContract.prototype, "deposit", null);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TypedClass } from "@proto-kit/common";
|
|
2
|
+
import { SmartContract } from "o1js";
|
|
3
|
+
import { BlockProvable } from "../../prover/block/BlockProvable";
|
|
4
|
+
import { ContractModule, SmartContractClassFromInterface } from "../ContractModule";
|
|
5
|
+
import { ProvableSettlementHook } from "../modularity/ProvableSettlementHook";
|
|
6
|
+
import { DispatchContractType } from "./DispatchSmartContract";
|
|
7
|
+
import { SettlementContractType } from "./SettlementSmartContract";
|
|
8
|
+
export type SettlementContractConfig = {
|
|
9
|
+
escapeHatchSlotsInterval?: number;
|
|
10
|
+
withdrawalStatePath: `${string}.${string}`;
|
|
11
|
+
withdrawalMethodPath: `${string}.${string}`;
|
|
12
|
+
};
|
|
13
|
+
export declare class SettlementContractProtocolModule extends ContractModule<SettlementContractType, TypedClass<DispatchContractType & SmartContract>, SettlementContractConfig> {
|
|
14
|
+
private readonly hooks;
|
|
15
|
+
private readonly blockProver;
|
|
16
|
+
constructor(hooks: ProvableSettlementHook<unknown>[], blockProver: BlockProvable);
|
|
17
|
+
contractFactory(dispatchContract: TypedClass<DispatchContractType & SmartContract>): SmartContractClassFromInterface<SettlementContractType>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=SettlementContractProtocolModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettlementContractProtocolModule.d.ts","sourceRoot":"","sources":["../../../src/settlement/contracts/SettlementContractProtocolModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAGrC,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EACL,cAAc,EACd,+BAA+B,EAChC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAEL,sBAAsB,EAEvB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,MAAM,wBAAwB,GAAG;IACrC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,mBAAmB,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAC3C,oBAAoB,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;CAC7C,CAAC;AAKF,qBACa,gCAAiC,SAAQ,cAAc,CAClE,sBAAsB,EACtB,UAAU,CAAC,oBAAoB,GAAG,aAAa,CAAC,EAChD,wBAAwB,CACzB;IAGG,OAAO,CAAC,QAAQ,CAAC,KAAK;IAEtB,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAFX,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,EAExC,WAAW,EAAE,aAAa;IAMtC,eAAe,CACpB,gBAAgB,EAAE,UAAU,CAAC,oBAAoB,GAAG,aAAa,CAAC,GACjE,+BAA+B,CAAC,sBAAsB,CAAC;CAmB3D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { inject, injectable, injectAll } from "tsyringe";
|
|
14
|
+
import { ContractModule, } from "../ContractModule";
|
|
15
|
+
import { LazyBlockProof, SettlementSmartContract, } from "./SettlementSmartContract";
|
|
16
|
+
// 24 hours
|
|
17
|
+
const DEFAULT_ESCAPE_HATCH = (60 / 3) * 24;
|
|
18
|
+
let SettlementContractProtocolModule = class SettlementContractProtocolModule extends ContractModule {
|
|
19
|
+
constructor(hooks, blockProver) {
|
|
20
|
+
LazyBlockProof.tag = blockProver.zkProgrammable.zkProgram.Proof.tag;
|
|
21
|
+
super();
|
|
22
|
+
this.hooks = hooks;
|
|
23
|
+
this.blockProver = blockProver;
|
|
24
|
+
}
|
|
25
|
+
contractFactory(dispatchContract) {
|
|
26
|
+
const { hooks, config } = this;
|
|
27
|
+
const withdrawalStatePathSplit = this.config.withdrawalStatePath.split(".");
|
|
28
|
+
const escapeHatchSlotsInterval = this.config.escapeHatchSlotsInterval ?? DEFAULT_ESCAPE_HATCH;
|
|
29
|
+
SettlementSmartContract.args = {
|
|
30
|
+
DispatchContract: dispatchContract,
|
|
31
|
+
hooks,
|
|
32
|
+
withdrawalStatePath: withdrawalStatePathSplit,
|
|
33
|
+
escapeHatchSlotsInterval,
|
|
34
|
+
};
|
|
35
|
+
return SettlementSmartContract;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
SettlementContractProtocolModule = __decorate([
|
|
39
|
+
injectable(),
|
|
40
|
+
__param(0, injectAll("ProvableSettlementHook")),
|
|
41
|
+
__param(1, inject("BlockProver")),
|
|
42
|
+
__metadata("design:paramtypes", [Array, Object])
|
|
43
|
+
], SettlementContractProtocolModule);
|
|
44
|
+
export { SettlementContractProtocolModule };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TypedClass } from "@proto-kit/common";
|
|
2
|
+
import { AccountUpdate, Field, Proof, PublicKey, Signature, SmartContract, State, UInt32 } from "o1js";
|
|
3
|
+
import { NetworkState } from "../../model/network/NetworkState";
|
|
4
|
+
import { BlockProverPublicInput, BlockProverPublicOutput } from "../../prover/block/BlockProvable";
|
|
5
|
+
import { OutgoingMessageArgumentBatch } from "../messages/OutgoingMessageArgument";
|
|
6
|
+
import { ProvableSettlementHook } from "../modularity/ProvableSettlementHook";
|
|
7
|
+
import { DispatchContractType } from "./DispatchSmartContract";
|
|
8
|
+
export declare class LazyBlockProof extends Proof<BlockProverPublicInput, BlockProverPublicOutput> {
|
|
9
|
+
static publicInputType: typeof BlockProverPublicInput;
|
|
10
|
+
static publicOutputType: typeof BlockProverPublicOutput;
|
|
11
|
+
static tag: () => {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface SettlementContractType {
|
|
16
|
+
initialize: (sequencer: PublicKey, dispatchContract: PublicKey) => void;
|
|
17
|
+
settle: (blockProof: LazyBlockProof, signature: Signature, dispatchContractAddress: PublicKey, publicKey: PublicKey, inputNetworkState: NetworkState, outputNetworkState: NetworkState, newPromisedMessagesHash: Field) => void;
|
|
18
|
+
rollupOutgoingMessages: (batch: OutgoingMessageArgumentBatch) => void;
|
|
19
|
+
redeem: (additionUpdate: AccountUpdate) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const BATCH_SIGNATURE_PREFIX: import("o1js/dist/node/lib/field").Field;
|
|
22
|
+
export declare class SettlementSmartContract extends SmartContract implements SettlementContractType {
|
|
23
|
+
static args: {
|
|
24
|
+
DispatchContract: TypedClass<DispatchContractType & SmartContract>;
|
|
25
|
+
hooks: ProvableSettlementHook<unknown>[];
|
|
26
|
+
withdrawalStatePath: [string, string];
|
|
27
|
+
escapeHatchSlotsInterval: number;
|
|
28
|
+
};
|
|
29
|
+
sequencerKey: State<import("o1js/dist/node/lib/field").Field>;
|
|
30
|
+
lastSettlementL1Block: State<UInt32>;
|
|
31
|
+
stateRoot: State<import("o1js/dist/node/lib/field").Field>;
|
|
32
|
+
networkStateHash: State<import("o1js/dist/node/lib/field").Field>;
|
|
33
|
+
blockHashRoot: State<import("o1js/dist/node/lib/field").Field>;
|
|
34
|
+
dispatchContractAddressX: State<import("o1js/dist/node/lib/field").Field>;
|
|
35
|
+
outgoingMessageCursor: State<import("o1js/dist/node/lib/field").Field>;
|
|
36
|
+
initialize(sequencer: PublicKey, dispatchContract: PublicKey): void;
|
|
37
|
+
settle(blockProof: LazyBlockProof, signature: Signature, dispatchContractAddress: PublicKey, publicKey: PublicKey, inputNetworkState: NetworkState, outputNetworkState: NetworkState, newPromisedMessagesHash: Field): void;
|
|
38
|
+
rollupOutgoingMessages(batch: OutgoingMessageArgumentBatch): void;
|
|
39
|
+
redeem(additionUpdate: AccountUpdate): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=SettlementSmartContract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettlementSmartContract.d.ts","sourceRoot":"","sources":["../../../src/settlement/contracts/SettlementSmartContract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EACL,aAAa,EAEb,KAAK,EAIL,KAAK,EAEL,SAAS,EACT,SAAS,EACT,aAAa,EACb,KAAK,EAGL,MAAM,EAEP,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEL,4BAA4B,EAC7B,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,sBAAsB,EAGvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,qBAAa,cAAe,SAAQ,KAAK,CACvC,sBAAsB,EACtB,uBAAuB,CACxB;IACC,OAAc,eAAe,gCAA0B;IAEvD,OAAc,gBAAgB,iCAA2B;IAEzD,OAAc,GAAG,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAEvC;CACH;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,KAAK,IAAI,CAAC;IACxE,MAAM,EAAE,CACN,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,SAAS,EAClC,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,YAAY,EAC/B,kBAAkB,EAAE,YAAY,EAChC,uBAAuB,EAAE,KAAK,KAC3B,IAAI,CAAC;IACV,sBAAsB,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,IAAI,CAAC;IACtE,MAAM,EAAE,CAAC,cAAc,EAAE,aAAa,KAAK,IAAI,CAAC;CACjD;AAGD,eAAO,MAAM,sBAAsB,0CAAqC,CAAC;AAEzE,qBAAa,uBACX,SAAQ,aACR,YAAW,sBAAsB;IAIjC,OAAc,IAAI,EAAE;QAClB,gBAAgB,EAAE,UAAU,CAAC,oBAAoB,GAAG,aAAa,CAAC,CAAC;QACnE,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtC,wBAAwB,EAAE,MAAM,CAAC;KAClC,CAAC;IAEmB,YAAY,kDAAkB;IAC7B,qBAAqB,gBAAmB;IAEzC,SAAS,kDAAkB;IAC3B,gBAAgB,kDAAkB;IAClC,aAAa,kDAAkB;IAE/B,wBAAwB,kDAAkB;IAE1C,qBAAqB,kDAAkB;IAGrD,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS;IAkB5D,MAAM,CACX,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,SAAS,EACpB,uBAAuB,EAAE,SAAS,EAClC,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,YAAY,EAC/B,kBAAkB,EAAE,YAAY,EAChC,uBAAuB,EAAE,KAAK;IAwIzB,sBAAsB,CAAC,KAAK,EAAE,4BAA4B;IAoD1D,MAAM,CAAC,cAAc,EAAE,aAAa;CAoB5C"}
|