-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrailgun-smart-wallet-utils.ts
More file actions
125 lines (101 loc) · 4.29 KB
/
railgun-smart-wallet-utils.ts
File metadata and controls
125 lines (101 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts";
import { newMockEvent } from "matchstick-as";
import { Shield, Transact, Unshield } from "../generated/RailgunSmartWallet/RailgunSmartWallet";
export function createShieldEvent(
treeNumber: BigInt,
startPosition: BigInt,
fees: BigInt[],
commitments: ethereum.Tuple[],
ciphertexts: ethereum.Tuple[],
): Shield {
const event = changetype<Shield>(newMockEvent());
event.parameters = [];
event.parameters.push(new ethereum.EventParam("treeNumber", ethereum.Value.fromUnsignedBigInt(treeNumber)));
event.parameters.push(new ethereum.EventParam("startPosition", ethereum.Value.fromUnsignedBigInt(startPosition)));
event.parameters.push(new ethereum.EventParam("commitments", ethereum.Value.fromTupleArray(commitments)));
event.parameters.push(new ethereum.EventParam("shieldCiphertext", ethereum.Value.fromTupleArray(ciphertexts)));
const feesArray = new Array<ethereum.Value>();
for (let index = 0; index < fees.length; index += 1) {
feesArray.push(ethereum.Value.fromUnsignedBigInt(fees[index]));
}
event.parameters.push(new ethereum.EventParam("fees", ethereum.Value.fromArray(feesArray)));
return event;
}
export function createCommitmentTuple(
npk: Bytes,
tokenType: i32,
tokenAddress: Address,
tokenSubID: BigInt,
value: BigInt,
): ethereum.Tuple {
const tokenTuple = new ethereum.Tuple();
tokenTuple.push(ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(tokenType)));
tokenTuple.push(ethereum.Value.fromAddress(tokenAddress));
tokenTuple.push(ethereum.Value.fromUnsignedBigInt(tokenSubID));
const commitment = new ethereum.Tuple();
commitment.push(ethereum.Value.fromBytes(npk));
commitment.push(ethereum.Value.fromTuple(tokenTuple));
commitment.push(ethereum.Value.fromUnsignedBigInt(value));
return commitment;
}
export function createShieldCiphertextTuple(
bundle0: Bytes,
bundle1: Bytes,
bundle2: Bytes,
shieldKey: Bytes,
): ethereum.Tuple {
const ciphertext = new ethereum.Tuple();
const bundle: Bytes[] = [bundle0, bundle1, bundle2];
ciphertext.push(ethereum.Value.fromBytesArray(bundle));
ciphertext.push(ethereum.Value.fromBytes(shieldKey));
return ciphertext;
}
export function createUnshieldEvent(
to: Address,
tokenType: i32,
tokenAddress: Address,
tokenSubID: BigInt,
amount: BigInt,
fee: BigInt,
): Unshield {
const event = changetype<Unshield>(newMockEvent());
event.parameters = [];
const tokenTuple = new ethereum.Tuple();
tokenTuple.push(ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(tokenType)));
tokenTuple.push(ethereum.Value.fromAddress(tokenAddress));
tokenTuple.push(ethereum.Value.fromUnsignedBigInt(tokenSubID));
event.parameters.push(new ethereum.EventParam("to", ethereum.Value.fromAddress(to)));
event.parameters.push(new ethereum.EventParam("token", ethereum.Value.fromTuple(tokenTuple)));
event.parameters.push(new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount)));
event.parameters.push(new ethereum.EventParam("fee", ethereum.Value.fromUnsignedBigInt(fee)));
return event;
}
export function createTransactCiphertextTuple(
ciphertext: Bytes[],
blindedSenderViewingKey: Bytes,
blindedReceiverViewingKey: Bytes,
annotationData: Bytes,
memo: Bytes,
): ethereum.Tuple {
const tuple = new ethereum.Tuple();
tuple.push(ethereum.Value.fromFixedBytesArray(ciphertext));
tuple.push(ethereum.Value.fromFixedBytes(blindedSenderViewingKey));
tuple.push(ethereum.Value.fromFixedBytes(blindedReceiverViewingKey));
tuple.push(ethereum.Value.fromBytes(annotationData));
tuple.push(ethereum.Value.fromBytes(memo));
return tuple;
}
export function createTransactEvent(
treeNumber: BigInt,
startPosition: BigInt,
hashes: Bytes[],
ciphertexts: ethereum.Tuple[],
): Transact {
const event = changetype<Transact>(newMockEvent());
event.parameters = [];
event.parameters.push(new ethereum.EventParam("treeNumber", ethereum.Value.fromUnsignedBigInt(treeNumber)));
event.parameters.push(new ethereum.EventParam("startPosition", ethereum.Value.fromUnsignedBigInt(startPosition)));
event.parameters.push(new ethereum.EventParam("hash", ethereum.Value.fromFixedBytesArray(hashes)));
event.parameters.push(new ethereum.EventParam("ciphertext", ethereum.Value.fromTupleArray(ciphertexts)));
return event;
}