Skip to content

Commit

Permalink
Add actionState to the wrapping request
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinOndejka committed Aug 10, 2023
1 parent f455f49 commit fd2f903
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/ZekoBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ describe('ZekoBridge', () => {
requests.push(
new WrappingRequest({
id: counter,
actionState:
requests.at(-1)?.getNextActionState() ?? Reducer.initialActionState,
...action,
})
);
Expand Down Expand Up @@ -328,6 +330,8 @@ describe('ZekoBridge', () => {
requests.push(
new WrappingRequest({
id: counter,
actionState:
requests.at(-1)?.getNextActionState() ?? Reducer.initialActionState,
...action,
})
);
Expand Down Expand Up @@ -428,6 +432,8 @@ describe('ZekoBridge', () => {
requests.push(
new WrappingRequest({
id: counter,
actionState:
requests.at(-1)?.getNextActionState() ?? Reducer.initialActionState,
...action,
})
);
Expand Down
19 changes: 17 additions & 2 deletions src/ZekoBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const TREE_CAPACITY = new MerkleTree(TREE_HEIGHT).leafCount;

export class WrappingRequest extends Struct({
id: Field,
actionState: Field,
amount: UInt64,
tokenId: Field,
receiver: PublicKey,
Expand All @@ -39,6 +40,18 @@ export class WrappingRequest extends Struct({
return this.id.toBigInt() % TREE_CAPACITY;
}

toAction() {
return new WrappingRequestAction({
amount: this.amount,
tokenId: this.tokenId,
receiver: this.receiver,
});
}

getNextActionState() {
return updateActionsState(this.actionState, this.toAction().hash());
}

static buildMerkleTree(requests: WrappingRequest[]): MerkleTree {
const tree = new MerkleTree(TREE_HEIGHT);

Expand Down Expand Up @@ -85,6 +98,7 @@ export class WrappingRequestAction extends Struct({
const witnesses = actions.map((action) => {
const request = new WrappingRequest({
id: currentState.counter,
actionState: currentState.actionState,
amount: action.amount,
tokenId: action.tokenId,
receiver: action.receiver,
Expand Down Expand Up @@ -145,7 +159,7 @@ export class WrappingRequestAction extends Struct({

proof =
proof === undefined
? await ActionsRecursiveReducer.first(publicInput, witnessesBatch)
? await ActionsRecursiveReducer.init(publicInput, witnessesBatch)
: await ActionsRecursiveReducer.step(
publicInput,
proof,
Expand Down Expand Up @@ -205,6 +219,7 @@ export class ActionsBatch extends Struct({
);
const request = new WrappingRequest({
id: stateAux.counter,
actionState: stateAux.actionState,
amount: action.amount,
tokenId: action.tokenId,
receiver: action.receiver,
Expand Down Expand Up @@ -265,7 +280,7 @@ export const ActionsRecursiveReducer = Experimental.ZkProgram({
publicInput: ReducerPublicInput,

methods: {
first: {
init: {
privateInputs: [ActionsBatch],

method(publicInput: ReducerPublicInput, batch: ActionsBatch) {
Expand Down

0 comments on commit fd2f903

Please sign in to comment.