Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 810e52f

Browse files
committed
Update exchange guide with store deletion events
1 parent 55a3f98 commit 810e52f

File tree

2 files changed

+88
-32
lines changed

2 files changed

+88
-32
lines changed

apps/nextra/pages/en/build/guides/exchanges.mdx

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ const [balanceStr] = await aptos.view<[string]>({
211211
const balance = parseInt(balanceStr, 10);
212212
```
213213

214+
Besides SDK, you can also directly use aptos node's [balance API endpoint](/build/apis/fullnode-rest-api-reference#tag/accounts/GET/accounts/{address}/balance/{asset_type}) to get the balance of a migrated coin or fungible asset.
215+
214216
## Tracking Balance Changes
215217

216218
Balance changes can be queried in one of two ways:
@@ -331,48 +333,80 @@ In this case, we only care about coin store changes.
331333
</details>
332334

333335
3. Events are the events that were emitted by the transaction. In this case, we
334-
only care about the `0x1::coin::deposit` and `0x1::coin::withdraw` events.
336+
only care about the `0x1::coin::Withdraw` and `0x1::coin::Deposit` events.
335337

336-
The Coin deposit event is emitted when coins are deposited into an account. The
337-
account's balance will increase by that amount in the field `data.amoount`. To
338-
determine the matching asset, you must match the `guid` in the `deposit_events`
339-
to the `guid` in the `changes` section for a `CoinStore`.
338+
The Coin withdraw event is emitted when coins are withdrawn from an account. The
339+
account's balance will decrease by that amount in the field `data.amount`. To
340+
determine the matching asset, you must match the `guid` in the `withdraw_events`
341+
to the `guid` in the `changes` section for a `CoinStore`. But if the `CoinStore`
342+
is not found in the `changes`, it means it got deleted, and a `CoinStoreDeleteEvent`
343+
must be present instead. Then you can match the `guid` with
344+
`deleted_withdraw_event_handle_creation_number` and `event_handle_creation_address`.
340345

341346
<details>
342-
<summary>Coin Deposit Event</summary>
347+
<summary>Coin Withdraw Event</summary>
343348
```json
344349
{
345-
"events": [{
346-
"guid": {
347-
"creation_number": "2",
348-
"account_address": "0x5d6233bb8d7f8bd714af196339e9fb3104c9d66f38867b2a0585c4f7b9d04d28"
350+
"events": [
351+
{
352+
"guid": {
353+
"creation_number": "3",
354+
"account_address": "0xf8e25f6c8ce40a15107fb4b4d288ca03dd434d057392f2ccb5fde505a300a0bf"
355+
},
356+
"sequence_number": "0",
357+
"type": "0x1::coin::WithdrawEvent",
358+
"data": {
359+
"amount": "100000"
360+
}
349361
},
350-
"sequence_number": "0",
351-
"type": "0x1::coin::DepositEvent",
352-
"data": {
353-
"amount": "10"
362+
]
363+
}
364+
```
365+
</details>
366+
367+
<details>
368+
<summary>Coin Store Deletion Event</summary>
369+
```json
370+
{
371+
"events": [
372+
{
373+
"guid": {
374+
"creation_number": "0",
375+
"account_address": "0x0"
376+
},
377+
"sequence_number": "0",
378+
"type": "0x1::coin::CoinStoreDeletion",
379+
"data": {
380+
"coin_type": "0x1::aptos_coin::AptosCoin",
381+
"deleted_deposit_event_handle_creation_number": "2",
382+
"deleted_withdraw_event_handle_creation_number": "3",
383+
"event_handle_creation_address": "0xf8e25f6c8ce40a15107fb4b4d288ca03dd434d057392f2ccb5fde505a300a0bf"
384+
}
354385
}
355-
}]
386+
]
356387
}
357388
```
358389
</details>
359390

360-
The Coin withdraw event is emitted when coins are withdrawn from an account. The
361-
account's balance will decrease by that amount in the field `data.amount`. To
391+
The Coin deposit event is emitted when coins are deposited into an account. The
392+
account's balance will increase by that amount in the field `data.amoount`. To
362393
determine the matching asset, you must match the `guid` in the `deposit_events`
363-
to the `guid` in the `changes` section for a `CoinStore`.
394+
to the `guid` in the `changes` section for a `CoinStore`. Similarly, if the `CoinStore`
395+
is not found in the `changes`, it means it got deleted, and a `CoinStoreDeleteEvent`
396+
must be present instead. Then you can match the `guid` with
397+
`deleted_deposit_event_handle_creation_number` and `event_handle_creation_address`.
364398

365399
<details>
366-
<summary>Coin Withdraw Event</summary>
400+
<summary>Coin Deposit Event</summary>
367401
```json
368402
{
369403
"events": [{
370404
"guid": {
371-
"creation_number": "3",
372-
"account_address": "0x559d4f690c683fca7c539237aa8dc4c6ec09886b7016bf66f2cdeffef55468f0"
405+
"creation_number": "2",
406+
"account_address": "0x5d6233bb8d7f8bd714af196339e9fb3104c9d66f38867b2a0585c4f7b9d04d28"
373407
},
374-
"sequence_number": "52484",
375-
"type": "0x1::coin::WithdrawEvent",
408+
"sequence_number": "0",
409+
"type": "0x1::coin::DepositEvent",
376410
"data": {
377411
"amount": "10"
378412
}
@@ -381,6 +415,7 @@ to the `guid` in the `changes` section for a `CoinStore`.
381415
```
382416
</details>
383417

418+
384419
4. Gas usage only is tracked for APT. There is no direct event for tracking gas,
385420
but it can be calculated from the transaction. Using the `gas_used` field, and
386421
the `gas_unit_price` field, you can calculate the total gas used. In this case,
@@ -710,7 +745,10 @@ is the address of the `metadata` for the fungible asset.
710745
Additionally, to figure out the actual owner of the assets, you will need to look
711746
at the owner of the store. In this case, you will need the `0x1::object::ObjectCore`, where
712747
the `address` field matches the `store` field from the events. The `owner` field
713-
will show the asset owner's address.
748+
will show the asset owner's address. similar to the coin events, if the `ObjectCore`
749+
is not found in the `changes`, it means it got deleted, and a `FungibleStoreDeletion`
750+
event must be present instead. Then you can match the `store` fields between the
751+
`Withdraw`/`Deposit` events and the `FungibleStoreDeletion` event.
714752

715753
<details>
716754
<summary>Fungible Asset Changes</summary>
@@ -759,6 +797,25 @@ will show the asset owner's address.
759797
```
760798
</details>
761799

800+
<details>
801+
<summary>FungibleStore Deletion Event</summary>
802+
```json
803+
{
804+
"guid": {
805+
"creation_number": "0",
806+
"account_address": "0x0"
807+
},
808+
"sequence_number": "0",
809+
"type": "0x1::fungible_asset::FungibleStoreDeletion",
810+
"data": {
811+
"metadata": "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
812+
"owner": "0xcf3906e2c9bc7e489c3b09d5ed5d90d8d403a68a50fe52932116b26e5878af26",
813+
"store": "0xa6ab8518e5f28a5f27247a895aa8b3de4a917209c6841b16187e8d64a67de242"
814+
}
815+
}
816+
```
817+
</details>
818+
762819

763820
### Coins migrated to Fungible Asset Balance Changes
764821

@@ -1114,6 +1171,7 @@ Here is an example of a migrated coin with APT: https://api.mainnet.aptoslabs.co
11141171
```
11151172
</details>
11161173

1174+
11171175
## Transferring Assets
11181176

11191177
### Coin (or migrated coin) Transfers
@@ -1160,7 +1218,7 @@ In order to check that everything is working correctly, we've provided these che
11601218
To test balance checks, you can check the balance for the account `0x5` for the asset `0x1::aptos_coin::AptosCoin`.
11611219
The balance should show `0.002 APT`, where 0.001 APT is a coin, and 0.001 APT is a migrated coin (fungible asset).
11621220

1163-
If your balance is not correct, see [Coin and Migrated Coin Balances](#coin-and-migrated-coin-balances) for more information.
1221+
If your balance is not correct, see [Coin and Migrated Coin Balances](#coin-and-migrated-coins-balances) for more information.
11641222

11651223
### Balance Change / Transfer Checks
11661224

packages/aptos-nextra-components/src/utils/mdast/mdast.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ test("keyRotation.md parse and fix AST", () => {
77
markdownToMdx(tree);
88
const markdown = astToMarkdown(tree);
99
expect(markdown).toEqual(
10-
astToMarkdown(
11-
readFileAsTree("./examples/keyRotation.expect.md"),
12-
).toString(),
10+
astToMarkdown(readFileAsTree("./examples/keyRotation.expect.md")).toString()
1311
);
1412
});
1513

@@ -20,8 +18,8 @@ test("account_snippet.md parse and fix AST", () => {
2018
const markdown = astToMarkdown(tree);
2119
expect(markdown).toEqual(
2220
astToMarkdown(
23-
readFileAsTree("./examples/account_snippet.expect.md"),
24-
).toString(),
21+
readFileAsTree("./examples/account_snippet.expect.md")
22+
).toString()
2523
);
2624
});
2725

@@ -31,8 +29,8 @@ test("vector_snippet.md parse and fix AST", () => {
3129
const markdown = astToMarkdown(tree);
3230
expect(markdown).toEqual(
3331
astToMarkdown(
34-
readFileAsTree("./examples/vector_snippet.expect.md"),
35-
).toString(),
32+
readFileAsTree("./examples/vector_snippet.expect.md")
33+
).toString()
3634
);
3735
});
3836

0 commit comments

Comments
 (0)