@secondlayer/cli 9.2.0 → 9.3.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/cli.js +79 -19
- package/dist/cli.js.map +3 -3
- package/package.json +15 -5
package/dist/cli.js
CHANGED
|
@@ -28910,7 +28910,7 @@ export default defineSubgraph({
|
|
|
28910
28910
|
`;
|
|
28911
28911
|
}
|
|
28912
28912
|
function sip010Balances(name) {
|
|
28913
|
-
return `import { defineSubgraph } from "@secondlayer/subgraphs";
|
|
28913
|
+
return `import { defineSchema, defineSubgraph, readContractAt, type TypedSubgraphContext } from "@secondlayer/subgraphs";
|
|
28914
28914
|
|
|
28915
28915
|
/**
|
|
28916
28916
|
* Track SIP-010 token balances per (asset_identifier, holder).
|
|
@@ -28925,10 +28925,53 @@ function sip010Balances(name) {
|
|
|
28925
28925
|
* under \`backfillMode: "concurrent"\`. Deltas commute, so order doesn't
|
|
28926
28926
|
* matter and a reorg rewind reverses cleanly via the journal.
|
|
28927
28927
|
*
|
|
28928
|
+
* Token metadata (decimals/symbol) comes from the token contract itself via
|
|
28929
|
+
* \`readContractAt\`, so \`amount\` stops being a bare integer nobody can
|
|
28930
|
+
* render. The read is pinned to the block being processed — a handler stays a
|
|
28931
|
+
* pure function of its block — and \`cache: "contract-constant"\` says these
|
|
28932
|
+
* two values can never change for a given token, so each is fetched ONCE
|
|
28933
|
+
* instead of once per block.
|
|
28934
|
+
*
|
|
28928
28935
|
* Query examples once deployed:
|
|
28929
28936
|
* GET /v1/subgraphs/${name}/balances?_search=SP1...
|
|
28930
28937
|
* GET /v1/subgraphs/${name}/balances?holder=SP1...
|
|
28938
|
+
* GET /v1/subgraphs/${name}/tokens
|
|
28931
28939
|
*/
|
|
28940
|
+
|
|
28941
|
+
/** The two SIP-010 read-only functions this subgraph calls. */
|
|
28942
|
+
const SIP010_ABI = {
|
|
28943
|
+
functions: [
|
|
28944
|
+
{ name: "get-decimals", access: "read-only", args: [], outputs: { response: { ok: "uint128", error: "uint128" } } },
|
|
28945
|
+
{ name: "get-symbol", access: "read-only", args: [], outputs: { response: { ok: { "string-ascii": { length: 32 } }, error: "uint128" } } },
|
|
28946
|
+
],
|
|
28947
|
+
} as const;
|
|
28948
|
+
|
|
28949
|
+
/** Tokens already labelled in this process — metadata is immutable, so one
|
|
28950
|
+
* resolution per token is enough even across a backfill. */
|
|
28951
|
+
const labelled = new Set<string>();
|
|
28952
|
+
|
|
28953
|
+
// Hoisted so the helper below can be typed against it.
|
|
28954
|
+
const schema = defineSchema({
|
|
28955
|
+
balances: {
|
|
28956
|
+
columns: {
|
|
28957
|
+
asset_identifier: { type: "text", indexed: true, search: true },
|
|
28958
|
+
holder: { type: "principal", indexed: true, search: true },
|
|
28959
|
+
amount: { type: "uint" },
|
|
28960
|
+
},
|
|
28961
|
+
// increment() upserts on this key.
|
|
28962
|
+
uniqueKeys: [["asset_identifier", "holder"]],
|
|
28963
|
+
},
|
|
28964
|
+
tokens: {
|
|
28965
|
+
columns: {
|
|
28966
|
+
asset_identifier: { type: "text", indexed: true },
|
|
28967
|
+
contract_id: { type: "text" },
|
|
28968
|
+
symbol: { type: "text" },
|
|
28969
|
+
decimals: { type: "uint" },
|
|
28970
|
+
},
|
|
28971
|
+
uniqueKeys: [["asset_identifier"]],
|
|
28972
|
+
},
|
|
28973
|
+
});
|
|
28974
|
+
|
|
28932
28975
|
export default defineSubgraph({
|
|
28933
28976
|
name: "${name}",
|
|
28934
28977
|
version: "1.0.0",
|
|
@@ -28940,20 +28983,11 @@ export default defineSubgraph({
|
|
|
28940
28983
|
burn: { type: "ft_burn" },
|
|
28941
28984
|
},
|
|
28942
28985
|
|
|
28943
|
-
schema
|
|
28944
|
-
balances: {
|
|
28945
|
-
columns: {
|
|
28946
|
-
asset_identifier: { type: "text", indexed: true, search: true },
|
|
28947
|
-
holder: { type: "principal", indexed: true, search: true },
|
|
28948
|
-
amount: { type: "uint" },
|
|
28949
|
-
},
|
|
28950
|
-
// increment() upserts on this key.
|
|
28951
|
-
uniqueKeys: [["asset_identifier", "holder"]],
|
|
28952
|
-
},
|
|
28953
|
-
},
|
|
28986
|
+
schema,
|
|
28954
28987
|
|
|
28955
28988
|
handlers: {
|
|
28956
|
-
transfer: (event, ctx) => {
|
|
28989
|
+
transfer: async (event, ctx) => {
|
|
28990
|
+
await labelToken(event.assetIdentifier, ctx);
|
|
28957
28991
|
const amount = BigInt(event.amount ?? 0);
|
|
28958
28992
|
if (event.sender) {
|
|
28959
28993
|
ctx.increment("balances", { asset_identifier: event.assetIdentifier, holder: event.sender }, { amount: -amount });
|
|
@@ -28974,6 +29008,22 @@ export default defineSubgraph({
|
|
|
28974
29008
|
},
|
|
28975
29009
|
},
|
|
28976
29010
|
});
|
|
29011
|
+
|
|
29012
|
+
/** Resolve a token's symbol + decimals from its contract, once. */
|
|
29013
|
+
async function labelToken(
|
|
29014
|
+
assetIdentifier: string | undefined,
|
|
29015
|
+
ctx: TypedSubgraphContext<typeof schema>,
|
|
29016
|
+
) {
|
|
29017
|
+
if (!assetIdentifier || labelled.has(assetIdentifier)) return;
|
|
29018
|
+
labelled.add(assetIdentifier);
|
|
29019
|
+
const contractId = assetIdentifier.split("::")[0];
|
|
29020
|
+
const token = readContractAt(ctx, contractId, SIP010_ABI, { cache: "contract-constant" });
|
|
29021
|
+
const [decimals, symbol] = await Promise.all([
|
|
29022
|
+
token.read.getDecimals({}),
|
|
29023
|
+
token.read.getSymbol({}),
|
|
29024
|
+
]);
|
|
29025
|
+
ctx.upsert("tokens", { asset_identifier: assetIdentifier }, { asset_identifier: assetIdentifier, contract_id: contractId, symbol, decimals });
|
|
29026
|
+
}
|
|
28977
29027
|
`;
|
|
28978
29028
|
}
|
|
28979
29029
|
function sbtcFlows(name) {
|
|
@@ -34689,7 +34739,7 @@ var {
|
|
|
34689
34739
|
// package.json
|
|
34690
34740
|
var package_default = {
|
|
34691
34741
|
name: "@secondlayer/cli",
|
|
34692
|
-
version: "9.
|
|
34742
|
+
version: "9.3.0",
|
|
34693
34743
|
repository: {
|
|
34694
34744
|
type: "git",
|
|
34695
34745
|
url: "git+https://github.com/ryanwaits/secondlayer.git",
|
|
@@ -34714,7 +34764,11 @@ var package_default = {
|
|
|
34714
34764
|
import: "./dist/plugins/index.js"
|
|
34715
34765
|
}
|
|
34716
34766
|
},
|
|
34717
|
-
files: [
|
|
34767
|
+
files: [
|
|
34768
|
+
"dist",
|
|
34769
|
+
"templates",
|
|
34770
|
+
"README.md"
|
|
34771
|
+
],
|
|
34718
34772
|
scripts: {
|
|
34719
34773
|
build: "bunup",
|
|
34720
34774
|
dev: "bunup --watch",
|
|
@@ -34722,7 +34776,13 @@ var package_default = {
|
|
|
34722
34776
|
typecheck: "tsc --noEmit",
|
|
34723
34777
|
prepublishOnly: "bun run build"
|
|
34724
34778
|
},
|
|
34725
|
-
keywords: [
|
|
34779
|
+
keywords: [
|
|
34780
|
+
"stacks",
|
|
34781
|
+
"clarity",
|
|
34782
|
+
"blockchain",
|
|
34783
|
+
"smart-contracts",
|
|
34784
|
+
"cli"
|
|
34785
|
+
],
|
|
34726
34786
|
author: "",
|
|
34727
34787
|
license: "MIT",
|
|
34728
34788
|
dependencies: {
|
|
@@ -34731,8 +34791,8 @@ var package_default = {
|
|
|
34731
34791
|
"@secondlayer/scaffold": "^1.5.0",
|
|
34732
34792
|
"@secondlayer/sdk": "^6.36.0",
|
|
34733
34793
|
"@secondlayer/shared": "^7.0.3",
|
|
34734
|
-
"@secondlayer/stacks": "^2.
|
|
34735
|
-
"@secondlayer/subgraphs": "^3.
|
|
34794
|
+
"@secondlayer/stacks": "^2.22.0",
|
|
34795
|
+
"@secondlayer/subgraphs": "^3.23.0",
|
|
34736
34796
|
"@biomejs/js-api": "^0.7.0",
|
|
34737
34797
|
"@biomejs/wasm-nodejs": "^1.9.0",
|
|
34738
34798
|
esbuild: "^0.27.4",
|
|
@@ -38559,5 +38619,5 @@ registerAccountCommand(program);
|
|
|
38559
38619
|
registerKeysCommand(program);
|
|
38560
38620
|
program.parse();
|
|
38561
38621
|
|
|
38562
|
-
//# debugId=
|
|
38622
|
+
//# debugId=083CEA7A9489EF8064756E2164756E21
|
|
38563
38623
|
//# sourceMappingURL=cli.js.map
|