@argonprotocol/testing 1.4.6 → 1.4.7-dev.68e22797

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -1382,7 +1382,6 @@ var {
1382
1382
  encodeMintingGatewayMintingAuthorityDeactivateTarget,
1383
1383
  hashMintingGatewayActivateMintingAuthority,
1384
1384
  hashMintingGatewayGatewayUpdateApproval,
1385
- hashMintingGatewayMintingAuthorityDeactivation,
1386
1385
  mintingGatewayAbi,
1387
1386
  MINTING_GATEWAY_UPDATE_KINDS
1388
1387
  } = import_mainchain6.EvmContracts;
@@ -1434,7 +1433,6 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1434
1433
  const argonApprovalsNonce = rawArgonApprovalsNonce;
1435
1434
  const argonApprovalsHash = rawArgonApprovalsHash;
1436
1435
  const paused = rawPaused;
1437
- const pendingClearOutQueueNonces = [];
1438
1436
  const candidateUpdates = [];
1439
1437
  let expectedPreviousApprovalHash = argonApprovalsHash;
1440
1438
  let readyQueueEntriesScanned = 0;
@@ -1449,14 +1447,8 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1449
1447
  }
1450
1448
  const entry = entryOption.unwrap();
1451
1449
  const approvingCouncilHash = toHexValue(entry.approvingCouncilHash);
1452
- if (!await queueEntryIsReady(
1453
- client,
1454
- entry,
1455
- approvingCouncilHash,
1456
- councilCache,
1457
- hashContext,
1458
- queueNonce
1459
- )) {
1450
+ const approvingCouncil = await loadCouncilByHash(client, approvingCouncilHash, councilCache);
1451
+ if (!queueEntryHasQuorum(entry, approvingCouncil)) {
1460
1452
  break;
1461
1453
  }
1462
1454
  readyQueueEntriesScanned += 1;
@@ -1473,10 +1465,15 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1473
1465
  expectedPreviousApprovalHash = toHexValue(entry.approvalHash);
1474
1466
  }
1475
1467
  }
1476
- while (candidateUpdates.length > 0 && candidateUpdates[candidateUpdates.length - 1]?.kind === MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate) {
1477
- pendingClearOutQueueNonces.unshift(candidateUpdates.pop().queueNonce);
1478
- }
1479
1468
  const updates = candidateUpdates;
1469
+ for (let index = 0; index < updates.length; index += 1) {
1470
+ const isBorder = updates[index].kind === MINTING_GATEWAY_UPDATE_KINDS.globalIssuanceCouncilRotate || index === updates.length - 1;
1471
+ if (isBorder || updates[index].signatures.length === 0) continue;
1472
+ updates[index] = {
1473
+ ...updates[index],
1474
+ signatures: []
1475
+ };
1476
+ }
1480
1477
  const firstQueueNonce = updates[0]?.queueNonce;
1481
1478
  const lastQueueNonce = updates[updates.length - 1]?.queueNonce;
