Contract state
Know what changed in any Stacks contract, when, and who changed it.
One ALEX swap names a single call. Index shows the calls that ran inside it, as which contract, and every entry they changed.
The transaction
Block 1,508,068, June 6, 2025. 0xe8b2ac70…9daf
| Call | amm-pool-v2-01::swap-x-for-y |
| Signed by | SP2VC…6A1M |
| Result | (ok (tuple (dx u100000000) (dy u4997501249))) |
What ran inside it
Four transfers out of the vault, called by a token contract the signer deployed.
| # | Call | Sender | Caller |
|---|---|---|---|
| 14 | token-abtc::transfer-fixed | amm-vault-v2-01 | ssl-labubu-672d3 |
| 16 | sbtc-token::transfer | amm-vault-v2-01 | ssl-labubu-672d3 |
| 18 | token-alex::transfer-fixed | amm-vault-v2-01 | ssl-labubu-672d3 |
| 20 | token-susdt::transfer-fixed | amm-vault-v2-01 | ssl-labubu-672d3 |
| 21 | ssl-labubu-672d3::transfer-fixed | amm-vault-v2-01 | amm-vault-v2-01 |
What changed
pools-data-map for pool 170 in amm-registry-v2-01.
| Field | Block 1,508,061 | Block 1,508,068 |
|---|---|---|
| balance-x | 200000000000 | 200100000000 |
| balance-y | 10000000000000 | 9995002498751 |
What left the vault
Five token transfers to the signer, in base units.
| Token | Amount |
|---|---|
| ssl-labubu-672d3 | 4997501249 |
| token-abtc | 5073942482 |
| sbtc-token | 1276470894 |
| token-alex | 11941965600464880 |
| token-susdt | 174832697784601 |
Every row is an Index read, and the block's writes check against Bitcoin. Check the block →
Read it yourself
A block's proven writes need no key. Add a key for the calls inside a transaction and the entries it wrote, decoded.
1$curl -s https://api.secondlayer.tools/v1/proofs/writes/1508068 \
2 | jq '[.state_writes[].key | select(contains(".amm-")) | split("::")[0:4] | join("::")]'
1import { SecondLayer } from "@secondlayer/sdk";
2
3const sl = new SecondLayer({ apiKey: process.env.SECONDLAYER_API_KEY });
4
5const { events } = await sl.index.events.list({
6 eventType: "nested_contract_call",
7 txId: "0xe8b2ac705dcbb35d487a4efd7a0fe384bbad1d1d97ea970410ad82a3cd0d9daf",
8 sender: "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01",
9});
10for (const call of events.filter((c) => c.sender !== c.caller)) {
11 console.log(call.contract_id, call.function_name);
12}
1$curl -s "https://api.secondlayer.tools/v1/index/events?event_type=map_set&tx_id=0xe8b2ac705dcbb35d487a4efd7a0fe384bbad1d1d97ea970410ad82a3cd0d9daf" \
2 -H "Authorization: Bearer $SECONDLAYER_API_KEY" \
3 | jq '.events[] | {map, key: .decoded.key}'
1[
2 "vm-account::SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01::19",
3 "vm-account::SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01::19",
4 "vm::SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01::0::reserve",
5 "vm::SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-registry-v2-01::0::pools-data-map"
6]
SP2XD…X1NK.token-abtc get-balance-fixed
SP2XD…X1NK.token-abtc transfer-fixed
SM3VD…JFQ4.sbtc-token get-balance-available
SM3VD…JFQ4.sbtc-token transfer
SP102…T0AM.token-alex get-balance-fixed
SP102…T0AM.token-alex transfer-fixed
SP2XD…X1NK.token-susdt get-balance-fixed
SP2XD…X1NK.token-susdt transfer-fixed
1{
2 "map": "reserve",
3 "key": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-wstx-v2"
4}
5{
6 "map": "pools-data-map",
7 "key": {
8 "factor": "100000000",
9 "token-x": "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-wstx-v2",
10 "token-y": "SP2VCNXGRZCBTP8E9MQ6DJPFVXRBPWBN63FE06A1M.ssl-labubu-672d3"
11 }
12}
1const { events } = await sl.index.events.list({
2 eventType: "nested_contract_call",
3 sender: "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01",
4 fromHeight: 1508068,
5 toHeight: 1508068,
6});
7const asAnother = events.filter((c) => c.sender !== c.caller);
8console.log(events.length, asAnother.length);
9 8
1const { events } = await sl.index.events.list({
2 eventType: "map_set",
3 contractId: "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-registry-v2-01",
4 map: "pools-data-map",
5 fromHeight: 1508061,
6 toHeight: 1508068,
7});
8for (const write of events.slice(-2)) {
9 const value = write.decoded.value as { "balance-y": string };
10 console.log(write.block_height, value["balance-y"]);
11}
1508061 10000000000000
1508068 9995002498751
Webhooks· push
Get pushed instead
Get a POST when the vault makes a call or writes a map entry. Try the same triggers on past blocks first with secondlayer webhooks simulate.
1import { trigger } from "@secondlayer/sdk";
2
3const vault = "SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-vault-v2-01";
4
5await sl.webhooks.create({
6 name: "vault-watch",
7 url: "https://my-app.com/webhook",
8 triggers: [
9 trigger.nestedContractCall({ sender: vault }),
10 trigger.mapSet({ contractId: vault }),
11 ],
12});