@theoo/sdk 0.4.3 → 0.4.4

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.
@@ -0,0 +1,92 @@
1
+ import type { VaultCall } from "./types.js";
2
+ /** `TheooVaultFactory`, at one address on every chain that has it. */
3
+ export declare const VAULT_FACTORY = "0xf9D5b7cB6081Ac75EBdd3A8763deF6981F2f78E4";
4
+ export declare const VAULT_LIMITS: {
5
+ readonly owners: 20;
6
+ readonly calls: 16;
7
+ readonly callData: 16384;
8
+ readonly delay: number;
9
+ };
10
+ export declare const VAULT_SEL: {
11
+ readonly create: string;
12
+ readonly propose: string;
13
+ readonly approve: string;
14
+ readonly revoke: string;
15
+ readonly reject: string;
16
+ readonly cancel: string;
17
+ readonly execute: string;
18
+ readonly addOwner: string;
19
+ readonly removeOwner: string;
20
+ readonly replaceOwner: string;
21
+ readonly setThreshold: string;
22
+ readonly setDelay: string;
23
+ readonly signMessage: string;
24
+ readonly erc20Transfer: string;
25
+ };
26
+ /** `abi.encode(calls)`, as the vault encodes them. */
27
+ export declare function encodeCalls(calls: VaultCall[]): Uint8Array;
28
+ /** What an approval of these calls must name. */
29
+ export declare function callsHash(calls: VaultCall[]): string;
30
+ /** Calldata for `propose(calls)`. */
31
+ export declare function proposeData(calls: VaultCall[]): string;
32
+ /** The calls inside `propose(calls)` calldata. Throws if it isn't one. */
33
+ export declare function decodePropose(calldata: string): VaultCall[];
34
+ /**
35
+ * Where a vault with these settings is, on every chain with the factory.
36
+ * The address commits to all of them, so it can be shared — and funded —
37
+ * before the vault is created anywhere.
38
+ */
39
+ export declare function predictVault(owners: string[], threshold: number, delay: number, salt: string): string;
40
+ /** 32 random bytes, for a new vault. */
41
+ export declare function newSalt(): string;
42
+ /** A call, said plainly: what an owner is being asked to approve. */
43
+ export type DescribedCall = {
44
+ kind: "send";
45
+ to: string;
46
+ value: bigint;
47
+ } | {
48
+ kind: "token";
49
+ token: string;
50
+ to: string;
51
+ amount: bigint;
52
+ } | {
53
+ kind: "add_owner";
54
+ owner: string;
55
+ threshold: number;
56
+ } | {
57
+ kind: "remove_owner";
58
+ owner: string;
59
+ threshold: number;
60
+ } | {
61
+ kind: "replace_owner";
62
+ owner: string;
63
+ with: string;
64
+ } | {
65
+ kind: "threshold";
66
+ threshold: number;
67
+ } | {
68
+ kind: "delay";
69
+ seconds: number;
70
+ } | {
71
+ kind: "sign_message";
72
+ hash: string;
73
+ signed: boolean;
74
+ } | {
75
+ kind: "call";
76
+ to: string;
77
+ value: bigint;
78
+ selector: string;
79
+ };
80
+ /** Turn one of a proposal's calls into what it does, for `vault` itself. */
81
+ export declare function describeCall(vault: string, c: VaultCall): DescribedCall;
82
+ /** Calls for the common proposals. */
83
+ export declare const vaultCalls: {
84
+ send: (to: string, wei: bigint | string) => VaultCall[];
85
+ sendToken: (token: string, to: string, amount: bigint | string) => VaultCall[];
86
+ addOwner: (vault: string, owner: string, threshold: number) => VaultCall[];
87
+ removeOwner: (vault: string, owner: string, threshold: number) => VaultCall[];
88
+ replaceOwner: (vault: string, owner: string, next: string) => VaultCall[];
89
+ setThreshold: (vault: string, threshold: number) => VaultCall[];
90
+ setDelay: (vault: string, seconds: number) => VaultCall[];
91
+ };
92
+ //# sourceMappingURL=vault.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,sEAAsE;AACtE,eAAO,MAAM,aAAa,+CAA+C,CAAC;AAE1E,eAAO,MAAM,YAAY;;;;;CAAiF,CAAC;AAE3G,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;CAeZ,CAAC;AA0BX,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,UAAU,CAE1D;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,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GACvD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,GAAG,aAAa,CA8BvE;AAED,sCAAsC;AACtC,eAAO,MAAM,UAAU;eACV,MAAM,OAAO,MAAM,GAAG,MAAM,KAAG,SAAS,EAAE;uBAClC,MAAM,MAAM,MAAM,UAAU,MAAM,GAAG,MAAM,KAAG,SAAS,EAAE;sBAO1D,MAAM,SAAS,MAAM,aAAa,MAAM,KAAG,SAAS,EAAE;yBAGnD,MAAM,SAAS,MAAM,aAAa,MAAM,KAAG,SAAS,EAAE;0BAGrD,MAAM,SAAS,MAAM,QAAQ,MAAM,KAAG,SAAS,EAAE;0BAGjD,MAAM,aAAa,MAAM,KAAG,SAAS,EAAE;sBAG3C,MAAM,WAAW,MAAM,KAAG,SAAS,EAAE;CAGxD,CAAC"}
package/dist/vault.js ADDED
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Multisig vaults, client side: the encoding a vault's contract uses, worked
3
+ * out here rather than taken from the server.
4
+ *
5
+ * The point is the approval. An owner approves proposal N by naming the hash
6
+ * of its calls, `keccak256(abi.encode(calls))`. That hash is computed here,
7
+ * from the calls this app is about to show, so the approval the passkey signs
8
+ * is an approval of *what was on the screen*: if anything between the chain
9
+ * and the screen misrepresented the proposal, the vault refuses the approval
10
+ * instead of counting it. See `contracts/src/TheooVault.sol`.
11
+ */
12
+ import { addressWord, padded, Reader, selector, splitCall, toBig, word } from "./abi.js";
13
+ import { bytesToHex, concatBytes, hexToBytes, keccak256 } from "./hash.js";
14
+ /** `TheooVaultFactory`, at one address on every chain that has it. */
15
+ export const VAULT_FACTORY = "0xf9D5b7cB6081Ac75EBdd3A8763deF6981F2f78E4";
16
+ export const VAULT_LIMITS = { owners: 20, calls: 16, callData: 16384, delay: 30 * 24 * 60 * 60 };
17
+ export const VAULT_SEL = {
18
+ create: selector("create(address[],uint8,uint64,bytes32)"),
19
+ propose: selector("propose((address,uint256,bytes,uint256)[])"),
20
+ approve: selector("approve(uint256,bytes32)"),
21
+ revoke: selector("revoke(uint256)"),
22
+ reject: selector("reject(uint256)"),
23
+ cancel: selector("cancel(uint256)"),
24
+ execute: selector("execute(uint256)"),
25
+ addOwner: selector("addOwner(address,uint8)"),
26
+ removeOwner: selector("removeOwner(address,uint8)"),
27
+ replaceOwner: selector("replaceOwner(address,address)"),
28
+ setThreshold: selector("setThreshold(uint8)"),
29
+ setDelay: selector("setDelay(uint64)"),
30
+ signMessage: selector("signMessage(bytes32,bool)"),
31
+ erc20Transfer: selector("transfer(address,uint256)"),
32
+ };
33
+ const data = (c) => hexToBytes(c.data && c.data !== "" ? c.data : "0x");
34
+ /** The calls as a tail of `(address,uint256,bytes,uint256)[]`: length, offsets, tuples. */
35
+ function callsArray(calls) {
36
+ const tuples = calls.map((c) => {
37
+ const d = data(c);
38
+ return concatBytes(addressWord(c.to), word(toBig(c.value ?? 0)), word(128n), word(toBig(c.gas ?? 0)), word(BigInt(d.length)), padded(d));
39
+ });
40
+ const offsets = [];
41
+ let at = 32 * calls.length;
42
+ for (const t of tuples) {
43
+ offsets.push(word(BigInt(at)));
44
+ at += t.length;
45
+ }
46
+ return concatBytes(word(BigInt(calls.length)), ...offsets, ...tuples);
47
+ }
48
+ /** `abi.encode(calls)`, as the vault encodes them. */
49
+ export function encodeCalls(calls) {
50
+ return concatBytes(word(32n), callsArray(calls));
51
+ }
52
+ /** What an approval of these calls must name. */
53
+ export function callsHash(calls) {
54
+ return bytesToHex(keccak256(encodeCalls(calls)));
55
+ }
56
+ /** Calldata for `propose(calls)`. */
57
+ export function proposeData(calls) {
58
+ return bytesToHex(concatBytes(hexToBytes(VAULT_SEL.propose), encodeCalls(calls)));
59
+ }
60
+ /** The calls inside `propose(calls)` calldata. Throws if it isn't one. */
61
+ export function decodePropose(calldata) {
62
+ const s = splitCall(calldata);
63
+ if (s.selector !== VAULT_SEL.propose)
64
+ throw new Error("not a proposal");
65
+ const arr = s.args.sub(0);
66
+ const n = Number(arr.uint(0));
67
+ if (n > VAULT_LIMITS.calls)
68
+ throw new Error("too many calls");
69
+ const els = new Reader(arr.data, arr.base + 32);
70
+ const out = [];
71
+ for (let i = 0; i < n; i++) {
72
+ const t = els.sub(32 * i);
73
+ out.push({ to: t.address(0), value: t.uint(32).toString(), data: bytesToHex(t.bytes(64)), gas: Number(t.uint(96)) });
74
+ }
75
+ return out;
76
+ }
77
+ /* ── addresses ─────────────────────────────────────────────────────────── */
78
+ function create1(deployer, nonce) {
79
+ // RLP([deployer, nonce]) for a nonce below 0x80.
80
+ const rlp = concatBytes(new Uint8Array([0xd6, 0x94]), hexToBytes(deployer), new Uint8Array([nonce]));
81
+ return bytesToHex(keccak256(rlp).slice(12));
82
+ }
83
+ function create2(deployer, salt, codeHash) {
84
+ return bytesToHex(keccak256(concatBytes(new Uint8Array([0xff]), hexToBytes(deployer), salt, codeHash)).slice(12));
85
+ }
86
+ /**
87
+ * Where a vault with these settings is, on every chain with the factory.
88
+ * The address commits to all of them, so it can be shared — and funded —
89
+ * before the vault is created anywhere.
90
+ */
91
+ export function predictVault(owners, threshold, delay, salt) {
92
+ const head = concatBytes(word(128n), word(BigInt(threshold)), word(BigInt(delay)), hexToBytes(salt));
93
+ const tail = concatBytes(word(BigInt(owners.length)), ...owners.map(addressWord));
94
+ const vaultSalt = keccak256(concatBytes(head, tail));
95
+ const implementation = create1(VAULT_FACTORY, 1);
96
+ const clone = concatBytes(hexToBytes("0x3d602d80600a3d3981f3363d3d373d3d3d363d73"), hexToBytes(implementation), hexToBytes("0x5af43d82803e903d91602b57fd5bf3"));
97
+ return create2(VAULT_FACTORY, vaultSalt, keccak256(clone));
98
+ }
99
+ /** 32 random bytes, for a new vault. */
100
+ export function newSalt() {
101
+ const b = new Uint8Array(32);
102
+ crypto.getRandomValues(b);
103
+ return bytesToHex(b);
104
+ }
105
+ /** Turn one of a proposal's calls into what it does, for `vault` itself. */
106
+ export function describeCall(vault, c) {
107
+ const value = toBig(c.value ?? 0);
108
+ const raw = data(c);
109
+ if (raw.length === 0)
110
+ return { kind: "send", to: c.to, value };
111
+ const s = splitCall(raw);
112
+ const a = s.args;
113
+ try {
114
+ if (c.to.toLowerCase() === vault.toLowerCase()) {
115
+ switch (s.selector) {
116
+ case VAULT_SEL.addOwner:
117
+ return { kind: "add_owner", owner: a.address(0), threshold: Number(a.uint(32)) };
118
+ case VAULT_SEL.removeOwner:
119
+ return { kind: "remove_owner", owner: a.address(0), threshold: Number(a.uint(32)) };
120
+ case VAULT_SEL.replaceOwner:
121
+ return { kind: "replace_owner", owner: a.address(0), with: a.address(32) };
122
+ case VAULT_SEL.setThreshold:
123
+ return { kind: "threshold", threshold: Number(a.uint(0)) };
124
+ case VAULT_SEL.setDelay:
125
+ return { kind: "delay", seconds: Number(a.uint(0)) };
126
+ case VAULT_SEL.signMessage:
127
+ return { kind: "sign_message", hash: a.bytes32(0), signed: a.bool(32) };
128
+ }
129
+ }
130
+ if (s.selector === VAULT_SEL.erc20Transfer && value === 0n && raw.length === 68) {
131
+ return { kind: "token", token: c.to, to: a.address(0), amount: a.uint(32) };
132
+ }
133
+ }
134
+ catch {
135
+ /* not what its selector claimed: shown as a raw call */
136
+ }
137
+ return { kind: "call", to: c.to, value, selector: s.selector };
138
+ }
139
+ /** Calls for the common proposals. */
140
+ export const vaultCalls = {
141
+ send: (to, wei) => [{ to, value: toBig(wei).toString(), data: "0x" }],
142
+ sendToken: (token, to, amount) => [
143
+ {
144
+ to: token,
145
+ value: "0",
146
+ data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.erc20Transfer), addressWord(to), word(toBig(amount)))),
147
+ },
148
+ ],
149
+ addOwner: (vault, owner, threshold) => [
150
+ { to: vault, value: "0", data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.addOwner), addressWord(owner), word(BigInt(threshold)))) },
151
+ ],
152
+ removeOwner: (vault, owner, threshold) => [
153
+ { to: vault, value: "0", data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.removeOwner), addressWord(owner), word(BigInt(threshold)))) },
154
+ ],
155
+ replaceOwner: (vault, owner, next) => [
156
+ { to: vault, value: "0", data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.replaceOwner), addressWord(owner), addressWord(next))) },
157
+ ],
158
+ setThreshold: (vault, threshold) => [
159
+ { to: vault, value: "0", data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.setThreshold), word(BigInt(threshold)))) },
160
+ ],
161
+ setDelay: (vault, seconds) => [
162
+ { to: vault, value: "0", data: bytesToHex(concatBytes(hexToBytes(VAULT_SEL.setDelay), word(BigInt(seconds)))) },
163
+ ],
164
+ };
165
+ //# sourceMappingURL=vault.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3E,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,4CAA4C,CAAC;AAE1E,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAM,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAW,CAAC;AAE3G,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,QAAQ,CAAC,wCAAwC,CAAC;IAC1D,OAAO,EAAE,QAAQ,CAAC,4CAA4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AAE,WAAW,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;KACpI;IACD,YAAY,EAAE,CAAC,KAAa,EAAE,SAAiB,EAAe,EAAE,CAAC;QAC/D,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE;KACtH;IACD,QAAQ,EAAE,CAAC,KAAa,EAAE,OAAe,EAAe,EAAE,CAAC;QACzD,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;KAChH;CACF,CAAC"}
@@ -0,0 +1,82 @@
1
+ import type { OperationKind, PreparedOperation, PreparedSolanaOperation, SolanaAction } from "./types.js";
2
+ /** Thrown before the passkey is asked: what the server sent isn't what was asked for. */
3
+ export declare class SigningRefused extends Error {
4
+ readonly code: "SIGNING_REFUSED";
5
+ constructor(reason: string);
6
+ }
7
+ /** 0x's AllowanceHolder: the only spender a token swap approves. Same address on every chain. */
8
+ export declare const ALLOWANCE_HOLDER = "0x0000000000001ff3684f28c67538d4d072c22734";
9
+ /** LI.FI's Diamond: the only spender a cross-chain swap approves. Same address on every chain. */
10
+ export declare const LIFI_DIAMOND = "0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae";
11
+ /**
12
+ * Account implementations an `upgrade_account` may move to: the canonical
13
+ * set's, the same address on every chain. The first is live today; the
14
+ * second is the reviewed build that replaces it (contracts/canonical.env).
15
+ * Drop the first once the chains have moved.
16
+ */
17
+ export declare const ACCOUNT_IMPLEMENTATIONS: string[];
18
+ export interface WireUserOp {
19
+ sender: string;
20
+ nonce: string;
21
+ factory?: string | null;
22
+ factoryData?: string | null;
23
+ callData: string;
24
+ callGasLimit: string;
25
+ verificationGasLimit: string;
26
+ preVerificationGas: string;
27
+ maxFeePerGas: string;
28
+ maxPriorityFeePerGas: string;
29
+ paymaster?: string | null;
30
+ paymasterVerificationGasLimit?: string | null;
31
+ paymasterPostOpGasLimit?: string | null;
32
+ paymasterData?: string | null;
33
+ }
34
+ /** The EntryPoint v0.8 hash of an operation: what its passkey signs. */
35
+ export declare function userOpHash(op: WireUserOp, entryPoint: string, chainId: number): Uint8Array;
36
+ export interface PlainCall {
37
+ to: string;
38
+ value: bigint;
39
+ data: string;
40
+ }
41
+ /** The relayer-model account's own challenge: `keccak256(abi.encode(account, chainid, nonce, to, value, data))`. */
42
+ export declare function legacyChallenge(account: string, chainId: number, nonce: bigint, call: PlainCall): Uint8Array;
43
+ /** What the account's ERC-1271 check expects the passkey to have signed for `hash`. */
44
+ export declare function replaySafeHash(account: string, chainId: number, hash: Uint8Array): Uint8Array;
45
+ /** The calls an ERC-4337 operation's callData makes, as the account will run them. */
46
+ export declare function decodeAccountCalls(callData: string): PlainCall[];
47
+ /** What a quote said leaves the account: checked against the calls. */
48
+ export interface Budget {
49
+ /** A token address, or `"native"`. */
50
+ token: string;
51
+ /** Smallest unit. */
52
+ amount: bigint;
53
+ /** The chain's own coin a route may also take as a fee. */
54
+ extraNative?: bigint;
55
+ }
56
+ export interface CheckOptions {
57
+ chain?: number;
58
+ budget?: Budget;
59
+ /** When the user pays the network fee themselves: the most they may be charged, in wei. */
60
+ maxFeeWei?: bigint;
61
+ }
62
+ /** The calls, against what was asked for. */
63
+ export declare function checkCalls(kind: OperationKind, calls: PlainCall[], account: string, o: CheckOptions): void;
64
+ /** Check a prepared EVM operation against what was asked for. Throws `SigningRefused`. */
65
+ export declare function checkPrepared(kind: OperationKind, prepared: PreparedOperation, o?: CheckOptions): void;
66
+ /** Check a message-signing request: the hash is the message's, and the challenge is what the account expects for it. */
67
+ export declare function checkSignBegin(req: {
68
+ message?: string;
69
+ typedData?: unknown;
70
+ hash?: string;
71
+ }, begun: {
72
+ chain: number;
73
+ account: string;
74
+ hash: string;
75
+ challenge: string;
76
+ webauthnOptions: unknown;
77
+ }): void;
78
+ /** The Solana program's challenge: `sha256("theoo/solana/v1" ‖ program ‖ account ‖ nonce ‖ sha256(action))`. */
79
+ export declare function solanaChallenge(programId: string, account: string, nonce: bigint, action: Uint8Array): Uint8Array;
80
+ /** Check a prepared Solana operation against the action asked for. Throws `SigningRefused`. */
81
+ export declare function checkPreparedSolana(action: SolanaAction, prepared: PreparedSolanaOperation): void;
82
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAa,aAAa,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,YAAY,EAAa,MAAM,YAAY,CAAC;AAIhI,yFAAyF;AACzF,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAG,iBAAiB,CAAU;gBAC/B,MAAM,EAAE,MAAM;CAI3B;AAQD,iGAAiG;AACjG,eAAO,MAAM,gBAAgB,+CAA+C,CAAC;AAC7E,kGAAkG;AAClG,eAAO,MAAM,YAAY,+CAA+C,CAAC;AACzE;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAA+F,CAAC;AAMpI,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,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