1482
1479
  return {
@@ -1488,7 +1485,6 @@ async function getReadyEthereumGatewayUpdates(client, gatewayClient, options = {
1488
1485
  argonApprovalsNonce,
1489
1486
  argonApprovalsHash,
1490
1487
  paused,
1491
- pendingClearOutQueueNonces,
1492
1488
  ...firstQueueNonce !== void 0 ? { firstQueueNonce, lastQueueNonce } : {},
1493
1489
  updates
1494
1490
  };
@@ -1516,7 +1512,7 @@ async function buildGatewayUpdate(client, destinationChain, hashContext, queueNo
1516
1512
  signingKey
1517
1513
  };
1518
1514
  const payload = encodeMintingGatewayMintingAuthorityActivationTarget(target);
1519
- const targetPayloadHash = payloadHashFromActivationPayload(hashContext, target);
1515
+ const targetPayloadHash = hashMintingGatewayActivateMintingAuthority(hashContext, target);
1520
1516
  const approvalHash = hashMintingGatewayGatewayUpdateApproval(hashContext, {
1521
1517
  queueNonce,
1522
1518
  approvingCouncilHash,
@@ -1541,17 +1537,30 @@ async function buildGatewayUpdate(client, destinationChain, hashContext, queueNo
1541
1537
  };
1542
1538
  }
1543
1539
  if (entry.target.isMintingAuthorityDeactivation) {
1544
- const { payload, signatures } = validateDeactivationEntry(
1545
- hashContext,
1540
+ const signingKey = (0, import_viem3.getAddress)(toHexValue(entry.target.asMintingAuthorityDeactivation));
1541
+ const payload = encodeMintingGatewayMintingAuthorityDeactivateTarget({ signingKey });
1542
+ const targetPayloadHash = (0, import_viem3.keccak256)(payload);
1543
+ const approvalHash = hashMintingGatewayGatewayUpdateApproval(hashContext, {
1546
1544
  queueNonce,
1547
- entry,
1548
- approvingCouncilHash
1549
- );
1545
+ approvingCouncilHash,
1546
+ kind: MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate,
1547
+ targetId: signingKeyTargetId(signingKey),
1548
+ targetPayloadHash,
1549
+ previousUpdateHash: toHexValue(entry.previousApprovalHash)
1550
+ });
1551
+ if (toHexValue(entry.targetPayloadHash) !== targetPayloadHash) {
1552
+ throw new Error(`Queue nonce ${queueNonce} target payload hash does not match deactivation`);
1553
+ }
1554
+ if (toHexValue(entry.approvalHash) !== approvalHash) {
1555
+ throw new Error(
1556
+ `Queue nonce ${queueNonce} approval hash does not match deactivation: actual=${toHexValue(entry.approvalHash)} expected=${approvalHash} previous=${toHexValue(entry.previousApprovalHash)} council=${approvingCouncilHash}`
1557
+ );
1558
+ }
1550
1559
  return {
1551
1560
  queueNonce,
1552
1561
  kind: MINTING_GATEWAY_UPDATE_KINDS.mintingAuthorityDeactivate,
1553
1562
  payload,
1554
- signatures
1563
+ signatures: getSortedSignatures(entry.signatures)
1555
1564
  };
1556
1565
  }
1557
1566
  throw new Error(`Unsupported approval queue target ${entry.target.type}`);
@@ -1577,23 +1586,20 @@ async function loadCouncilByHash(client, councilHash, cache) {
1577
1586
  return loaded;
1578
1587
  }
1579
1588
  function queueEntryHasQuorum(entry, council) {
1580
- const signedWeight = [...entry.signatures.entries()].reduce((total, [signer]) => {
1589
+ let signedWeight = 0n;
1590
+ for (const [signer] of entry.signatures.entries()) {
1581
1591
  const signerAddress = (0, import_viem3.getAddress)(toHexValue(signer));
1582
1592
  const member = council.members.find((x) => x.signer === signerAddress);
1583
1593
  if (!member) {
1584
1594
  throw new Error(`Signature submitted by ${signerAddress}, which is not in the council`);
1585
1595
  }
1586
- return total + member.weight;
1587
- }, 0n);
1588
- return signedWeight * 2n > council.totalWeight;
1589
- }
1590
- async function queueEntryIsReady(client, entry, approvingCouncilHash, councilCache, hashContext, queueNonce) {
1591
- if (entry.target.isMintingAuthorityDeactivation) {
1592
- validateDeactivationEntry(hashContext, queueNonce, entry, approvingCouncilHash);
1596
+ signedWeight += member.weight;
1597
+ }
1598
+ if (signedWeight * 100n >= council.totalWeight * 90n) {
1593
1599
  return true;
1594
1600
  }
1595
- const approvingCouncil = await loadCouncilByHash(client, approvingCouncilHash, councilCache);
1596
- return queueEntryHasQuorum(entry, approvingCouncil);
1601
+ const unsignedMemberCount = council.members.length - entry.signatures.size;
1602
+ return unsignedMemberCount <= 2 && signedWeight * 100n >= council.totalWeight * 80n;
1597
1603
  }
1598
1604
  function councilToSnapshot(council) {
1599
1605
  return {
@@ -1601,46 +1607,8 @@ function councilToSnapshot(council) {
1601
1607
  weights: council.members.map((member) => member.weight)
1602
1608
  };
1603
1609
  }
1604
- function payloadHashFromActivationPayload(hashContext, target) {
1605
- return hashMintingGatewayActivateMintingAuthority(hashContext, target);
1606
- }
1607
- function payloadHashFromDeactivationPayload(target) {
1608
- return (0, import_viem3.keccak256)(encodeMintingGatewayMintingAuthorityDeactivateTarget(target));
1609
- }
1610
- function validateDeactivationEntry(hashContext, queueNonce, entry, approvingCouncilHash) {
1611
- const signingKey = (0, import_viem3.getAddress)(toHexValue(entry.target.asMintingAuthorityDeactivation));
1612
- const target = { signingKey };
1613
- const payload = encodeMintingGatewayMintingAuthorityDeactivateTarget(target);
1614
- const targetPayloadHash = payloadHashFromDeactivationPayload(target);
1615
- const approvalHash = hashMintingGatewayMintingAuthorityDeactivation(hashContext, {
1616
- queueNonce,
1617
- target,
1618
- previousUpdateHash: toHexValue(entry.previousApprovalHash)
1619
- });
1620
- if (toHexValue(entry.targetPayloadHash) !== targetPayloadHash) {
1621
- throw new Error(`Queue nonce ${queueNonce} target payload hash does not match deactivation`);
1622
- }
1623
- if (toHexValue(entry.approvalHash) !== approvalHash) {
1624
- throw new Error(
1625
- `Queue nonce ${queueNonce} approval hash does not match deactivation: actual=${toHexValue(entry.approvalHash)} expected=${approvalHash} previous=${toHexValue(entry.previousApprovalHash)} council=${approvingCouncilHash}`
1626
- );
1627
- }
1628
- const deactivationSignatures = [...entry.signatures.entries()];
1629
- if (deactivationSignatures.length !== 1) {
1630
- throw new Error(
1631
- `Queue nonce ${queueNonce} expected exactly one deactivation signature, received ${deactivationSignatures.length}`
1632
- );
1633
- }
1634
- const [signer] = deactivationSignatures[0];
1635
- if ((0, import_viem3.getAddress)(toHexValue(signer)) !== signingKey) {
1636
- throw new Error(
1637
- `Queue nonce ${queueNonce} deactivation signature was submitted by ${(0, import_viem3.getAddress)(toHexValue(signer))}, expected ${signingKey}`
1638
- );
1639
- }
1640
- return {
1641
- payload,
1642
- signatures: getSortedSignatures(entry.signatures)
1643
- };
1610
+ function signingKeyTargetId(signingKey) {
1611
+ return `0x${signingKey.slice(2).padStart(64, "0").toLowerCase()}`;
1644
1612
  }
1645
1613
  function getSortedSignatures(signatures) {
1646
1614
  return [...signatures.entries()].sort(