@secretkeylabs/stacks-tools 0.2.0 → 0.3.0-6f23618
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/queries/get-signer-stacked-amount.d.ts +18 -0
- package/dist/queries/get-signer-stacked-amount.js +59 -0
- package/dist/queries/get-signer-stacked-amount.js.map +1 -0
- package/dist/queries/index.d.ts +2 -2
- package/dist/queries/index.js +2 -2
- package/dist/queries/index.js.map +1 -1
- package/dist/stacks-api/index.d.ts +1 -0
- package/dist/stacks-api/proof-of-transfer/index.d.ts +2 -0
- package/dist/stacks-api/proof-of-transfer/index.js +2 -0
- package/dist/stacks-api/proof-of-transfer/index.js.map +1 -1
- package/dist/stacks-api/proof-of-transfer/signer-in-cycle.d.ts +22 -0
- package/dist/stacks-api/proof-of-transfer/signer-in-cycle.js +57 -0
- package/dist/stacks-api/proof-of-transfer/signer-in-cycle.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ApiRequestOptions } from "../stacks-api/types.js";
|
|
2
|
+
import { type Result, type SafeError } from "../utils/safe.js";
|
|
3
|
+
export type Identifier = {
|
|
4
|
+
type: "address";
|
|
5
|
+
signerAddress: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "publicKey";
|
|
8
|
+
signerPublicKey: string;
|
|
9
|
+
};
|
|
10
|
+
export type Args = {
|
|
11
|
+
identifier: Identifier;
|
|
12
|
+
} & {
|
|
13
|
+
cycleNumber: number;
|
|
14
|
+
} & ApiRequestOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Return the total locked amount for a signer in a PoX cycle.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSignerStackedAmount(args: Args): Promise<Result<bigint, SafeError<"SignerNotFound" | string>>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { signersInCycle } from "../stacks-api/proof-of-transfer/signers-in-cycle.js";
|
|
2
|
+
import { safeCallRateLimitedApi } from "../utils/call-rate-limited-api.js";
|
|
3
|
+
import { error as safeError, success, } from "../utils/safe.js";
|
|
4
|
+
/**
|
|
5
|
+
* Return the total locked amount for a signer in a PoX cycle.
|
|
6
|
+
*/
|
|
7
|
+
export async function getSignerStackedAmount(args) {
|
|
8
|
+
let totalLocked = 0n;
|
|
9
|
+
const { identifier, ...rest } = args;
|
|
10
|
+
let hasMore = true;
|
|
11
|
+
let offset = 0;
|
|
12
|
+
let found = false;
|
|
13
|
+
const limit = 200;
|
|
14
|
+
while (hasMore && !found) {
|
|
15
|
+
const [error, data] = await safeCallRateLimitedApi(() => signersInCycle({
|
|
16
|
+
...rest,
|
|
17
|
+
limit,
|
|
18
|
+
}));
|
|
19
|
+
if (error) {
|
|
20
|
+
return safeError({
|
|
21
|
+
name: "GetSignerTotalLockedError",
|
|
22
|
+
message: "Failed to get signer total locked.",
|
|
23
|
+
data: {
|
|
24
|
+
error,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
for (const signer of data.results) {
|
|
29
|
+
if (identifier.type === "address") {
|
|
30
|
+
if (signer.signer_address === identifier.signerAddress) {
|
|
31
|
+
totalLocked = BigInt(signer.stacked_amount);
|
|
32
|
+
found = true;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (signer.signing_key === identifier.signerPublicKey) {
|
|
38
|
+
totalLocked = BigInt(signer.stacked_amount);
|
|
39
|
+
found = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
offset += limit + data.results.length;
|
|
45
|
+
hasMore = offset < data.total;
|
|
46
|
+
}
|
|
47
|
+
if (!found) {
|
|
48
|
+
return safeError({
|
|
49
|
+
name: "SignerNotFound",
|
|
50
|
+
message: "Signer not found.",
|
|
51
|
+
data: {
|
|
52
|
+
identifier,
|
|
53
|
+
cycle: args.cycleNumber,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return success(totalLocked);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=get-signer-stacked-amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-signer-stacked-amount.js","sourceRoot":"","sources":["../../src/queries/get-signer-stacked-amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qDAAqD,CAAC;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EACL,KAAK,IAAI,SAAS,EAClB,OAAO,GAGR,MAAM,kBAAkB,CAAC;AAgB1B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAU;IAEV,IAAI,WAAW,GAAG,EAAE,CAAC;IAErB,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAErC,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,MAAM,KAAK,GAAG,GAAG,CAAC;IAClB,OAAO,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,MAAM,sBAAsB,CAAC,GAAG,EAAE,CACtD,cAAc,CAAC;YACb,GAAG,IAAI;YACP,KAAK;SACN,CAAC,CACH,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,SAAS,CAAC;gBACf,IAAI,EAAE,2BAA2B;gBACjC,OAAO,EAAE,oCAAoC;gBAC7C,IAAI,EAAE;oBACJ,KAAK;iBACN;aACF,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAClC,IAAI,MAAM,CAAC,cAAc,KAAK,UAAU,CAAC,aAAa,EAAE,CAAC;oBACvD,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;oBAC5C,KAAK,GAAG,IAAI,CAAC;oBACb,MAAM;gBACR,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,MAAM,CAAC,WAAW,KAAK,UAAU,CAAC,eAAe,EAAE,CAAC;oBACtD,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;oBAC5C,KAAK,GAAG,IAAI,CAAC;oBACb,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACtC,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;YACf,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,mBAAmB;YAC5B,IAAI,EAAE;gBACJ,UAAU;gBACV,KAAK,EAAE,IAAI,CAAC,WAAW;aACxB;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/queries/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSignerStackedAmount } from "./get-signer-stacked-amount.js";
|
|
2
2
|
export declare const queries: {
|
|
3
|
-
|
|
3
|
+
getSignerStackedAmount: typeof getSignerStackedAmount;
|
|
4
4
|
};
|
package/dist/queries/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,sBAAsB;CACvB,CAAC"}
|
|
@@ -12,6 +12,7 @@ export declare const stacksApi: {
|
|
|
12
12
|
proofOfTransfer: {
|
|
13
13
|
cycle: typeof import("./proof-of-transfer/cycle.js").cycle;
|
|
14
14
|
cycles: typeof import("./proof-of-transfer/cycles.js").cycles;
|
|
15
|
+
signerInCycle: typeof import("./proof-of-transfer/signer-in-cycle.js").signerInCycle;
|
|
15
16
|
signersInCycle: typeof import("./proof-of-transfer/signers-in-cycle.js").signersInCycle;
|
|
16
17
|
stackersForSignerInCycle: typeof import("./proof-of-transfer/stackers-for-signer-in-cycle.js").stackersForSignerInCycle;
|
|
17
18
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cycle } from "./cycle.js";
|
|
2
2
|
import { cycles } from "./cycles.js";
|
|
3
|
+
import { signerInCycle } from "./signer-in-cycle.js";
|
|
3
4
|
import { signersInCycle } from "./signers-in-cycle.js";
|
|
4
5
|
import { stackersForSignerInCycle } from "./stackers-for-signer-in-cycle.js";
|
|
5
6
|
export declare const proofOfTransfer: {
|
|
6
7
|
cycle: typeof cycle;
|
|
7
8
|
cycles: typeof cycles;
|
|
9
|
+
signerInCycle: typeof signerInCycle;
|
|
8
10
|
signersInCycle: typeof signersInCycle;
|
|
9
11
|
stackersForSignerInCycle: typeof stackersForSignerInCycle;
|
|
10
12
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cycle } from "./cycle.js";
|
|
2
2
|
import { cycles } from "./cycles.js";
|
|
3
|
+
import { signerInCycle } from "./signer-in-cycle.js";
|
|
3
4
|
import { signersInCycle } from "./signers-in-cycle.js";
|
|
4
5
|
import { stackersForSignerInCycle } from "./stackers-for-signer-in-cycle.js";
|
|
5
6
|
export const proofOfTransfer = {
|
|
6
7
|
cycle,
|
|
7
8
|
cycles,
|
|
9
|
+
signerInCycle,
|
|
8
10
|
signersInCycle,
|
|
9
11
|
stackersForSignerInCycle,
|
|
10
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stacks-api/proof-of-transfer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK;IACL,MAAM;IACN,cAAc;IACd,wBAAwB;CACzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stacks-api/proof-of-transfer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK;IACL,MAAM;IACN,aAAa;IACb,cAAc;IACd,wBAAwB;CACzB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Result } from "../../utils/safe.js";
|
|
2
|
+
import type { ApiRequestOptions } from "../types.js";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
export type Args = {
|
|
5
|
+
/**
|
|
6
|
+
* The signers public key as a hex string, with or without a '0x' prefix.
|
|
7
|
+
*/
|
|
8
|
+
signerPublicKey: string;
|
|
9
|
+
cycleId: number;
|
|
10
|
+
} & ApiRequestOptions;
|
|
11
|
+
export declare const signerInCycleResponseSchema: v.ObjectSchema<{
|
|
12
|
+
readonly signing_key: v.StringSchema<undefined>;
|
|
13
|
+
readonly signer_address: v.StringSchema<undefined>;
|
|
14
|
+
readonly weight: v.NumberSchema<undefined>;
|
|
15
|
+
readonly stacked_amount: v.StringSchema<undefined>;
|
|
16
|
+
readonly weight_percent: v.NumberSchema<undefined>;
|
|
17
|
+
readonly stacked_amount_percent: v.NumberSchema<undefined>;
|
|
18
|
+
readonly solo_stacker_count: v.NumberSchema<undefined>;
|
|
19
|
+
readonly pooled_stacker_count: v.NumberSchema<undefined>;
|
|
20
|
+
}, undefined>;
|
|
21
|
+
export type SignerInCycleResponse = v.InferOutput<typeof signerInCycleResponseSchema>;
|
|
22
|
+
export declare function signerInCycle(args: Args): Promise<Result<SignerInCycleResponse>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { error, safePromise, success } from "../../utils/safe.js";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
export const signerInCycleResponseSchema = v.object({
|
|
4
|
+
signing_key: v.string(),
|
|
5
|
+
signer_address: v.string(),
|
|
6
|
+
weight: v.number(),
|
|
7
|
+
stacked_amount: v.string(),
|
|
8
|
+
weight_percent: v.number(),
|
|
9
|
+
stacked_amount_percent: v.number(),
|
|
10
|
+
solo_stacker_count: v.number(),
|
|
11
|
+
pooled_stacker_count: v.number(),
|
|
12
|
+
});
|
|
13
|
+
export async function signerInCycle(args) {
|
|
14
|
+
const init = {};
|
|
15
|
+
if (args.apiKeyConfig) {
|
|
16
|
+
init.headers = {
|
|
17
|
+
[args.apiKeyConfig.header]: args.apiKeyConfig.key,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const signerPublicKey = args.signerPublicKey.startsWith("0x")
|
|
21
|
+
? args.signerPublicKey
|
|
22
|
+
: `0x${args.signerPublicKey}`;
|
|
23
|
+
const endpoint = `${args.baseUrl}/extended/v2/pox/cycles/${args.cycleId}/signers/${signerPublicKey}`;
|
|
24
|
+
const res = await fetch(endpoint, init);
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
return error({
|
|
27
|
+
name: "FetchSignerInCycleError",
|
|
28
|
+
message: "Failed to fetch signer in cycle.",
|
|
29
|
+
data: {
|
|
30
|
+
status: res.status,
|
|
31
|
+
statusText: res.statusText,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
36
|
+
if (jsonError) {
|
|
37
|
+
return error({
|
|
38
|
+
name: "ParseBodyError",
|
|
39
|
+
message: "Failed to parse response body.",
|
|
40
|
+
data: {
|
|
41
|
+
signerPublicKey: args.signerPublicKey,
|
|
42
|
+
cycleId: args.cycleId,
|
|
43
|
+
jsonError,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const validationResult = v.safeParse(signerInCycleResponseSchema, data);
|
|
48
|
+
if (!validationResult.success) {
|
|
49
|
+
return error({
|
|
50
|
+
name: "ValidateDataError",
|
|
51
|
+
message: "Failed to validate response data.",
|
|
52
|
+
data: validationResult.issues,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return success(validationResult.output);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=signer-in-cycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer-in-cycle.js","sourceRoot":"","sources":["../../../src/stacks-api/proof-of-transfer/signer-in-cycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAe,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAU7B,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAAC;IAClD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,cAAc,EAAE,CAAC,CAAC,MAAM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