|
1 | 1 | import {
|
| 2 | + BurnchainOpDelegateStx, |
2 | 3 | BurnchainOpRegisterAssetFt,
|
3 | 4 | BurnchainOpRegisterAssetNft,
|
4 | 5 | BurnchainOpStackStx,
|
@@ -518,6 +519,78 @@ function createTransactionFromCoreBtcStxLockEventPox4(
|
518 | 519 | return tx;
|
519 | 520 | }
|
520 | 521 |
|
| 522 | +function createTransactionFromCoreBtcDelegateStxEventPox4( |
| 523 | + chainId: ChainID, |
| 524 | + contractEvent: SmartContractEvent, |
| 525 | + decodedEvent: DbPoxSyntheticDelegateStxEvent, |
| 526 | + burnOpData: BurnchainOpDelegateStx, |
| 527 | + txResult: string, |
| 528 | + txId: string |
| 529 | +): DecodedTxResult { |
| 530 | + const resultCv = decodeClarityValue<ClarityValueResponse>(txResult); |
| 531 | + if (resultCv.type_id !== ClarityTypeID.ResponseOk) { |
| 532 | + throw new Error(`Unexpected tx result Clarity type ID: ${resultCv.type_id}`); |
| 533 | + } |
| 534 | + const senderAddress = decodeStacksAddress(burnOpData.delegate_stx.sender.address); |
| 535 | + const poxContractAddressString = |
| 536 | + getChainIDNetwork(chainId) === 'mainnet' |
| 537 | + ? BootContractAddress.mainnet |
| 538 | + : BootContractAddress.testnet; |
| 539 | + const poxContractAddress = decodeStacksAddress(poxContractAddressString); |
| 540 | + const contractName = contractEvent.contract_event.contract_identifier?.split('.')?.[1] ?? 'pox'; |
| 541 | + |
| 542 | + const legacyClarityVals = [ |
| 543 | + uintCV(burnOpData.delegate_stx.delegated_ustx), // amount-ustx |
| 544 | + principalCV(burnOpData.delegate_stx.delegate_to.address), // delegate-to |
| 545 | + someCV(uintCV(burnOpData.delegate_stx.until_burn_height)), // until-burn-ht |
| 546 | + someCV(poxAddressToTuple(burnOpData.delegate_stx.reward_addr[1])), // pox-addr |
| 547 | + ]; |
| 548 | + const fnLenBuffer = Buffer.alloc(4); |
| 549 | + fnLenBuffer.writeUInt32BE(legacyClarityVals.length); |
| 550 | + const serializedClarityValues = legacyClarityVals.map(c => serializeCV(c)); |
| 551 | + const rawFnArgs = bufferToHex(Buffer.concat([fnLenBuffer, ...serializedClarityValues])); |
| 552 | + const clarityFnArgs = decodeClarityValueList(rawFnArgs); |
| 553 | + |
| 554 | + const tx: DecodedTxResult = { |
| 555 | + tx_id: txId, |
| 556 | + version: |
| 557 | + getChainIDNetwork(chainId) === 'mainnet' |
| 558 | + ? TransactionVersion.Mainnet |
| 559 | + : TransactionVersion.Testnet, |
| 560 | + chain_id: chainId, |
| 561 | + auth: { |
| 562 | + type_id: PostConditionAuthFlag.Standard, |
| 563 | + origin_condition: { |
| 564 | + hash_mode: TxSpendingConditionSingleSigHashMode.P2PKH, |
| 565 | + signer: { |
| 566 | + address_version: senderAddress[0], |
| 567 | + address_hash_bytes: senderAddress[1], |
| 568 | + address: decodedEvent.stacker, |
| 569 | + }, |
| 570 | + nonce: '0', |
| 571 | + tx_fee: '0', |
| 572 | + key_encoding: TxPublicKeyEncoding.Compressed, |
| 573 | + signature: '0x', |
| 574 | + }, |
| 575 | + }, |
| 576 | + anchor_mode: AnchorModeID.Any, |
| 577 | + post_condition_mode: PostConditionModeID.Allow, |
| 578 | + post_conditions: [], |
| 579 | + post_conditions_buffer: '0x0100000000', |
| 580 | + payload: { |
| 581 | + type_id: TxPayloadTypeID.ContractCall, |
| 582 | + address: poxContractAddressString, |
| 583 | + address_version: poxContractAddress[0], |
| 584 | + address_hash_bytes: poxContractAddress[1], |
| 585 | + contract_name: contractName, |
| 586 | + function_name: 'delegate-stx', |
| 587 | + function_args: clarityFnArgs, |
| 588 | + function_args_buffer: rawFnArgs, |
| 589 | + }, |
| 590 | + }; |
| 591 | + return tx; |
| 592 | +} |
| 593 | + |
521 | 594 | /*
|
522 | 595 | ;; Delegate to `delegate-to` the ability to stack from a given address.
|
523 | 596 | ;; This method _does not_ lock the funds, rather, it allows the delegate
|
@@ -547,8 +620,8 @@ function createTransactionFromCoreBtcDelegateStxEvent(
|
547 | 620 | const senderAddress = decodeStacksAddress(decodedEvent.stacker);
|
548 | 621 | const poxContractAddressString =
|
549 | 622 | getChainIDNetwork(chainId) === 'mainnet'
|
550 |
| - ? 'SP000000000000000000002Q6VF78' |
551 |
| - : 'ST000000000000000000002AMW42H'; |
| 623 | + ? BootContractAddress.mainnet |
| 624 | + : BootContractAddress.testnet; |
552 | 625 | const poxContractAddress = decodeStacksAddress(poxContractAddressString);
|
553 | 626 | const contractName = contractEvent.contract_event.contract_identifier?.split('.')?.[1] ?? 'pox';
|
554 | 627 |
|
@@ -795,6 +868,22 @@ export function parseMessageTransaction(
|
795 | 868 | stxStacksPoxEvent
|
796 | 869 | );
|
797 | 870 | txSender = stxLockEvent.stx_lock_event.locked_address;
|
| 871 | + } else if ( |
| 872 | + poxEvent && |
| 873 | + poxEvent.decodedEvent.name === SyntheticPoxEventName.DelegateStx && |
| 874 | + poxEvent.contractEvent.contract_event.contract_identifier?.split('.')?.[1] === 'pox-4' && |
| 875 | + coreTx.burnchain_op && |
| 876 | + 'delegate_stx' in coreTx.burnchain_op |
| 877 | + ) { |
| 878 | + rawTx = createTransactionFromCoreBtcDelegateStxEventPox4( |
| 879 | + chainId, |
| 880 | + poxEvent.contractEvent, |
| 881 | + poxEvent.decodedEvent, |
| 882 | + coreTx.burnchain_op, |
| 883 | + coreTx.raw_result, |
| 884 | + coreTx.txid |
| 885 | + ); |
| 886 | + txSender = coreTx.burnchain_op.delegate_stx.sender.address; |
798 | 887 | } else if (poxEvent && poxEvent.decodedEvent.name === SyntheticPoxEventName.DelegateStx) {
|
799 | 888 | rawTx = createTransactionFromCoreBtcDelegateStxEvent(
|
800 | 889 | chainId,
|
|
0 commit comments