Skip to content

Commit 6727747

Browse files
werner-stacksgitbook-bot
authored andcommitted
GITBOOK-39: PostCondition type: add Staking and PoX members, verified against 7.5.0
1 parent 816cb27 commit 6727747

1 file changed

Lines changed: 69 additions & 4 deletions

File tree

‎docs/reference/stacks.js/stacks-transactions/types/PostCondition.md‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PostCondition
22

3-
Union type representing the three kinds of post-conditions: STX, fungible token, and non-fungible token.
3+
Union type representing the five kinds of post-conditions: STX, fungible token, non-fungible token, staking, and PoX.
44

55
***
66

@@ -17,18 +17,37 @@ const stxPc: PostCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HP
1717
const ftPc: PostCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
1818
.willSendGte(100)
1919
.ft('ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token', 'token-name');
20+
21+
// Staking post condition
22+
const stakingPc: PostCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
23+
.willSendLte(1000000)
24+
.ustxToLock();
25+
26+
// PoX post condition
27+
const poxPc: PostCondition = Pc.principal(
28+
'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6'
29+
).willNotPerformPox();
2030
```
2131

22-
**[Reference Link](https://github.com/stx-labs/stacks.js/tree/main/packages/transactions/src/postcondition-types.ts)**
32+
[**Reference Link**](https://github.com/stx-labs/stacks.js/blob/b7f0ed3f87cd4c5bfb7ab3c4bd8787c2018e3cec/packages/transactions/src/postcondition-types.ts)
2333

2434
***
2535

2636
### Definition
2737

2838
```ts
29-
type PostCondition = StxPostCondition | FungiblePostCondition | NonFungiblePostCondition;
39+
type PostCondition =
40+
| StxPostCondition
41+
| FungiblePostCondition
42+
| NonFungiblePostCondition
43+
| StakingPostCondition
44+
| PoxPostCondition;
3045
```
3146

47+
{% hint style="info" %}
48+
`StakingPostCondition` and `PoxPostCondition` were added for Stacks epoch 4.0 and are available in `@stacks/transactions` 7.5.0 and later. The source labels them SIP-044 in its JSDoc; the post-conditions themselves are specified in [SIP-045 §3.4.3](https://github.com/stacksgov/sips/blob/main/sips/sip-045/sip-045-pox-5-bitcoin-staking.md).
49+
{% endhint %}
50+
3251
***
3352

3453
### StxPostCondition
@@ -72,11 +91,57 @@ interface NonFungiblePostCondition {
7291
type: 'nft-postcondition';
7392
/** Address sending the asset */
7493
address: string;
75-
/** Comparator: 'sent' | 'not-sent' */
94+
/** Comparator: 'sent' | 'not-sent' | 'maybe-sent' */
7695
condition: NonFungibleComparator;
7796
/** Asset string: '<contract-id>::<token-name>' */
7897
asset: AssetString;
7998
/** Clarity value identifying the specific NFT */
8099
assetId: ClarityValue;
81100
}
82101
```
102+
103+
`maybe-sent` was added by [SIP-040](https://github.com/stacksgov/sips/blob/main/sips/sip-040/sip-040-post-conds.md) and is available in `@stacks/transactions` 7.4.0 and later. It always passes, and still counts as covering that NFT instance under `Deny` or `Originator` mode.
104+
105+
***
106+
107+
### StakingPostCondition
108+
109+
Guards staking STX, or modifying staked STX, for a principal — for example the pox-5 `stake`, `register-for-bond`, and `stake-update` calls. Uses the same comparators as `StxPostCondition`.
110+
111+
```ts
112+
interface StakingPostCondition {
113+
type: 'staking-postcondition';
114+
/** Address staking the STX (principal address, contract-id, or 'origin') */
115+
address: string;
116+
/** Comparator: 'eq' | 'gt' | 'gte' | 'lt' | 'lte' */
117+
condition: FungibleComparator;
118+
/** Amount in microSTX */
119+
amount: string | bigint | number;
120+
}
121+
```
122+
123+
***
124+
125+
### PoxPostCondition
126+
127+
Guards PoX state changes that do not alter locking status — for example the pox-5 `unstake`, `unstake-sbtc`, `update-bond-registration`, and `announce-l1-early-exit` calls. Carries only a principal and a condition code: there is no asset and no amount.
128+
129+
```ts
130+
interface PoxPostCondition {
131+
type: 'pox-postcondition';
132+
/** Address whose PoX actions are constrained (principal address, contract-id, or 'origin') */
133+
address: string;
134+
/** Comparator: 'will-not-perform' | 'may-perform' | 'will-perform' */
135+
condition: PoxComparator;
136+
}
137+
```
138+
139+
```ts
140+
type PoxComparator = 'will-not-perform' | 'may-perform' | 'will-perform';
141+
```
142+
143+
| Comparator | Meaning |
144+
| ------------------ | -------------------------------------------------------- |
145+
| `will-not-perform` | The principal must not perform a gated PoX action |
146+
| `may-perform` | The principal may or may not perform one — always passes |
147+
| `will-perform` | The principal must perform a gated PoX action |

0 commit comments

Comments
 (0)