@cloakely/sdk 0.3.1 → 0.5.0
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/abis.d.ts +1037 -172
- package/dist/abis.js +1421 -294
- package/dist/bytecode.d.ts +10 -7
- package/dist/bytecode.js +1 -1
- package/dist/cloak.d.ts +83 -0
- package/dist/cloak.js +18 -28
- package/dist/deployments.d.ts +26 -5
- package/dist/deployments.js +79 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/private/client.d.ts +28 -4
- package/dist/private/client.js +84 -20
- package/dist/private/crypto.d.ts +23 -5
- package/dist/private/crypto.js +14 -5
- package/dist/registry.d.ts +48 -0
- package/dist/registry.js +54 -0
- package/package.json +1 -1
package/dist/private/crypto.d.ts
CHANGED
|
@@ -7,13 +7,31 @@ export declare const MAIN_KEY = 4294967295;
|
|
|
7
7
|
export declare const randomField: () => bigint;
|
|
8
8
|
export declare const randomKeyIndex: () => number;
|
|
9
9
|
export declare function poseidon(inputs: bigint[]): Promise<bigint>;
|
|
10
|
-
/** The message a wallet signs to derive its Cloak private account (deterministic for standard EOAs). */
|
|
11
|
-
export declare const ACCOUNT_MESSAGE = "Cloak private account v1\n\nSigning this derives your private trading keys on Elysium. It costs nothing and does not move funds.";
|
|
12
10
|
/**
|
|
13
|
-
* EIP-712 request whose signature derives
|
|
14
|
-
*
|
|
11
|
+
* EIP-712 request whose signature derives a wallet's Cloak private account (v4 on). It is bound to the chain only, never
|
|
12
|
+
* to a contract, so the account and its `cloak:` address stay the same through every upgrade.
|
|
15
13
|
*/
|
|
16
|
-
export declare const ACCOUNT_TYPED_DATA: (chainId: number
|
|
14
|
+
export declare const ACCOUNT_TYPED_DATA: (chainId: number) => {
|
|
15
|
+
readonly domain: {
|
|
16
|
+
readonly name: "Cloak";
|
|
17
|
+
readonly version: "4";
|
|
18
|
+
readonly chainId: number;
|
|
19
|
+
};
|
|
20
|
+
readonly types: {
|
|
21
|
+
readonly PrivateAccount: readonly [{
|
|
22
|
+
readonly name: "purpose";
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
}];
|
|
25
|
+
};
|
|
26
|
+
readonly primaryType: "PrivateAccount";
|
|
27
|
+
readonly message: {
|
|
28
|
+
readonly purpose: "Derive my Cloak private account. This costs nothing and moves no funds. Only sign this on cloak.boblabs.tech.";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** The plain message v1 accounts were derived from. Only used to move an old v1 balance. */
|
|
32
|
+
export declare const ACCOUNT_MESSAGE = "Cloak private account v1\n\nSigning this derives your private trading keys on Elysium. It costs nothing and does not move funds.";
|
|
33
|
+
/** The EIP-712 request v2 and v3 accounts were derived from, bound to that deployment's router. Only used to move an old balance. */
|
|
34
|
+
export declare const ROUTER_ACCOUNT_TYPED_DATA: (chainId: number, router: `0x${string}`) => {
|
|
17
35
|
readonly domain: {
|
|
18
36
|
readonly name: "Cloak";
|
|
19
37
|
readonly version: "2";
|
package/dist/private/crypto.js
CHANGED
|
@@ -18,13 +18,22 @@ export async function poseidon(inputs) {
|
|
|
18
18
|
_poseidon ??= await (await import("circomlibjs")).buildPoseidon(); // loaded on first use
|
|
19
19
|
return _poseidon.F.toObject(_poseidon(inputs.map((x) => BigInt(x))));
|
|
20
20
|
}
|
|
21
|
-
/** The message a wallet signs to derive its Cloak private account (deterministic for standard EOAs). */
|
|
22
|
-
export const ACCOUNT_MESSAGE = "Cloak private account v1\n\nSigning this derives your private trading keys on Elysium. It costs nothing and does not move funds.";
|
|
23
21
|
/**
|
|
24
|
-
* EIP-712 request whose signature derives
|
|
25
|
-
*
|
|
22
|
+
* EIP-712 request whose signature derives a wallet's Cloak private account (v4 on). It is bound to the chain only, never
|
|
23
|
+
* to a contract, so the account and its `cloak:` address stay the same through every upgrade.
|
|
26
24
|
*/
|
|
27
|
-
export const ACCOUNT_TYPED_DATA = (chainId
|
|
25
|
+
export const ACCOUNT_TYPED_DATA = (chainId) => ({
|
|
26
|
+
domain: { name: "Cloak", version: "4", chainId },
|
|
27
|
+
types: { PrivateAccount: [{ name: "purpose", type: "string" }] },
|
|
28
|
+
primaryType: "PrivateAccount",
|
|
29
|
+
message: {
|
|
30
|
+
purpose: "Derive my Cloak private account. This costs nothing and moves no funds. Only sign this on cloak.boblabs.tech.",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
/** The plain message v1 accounts were derived from. Only used to move an old v1 balance. */
|
|
34
|
+
export const ACCOUNT_MESSAGE = "Cloak private account v1\n\nSigning this derives your private trading keys on Elysium. It costs nothing and does not move funds.";
|
|
35
|
+
/** The EIP-712 request v2 and v3 accounts were derived from, bound to that deployment's router. Only used to move an old balance. */
|
|
36
|
+
export const ROUTER_ACCOUNT_TYPED_DATA = (chainId, router) => ({
|
|
28
37
|
domain: { name: "Cloak", version: "2", chainId, verifyingContract: router },
|
|
29
38
|
types: { PrivateAccount: [{ name: "purpose", type: "string" }] },
|
|
30
39
|
primaryType: "PrivateAccount",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Address, type PublicClient } from "viem";
|
|
2
|
+
/** One contract in CloakConfig's registry. */
|
|
3
|
+
export interface RegistryEntry {
|
|
4
|
+
kind: string;
|
|
5
|
+
addr: Address;
|
|
6
|
+
version: number;
|
|
7
|
+
startBlock: bigint;
|
|
8
|
+
}
|
|
9
|
+
/** An earlier deployment, rebuilt from the registry: what's needed to list its launches and move its balances. */
|
|
10
|
+
export interface RegistryVersion {
|
|
11
|
+
version: number;
|
|
12
|
+
router?: Address;
|
|
13
|
+
routerBlock?: bigint;
|
|
14
|
+
batcher?: Address;
|
|
15
|
+
batcherBlock?: bigint;
|
|
16
|
+
factory?: Address;
|
|
17
|
+
factoryBlock?: bigint;
|
|
18
|
+
/** Standalone vaults of that deployment, outside its router (v2's USDC vault). */
|
|
19
|
+
pools: {
|
|
20
|
+
addr: Address;
|
|
21
|
+
startBlock: bigint;
|
|
22
|
+
}[];
|
|
23
|
+
}
|
|
24
|
+
/** Everything Cloak has deployed on a chain, read from CloakConfig, so apps only need that one address. */
|
|
25
|
+
export interface CloakRegistry {
|
|
26
|
+
config: Address;
|
|
27
|
+
entries: RegistryEntry[];
|
|
28
|
+
/** Factories whose launches the vaults may list, oldest first. */
|
|
29
|
+
launchFactories: Address[];
|
|
30
|
+
/** The current version (the newest router's). */
|
|
31
|
+
version: number;
|
|
32
|
+
vaults?: Address;
|
|
33
|
+
/** First block of the permanent vaults: scan private notes from here, whichever router is current. */
|
|
34
|
+
vaultsBlock?: bigint;
|
|
35
|
+
router: Address;
|
|
36
|
+
routerBlock: bigint;
|
|
37
|
+
batcher?: Address;
|
|
38
|
+
batcherBlock?: bigint;
|
|
39
|
+
migrator?: Address;
|
|
40
|
+
factory: Address;
|
|
41
|
+
factoryBlock: bigint;
|
|
42
|
+
/** Earlier factories of the current version (a factory added next to the first), newest first. */
|
|
43
|
+
earlierFactories: Address[];
|
|
44
|
+
/** Earlier deployments, newest first. */
|
|
45
|
+
previous: RegistryVersion[];
|
|
46
|
+
}
|
|
47
|
+
/** Read CloakConfig's registry. Throws if it has no router or factory yet. */
|
|
48
|
+
export declare function readRegistry(publicClient: PublicClient, config: Address): Promise<CloakRegistry>;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { hexToString } from "viem";
|
|
2
|
+
import { cloakConfigAbi } from "./abis.js";
|
|
3
|
+
const kindOf = (k) => hexToString(k, { size: 32 }).replace(/\0+$/, "");
|
|
4
|
+
/** Read CloakConfig's registry. Throws if it has no router or factory yet. */
|
|
5
|
+
export async function readRegistry(publicClient, config) {
|
|
6
|
+
const c = { address: config, abi: cloakConfigAbi };
|
|
7
|
+
const [n, nf] = await Promise.all([
|
|
8
|
+
publicClient.readContract({ ...c, functionName: "registryCount" }),
|
|
9
|
+
publicClient.readContract({ ...c, functionName: "launchFactoriesCount" }),
|
|
10
|
+
]);
|
|
11
|
+
const [rows, launchFactories] = await Promise.all([
|
|
12
|
+
Promise.all(Array.from({ length: Number(n) }, (_, i) => publicClient.readContract({ ...c, functionName: "registry", args: [BigInt(i)] }))),
|
|
13
|
+
Promise.all(Array.from({ length: Number(nf) }, (_, i) => publicClient.readContract({ ...c, functionName: "launchFactories", args: [BigInt(i)] }))),
|
|
14
|
+
]);
|
|
15
|
+
const entries = rows.map(([kind, addr, version, startBlock]) => ({ kind: kindOf(kind), addr, version: Number(version), startBlock: BigInt(startBlock) }));
|
|
16
|
+
const newest = (kind, version) => [...entries].reverse().find((e) => e.kind === kind && (version === undefined || e.version === version));
|
|
17
|
+
const router = newest("router");
|
|
18
|
+
const factory = newest("factory");
|
|
19
|
+
if (!router || !factory)
|
|
20
|
+
throw new Error(`CloakConfig ${config} has no router or factory registered yet`);
|
|
21
|
+
const batcher = newest("batcher", router.version);
|
|
22
|
+
const versions = [...new Set(entries.map((e) => e.version))].filter((v) => v < router.version).sort((a, b) => b - a);
|
|
23
|
+
return {
|
|
24
|
+
config,
|
|
25
|
+
entries,
|
|
26
|
+
launchFactories,
|
|
27
|
+
version: router.version,
|
|
28
|
+
vaults: newest("vaults")?.addr,
|
|
29
|
+
vaultsBlock: newest("vaults")?.startBlock,
|
|
30
|
+
router: router.addr,
|
|
31
|
+
routerBlock: router.startBlock,
|
|
32
|
+
batcher: batcher?.addr,
|
|
33
|
+
batcherBlock: batcher?.startBlock,
|
|
34
|
+
migrator: newest("migrator", router.version)?.addr,
|
|
35
|
+
factory: factory.addr,
|
|
36
|
+
factoryBlock: factory.startBlock,
|
|
37
|
+
earlierFactories: entries.filter((e) => e.kind === "factory" && e.version === factory.version && e.addr !== factory.addr).reverse().map((e) => e.addr),
|
|
38
|
+
previous: versions.map((v) => {
|
|
39
|
+
const r = newest("router", v);
|
|
40
|
+
const b = newest("batcher", v);
|
|
41
|
+
const f = newest("factory", v);
|
|
42
|
+
return {
|
|
43
|
+
version: v,
|
|
44
|
+
router: r?.addr,
|
|
45
|
+
routerBlock: r?.startBlock,
|
|
46
|
+
batcher: b?.addr,
|
|
47
|
+
batcherBlock: b?.startBlock,
|
|
48
|
+
factory: f?.addr,
|
|
49
|
+
factoryBlock: f?.startBlock,
|
|
50
|
+
pools: entries.filter((e) => e.kind === "pool" && e.version === v).map((e) => ({ addr: e.addr, startBlock: e.startBlock })),
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloakely/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Cloak on Elysium: sealed-bid token launches and private trading (shielded balances, private swaps, batch auctions, private sends) with on-device zero-knowledge proofs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloak",
|