-
Notifications
You must be signed in to change notification settings - Fork 309
Description
A PoX-2 contract will be deployed after the Stacks 2.1 hardfork goes live. Several new functions will be available:
-
stack-extend
/delegate-stack-extend
Stacks 2.1: PoX 2stack-extend
,delegate-stack-extend
stacks-network/stacks-core#2755 -
stack-unlock
PoX Updates:stack-unlock
stacks-network/stacks-core#2534 -
stack-increase
2.1: Feature:stack-increase
for PoX-2 stacks-network/stacks-core#3282 - Native segwit address support: Feat/native segwit stacks-network/stacks-core#3283
This changes the signatures for functions (e.g.stack-stx
,delegate-stack-stx
, etc) to use 32 bytes rather than 20 for address hashbytes, and expands the number of valid address version bytes. For for context see PoX: native segwit support stacks-network/stacks-core#2586 and Feat/get pox addrs stacks-network/stacks-core#3245).
It probably makes sense to create a new set of sister function calls for PoX-2, and detect if the new functions should be used via an RPC call to determine if PoX-2 is live. The library needs to detect if Period 3
has activated -- this is after the 2.1 fork, and after PoX cycle (N+1), see https://github.com/stacksgov/sips/blob/c0fb33e0fc2b62e8e6d4ed85fb4b4aa289bb6042/sips/sip-015/sip-015-network-upgrade.md#specification
It may be possible to detect if PoX-2 is ready by checking if GET /v2/pox
returns {"contract_id":"ST000000000000000000002AMW42H.pox-2"}
, but that appears to be unimplemented as of opening this issue: stacks-network/stacks-core#3262
In the meantime, something like this should work:
async function isPoX2Ready(): Promise<boolean> {
const req = await fetch(`/v2/data_var/ST000000000000000000002AMW42H/pox-2/configured?proof=0`);
const body = await req.text();
if (req.ok) {
return JSON.parse(body)['data'] === '0x03'; // Clarity boolean-true
} else if (req.status === 404 && body === 'Data var not found') {
return false;
} else {
throw new Error(`Unexpected response: ${req.status} - ${body}`);
}
}